Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fwl / src / core / fwl_panelimp.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 #include "include/fwl_targetimp.h"\r
9 #include "include/fwl_noteimp.h"\r
10 #include "include/fwl_widgetimp.h"\r
11 #include "include/fwl_panelimp.h"\r
12 IFWL_Panel* IFWL_Panel::Create()\r
13 {\r
14     return new IFWL_Panel;\r
15 }\r
16 FWL_ERR IFWL_Panel::Initialize(IFWL_Widget *pOuter )\r
17 {\r
18     m_pData = FX_NEW CFWL_PanelImp(pOuter);\r
19     ((CFWL_PanelImp*)m_pData)->SetInterface(this);\r
20     return ((CFWL_PanelImp*)m_pData)->Initialize();\r
21 }\r
22 FWL_ERR IFWL_Panel::Initialize(CFWL_WidgetImpProperties &properties, IFWL_Widget *pOuter )\r
23 {\r
24     m_pData = FX_NEW CFWL_PanelImp(properties, pOuter);\r
25     ((CFWL_PanelImp*)m_pData)->SetInterface(this);\r
26     return ((CFWL_PanelImp*)m_pData)->Initialize();\r
27 }\r
28 IFWL_Content* IFWL_Panel::GetContent()\r
29 {\r
30     return ((CFWL_PanelImp*)m_pData)->GetContent();\r
31 }\r
32 FWL_ERR IFWL_Panel::SetContent(IFWL_Content *pContent)\r
33 {\r
34     return ((CFWL_PanelImp*)m_pData)->SetContent(pContent);\r
35 }\r
36 IFWL_Panel::IFWL_Panel()\r
37 {\r
38     m_pData = NULL;\r
39 }\r
40 IFWL_Panel::~IFWL_Panel()\r
41 {\r
42     if (m_pData) {\r
43         delete (CFWL_PanelImp*)m_pData;\r
44         m_pData = NULL;\r
45     }\r
46 }\r
47 CFWL_PanelImp::CFWL_PanelImp(IFWL_Widget* pOuter )\r
48     : CFWL_WidgetImp(pOuter)\r
49     , m_pContent(NULL)\r
50 {\r
51 }\r
52 CFWL_PanelImp::CFWL_PanelImp(const CFWL_WidgetImpProperties &properties, IFWL_Widget *pOuter )\r
53     : CFWL_WidgetImp(properties, pOuter)\r
54     , m_pContent(NULL)\r
55 {\r
56 }\r
57 CFWL_PanelImp::~CFWL_PanelImp()\r
58 {\r
59 }\r
60 FWL_ERR CFWL_PanelImp::GetClassName(CFX_WideString &wsClass) const\r
61 {\r
62     wsClass = FWL_CLASS_Panel;\r
63     return FWL_ERR_Succeeded;\r
64 }\r
65 FX_DWORD CFWL_PanelImp::GetClassID() const\r
66 {\r
67     return FWL_CLASSHASH_Panel;\r
68 }\r
69 FWL_ERR CFWL_PanelImp::GetWidgetRect(CFX_RectF &rect, FX_BOOL bAutoSize )\r
70 {\r
71     if (bAutoSize) {\r
72         if (m_pContent) {\r
73             m_pContent->GetWidgetRect(rect, TRUE);\r
74         }\r
75     } else {\r
76         rect = m_pProperties->m_rtWidget;\r
77     }\r
78     return FWL_ERR_Succeeded;\r
79 }\r
80 FWL_ERR CFWL_PanelImp::Update()\r
81 {\r
82     if (m_pContent) {\r
83         CFX_RectF rtClient;\r
84         GetClientRect(rtClient);\r
85         FWL_GRIDUNIT eWidth = FWL_GRIDUNIT_Fixed, eHeight = FWL_GRIDUNIT_Fixed;\r
86         IFWL_WidgetMgr *pWidgetMgr = FWL_GetWidgetMgr();\r
87         _FWL_RETURN_VALUE_IF_FAIL(pWidgetMgr, FWL_ERR_Indefinite);\r
88         IFWL_Widget *pParent = pWidgetMgr->GetWidget((IFWL_Widget*)this, FWL_WGTRELATION_Parent);\r
89         if (pParent && pParent->GetClassID() == FWL_CLASSHASH_Grid) {\r
90             IFWL_Grid* pGrid = (IFWL_Grid*)pParent;\r
91             pGrid->GetWidgetSize((IFWL_Widget*)this, FWL_GRIDSIZE_Width, eWidth);\r
92             pGrid->GetWidgetSize((IFWL_Widget*)this, FWL_GRIDSIZE_Height, eHeight);\r
93         }\r
94         if (eWidth != FWL_GRIDUNIT_Auto || eHeight != FWL_GRIDUNIT_Auto) {\r
95         }\r
96         m_pContent->SetWidgetRect(rtClient);\r
97         m_pContent->Update();\r
98     }\r
99     return FWL_ERR_Succeeded;\r
100 }\r
101 IFWL_Content* CFWL_PanelImp::GetContent()\r
102 {\r
103     return m_pContent;\r
104 }\r
105 FWL_ERR CFWL_PanelImp::SetContent(IFWL_Content *pContent)\r
106 {\r
107     _FWL_RETURN_VALUE_IF_FAIL(pContent, FWL_ERR_Indefinite);\r
108     m_pContent = pContent;\r
109     return pContent->SetParent(m_pInterface);\r
110 }\r
111 class CFWL_CustomPanelImp : public CFWL_WidgetImp\r
112 {\r
113 public:\r
114     CFWL_CustomPanelImp(IFWL_Widget *pOuter = NULL);\r
115     CFWL_CustomPanelImp(const CFWL_WidgetImpProperties &properties, IFWL_Widget *pOuter = NULL);\r
116     virtual ~CFWL_CustomPanelImp();\r
117     virtual FWL_ERR                     GetWidgetRect(CFX_RectF &rect, FX_BOOL bAutoSize = FALSE);\r
118     virtual     FWL_ERR                 Update();\r
119     virtual IFWL_Content*       GetContent();\r
120     virtual FWL_ERR                     SetContent(IFWL_Content *pContent);\r
121     FWL_ERR                                     SetProxy(IFWL_Proxy *pProxy);\r
122 protected:\r
123     IFWL_Content                        *m_pContent;\r
124     IFWL_Proxy                          *m_pProxy;\r
125 };\r
126 CFWL_CustomPanelImp::CFWL_CustomPanelImp(IFWL_Widget* pOuter )\r
127     : CFWL_WidgetImp(pOuter)\r
128     , m_pContent(NULL)\r
129     , m_pProxy(NULL)\r
130 {\r
131 }\r
132 CFWL_CustomPanelImp::CFWL_CustomPanelImp(const CFWL_WidgetImpProperties &properties, IFWL_Widget *pOuter )\r
133     : CFWL_WidgetImp(properties, pOuter)\r
134     , m_pContent(NULL)\r
135     , m_pProxy(NULL)\r
136 {\r
137 }\r
138 CFWL_CustomPanelImp::~CFWL_CustomPanelImp()\r
139 {\r
140 }\r
141 FWL_ERR CFWL_CustomPanelImp::GetWidgetRect(CFX_RectF &rect, FX_BOOL bAutoSize )\r
142 {\r
143     if (bAutoSize && m_pProxy && (m_pProxy->GetWidgetRect(rect, bAutoSize) == FWL_ERR_Succeeded)) {\r
144         return FWL_ERR_Succeeded;\r
145     }\r
146     return CFWL_WidgetImp::GetWidgetRect(rect, bAutoSize);\r
147 }\r
148 FWL_ERR CFWL_CustomPanelImp::Update()\r
149 {\r
150     if (m_pProxy) {\r
151         return m_pProxy->Update();\r
152     }\r
153     return CFWL_WidgetImp::Update();\r
154 }\r
155 IFWL_Content* CFWL_CustomPanelImp::GetContent()\r
156 {\r
157     return m_pContent;\r
158 }\r
159 FWL_ERR CFWL_CustomPanelImp::SetContent(IFWL_Content *pContent)\r
160 {\r
161     _FWL_RETURN_VALUE_IF_FAIL(pContent, FWL_ERR_Indefinite);\r
162     m_pContent = pContent;\r
163     return pContent->SetParent(m_pInterface);\r
164 }\r
165 FWL_ERR CFWL_CustomPanelImp::SetProxy(IFWL_Proxy *pProxy)\r
166 {\r
167     m_pProxy = pProxy;\r
168     return FWL_ERR_Succeeded;\r
169 }\r
170 IFWL_CustomPanel* IFWL_CustomPanel::Create()\r
171 {\r
172     return new IFWL_CustomPanel;\r
173 }\r
174 FWL_ERR IFWL_CustomPanel::Initialize(IFWL_Widget *pOuter )\r
175 {\r
176     m_pData = FX_NEW CFWL_CustomPanelImp(pOuter);\r
177     ((CFWL_CustomPanelImp*)m_pData)->SetInterface(this);\r
178     return ((CFWL_CustomPanelImp*)m_pData)->Initialize();\r
179 }\r
180 FWL_ERR IFWL_CustomPanel::Initialize(CFWL_WidgetImpProperties &properties, IFWL_Widget *pOuter )\r
181 {\r
182     m_pData = FX_NEW CFWL_CustomPanelImp(properties, pOuter);\r
183     ((CFWL_CustomPanelImp*)m_pData)->SetInterface(this);\r
184     return ((CFWL_CustomPanelImp*)m_pData)->Initialize();\r
185 }\r
186 IFWL_Content* IFWL_CustomPanel::GetContent()\r
187 {\r
188     return ((CFWL_CustomPanelImp*)m_pData)->GetContent();\r
189 }\r
190 FWL_ERR IFWL_CustomPanel::SetContent(IFWL_Content *pContent)\r
191 {\r
192     return ((CFWL_CustomPanelImp*)m_pData)->SetContent(pContent);\r
193 }\r
194 FWL_ERR IFWL_CustomPanel::SetProxy(IFWL_Proxy *pProxy)\r
195 {\r
196     return ((CFWL_CustomPanelImp*)m_pData)->SetProxy(pProxy);\r
197 }\r
198 IFWL_CustomPanel::IFWL_CustomPanel()\r
199 {\r
200     m_pData = NULL;\r
201 }\r
202 IFWL_CustomPanel::~IFWL_CustomPanel()\r
203 {\r
204     if (m_pData) {\r
205         delete (CFWL_CustomPanelImp*)m_pData;\r
206         m_pData = NULL;\r
207     }\r
208 }\r