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