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/include/fwl/lightwidget/widget.h" | |
8 | |
9 #include "xfa/fde/tto/fde_textout.h" | |
10 #include "xfa/fwl/core/cfwl_themetext.h" | |
11 #include "xfa/fwl/core/fwl_noteimp.h" | |
12 #include "xfa/fwl/core/fwl_noteimp.h" | |
13 #include "xfa/fwl/core/fwl_targetimp.h" | |
14 #include "xfa/fwl/core/fwl_widgetimp.h" | |
15 #include "xfa/fwl/core/fwl_widgetmgrimp.h" | |
16 #include "xfa/fwl/core/ifwl_notethread.h" | |
17 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
18 | |
19 CFWL_WidgetImpProperties CFWL_WidgetProperties::MakeWidgetImpProperties( | |
20 IFWL_DataProvider* pDataProvider) const { | |
21 CFWL_WidgetImpProperties result; | |
22 result.m_ctmOnParent = m_ctmOnParent; | |
23 result.m_rtWidget = m_rtWidget; | |
24 result.m_dwStyles = m_dwStyles; | |
25 result.m_dwStyleExes = m_dwStyleExes; | |
26 result.m_dwStates = m_dwStates; | |
27 if (m_pParent) | |
28 result.m_pParent = m_pParent->GetWidget(); | |
29 if (m_pOwner) | |
30 result.m_pOwner = m_pOwner->GetWidget(); | |
31 result.m_pDataProvider = pDataProvider; | |
32 return result; | |
33 } | |
34 IFWL_Widget* CFWL_Widget::GetWidget() { | |
35 return m_pIface; | |
36 } | |
37 FWL_ERR CFWL_Widget::GetClassName(CFX_WideString& wsClass) const { | |
38 if (!m_pIface) | |
39 return FWL_ERR_Indefinite; | |
40 return m_pIface->GetClassName(wsClass); | |
41 } | |
42 uint32_t CFWL_Widget::GetClassID() const { | |
43 if (!m_pIface) | |
44 return 0; | |
45 return m_pIface->GetClassID(); | |
46 } | |
47 FX_BOOL CFWL_Widget::IsInstance(const CFX_WideStringC& wsClass) const { | |
48 if (!m_pIface) | |
49 return FALSE; | |
50 return m_pIface->IsInstance(wsClass); | |
51 } | |
52 static void* gs_pFWLWidget = (void*)FXBSTR_ID('l', 'i', 'g', 't'); | |
53 FWL_ERR CFWL_Widget::Initialize(const CFWL_WidgetProperties* pProperties) { | |
54 if (!m_pIface) | |
55 return FWL_ERR_Indefinite; | |
56 return m_pIface->SetPrivateData(gs_pFWLWidget, this, NULL); | |
57 } | |
58 FWL_ERR CFWL_Widget::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
59 if (!m_pIface) | |
60 return FWL_ERR_Indefinite; | |
61 return m_pIface->GetWidgetRect(rect, bAutoSize); | |
62 } | |
63 FWL_ERR CFWL_Widget::GetGlobalRect(CFX_RectF& rect) { | |
64 if (!m_pIface) | |
65 return FWL_ERR_Indefinite; | |
66 return m_pIface->GetGlobalRect(rect); | |
67 } | |
68 FWL_ERR CFWL_Widget::SetWidgetRect(const CFX_RectF& rect) { | |
69 if (!m_pIface) | |
70 return FWL_ERR_Indefinite; | |
71 return m_pIface->SetWidgetRect(rect); | |
72 } | |
73 FWL_ERR CFWL_Widget::GetClientRect(CFX_RectF& rect) { | |
74 if (!m_pIface) | |
75 return FWL_ERR_Indefinite; | |
76 return m_pIface->GetClientRect(rect); | |
77 } | |
78 CFWL_Widget* CFWL_Widget::GetParent() { | |
79 if (!m_pIface) | |
80 return NULL; | |
81 IFWL_Widget* parent = m_pIface->GetParent(); | |
82 if (parent) { | |
83 return static_cast<CFWL_Widget*>(parent->GetPrivateData(gs_pFWLWidget)); | |
84 } | |
85 return NULL; | |
86 } | |
87 FWL_ERR CFWL_Widget::SetParent(CFWL_Widget* pParent) { | |
88 if (!m_pIface) | |
89 return FWL_ERR_Indefinite; | |
90 return m_pIface->SetParent(pParent ? pParent->GetWidget() : NULL); | |
91 } | |
92 CFWL_Widget* CFWL_Widget::GetOwner() { | |
93 if (!m_pIface) | |
94 return NULL; | |
95 return NULL; | |
96 } | |
97 FWL_ERR CFWL_Widget::SetOwner(CFWL_Widget* pOwner) { | |
98 if (!m_pIface) | |
99 return FWL_ERR_Indefinite; | |
100 return FWL_ERR_Succeeded; | |
101 } | |
102 uint32_t CFWL_Widget::GetStyles() { | |
103 if (!m_pIface) | |
104 return 0; | |
105 return m_pIface->GetStyles(); | |
106 } | |
107 FWL_ERR CFWL_Widget::ModifyStyles(uint32_t dwStylesAdded, | |
108 uint32_t dwStylesRemoved) { | |
109 if (!m_pIface) | |
110 return FWL_ERR_Indefinite; | |
111 return m_pIface->ModifyStyles(dwStylesAdded, dwStylesRemoved); | |
112 } | |
113 uint32_t CFWL_Widget::GetStylesEx() { | |
114 if (!m_pIface) | |
115 return 0; | |
116 return m_pIface->GetStylesEx(); | |
117 } | |
118 FWL_ERR CFWL_Widget::ModifyStylesEx(uint32_t dwStylesExAdded, | |
119 uint32_t dwStylesExRemoved) { | |
120 return m_pIface->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | |
121 } | |
122 uint32_t CFWL_Widget::GetStates() { | |
123 if (!m_pIface) | |
124 return FWL_ERR_Indefinite; | |
125 return m_pIface->GetStates(); | |
126 } | |
127 FWL_ERR CFWL_Widget::SetStates(uint32_t dwStates, FX_BOOL bSet) { | |
128 if (!m_pIface) | |
129 return FWL_ERR_Indefinite; | |
130 return m_pIface->SetStates(dwStates, bSet); | |
131 } | |
132 FWL_ERR CFWL_Widget::SetPrivateData(void* module_id, | |
133 void* pData, | |
134 PD_CALLBACK_FREEDATA callback) { | |
135 if (!m_pIface) | |
136 return FWL_ERR_Indefinite; | |
137 return m_pIface->SetPrivateData(module_id, pData, callback); | |
138 } | |
139 void* CFWL_Widget::GetPrivateData(void* module_id) { | |
140 if (!m_pIface) | |
141 return NULL; | |
142 return m_pIface->GetPrivateData(module_id); | |
143 } | |
144 FWL_ERR CFWL_Widget::Update() { | |
145 if (!m_pIface) | |
146 return FWL_ERR_Indefinite; | |
147 return m_pIface->Update(); | |
148 } | |
149 FWL_ERR CFWL_Widget::LockUpdate() { | |
150 if (!m_pIface) | |
151 return FWL_ERR_Indefinite; | |
152 return m_pIface->LockUpdate(); | |
153 } | |
154 FWL_ERR CFWL_Widget::UnlockUpdate() { | |
155 if (!m_pIface) | |
156 return FWL_ERR_Indefinite; | |
157 return m_pIface->UnlockUpdate(); | |
158 } | |
159 uint32_t CFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | |
160 if (!m_pIface) | |
161 return 0; | |
162 return m_pIface->HitTest(fx, fy); | |
163 } | |
164 FWL_ERR CFWL_Widget::TransformTo(CFWL_Widget* pWidget, | |
165 FX_FLOAT& fx, | |
166 FX_FLOAT& fy) { | |
167 if (!m_pIface) | |
168 return FWL_ERR_Indefinite; | |
169 return m_pIface->TransformTo(pWidget ? pWidget->GetWidget() : NULL, fx, fy); | |
170 } | |
171 FWL_ERR CFWL_Widget::TransformTo(CFWL_Widget* pWidget, CFX_RectF& rt) { | |
172 if (!m_pIface) | |
173 return FWL_ERR_Indefinite; | |
174 return m_pIface->TransformTo(pWidget ? pWidget->GetWidget() : NULL, rt); | |
175 } | |
176 FWL_ERR CFWL_Widget::GetMatrix(CFX_Matrix& matrix, FX_BOOL bGlobal) { | |
177 if (!m_pIface) | |
178 return FWL_ERR_Indefinite; | |
179 return m_pIface->GetMatrix(matrix, bGlobal); | |
180 } | |
181 FWL_ERR CFWL_Widget::SetMatrix(const CFX_Matrix& matrix) { | |
182 if (!m_pIface) | |
183 return FWL_ERR_Indefinite; | |
184 return m_pIface->SetMatrix(matrix); | |
185 } | |
186 FWL_ERR CFWL_Widget::DrawWidget(CFX_Graphics* pGraphics, | |
187 const CFX_Matrix* pMatrix) { | |
188 if (!m_pIface) | |
189 return FWL_ERR_Indefinite; | |
190 return m_pIface->DrawWidget(pGraphics, pMatrix); | |
191 } | |
192 IFWL_WidgetDelegate* CFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { | |
193 if (!m_pIface) | |
194 return NULL; | |
195 m_pDelegate = m_pIface->SetDelegate(pDelegate); | |
196 return m_pDelegate; | |
197 } | |
198 CFWL_Widget::CFWL_Widget() | |
199 : m_pIface(NULL), m_pDelegate(NULL), m_pProperties(NULL) { | |
200 m_pProperties = new CFWL_WidgetProperties; | |
201 m_pWidgetMgr = static_cast<CFWL_WidgetMgr*>(FWL_GetWidgetMgr()); | |
202 FXSYS_assert(m_pWidgetMgr != NULL); | |
203 } | |
204 CFWL_Widget::~CFWL_Widget() { | |
205 delete m_pProperties; | |
206 if (m_pIface) { | |
207 m_pIface->Finalize(); | |
208 delete m_pIface; | |
209 } | |
210 } | |
211 FWL_ERR CFWL_Widget::Repaint(const CFX_RectF* pRect) { | |
212 if (!m_pIface) | |
213 return FWL_ERR_Indefinite; | |
214 CFX_RectF rect; | |
215 if (pRect) { | |
216 rect = *pRect; | |
217 } else { | |
218 m_pIface->GetWidgetRect(rect); | |
219 rect.left = rect.top = 0; | |
220 } | |
221 return m_pWidgetMgr->RepaintWidget(m_pIface, &rect); | |
222 } | |
223 FWL_ERR CFWL_Widget::SetFocus(FX_BOOL bFocus) { | |
224 if (!m_pIface) | |
225 return FWL_ERR_Indefinite; | |
226 IFWL_NoteThread* pThread = m_pIface->GetOwnerThread(); | |
227 if (!pThread) | |
228 return FWL_ERR_Indefinite; | |
229 IFWL_NoteDriver* pDriver = pThread->GetNoteDriver(); | |
230 if (!pDriver) | |
231 return FWL_ERR_Indefinite; | |
232 if (bFocus) { | |
233 pDriver->SetFocus(m_pIface); | |
234 } else { | |
235 if (pDriver->GetFocus() == m_pIface) { | |
236 pDriver->SetFocus(NULL); | |
237 } | |
238 } | |
239 return FWL_ERR_Succeeded; | |
240 } | |
241 FWL_ERR CFWL_Widget::SetGrab(FX_BOOL bSet) { | |
242 if (!m_pIface) | |
243 return FWL_ERR_Indefinite; | |
244 IFWL_NoteThread* pThread = m_pIface->GetOwnerThread(); | |
245 if (!pThread) | |
246 return FWL_ERR_Indefinite; | |
247 IFWL_NoteDriver* pDriver = pThread->GetNoteDriver(); | |
248 if (!pDriver) | |
249 return FWL_ERR_Indefinite; | |
250 pDriver->SetGrab(m_pIface, bSet); | |
251 return FWL_ERR_Succeeded; | |
252 } | |
253 void CFWL_Widget::RegisterEventTarget(CFWL_Widget* pEventSource, | |
254 uint32_t dwFilter) { | |
255 if (!m_pIface) | |
256 return; | |
257 IFWL_NoteThread* pThread = m_pIface->GetOwnerThread(); | |
258 if (!pThread) | |
259 return; | |
260 IFWL_NoteDriver* pNoteDriver = pThread->GetNoteDriver(); | |
261 if (!pNoteDriver) | |
262 return; | |
263 IFWL_Widget* pEventSourceImp = | |
264 !pEventSource ? NULL : pEventSource->GetWidget(); | |
265 pNoteDriver->RegisterEventTarget(GetWidget(), pEventSourceImp, dwFilter); | |
266 } | |
267 void CFWL_Widget::DispatchEvent(CFWL_Event* pEvent) { | |
268 if (!m_pIface) | |
269 return; | |
270 if (m_pIface->GetOuter()) { | |
271 return; | |
272 } | |
273 IFWL_NoteThread* pThread = m_pIface->GetOwnerThread(); | |
274 if (!pThread) | |
275 return; | |
276 IFWL_NoteDriver* pNoteDriver = pThread->GetNoteDriver(); | |
277 if (!pNoteDriver) | |
278 return; | |
279 pNoteDriver->SendNote(pEvent); | |
280 } | |
281 #define FWL_WGT_CalcHeight 2048 | |
282 #define FWL_WGT_CalcWidth 2048 | |
283 #define FWL_WGT_CalcMultiLineDefWidth 120.0f | |
284 CFX_SizeF CFWL_Widget::CalcTextSize(const CFX_WideString& wsText, | |
285 FX_BOOL bMultiLine, | |
286 int32_t iLineWidth) { | |
287 if (!m_pIface) | |
288 return CFX_SizeF(); | |
289 IFWL_ThemeProvider* pTheme = m_pIface->GetThemeProvider(); | |
290 if (!pTheme) | |
291 return CFX_SizeF(); | |
292 | |
293 CFWL_ThemeText calPart; | |
294 calPart.m_pWidget = m_pIface; | |
295 calPart.m_wsText = wsText; | |
296 calPart.m_dwTTOStyles = | |
297 bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine; | |
298 calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; | |
299 CFX_RectF rect; | |
300 FX_FLOAT fWidth = bMultiLine | |
301 ? (iLineWidth > 0 ? (FX_FLOAT)iLineWidth | |
302 : FWL_WGT_CalcMultiLineDefWidth) | |
303 : FWL_WGT_CalcWidth; | |
304 rect.Set(0, 0, fWidth, FWL_WGT_CalcHeight); | |
305 pTheme->CalcTextRect(&calPart, rect); | |
306 return CFX_SizeF(rect.width, rect.height); | |
307 } | |
308 CFWL_WidgetDelegate::CFWL_WidgetDelegate() {} | |
309 CFWL_WidgetDelegate::~CFWL_WidgetDelegate() {} | |
310 int32_t CFWL_WidgetDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
311 return 1; | |
312 } | |
313 FWL_ERR CFWL_WidgetDelegate::OnProcessEvent(CFWL_Event* pEvent) { | |
314 return FWL_ERR_Succeeded; | |
315 } | |
316 FWL_ERR CFWL_WidgetDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
317 const CFX_Matrix* pMatrix) { | |
318 return FWL_ERR_Succeeded; | |
319 } | |
OLD | NEW |