• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/foxitlib.h"
8 #include "xfa/src/fwl/src/core/include/fwl_targetimp.h"
9 #include "xfa/src/fwl/src/core/include/fwl_noteimp.h"
10 #include "xfa/src/fwl/src/core/include/fwl_widgetimp.h"
11 #include "xfa/src/fwl/src/core/include/fwl_panelimp.h"
12 
13 // static
Create(CFWL_WidgetImpProperties & properties,IFWL_Widget * pOuter)14 IFWL_Panel* IFWL_Panel::Create(CFWL_WidgetImpProperties& properties,
15                                IFWL_Widget* pOuter) {
16   IFWL_Panel* pPanel = new IFWL_Panel;
17   CFWL_PanelImp* pPanelImpl = new CFWL_PanelImp(properties, pOuter);
18   pPanel->SetImpl(pPanelImpl);
19   pPanelImpl->SetInterface(pPanel);
20   return pPanel;
21 }
IFWL_Panel()22 IFWL_Panel::IFWL_Panel() {}
GetContent()23 IFWL_Content* IFWL_Panel::GetContent() {
24   return static_cast<CFWL_PanelImp*>(GetImpl())->GetContent();
25 }
SetContent(IFWL_Content * pContent)26 FWL_ERR IFWL_Panel::SetContent(IFWL_Content* pContent) {
27   return static_cast<CFWL_PanelImp*>(GetImpl())->SetContent(pContent);
28 }
29 
CFWL_PanelImp(const CFWL_WidgetImpProperties & properties,IFWL_Widget * pOuter)30 CFWL_PanelImp::CFWL_PanelImp(const CFWL_WidgetImpProperties& properties,
31                              IFWL_Widget* pOuter)
32     : CFWL_WidgetImp(properties, pOuter), m_pContent(nullptr) {}
~CFWL_PanelImp()33 CFWL_PanelImp::~CFWL_PanelImp() {}
GetClassName(CFX_WideString & wsClass) const34 FWL_ERR CFWL_PanelImp::GetClassName(CFX_WideString& wsClass) const {
35   wsClass = FWL_CLASS_Panel;
36   return FWL_ERR_Succeeded;
37 }
GetClassID() const38 FX_DWORD CFWL_PanelImp::GetClassID() const {
39   return FWL_CLASSHASH_Panel;
40 }
GetWidgetRect(CFX_RectF & rect,FX_BOOL bAutoSize)41 FWL_ERR CFWL_PanelImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) {
42   if (bAutoSize) {
43     if (m_pContent) {
44       m_pContent->GetWidgetRect(rect, TRUE);
45     }
46   } else {
47     rect = m_pProperties->m_rtWidget;
48   }
49   return FWL_ERR_Succeeded;
50 }
Update()51 FWL_ERR CFWL_PanelImp::Update() {
52   if (m_pContent) {
53     CFX_RectF rtClient;
54     GetClientRect(rtClient);
55     FWL_GRIDUNIT eWidth = FWL_GRIDUNIT_Fixed, eHeight = FWL_GRIDUNIT_Fixed;
56     IFWL_WidgetMgr* pWidgetMgr = FWL_GetWidgetMgr();
57     if (!pWidgetMgr)
58       return FWL_ERR_Indefinite;
59     IFWL_Widget* pParent =
60         pWidgetMgr->GetWidget(GetInterface(), FWL_WGTRELATION_Parent);
61     if (pParent && pParent->GetClassID() == FWL_CLASSHASH_Grid) {
62       IFWL_Grid* pGrid = static_cast<IFWL_Grid*>(pParent);
63       pGrid->GetWidgetSize(GetInterface(), FWL_GRIDSIZE_Width, eWidth);
64       pGrid->GetWidgetSize(GetInterface(), FWL_GRIDSIZE_Height, eHeight);
65     }
66     m_pContent->SetWidgetRect(rtClient);
67     m_pContent->Update();
68   }
69   return FWL_ERR_Succeeded;
70 }
GetContent()71 IFWL_Content* CFWL_PanelImp::GetContent() {
72   return m_pContent;
73 }
SetContent(IFWL_Content * pContent)74 FWL_ERR CFWL_PanelImp::SetContent(IFWL_Content* pContent) {
75   if (!pContent)
76     return FWL_ERR_Indefinite;
77   m_pContent = pContent;
78   return pContent->SetParent(m_pInterface);
79 }
80 class CFWL_CustomPanelImp : public CFWL_WidgetImp {
81  public:
82   CFWL_CustomPanelImp(const CFWL_WidgetImpProperties& properties,
83                       IFWL_Widget* pOuter);
84   virtual ~CFWL_CustomPanelImp();
85   virtual FWL_ERR GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE);
86   virtual FWL_ERR Update();
87   virtual IFWL_Content* GetContent();
88   virtual FWL_ERR SetContent(IFWL_Content* pContent);
89   FWL_ERR SetProxy(IFWL_Proxy* pProxy);
90 
91  protected:
92   IFWL_Content* m_pContent;
93   IFWL_Proxy* m_pProxy;
94 };
CFWL_CustomPanelImp(const CFWL_WidgetImpProperties & properties,IFWL_Widget * pOuter)95 CFWL_CustomPanelImp::CFWL_CustomPanelImp(
96     const CFWL_WidgetImpProperties& properties,
97     IFWL_Widget* pOuter)
98     : CFWL_WidgetImp(properties, pOuter),
99       m_pContent(nullptr),
100       m_pProxy(nullptr) {}
~CFWL_CustomPanelImp()101 CFWL_CustomPanelImp::~CFWL_CustomPanelImp() {}
GetWidgetRect(CFX_RectF & rect,FX_BOOL bAutoSize)102 FWL_ERR CFWL_CustomPanelImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) {
103   if (bAutoSize && m_pProxy &&
104       (m_pProxy->GetWidgetRect(rect, bAutoSize) == FWL_ERR_Succeeded)) {
105     return FWL_ERR_Succeeded;
106   }
107   return CFWL_WidgetImp::GetWidgetRect(rect, bAutoSize);
108 }
Update()109 FWL_ERR CFWL_CustomPanelImp::Update() {
110   if (m_pProxy) {
111     return m_pProxy->Update();
112   }
113   return CFWL_WidgetImp::Update();
114 }
GetContent()115 IFWL_Content* CFWL_CustomPanelImp::GetContent() {
116   return m_pContent;
117 }
SetContent(IFWL_Content * pContent)118 FWL_ERR CFWL_CustomPanelImp::SetContent(IFWL_Content* pContent) {
119   if (!pContent)
120     return FWL_ERR_Indefinite;
121   m_pContent = pContent;
122   return pContent->SetParent(m_pInterface);
123 }
SetProxy(IFWL_Proxy * pProxy)124 FWL_ERR CFWL_CustomPanelImp::SetProxy(IFWL_Proxy* pProxy) {
125   m_pProxy = pProxy;
126   return FWL_ERR_Succeeded;
127 }
128 
129 // statuc
Create(CFWL_WidgetImpProperties & properties,IFWL_Widget * pOuter)130 IFWL_CustomPanel* IFWL_CustomPanel::Create(CFWL_WidgetImpProperties& properties,
131                                            IFWL_Widget* pOuter) {
132   IFWL_CustomPanel* pCustomPanel = new IFWL_CustomPanel;
133   CFWL_CustomPanelImp* pCustomPanelImpl =
134       new CFWL_CustomPanelImp(properties, pOuter);
135   pCustomPanel->SetImpl(pCustomPanelImpl);
136   pCustomPanelImpl->SetInterface(pCustomPanel);
137   return pCustomPanel;
138 }
IFWL_CustomPanel()139 IFWL_CustomPanel::IFWL_CustomPanel() {}
GetContent()140 IFWL_Content* IFWL_CustomPanel::GetContent() {
141   return static_cast<CFWL_CustomPanelImp*>(GetImpl())->GetContent();
142 }
SetContent(IFWL_Content * pContent)143 FWL_ERR IFWL_CustomPanel::SetContent(IFWL_Content* pContent) {
144   return static_cast<CFWL_CustomPanelImp*>(GetImpl())->SetContent(pContent);
145 }
SetProxy(IFWL_Proxy * pProxy)146 FWL_ERR IFWL_CustomPanel::SetProxy(IFWL_Proxy* pProxy) {
147   return static_cast<CFWL_CustomPanelImp*>(GetImpl())->SetProxy(pProxy);
148 }
149