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/ifwl_widget.h" | 7 #include "xfa/fwl/core/ifwl_widget.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "xfa/fde/tto/fde_textout.h" | 11 #include "xfa/fde/tto/fde_textout.h" |
12 #include "xfa/fwl/core/cfwl_message.h" | 12 #include "xfa/fwl/core/cfwl_message.h" |
13 #include "xfa/fwl/core/cfwl_themebackground.h" | 13 #include "xfa/fwl/core/cfwl_themebackground.h" |
14 #include "xfa/fwl/core/cfwl_themepart.h" | 14 #include "xfa/fwl/core/cfwl_themepart.h" |
15 #include "xfa/fwl/core/cfwl_themetext.h" | 15 #include "xfa/fwl/core/cfwl_themetext.h" |
16 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 16 #include "xfa/fwl/core/cfwl_widgetmgr.h" |
17 #include "xfa/fwl/core/fwl_noteimp.h" | 17 #include "xfa/fwl/core/fwl_noteimp.h" |
18 #include "xfa/fwl/core/ifwl_app.h" | 18 #include "xfa/fwl/core/ifwl_app.h" |
19 #include "xfa/fwl/core/ifwl_combobox.h" | 19 #include "xfa/fwl/core/ifwl_combobox.h" |
20 #include "xfa/fwl/core/ifwl_form.h" | 20 #include "xfa/fwl/core/ifwl_form.h" |
21 #include "xfa/fwl/core/ifwl_themeprovider.h" | 21 #include "xfa/fwl/core/ifwl_themeprovider.h" |
22 #include "xfa/fwl/core/ifwl_widget.h" | 22 #include "xfa/fwl/core/ifwl_widget.h" |
23 #include "xfa/fxfa/xfa_ffapp.h" | 23 #include "xfa/fxfa/xfa_ffapp.h" |
24 | 24 |
25 #define FWL_STYLEEXT_MNU_Vert (1L << 0) | 25 #define FWL_STYLEEXT_MNU_Vert (1L << 0) |
26 | 26 |
27 IFWL_Widget::IFWL_Widget(const CFWL_WidgetImpProperties& properties, | 27 IFWL_Widget::IFWL_Widget(const IFWL_App* app, |
| 28 const CFWL_WidgetImpProperties& properties, |
28 IFWL_Widget* pOuter) | 29 IFWL_Widget* pOuter) |
29 : m_pWidgetMgr(CFWL_WidgetMgr::GetInstance()), | 30 : m_pOwnerApp(app), |
| 31 m_pWidgetMgr(app->GetWidgetMgr()), |
30 m_pProperties(new CFWL_WidgetImpProperties(properties)), | 32 m_pProperties(new CFWL_WidgetImpProperties(properties)), |
31 m_pDelegate(nullptr), | 33 m_pDelegate(nullptr), |
32 m_pCurDelegate(nullptr), | 34 m_pCurDelegate(nullptr), |
33 m_pOuter(pOuter), | 35 m_pOuter(pOuter), |
34 m_pLayoutItem(nullptr), | 36 m_pLayoutItem(nullptr), |
35 m_pAssociate(nullptr), | 37 m_pAssociate(nullptr), |
36 m_iLock(0), | 38 m_iLock(0), |
37 m_nEventKey(0) { | 39 m_nEventKey(0) { |
38 ASSERT(m_pWidgetMgr); | 40 ASSERT(m_pWidgetMgr); |
39 } | 41 } |
40 | 42 |
41 IFWL_Widget::~IFWL_Widget() {} | 43 IFWL_Widget::~IFWL_Widget() {} |
42 | 44 |
43 FWL_Error IFWL_Widget::Initialize() { | 45 void IFWL_Widget::Initialize() { |
44 IFWL_App* pApp = FWL_GetApp(); | |
45 if (!pApp) | |
46 return FWL_Error::Indefinite; | |
47 | |
48 CXFA_FFApp* pAdapter = pApp->GetAdapterNative(); | |
49 if (!pAdapter) | |
50 return FWL_Error::Indefinite; | |
51 | |
52 SetOwnerApp(FWL_GetApp()); | |
53 | |
54 IFWL_Widget* pParent = m_pProperties->m_pParent; | 46 IFWL_Widget* pParent = m_pProperties->m_pParent; |
55 m_pWidgetMgr->InsertWidget(pParent, this); | 47 m_pWidgetMgr->InsertWidget(pParent, this); |
56 if (!IsChild()) { | 48 if (!IsChild()) { |
57 IFWL_Widget* pOwner = m_pProperties->m_pOwner; | 49 IFWL_Widget* pOwner = m_pProperties->m_pOwner; |
58 if (pOwner) | 50 if (pOwner) |
59 m_pWidgetMgr->SetOwner(pOwner, this); | 51 m_pWidgetMgr->SetOwner(pOwner, this); |
60 } | 52 } |
61 return FWL_Error::Succeeded; | |
62 } | 53 } |
63 | 54 |
64 void IFWL_Widget::Finalize() { | 55 void IFWL_Widget::Finalize() { |
65 NotifyDriver(); | 56 NotifyDriver(); |
66 m_pWidgetMgr->RemoveWidget(this); | 57 m_pWidgetMgr->RemoveWidget(this); |
67 } | 58 } |
68 | 59 |
69 FX_BOOL IFWL_Widget::IsInstance(const CFX_WideStringC& wsClass) const { | 60 FX_BOOL IFWL_Widget::IsInstance(const CFX_WideStringC& wsClass) const { |
70 return FALSE; | 61 return FALSE; |
71 } | 62 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 182 } |
192 | 183 |
193 void IFWL_Widget::SetStates(uint32_t dwStates, FX_BOOL bSet) { | 184 void IFWL_Widget::SetStates(uint32_t dwStates, FX_BOOL bSet) { |
194 bSet ? (m_pProperties->m_dwStates |= dwStates) | 185 bSet ? (m_pProperties->m_dwStates |= dwStates) |
195 : (m_pProperties->m_dwStates &= ~dwStates); | 186 : (m_pProperties->m_dwStates &= ~dwStates); |
196 if (!(dwStates & FWL_WGTSTATE_Invisible) || !bSet) | 187 if (!(dwStates & FWL_WGTSTATE_Invisible) || !bSet) |
197 return; | 188 return; |
198 | 189 |
199 CFWL_NoteDriver* noteDriver = | 190 CFWL_NoteDriver* noteDriver = |
200 static_cast<CFWL_NoteDriver*>(GetOwnerApp()->GetNoteDriver()); | 191 static_cast<CFWL_NoteDriver*>(GetOwnerApp()->GetNoteDriver()); |
201 CFWL_WidgetMgr* widgetMgr = CFWL_WidgetMgr::GetInstance(); | 192 CFWL_WidgetMgr* widgetMgr = GetOwnerApp()->GetWidgetMgr(); |
202 noteDriver->NotifyTargetHide(this); | 193 noteDriver->NotifyTargetHide(this); |
203 IFWL_Widget* child = widgetMgr->GetFirstChildWidget(this); | 194 IFWL_Widget* child = widgetMgr->GetFirstChildWidget(this); |
204 while (child) { | 195 while (child) { |
205 noteDriver->NotifyTargetHide(child); | 196 noteDriver->NotifyTargetHide(child); |
206 NotifyHideChildWidget(widgetMgr, child, noteDriver); | 197 NotifyHideChildWidget(widgetMgr, child, noteDriver); |
207 child = widgetMgr->GetNextSiblingWidget(child); | 198 child = widgetMgr->GetNextSiblingWidget(child); |
208 } | 199 } |
209 return; | 200 return; |
210 } | 201 } |
211 | 202 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 m_pCurDelegate = m_pDelegate; | 358 m_pCurDelegate = m_pDelegate; |
368 } | 359 } |
369 if (!pDelegate) { | 360 if (!pDelegate) { |
370 return m_pCurDelegate; | 361 return m_pCurDelegate; |
371 } | 362 } |
372 IFWL_WidgetDelegate* pOldDelegate = m_pCurDelegate; | 363 IFWL_WidgetDelegate* pOldDelegate = m_pCurDelegate; |
373 m_pCurDelegate = pDelegate; | 364 m_pCurDelegate = pDelegate; |
374 return pOldDelegate; | 365 return pOldDelegate; |
375 } | 366 } |
376 | 367 |
377 IFWL_App* IFWL_Widget::GetOwnerApp() const { | 368 const IFWL_App* IFWL_Widget::GetOwnerApp() const { |
378 return m_pOwnerApp; | 369 return m_pOwnerApp; |
379 } | 370 } |
380 | 371 |
381 FWL_Error IFWL_Widget::SetOwnerApp(IFWL_App* pOwnerApp) { | |
382 m_pOwnerApp = pOwnerApp; | |
383 return FWL_Error::Succeeded; | |
384 } | |
385 | |
386 uint32_t IFWL_Widget::GetEventKey() const { | 372 uint32_t IFWL_Widget::GetEventKey() const { |
387 return m_nEventKey; | 373 return m_nEventKey; |
388 } | 374 } |
389 | 375 |
390 void IFWL_Widget::SetEventKey(uint32_t key) { | 376 void IFWL_Widget::SetEventKey(uint32_t key) { |
391 m_nEventKey = key; | 377 m_nEventKey = key; |
392 } | 378 } |
393 | 379 |
394 void* IFWL_Widget::GetLayoutItem() const { | 380 void* IFWL_Widget::GetLayoutItem() const { |
395 return m_pLayoutItem; | 381 return m_pLayoutItem; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 calPart.m_wsText = wsText; | 549 calPart.m_wsText = wsText; |
564 calPart.m_dwTTOStyles = dwTTOStyles; | 550 calPart.m_dwTTOStyles = dwTTOStyles; |
565 calPart.m_iTTOAlign = iTTOAlign; | 551 calPart.m_iTTOAlign = iTTOAlign; |
566 pTheme->CalcTextRect(&calPart, rect); | 552 pTheme->CalcTextRect(&calPart, rect); |
567 } | 553 } |
568 | 554 |
569 void IFWL_Widget::SetFocus(FX_BOOL bFocus) { | 555 void IFWL_Widget::SetFocus(FX_BOOL bFocus) { |
570 if (m_pWidgetMgr->IsFormDisabled()) | 556 if (m_pWidgetMgr->IsFormDisabled()) |
571 return; | 557 return; |
572 | 558 |
573 IFWL_App* pApp = GetOwnerApp(); | 559 const IFWL_App* pApp = GetOwnerApp(); |
574 if (!pApp) | 560 if (!pApp) |
575 return; | 561 return; |
576 | 562 |
577 CFWL_NoteDriver* pDriver = | 563 CFWL_NoteDriver* pDriver = |
578 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | 564 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); |
579 if (!pDriver) | 565 if (!pDriver) |
580 return; | 566 return; |
581 | 567 |
582 IFWL_Widget* curFocus = pDriver->GetFocus(); | 568 IFWL_Widget* curFocus = pDriver->GetFocus(); |
583 if (bFocus && curFocus != this) { | 569 if (bFocus && curFocus != this) { |
584 pDriver->SetFocus(this); | 570 pDriver->SetFocus(this); |
585 } else if (!bFocus && curFocus == this) { | 571 } else if (!bFocus && curFocus == this) { |
586 pDriver->SetFocus(nullptr); | 572 pDriver->SetFocus(nullptr); |
587 } | 573 } |
588 } | 574 } |
589 | 575 |
590 void IFWL_Widget::SetGrab(FX_BOOL bSet) { | 576 void IFWL_Widget::SetGrab(FX_BOOL bSet) { |
591 IFWL_App* pApp = GetOwnerApp(); | 577 const IFWL_App* pApp = GetOwnerApp(); |
592 if (!pApp) | 578 if (!pApp) |
593 return; | 579 return; |
594 CFWL_NoteDriver* pDriver = | 580 CFWL_NoteDriver* pDriver = |
595 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | 581 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); |
596 pDriver->SetGrab(this, bSet); | 582 pDriver->SetGrab(this, bSet); |
597 } | 583 } |
598 | 584 |
599 FX_BOOL IFWL_Widget::GetPopupPos(FX_FLOAT fMinHeight, | 585 FX_BOOL IFWL_Widget::GetPopupPos(FX_FLOAT fMinHeight, |
600 FX_FLOAT fMaxHeight, | 586 FX_FLOAT fMaxHeight, |
601 const CFX_RectF& rtAnchor, | 587 const CFX_RectF& rtAnchor, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 rtPopup.Offset(fx, fy); | 683 rtPopup.Offset(fx, fy); |
698 return TRUE; | 684 return TRUE; |
699 } | 685 } |
700 | 686 |
701 FX_BOOL IFWL_Widget::GetScreenSize(FX_FLOAT& fx, FX_FLOAT& fy) { | 687 FX_BOOL IFWL_Widget::GetScreenSize(FX_FLOAT& fx, FX_FLOAT& fy) { |
702 return FALSE; | 688 return FALSE; |
703 } | 689 } |
704 | 690 |
705 void IFWL_Widget::RegisterEventTarget(IFWL_Widget* pEventSource, | 691 void IFWL_Widget::RegisterEventTarget(IFWL_Widget* pEventSource, |
706 uint32_t dwFilter) { | 692 uint32_t dwFilter) { |
707 IFWL_App* pApp = GetOwnerApp(); | 693 const IFWL_App* pApp = GetOwnerApp(); |
708 if (!pApp) | 694 if (!pApp) |
709 return; | 695 return; |
710 | 696 |
711 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); | 697 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); |
712 if (!pNoteDriver) | 698 if (!pNoteDriver) |
713 return; | 699 return; |
714 | 700 |
715 pNoteDriver->RegisterEventTarget(this, pEventSource, dwFilter); | 701 pNoteDriver->RegisterEventTarget(this, pEventSource, dwFilter); |
716 } | 702 } |
717 | 703 |
718 void IFWL_Widget::UnregisterEventTarget() { | 704 void IFWL_Widget::UnregisterEventTarget() { |
719 IFWL_App* pApp = GetOwnerApp(); | 705 const IFWL_App* pApp = GetOwnerApp(); |
720 if (!pApp) | 706 if (!pApp) |
721 return; | 707 return; |
722 | 708 |
723 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); | 709 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); |
724 if (!pNoteDriver) | 710 if (!pNoteDriver) |
725 return; | 711 return; |
726 | 712 |
727 pNoteDriver->UnregisterEventTarget(this); | 713 pNoteDriver->UnregisterEventTarget(this); |
728 } | 714 } |
729 | 715 |
730 void IFWL_Widget::DispatchKeyEvent(CFWL_MsgKey* pNote) { | 716 void IFWL_Widget::DispatchKeyEvent(CFWL_MsgKey* pNote) { |
731 if (!pNote) | 717 if (!pNote) |
732 return; | 718 return; |
733 CFWL_EvtKey* pEvent = new CFWL_EvtKey; | 719 CFWL_EvtKey* pEvent = new CFWL_EvtKey; |
734 pEvent->m_pSrcTarget = this; | 720 pEvent->m_pSrcTarget = this; |
735 pEvent->m_dwCmd = pNote->m_dwCmd; | 721 pEvent->m_dwCmd = pNote->m_dwCmd; |
736 pEvent->m_dwKeyCode = pNote->m_dwKeyCode; | 722 pEvent->m_dwKeyCode = pNote->m_dwKeyCode; |
737 pEvent->m_dwFlags = pNote->m_dwFlags; | 723 pEvent->m_dwFlags = pNote->m_dwFlags; |
738 DispatchEvent(pEvent); | 724 DispatchEvent(pEvent); |
739 pEvent->Release(); | 725 pEvent->Release(); |
740 } | 726 } |
741 | 727 |
742 void IFWL_Widget::DispatchEvent(CFWL_Event* pEvent) { | 728 void IFWL_Widget::DispatchEvent(CFWL_Event* pEvent) { |
743 if (m_pOuter) { | 729 if (m_pOuter) { |
744 IFWL_WidgetDelegate* pDelegate = m_pOuter->SetDelegate(nullptr); | 730 IFWL_WidgetDelegate* pDelegate = m_pOuter->SetDelegate(nullptr); |
745 pDelegate->OnProcessEvent(pEvent); | 731 pDelegate->OnProcessEvent(pEvent); |
746 return; | 732 return; |
747 } | 733 } |
748 IFWL_App* pApp = GetOwnerApp(); | 734 const IFWL_App* pApp = GetOwnerApp(); |
749 if (!pApp) | 735 if (!pApp) |
750 return; | 736 return; |
751 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); | 737 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); |
752 if (!pNoteDriver) | 738 if (!pNoteDriver) |
753 return; | 739 return; |
754 pNoteDriver->SendEvent(pEvent); | 740 pNoteDriver->SendEvent(pEvent); |
755 } | 741 } |
756 | 742 |
757 void IFWL_Widget::Repaint(const CFX_RectF* pRect) { | 743 void IFWL_Widget::Repaint(const CFX_RectF* pRect) { |
758 if (pRect) { | 744 if (pRect) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 param.m_iPart = iPartEdge; | 796 param.m_iPart = iPartEdge; |
811 param.m_pGraphics = pGraphics; | 797 param.m_pGraphics = pGraphics; |
812 if (pMatrix) { | 798 if (pMatrix) { |
813 param.m_matrix.Concat(*pMatrix, TRUE); | 799 param.m_matrix.Concat(*pMatrix, TRUE); |
814 } | 800 } |
815 param.m_rtPart = rtEdge; | 801 param.m_rtPart = rtEdge; |
816 pTheme->DrawBackground(¶m); | 802 pTheme->DrawBackground(¶m); |
817 } | 803 } |
818 | 804 |
819 void IFWL_Widget::NotifyDriver() { | 805 void IFWL_Widget::NotifyDriver() { |
820 IFWL_App* pApp = GetOwnerApp(); | 806 const IFWL_App* pApp = GetOwnerApp(); |
821 if (!pApp) | 807 if (!pApp) |
822 return; | 808 return; |
823 | 809 |
824 CFWL_NoteDriver* pDriver = | 810 CFWL_NoteDriver* pDriver = |
825 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | 811 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); |
826 if (!pDriver) | 812 if (!pDriver) |
827 return; | 813 return; |
828 | 814 |
829 pDriver->NotifyTargetDestroy(this); | 815 pDriver->NotifyTargetDestroy(this); |
830 } | 816 } |
831 | 817 |
832 CFX_SizeF IFWL_Widget::GetOffsetFromParent(IFWL_Widget* pParent) { | 818 CFX_SizeF IFWL_Widget::GetOffsetFromParent(IFWL_Widget* pParent) { |
833 if (pParent == this) | 819 if (pParent == this) |
834 return CFX_SizeF(); | 820 return CFX_SizeF(); |
835 | 821 |
836 CFWL_WidgetMgr* pWidgetMgr = CFWL_WidgetMgr::GetInstance(); | 822 CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); |
837 if (!pWidgetMgr) | 823 if (!pWidgetMgr) |
838 return CFX_SizeF(); | 824 return CFX_SizeF(); |
839 | 825 |
840 CFX_SizeF szRet(m_pProperties->m_rtWidget.left, | 826 CFX_SizeF szRet(m_pProperties->m_rtWidget.left, |
841 m_pProperties->m_rtWidget.top); | 827 m_pProperties->m_rtWidget.top); |
842 | 828 |
843 IFWL_Widget* pDstWidget = GetParent(); | 829 IFWL_Widget* pDstWidget = GetParent(); |
844 while (pDstWidget && pDstWidget != pParent) { | 830 while (pDstWidget && pDstWidget != pParent) { |
845 CFX_RectF rtDst; | 831 CFX_RectF rtDst; |
846 pDstWidget->GetWidgetRect(rtDst); | 832 pDstWidget->GetWidgetRect(rtDst); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 } | 916 } |
931 } | 917 } |
932 | 918 |
933 void CFWL_WidgetImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {} | 919 void CFWL_WidgetImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {} |
934 | 920 |
935 void CFWL_WidgetImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | 921 void CFWL_WidgetImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, |
936 const CFX_Matrix* pMatrix) { | 922 const CFX_Matrix* pMatrix) { |
937 CFWL_EvtDraw evt; | 923 CFWL_EvtDraw evt; |
938 evt.m_pGraphics = pGraphics; | 924 evt.m_pGraphics = pGraphics; |
939 } | 925 } |
OLD | NEW |