| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "xfa/src/fwl/core/fwl_widgetimp.h" | |
| 8 | |
| 9 #include <algorithm> | |
| 10 | |
| 11 #include "xfa/include/fwl/adapter/fwl_adapternative.h" | |
| 12 #include "xfa/include/fwl/adapter/fwl_adapterthreadmgr.h" | |
| 13 #include "xfa/include/fwl/adapter/fwl_adapterwidgetmgr.h" | |
| 14 #include "xfa/include/fwl/basewidget/fwl_combobox.h" | |
| 15 #include "xfa/include/fwl/basewidget/fwl_datetimepicker.h" | |
| 16 #include "xfa/include/fwl/basewidget/fwl_menu.h" | |
| 17 #include "xfa/include/fwl/core/fwl_app.h" | |
| 18 #include "xfa/include/fwl/core/fwl_content.h" | |
| 19 #include "xfa/include/fwl/core/fwl_form.h" | |
| 20 #include "xfa/include/fwl/core/fwl_theme.h" | |
| 21 #include "xfa/src/fde/tto/fde_textout.h" | |
| 22 #include "xfa/src/fwl/core/fwl_appimp.h" | |
| 23 #include "xfa/src/fwl/core/fwl_noteimp.h" | |
| 24 #include "xfa/src/fwl/core/fwl_targetimp.h" | |
| 25 #include "xfa/src/fwl/core/fwl_threadimp.h" | |
| 26 #include "xfa/src/fwl/core/fwl_widgetmgrimp.h" | |
| 27 | |
| 28 FWL_ERR IFWL_Widget::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
| 29 return static_cast<CFWL_WidgetImp*>(GetImpl()) | |
| 30 ->GetWidgetRect(rect, bAutoSize); | |
| 31 } | |
| 32 FWL_ERR IFWL_Widget::GetGlobalRect(CFX_RectF& rect) { | |
| 33 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetGlobalRect(rect); | |
| 34 } | |
| 35 FWL_ERR IFWL_Widget::SetWidgetRect(const CFX_RectF& rect) { | |
| 36 return static_cast<CFWL_WidgetImp*>(GetImpl())->SetWidgetRect(rect); | |
| 37 } | |
| 38 FWL_ERR IFWL_Widget::GetClientRect(CFX_RectF& rect) { | |
| 39 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetClientRect(rect); | |
| 40 } | |
| 41 IFWL_Widget* IFWL_Widget::GetParent() { | |
| 42 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetParent(); | |
| 43 } | |
| 44 FWL_ERR IFWL_Widget::SetParent(IFWL_Widget* pParent) { | |
| 45 return static_cast<CFWL_WidgetImp*>(GetImpl())->SetParent(pParent); | |
| 46 } | |
| 47 IFWL_Widget* IFWL_Widget::GetOwner() { | |
| 48 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetOwner(); | |
| 49 } | |
| 50 FWL_ERR IFWL_Widget::SetOwner(IFWL_Widget* pOwner) { | |
| 51 return static_cast<CFWL_WidgetImp*>(GetImpl())->SetOwner(pOwner); | |
| 52 } | |
| 53 IFWL_Widget* IFWL_Widget::GetOuter() { | |
| 54 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetOuter(); | |
| 55 } | |
| 56 FX_DWORD IFWL_Widget::GetStyles() { | |
| 57 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetStyles(); | |
| 58 } | |
| 59 FWL_ERR IFWL_Widget::ModifyStyles(FX_DWORD dwStylesAdded, | |
| 60 FX_DWORD dwStylesRemoved) { | |
| 61 return static_cast<CFWL_WidgetImp*>(GetImpl()) | |
| 62 ->ModifyStyles(dwStylesAdded, dwStylesRemoved); | |
| 63 } | |
| 64 FX_DWORD IFWL_Widget::GetStylesEx() { | |
| 65 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetStylesEx(); | |
| 66 } | |
| 67 FWL_ERR IFWL_Widget::ModifyStylesEx(FX_DWORD dwStylesExAdded, | |
| 68 FX_DWORD dwStylesExRemoved) { | |
| 69 return static_cast<CFWL_WidgetImp*>(GetImpl()) | |
| 70 ->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | |
| 71 } | |
| 72 FX_DWORD IFWL_Widget::GetStates() { | |
| 73 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetStates(); | |
| 74 } | |
| 75 FWL_ERR IFWL_Widget::SetStates(FX_DWORD dwStates, FX_BOOL bSet) { | |
| 76 return static_cast<CFWL_WidgetImp*>(GetImpl())->SetStates(dwStates, bSet); | |
| 77 } | |
| 78 FWL_ERR IFWL_Widget::SetPrivateData(void* module_id, | |
| 79 void* pData, | |
| 80 PD_CALLBACK_FREEDATA callback) { | |
| 81 return static_cast<CFWL_WidgetImp*>(GetImpl()) | |
| 82 ->SetPrivateData(module_id, pData, callback); | |
| 83 } | |
| 84 void* IFWL_Widget::GetPrivateData(void* module_id) { | |
| 85 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetPrivateData(module_id); | |
| 86 } | |
| 87 FWL_ERR IFWL_Widget::Update() { | |
| 88 return static_cast<CFWL_WidgetImp*>(GetImpl())->Update(); | |
| 89 } | |
| 90 FWL_ERR IFWL_Widget::LockUpdate() { | |
| 91 return static_cast<CFWL_WidgetImp*>(GetImpl())->LockUpdate(); | |
| 92 } | |
| 93 FWL_ERR IFWL_Widget::UnlockUpdate() { | |
| 94 return static_cast<CFWL_WidgetImp*>(GetImpl())->UnlockUpdate(); | |
| 95 } | |
| 96 FX_DWORD IFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | |
| 97 return static_cast<CFWL_WidgetImp*>(GetImpl())->HitTest(fx, fy); | |
| 98 } | |
| 99 FWL_ERR IFWL_Widget::TransformTo(IFWL_Widget* pWidget, | |
| 100 FX_FLOAT& fx, | |
| 101 FX_FLOAT& fy) { | |
| 102 return static_cast<CFWL_WidgetImp*>(GetImpl())->TransformTo(pWidget, fx, fy); | |
| 103 } | |
| 104 FWL_ERR IFWL_Widget::TransformTo(IFWL_Widget* pWidget, CFX_RectF& rt) { | |
| 105 return static_cast<CFWL_WidgetImp*>(GetImpl())->TransformTo(pWidget, rt); | |
| 106 } | |
| 107 FWL_ERR IFWL_Widget::GetMatrix(CFX_Matrix& matrix, FX_BOOL bGlobal) { | |
| 108 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetMatrix(matrix, bGlobal); | |
| 109 } | |
| 110 FWL_ERR IFWL_Widget::SetMatrix(const CFX_Matrix& matrix) { | |
| 111 return static_cast<CFWL_WidgetImp*>(GetImpl())->SetMatrix(matrix); | |
| 112 } | |
| 113 FWL_ERR IFWL_Widget::DrawWidget(CFX_Graphics* pGraphics, | |
| 114 const CFX_Matrix* pMatrix) { | |
| 115 return static_cast<CFWL_WidgetImp*>(GetImpl()) | |
| 116 ->DrawWidget(pGraphics, pMatrix); | |
| 117 } | |
| 118 IFWL_ThemeProvider* IFWL_Widget::GetThemeProvider() { | |
| 119 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetThemeProvider(); | |
| 120 } | |
| 121 FWL_ERR IFWL_Widget::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { | |
| 122 return static_cast<CFWL_WidgetImp*>(GetImpl()) | |
| 123 ->SetThemeProvider(pThemeProvider); | |
| 124 } | |
| 125 FWL_ERR IFWL_Widget::SetDataProvider(IFWL_DataProvider* pDataProvider) { | |
| 126 return static_cast<CFWL_WidgetImp*>(GetImpl()) | |
| 127 ->SetDataProvider(pDataProvider); | |
| 128 } | |
| 129 IFWL_WidgetDelegate* IFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { | |
| 130 return static_cast<CFWL_WidgetImp*>(GetImpl())->SetDelegate(pDelegate); | |
| 131 } | |
| 132 IFWL_NoteThread* IFWL_Widget::GetOwnerThread() const { | |
| 133 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetOwnerThread(); | |
| 134 } | |
| 135 CFX_SizeF IFWL_Widget::GetOffsetFromParent(IFWL_Widget* pParent) { | |
| 136 return static_cast<CFWL_WidgetImp*>(GetImpl())->GetOffsetFromParent(pParent); | |
| 137 } | |
| 138 FWL_ERR CFWL_WidgetImp::Initialize() { | |
| 139 IFWL_App* pApp = FWL_GetApp(); | |
| 140 if (!pApp) | |
| 141 return FWL_ERR_Indefinite; | |
| 142 IFWL_AdapterNative* pAdapter = pApp->GetAdapterNative(); | |
| 143 if (!pAdapter) | |
| 144 return FWL_ERR_Indefinite; | |
| 145 IFWL_AdapterThreadMgr* pAdapterThread = pAdapter->GetThreadMgr(); | |
| 146 if (!pAdapterThread) | |
| 147 return FWL_ERR_Indefinite; | |
| 148 SetOwnerThread(static_cast<CFWL_NoteThreadImp*>( | |
| 149 pAdapterThread->GetCurrentThread()->GetImpl())); | |
| 150 IFWL_Widget* pParent = m_pProperties->m_pParent; | |
| 151 m_pWidgetMgr->InsertWidget(pParent, m_pInterface); | |
| 152 if (!IsChild()) { | |
| 153 { | |
| 154 IFWL_Widget* pOwner = m_pProperties->m_pOwner; | |
| 155 if (pOwner) { | |
| 156 m_pWidgetMgr->SetOwner(pOwner, m_pInterface); | |
| 157 } | |
| 158 } | |
| 159 m_pWidgetMgr->CreateWidget_Native(m_pInterface); | |
| 160 } | |
| 161 return FWL_ERR_Succeeded; | |
| 162 } | |
| 163 FWL_ERR CFWL_WidgetImp::Finalize() { | |
| 164 NotifyDriver(); | |
| 165 IFWL_Form* pForm = static_cast<IFWL_Form*>( | |
| 166 FWL_GetWidgetMgr()->GetWidget(m_pInterface, FWL_WGTRELATION_SystemForm)); | |
| 167 if (pForm && pForm != m_pInterface) { | |
| 168 IFWL_Content* pContent = pForm->GetContent(); | |
| 169 if (pContent) { | |
| 170 pContent->RemoveWidget(m_pInterface); | |
| 171 } | |
| 172 } | |
| 173 if (!IsChild()) { | |
| 174 m_pWidgetMgr->DestroyWidget_Native(m_pInterface); | |
| 175 } | |
| 176 m_pWidgetMgr->RemoveWidget(m_pInterface); | |
| 177 return FWL_ERR_Succeeded; | |
| 178 } | |
| 179 FWL_ERR CFWL_WidgetImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
| 180 if (bAutoSize) { | |
| 181 if (HasEdge()) { | |
| 182 FX_FLOAT fEdge = GetEdgeWidth(); | |
| 183 rect.Inflate(fEdge, fEdge); | |
| 184 } | |
| 185 if (HasBorder()) { | |
| 186 FX_FLOAT fBorder = GetBorderSize(); | |
| 187 rect.Inflate(fBorder, fBorder); | |
| 188 } | |
| 189 } else { | |
| 190 rect = m_pProperties->m_rtWidget; | |
| 191 } | |
| 192 return FWL_ERR_Succeeded; | |
| 193 } | |
| 194 FWL_ERR CFWL_WidgetImp::GetGlobalRect(CFX_RectF& rect) { | |
| 195 IFWL_Widget* pForm = | |
| 196 m_pWidgetMgr->GetWidget(m_pInterface, FWL_WGTRELATION_SystemForm); | |
| 197 if (!pForm) | |
| 198 return FWL_ERR_Indefinite; | |
| 199 rect.Set(0, 0, m_pProperties->m_rtWidget.width, | |
| 200 m_pProperties->m_rtWidget.height); | |
| 201 if (pForm == m_pInterface) { | |
| 202 return FWL_ERR_Succeeded; | |
| 203 } | |
| 204 return TransformTo(pForm, rect); | |
| 205 } | |
| 206 FWL_ERR CFWL_WidgetImp::SetWidgetRect(const CFX_RectF& rect) { | |
| 207 CFX_RectF rtOld = m_pProperties->m_rtWidget; | |
| 208 m_pProperties->m_rtWidget = rect; | |
| 209 if (IsChild()) { | |
| 210 if (FXSYS_fabs(rtOld.width - rect.width) > 0.5f || | |
| 211 FXSYS_fabs(rtOld.height - rect.height) > 0.5f) { | |
| 212 CFWL_EvtSizeChanged ev; | |
| 213 ev.m_pSrcTarget = m_pInterface; | |
| 214 ev.m_rtOld = rtOld; | |
| 215 ev.m_rtNew = rect; | |
| 216 IFWL_WidgetDelegate* pDelegate = SetDelegate(NULL); | |
| 217 if (pDelegate) { | |
| 218 pDelegate->OnProcessEvent(&ev); | |
| 219 } | |
| 220 } | |
| 221 return FWL_ERR_Succeeded; | |
| 222 } | |
| 223 m_pWidgetMgr->SetWidgetRect_Native(m_pInterface, rect); | |
| 224 return FWL_ERR_Succeeded; | |
| 225 } | |
| 226 FWL_ERR CFWL_WidgetImp::GetClientRect(CFX_RectF& rect) { | |
| 227 GetEdgeRect(rect); | |
| 228 if (HasEdge()) { | |
| 229 FX_FLOAT fEdge = GetEdgeWidth(); | |
| 230 rect.Deflate(fEdge, fEdge); | |
| 231 } | |
| 232 return FWL_ERR_Succeeded; | |
| 233 } | |
| 234 IFWL_Widget* CFWL_WidgetImp::GetParent() { | |
| 235 return m_pWidgetMgr->GetWidget(m_pInterface, FWL_WGTRELATION_Parent); | |
| 236 } | |
| 237 FWL_ERR CFWL_WidgetImp::SetParent(IFWL_Widget* pParent) { | |
| 238 m_pProperties->m_pParent = pParent; | |
| 239 m_pWidgetMgr->SetParent(pParent, m_pInterface); | |
| 240 return FWL_ERR_Succeeded; | |
| 241 } | |
| 242 IFWL_Widget* CFWL_WidgetImp::GetOwner() { | |
| 243 return m_pWidgetMgr->GetWidget(m_pInterface, FWL_WGTRELATION_Owner); | |
| 244 } | |
| 245 FWL_ERR CFWL_WidgetImp::SetOwner(IFWL_Widget* pOwner) { | |
| 246 m_pProperties->m_pOwner = pOwner; | |
| 247 m_pWidgetMgr->SetOwner(pOwner, m_pInterface); | |
| 248 return FWL_ERR_Succeeded; | |
| 249 } | |
| 250 IFWL_Widget* CFWL_WidgetImp::GetOuter() { | |
| 251 return m_pOuter; | |
| 252 } | |
| 253 FX_DWORD CFWL_WidgetImp::GetStyles() { | |
| 254 return m_pProperties->m_dwStyles; | |
| 255 } | |
| 256 FWL_ERR CFWL_WidgetImp::ModifyStyles(FX_DWORD dwStylesAdded, | |
| 257 FX_DWORD dwStylesRemoved) { | |
| 258 m_pProperties->m_dwStyles = | |
| 259 (m_pProperties->m_dwStyles & ~dwStylesRemoved) | dwStylesAdded; | |
| 260 return FWL_ERR_Succeeded; | |
| 261 } | |
| 262 FX_DWORD CFWL_WidgetImp::GetStylesEx() { | |
| 263 return m_pProperties->m_dwStyleExes; | |
| 264 } | |
| 265 FWL_ERR CFWL_WidgetImp::ModifyStylesEx(FX_DWORD dwStylesExAdded, | |
| 266 FX_DWORD dwStylesExRemoved) { | |
| 267 m_pProperties->m_dwStyleExes = | |
| 268 (m_pProperties->m_dwStyleExes & ~dwStylesExRemoved) | dwStylesExAdded; | |
| 269 return FWL_ERR_Succeeded; | |
| 270 } | |
| 271 FX_DWORD CFWL_WidgetImp::GetStates() { | |
| 272 return m_pProperties->m_dwStates; | |
| 273 } | |
| 274 static void NotifyHideChildWidget(IFWL_WidgetMgr* widgetMgr, | |
| 275 IFWL_Widget* widget, | |
| 276 CFWL_NoteDriver* noteDriver) { | |
| 277 IFWL_Widget* child = widgetMgr->GetWidget(widget, FWL_WGTRELATION_FirstChild); | |
| 278 while (child) { | |
| 279 noteDriver->NotifyTargetHide(child); | |
| 280 NotifyHideChildWidget(widgetMgr, child, noteDriver); | |
| 281 child = widgetMgr->GetWidget(child, FWL_WGTRELATION_NextSibling); | |
| 282 } | |
| 283 } | |
| 284 FWL_ERR CFWL_WidgetImp::SetStates(FX_DWORD dwStates, FX_BOOL bSet) { | |
| 285 bSet ? (m_pProperties->m_dwStates |= dwStates) | |
| 286 : (m_pProperties->m_dwStates &= ~dwStates); | |
| 287 FWL_ERR ret = FWL_ERR_Succeeded; | |
| 288 if (dwStates & FWL_WGTSTATE_Invisible) { | |
| 289 if (bSet) { | |
| 290 ret = m_pWidgetMgr->HideWidget_Native(m_pInterface); | |
| 291 CFWL_NoteDriver* noteDriver = | |
| 292 static_cast<CFWL_NoteDriver*>(GetOwnerThread()->GetNoteDriver()); | |
| 293 IFWL_WidgetMgr* widgetMgr = FWL_GetWidgetMgr(); | |
| 294 noteDriver->NotifyTargetHide(m_pInterface); | |
| 295 IFWL_Widget* child = | |
| 296 widgetMgr->GetWidget(m_pInterface, FWL_WGTRELATION_FirstChild); | |
| 297 while (child) { | |
| 298 noteDriver->NotifyTargetHide(child); | |
| 299 NotifyHideChildWidget(widgetMgr, child, noteDriver); | |
| 300 child = widgetMgr->GetWidget(child, FWL_WGTRELATION_NextSibling); | |
| 301 } | |
| 302 } else { | |
| 303 ret = m_pWidgetMgr->ShowWidget_Native(m_pInterface); | |
| 304 } | |
| 305 } | |
| 306 return ret; | |
| 307 } | |
| 308 FWL_ERR CFWL_WidgetImp::SetPrivateData(void* module_id, | |
| 309 void* pData, | |
| 310 PD_CALLBACK_FREEDATA callback) { | |
| 311 if (!m_pPrivateData) { | |
| 312 m_pPrivateData = new CFX_PrivateData; | |
| 313 } | |
| 314 m_pPrivateData->SetPrivateData(module_id, pData, callback); | |
| 315 return FWL_ERR_Succeeded; | |
| 316 } | |
| 317 void* CFWL_WidgetImp::GetPrivateData(void* module_id) { | |
| 318 if (!m_pPrivateData) | |
| 319 return NULL; | |
| 320 return m_pPrivateData->GetPrivateData(module_id); | |
| 321 } | |
| 322 FWL_ERR CFWL_WidgetImp::Update() { | |
| 323 return FWL_ERR_Succeeded; | |
| 324 } | |
| 325 FWL_ERR CFWL_WidgetImp::LockUpdate() { | |
| 326 m_iLock++; | |
| 327 return FWL_ERR_Succeeded; | |
| 328 } | |
| 329 FWL_ERR CFWL_WidgetImp::UnlockUpdate() { | |
| 330 if (IsLocked()) { | |
| 331 m_iLock--; | |
| 332 } | |
| 333 return FWL_ERR_Succeeded; | |
| 334 } | |
| 335 FX_DWORD CFWL_WidgetImp::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | |
| 336 CFX_RectF rtClient; | |
| 337 GetClientRect(rtClient); | |
| 338 if (rtClient.Contains(fx, fy)) { | |
| 339 return FWL_WGTHITTEST_Client; | |
| 340 } | |
| 341 if (HasEdge()) { | |
| 342 CFX_RectF rtEdge; | |
| 343 GetEdgeRect(rtEdge); | |
| 344 if (rtEdge.Contains(fx, fy)) { | |
| 345 return FWL_WGTHITTEST_Edge; | |
| 346 } | |
| 347 } | |
| 348 if (HasBorder()) { | |
| 349 CFX_RectF rtRelative; | |
| 350 GetRelativeRect(rtRelative); | |
| 351 if (rtRelative.Contains(fx, fy)) { | |
| 352 return FWL_WGTHITTEST_Border; | |
| 353 } | |
| 354 } | |
| 355 return FWL_WGTHITTEST_Unknown; | |
| 356 } | |
| 357 FWL_ERR CFWL_WidgetImp::TransformTo(IFWL_Widget* pWidget, | |
| 358 FX_FLOAT& fx, | |
| 359 FX_FLOAT& fy) { | |
| 360 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 361 CFX_SizeF szOffset; | |
| 362 if (IsParent(pWidget)) { | |
| 363 szOffset = GetOffsetFromParent(pWidget); | |
| 364 } else { | |
| 365 szOffset = pWidget->GetOffsetFromParent(m_pInterface); | |
| 366 szOffset.x = -szOffset.x; | |
| 367 szOffset.y = -szOffset.y; | |
| 368 } | |
| 369 fx += szOffset.x; | |
| 370 fy += szOffset.y; | |
| 371 return FWL_ERR_Succeeded; | |
| 372 } | |
| 373 CFX_RectF r; | |
| 374 CFX_Matrix m; | |
| 375 IFWL_Widget* parent = GetParent(); | |
| 376 if (parent) { | |
| 377 GetWidgetRect(r); | |
| 378 fx += r.left; | |
| 379 fy += r.top; | |
| 380 GetMatrix(m, TRUE); | |
| 381 m.TransformPoint(fx, fy); | |
| 382 } | |
| 383 IFWL_Widget* form1 = | |
| 384 m_pWidgetMgr->GetWidget(m_pInterface, FWL_WGTRELATION_SystemForm); | |
| 385 if (!form1) | |
| 386 return FWL_ERR_Indefinite; | |
| 387 if (!pWidget) { | |
| 388 form1->GetWidgetRect(r); | |
| 389 fx += r.left; | |
| 390 fy += r.top; | |
| 391 #ifdef FWL_UseMacSystemBorder | |
| 392 if (form1->GetStyles() & FWL_WGTSTYLE_Caption) { | |
| 393 FX_FLOAT l, t, r, b; | |
| 394 l = t = r = b = 0; | |
| 395 FWL_GetAdapterWidgetMgr()->GetSystemBorder(l, t, r, b); | |
| 396 fy += t; | |
| 397 } | |
| 398 #endif | |
| 399 return FWL_ERR_Succeeded; | |
| 400 } | |
| 401 IFWL_Widget* form2 = | |
| 402 m_pWidgetMgr->GetWidget(pWidget, FWL_WGTRELATION_SystemForm); | |
| 403 if (!form2) | |
| 404 return FWL_ERR_Indefinite; | |
| 405 if (form1 != form2) { | |
| 406 form1->GetWidgetRect(r); | |
| 407 fx += r.left; | |
| 408 fy += r.top; | |
| 409 form2->GetWidgetRect(r); | |
| 410 fx -= r.left; | |
| 411 fy -= r.top; | |
| 412 #ifdef FWL_UseMacSystemBorder | |
| 413 if ((form1->GetStyles() & FWL_WGTSTYLE_Caption) != | |
| 414 (form2->GetStyles() & FWL_WGTSTYLE_Caption)) { | |
| 415 FX_FLOAT l, t, r, b; | |
| 416 l = t = r = b = 0; | |
| 417 FWL_GetAdapterWidgetMgr()->GetSystemBorder(l, t, r, b); | |
| 418 (form1->GetStyles() & FWL_WGTSTYLE_Caption) ? (fy += t) : (fy -= t); | |
| 419 } | |
| 420 #endif | |
| 421 } | |
| 422 parent = pWidget->GetParent(); | |
| 423 if (parent) { | |
| 424 pWidget->GetMatrix(m, TRUE); | |
| 425 CFX_Matrix m1; | |
| 426 m1.SetIdentity(); | |
| 427 m1.SetReverse(m); | |
| 428 m1.TransformPoint(fx, fy); | |
| 429 pWidget->GetWidgetRect(r); | |
| 430 fx -= r.left; | |
| 431 fy -= r.top; | |
| 432 } | |
| 433 return FWL_ERR_Succeeded; | |
| 434 } | |
| 435 FWL_ERR CFWL_WidgetImp::TransformTo(IFWL_Widget* pWidget, CFX_RectF& rt) { | |
| 436 return TransformTo(pWidget, rt.left, rt.top); | |
| 437 } | |
| 438 FWL_ERR CFWL_WidgetImp::GetMatrix(CFX_Matrix& matrix, FX_BOOL bGlobal) { | |
| 439 if (!m_pProperties) | |
| 440 return FWL_ERR_Indefinite; | |
| 441 if (bGlobal) { | |
| 442 IFWL_Widget* parent = GetParent(); | |
| 443 CFX_PtrArray parents; | |
| 444 while (parent) { | |
| 445 parents.Add(parent); | |
| 446 parent = parent->GetParent(); | |
| 447 } | |
| 448 matrix.SetIdentity(); | |
| 449 CFX_Matrix ctmOnParent; | |
| 450 CFX_RectF rect; | |
| 451 int32_t count = parents.GetSize(); | |
| 452 for (int32_t i = count - 2; i >= 0; i--) { | |
| 453 parent = static_cast<IFWL_Widget*>(parents.GetAt(i)); | |
| 454 parent->GetMatrix(ctmOnParent, FALSE); | |
| 455 parent->GetWidgetRect(rect); | |
| 456 matrix.Concat(ctmOnParent, TRUE); | |
| 457 matrix.Translate(rect.left, rect.top, TRUE); | |
| 458 } | |
| 459 matrix.Concat(m_pProperties->m_ctmOnParent, TRUE); | |
| 460 parents.RemoveAll(); | |
| 461 } else { | |
| 462 matrix = m_pProperties->m_ctmOnParent; | |
| 463 } | |
| 464 return FWL_ERR_Succeeded; | |
| 465 } | |
| 466 FWL_ERR CFWL_WidgetImp::SetMatrix(const CFX_Matrix& matrix) { | |
| 467 if (!m_pProperties) | |
| 468 return FWL_ERR_Indefinite; | |
| 469 IFWL_Widget* parent = GetParent(); | |
| 470 if (!parent) { | |
| 471 return FWL_ERR_Indefinite; | |
| 472 } | |
| 473 m_pProperties->m_ctmOnParent = matrix; | |
| 474 return FWL_ERR_Succeeded; | |
| 475 } | |
| 476 FWL_ERR CFWL_WidgetImp::DrawWidget(CFX_Graphics* pGraphics, | |
| 477 const CFX_Matrix* pMatrix) { | |
| 478 return FWL_ERR_Indefinite; | |
| 479 } | |
| 480 IFWL_ThemeProvider* CFWL_WidgetImp::GetThemeProvider() { | |
| 481 return m_pProperties->m_pThemeProvider; | |
| 482 } | |
| 483 FWL_ERR CFWL_WidgetImp::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { | |
| 484 m_pProperties->m_pThemeProvider = pThemeProvider; | |
| 485 return FWL_ERR_Succeeded; | |
| 486 } | |
| 487 FWL_ERR CFWL_WidgetImp::SetDataProvider(IFWL_DataProvider* pDataProvider) { | |
| 488 m_pProperties->m_pDataProvider = pDataProvider; | |
| 489 return FWL_ERR_Succeeded; | |
| 490 } | |
| 491 IFWL_WidgetDelegate* CFWL_WidgetImp::SetDelegate( | |
| 492 IFWL_WidgetDelegate* pDelegate) { | |
| 493 if (!m_pCurDelegate) { | |
| 494 m_pCurDelegate = m_pDelegate; | |
| 495 } | |
| 496 if (!pDelegate) { | |
| 497 return m_pCurDelegate; | |
| 498 } | |
| 499 IFWL_WidgetDelegate* pOldDelegate = m_pCurDelegate; | |
| 500 m_pCurDelegate = pDelegate; | |
| 501 return pOldDelegate; | |
| 502 } | |
| 503 IFWL_NoteThread* CFWL_WidgetImp::GetOwnerThread() const { | |
| 504 return static_cast<IFWL_NoteThread*>(m_pOwnerThread->GetInterface()); | |
| 505 } | |
| 506 FWL_ERR CFWL_WidgetImp::SetOwnerThread(CFWL_NoteThreadImp* pOwnerThread) { | |
| 507 m_pOwnerThread = pOwnerThread; | |
| 508 return FWL_ERR_Succeeded; | |
| 509 } | |
| 510 IFWL_Widget* CFWL_WidgetImp::GetInterface() const { | |
| 511 return m_pInterface; | |
| 512 } | |
| 513 void CFWL_WidgetImp::SetInterface(IFWL_Widget* pInterface) { | |
| 514 m_pInterface = pInterface; | |
| 515 } | |
| 516 CFWL_WidgetImp::CFWL_WidgetImp(const CFWL_WidgetImpProperties& properties, | |
| 517 IFWL_Widget* pOuter) | |
| 518 : m_pProperties(new CFWL_WidgetImpProperties), | |
| 519 m_pPrivateData(NULL), | |
| 520 m_pDelegate(NULL), | |
| 521 m_pCurDelegate(NULL), | |
| 522 m_pOuter(pOuter), | |
| 523 m_pInterface(NULL), | |
| 524 m_iLock(0) { | |
| 525 *m_pProperties = properties; | |
| 526 m_pWidgetMgr = static_cast<CFWL_WidgetMgr*>(FWL_GetWidgetMgr()); | |
| 527 FXSYS_assert(m_pWidgetMgr != NULL); | |
| 528 } | |
| 529 CFWL_WidgetImp::~CFWL_WidgetImp() { | |
| 530 if (m_pPrivateData) { | |
| 531 delete m_pPrivateData; | |
| 532 m_pPrivateData = NULL; | |
| 533 } | |
| 534 if (m_pProperties) { | |
| 535 delete m_pProperties; | |
| 536 m_pProperties = NULL; | |
| 537 } | |
| 538 } | |
| 539 FX_BOOL CFWL_WidgetImp::IsEnabled() const { | |
| 540 return (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == 0; | |
| 541 } | |
| 542 FX_BOOL CFWL_WidgetImp::IsVisible() const { | |
| 543 return (m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) == 0; | |
| 544 } | |
| 545 FX_BOOL CFWL_WidgetImp::IsActive() const { | |
| 546 return (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) == 0; | |
| 547 } | |
| 548 FX_BOOL CFWL_WidgetImp::IsOverLapper() const { | |
| 549 return (m_pProperties->m_dwStyles & FWL_WGTSTYLE_WindowTypeMask) == | |
| 550 FWL_WGTSTYLE_OverLapper; | |
| 551 } | |
| 552 FX_BOOL CFWL_WidgetImp::IsPopup() const { | |
| 553 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Popup); | |
| 554 } | |
| 555 FX_BOOL CFWL_WidgetImp::IsChild() const { | |
| 556 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Child); | |
| 557 } | |
| 558 FX_BOOL CFWL_WidgetImp::IsLocked() const { | |
| 559 return m_iLock > 0; | |
| 560 } | |
| 561 FX_BOOL CFWL_WidgetImp::IsOffscreen() const { | |
| 562 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Offscreen); | |
| 563 } | |
| 564 FX_BOOL CFWL_WidgetImp::HasBorder() const { | |
| 565 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border); | |
| 566 } | |
| 567 FX_BOOL CFWL_WidgetImp::HasEdge() const { | |
| 568 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_EdgeMask); | |
| 569 } | |
| 570 void CFWL_WidgetImp::GetEdgeRect(CFX_RectF& rtEdge) { | |
| 571 rtEdge = m_pProperties->m_rtWidget; | |
| 572 rtEdge.left = rtEdge.top = 0; | |
| 573 if (HasBorder()) { | |
| 574 FX_FLOAT fCX = GetBorderSize(); | |
| 575 FX_FLOAT fCY = GetBorderSize(FALSE); | |
| 576 rtEdge.Deflate(fCX, fCY); | |
| 577 } | |
| 578 } | |
| 579 FX_FLOAT CFWL_WidgetImp::GetBorderSize(FX_BOOL bCX) { | |
| 580 FX_FLOAT* pfBorder = static_cast<FX_FLOAT*>(GetThemeCapacity( | |
| 581 bCX ? FWL_WGTCAPACITY_CXBorder : FWL_WGTCAPACITY_CYBorder)); | |
| 582 if (!pfBorder) | |
| 583 return 0; | |
| 584 return *pfBorder; | |
| 585 } | |
| 586 FX_FLOAT CFWL_WidgetImp::GetEdgeWidth() { | |
| 587 FX_DWORD dwCapacity = 0; | |
| 588 switch (m_pProperties->m_dwStyles & FWL_WGTSTYLE_EdgeMask) { | |
| 589 case FWL_WGTSTYLE_EdgeFlat: { | |
| 590 dwCapacity = FWL_WGTCAPACITY_EdgeFlat; | |
| 591 break; | |
| 592 } | |
| 593 case FWL_WGTSTYLE_EdgeRaised: { | |
| 594 dwCapacity = FWL_WGTCAPACITY_EdgeRaised; | |
| 595 break; | |
| 596 } | |
| 597 case FWL_WGTSTYLE_EdgeSunken: { | |
| 598 dwCapacity = FWL_WGTCAPACITY_EdgeSunken; | |
| 599 break; | |
| 600 } | |
| 601 } | |
| 602 if (dwCapacity > 0) { | |
| 603 FX_FLOAT* fRet = static_cast<FX_FLOAT*>(GetThemeCapacity(dwCapacity)); | |
| 604 return fRet ? *fRet : 0; | |
| 605 } | |
| 606 return 0; | |
| 607 } | |
| 608 void CFWL_WidgetImp::GetRelativeRect(CFX_RectF& rect) { | |
| 609 rect = m_pProperties->m_rtWidget; | |
| 610 rect.left = rect.top = 0; | |
| 611 } | |
| 612 void* CFWL_WidgetImp::GetThemeCapacity(FX_DWORD dwCapacity) { | |
| 613 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); | |
| 614 if (!pTheme) | |
| 615 return NULL; | |
| 616 CFWL_ThemePart part; | |
| 617 part.m_pWidget = m_pInterface; | |
| 618 return pTheme->GetCapacity(&part, dwCapacity); | |
| 619 } | |
| 620 IFWL_ThemeProvider* CFWL_WidgetImp::GetAvailableTheme() { | |
| 621 if (m_pProperties->m_pThemeProvider) { | |
| 622 return m_pProperties->m_pThemeProvider; | |
| 623 } | |
| 624 IFWL_Widget* pUp = m_pInterface; | |
| 625 do { | |
| 626 FWL_WGTRELATION relation = (pUp->GetStyles() & FWL_WGTSTYLE_Popup) | |
| 627 ? FWL_WGTRELATION_Owner | |
| 628 : FWL_WGTRELATION_Parent; | |
| 629 pUp = m_pWidgetMgr->GetWidget(pUp, relation); | |
| 630 if (pUp) { | |
| 631 IFWL_ThemeProvider* pRet = pUp->GetThemeProvider(); | |
| 632 if (pRet && pRet->IsValidWidget(m_pInterface)) { | |
| 633 return pRet; | |
| 634 } | |
| 635 } | |
| 636 } while (pUp); | |
| 637 return FWL_GetApp()->GetThemeProvider(); | |
| 638 } | |
| 639 CFWL_WidgetImp* CFWL_WidgetImp::GetRootOuter() { | |
| 640 IFWL_Widget* pRet = m_pOuter; | |
| 641 if (!pRet) | |
| 642 return nullptr; | |
| 643 while (IFWL_Widget* pOuter = pRet->GetOuter()) { | |
| 644 pRet = pOuter; | |
| 645 } | |
| 646 return static_cast<CFWL_WidgetImp*>(pRet->GetImpl()); | |
| 647 } | |
| 648 #define FWL_WGT_CalcHeight 2048 | |
| 649 #define FWL_WGT_CalcWidth 2048 | |
| 650 #define FWL_WGT_CalcMultiLineDefWidth 120.0f | |
| 651 CFX_SizeF CFWL_WidgetImp::CalcTextSize(const CFX_WideString& wsText, | |
| 652 IFWL_ThemeProvider* pTheme, | |
| 653 FX_BOOL bMultiLine, | |
| 654 int32_t iLineWidth) { | |
| 655 if (!pTheme) | |
| 656 return CFX_SizeF(); | |
| 657 | |
| 658 CFWL_ThemeText calPart; | |
| 659 calPart.m_pWidget = m_pInterface; | |
| 660 calPart.m_wsText = wsText; | |
| 661 calPart.m_dwTTOStyles = | |
| 662 bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine; | |
| 663 calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; | |
| 664 CFX_RectF rect; | |
| 665 FX_FLOAT fWidth = bMultiLine | |
| 666 ? (iLineWidth > 0 ? (FX_FLOAT)iLineWidth | |
| 667 : FWL_WGT_CalcMultiLineDefWidth) | |
| 668 : FWL_WGT_CalcWidth; | |
| 669 rect.Set(0, 0, fWidth, FWL_WGT_CalcHeight); | |
| 670 pTheme->CalcTextRect(&calPart, rect); | |
| 671 return CFX_SizeF(rect.width, rect.height); | |
| 672 } | |
| 673 void CFWL_WidgetImp::CalcTextRect(const CFX_WideString& wsText, | |
| 674 IFWL_ThemeProvider* pTheme, | |
| 675 FX_DWORD dwTTOStyles, | |
| 676 int32_t iTTOAlign, | |
| 677 CFX_RectF& rect) { | |
| 678 CFWL_ThemeText calPart; | |
| 679 calPart.m_pWidget = m_pInterface; | |
| 680 calPart.m_wsText = wsText; | |
| 681 calPart.m_dwTTOStyles = dwTTOStyles; | |
| 682 calPart.m_iTTOAlign = iTTOAlign; | |
| 683 pTheme->CalcTextRect(&calPart, rect); | |
| 684 } | |
| 685 void CFWL_WidgetImp::SetFocus(FX_BOOL bFocus) { | |
| 686 if (m_pWidgetMgr->IsFormDisabled()) | |
| 687 return; | |
| 688 IFWL_NoteThread* pThread = GetOwnerThread(); | |
| 689 if (!pThread) | |
| 690 return; | |
| 691 CFWL_NoteDriver* pDriver = | |
| 692 static_cast<CFWL_NoteDriver*>(pThread->GetNoteDriver()); | |
| 693 if (!pDriver) | |
| 694 return; | |
| 695 IFWL_Widget* curFocus = pDriver->GetFocus(); | |
| 696 if (bFocus && curFocus != m_pInterface) { | |
| 697 pDriver->SetFocus(m_pInterface); | |
| 698 } else if (!bFocus && curFocus == m_pInterface) { | |
| 699 pDriver->SetFocus(NULL); | |
| 700 } | |
| 701 } | |
| 702 void CFWL_WidgetImp::SetGrab(FX_BOOL bSet) { | |
| 703 IFWL_NoteThread* pThread = GetOwnerThread(); | |
| 704 if (!pThread) | |
| 705 return; | |
| 706 CFWL_NoteDriver* pDriver = | |
| 707 static_cast<CFWL_NoteDriver*>(pThread->GetNoteDriver()); | |
| 708 pDriver->SetGrab(m_pInterface, bSet); | |
| 709 } | |
| 710 FX_BOOL CFWL_WidgetImp::GetPopupPos(FX_FLOAT fMinHeight, | |
| 711 FX_FLOAT fMaxHeight, | |
| 712 const CFX_RectF& rtAnchor, | |
| 713 CFX_RectF& rtPopup) { | |
| 714 if (GetClassID() == FWL_CLASSHASH_Menu) { | |
| 715 return GetPopupPosMenu(fMinHeight, fMaxHeight, rtAnchor, rtPopup); | |
| 716 } else { | |
| 717 if (GetClassID() == FWL_CLASSHASH_ComboBox) { | |
| 718 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 719 return m_pWidgetMgr->GetAdapterPopupPos(m_pInterface, fMinHeight, | |
| 720 fMaxHeight, rtAnchor, rtPopup); | |
| 721 } else { | |
| 722 return GetPopupPosComboBox(fMinHeight, fMaxHeight, rtAnchor, rtPopup); | |
| 723 } | |
| 724 } else if (GetClassID() == FWL_CLASSHASH_DateTimePicker && | |
| 725 m_pWidgetMgr->IsFormDisabled()) { | |
| 726 return m_pWidgetMgr->GetAdapterPopupPos(m_pInterface, fMinHeight, | |
| 727 fMaxHeight, rtAnchor, rtPopup); | |
| 728 } else { | |
| 729 return GetPopupPosGeneral(fMinHeight, fMaxHeight, rtAnchor, rtPopup); | |
| 730 } | |
| 731 } | |
| 732 return FALSE; | |
| 733 } | |
| 734 FX_BOOL CFWL_WidgetImp::GetPopupPosMenu(FX_FLOAT fMinHeight, | |
| 735 FX_FLOAT fMaxHeight, | |
| 736 const CFX_RectF& rtAnchor, | |
| 737 CFX_RectF& rtPopup) { | |
| 738 FX_FLOAT fx = 0; | |
| 739 FX_FLOAT fy = 0; | |
| 740 FX_FLOAT fScreenWidth = 0; | |
| 741 FX_FLOAT fScreenHeight = 0; | |
| 742 GetScreenSize(fScreenWidth, fScreenHeight); | |
| 743 if (GetStylesEx() & FWL_STYLEEXT_MNU_Vert) { | |
| 744 FX_BOOL bLeft = m_pProperties->m_rtWidget.left < 0; | |
| 745 FX_FLOAT fRight = rtAnchor.right() + rtPopup.width; | |
| 746 TransformTo(NULL, fx, fy); | |
| 747 if (fRight + fx > fScreenWidth || bLeft) { | |
| 748 rtPopup.Set(rtAnchor.left - rtPopup.width, rtAnchor.top, rtPopup.width, | |
| 749 rtPopup.height); | |
| 750 } else { | |
| 751 rtPopup.Set(rtAnchor.right(), rtAnchor.top, rtPopup.width, | |
| 752 rtPopup.height); | |
| 753 } | |
| 754 } else { | |
| 755 FX_FLOAT fBottom = rtAnchor.bottom() + rtPopup.height; | |
| 756 TransformTo(NULL, fx, fy); | |
| 757 if (fBottom + fy > fScreenHeight) { | |
| 758 rtPopup.Set(rtAnchor.left, rtAnchor.top - rtPopup.height, rtPopup.width, | |
| 759 rtPopup.height); | |
| 760 } else { | |
| 761 rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), rtPopup.width, | |
| 762 rtPopup.height); | |
| 763 } | |
| 764 } | |
| 765 rtPopup.Offset(fx, fy); | |
| 766 return TRUE; | |
| 767 } | |
| 768 FX_BOOL CFWL_WidgetImp::GetPopupPosComboBox(FX_FLOAT fMinHeight, | |
| 769 FX_FLOAT fMaxHeight, | |
| 770 const CFX_RectF& rtAnchor, | |
| 771 CFX_RectF& rtPopup) { | |
| 772 FX_FLOAT fx = 0; | |
| 773 FX_FLOAT fy = 0; | |
| 774 FX_FLOAT fScreenWidth = 0; | |
| 775 FX_FLOAT fScreenHeight = 0; | |
| 776 GetScreenSize(fScreenWidth, fScreenHeight); | |
| 777 FX_FLOAT fPopHeight = rtPopup.height; | |
| 778 if (rtPopup.height > fMaxHeight) { | |
| 779 fPopHeight = fMaxHeight; | |
| 780 } else if (rtPopup.height < fMinHeight) { | |
| 781 fPopHeight = fMinHeight; | |
| 782 } | |
| 783 FX_FLOAT fWidth = std::max(rtAnchor.width, rtPopup.width); | |
| 784 FX_FLOAT fBottom = rtAnchor.bottom() + fPopHeight; | |
| 785 TransformTo(NULL, fx, fy); | |
| 786 if (fBottom + fy > fScreenHeight) { | |
| 787 rtPopup.Set(rtAnchor.left, rtAnchor.top - fPopHeight, fWidth, fPopHeight); | |
| 788 } else { | |
| 789 rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), fWidth, fPopHeight); | |
| 790 } | |
| 791 rtPopup.Offset(fx, fy); | |
| 792 return TRUE; | |
| 793 } | |
| 794 FX_BOOL CFWL_WidgetImp::GetPopupPosGeneral(FX_FLOAT fMinHeight, | |
| 795 FX_FLOAT fMaxHeight, | |
| 796 const CFX_RectF& rtAnchor, | |
| 797 CFX_RectF& rtPopup) { | |
| 798 FX_FLOAT fx = 0; | |
| 799 FX_FLOAT fy = 0; | |
| 800 FX_FLOAT fScreenWidth = 0; | |
| 801 FX_FLOAT fScreenHeight = 0; | |
| 802 GetScreenSize(fScreenWidth, fScreenHeight); | |
| 803 TransformTo(NULL, fx, fy); | |
| 804 if (rtAnchor.bottom() + fy > fScreenHeight) { | |
| 805 rtPopup.Set(rtAnchor.left, rtAnchor.top - rtPopup.height, rtPopup.width, | |
| 806 rtPopup.height); | |
| 807 } else { | |
| 808 rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), rtPopup.width, | |
| 809 rtPopup.height); | |
| 810 } | |
| 811 rtPopup.Offset(fx, fy); | |
| 812 return TRUE; | |
| 813 } | |
| 814 FX_BOOL CFWL_WidgetImp::GetScreenSize(FX_FLOAT& fx, FX_FLOAT& fy) { | |
| 815 return FALSE; | |
| 816 } | |
| 817 void CFWL_WidgetImp::RegisterEventTarget(IFWL_Widget* pEventSource, | |
| 818 FX_DWORD dwFilter) { | |
| 819 IFWL_NoteThread* pThread = GetOwnerThread(); | |
| 820 if (!pThread) | |
| 821 return; | |
| 822 IFWL_NoteDriver* pNoteDriver = pThread->GetNoteDriver(); | |
| 823 if (!pNoteDriver) | |
| 824 return; | |
| 825 pNoteDriver->RegisterEventTarget(m_pInterface, pEventSource, dwFilter); | |
| 826 } | |
| 827 void CFWL_WidgetImp::UnregisterEventTarget() { | |
| 828 IFWL_NoteThread* pThread = GetOwnerThread(); | |
| 829 if (!pThread) | |
| 830 return; | |
| 831 IFWL_NoteDriver* pNoteDriver = pThread->GetNoteDriver(); | |
| 832 if (!pNoteDriver) | |
| 833 return; | |
| 834 pNoteDriver->UnregisterEventTarget(m_pInterface); | |
| 835 } | |
| 836 void CFWL_WidgetImp::DispatchKeyEvent(CFWL_MsgKey* pNote) { | |
| 837 if (!pNote) | |
| 838 return; | |
| 839 CFWL_EvtKey* pEvent = new CFWL_EvtKey; | |
| 840 pEvent->m_pSrcTarget = m_pInterface; | |
| 841 pEvent->m_dwCmd = pNote->m_dwCmd; | |
| 842 pEvent->m_dwKeyCode = pNote->m_dwKeyCode; | |
| 843 pEvent->m_dwFlags = pNote->m_dwFlags; | |
| 844 DispatchEvent(pEvent); | |
| 845 pEvent->Release(); | |
| 846 } | |
| 847 void CFWL_WidgetImp::DispatchEvent(CFWL_Event* pEvent) { | |
| 848 if (m_pOuter) { | |
| 849 IFWL_WidgetDelegate* pDelegate = m_pOuter->SetDelegate(NULL); | |
| 850 pDelegate->OnProcessEvent(pEvent); | |
| 851 return; | |
| 852 } | |
| 853 IFWL_NoteThread* pThread = GetOwnerThread(); | |
| 854 if (!pThread) | |
| 855 return; | |
| 856 IFWL_NoteDriver* pNoteDriver = pThread->GetNoteDriver(); | |
| 857 if (!pNoteDriver) | |
| 858 return; | |
| 859 pNoteDriver->SendNote(pEvent); | |
| 860 } | |
| 861 void CFWL_WidgetImp::Repaint(const CFX_RectF* pRect) { | |
| 862 if (pRect) { | |
| 863 m_pWidgetMgr->RepaintWidget(m_pInterface, pRect); | |
| 864 return; | |
| 865 } | |
| 866 CFX_RectF rect; | |
| 867 rect = m_pProperties->m_rtWidget; | |
| 868 rect.left = rect.top = 0; | |
| 869 m_pWidgetMgr->RepaintWidget(m_pInterface, &rect); | |
| 870 } | |
| 871 void CFWL_WidgetImp::DrawBackground(CFX_Graphics* pGraphics, | |
| 872 int32_t iPartBk, | |
| 873 IFWL_ThemeProvider* pTheme, | |
| 874 const CFX_Matrix* pMatrix) { | |
| 875 CFX_RectF rtRelative; | |
| 876 GetRelativeRect(rtRelative); | |
| 877 CFWL_ThemeBackground param; | |
| 878 param.m_pWidget = m_pInterface; | |
| 879 param.m_iPart = iPartBk; | |
| 880 param.m_pGraphics = pGraphics; | |
| 881 if (pMatrix) { | |
| 882 param.m_matrix.Concat(*pMatrix, TRUE); | |
| 883 } | |
| 884 param.m_rtPart = rtRelative; | |
| 885 pTheme->DrawBackground(¶m); | |
| 886 } | |
| 887 void CFWL_WidgetImp::DrawBorder(CFX_Graphics* pGraphics, | |
| 888 int32_t iPartBorder, | |
| 889 IFWL_ThemeProvider* pTheme, | |
| 890 const CFX_Matrix* pMatrix) { | |
| 891 CFX_RectF rtRelative; | |
| 892 GetRelativeRect(rtRelative); | |
| 893 CFWL_ThemeBackground param; | |
| 894 param.m_pWidget = m_pInterface; | |
| 895 param.m_iPart = iPartBorder; | |
| 896 param.m_pGraphics = pGraphics; | |
| 897 if (pMatrix) { | |
| 898 param.m_matrix.Concat(*pMatrix, TRUE); | |
| 899 } | |
| 900 param.m_rtPart = rtRelative; | |
| 901 pTheme->DrawBackground(¶m); | |
| 902 } | |
| 903 void CFWL_WidgetImp::DrawEdge(CFX_Graphics* pGraphics, | |
| 904 int32_t iPartEdge, | |
| 905 IFWL_ThemeProvider* pTheme, | |
| 906 const CFX_Matrix* pMatrix) { | |
| 907 CFX_RectF rtEdge; | |
| 908 GetEdgeRect(rtEdge); | |
| 909 CFWL_ThemeBackground param; | |
| 910 param.m_pWidget = m_pInterface; | |
| 911 param.m_iPart = iPartEdge; | |
| 912 param.m_pGraphics = pGraphics; | |
| 913 if (pMatrix) { | |
| 914 param.m_matrix.Concat(*pMatrix, TRUE); | |
| 915 } | |
| 916 param.m_rtPart = rtEdge; | |
| 917 pTheme->DrawBackground(¶m); | |
| 918 } | |
| 919 void CFWL_WidgetImp::NotifyDriver() { | |
| 920 IFWL_NoteThread* pThread = GetOwnerThread(); | |
| 921 if (!pThread) | |
| 922 return; | |
| 923 CFWL_NoteDriver* pDriver = | |
| 924 static_cast<CFWL_NoteDriver*>(pThread->GetNoteDriver()); | |
| 925 if (!pDriver) | |
| 926 return; | |
| 927 pDriver->NotifyTargetDestroy(m_pInterface); | |
| 928 } | |
| 929 CFX_SizeF CFWL_WidgetImp::GetOffsetFromParent(IFWL_Widget* pParent) { | |
| 930 if (pParent == GetInterface()) | |
| 931 return CFX_SizeF(); | |
| 932 | |
| 933 IFWL_WidgetMgr* pWidgetMgr = FWL_GetWidgetMgr(); | |
| 934 if (!pWidgetMgr) | |
| 935 return CFX_SizeF(); | |
| 936 | |
| 937 CFX_SizeF szRet(m_pProperties->m_rtWidget.left, | |
| 938 m_pProperties->m_rtWidget.top); | |
| 939 | |
| 940 IFWL_Widget* pDstWidget = GetParent(); | |
| 941 while (pDstWidget && pDstWidget != pParent) { | |
| 942 CFX_RectF rtDst; | |
| 943 pDstWidget->GetWidgetRect(rtDst); | |
| 944 szRet += CFX_SizeF(rtDst.left, rtDst.top); | |
| 945 pDstWidget = pWidgetMgr->GetWidget(pDstWidget, FWL_WGTRELATION_Parent); | |
| 946 } | |
| 947 return szRet; | |
| 948 } | |
| 949 FX_BOOL CFWL_WidgetImp::IsParent(IFWL_Widget* pParent) { | |
| 950 IFWL_Widget* pUpWidget = GetParent(); | |
| 951 while (pUpWidget) { | |
| 952 if (pUpWidget == pParent) | |
| 953 return TRUE; | |
| 954 pUpWidget = pUpWidget->GetParent(); | |
| 955 } | |
| 956 return FALSE; | |
| 957 } | |
| 958 CFWL_WidgetImpDelegate::CFWL_WidgetImpDelegate() {} | |
| 959 int32_t CFWL_WidgetImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 960 if (!pMessage->m_pDstTarget) | |
| 961 return 0; | |
| 962 CFWL_WidgetImp* pWidget = | |
| 963 static_cast<CFWL_WidgetImp*>(pMessage->m_pDstTarget->GetImpl()); | |
| 964 FX_DWORD dwMsgCode = pMessage->GetClassID(); | |
| 965 switch (dwMsgCode) { | |
| 966 case FWL_MSGHASH_Mouse: { | |
| 967 CFWL_MsgMouse* pMsgMouse = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 968 CFWL_EvtMouse evt; | |
| 969 evt.m_pSrcTarget = pWidget->m_pInterface; | |
| 970 evt.m_pDstTarget = pWidget->m_pInterface; | |
| 971 evt.m_dwCmd = pMsgMouse->m_dwCmd; | |
| 972 evt.m_dwFlags = pMsgMouse->m_dwFlags; | |
| 973 evt.m_fx = pMsgMouse->m_fx; | |
| 974 evt.m_fy = pMsgMouse->m_fy; | |
| 975 pWidget->DispatchEvent(&evt); | |
| 976 break; | |
| 977 } | |
| 978 case FWL_MSGHASH_MouseWheel: { | |
| 979 CFWL_MsgMouseWheel* pMsgMouseWheel = | |
| 980 static_cast<CFWL_MsgMouseWheel*>(pMessage); | |
| 981 CFWL_EvtMouseWheel evt; | |
| 982 evt.m_pSrcTarget = pWidget->m_pInterface; | |
| 983 evt.m_pDstTarget = pWidget->m_pInterface; | |
| 984 evt.m_dwFlags = pMsgMouseWheel->m_dwFlags; | |
| 985 evt.m_fDeltaX = pMsgMouseWheel->m_fDeltaX; | |
| 986 evt.m_fDeltaY = pMsgMouseWheel->m_fDeltaY; | |
| 987 evt.m_fx = pMsgMouseWheel->m_fx; | |
| 988 evt.m_fy = pMsgMouseWheel->m_fy; | |
| 989 pWidget->DispatchEvent(&evt); | |
| 990 break; | |
| 991 } | |
| 992 case FWL_MSGHASH_Key: { | |
| 993 CFWL_MsgKey* pMsgKey = static_cast<CFWL_MsgKey*>(pMessage); | |
| 994 CFWL_EvtKey evt; | |
| 995 evt.m_pSrcTarget = pWidget->m_pInterface; | |
| 996 evt.m_pDstTarget = pWidget->m_pInterface; | |
| 997 evt.m_dwKeyCode = pMsgKey->m_dwKeyCode; | |
| 998 evt.m_dwFlags = pMsgKey->m_dwFlags; | |
| 999 evt.m_dwCmd = pMsgKey->m_dwCmd; | |
| 1000 pWidget->DispatchEvent(&evt); | |
| 1001 break; | |
| 1002 } | |
| 1003 case FWL_MSGHASH_SetFocus: { | |
| 1004 CFWL_MsgSetFocus* pMsgSetFocus = static_cast<CFWL_MsgSetFocus*>(pMessage); | |
| 1005 CFWL_EvtSetFocus evt; | |
| 1006 evt.m_pSrcTarget = pMsgSetFocus->m_pDstTarget; | |
| 1007 evt.m_pDstTarget = pMsgSetFocus->m_pDstTarget; | |
| 1008 evt.m_pSetFocus = pWidget->m_pInterface; | |
| 1009 pWidget->DispatchEvent(&evt); | |
| 1010 break; | |
| 1011 } | |
| 1012 case FWL_MSGHASH_KillFocus: { | |
| 1013 CFWL_MsgKillFocus* pMsgKillFocus = | |
| 1014 static_cast<CFWL_MsgKillFocus*>(pMessage); | |
| 1015 CFWL_EvtKillFocus evt; | |
| 1016 evt.m_pSrcTarget = pMsgKillFocus->m_pDstTarget; | |
| 1017 evt.m_pDstTarget = pMsgKillFocus->m_pDstTarget; | |
| 1018 evt.m_pKillFocus = pWidget->m_pInterface; | |
| 1019 pWidget->DispatchEvent(&evt); | |
| 1020 break; | |
| 1021 } | |
| 1022 default: {} | |
| 1023 } | |
| 1024 return 1; | |
| 1025 } | |
| 1026 FWL_ERR CFWL_WidgetImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { | |
| 1027 return FWL_ERR_Succeeded; | |
| 1028 } | |
| 1029 FWL_ERR CFWL_WidgetImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 1030 const CFX_Matrix* pMatrix) { | |
| 1031 CFWL_EvtDraw evt; | |
| 1032 evt.m_pGraphics = pGraphics; | |
| 1033 return FWL_ERR_Succeeded; | |
| 1034 } | |
| 1035 class CFWL_CustomImp : public CFWL_WidgetImp { | |
| 1036 public: | |
| 1037 CFWL_CustomImp(const CFWL_WidgetImpProperties& properties, | |
| 1038 IFWL_Widget* pOuter); | |
| 1039 virtual FWL_ERR GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE); | |
| 1040 virtual FWL_ERR Update(); | |
| 1041 virtual FWL_ERR SetProxy(IFWL_Proxy* pProxy); | |
| 1042 | |
| 1043 protected: | |
| 1044 IFWL_Proxy* m_pProxy; | |
| 1045 }; | |
| 1046 CFWL_CustomImp::CFWL_CustomImp(const CFWL_WidgetImpProperties& properties, | |
| 1047 IFWL_Widget* pOuter) | |
| 1048 : CFWL_WidgetImp(properties, pOuter), m_pProxy(NULL) {} | |
| 1049 FWL_ERR CFWL_CustomImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
| 1050 if (m_pProxy && | |
| 1051 (m_pProxy->GetWidgetRect(rect, bAutoSize) == FWL_ERR_Succeeded)) { | |
| 1052 return FWL_ERR_Succeeded; | |
| 1053 } | |
| 1054 return CFWL_WidgetImp::GetWidgetRect(rect, bAutoSize); | |
| 1055 } | |
| 1056 FWL_ERR CFWL_CustomImp::Update() { | |
| 1057 if (m_pProxy) { | |
| 1058 return m_pProxy->Update(); | |
| 1059 } | |
| 1060 return CFWL_WidgetImp::Update(); | |
| 1061 } | |
| 1062 FWL_ERR CFWL_CustomImp::SetProxy(IFWL_Proxy* pProxy) { | |
| 1063 m_pProxy = pProxy; | |
| 1064 return FWL_ERR_Succeeded; | |
| 1065 } | |
| 1066 | |
| 1067 // static | |
| 1068 IFWL_Custom* IFWL_Custom::Create(const CFWL_WidgetImpProperties& properties, | |
| 1069 IFWL_Widget* pOuter) { | |
| 1070 IFWL_Custom* pCustom = new IFWL_Custom; | |
| 1071 CFWL_CustomImp* pCustomImpl = new CFWL_CustomImp(properties, pOuter); | |
| 1072 pCustom->SetImpl(pCustomImpl); | |
| 1073 pCustomImpl->SetInterface(pCustom); | |
| 1074 return pCustom; | |
| 1075 } | |
| 1076 IFWL_Custom::IFWL_Custom() {} | |
| 1077 FWL_ERR IFWL_Custom::SetProxy(IFWL_Proxy* pProxy) { | |
| 1078 return static_cast<CFWL_CustomImp*>(GetImpl())->SetProxy(pProxy); | |
| 1079 } | |
| 1080 void FWL_SetWidgetRect(IFWL_Widget* widget, const CFX_RectF& rect) { | |
| 1081 static_cast<CFWL_WidgetImp*>(widget->GetImpl())->m_pProperties->m_rtWidget = | |
| 1082 rect; | |
| 1083 } | |
| 1084 void FWL_SetWidgetStates(IFWL_Widget* widget, FX_DWORD dwStates) { | |
| 1085 static_cast<CFWL_WidgetImp*>(widget->GetImpl())->m_pProperties->m_dwStates = | |
| 1086 dwStates; | |
| 1087 } | |
| 1088 void FWL_SetWidgetStyles(IFWL_Widget* widget, FX_DWORD dwStyles) { | |
| 1089 static_cast<CFWL_WidgetImp*>(widget->GetImpl())->m_pProperties->m_dwStyles = | |
| 1090 dwStyles; | |
| 1091 } | |
| 1092 FWL_ERR FWL_EnabelWidget(IFWL_Widget* widget, FX_BOOL bEnable) { | |
| 1093 widget->SetStates(FWL_WGTSTATE_Disabled, !bEnable); | |
| 1094 IFWL_WidgetMgr* widgetMgr = FWL_GetWidgetMgr(); | |
| 1095 IFWL_Widget* child = widgetMgr->GetWidget(widget, FWL_WGTRELATION_FirstChild); | |
| 1096 while (child) { | |
| 1097 FWL_EnabelWidget(child, bEnable); | |
| 1098 child = widgetMgr->GetWidget(child, FWL_WGTRELATION_NextSibling); | |
| 1099 } | |
| 1100 return FWL_ERR_Succeeded; | |
| 1101 } | |
| OLD | NEW |