Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1496)

Side by Side Diff: xfa/fwl/core/ifwl_widget.cpp

Issue 2524173002: Merge IFWL and CFWL classes. (Closed)
Patch Set: make chrome build happy Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/fwl/core/ifwl_widget.h"
8
9 #include <algorithm>
10 #include <utility>
11
12 #include "xfa/fde/tto/fde_textout.h"
13 #include "xfa/fwl/core/cfwl_app.h"
14 #include "xfa/fwl/core/cfwl_evtkey.h"
15 #include "xfa/fwl/core/cfwl_evtkillfocus.h"
16 #include "xfa/fwl/core/cfwl_evtmouse.h"
17 #include "xfa/fwl/core/cfwl_evtmousewheel.h"
18 #include "xfa/fwl/core/cfwl_evtsetfocus.h"
19 #include "xfa/fwl/core/cfwl_evtsizechanged.h"
20 #include "xfa/fwl/core/cfwl_form.h"
21 #include "xfa/fwl/core/cfwl_msgkey.h"
22 #include "xfa/fwl/core/cfwl_msgkillfocus.h"
23 #include "xfa/fwl/core/cfwl_msgmouse.h"
24 #include "xfa/fwl/core/cfwl_msgmousewheel.h"
25 #include "xfa/fwl/core/cfwl_msgsetfocus.h"
26 #include "xfa/fwl/core/cfwl_notedriver.h"
27 #include "xfa/fwl/core/cfwl_themebackground.h"
28 #include "xfa/fwl/core/cfwl_themepart.h"
29 #include "xfa/fwl/core/cfwl_themetext.h"
30 #include "xfa/fwl/core/cfwl_widgetmgr.h"
31 #include "xfa/fwl/core/ifwl_combobox.h"
32 #include "xfa/fwl/core/ifwl_themeprovider.h"
33 #include "xfa/fxfa/xfa_ffapp.h"
34
35 #define FWL_STYLEEXT_MNU_Vert (1L << 0)
36 #define FWL_WGT_CalcHeight 2048
37 #define FWL_WGT_CalcWidth 2048
38 #define FWL_WGT_CalcMultiLineDefWidth 120.0f
39
40 IFWL_Widget::IFWL_Widget(const CFWL_App* app,
41 std::unique_ptr<CFWL_WidgetProperties> properties,
42 IFWL_Widget* pOuter)
43 : m_pOwnerApp(app),
44 m_pWidgetMgr(app->GetWidgetMgr()),
45 m_pProperties(std::move(properties)),
46 m_pOuter(pOuter),
47 m_iLock(0),
48 m_pLayoutItem(nullptr),
49 m_pAssociate(nullptr),
50 m_nEventKey(0),
51 m_pDelegate(nullptr) {
52 ASSERT(m_pWidgetMgr);
53
54 IFWL_Widget* pParent = m_pProperties->m_pParent;
55 m_pWidgetMgr->InsertWidget(pParent, this);
56 if (IsChild())
57 return;
58
59 IFWL_Widget* pOwner = m_pProperties->m_pOwner;
60 if (pOwner)
61 m_pWidgetMgr->SetOwner(pOwner, this);
62 }
63
64 IFWL_Widget::~IFWL_Widget() {
65 NotifyDriver();
66 m_pWidgetMgr->RemoveWidget(this);
67 }
68
69 bool IFWL_Widget::IsInstance(const CFX_WideStringC& wsClass) const {
70 return false;
71 }
72
73 void IFWL_Widget::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) {
74 if (!bAutoSize) {
75 rect = m_pProperties->m_rtWidget;
76 return;
77 }
78
79 if (HasEdge()) {
80 FX_FLOAT fEdge = GetEdgeWidth();
81 rect.Inflate(fEdge, fEdge);
82 }
83 if (HasBorder()) {
84 FX_FLOAT fBorder = GetBorderSize();
85 rect.Inflate(fBorder, fBorder);
86 }
87 }
88
89 void IFWL_Widget::SetWidgetRect(const CFX_RectF& rect) {
90 CFX_RectF rtOld = m_pProperties->m_rtWidget;
91 m_pProperties->m_rtWidget = rect;
92 if (IsChild()) {
93 if (FXSYS_fabs(rtOld.width - rect.width) > 0.5f ||
94 FXSYS_fabs(rtOld.height - rect.height) > 0.5f) {
95 CFWL_EvtSizeChanged ev;
96 ev.m_pSrcTarget = this;
97 ev.m_rtOld = rtOld;
98 ev.m_rtNew = rect;
99
100 if (IFWL_WidgetDelegate* pDelegate = GetDelegate())
101 pDelegate->OnProcessEvent(&ev);
102 }
103 return;
104 }
105 m_pWidgetMgr->SetWidgetRect_Native(this, rect);
106 }
107
108 void IFWL_Widget::GetClientRect(CFX_RectF& rect) {
109 GetEdgeRect(rect);
110 if (HasEdge()) {
111 FX_FLOAT fEdge = GetEdgeWidth();
112 rect.Deflate(fEdge, fEdge);
113 }
114 }
115
116 void IFWL_Widget::SetParent(IFWL_Widget* pParent) {
117 m_pProperties->m_pParent = pParent;
118 m_pWidgetMgr->SetParent(pParent, this);
119 }
120
121 uint32_t IFWL_Widget::GetStyles() const {
122 return m_pProperties->m_dwStyles;
123 }
124
125 void IFWL_Widget::ModifyStyles(uint32_t dwStylesAdded,
126 uint32_t dwStylesRemoved) {
127 m_pProperties->m_dwStyles =
128 (m_pProperties->m_dwStyles & ~dwStylesRemoved) | dwStylesAdded;
129 }
130
131 uint32_t IFWL_Widget::GetStylesEx() const {
132 return m_pProperties->m_dwStyleExes;
133 }
134 uint32_t IFWL_Widget::GetStates() const {
135 return m_pProperties->m_dwStates;
136 }
137
138 void IFWL_Widget::ModifyStylesEx(uint32_t dwStylesExAdded,
139 uint32_t dwStylesExRemoved) {
140 m_pProperties->m_dwStyleExes =
141 (m_pProperties->m_dwStyleExes & ~dwStylesExRemoved) | dwStylesExAdded;
142 }
143
144 static void NotifyHideChildWidget(CFWL_WidgetMgr* widgetMgr,
145 IFWL_Widget* widget,
146 CFWL_NoteDriver* noteDriver) {
147 IFWL_Widget* child = widgetMgr->GetFirstChildWidget(widget);
148 while (child) {
149 noteDriver->NotifyTargetHide(child);
150 NotifyHideChildWidget(widgetMgr, child, noteDriver);
151 child = widgetMgr->GetNextSiblingWidget(child);
152 }
153 }
154
155 void IFWL_Widget::SetStates(uint32_t dwStates, bool bSet) {
156 bSet ? (m_pProperties->m_dwStates |= dwStates)
157 : (m_pProperties->m_dwStates &= ~dwStates);
158 if (!(dwStates & FWL_WGTSTATE_Invisible) || !bSet)
159 return;
160
161 CFWL_NoteDriver* noteDriver =
162 static_cast<CFWL_NoteDriver*>(GetOwnerApp()->GetNoteDriver());
163 CFWL_WidgetMgr* widgetMgr = GetOwnerApp()->GetWidgetMgr();
164 noteDriver->NotifyTargetHide(this);
165 IFWL_Widget* child = widgetMgr->GetFirstChildWidget(this);
166 while (child) {
167 noteDriver->NotifyTargetHide(child);
168 NotifyHideChildWidget(widgetMgr, child, noteDriver);
169 child = widgetMgr->GetNextSiblingWidget(child);
170 }
171 return;
172 }
173
174 FWL_WidgetHit IFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) {
175 CFX_RectF rtClient;
176 GetClientRect(rtClient);
177 if (rtClient.Contains(fx, fy))
178 return FWL_WidgetHit::Client;
179 if (HasEdge()) {
180 CFX_RectF rtEdge;
181 GetEdgeRect(rtEdge);
182 if (rtEdge.Contains(fx, fy))
183 return FWL_WidgetHit::Edge;
184 }
185 if (HasBorder()) {
186 CFX_RectF rtRelative;
187 GetRelativeRect(rtRelative);
188 if (rtRelative.Contains(fx, fy))
189 return FWL_WidgetHit::Border;
190 }
191 return FWL_WidgetHit::Unknown;
192 }
193
194 void IFWL_Widget::TransformTo(IFWL_Widget* pWidget,
195 FX_FLOAT& fx,
196 FX_FLOAT& fy) {
197 if (m_pWidgetMgr->IsFormDisabled()) {
198 CFX_SizeF szOffset;
199 if (IsParent(pWidget)) {
200 szOffset = GetOffsetFromParent(pWidget);
201 } else {
202 szOffset = pWidget->GetOffsetFromParent(this);
203 szOffset.x = -szOffset.x;
204 szOffset.y = -szOffset.y;
205 }
206 fx += szOffset.x;
207 fy += szOffset.y;
208 return;
209 }
210 CFX_RectF r;
211 CFX_Matrix m;
212 IFWL_Widget* parent = GetParent();
213 if (parent) {
214 GetWidgetRect(r);
215 fx += r.left;
216 fy += r.top;
217 GetMatrix(m, true);
218 m.TransformPoint(fx, fy);
219 }
220 IFWL_Widget* form1 = m_pWidgetMgr->GetSystemFormWidget(this);
221 if (!form1)
222 return;
223 if (!pWidget) {
224 form1->GetWidgetRect(r);
225 fx += r.left;
226 fy += r.top;
227 return;
228 }
229 IFWL_Widget* form2 = m_pWidgetMgr->GetSystemFormWidget(pWidget);
230 if (!form2)
231 return;
232 if (form1 != form2) {
233 form1->GetWidgetRect(r);
234 fx += r.left;
235 fy += r.top;
236 form2->GetWidgetRect(r);
237 fx -= r.left;
238 fy -= r.top;
239 }
240 parent = pWidget->GetParent();
241 if (parent) {
242 pWidget->GetMatrix(m, true);
243 CFX_Matrix m1;
244 m1.SetIdentity();
245 m1.SetReverse(m);
246 m1.TransformPoint(fx, fy);
247 pWidget->GetWidgetRect(r);
248 fx -= r.left;
249 fy -= r.top;
250 }
251 }
252
253 void IFWL_Widget::GetMatrix(CFX_Matrix& matrix, bool bGlobal) {
254 if (!m_pProperties)
255 return;
256 if (!bGlobal) {
257 matrix.SetIdentity();
258 return;
259 }
260
261 IFWL_Widget* parent = GetParent();
262 CFX_ArrayTemplate<IFWL_Widget*> parents;
263 while (parent) {
264 parents.Add(parent);
265 parent = parent->GetParent();
266 }
267 matrix.SetIdentity();
268 CFX_Matrix ctmOnParent;
269 CFX_RectF rect;
270 int32_t count = parents.GetSize();
271 for (int32_t i = count - 2; i >= 0; i--) {
272 parent = parents.GetAt(i);
273 parent->GetMatrix(ctmOnParent, false);
274 parent->GetWidgetRect(rect);
275 matrix.Concat(ctmOnParent, true);
276 matrix.Translate(rect.left, rect.top, true);
277 }
278 CFX_Matrix m;
279 m.SetIdentity();
280 matrix.Concat(m, true);
281 parents.RemoveAll();
282 }
283
284 IFWL_ThemeProvider* IFWL_Widget::GetThemeProvider() const {
285 return m_pProperties->m_pThemeProvider;
286 }
287
288 void IFWL_Widget::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
289 m_pProperties->m_pThemeProvider = pThemeProvider;
290 }
291
292 bool IFWL_Widget::IsEnabled() const {
293 return (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == 0;
294 }
295
296 bool IFWL_Widget::IsActive() const {
297 return (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) == 0;
298 }
299
300 bool IFWL_Widget::HasBorder() const {
301 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border);
302 }
303
304 bool IFWL_Widget::HasEdge() const {
305 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_EdgeMask);
306 }
307
308 bool IFWL_Widget::IsVisible() const {
309 return (m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) == 0;
310 }
311
312 bool IFWL_Widget::IsOverLapper() const {
313 return (m_pProperties->m_dwStyles & FWL_WGTSTYLE_WindowTypeMask) ==
314 FWL_WGTSTYLE_OverLapper;
315 }
316
317 bool IFWL_Widget::IsPopup() const {
318 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Popup);
319 }
320
321 bool IFWL_Widget::IsChild() const {
322 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Child);
323 }
324
325 bool IFWL_Widget::IsOffscreen() const {
326 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Offscreen);
327 }
328
329 void IFWL_Widget::GetEdgeRect(CFX_RectF& rtEdge) {
330 rtEdge = m_pProperties->m_rtWidget;
331 rtEdge.left = rtEdge.top = 0;
332 if (HasBorder()) {
333 FX_FLOAT fCX = GetBorderSize();
334 FX_FLOAT fCY = GetBorderSize(false);
335 rtEdge.Deflate(fCX, fCY);
336 }
337 }
338
339 FX_FLOAT IFWL_Widget::GetBorderSize(bool bCX) {
340 FX_FLOAT* pfBorder = static_cast<FX_FLOAT*>(GetThemeCapacity(
341 bCX ? CFWL_WidgetCapacity::CXBorder : CFWL_WidgetCapacity::CYBorder));
342 if (!pfBorder)
343 return 0;
344 return *pfBorder;
345 }
346
347 FX_FLOAT IFWL_Widget::GetEdgeWidth() {
348 CFWL_WidgetCapacity dwCapacity = CFWL_WidgetCapacity::None;
349 switch (m_pProperties->m_dwStyles & FWL_WGTSTYLE_EdgeMask) {
350 case FWL_WGTSTYLE_EdgeFlat: {
351 dwCapacity = CFWL_WidgetCapacity::EdgeFlat;
352 break;
353 }
354 case FWL_WGTSTYLE_EdgeRaised: {
355 dwCapacity = CFWL_WidgetCapacity::EdgeRaised;
356 break;
357 }
358 case FWL_WGTSTYLE_EdgeSunken: {
359 dwCapacity = CFWL_WidgetCapacity::EdgeSunken;
360 break;
361 }
362 }
363 if (dwCapacity != CFWL_WidgetCapacity::None) {
364 FX_FLOAT* fRet = static_cast<FX_FLOAT*>(GetThemeCapacity(dwCapacity));
365 return fRet ? *fRet : 0;
366 }
367 return 0;
368 }
369
370 void IFWL_Widget::GetRelativeRect(CFX_RectF& rect) {
371 rect = m_pProperties->m_rtWidget;
372 rect.left = rect.top = 0;
373 }
374
375 void* IFWL_Widget::GetThemeCapacity(CFWL_WidgetCapacity dwCapacity) {
376 IFWL_ThemeProvider* pTheme = GetAvailableTheme();
377 if (!pTheme)
378 return nullptr;
379
380 CFWL_ThemePart part;
381 part.m_pWidget = this;
382 return pTheme->GetCapacity(&part, dwCapacity);
383 }
384
385 IFWL_ThemeProvider* IFWL_Widget::GetAvailableTheme() {
386 if (m_pProperties->m_pThemeProvider)
387 return m_pProperties->m_pThemeProvider;
388
389 IFWL_Widget* pUp = this;
390 do {
391 pUp = (pUp->GetStyles() & FWL_WGTSTYLE_Popup)
392 ? m_pWidgetMgr->GetOwnerWidget(pUp)
393 : m_pWidgetMgr->GetParentWidget(pUp);
394 if (pUp) {
395 IFWL_ThemeProvider* pRet = pUp->GetThemeProvider();
396 if (pRet)
397 return pRet;
398 }
399 } while (pUp);
400 return nullptr;
401 }
402
403 IFWL_Widget* IFWL_Widget::GetRootOuter() {
404 IFWL_Widget* pRet = m_pOuter;
405 if (!pRet)
406 return nullptr;
407
408 while (IFWL_Widget* pOuter = pRet->GetOuter())
409 pRet = pOuter;
410 return pRet;
411 }
412
413 CFX_SizeF IFWL_Widget::CalcTextSize(const CFX_WideString& wsText,
414 IFWL_ThemeProvider* pTheme,
415 bool bMultiLine,
416 int32_t iLineWidth) {
417 if (!pTheme)
418 return CFX_SizeF();
419
420 CFWL_ThemeText calPart;
421 calPart.m_pWidget = this;
422 calPart.m_wsText = wsText;
423 calPart.m_dwTTOStyles =
424 bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine;
425 calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft;
426 CFX_RectF rect;
427 FX_FLOAT fWidth = bMultiLine
428 ? (iLineWidth > 0 ? (FX_FLOAT)iLineWidth
429 : FWL_WGT_CalcMultiLineDefWidth)
430 : FWL_WGT_CalcWidth;
431 rect.Set(0, 0, fWidth, FWL_WGT_CalcHeight);
432 pTheme->CalcTextRect(&calPart, rect);
433 return CFX_SizeF(rect.width, rect.height);
434 }
435
436 void IFWL_Widget::CalcTextRect(const CFX_WideString& wsText,
437 IFWL_ThemeProvider* pTheme,
438 uint32_t dwTTOStyles,
439 int32_t iTTOAlign,
440 CFX_RectF& rect) {
441 CFWL_ThemeText calPart;
442 calPart.m_pWidget = this;
443 calPart.m_wsText = wsText;
444 calPart.m_dwTTOStyles = dwTTOStyles;
445 calPart.m_iTTOAlign = iTTOAlign;
446 pTheme->CalcTextRect(&calPart, rect);
447 }
448
449 void IFWL_Widget::SetFocus(bool bFocus) {
450 if (m_pWidgetMgr->IsFormDisabled())
451 return;
452
453 const CFWL_App* pApp = GetOwnerApp();
454 if (!pApp)
455 return;
456
457 CFWL_NoteDriver* pDriver =
458 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver());
459 if (!pDriver)
460 return;
461
462 IFWL_Widget* curFocus = pDriver->GetFocus();
463 if (bFocus && curFocus != this)
464 pDriver->SetFocus(this);
465 else if (!bFocus && curFocus == this)
466 pDriver->SetFocus(nullptr);
467 }
468
469 void IFWL_Widget::SetGrab(bool bSet) {
470 const CFWL_App* pApp = GetOwnerApp();
471 if (!pApp)
472 return;
473
474 CFWL_NoteDriver* pDriver =
475 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver());
476 pDriver->SetGrab(this, bSet);
477 }
478
479 void IFWL_Widget::GetPopupPos(FX_FLOAT fMinHeight,
480 FX_FLOAT fMaxHeight,
481 const CFX_RectF& rtAnchor,
482 CFX_RectF& rtPopup) {
483 if (GetClassID() == FWL_Type::ComboBox) {
484 if (m_pWidgetMgr->IsFormDisabled()) {
485 m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor,
486 rtPopup);
487 return;
488 }
489 GetPopupPosComboBox(fMinHeight, fMaxHeight, rtAnchor, rtPopup);
490 return;
491 }
492 if (GetClassID() == FWL_Type::DateTimePicker &&
493 m_pWidgetMgr->IsFormDisabled()) {
494 m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor,
495 rtPopup);
496 return;
497 }
498 GetPopupPosGeneral(fMinHeight, fMaxHeight, rtAnchor, rtPopup);
499 }
500
501 bool IFWL_Widget::GetPopupPosMenu(FX_FLOAT fMinHeight,
502 FX_FLOAT fMaxHeight,
503 const CFX_RectF& rtAnchor,
504 CFX_RectF& rtPopup) {
505 FX_FLOAT fx = 0;
506 FX_FLOAT fy = 0;
507
508 if (GetStylesEx() & FWL_STYLEEXT_MNU_Vert) {
509 bool bLeft = m_pProperties->m_rtWidget.left < 0;
510 FX_FLOAT fRight = rtAnchor.right() + rtPopup.width;
511 TransformTo(nullptr, fx, fy);
512 if (fRight + fx > 0.0f || bLeft) {
513 rtPopup.Set(rtAnchor.left - rtPopup.width, rtAnchor.top, rtPopup.width,
514 rtPopup.height);
515 } else {
516 rtPopup.Set(rtAnchor.right(), rtAnchor.top, rtPopup.width,
517 rtPopup.height);
518 }
519 } else {
520 FX_FLOAT fBottom = rtAnchor.bottom() + rtPopup.height;
521 TransformTo(nullptr, fx, fy);
522 if (fBottom + fy > 0.0f) {
523 rtPopup.Set(rtAnchor.left, rtAnchor.top - rtPopup.height, rtPopup.width,
524 rtPopup.height);
525 } else {
526 rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), rtPopup.width,
527 rtPopup.height);
528 }
529 }
530 rtPopup.Offset(fx, fy);
531 return true;
532 }
533
534 bool IFWL_Widget::GetPopupPosComboBox(FX_FLOAT fMinHeight,
535 FX_FLOAT fMaxHeight,
536 const CFX_RectF& rtAnchor,
537 CFX_RectF& rtPopup) {
538 FX_FLOAT fx = 0;
539 FX_FLOAT fy = 0;
540
541 FX_FLOAT fPopHeight = rtPopup.height;
542 if (rtPopup.height > fMaxHeight)
543 fPopHeight = fMaxHeight;
544 else if (rtPopup.height < fMinHeight)
545 fPopHeight = fMinHeight;
546
547 FX_FLOAT fWidth = std::max(rtAnchor.width, rtPopup.width);
548 FX_FLOAT fBottom = rtAnchor.bottom() + fPopHeight;
549 TransformTo(nullptr, fx, fy);
550 if (fBottom + fy > 0.0f)
551 rtPopup.Set(rtAnchor.left, rtAnchor.top - fPopHeight, fWidth, fPopHeight);
552 else
553 rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), fWidth, fPopHeight);
554
555 rtPopup.Offset(fx, fy);
556 return true;
557 }
558
559 bool IFWL_Widget::GetPopupPosGeneral(FX_FLOAT fMinHeight,
560 FX_FLOAT fMaxHeight,
561 const CFX_RectF& rtAnchor,
562 CFX_RectF& rtPopup) {
563 FX_FLOAT fx = 0;
564 FX_FLOAT fy = 0;
565
566 TransformTo(nullptr, fx, fy);
567 if (rtAnchor.bottom() + fy > 0.0f) {
568 rtPopup.Set(rtAnchor.left, rtAnchor.top - rtPopup.height, rtPopup.width,
569 rtPopup.height);
570 } else {
571 rtPopup.Set(rtAnchor.left, rtAnchor.bottom(), rtPopup.width,
572 rtPopup.height);
573 }
574 rtPopup.Offset(fx, fy);
575 return true;
576 }
577
578 void IFWL_Widget::RegisterEventTarget(IFWL_Widget* pEventSource) {
579 const CFWL_App* pApp = GetOwnerApp();
580 if (!pApp)
581 return;
582
583 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver();
584 if (!pNoteDriver)
585 return;
586
587 pNoteDriver->RegisterEventTarget(this, pEventSource);
588 }
589
590 void IFWL_Widget::UnregisterEventTarget() {
591 const CFWL_App* pApp = GetOwnerApp();
592 if (!pApp)
593 return;
594
595 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver();
596 if (!pNoteDriver)
597 return;
598
599 pNoteDriver->UnregisterEventTarget(this);
600 }
601
602 void IFWL_Widget::DispatchKeyEvent(CFWL_MsgKey* pNote) {
603 if (!pNote)
604 return;
605
606 auto pEvent = pdfium::MakeUnique<CFWL_EvtKey>();
607 pEvent->m_pSrcTarget = this;
608 pEvent->m_dwCmd = pNote->m_dwCmd;
609 pEvent->m_dwKeyCode = pNote->m_dwKeyCode;
610 pEvent->m_dwFlags = pNote->m_dwFlags;
611 DispatchEvent(pEvent.get());
612 }
613
614 void IFWL_Widget::DispatchEvent(CFWL_Event* pEvent) {
615 if (m_pOuter) {
616 m_pOuter->GetDelegate()->OnProcessEvent(pEvent);
617 return;
618 }
619 const CFWL_App* pApp = GetOwnerApp();
620 if (!pApp)
621 return;
622
623 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver();
624 if (!pNoteDriver)
625 return;
626 pNoteDriver->SendEvent(pEvent);
627 }
628
629 void IFWL_Widget::Repaint(const CFX_RectF* pRect) {
630 if (pRect) {
631 m_pWidgetMgr->RepaintWidget(this, pRect);
632 return;
633 }
634 CFX_RectF rect;
635 rect = m_pProperties->m_rtWidget;
636 rect.left = rect.top = 0;
637 m_pWidgetMgr->RepaintWidget(this, &rect);
638 }
639
640 void IFWL_Widget::DrawBackground(CFX_Graphics* pGraphics,
641 CFWL_Part iPartBk,
642 IFWL_ThemeProvider* pTheme,
643 const CFX_Matrix* pMatrix) {
644 CFX_RectF rtRelative;
645 GetRelativeRect(rtRelative);
646 CFWL_ThemeBackground param;
647 param.m_pWidget = this;
648 param.m_iPart = iPartBk;
649 param.m_pGraphics = pGraphics;
650 if (pMatrix)
651 param.m_matrix.Concat(*pMatrix, true);
652 param.m_rtPart = rtRelative;
653 pTheme->DrawBackground(&param);
654 }
655
656 void IFWL_Widget::DrawBorder(CFX_Graphics* pGraphics,
657 CFWL_Part iPartBorder,
658 IFWL_ThemeProvider* pTheme,
659 const CFX_Matrix* pMatrix) {
660 CFX_RectF rtRelative;
661 GetRelativeRect(rtRelative);
662 CFWL_ThemeBackground param;
663 param.m_pWidget = this;
664 param.m_iPart = iPartBorder;
665 param.m_pGraphics = pGraphics;
666 if (pMatrix)
667 param.m_matrix.Concat(*pMatrix, true);
668 param.m_rtPart = rtRelative;
669 pTheme->DrawBackground(&param);
670 }
671
672 void IFWL_Widget::DrawEdge(CFX_Graphics* pGraphics,
673 CFWL_Part iPartEdge,
674 IFWL_ThemeProvider* pTheme,
675 const CFX_Matrix* pMatrix) {
676 CFX_RectF rtEdge;
677 GetEdgeRect(rtEdge);
678 CFWL_ThemeBackground param;
679 param.m_pWidget = this;
680 param.m_iPart = iPartEdge;
681 param.m_pGraphics = pGraphics;
682 if (pMatrix)
683 param.m_matrix.Concat(*pMatrix, true);
684 param.m_rtPart = rtEdge;
685 pTheme->DrawBackground(&param);
686 }
687
688 void IFWL_Widget::NotifyDriver() {
689 const CFWL_App* pApp = GetOwnerApp();
690 if (!pApp)
691 return;
692
693 CFWL_NoteDriver* pDriver =
694 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver());
695 if (!pDriver)
696 return;
697
698 pDriver->NotifyTargetDestroy(this);
699 }
700
701 CFX_SizeF IFWL_Widget::GetOffsetFromParent(IFWL_Widget* pParent) {
702 if (pParent == this)
703 return CFX_SizeF();
704
705 CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr();
706 if (!pWidgetMgr)
707 return CFX_SizeF();
708
709 CFX_SizeF szRet(m_pProperties->m_rtWidget.left,
710 m_pProperties->m_rtWidget.top);
711
712 IFWL_Widget* pDstWidget = GetParent();
713 while (pDstWidget && pDstWidget != pParent) {
714 CFX_RectF rtDst;
715 pDstWidget->GetWidgetRect(rtDst);
716 szRet += CFX_SizeF(rtDst.left, rtDst.top);
717 pDstWidget = pWidgetMgr->GetParentWidget(pDstWidget);
718 }
719 return szRet;
720 }
721
722 bool IFWL_Widget::IsParent(IFWL_Widget* pParent) {
723 IFWL_Widget* pUpWidget = GetParent();
724 while (pUpWidget) {
725 if (pUpWidget == pParent)
726 return true;
727 pUpWidget = pUpWidget->GetParent();
728 }
729 return false;
730 }
731
732 void IFWL_Widget::OnProcessMessage(CFWL_Message* pMessage) {
733 if (!pMessage->m_pDstTarget)
734 return;
735
736 IFWL_Widget* pWidget = pMessage->m_pDstTarget;
737 CFWL_MessageType dwMsgCode = pMessage->GetClassID();
738 switch (dwMsgCode) {
739 case CFWL_MessageType::Mouse: {
740 CFWL_MsgMouse* pMsgMouse = static_cast<CFWL_MsgMouse*>(pMessage);
741 CFWL_EvtMouse evt;
742 evt.m_pSrcTarget = pWidget;
743 evt.m_pDstTarget = pWidget;
744 evt.m_dwCmd = pMsgMouse->m_dwCmd;
745 evt.m_dwFlags = pMsgMouse->m_dwFlags;
746 evt.m_fx = pMsgMouse->m_fx;
747 evt.m_fy = pMsgMouse->m_fy;
748 pWidget->DispatchEvent(&evt);
749 break;
750 }
751 case CFWL_MessageType::MouseWheel: {
752 CFWL_MsgMouseWheel* pMsgMouseWheel =
753 static_cast<CFWL_MsgMouseWheel*>(pMessage);
754 CFWL_EvtMouseWheel evt;
755 evt.m_pSrcTarget = pWidget;
756 evt.m_pDstTarget = pWidget;
757 evt.m_dwFlags = pMsgMouseWheel->m_dwFlags;
758 evt.m_fDeltaX = pMsgMouseWheel->m_fDeltaX;
759 evt.m_fDeltaY = pMsgMouseWheel->m_fDeltaY;
760 evt.m_fx = pMsgMouseWheel->m_fx;
761 evt.m_fy = pMsgMouseWheel->m_fy;
762 pWidget->DispatchEvent(&evt);
763 break;
764 }
765 case CFWL_MessageType::Key: {
766 CFWL_MsgKey* pMsgKey = static_cast<CFWL_MsgKey*>(pMessage);
767 CFWL_EvtKey evt;
768 evt.m_pSrcTarget = pWidget;
769 evt.m_pDstTarget = pWidget;
770 evt.m_dwKeyCode = pMsgKey->m_dwKeyCode;
771 evt.m_dwFlags = pMsgKey->m_dwFlags;
772 evt.m_dwCmd = pMsgKey->m_dwCmd;
773 pWidget->DispatchEvent(&evt);
774 break;
775 }
776 case CFWL_MessageType::SetFocus: {
777 CFWL_MsgSetFocus* pMsgSetFocus = static_cast<CFWL_MsgSetFocus*>(pMessage);
778 CFWL_EvtSetFocus evt;
779 evt.m_pSrcTarget = pMsgSetFocus->m_pDstTarget;
780 evt.m_pDstTarget = pMsgSetFocus->m_pDstTarget;
781 evt.m_pSetFocus = pWidget;
782 pWidget->DispatchEvent(&evt);
783 break;
784 }
785 case CFWL_MessageType::KillFocus: {
786 CFWL_MsgKillFocus* pMsgKillFocus =
787 static_cast<CFWL_MsgKillFocus*>(pMessage);
788 CFWL_EvtKillFocus evt;
789 evt.m_pSrcTarget = pMsgKillFocus->m_pDstTarget;
790 evt.m_pDstTarget = pMsgKillFocus->m_pDstTarget;
791 evt.m_pKillFocus = pWidget;
792 pWidget->DispatchEvent(&evt);
793 break;
794 }
795 default:
796 break;
797 }
798 }
799
800 void IFWL_Widget::OnProcessEvent(CFWL_Event* pEvent) {}
801
802 void IFWL_Widget::OnDrawWidget(CFX_Graphics* pGraphics,
803 const CFX_Matrix* pMatrix) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698