| 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/fwl/core/fwl_widgetimp.h" | |
| 8 | |
| 9 #include <algorithm> | |
| 10 | |
| 11 #include "xfa/fde/tto/fde_textout.h" | |
| 12 #include "xfa/fwl/basewidget/ifwl_combobox.h" | |
| 13 #include "xfa/fwl/core/cfwl_message.h" | |
| 14 #include "xfa/fwl/core/cfwl_themebackground.h" | |
| 15 #include "xfa/fwl/core/cfwl_themepart.h" | |
| 16 #include "xfa/fwl/core/cfwl_themetext.h" | |
| 17 #include "xfa/fwl/core/cfwl_widgetmgr.h" | |
| 18 #include "xfa/fwl/core/fwl_noteimp.h" | |
| 19 #include "xfa/fwl/core/ifwl_app.h" | |
| 20 #include "xfa/fwl/core/ifwl_form.h" | |
| 21 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
| 22 #include "xfa/fwl/core/ifwl_widget.h" | |
| 23 #include "xfa/fxfa/xfa_ffapp.h" | |
| 24 | |
| 25 #define FWL_STYLEEXT_MNU_Vert (1L << 0) | |
| 26 | |
| 27 IFWL_Widget::IFWL_Widget() {} | |
| 28 | |
| 29 IFWL_Widget::~IFWL_Widget() {} | |
| 30 | |
| 31 FWL_Error IFWL_Widget::GetClassName(CFX_WideString& wsClass) const { | |
| 32 return m_pImpl->GetClassName(wsClass); | |
| 33 } | |
| 34 | |
| 35 FWL_Type IFWL_Widget::GetClassID() const { | |
| 36 return m_pImpl->GetClassID(); | |
| 37 } | |
| 38 | |
| 39 FX_BOOL IFWL_Widget::IsInstance(const CFX_WideStringC& wsClass) const { | |
| 40 return m_pImpl->IsInstance(wsClass); | |
| 41 } | |
| 42 | |
| 43 FWL_Error IFWL_Widget::Initialize() { | |
| 44 return m_pImpl->Initialize(); | |
| 45 } | |
| 46 | |
| 47 FWL_Error IFWL_Widget::Finalize() { | |
| 48 return m_pImpl->Finalize(); | |
| 49 } | |
| 50 | |
| 51 FWL_Error IFWL_Widget::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
| 52 return GetImpl()->GetWidgetRect(rect, bAutoSize); | |
| 53 } | |
| 54 FWL_Error IFWL_Widget::GetGlobalRect(CFX_RectF& rect) { | |
| 55 return GetImpl()->GetGlobalRect(rect); | |
| 56 } | |
| 57 FWL_Error IFWL_Widget::SetWidgetRect(const CFX_RectF& rect) { | |
| 58 return GetImpl()->SetWidgetRect(rect); | |
| 59 } | |
| 60 FWL_Error IFWL_Widget::GetClientRect(CFX_RectF& rect) { | |
| 61 return GetImpl()->GetClientRect(rect); | |
| 62 } | |
| 63 IFWL_Widget* IFWL_Widget::GetParent() { | |
| 64 return GetImpl()->GetParent(); | |
| 65 } | |
| 66 FWL_Error IFWL_Widget::SetParent(IFWL_Widget* pParent) { | |
| 67 return GetImpl()->SetParent(pParent); | |
| 68 } | |
| 69 IFWL_Widget* IFWL_Widget::GetOwner() { | |
| 70 return GetImpl()->GetOwner(); | |
| 71 } | |
| 72 FWL_Error IFWL_Widget::SetOwner(IFWL_Widget* pOwner) { | |
| 73 return GetImpl()->SetOwner(pOwner); | |
| 74 } | |
| 75 IFWL_Widget* IFWL_Widget::GetOuter() { | |
| 76 return GetImpl()->GetOuter(); | |
| 77 } | |
| 78 uint32_t IFWL_Widget::GetStyles() { | |
| 79 return GetImpl()->GetStyles(); | |
| 80 } | |
| 81 FWL_Error IFWL_Widget::ModifyStyles(uint32_t dwStylesAdded, | |
| 82 uint32_t dwStylesRemoved) { | |
| 83 return GetImpl()->ModifyStyles(dwStylesAdded, dwStylesRemoved); | |
| 84 } | |
| 85 uint32_t IFWL_Widget::GetStylesEx() { | |
| 86 return GetImpl()->GetStylesEx(); | |
| 87 } | |
| 88 FWL_Error IFWL_Widget::ModifyStylesEx(uint32_t dwStylesExAdded, | |
| 89 uint32_t dwStylesExRemoved) { | |
| 90 return GetImpl()->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | |
| 91 } | |
| 92 uint32_t IFWL_Widget::GetStates() { | |
| 93 return GetImpl()->GetStates(); | |
| 94 } | |
| 95 void IFWL_Widget::SetStates(uint32_t dwStates, FX_BOOL bSet) { | |
| 96 GetImpl()->SetStates(dwStates, bSet); | |
| 97 } | |
| 98 | |
| 99 uint32_t IFWL_Widget::GetEventKey() const { | |
| 100 return GetImpl()->GetEventKey(); | |
| 101 } | |
| 102 | |
| 103 void IFWL_Widget::SetEventKey(uint32_t key) { | |
| 104 GetImpl()->SetEventKey(key); | |
| 105 } | |
| 106 | |
| 107 void* IFWL_Widget::GetLayoutItem() const { | |
| 108 return GetImpl()->GetLayoutItem(); | |
| 109 } | |
| 110 | |
| 111 void IFWL_Widget::SetLayoutItem(void* pItem) { | |
| 112 GetImpl()->SetLayoutItem(pItem); | |
| 113 } | |
| 114 | |
| 115 void* IFWL_Widget::GetAssociateWidget() const { | |
| 116 return GetImpl()->GetAssociateWidget(); | |
| 117 } | |
| 118 | |
| 119 void IFWL_Widget::SetAssociateWidget(void* pAssociate) { | |
| 120 GetImpl()->SetAssociateWidget(pAssociate); | |
| 121 } | |
| 122 | |
| 123 FWL_Error IFWL_Widget::Update() { | |
| 124 return GetImpl()->Update(); | |
| 125 } | |
| 126 FWL_Error IFWL_Widget::LockUpdate() { | |
| 127 return GetImpl()->LockUpdate(); | |
| 128 } | |
| 129 FWL_Error IFWL_Widget::UnlockUpdate() { | |
| 130 return GetImpl()->UnlockUpdate(); | |
| 131 } | |
| 132 FWL_WidgetHit IFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | |
| 133 return GetImpl()->HitTest(fx, fy); | |
| 134 } | |
| 135 FWL_Error IFWL_Widget::TransformTo(IFWL_Widget* pWidget, | |
| 136 FX_FLOAT& fx, | |
| 137 FX_FLOAT& fy) { | |
| 138 return GetImpl()->TransformTo(pWidget, fx, fy); | |
| 139 } | |
| 140 FWL_Error IFWL_Widget::TransformTo(IFWL_Widget* pWidget, CFX_RectF& rt) { | |
| 141 return GetImpl()->TransformTo(pWidget, rt); | |
| 142 } | |
| 143 FWL_Error IFWL_Widget::GetMatrix(CFX_Matrix& matrix, FX_BOOL bGlobal) { | |
| 144 return GetImpl()->GetMatrix(matrix, bGlobal); | |
| 145 } | |
| 146 FWL_Error IFWL_Widget::SetMatrix(const CFX_Matrix& matrix) { | |
| 147 return GetImpl()->SetMatrix(matrix); | |
| 148 } | |
| 149 FWL_Error IFWL_Widget::DrawWidget(CFX_Graphics* pGraphics, | |
| 150 const CFX_Matrix* pMatrix) { | |
| 151 return GetImpl()->DrawWidget(pGraphics, pMatrix); | |
| 152 } | |
| 153 IFWL_ThemeProvider* IFWL_Widget::GetThemeProvider() { | |
| 154 return GetImpl()->GetThemeProvider(); | |
| 155 } | |
| 156 FWL_Error IFWL_Widget::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { | |
| 157 return GetImpl()->SetThemeProvider(pThemeProvider); | |
| 158 } | |
| 159 IFWL_WidgetDelegate* IFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { | |
| 160 return GetImpl()->SetDelegate(pDelegate); | |
| 161 } | |
| 162 IFWL_App* IFWL_Widget::GetOwnerApp() const { | |
| 163 return GetImpl()->GetOwnerApp(); | |
| 164 } | |
| 165 CFX_SizeF IFWL_Widget::GetOffsetFromParent(IFWL_Widget* pParent) { | |
| 166 return GetImpl()->GetOffsetFromParent(pParent); | |
| 167 } | |
| 168 | |
| 169 FWL_Error CFWL_WidgetImp::Initialize() { | |
| 170 IFWL_App* pApp = FWL_GetApp(); | |
| 171 if (!pApp) | |
| 172 return FWL_Error::Indefinite; | |
| 173 | |
| 174 CXFA_FFApp* pAdapter = pApp->GetAdapterNative(); | |
| 175 if (!pAdapter) | |
| 176 return FWL_Error::Indefinite; | |
| 177 | |
| 178 SetOwnerApp(FWL_GetApp()); | |
| 179 | |
| 180 IFWL_Widget* pParent = m_pProperties->m_pParent; | |
| 181 m_pWidgetMgr->InsertWidget(pParent, m_pInterface); | |
| 182 if (!IsChild()) { | |
| 183 IFWL_Widget* pOwner = m_pProperties->m_pOwner; | |
| 184 if (pOwner) | |
| 185 m_pWidgetMgr->SetOwner(pOwner, m_pInterface); | |
| 186 } | |
| 187 return FWL_Error::Succeeded; | |
| 188 } | |
| 189 | |
| 190 FWL_Error CFWL_WidgetImp::Finalize() { | |
| 191 NotifyDriver(); | |
| 192 m_pWidgetMgr->RemoveWidget(m_pInterface); | |
| 193 return FWL_Error::Succeeded; | |
| 194 } | |
| 195 | |
| 196 FWL_Error CFWL_WidgetImp::GetClassName(CFX_WideString& wsClass) const { | |
| 197 wsClass.clear(); | |
| 198 return FWL_Error::Succeeded; | |
| 199 } | |
| 200 | |
| 201 FX_BOOL CFWL_WidgetImp::IsInstance(const CFX_WideStringC& wsClass) const { | |
| 202 return FALSE; | |
| 203 } | |
| 204 | |
| 205 FWL_Error CFWL_WidgetImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
| 206 if (bAutoSize) { | |
| 207 if (HasEdge()) { | |
| 208 FX_FLOAT fEdge = GetEdgeWidth(); | |
| 209 rect.Inflate(fEdge, fEdge); | |
| 210 } | |
| 211 if (HasBorder()) { | |
| 212 FX_FLOAT fBorder = GetBorderSize(); | |
| 213 rect.Inflate(fBorder, fBorder); | |
| 214 } | |
| 215 } else { | |
| 216 rect = m_pProperties->m_rtWidget; | |
| 217 } | |
| 218 return FWL_Error::Succeeded; | |
| 219 } | |
| 220 | |
| 221 FWL_Error CFWL_WidgetImp::GetGlobalRect(CFX_RectF& rect) { | |
| 222 IFWL_Widget* pForm = m_pWidgetMgr->GetSystemFormWidget(m_pInterface); | |
| 223 if (!pForm) | |
| 224 return FWL_Error::Indefinite; | |
| 225 | |
| 226 rect.Set(0, 0, m_pProperties->m_rtWidget.width, | |
| 227 m_pProperties->m_rtWidget.height); | |
| 228 if (pForm == m_pInterface) | |
| 229 return FWL_Error::Succeeded; | |
| 230 | |
| 231 return TransformTo(pForm, rect); | |
| 232 } | |
| 233 | |
| 234 FWL_Error CFWL_WidgetImp::SetWidgetRect(const CFX_RectF& rect) { | |
| 235 CFX_RectF rtOld = m_pProperties->m_rtWidget; | |
| 236 m_pProperties->m_rtWidget = rect; | |
| 237 if (IsChild()) { | |
| 238 if (FXSYS_fabs(rtOld.width - rect.width) > 0.5f || | |
| 239 FXSYS_fabs(rtOld.height - rect.height) > 0.5f) { | |
| 240 CFWL_EvtSizeChanged ev; | |
| 241 ev.m_pSrcTarget = m_pInterface; | |
| 242 ev.m_rtOld = rtOld; | |
| 243 ev.m_rtNew = rect; | |
| 244 IFWL_WidgetDelegate* pDelegate = SetDelegate(nullptr); | |
| 245 if (pDelegate) { | |
| 246 pDelegate->OnProcessEvent(&ev); | |
| 247 } | |
| 248 } | |
| 249 return FWL_Error::Succeeded; | |
| 250 } | |
| 251 m_pWidgetMgr->SetWidgetRect_Native(m_pInterface, rect); | |
| 252 return FWL_Error::Succeeded; | |
| 253 } | |
| 254 FWL_Error CFWL_WidgetImp::GetClientRect(CFX_RectF& rect) { | |
| 255 GetEdgeRect(rect); | |
| 256 if (HasEdge()) { | |
| 257 FX_FLOAT fEdge = GetEdgeWidth(); | |
| 258 rect.Deflate(fEdge, fEdge); | |
| 259 } | |
| 260 return FWL_Error::Succeeded; | |
| 261 } | |
| 262 IFWL_Widget* CFWL_WidgetImp::GetParent() { | |
| 263 return m_pWidgetMgr->GetParentWidget(m_pInterface); | |
| 264 } | |
| 265 FWL_Error CFWL_WidgetImp::SetParent(IFWL_Widget* pParent) { | |
| 266 m_pProperties->m_pParent = pParent; | |
| 267 m_pWidgetMgr->SetParent(pParent, m_pInterface); | |
| 268 return FWL_Error::Succeeded; | |
| 269 } | |
| 270 IFWL_Widget* CFWL_WidgetImp::GetOwner() { | |
| 271 return m_pWidgetMgr->GetOwnerWidget(m_pInterface); | |
| 272 } | |
| 273 FWL_Error CFWL_WidgetImp::SetOwner(IFWL_Widget* pOwner) { | |
| 274 m_pProperties->m_pOwner = pOwner; | |
| 275 m_pWidgetMgr->SetOwner(pOwner, m_pInterface); | |
| 276 return FWL_Error::Succeeded; | |
| 277 } | |
| 278 IFWL_Widget* CFWL_WidgetImp::GetOuter() { | |
| 279 return m_pOuter; | |
| 280 } | |
| 281 uint32_t CFWL_WidgetImp::GetStyles() { | |
| 282 return m_pProperties->m_dwStyles; | |
| 283 } | |
| 284 FWL_Error CFWL_WidgetImp::ModifyStyles(uint32_t dwStylesAdded, | |
| 285 uint32_t dwStylesRemoved) { | |
| 286 m_pProperties->m_dwStyles = | |
| 287 (m_pProperties->m_dwStyles & ~dwStylesRemoved) | dwStylesAdded; | |
| 288 return FWL_Error::Succeeded; | |
| 289 } | |
| 290 uint32_t CFWL_WidgetImp::GetStylesEx() { | |
| 291 return m_pProperties->m_dwStyleExes; | |
| 292 } | |
| 293 FWL_Error CFWL_WidgetImp::ModifyStylesEx(uint32_t dwStylesExAdded, | |
| 294 uint32_t dwStylesExRemoved) { | |
| 295 m_pProperties->m_dwStyleExes = | |
| 296 (m_pProperties->m_dwStyleExes & ~dwStylesExRemoved) | dwStylesExAdded; | |
| 297 return FWL_Error::Succeeded; | |
| 298 } | |
| 299 uint32_t CFWL_WidgetImp::GetStates() { | |
| 300 return m_pProperties->m_dwStates; | |
| 301 } | |
| 302 static void NotifyHideChildWidget(CFWL_WidgetMgr* widgetMgr, | |
| 303 IFWL_Widget* widget, | |
| 304 CFWL_NoteDriver* noteDriver) { | |
| 305 IFWL_Widget* child = widgetMgr->GetFirstChildWidget(widget); | |
| 306 while (child) { | |
| 307 noteDriver->NotifyTargetHide(child); | |
| 308 NotifyHideChildWidget(widgetMgr, child, noteDriver); | |
| 309 child = widgetMgr->GetNextSiblingWidget(child); | |
| 310 } | |
| 311 } | |
| 312 | |
| 313 void CFWL_WidgetImp::SetStates(uint32_t dwStates, FX_BOOL bSet) { | |
| 314 bSet ? (m_pProperties->m_dwStates |= dwStates) | |
| 315 : (m_pProperties->m_dwStates &= ~dwStates); | |
| 316 if (!(dwStates & FWL_WGTSTATE_Invisible) || !bSet) | |
| 317 return; | |
| 318 | |
| 319 CFWL_NoteDriver* noteDriver = | |
| 320 static_cast<CFWL_NoteDriver*>(GetOwnerApp()->GetNoteDriver()); | |
| 321 CFWL_WidgetMgr* widgetMgr = CFWL_WidgetMgr::GetInstance(); | |
| 322 noteDriver->NotifyTargetHide(m_pInterface); | |
| 323 IFWL_Widget* child = widgetMgr->GetFirstChildWidget(m_pInterface); | |
| 324 while (child) { | |
| 325 noteDriver->NotifyTargetHide(child); | |
| 326 NotifyHideChildWidget(widgetMgr, child, noteDriver); | |
| 327 child = widgetMgr->GetNextSiblingWidget(child); | |
| 328 } | |
| 329 return; | |
| 330 } | |
| 331 FWL_Error CFWL_WidgetImp::Update() { | |
| 332 return FWL_Error::Succeeded; | |
| 333 } | |
| 334 FWL_Error CFWL_WidgetImp::LockUpdate() { | |
| 335 m_iLock++; | |
| 336 return FWL_Error::Succeeded; | |
| 337 } | |
| 338 FWL_Error CFWL_WidgetImp::UnlockUpdate() { | |
| 339 if (IsLocked()) { | |
| 340 m_iLock--; | |
| 341 } | |
| 342 return FWL_Error::Succeeded; | |
| 343 } | |
| 344 FWL_WidgetHit CFWL_WidgetImp::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | |
| 345 CFX_RectF rtClient; | |
| 346 GetClientRect(rtClient); | |
| 347 if (rtClient.Contains(fx, fy)) | |
| 348 return FWL_WidgetHit::Client; | |
| 349 if (HasEdge()) { | |
| 350 CFX_RectF rtEdge; | |
| 351 GetEdgeRect(rtEdge); | |
| 352 if (rtEdge.Contains(fx, fy)) | |
| 353 return FWL_WidgetHit::Edge; | |
| 354 } | |
| 355 if (HasBorder()) { | |
| 356 CFX_RectF rtRelative; | |
| 357 GetRelativeRect(rtRelative); | |
| 358 if (rtRelative.Contains(fx, fy)) | |
| 359 return FWL_WidgetHit::Border; | |
| 360 } | |
| 361 return FWL_WidgetHit::Unknown; | |
| 362 } | |
| 363 FWL_Error CFWL_WidgetImp::TransformTo(IFWL_Widget* pWidget, | |
| 364 FX_FLOAT& fx, | |
| 365 FX_FLOAT& fy) { | |
| 366 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 367 CFX_SizeF szOffset; | |
| 368 if (IsParent(pWidget)) { | |
| 369 szOffset = GetOffsetFromParent(pWidget); | |
| 370 } else { | |
| 371 szOffset = pWidget->GetOffsetFromParent(m_pInterface); | |
| 372 szOffset.x = -szOffset.x; | |
| 373 szOffset.y = -szOffset.y; | |
| 374 } | |
| 375 fx += szOffset.x; | |
| 376 fy += szOffset.y; | |
| 377 return FWL_Error::Succeeded; | |
| 378 } | |
| 379 CFX_RectF r; | |
| 380 CFX_Matrix m; | |
| 381 IFWL_Widget* parent = GetParent(); | |
| 382 if (parent) { | |
| 383 GetWidgetRect(r); | |
| 384 fx += r.left; | |
| 385 fy += r.top; | |
| 386 GetMatrix(m, TRUE); | |
| 387 m.TransformPoint(fx, fy); | |
| 388 } | |
| 389 IFWL_Widget* form1 = m_pWidgetMgr->GetSystemFormWidget(m_pInterface); | |
| 390 if (!form1) | |
| 391 return FWL_Error::Indefinite; | |
| 392 if (!pWidget) { | |
| 393 form1->GetWidgetRect(r); | |
| 394 fx += r.left; | |
| 395 fy += r.top; | |
| 396 return FWL_Error::Succeeded; | |
| 397 } | |
| 398 IFWL_Widget* form2 = m_pWidgetMgr->GetSystemFormWidget(pWidget); | |
| 399 if (!form2) | |
| 400 return FWL_Error::Indefinite; | |
| 401 if (form1 != form2) { | |
| 402 form1->GetWidgetRect(r); | |
| 403 fx += r.left; | |
| 404 fy += r.top; | |
| 405 form2->GetWidgetRect(r); | |
| 406 fx -= r.left; | |
| 407 fy -= r.top; | |
| 408 } | |
| 409 parent = pWidget->GetParent(); | |
| 410 if (parent) { | |
| 411 pWidget->GetMatrix(m, TRUE); | |
| 412 CFX_Matrix m1; | |
| 413 m1.SetIdentity(); | |
| 414 m1.SetReverse(m); | |
| 415 m1.TransformPoint(fx, fy); | |
| 416 pWidget->GetWidgetRect(r); | |
| 417 fx -= r.left; | |
| 418 fy -= r.top; | |
| 419 } | |
| 420 return FWL_Error::Succeeded; | |
| 421 } | |
| 422 FWL_Error CFWL_WidgetImp::TransformTo(IFWL_Widget* pWidget, CFX_RectF& rt) { | |
| 423 return TransformTo(pWidget, rt.left, rt.top); | |
| 424 } | |
| 425 FWL_Error CFWL_WidgetImp::GetMatrix(CFX_Matrix& matrix, FX_BOOL bGlobal) { | |
| 426 if (!m_pProperties) | |
| 427 return FWL_Error::Indefinite; | |
| 428 if (bGlobal) { | |
| 429 IFWL_Widget* parent = GetParent(); | |
| 430 CFX_ArrayTemplate<IFWL_Widget*> parents; | |
| 431 while (parent) { | |
| 432 parents.Add(parent); | |
| 433 parent = parent->GetParent(); | |
| 434 } | |
| 435 matrix.SetIdentity(); | |
| 436 CFX_Matrix ctmOnParent; | |
| 437 CFX_RectF rect; | |
| 438 int32_t count = parents.GetSize(); | |
| 439 for (int32_t i = count - 2; i >= 0; i--) { | |
| 440 parent = parents.GetAt(i); | |
| 441 parent->GetMatrix(ctmOnParent, FALSE); | |
| 442 parent->GetWidgetRect(rect); | |
| 443 matrix.Concat(ctmOnParent, TRUE); | |
| 444 matrix.Translate(rect.left, rect.top, TRUE); | |
| 445 } | |
| 446 matrix.Concat(m_pProperties->m_ctmOnParent, TRUE); | |
| 447 parents.RemoveAll(); | |
| 448 } else { | |
| 449 matrix = m_pProperties->m_ctmOnParent; | |
| 450 } | |
| 451 return FWL_Error::Succeeded; | |
| 452 } | |
| 453 FWL_Error CFWL_WidgetImp::SetMatrix(const CFX_Matrix& matrix) { | |
| 454 if (!m_pProperties) | |
| 455 return FWL_Error::Indefinite; | |
| 456 IFWL_Widget* parent = GetParent(); | |
| 457 if (!parent) { | |
| 458 return FWL_Error::Indefinite; | |
| 459 } | |
| 460 m_pProperties->m_ctmOnParent = matrix; | |
| 461 return FWL_Error::Succeeded; | |
| 462 } | |
| 463 FWL_Error CFWL_WidgetImp::DrawWidget(CFX_Graphics* pGraphics, | |
| 464 const CFX_Matrix* pMatrix) { | |
| 465 return FWL_Error::Indefinite; | |
| 466 } | |
| 467 IFWL_ThemeProvider* CFWL_WidgetImp::GetThemeProvider() { | |
| 468 return m_pProperties->m_pThemeProvider; | |
| 469 } | |
| 470 FWL_Error CFWL_WidgetImp::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { | |
| 471 m_pProperties->m_pThemeProvider = pThemeProvider; | |
| 472 return FWL_Error::Succeeded; | |
| 473 } | |
| 474 IFWL_WidgetDelegate* CFWL_WidgetImp::SetDelegate( | |
| 475 IFWL_WidgetDelegate* pDelegate) { | |
| 476 if (!m_pCurDelegate) { | |
| 477 m_pCurDelegate = m_pDelegate; | |
| 478 } | |
| 479 if (!pDelegate) { | |
| 480 return m_pCurDelegate; | |
| 481 } | |
| 482 IFWL_WidgetDelegate* pOldDelegate = m_pCurDelegate; | |
| 483 m_pCurDelegate = pDelegate; | |
| 484 return pOldDelegate; | |
| 485 } | |
| 486 IFWL_App* CFWL_WidgetImp::GetOwnerApp() const { | |
| 487 return m_pOwnerApp; | |
| 488 } | |
| 489 FWL_Error CFWL_WidgetImp::SetOwnerApp(IFWL_App* pOwnerApp) { | |
| 490 m_pOwnerApp = pOwnerApp; | |
| 491 return FWL_Error::Succeeded; | |
| 492 } | |
| 493 IFWL_Widget* CFWL_WidgetImp::GetInterface() const { | |
| 494 return m_pInterface; | |
| 495 } | |
| 496 void CFWL_WidgetImp::SetInterface(IFWL_Widget* pInterface) { | |
| 497 m_pInterface = pInterface; | |
| 498 } | |
| 499 | |
| 500 uint32_t CFWL_WidgetImp::GetEventKey() const { | |
| 501 return m_nEventKey; | |
| 502 } | |
| 503 | |
| 504 void CFWL_WidgetImp::SetEventKey(uint32_t key) { | |
| 505 m_nEventKey = key; | |
| 506 } | |
| 507 | |
| 508 void* CFWL_WidgetImp::GetLayoutItem() const { | |
| 509 return m_pLayoutItem; | |
| 510 } | |
| 511 | |
| 512 void CFWL_WidgetImp::SetLayoutItem(void* pItem) { | |
| 513 m_pLayoutItem = pItem; | |
| 514 } | |
| 515 | |
| 516 void* CFWL_WidgetImp::GetAssociateWidget() const { | |
| 517 return m_pAssociate; | |
| 518 } | |
| 519 | |
| 520 void CFWL_WidgetImp::SetAssociateWidget(void* pAssociate) { | |
| 521 m_pAssociate = pAssociate; | |
| 522 } | |
| 523 | |
| 524 CFWL_WidgetImp::CFWL_WidgetImp(const CFWL_WidgetImpProperties& properties, | |
| 525 IFWL_Widget* pOuter) | |
| 526 : m_pWidgetMgr(CFWL_WidgetMgr::GetInstance()), | |
| 527 m_pProperties(new CFWL_WidgetImpProperties(properties)), | |
| 528 m_pDelegate(nullptr), | |
| 529 m_pCurDelegate(nullptr), | |
| 530 m_pOuter(pOuter), | |
| 531 m_pInterface(nullptr), | |
| 532 m_pLayoutItem(nullptr), | |
| 533 m_pAssociate(nullptr), | |
| 534 m_iLock(0), | |
| 535 m_nEventKey(0) { | |
| 536 ASSERT(m_pWidgetMgr); | |
| 537 } | |
| 538 | |
| 539 CFWL_WidgetImp::~CFWL_WidgetImp() {} | |
| 540 | |
| 541 FX_BOOL CFWL_WidgetImp::IsEnabled() const { | |
| 542 return (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == 0; | |
| 543 } | |
| 544 FX_BOOL CFWL_WidgetImp::IsVisible() const { | |
| 545 return (m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) == 0; | |
| 546 } | |
| 547 FX_BOOL CFWL_WidgetImp::IsActive() const { | |
| 548 return (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) == 0; | |
| 549 } | |
| 550 FX_BOOL CFWL_WidgetImp::IsOverLapper() const { | |
| 551 return (m_pProperties->m_dwStyles & FWL_WGTSTYLE_WindowTypeMask) == | |
| 552 FWL_WGTSTYLE_OverLapper; | |
| 553 } | |
| 554 FX_BOOL CFWL_WidgetImp::IsPopup() const { | |
| 555 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Popup); | |
| 556 } | |
| 557 FX_BOOL CFWL_WidgetImp::IsChild() const { | |
| 558 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Child); | |
| 559 } | |
| 560 FX_BOOL CFWL_WidgetImp::IsLocked() const { | |
| 561 return m_iLock > 0; | |
| 562 } | |
| 563 FX_BOOL CFWL_WidgetImp::IsOffscreen() const { | |
| 564 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Offscreen); | |
| 565 } | |
| 566 FX_BOOL CFWL_WidgetImp::HasBorder() const { | |
| 567 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border); | |
| 568 } | |
| 569 FX_BOOL CFWL_WidgetImp::HasEdge() const { | |
| 570 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_EdgeMask); | |
| 571 } | |
| 572 void CFWL_WidgetImp::GetEdgeRect(CFX_RectF& rtEdge) { | |
| 573 rtEdge = m_pProperties->m_rtWidget; | |
| 574 rtEdge.left = rtEdge.top = 0; | |
| 575 if (HasBorder()) { | |
| 576 FX_FLOAT fCX = GetBorderSize(); | |
| 577 FX_FLOAT fCY = GetBorderSize(FALSE); | |
| 578 rtEdge.Deflate(fCX, fCY); | |
| 579 } | |
| 580 } | |
| 581 FX_FLOAT CFWL_WidgetImp::GetBorderSize(FX_BOOL bCX) { | |
| 582 FX_FLOAT* pfBorder = static_cast<FX_FLOAT*>(GetThemeCapacity( | |
| 583 bCX ? CFWL_WidgetCapacity::CXBorder : CFWL_WidgetCapacity::CYBorder)); | |
| 584 if (!pfBorder) | |
| 585 return 0; | |
| 586 return *pfBorder; | |
| 587 } | |
| 588 FX_FLOAT CFWL_WidgetImp::GetEdgeWidth() { | |
| 589 CFWL_WidgetCapacity dwCapacity = CFWL_WidgetCapacity::None; | |
| 590 switch (m_pProperties->m_dwStyles & FWL_WGTSTYLE_EdgeMask) { | |
| 591 case FWL_WGTSTYLE_EdgeFlat: { | |
| 592 dwCapacity = CFWL_WidgetCapacity::EdgeFlat; | |
| 593 break; | |
| 594 } | |
| 595 case FWL_WGTSTYLE_EdgeRaised: { | |
| 596 dwCapacity = CFWL_WidgetCapacity::EdgeRaised; | |
| 597 break; | |
| 598 } | |
| 599 case FWL_WGTSTYLE_EdgeSunken: { | |
| 600 dwCapacity = CFWL_WidgetCapacity::EdgeSunken; | |
| 601 break; | |
| 602 } | |
| 603 } | |
| 604 if (dwCapacity != CFWL_WidgetCapacity::None) { | |
| 605 FX_FLOAT* fRet = static_cast<FX_FLOAT*>(GetThemeCapacity(dwCapacity)); | |
| 606 return fRet ? *fRet : 0; | |
| 607 } | |
| 608 return 0; | |
| 609 } | |
| 610 void CFWL_WidgetImp::GetRelativeRect(CFX_RectF& rect) { | |
| 611 rect = m_pProperties->m_rtWidget; | |
| 612 rect.left = rect.top = 0; | |
| 613 } | |
| 614 void* CFWL_WidgetImp::GetThemeCapacity(CFWL_WidgetCapacity dwCapacity) { | |
| 615 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); | |
| 616 if (!pTheme) | |
| 617 return nullptr; | |
| 618 CFWL_ThemePart part; | |
| 619 part.m_pWidget = m_pInterface; | |
| 620 return pTheme->GetCapacity(&part, dwCapacity); | |
| 621 } | |
| 622 IFWL_ThemeProvider* CFWL_WidgetImp::GetAvailableTheme() { | |
| 623 if (m_pProperties->m_pThemeProvider) { | |
| 624 return m_pProperties->m_pThemeProvider; | |
| 625 } | |
| 626 IFWL_Widget* pUp = m_pInterface; | |
| 627 do { | |
| 628 pUp = (pUp->GetStyles() & FWL_WGTSTYLE_Popup) | |
| 629 ? m_pWidgetMgr->GetOwnerWidget(pUp) | |
| 630 : m_pWidgetMgr->GetParentWidget(pUp); | |
| 631 if (pUp) { | |
| 632 IFWL_ThemeProvider* pRet = pUp->GetThemeProvider(); | |
| 633 if (pRet) | |
| 634 return pRet; | |
| 635 } | |
| 636 } while (pUp); | |
| 637 return nullptr; | |
| 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 uint32_t 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 | |
| 689 IFWL_App* pApp = GetOwnerApp(); | |
| 690 if (!pApp) | |
| 691 return; | |
| 692 | |
| 693 CFWL_NoteDriver* pDriver = | |
| 694 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
| 695 if (!pDriver) | |
| 696 return; | |
| 697 | |
| 698 IFWL_Widget* curFocus = pDriver->GetFocus(); | |
| 699 if (bFocus && curFocus != m_pInterface) { | |
| 700 pDriver->SetFocus(m_pInterface); | |
| 701 } else if (!bFocus && curFocus == m_pInterface) { | |
| 702 pDriver->SetFocus(nullptr); | |
| 703 } | |
| 704 } | |
| 705 void CFWL_WidgetImp::SetGrab(FX_BOOL bSet) { | |
| 706 IFWL_App* pApp = GetOwnerApp(); | |
| 707 if (!pApp) | |
| 708 return; | |
| 709 CFWL_NoteDriver* pDriver = | |
| 710 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
| 711 pDriver->SetGrab(m_pInterface, bSet); | |
| 712 } | |
| 713 | |
| 714 FX_BOOL CFWL_WidgetImp::GetPopupPos(FX_FLOAT fMinHeight, | |
| 715 FX_FLOAT fMaxHeight, | |
| 716 const CFX_RectF& rtAnchor, | |
| 717 CFX_RectF& rtPopup) { | |
| 718 if (GetClassID() == FWL_Type::ComboBox) { | |
| 719 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 720 return m_pWidgetMgr->GetAdapterPopupPos(m_pInterface, fMinHeight, | |
| 721 fMaxHeight, rtAnchor, rtPopup); | |
| 722 } | |
| 723 return GetPopupPosComboBox(fMinHeight, fMaxHeight, rtAnchor, rtPopup); | |
| 724 } | |
| 725 if (GetClassID() == FWL_Type::DateTimePicker && | |
| 726 m_pWidgetMgr->IsFormDisabled()) { | |
| 727 return m_pWidgetMgr->GetAdapterPopupPos(m_pInterface, fMinHeight, | |
| 728 fMaxHeight, rtAnchor, rtPopup); | |
| 729 } | |
| 730 return GetPopupPosGeneral(fMinHeight, fMaxHeight, rtAnchor, rtPopup); | |
| 731 } | |
| 732 | |
| 733 FX_BOOL CFWL_WidgetImp::GetPopupPosMenu(FX_FLOAT fMinHeight, | |
| 734 FX_FLOAT fMaxHeight, | |
| 735 const CFX_RectF& rtAnchor, | |
| 736 CFX_RectF& rtPopup) { | |
| 737 FX_FLOAT fx = 0; | |
| 738 FX_FLOAT fy = 0; | |
| 739 FX_FLOAT fScreenWidth = 0; | |
| 740 FX_FLOAT fScreenHeight = 0; | |
| 741 GetScreenSize(fScreenWidth, fScreenHeight); | |
| 742 if (GetStylesEx() & FWL_STYLEEXT_MNU_Vert) { | |
| 743 FX_BOOL bLeft = m_pProperties->m_rtWidget.left < 0; | |
| 744 FX_FLOAT fRight = rtAnchor.right() + rtPopup.width; | |
| 745 TransformTo(nullptr, fx, fy); | |
| 746 if (fRight + fx > fScreenWidth || bLeft) { | |
| 747 rtPopup.Set(rtAnchor.left - rtPopup.width, rtAnchor.top, rtPopup.width, | |
| 748 rtPopup.height); | |
| 749 } else { | |
| 750 rtPopup.Set(rtAnchor.right(), rtAnchor.top, rtPopup.width, | |
| 751 rtPopup.height); | |
| 752 } | |
| 753 } else { | |
| 754 FX_FLOAT fBottom = rtAnchor.bottom() + rtPopup.height; | |
| 755 TransformTo(nullptr, fx, fy); | |
| 756 if (fBottom + fy > fScreenHeight) { | |
| 757 rtPopup.Set(rtAnchor.left, rtAnchor.top - rtPopup.height, rtPopup.width, | |
| 758 rtPopup.height); | |
| 759 } else { | |
| 760 rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), rtPopup.width, | |
| 761 rtPopup.height); | |
| 762 } | |
| 763 } | |
| 764 rtPopup.Offset(fx, fy); | |
| 765 return TRUE; | |
| 766 } | |
| 767 FX_BOOL CFWL_WidgetImp::GetPopupPosComboBox(FX_FLOAT fMinHeight, | |
| 768 FX_FLOAT fMaxHeight, | |
| 769 const CFX_RectF& rtAnchor, | |
| 770 CFX_RectF& rtPopup) { | |
| 771 FX_FLOAT fx = 0; | |
| 772 FX_FLOAT fy = 0; | |
| 773 FX_FLOAT fScreenWidth = 0; | |
| 774 FX_FLOAT fScreenHeight = 0; | |
| 775 GetScreenSize(fScreenWidth, fScreenHeight); | |
| 776 FX_FLOAT fPopHeight = rtPopup.height; | |
| 777 if (rtPopup.height > fMaxHeight) { | |
| 778 fPopHeight = fMaxHeight; | |
| 779 } else if (rtPopup.height < fMinHeight) { | |
| 780 fPopHeight = fMinHeight; | |
| 781 } | |
| 782 FX_FLOAT fWidth = std::max(rtAnchor.width, rtPopup.width); | |
| 783 FX_FLOAT fBottom = rtAnchor.bottom() + fPopHeight; | |
| 784 TransformTo(nullptr, fx, fy); | |
| 785 if (fBottom + fy > fScreenHeight) { | |
| 786 rtPopup.Set(rtAnchor.left, rtAnchor.top - fPopHeight, fWidth, fPopHeight); | |
| 787 } else { | |
| 788 rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), fWidth, fPopHeight); | |
| 789 } | |
| 790 rtPopup.Offset(fx, fy); | |
| 791 return TRUE; | |
| 792 } | |
| 793 FX_BOOL CFWL_WidgetImp::GetPopupPosGeneral(FX_FLOAT fMinHeight, | |
| 794 FX_FLOAT fMaxHeight, | |
| 795 const CFX_RectF& rtAnchor, | |
| 796 CFX_RectF& rtPopup) { | |
| 797 FX_FLOAT fx = 0; | |
| 798 FX_FLOAT fy = 0; | |
| 799 FX_FLOAT fScreenWidth = 0; | |
| 800 FX_FLOAT fScreenHeight = 0; | |
| 801 GetScreenSize(fScreenWidth, fScreenHeight); | |
| 802 TransformTo(nullptr, fx, fy); | |
| 803 if (rtAnchor.bottom() + fy > fScreenHeight) { | |
| 804 rtPopup.Set(rtAnchor.left, rtAnchor.top - rtPopup.height, rtPopup.width, | |
| 805 rtPopup.height); | |
| 806 } else { | |
| 807 rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), rtPopup.width, | |
| 808 rtPopup.height); | |
| 809 } | |
| 810 rtPopup.Offset(fx, fy); | |
| 811 return TRUE; | |
| 812 } | |
| 813 FX_BOOL CFWL_WidgetImp::GetScreenSize(FX_FLOAT& fx, FX_FLOAT& fy) { | |
| 814 return FALSE; | |
| 815 } | |
| 816 void CFWL_WidgetImp::RegisterEventTarget(IFWL_Widget* pEventSource, | |
| 817 uint32_t dwFilter) { | |
| 818 IFWL_App* pApp = GetOwnerApp(); | |
| 819 if (!pApp) | |
| 820 return; | |
| 821 | |
| 822 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); | |
| 823 if (!pNoteDriver) | |
| 824 return; | |
| 825 | |
| 826 pNoteDriver->RegisterEventTarget(m_pInterface, pEventSource, dwFilter); | |
| 827 } | |
| 828 void CFWL_WidgetImp::UnregisterEventTarget() { | |
| 829 IFWL_App* pApp = GetOwnerApp(); | |
| 830 if (!pApp) | |
| 831 return; | |
| 832 | |
| 833 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); | |
| 834 if (!pNoteDriver) | |
| 835 return; | |
| 836 | |
| 837 pNoteDriver->UnregisterEventTarget(m_pInterface); | |
| 838 } | |
| 839 void CFWL_WidgetImp::DispatchKeyEvent(CFWL_MsgKey* pNote) { | |
| 840 if (!pNote) | |
| 841 return; | |
| 842 CFWL_EvtKey* pEvent = new CFWL_EvtKey; | |
| 843 pEvent->m_pSrcTarget = m_pInterface; | |
| 844 pEvent->m_dwCmd = pNote->m_dwCmd; | |
| 845 pEvent->m_dwKeyCode = pNote->m_dwKeyCode; | |
| 846 pEvent->m_dwFlags = pNote->m_dwFlags; | |
| 847 DispatchEvent(pEvent); | |
| 848 pEvent->Release(); | |
| 849 } | |
| 850 void CFWL_WidgetImp::DispatchEvent(CFWL_Event* pEvent) { | |
| 851 if (m_pOuter) { | |
| 852 IFWL_WidgetDelegate* pDelegate = m_pOuter->SetDelegate(nullptr); | |
| 853 pDelegate->OnProcessEvent(pEvent); | |
| 854 return; | |
| 855 } | |
| 856 IFWL_App* pApp = GetOwnerApp(); | |
| 857 if (!pApp) | |
| 858 return; | |
| 859 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); | |
| 860 if (!pNoteDriver) | |
| 861 return; | |
| 862 pNoteDriver->SendEvent(pEvent); | |
| 863 } | |
| 864 void CFWL_WidgetImp::Repaint(const CFX_RectF* pRect) { | |
| 865 if (pRect) { | |
| 866 m_pWidgetMgr->RepaintWidget(m_pInterface, pRect); | |
| 867 return; | |
| 868 } | |
| 869 CFX_RectF rect; | |
| 870 rect = m_pProperties->m_rtWidget; | |
| 871 rect.left = rect.top = 0; | |
| 872 m_pWidgetMgr->RepaintWidget(m_pInterface, &rect); | |
| 873 } | |
| 874 void CFWL_WidgetImp::DrawBackground(CFX_Graphics* pGraphics, | |
| 875 CFWL_Part iPartBk, | |
| 876 IFWL_ThemeProvider* pTheme, | |
| 877 const CFX_Matrix* pMatrix) { | |
| 878 CFX_RectF rtRelative; | |
| 879 GetRelativeRect(rtRelative); | |
| 880 CFWL_ThemeBackground param; | |
| 881 param.m_pWidget = m_pInterface; | |
| 882 param.m_iPart = iPartBk; | |
| 883 param.m_pGraphics = pGraphics; | |
| 884 if (pMatrix) { | |
| 885 param.m_matrix.Concat(*pMatrix, TRUE); | |
| 886 } | |
| 887 param.m_rtPart = rtRelative; | |
| 888 pTheme->DrawBackground(¶m); | |
| 889 } | |
| 890 void CFWL_WidgetImp::DrawBorder(CFX_Graphics* pGraphics, | |
| 891 CFWL_Part iPartBorder, | |
| 892 IFWL_ThemeProvider* pTheme, | |
| 893 const CFX_Matrix* pMatrix) { | |
| 894 CFX_RectF rtRelative; | |
| 895 GetRelativeRect(rtRelative); | |
| 896 CFWL_ThemeBackground param; | |
| 897 param.m_pWidget = m_pInterface; | |
| 898 param.m_iPart = iPartBorder; | |
| 899 param.m_pGraphics = pGraphics; | |
| 900 if (pMatrix) { | |
| 901 param.m_matrix.Concat(*pMatrix, TRUE); | |
| 902 } | |
| 903 param.m_rtPart = rtRelative; | |
| 904 pTheme->DrawBackground(¶m); | |
| 905 } | |
| 906 void CFWL_WidgetImp::DrawEdge(CFX_Graphics* pGraphics, | |
| 907 CFWL_Part iPartEdge, | |
| 908 IFWL_ThemeProvider* pTheme, | |
| 909 const CFX_Matrix* pMatrix) { | |
| 910 CFX_RectF rtEdge; | |
| 911 GetEdgeRect(rtEdge); | |
| 912 CFWL_ThemeBackground param; | |
| 913 param.m_pWidget = m_pInterface; | |
| 914 param.m_iPart = iPartEdge; | |
| 915 param.m_pGraphics = pGraphics; | |
| 916 if (pMatrix) { | |
| 917 param.m_matrix.Concat(*pMatrix, TRUE); | |
| 918 } | |
| 919 param.m_rtPart = rtEdge; | |
| 920 pTheme->DrawBackground(¶m); | |
| 921 } | |
| 922 void CFWL_WidgetImp::NotifyDriver() { | |
| 923 IFWL_App* pApp = GetOwnerApp(); | |
| 924 if (!pApp) | |
| 925 return; | |
| 926 | |
| 927 CFWL_NoteDriver* pDriver = | |
| 928 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
| 929 if (!pDriver) | |
| 930 return; | |
| 931 | |
| 932 pDriver->NotifyTargetDestroy(m_pInterface); | |
| 933 } | |
| 934 CFX_SizeF CFWL_WidgetImp::GetOffsetFromParent(IFWL_Widget* pParent) { | |
| 935 if (pParent == GetInterface()) | |
| 936 return CFX_SizeF(); | |
| 937 | |
| 938 CFWL_WidgetMgr* pWidgetMgr = CFWL_WidgetMgr::GetInstance(); | |
| 939 if (!pWidgetMgr) | |
| 940 return CFX_SizeF(); | |
| 941 | |
| 942 CFX_SizeF szRet(m_pProperties->m_rtWidget.left, | |
| 943 m_pProperties->m_rtWidget.top); | |
| 944 | |
| 945 IFWL_Widget* pDstWidget = GetParent(); | |
| 946 while (pDstWidget && pDstWidget != pParent) { | |
| 947 CFX_RectF rtDst; | |
| 948 pDstWidget->GetWidgetRect(rtDst); | |
| 949 szRet += CFX_SizeF(rtDst.left, rtDst.top); | |
| 950 pDstWidget = pWidgetMgr->GetParentWidget(pDstWidget); | |
| 951 } | |
| 952 return szRet; | |
| 953 } | |
| 954 FX_BOOL CFWL_WidgetImp::IsParent(IFWL_Widget* pParent) { | |
| 955 IFWL_Widget* pUpWidget = GetParent(); | |
| 956 while (pUpWidget) { | |
| 957 if (pUpWidget == pParent) | |
| 958 return TRUE; | |
| 959 pUpWidget = pUpWidget->GetParent(); | |
| 960 } | |
| 961 return FALSE; | |
| 962 } | |
| 963 | |
| 964 CFWL_WidgetImpDelegate::CFWL_WidgetImpDelegate() {} | |
| 965 | |
| 966 void CFWL_WidgetImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 967 if (!pMessage->m_pDstTarget) | |
| 968 return; | |
| 969 | |
| 970 CFWL_WidgetImp* pWidget = | |
| 971 static_cast<CFWL_WidgetImp*>(pMessage->m_pDstTarget->GetImpl()); | |
| 972 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | |
| 973 switch (dwMsgCode) { | |
| 974 case CFWL_MessageType::Mouse: { | |
| 975 CFWL_MsgMouse* pMsgMouse = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 976 CFWL_EvtMouse evt; | |
| 977 evt.m_pSrcTarget = pWidget->m_pInterface; | |
| 978 evt.m_pDstTarget = pWidget->m_pInterface; | |
| 979 evt.m_dwCmd = pMsgMouse->m_dwCmd; | |
| 980 evt.m_dwFlags = pMsgMouse->m_dwFlags; | |
| 981 evt.m_fx = pMsgMouse->m_fx; | |
| 982 evt.m_fy = pMsgMouse->m_fy; | |
| 983 pWidget->DispatchEvent(&evt); | |
| 984 break; | |
| 985 } | |
| 986 case CFWL_MessageType::MouseWheel: { | |
| 987 CFWL_MsgMouseWheel* pMsgMouseWheel = | |
| 988 static_cast<CFWL_MsgMouseWheel*>(pMessage); | |
| 989 CFWL_EvtMouseWheel evt; | |
| 990 evt.m_pSrcTarget = pWidget->m_pInterface; | |
| 991 evt.m_pDstTarget = pWidget->m_pInterface; | |
| 992 evt.m_dwFlags = pMsgMouseWheel->m_dwFlags; | |
| 993 evt.m_fDeltaX = pMsgMouseWheel->m_fDeltaX; | |
| 994 evt.m_fDeltaY = pMsgMouseWheel->m_fDeltaY; | |
| 995 evt.m_fx = pMsgMouseWheel->m_fx; | |
| 996 evt.m_fy = pMsgMouseWheel->m_fy; | |
| 997 pWidget->DispatchEvent(&evt); | |
| 998 break; | |
| 999 } | |
| 1000 case CFWL_MessageType::Key: { | |
| 1001 CFWL_MsgKey* pMsgKey = static_cast<CFWL_MsgKey*>(pMessage); | |
| 1002 CFWL_EvtKey evt; | |
| 1003 evt.m_pSrcTarget = pWidget->m_pInterface; | |
| 1004 evt.m_pDstTarget = pWidget->m_pInterface; | |
| 1005 evt.m_dwKeyCode = pMsgKey->m_dwKeyCode; | |
| 1006 evt.m_dwFlags = pMsgKey->m_dwFlags; | |
| 1007 evt.m_dwCmd = pMsgKey->m_dwCmd; | |
| 1008 pWidget->DispatchEvent(&evt); | |
| 1009 break; | |
| 1010 } | |
| 1011 case CFWL_MessageType::SetFocus: { | |
| 1012 CFWL_MsgSetFocus* pMsgSetFocus = static_cast<CFWL_MsgSetFocus*>(pMessage); | |
| 1013 CFWL_EvtSetFocus evt; | |
| 1014 evt.m_pSrcTarget = pMsgSetFocus->m_pDstTarget; | |
| 1015 evt.m_pDstTarget = pMsgSetFocus->m_pDstTarget; | |
| 1016 evt.m_pSetFocus = pWidget->m_pInterface; | |
| 1017 pWidget->DispatchEvent(&evt); | |
| 1018 break; | |
| 1019 } | |
| 1020 case CFWL_MessageType::KillFocus: { | |
| 1021 CFWL_MsgKillFocus* pMsgKillFocus = | |
| 1022 static_cast<CFWL_MsgKillFocus*>(pMessage); | |
| 1023 CFWL_EvtKillFocus evt; | |
| 1024 evt.m_pSrcTarget = pMsgKillFocus->m_pDstTarget; | |
| 1025 evt.m_pDstTarget = pMsgKillFocus->m_pDstTarget; | |
| 1026 evt.m_pKillFocus = pWidget->m_pInterface; | |
| 1027 pWidget->DispatchEvent(&evt); | |
| 1028 break; | |
| 1029 } | |
| 1030 default: | |
| 1031 break; | |
| 1032 } | |
| 1033 } | |
| 1034 | |
| 1035 void CFWL_WidgetImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {} | |
| 1036 | |
| 1037 void CFWL_WidgetImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 1038 const CFX_Matrix* pMatrix) { | |
| 1039 CFWL_EvtDraw evt; | |
| 1040 evt.m_pGraphics = pGraphics; | |
| 1041 } | |
| OLD | NEW |