blob: a2c270c332a8e570e26971d4ec9c898d49ee58ec [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// 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
dsinclair447b1f32016-12-08 10:06:32 -08007#include "xfa/fwl/cfwl_widget.h"
Dan Sinclair1770c022016-03-14 14:14:16 -04008
dsinclair2c489cc2016-11-23 16:17:20 -08009#include <algorithm>
10#include <utility>
Tom Sepez576e8152017-01-30 14:26:24 -080011#include <vector>
dsinclair2c489cc2016-11-23 16:17:20 -080012
Tom Sepez576e8152017-01-30 14:26:24 -080013#include "third_party/base/stl_util.h"
Dan Sinclairbccf5732017-03-30 14:10:32 -040014#include "xfa/fde/cfde_textout.h"
dsinclair447b1f32016-12-08 10:06:32 -080015#include "xfa/fwl/cfwl_app.h"
16#include "xfa/fwl/cfwl_combobox.h"
17#include "xfa/fwl/cfwl_event.h"
18#include "xfa/fwl/cfwl_eventmouse.h"
19#include "xfa/fwl/cfwl_form.h"
20#include "xfa/fwl/cfwl_messagekey.h"
21#include "xfa/fwl/cfwl_messagekillfocus.h"
22#include "xfa/fwl/cfwl_messagemouse.h"
23#include "xfa/fwl/cfwl_messagemousewheel.h"
24#include "xfa/fwl/cfwl_messagesetfocus.h"
25#include "xfa/fwl/cfwl_notedriver.h"
26#include "xfa/fwl/cfwl_themebackground.h"
27#include "xfa/fwl/cfwl_themepart.h"
28#include "xfa/fwl/cfwl_themetext.h"
29#include "xfa/fwl/cfwl_widgetmgr.h"
30#include "xfa/fwl/ifwl_themeprovider.h"
Dan Sinclair80c48782017-03-23 12:11:20 -040031#include "xfa/fxfa/cxfa_ffapp.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040032
dsinclair2c489cc2016-11-23 16:17:20 -080033#define FWL_STYLEEXT_MNU_Vert (1L << 0)
dsinclair55fa3562016-05-04 14:24:53 -070034#define FWL_WGT_CalcHeight 2048
35#define FWL_WGT_CalcWidth 2048
36#define FWL_WGT_CalcMultiLineDefWidth 120.0f
37
dsinclair2c489cc2016-11-23 16:17:20 -080038CFWL_Widget::CFWL_Widget(const CFWL_App* app,
39 std::unique_ptr<CFWL_WidgetProperties> properties,
40 CFWL_Widget* pOuter)
41 : m_pOwnerApp(app),
42 m_pWidgetMgr(app->GetWidgetMgr()),
43 m_pProperties(std::move(properties)),
44 m_pOuter(pOuter),
45 m_iLock(0),
46 m_pLayoutItem(nullptr),
47 m_nEventKey(0),
48 m_pDelegate(nullptr) {
49 ASSERT(m_pWidgetMgr);
dsinclair73895de2016-10-20 07:19:43 -070050
dsinclair2c489cc2016-11-23 16:17:20 -080051 CFWL_Widget* pParent = m_pProperties->m_pParent;
52 m_pWidgetMgr->InsertWidget(pParent, this);
53 if (IsChild())
54 return;
dsinclair73895de2016-10-20 07:19:43 -070055
dsinclair2c489cc2016-11-23 16:17:20 -080056 CFWL_Widget* pOwner = m_pProperties->m_pOwner;
57 if (pOwner)
58 m_pWidgetMgr->SetOwner(pOwner, this);
59}
60
61CFWL_Widget::~CFWL_Widget() {
62 NotifyDriver();
63 m_pWidgetMgr->RemoveWidget(this);
64}
65
66bool CFWL_Widget::IsInstance(const CFX_WideStringC& wsClass) const {
67 return false;
dsinclair20855382016-10-31 07:29:34 -070068}
69
dsinclairda911bc2016-12-07 18:47:00 -080070CFX_RectF CFWL_Widget::GetAutosizedWidgetRect() {
71 return CFX_RectF();
72}
73
74CFX_RectF CFWL_Widget::GetWidgetRect() {
75 return m_pProperties->m_rtWidget;
dsinclair67c6ca32016-12-07 18:24:00 -080076}
dsinclair2c489cc2016-11-23 16:17:20 -080077
dsinclair67c6ca32016-12-07 18:24:00 -080078void CFWL_Widget::InflateWidgetRect(CFX_RectF& rect) {
dsinclair2c489cc2016-11-23 16:17:20 -080079 if (HasBorder()) {
Dan Sinclair05df0752017-03-14 14:43:42 -040080 float fBorder = GetBorderSize(true);
dsinclair2c489cc2016-11-23 16:17:20 -080081 rect.Inflate(fBorder, fBorder);
82 }
Dan Sinclair1770c022016-03-14 14:14:16 -040083}
dsinclair7f432a12016-03-29 12:38:01 -070084
dsinclair98329fe2016-11-10 09:40:14 -080085void CFWL_Widget::SetWidgetRect(const CFX_RectF& rect) {
dsinclair2c489cc2016-11-23 16:17:20 -080086 m_pProperties->m_rtWidget = rect;
dsinclair2c489cc2016-11-23 16:17:20 -080087}
88
dsinclair43ac44c2016-12-08 14:05:14 -080089CFX_RectF CFWL_Widget::GetClientRect() {
dsinclair46a4bbf2016-12-15 13:44:02 -080090 return GetEdgeRect();
dsinclair2c489cc2016-11-23 16:17:20 -080091}
92
93void CFWL_Widget::SetParent(CFWL_Widget* pParent) {
94 m_pProperties->m_pParent = pParent;
95 m_pWidgetMgr->SetParent(pParent, this);
96}
97
98uint32_t CFWL_Widget::GetStyles() const {
99 return m_pProperties->m_dwStyles;
Dan Sinclair1770c022016-03-14 14:14:16 -0400100}
dsinclair7f432a12016-03-29 12:38:01 -0700101
dsinclair98329fe2016-11-10 09:40:14 -0800102void CFWL_Widget::ModifyStyles(uint32_t dwStylesAdded,
103 uint32_t dwStylesRemoved) {
dsinclair2c489cc2016-11-23 16:17:20 -0800104 m_pProperties->m_dwStyles =
105 (m_pProperties->m_dwStyles & ~dwStylesRemoved) | dwStylesAdded;
Dan Sinclair1770c022016-03-14 14:14:16 -0400106}
dsinclair55fa3562016-05-04 14:24:53 -0700107
dsinclair2c489cc2016-11-23 16:17:20 -0800108uint32_t CFWL_Widget::GetStylesEx() const {
109 return m_pProperties->m_dwStyleExes;
110}
111uint32_t CFWL_Widget::GetStates() const {
112 return m_pProperties->m_dwStates;
Dan Sinclair1770c022016-03-14 14:14:16 -0400113}
dsinclair7f432a12016-03-29 12:38:01 -0700114
dsinclair98329fe2016-11-10 09:40:14 -0800115void CFWL_Widget::ModifyStylesEx(uint32_t dwStylesExAdded,
116 uint32_t dwStylesExRemoved) {
dsinclair2c489cc2016-11-23 16:17:20 -0800117 m_pProperties->m_dwStyleExes =
118 (m_pProperties->m_dwStyleExes & ~dwStylesExRemoved) | dwStylesExAdded;
Dan Sinclair1770c022016-03-14 14:14:16 -0400119}
dsinclair7f432a12016-03-29 12:38:01 -0700120
dsinclair2c489cc2016-11-23 16:17:20 -0800121static void NotifyHideChildWidget(CFWL_WidgetMgr* widgetMgr,
122 CFWL_Widget* widget,
123 CFWL_NoteDriver* noteDriver) {
124 CFWL_Widget* child = widgetMgr->GetFirstChildWidget(widget);
125 while (child) {
126 noteDriver->NotifyTargetHide(child);
127 NotifyHideChildWidget(widgetMgr, child, noteDriver);
128 child = widgetMgr->GetNextSiblingWidget(child);
129 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400130}
dsinclair7f432a12016-03-29 12:38:01 -0700131
dsinclair7fa190d2016-12-07 17:23:28 -0800132void CFWL_Widget::SetStates(uint32_t dwStates) {
133 m_pProperties->m_dwStates |= dwStates;
134 if (!(dwStates & FWL_WGTSTATE_Invisible))
dsinclair2c489cc2016-11-23 16:17:20 -0800135 return;
dsinclair7f432a12016-03-29 12:38:01 -0700136
dsinclair2c489cc2016-11-23 16:17:20 -0800137 CFWL_NoteDriver* noteDriver =
138 static_cast<CFWL_NoteDriver*>(GetOwnerApp()->GetNoteDriver());
139 CFWL_WidgetMgr* widgetMgr = GetOwnerApp()->GetWidgetMgr();
140 noteDriver->NotifyTargetHide(this);
141 CFWL_Widget* child = widgetMgr->GetFirstChildWidget(this);
142 while (child) {
143 noteDriver->NotifyTargetHide(child);
144 NotifyHideChildWidget(widgetMgr, child, noteDriver);
145 child = widgetMgr->GetNextSiblingWidget(child);
146 }
147 return;
Dan Sinclair1770c022016-03-14 14:14:16 -0400148}
dsinclair7f432a12016-03-29 12:38:01 -0700149
dsinclair7fa190d2016-12-07 17:23:28 -0800150void CFWL_Widget::RemoveStates(uint32_t dwStates) {
151 m_pProperties->m_dwStates &= ~dwStates;
152}
153
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500154FWL_WidgetHit CFWL_Widget::HitTest(const CFX_PointF& point) {
155 if (GetClientRect().Contains(point))
dsinclair2c489cc2016-11-23 16:17:20 -0800156 return FWL_WidgetHit::Client;
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500157 if (HasBorder() && GetRelativeRect().Contains(point))
dsinclair43ac44c2016-12-08 14:05:14 -0800158 return FWL_WidgetHit::Border;
dsinclair2c489cc2016-11-23 16:17:20 -0800159 return FWL_WidgetHit::Unknown;
Dan Sinclair1770c022016-03-14 14:14:16 -0400160}
dsinclair7f432a12016-03-29 12:38:01 -0700161
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500162CFX_PointF CFWL_Widget::TransformTo(CFWL_Widget* pWidget,
163 const CFX_PointF& point) {
dsinclair2c489cc2016-11-23 16:17:20 -0800164 if (m_pWidgetMgr->IsFormDisabled()) {
165 CFX_SizeF szOffset;
166 if (IsParent(pWidget)) {
167 szOffset = GetOffsetFromParent(pWidget);
168 } else {
169 szOffset = pWidget->GetOffsetFromParent(this);
dan sinclair071d7862017-02-07 20:46:32 -0500170 szOffset.width = -szOffset.width;
171 szOffset.height = -szOffset.height;
dsinclair2c489cc2016-11-23 16:17:20 -0800172 }
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500173 return point + CFX_PointF(szOffset.width, szOffset.height);
dsinclair2c489cc2016-11-23 16:17:20 -0800174 }
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500175
176 CFX_PointF ret = point;
dsinclair2c489cc2016-11-23 16:17:20 -0800177 CFWL_Widget* parent = GetParent();
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500178 if (parent)
179 ret = GetMatrix().Transform(ret + GetWidgetRect().TopLeft());
180
dsinclair2c489cc2016-11-23 16:17:20 -0800181 CFWL_Widget* form1 = m_pWidgetMgr->GetSystemFormWidget(this);
182 if (!form1)
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500183 return ret;
dsinclairda911bc2016-12-07 18:47:00 -0800184
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500185 if (!pWidget)
186 return ret + form1->GetWidgetRect().TopLeft();
187
dsinclair2c489cc2016-11-23 16:17:20 -0800188 CFWL_Widget* form2 = m_pWidgetMgr->GetSystemFormWidget(pWidget);
189 if (!form2)
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500190 return ret;
dsinclair2c489cc2016-11-23 16:17:20 -0800191 if (form1 != form2) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500192 ret += form1->GetWidgetRect().TopLeft();
193 ret -= form2->GetWidgetRect().TopLeft();
dsinclair2c489cc2016-11-23 16:17:20 -0800194 }
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500195
dsinclair2c489cc2016-11-23 16:17:20 -0800196 parent = pWidget->GetParent();
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500197 if (!parent)
198 return ret;
199
Nicolas Penab21f1742017-06-29 12:02:06 -0400200 return pWidget->GetMatrix().GetInverse().Transform(ret) -
201 pWidget->GetWidgetRect().TopLeft();
dsinclair2c489cc2016-11-23 16:17:20 -0800202}
203
dsinclair1babeee2016-12-08 19:45:00 -0800204CFX_Matrix CFWL_Widget::GetMatrix() {
dsinclair2c489cc2016-11-23 16:17:20 -0800205 if (!m_pProperties)
dsinclair1babeee2016-12-08 19:45:00 -0800206 return CFX_Matrix();
dsinclair2c489cc2016-11-23 16:17:20 -0800207
208 CFWL_Widget* parent = GetParent();
Tom Sepez576e8152017-01-30 14:26:24 -0800209 std::vector<CFWL_Widget*> parents;
dsinclair2c489cc2016-11-23 16:17:20 -0800210 while (parent) {
Tom Sepez576e8152017-01-30 14:26:24 -0800211 parents.push_back(parent);
dsinclair2c489cc2016-11-23 16:17:20 -0800212 parent = parent->GetParent();
213 }
dsinclair1babeee2016-12-08 19:45:00 -0800214
215 CFX_Matrix matrix;
dsinclair2c489cc2016-11-23 16:17:20 -0800216 CFX_Matrix ctmOnParent;
217 CFX_RectF rect;
Tom Sepez576e8152017-01-30 14:26:24 -0800218 int32_t count = pdfium::CollectionSize<int32_t>(parents);
dsinclair2c489cc2016-11-23 16:17:20 -0800219 for (int32_t i = count - 2; i >= 0; i--) {
Tom Sepez576e8152017-01-30 14:26:24 -0800220 parent = parents[i];
dsinclair1babeee2016-12-08 19:45:00 -0800221 if (parent->m_pProperties)
222 ctmOnParent.SetIdentity();
dsinclairda911bc2016-12-07 18:47:00 -0800223 rect = parent->GetWidgetRect();
dsinclair2c489cc2016-11-23 16:17:20 -0800224 matrix.Concat(ctmOnParent, true);
225 matrix.Translate(rect.left, rect.top, true);
226 }
227 CFX_Matrix m;
228 m.SetIdentity();
229 matrix.Concat(m, true);
Tom Sepez576e8152017-01-30 14:26:24 -0800230 parents.clear();
dsinclair1babeee2016-12-08 19:45:00 -0800231 return matrix;
dsinclair2c489cc2016-11-23 16:17:20 -0800232}
233
234IFWL_ThemeProvider* CFWL_Widget::GetThemeProvider() const {
235 return m_pProperties->m_pThemeProvider;
236}
237
238void CFWL_Widget::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
239 m_pProperties->m_pThemeProvider = pThemeProvider;
240}
241
242bool CFWL_Widget::IsEnabled() const {
243 return (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == 0;
244}
245
dsinclair2c489cc2016-11-23 16:17:20 -0800246bool CFWL_Widget::HasBorder() const {
247 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border);
248}
249
dsinclair2c489cc2016-11-23 16:17:20 -0800250bool CFWL_Widget::IsVisible() const {
251 return (m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) == 0;
252}
253
254bool CFWL_Widget::IsOverLapper() const {
255 return (m_pProperties->m_dwStyles & FWL_WGTSTYLE_WindowTypeMask) ==
256 FWL_WGTSTYLE_OverLapper;
257}
258
259bool CFWL_Widget::IsPopup() const {
260 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Popup);
261}
262
263bool CFWL_Widget::IsChild() const {
264 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Child);
265}
266
dsinclair43ac44c2016-12-08 14:05:14 -0800267CFX_RectF CFWL_Widget::GetEdgeRect() {
Dan Sinclairbba2a7c2017-02-07 16:36:39 -0500268 CFX_RectF rtEdge(0, 0, m_pProperties->m_rtWidget.width,
269 m_pProperties->m_rtWidget.height);
dsinclair2c489cc2016-11-23 16:17:20 -0800270 if (HasBorder()) {
Dan Sinclair05df0752017-03-14 14:43:42 -0400271 float fCX = GetBorderSize(true);
272 float fCY = GetBorderSize(false);
dsinclair2c489cc2016-11-23 16:17:20 -0800273 rtEdge.Deflate(fCX, fCY);
274 }
dsinclair43ac44c2016-12-08 14:05:14 -0800275 return rtEdge;
dsinclair2c489cc2016-11-23 16:17:20 -0800276}
277
Dan Sinclair05df0752017-03-14 14:43:42 -0400278float CFWL_Widget::GetBorderSize(bool bCX) {
Dan Sinclairc635c932017-01-03 15:46:55 -0500279 IFWL_ThemeProvider* theme = GetAvailableTheme();
280 if (!theme)
281 return 0.0f;
282 return bCX ? theme->GetCXBorderSize() : theme->GetCYBorderSize();
dsinclair2c489cc2016-11-23 16:17:20 -0800283}
284
dsinclair43ac44c2016-12-08 14:05:14 -0800285CFX_RectF CFWL_Widget::GetRelativeRect() {
Dan Sinclairbba2a7c2017-02-07 16:36:39 -0500286 return CFX_RectF(0, 0, m_pProperties->m_rtWidget.width,
287 m_pProperties->m_rtWidget.height);
dsinclair2c489cc2016-11-23 16:17:20 -0800288}
289
dsinclair2c489cc2016-11-23 16:17:20 -0800290IFWL_ThemeProvider* CFWL_Widget::GetAvailableTheme() {
291 if (m_pProperties->m_pThemeProvider)
292 return m_pProperties->m_pThemeProvider;
293
294 CFWL_Widget* pUp = this;
295 do {
296 pUp = (pUp->GetStyles() & FWL_WGTSTYLE_Popup)
297 ? m_pWidgetMgr->GetOwnerWidget(pUp)
298 : m_pWidgetMgr->GetParentWidget(pUp);
299 if (pUp) {
300 IFWL_ThemeProvider* pRet = pUp->GetThemeProvider();
301 if (pRet)
302 return pRet;
303 }
304 } while (pUp);
305 return nullptr;
306}
307
308CFWL_Widget* CFWL_Widget::GetRootOuter() {
309 CFWL_Widget* pRet = m_pOuter;
310 if (!pRet)
311 return nullptr;
312
313 while (CFWL_Widget* pOuter = pRet->GetOuter())
314 pRet = pOuter;
315 return pRet;
316}
317
318CFX_SizeF CFWL_Widget::CalcTextSize(const CFX_WideString& wsText,
319 IFWL_ThemeProvider* pTheme,
dsinclair442997c2016-12-07 17:58:41 -0800320 bool bMultiLine) {
dsinclair2c489cc2016-11-23 16:17:20 -0800321 if (!pTheme)
322 return CFX_SizeF();
323
324 CFWL_ThemeText calPart;
325 calPart.m_pWidget = this;
326 calPart.m_wsText = wsText;
327 calPart.m_dwTTOStyles =
328 bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine;
329 calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft;
Dan Sinclair05df0752017-03-14 14:43:42 -0400330 float fWidth = bMultiLine ? FWL_WGT_CalcMultiLineDefWidth : FWL_WGT_CalcWidth;
Dan Sinclairbba2a7c2017-02-07 16:36:39 -0500331 CFX_RectF rect(0, 0, fWidth, FWL_WGT_CalcHeight);
dsinclair2c489cc2016-11-23 16:17:20 -0800332 pTheme->CalcTextRect(&calPart, rect);
333 return CFX_SizeF(rect.width, rect.height);
334}
335
336void CFWL_Widget::CalcTextRect(const CFX_WideString& wsText,
337 IFWL_ThemeProvider* pTheme,
338 uint32_t dwTTOStyles,
339 int32_t iTTOAlign,
340 CFX_RectF& rect) {
341 CFWL_ThemeText calPart;
342 calPart.m_pWidget = this;
343 calPart.m_wsText = wsText;
344 calPart.m_dwTTOStyles = dwTTOStyles;
345 calPart.m_iTTOAlign = iTTOAlign;
346 pTheme->CalcTextRect(&calPart, rect);
347}
348
349void CFWL_Widget::SetFocus(bool bFocus) {
350 if (m_pWidgetMgr->IsFormDisabled())
351 return;
352
353 const CFWL_App* pApp = GetOwnerApp();
354 if (!pApp)
355 return;
356
357 CFWL_NoteDriver* pDriver =
358 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver());
359 if (!pDriver)
360 return;
361
362 CFWL_Widget* curFocus = pDriver->GetFocus();
363 if (bFocus && curFocus != this)
364 pDriver->SetFocus(this);
365 else if (!bFocus && curFocus == this)
366 pDriver->SetFocus(nullptr);
367}
368
369void CFWL_Widget::SetGrab(bool bSet) {
370 const CFWL_App* pApp = GetOwnerApp();
371 if (!pApp)
372 return;
373
374 CFWL_NoteDriver* pDriver =
375 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver());
376 pDriver->SetGrab(this, bSet);
377}
378
Dan Sinclair05df0752017-03-14 14:43:42 -0400379void CFWL_Widget::GetPopupPos(float fMinHeight,
380 float fMaxHeight,
dsinclair2c489cc2016-11-23 16:17:20 -0800381 const CFX_RectF& rtAnchor,
382 CFX_RectF& rtPopup) {
383 if (GetClassID() == FWL_Type::ComboBox) {
384 if (m_pWidgetMgr->IsFormDisabled()) {
385 m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor,
386 rtPopup);
387 return;
388 }
389 GetPopupPosComboBox(fMinHeight, fMaxHeight, rtAnchor, rtPopup);
390 return;
391 }
392 if (GetClassID() == FWL_Type::DateTimePicker &&
393 m_pWidgetMgr->IsFormDisabled()) {
394 m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor,
395 rtPopup);
396 return;
397 }
398 GetPopupPosGeneral(fMinHeight, fMaxHeight, rtAnchor, rtPopup);
399}
400
Dan Sinclair05df0752017-03-14 14:43:42 -0400401bool CFWL_Widget::GetPopupPosMenu(float fMinHeight,
402 float fMaxHeight,
dsinclair2c489cc2016-11-23 16:17:20 -0800403 const CFX_RectF& rtAnchor,
404 CFX_RectF& rtPopup) {
dsinclair2c489cc2016-11-23 16:17:20 -0800405 if (GetStylesEx() & FWL_STYLEEXT_MNU_Vert) {
406 bool bLeft = m_pProperties->m_rtWidget.left < 0;
Dan Sinclair05df0752017-03-14 14:43:42 -0400407 float fRight = rtAnchor.right() + rtPopup.width;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500408 CFX_PointF point = TransformTo(nullptr, CFX_PointF());
409 if (fRight + point.x > 0.0f || bLeft) {
Dan Sinclairbba2a7c2017-02-07 16:36:39 -0500410 rtPopup = CFX_RectF(rtAnchor.left - rtPopup.width, rtAnchor.top,
411 rtPopup.width, rtPopup.height);
dsinclair2c489cc2016-11-23 16:17:20 -0800412 } else {
Dan Sinclairbba2a7c2017-02-07 16:36:39 -0500413 rtPopup = CFX_RectF(rtAnchor.right(), rtAnchor.top, rtPopup.width,
414 rtPopup.height);
dsinclair2c489cc2016-11-23 16:17:20 -0800415 }
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500416 rtPopup.Offset(point.x, point.y);
417 return true;
dsinclair2c489cc2016-11-23 16:17:20 -0800418 }
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500419
Dan Sinclair05df0752017-03-14 14:43:42 -0400420 float fBottom = rtAnchor.bottom() + rtPopup.height;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500421 CFX_PointF point = TransformTo(nullptr, point);
422 if (fBottom + point.y > 0.0f) {
423 rtPopup = CFX_RectF(rtAnchor.left, rtAnchor.top - rtPopup.height,
424 rtPopup.width, rtPopup.height);
425 } else {
426 rtPopup = CFX_RectF(rtAnchor.left, rtAnchor.bottom(), rtPopup.width,
427 rtPopup.height);
428 }
429 rtPopup.Offset(point.x, point.y);
dsinclair2c489cc2016-11-23 16:17:20 -0800430 return true;
431}
432
Dan Sinclair05df0752017-03-14 14:43:42 -0400433bool CFWL_Widget::GetPopupPosComboBox(float fMinHeight,
434 float fMaxHeight,
dsinclair2c489cc2016-11-23 16:17:20 -0800435 const CFX_RectF& rtAnchor,
436 CFX_RectF& rtPopup) {
Dan Sinclair05df0752017-03-14 14:43:42 -0400437 float fPopHeight = rtPopup.height;
dsinclair2c489cc2016-11-23 16:17:20 -0800438 if (rtPopup.height > fMaxHeight)
439 fPopHeight = fMaxHeight;
440 else if (rtPopup.height < fMinHeight)
441 fPopHeight = fMinHeight;
442
Dan Sinclair05df0752017-03-14 14:43:42 -0400443 float fWidth = std::max(rtAnchor.width, rtPopup.width);
444 float fBottom = rtAnchor.bottom() + fPopHeight;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500445 CFX_PointF point = TransformTo(nullptr, CFX_PointF());
446 if (fBottom + point.y > 0.0f) {
Dan Sinclairbba2a7c2017-02-07 16:36:39 -0500447 rtPopup =
448 CFX_RectF(rtAnchor.left, rtAnchor.top - fPopHeight, fWidth, fPopHeight);
449 } else {
450 rtPopup = CFX_RectF(rtAnchor.left, rtAnchor.bottom(), fWidth, fPopHeight);
451 }
dsinclair2c489cc2016-11-23 16:17:20 -0800452
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500453 rtPopup.Offset(point.x, point.y);
dsinclair2c489cc2016-11-23 16:17:20 -0800454 return true;
455}
456
Dan Sinclair05df0752017-03-14 14:43:42 -0400457bool CFWL_Widget::GetPopupPosGeneral(float fMinHeight,
458 float fMaxHeight,
dsinclair2c489cc2016-11-23 16:17:20 -0800459 const CFX_RectF& rtAnchor,
460 CFX_RectF& rtPopup) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500461 CFX_PointF point = TransformTo(nullptr, CFX_PointF());
462 if (rtAnchor.bottom() + point.y > 0.0f) {
Dan Sinclairbba2a7c2017-02-07 16:36:39 -0500463 rtPopup = CFX_RectF(rtAnchor.left, rtAnchor.top - rtPopup.height,
464 rtPopup.width, rtPopup.height);
dsinclair2c489cc2016-11-23 16:17:20 -0800465 } else {
Dan Sinclairbba2a7c2017-02-07 16:36:39 -0500466 rtPopup = CFX_RectF(rtAnchor.left, rtAnchor.bottom(), rtPopup.width,
467 rtPopup.height);
dsinclair2c489cc2016-11-23 16:17:20 -0800468 }
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500469 rtPopup.Offset(point.x, point.y);
dsinclair2c489cc2016-11-23 16:17:20 -0800470 return true;
471}
472
473void CFWL_Widget::RegisterEventTarget(CFWL_Widget* pEventSource) {
474 const CFWL_App* pApp = GetOwnerApp();
475 if (!pApp)
476 return;
477
478 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver();
479 if (!pNoteDriver)
480 return;
481
482 pNoteDriver->RegisterEventTarget(this, pEventSource);
483}
484
485void CFWL_Widget::UnregisterEventTarget() {
486 const CFWL_App* pApp = GetOwnerApp();
487 if (!pApp)
488 return;
489
490 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver();
491 if (!pNoteDriver)
492 return;
493
494 pNoteDriver->UnregisterEventTarget(this);
495}
496
dsinclair2c489cc2016-11-23 16:17:20 -0800497void CFWL_Widget::DispatchEvent(CFWL_Event* pEvent) {
498 if (m_pOuter) {
499 m_pOuter->GetDelegate()->OnProcessEvent(pEvent);
500 return;
501 }
502 const CFWL_App* pApp = GetOwnerApp();
503 if (!pApp)
504 return;
505
506 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver();
507 if (!pNoteDriver)
508 return;
509 pNoteDriver->SendEvent(pEvent);
510}
511
dsinclair43ac44c2016-12-08 14:05:14 -0800512void CFWL_Widget::Repaint() {
Dan Sinclairbba2a7c2017-02-07 16:36:39 -0500513 RepaintRect(CFX_RectF(0, 0, m_pProperties->m_rtWidget.width,
514 m_pProperties->m_rtWidget.height));
dsinclair43ac44c2016-12-08 14:05:14 -0800515}
516
517void CFWL_Widget::RepaintRect(const CFX_RectF& pRect) {
518 m_pWidgetMgr->RepaintWidget(this, pRect);
dsinclair2c489cc2016-11-23 16:17:20 -0800519}
520
Dan Sinclair2b918c82017-07-13 14:47:10 -0400521void CFWL_Widget::DrawBackground(CXFA_Graphics* pGraphics,
dsinclair2c489cc2016-11-23 16:17:20 -0800522 CFWL_Part iPartBk,
523 IFWL_ThemeProvider* pTheme,
524 const CFX_Matrix* pMatrix) {
dsinclair2c489cc2016-11-23 16:17:20 -0800525 CFWL_ThemeBackground param;
526 param.m_pWidget = this;
527 param.m_iPart = iPartBk;
528 param.m_pGraphics = pGraphics;
529 if (pMatrix)
530 param.m_matrix.Concat(*pMatrix, true);
dsinclair43ac44c2016-12-08 14:05:14 -0800531 param.m_rtPart = GetRelativeRect();
dsinclair2c489cc2016-11-23 16:17:20 -0800532 pTheme->DrawBackground(&param);
533}
534
Dan Sinclair2b918c82017-07-13 14:47:10 -0400535void CFWL_Widget::DrawBorder(CXFA_Graphics* pGraphics,
dsinclair2c489cc2016-11-23 16:17:20 -0800536 CFWL_Part iPartBorder,
537 IFWL_ThemeProvider* pTheme,
dsinclair98329fe2016-11-10 09:40:14 -0800538 const CFX_Matrix* pMatrix) {
dsinclair2c489cc2016-11-23 16:17:20 -0800539 CFWL_ThemeBackground param;
540 param.m_pWidget = this;
541 param.m_iPart = iPartBorder;
542 param.m_pGraphics = pGraphics;
543 if (pMatrix)
544 param.m_matrix.Concat(*pMatrix, true);
dsinclair43ac44c2016-12-08 14:05:14 -0800545 param.m_rtPart = GetRelativeRect();
dsinclair2c489cc2016-11-23 16:17:20 -0800546 pTheme->DrawBackground(&param);
Dan Sinclair1770c022016-03-14 14:14:16 -0400547}
dsinclair7f432a12016-03-29 12:38:01 -0700548
dsinclair2c489cc2016-11-23 16:17:20 -0800549void CFWL_Widget::NotifyDriver() {
550 const CFWL_App* pApp = GetOwnerApp();
551 if (!pApp)
552 return;
553
554 CFWL_NoteDriver* pDriver =
555 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver());
556 if (!pDriver)
557 return;
558
559 pDriver->NotifyTargetDestroy(this);
Dan Sinclair1770c022016-03-14 14:14:16 -0400560}
dsinclair2c489cc2016-11-23 16:17:20 -0800561
562CFX_SizeF CFWL_Widget::GetOffsetFromParent(CFWL_Widget* pParent) {
563 if (pParent == this)
564 return CFX_SizeF();
565
566 CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr();
567 if (!pWidgetMgr)
568 return CFX_SizeF();
569
570 CFX_SizeF szRet(m_pProperties->m_rtWidget.left,
571 m_pProperties->m_rtWidget.top);
572
573 CFWL_Widget* pDstWidget = GetParent();
574 while (pDstWidget && pDstWidget != pParent) {
dsinclairda911bc2016-12-07 18:47:00 -0800575 CFX_RectF rtDst = pDstWidget->GetWidgetRect();
dsinclair2c489cc2016-11-23 16:17:20 -0800576 szRet += CFX_SizeF(rtDst.left, rtDst.top);
577 pDstWidget = pWidgetMgr->GetParentWidget(pDstWidget);
578 }
579 return szRet;
580}
581
582bool CFWL_Widget::IsParent(CFWL_Widget* pParent) {
583 CFWL_Widget* pUpWidget = GetParent();
584 while (pUpWidget) {
585 if (pUpWidget == pParent)
586 return true;
587 pUpWidget = pUpWidget->GetParent();
588 }
589 return false;
590}
591
592void CFWL_Widget::OnProcessMessage(CFWL_Message* pMessage) {
593 if (!pMessage->m_pDstTarget)
594 return;
595
596 CFWL_Widget* pWidget = pMessage->m_pDstTarget;
dsinclair4614b452016-12-07 17:01:58 -0800597 switch (pMessage->GetType()) {
598 case CFWL_Message::Type::Mouse: {
dsinclair447b1f32016-12-08 10:06:32 -0800599 CFWL_MessageMouse* pMsgMouse = static_cast<CFWL_MessageMouse*>(pMessage);
dsinclair4614b452016-12-07 17:01:58 -0800600
dsinclair447b1f32016-12-08 10:06:32 -0800601 CFWL_EventMouse evt(pWidget, pWidget);
dsinclair2c489cc2016-11-23 16:17:20 -0800602 evt.m_dwCmd = pMsgMouse->m_dwCmd;
dsinclair2c489cc2016-11-23 16:17:20 -0800603 pWidget->DispatchEvent(&evt);
604 break;
605 }
606 default:
607 break;
608 }
609}
610
611void CFWL_Widget::OnProcessEvent(CFWL_Event* pEvent) {}
612
Dan Sinclair2b918c82017-07-13 14:47:10 -0400613void CFWL_Widget::OnDrawWidget(CXFA_Graphics* pGraphics,
dsinclair2c489cc2016-11-23 16:17:20 -0800614 const CFX_Matrix* pMatrix) {}