OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fwl/core/fwl_widgetimp.h" | 7 #include "xfa/fwl/core/fwl_widgetimp.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 202 } |
203 if (HasBorder()) { | 203 if (HasBorder()) { |
204 FX_FLOAT fBorder = GetBorderSize(); | 204 FX_FLOAT fBorder = GetBorderSize(); |
205 rect.Inflate(fBorder, fBorder); | 205 rect.Inflate(fBorder, fBorder); |
206 } | 206 } |
207 } else { | 207 } else { |
208 rect = m_pProperties->m_rtWidget; | 208 rect = m_pProperties->m_rtWidget; |
209 } | 209 } |
210 return FWL_Error::Succeeded; | 210 return FWL_Error::Succeeded; |
211 } | 211 } |
| 212 |
212 FWL_Error CFWL_WidgetImp::GetGlobalRect(CFX_RectF& rect) { | 213 FWL_Error CFWL_WidgetImp::GetGlobalRect(CFX_RectF& rect) { |
213 IFWL_Widget* pForm = | 214 IFWL_Widget* pForm = m_pWidgetMgr->GetSystemFormWidget(m_pInterface); |
214 m_pWidgetMgr->GetWidget(m_pInterface, FWL_WGTRELATION_SystemForm); | |
215 if (!pForm) | 215 if (!pForm) |
216 return FWL_Error::Indefinite; | 216 return FWL_Error::Indefinite; |
| 217 |
217 rect.Set(0, 0, m_pProperties->m_rtWidget.width, | 218 rect.Set(0, 0, m_pProperties->m_rtWidget.width, |
218 m_pProperties->m_rtWidget.height); | 219 m_pProperties->m_rtWidget.height); |
219 if (pForm == m_pInterface) { | 220 if (pForm == m_pInterface) |
220 return FWL_Error::Succeeded; | 221 return FWL_Error::Succeeded; |
221 } | 222 |
222 return TransformTo(pForm, rect); | 223 return TransformTo(pForm, rect); |
223 } | 224 } |
| 225 |
224 FWL_Error CFWL_WidgetImp::SetWidgetRect(const CFX_RectF& rect) { | 226 FWL_Error CFWL_WidgetImp::SetWidgetRect(const CFX_RectF& rect) { |
225 CFX_RectF rtOld = m_pProperties->m_rtWidget; | 227 CFX_RectF rtOld = m_pProperties->m_rtWidget; |
226 m_pProperties->m_rtWidget = rect; | 228 m_pProperties->m_rtWidget = rect; |
227 if (IsChild()) { | 229 if (IsChild()) { |
228 if (FXSYS_fabs(rtOld.width - rect.width) > 0.5f || | 230 if (FXSYS_fabs(rtOld.width - rect.width) > 0.5f || |
229 FXSYS_fabs(rtOld.height - rect.height) > 0.5f) { | 231 FXSYS_fabs(rtOld.height - rect.height) > 0.5f) { |
230 CFWL_EvtSizeChanged ev; | 232 CFWL_EvtSizeChanged ev; |
231 ev.m_pSrcTarget = m_pInterface; | 233 ev.m_pSrcTarget = m_pInterface; |
232 ev.m_rtOld = rtOld; | 234 ev.m_rtOld = rtOld; |
233 ev.m_rtNew = rect; | 235 ev.m_rtNew = rect; |
234 IFWL_WidgetDelegate* pDelegate = SetDelegate(NULL); | 236 IFWL_WidgetDelegate* pDelegate = SetDelegate(NULL); |
235 if (pDelegate) { | 237 if (pDelegate) { |
236 pDelegate->OnProcessEvent(&ev); | 238 pDelegate->OnProcessEvent(&ev); |
237 } | 239 } |
238 } | 240 } |
239 return FWL_Error::Succeeded; | 241 return FWL_Error::Succeeded; |
240 } | 242 } |
241 m_pWidgetMgr->SetWidgetRect_Native(m_pInterface, rect); | 243 m_pWidgetMgr->SetWidgetRect_Native(m_pInterface, rect); |
242 return FWL_Error::Succeeded; | 244 return FWL_Error::Succeeded; |
243 } | 245 } |
244 FWL_Error CFWL_WidgetImp::GetClientRect(CFX_RectF& rect) { | 246 FWL_Error CFWL_WidgetImp::GetClientRect(CFX_RectF& rect) { |
245 GetEdgeRect(rect); | 247 GetEdgeRect(rect); |
246 if (HasEdge()) { | 248 if (HasEdge()) { |
247 FX_FLOAT fEdge = GetEdgeWidth(); | 249 FX_FLOAT fEdge = GetEdgeWidth(); |
248 rect.Deflate(fEdge, fEdge); | 250 rect.Deflate(fEdge, fEdge); |
249 } | 251 } |
250 return FWL_Error::Succeeded; | 252 return FWL_Error::Succeeded; |
251 } | 253 } |
252 IFWL_Widget* CFWL_WidgetImp::GetParent() { | 254 IFWL_Widget* CFWL_WidgetImp::GetParent() { |
253 return m_pWidgetMgr->GetWidget(m_pInterface, FWL_WGTRELATION_Parent); | 255 return m_pWidgetMgr->GetParentWidget(m_pInterface); |
254 } | 256 } |
255 FWL_Error CFWL_WidgetImp::SetParent(IFWL_Widget* pParent) { | 257 FWL_Error CFWL_WidgetImp::SetParent(IFWL_Widget* pParent) { |
256 m_pProperties->m_pParent = pParent; | 258 m_pProperties->m_pParent = pParent; |
257 m_pWidgetMgr->SetParent(pParent, m_pInterface); | 259 m_pWidgetMgr->SetParent(pParent, m_pInterface); |
258 return FWL_Error::Succeeded; | 260 return FWL_Error::Succeeded; |
259 } | 261 } |
260 IFWL_Widget* CFWL_WidgetImp::GetOwner() { | 262 IFWL_Widget* CFWL_WidgetImp::GetOwner() { |
261 return m_pWidgetMgr->GetWidget(m_pInterface, FWL_WGTRELATION_Owner); | 263 return m_pWidgetMgr->GetOwnerWidget(m_pInterface); |
262 } | 264 } |
263 FWL_Error CFWL_WidgetImp::SetOwner(IFWL_Widget* pOwner) { | 265 FWL_Error CFWL_WidgetImp::SetOwner(IFWL_Widget* pOwner) { |
264 m_pProperties->m_pOwner = pOwner; | 266 m_pProperties->m_pOwner = pOwner; |
265 m_pWidgetMgr->SetOwner(pOwner, m_pInterface); | 267 m_pWidgetMgr->SetOwner(pOwner, m_pInterface); |
266 return FWL_Error::Succeeded; | 268 return FWL_Error::Succeeded; |
267 } | 269 } |
268 IFWL_Widget* CFWL_WidgetImp::GetOuter() { | 270 IFWL_Widget* CFWL_WidgetImp::GetOuter() { |
269 return m_pOuter; | 271 return m_pOuter; |
270 } | 272 } |
271 uint32_t CFWL_WidgetImp::GetStyles() { | 273 uint32_t CFWL_WidgetImp::GetStyles() { |
(...skipping 10 matching lines...) Expand all Loading... |
282 } | 284 } |
283 FWL_Error CFWL_WidgetImp::ModifyStylesEx(uint32_t dwStylesExAdded, | 285 FWL_Error CFWL_WidgetImp::ModifyStylesEx(uint32_t dwStylesExAdded, |
284 uint32_t dwStylesExRemoved) { | 286 uint32_t dwStylesExRemoved) { |
285 m_pProperties->m_dwStyleExes = | 287 m_pProperties->m_dwStyleExes = |
286 (m_pProperties->m_dwStyleExes & ~dwStylesExRemoved) | dwStylesExAdded; | 288 (m_pProperties->m_dwStyleExes & ~dwStylesExRemoved) | dwStylesExAdded; |
287 return FWL_Error::Succeeded; | 289 return FWL_Error::Succeeded; |
288 } | 290 } |
289 uint32_t CFWL_WidgetImp::GetStates() { | 291 uint32_t CFWL_WidgetImp::GetStates() { |
290 return m_pProperties->m_dwStates; | 292 return m_pProperties->m_dwStates; |
291 } | 293 } |
292 static void NotifyHideChildWidget(IFWL_WidgetMgr* widgetMgr, | 294 static void NotifyHideChildWidget(CFWL_WidgetMgr* widgetMgr, |
293 IFWL_Widget* widget, | 295 IFWL_Widget* widget, |
294 CFWL_NoteDriver* noteDriver) { | 296 CFWL_NoteDriver* noteDriver) { |
295 IFWL_Widget* child = widgetMgr->GetWidget(widget, FWL_WGTRELATION_FirstChild); | 297 IFWL_Widget* child = widgetMgr->GetFirstChildWidget(widget); |
296 while (child) { | 298 while (child) { |
297 noteDriver->NotifyTargetHide(child); | 299 noteDriver->NotifyTargetHide(child); |
298 NotifyHideChildWidget(widgetMgr, child, noteDriver); | 300 NotifyHideChildWidget(widgetMgr, child, noteDriver); |
299 child = widgetMgr->GetWidget(child, FWL_WGTRELATION_NextSibling); | 301 child = widgetMgr->GetNextSiblingWidget(child); |
300 } | 302 } |
301 } | 303 } |
302 | 304 |
303 void CFWL_WidgetImp::SetStates(uint32_t dwStates, FX_BOOL bSet) { | 305 void CFWL_WidgetImp::SetStates(uint32_t dwStates, FX_BOOL bSet) { |
304 bSet ? (m_pProperties->m_dwStates |= dwStates) | 306 bSet ? (m_pProperties->m_dwStates |= dwStates) |
305 : (m_pProperties->m_dwStates &= ~dwStates); | 307 : (m_pProperties->m_dwStates &= ~dwStates); |
306 if (!(dwStates & FWL_WGTSTATE_Invisible) || !bSet) | 308 if (!(dwStates & FWL_WGTSTATE_Invisible) || !bSet) |
307 return; | 309 return; |
308 | 310 |
309 CFWL_NoteDriver* noteDriver = | 311 CFWL_NoteDriver* noteDriver = |
310 static_cast<CFWL_NoteDriver*>(GetOwnerApp()->GetNoteDriver()); | 312 static_cast<CFWL_NoteDriver*>(GetOwnerApp()->GetNoteDriver()); |
311 IFWL_WidgetMgr* widgetMgr = FWL_GetWidgetMgr(); | 313 CFWL_WidgetMgr* widgetMgr = CFWL_WidgetMgr::GetInstance(); |
312 noteDriver->NotifyTargetHide(m_pInterface); | 314 noteDriver->NotifyTargetHide(m_pInterface); |
313 IFWL_Widget* child = | 315 IFWL_Widget* child = widgetMgr->GetFirstChildWidget(m_pInterface); |
314 widgetMgr->GetWidget(m_pInterface, FWL_WGTRELATION_FirstChild); | |
315 while (child) { | 316 while (child) { |
316 noteDriver->NotifyTargetHide(child); | 317 noteDriver->NotifyTargetHide(child); |
317 NotifyHideChildWidget(widgetMgr, child, noteDriver); | 318 NotifyHideChildWidget(widgetMgr, child, noteDriver); |
318 child = widgetMgr->GetWidget(child, FWL_WGTRELATION_NextSibling); | 319 child = widgetMgr->GetNextSiblingWidget(child); |
319 } | 320 } |
320 return; | 321 return; |
321 } | 322 } |
322 FWL_Error CFWL_WidgetImp::SetPrivateData(void* module_id, | 323 FWL_Error CFWL_WidgetImp::SetPrivateData(void* module_id, |
323 void* pData, | 324 void* pData, |
324 PD_CALLBACK_FREEDATA callback) { | 325 PD_CALLBACK_FREEDATA callback) { |
325 if (!m_pPrivateData) { | 326 if (!m_pPrivateData) { |
326 m_pPrivateData = new CFX_PrivateData; | 327 m_pPrivateData = new CFX_PrivateData; |
327 } | 328 } |
328 m_pPrivateData->SetPrivateData(module_id, pData, callback); | 329 m_pPrivateData->SetPrivateData(module_id, pData, callback); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 CFX_RectF r; | 385 CFX_RectF r; |
385 CFX_Matrix m; | 386 CFX_Matrix m; |
386 IFWL_Widget* parent = GetParent(); | 387 IFWL_Widget* parent = GetParent(); |
387 if (parent) { | 388 if (parent) { |
388 GetWidgetRect(r); | 389 GetWidgetRect(r); |
389 fx += r.left; | 390 fx += r.left; |
390 fy += r.top; | 391 fy += r.top; |
391 GetMatrix(m, TRUE); | 392 GetMatrix(m, TRUE); |
392 m.TransformPoint(fx, fy); | 393 m.TransformPoint(fx, fy); |
393 } | 394 } |
394 IFWL_Widget* form1 = | 395 IFWL_Widget* form1 = m_pWidgetMgr->GetSystemFormWidget(m_pInterface); |
395 m_pWidgetMgr->GetWidget(m_pInterface, FWL_WGTRELATION_SystemForm); | |
396 if (!form1) | 396 if (!form1) |
397 return FWL_Error::Indefinite; | 397 return FWL_Error::Indefinite; |
398 if (!pWidget) { | 398 if (!pWidget) { |
399 form1->GetWidgetRect(r); | 399 form1->GetWidgetRect(r); |
400 fx += r.left; | 400 fx += r.left; |
401 fy += r.top; | 401 fy += r.top; |
402 return FWL_Error::Succeeded; | 402 return FWL_Error::Succeeded; |
403 } | 403 } |
404 IFWL_Widget* form2 = | 404 IFWL_Widget* form2 = m_pWidgetMgr->GetSystemFormWidget(pWidget); |
405 m_pWidgetMgr->GetWidget(pWidget, FWL_WGTRELATION_SystemForm); | |
406 if (!form2) | 405 if (!form2) |
407 return FWL_Error::Indefinite; | 406 return FWL_Error::Indefinite; |
408 if (form1 != form2) { | 407 if (form1 != form2) { |
409 form1->GetWidgetRect(r); | 408 form1->GetWidgetRect(r); |
410 fx += r.left; | 409 fx += r.left; |
411 fy += r.top; | 410 fy += r.top; |
412 form2->GetWidgetRect(r); | 411 form2->GetWidgetRect(r); |
413 fx -= r.left; | 412 fx -= r.left; |
414 fy -= r.top; | 413 fy -= r.top; |
415 } | 414 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 CFWL_WidgetImp::CFWL_WidgetImp(const CFWL_WidgetImpProperties& properties, | 509 CFWL_WidgetImp::CFWL_WidgetImp(const CFWL_WidgetImpProperties& properties, |
511 IFWL_Widget* pOuter) | 510 IFWL_Widget* pOuter) |
512 : m_pProperties(new CFWL_WidgetImpProperties), | 511 : m_pProperties(new CFWL_WidgetImpProperties), |
513 m_pPrivateData(NULL), | 512 m_pPrivateData(NULL), |
514 m_pDelegate(NULL), | 513 m_pDelegate(NULL), |
515 m_pCurDelegate(NULL), | 514 m_pCurDelegate(NULL), |
516 m_pOuter(pOuter), | 515 m_pOuter(pOuter), |
517 m_pInterface(NULL), | 516 m_pInterface(NULL), |
518 m_iLock(0) { | 517 m_iLock(0) { |
519 *m_pProperties = properties; | 518 *m_pProperties = properties; |
520 m_pWidgetMgr = static_cast<CFWL_WidgetMgr*>(FWL_GetWidgetMgr()); | 519 m_pWidgetMgr = CFWL_WidgetMgr::GetInstance(); |
521 ASSERT(m_pWidgetMgr != NULL); | 520 ASSERT(m_pWidgetMgr != NULL); |
522 } | 521 } |
523 CFWL_WidgetImp::~CFWL_WidgetImp() { | 522 CFWL_WidgetImp::~CFWL_WidgetImp() { |
524 if (m_pPrivateData) { | 523 if (m_pPrivateData) { |
525 delete m_pPrivateData; | 524 delete m_pPrivateData; |
526 m_pPrivateData = NULL; | 525 m_pPrivateData = NULL; |
527 } | 526 } |
528 if (m_pProperties) { | 527 if (m_pProperties) { |
529 delete m_pProperties; | 528 delete m_pProperties; |
530 m_pProperties = NULL; | 529 m_pProperties = NULL; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 CFWL_ThemePart part; | 609 CFWL_ThemePart part; |
611 part.m_pWidget = m_pInterface; | 610 part.m_pWidget = m_pInterface; |
612 return pTheme->GetCapacity(&part, dwCapacity); | 611 return pTheme->GetCapacity(&part, dwCapacity); |
613 } | 612 } |
614 IFWL_ThemeProvider* CFWL_WidgetImp::GetAvailableTheme() { | 613 IFWL_ThemeProvider* CFWL_WidgetImp::GetAvailableTheme() { |
615 if (m_pProperties->m_pThemeProvider) { | 614 if (m_pProperties->m_pThemeProvider) { |
616 return m_pProperties->m_pThemeProvider; | 615 return m_pProperties->m_pThemeProvider; |
617 } | 616 } |
618 IFWL_Widget* pUp = m_pInterface; | 617 IFWL_Widget* pUp = m_pInterface; |
619 do { | 618 do { |
620 FWL_WGTRELATION relation = (pUp->GetStyles() & FWL_WGTSTYLE_Popup) | 619 pUp = (pUp->GetStyles() & FWL_WGTSTYLE_Popup) |
621 ? FWL_WGTRELATION_Owner | 620 ? m_pWidgetMgr->GetOwnerWidget(pUp) |
622 : FWL_WGTRELATION_Parent; | 621 : m_pWidgetMgr->GetParentWidget(pUp); |
623 pUp = m_pWidgetMgr->GetWidget(pUp, relation); | |
624 if (pUp) { | 622 if (pUp) { |
625 IFWL_ThemeProvider* pRet = pUp->GetThemeProvider(); | 623 IFWL_ThemeProvider* pRet = pUp->GetThemeProvider(); |
626 if (pRet && pRet->IsValidWidget(m_pInterface)) { | 624 if (pRet && pRet->IsValidWidget(m_pInterface)) |
627 return pRet; | 625 return pRet; |
628 } | |
629 } | 626 } |
630 } while (pUp); | 627 } while (pUp); |
631 return FWL_GetApp()->GetThemeProvider(); | 628 return FWL_GetApp()->GetThemeProvider(); |
632 } | 629 } |
633 CFWL_WidgetImp* CFWL_WidgetImp::GetRootOuter() { | 630 CFWL_WidgetImp* CFWL_WidgetImp::GetRootOuter() { |
634 IFWL_Widget* pRet = m_pOuter; | 631 IFWL_Widget* pRet = m_pOuter; |
635 if (!pRet) | 632 if (!pRet) |
636 return nullptr; | 633 return nullptr; |
637 while (IFWL_Widget* pOuter = pRet->GetOuter()) { | 634 while (IFWL_Widget* pOuter = pRet->GetOuter()) { |
638 pRet = pOuter; | 635 pRet = pOuter; |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | 919 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); |
923 if (!pDriver) | 920 if (!pDriver) |
924 return; | 921 return; |
925 | 922 |
926 pDriver->NotifyTargetDestroy(m_pInterface); | 923 pDriver->NotifyTargetDestroy(m_pInterface); |
927 } | 924 } |
928 CFX_SizeF CFWL_WidgetImp::GetOffsetFromParent(IFWL_Widget* pParent) { | 925 CFX_SizeF CFWL_WidgetImp::GetOffsetFromParent(IFWL_Widget* pParent) { |
929 if (pParent == GetInterface()) | 926 if (pParent == GetInterface()) |
930 return CFX_SizeF(); | 927 return CFX_SizeF(); |
931 | 928 |
932 IFWL_WidgetMgr* pWidgetMgr = FWL_GetWidgetMgr(); | 929 CFWL_WidgetMgr* pWidgetMgr = CFWL_WidgetMgr::GetInstance(); |
933 if (!pWidgetMgr) | 930 if (!pWidgetMgr) |
934 return CFX_SizeF(); | 931 return CFX_SizeF(); |
935 | 932 |
936 CFX_SizeF szRet(m_pProperties->m_rtWidget.left, | 933 CFX_SizeF szRet(m_pProperties->m_rtWidget.left, |
937 m_pProperties->m_rtWidget.top); | 934 m_pProperties->m_rtWidget.top); |
938 | 935 |
939 IFWL_Widget* pDstWidget = GetParent(); | 936 IFWL_Widget* pDstWidget = GetParent(); |
940 while (pDstWidget && pDstWidget != pParent) { | 937 while (pDstWidget && pDstWidget != pParent) { |
941 CFX_RectF rtDst; | 938 CFX_RectF rtDst; |
942 pDstWidget->GetWidgetRect(rtDst); | 939 pDstWidget->GetWidgetRect(rtDst); |
943 szRet += CFX_SizeF(rtDst.left, rtDst.top); | 940 szRet += CFX_SizeF(rtDst.left, rtDst.top); |
944 pDstWidget = pWidgetMgr->GetWidget(pDstWidget, FWL_WGTRELATION_Parent); | 941 pDstWidget = pWidgetMgr->GetParentWidget(pDstWidget); |
945 } | 942 } |
946 return szRet; | 943 return szRet; |
947 } | 944 } |
948 FX_BOOL CFWL_WidgetImp::IsParent(IFWL_Widget* pParent) { | 945 FX_BOOL CFWL_WidgetImp::IsParent(IFWL_Widget* pParent) { |
949 IFWL_Widget* pUpWidget = GetParent(); | 946 IFWL_Widget* pUpWidget = GetParent(); |
950 while (pUpWidget) { | 947 while (pUpWidget) { |
951 if (pUpWidget == pParent) | 948 if (pUpWidget == pParent) |
952 return TRUE; | 949 return TRUE; |
953 pUpWidget = pUpWidget->GetParent(); | 950 pUpWidget = pUpWidget->GetParent(); |
954 } | 951 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 } | 1023 } |
1027 } | 1024 } |
1028 | 1025 |
1029 void CFWL_WidgetImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {} | 1026 void CFWL_WidgetImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {} |
1030 | 1027 |
1031 void CFWL_WidgetImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | 1028 void CFWL_WidgetImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, |
1032 const CFX_Matrix* pMatrix) { | 1029 const CFX_Matrix* pMatrix) { |
1033 CFWL_EvtDraw evt; | 1030 CFWL_EvtDraw evt; |
1034 evt.m_pGraphics = pGraphics; | 1031 evt.m_pGraphics = pGraphics; |
1035 } | 1032 } |
OLD | NEW |