blob: 226916226084272ad0677211a17c16b7077dff3c [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Lei Zhang60f507b2015-06-13 00:41:00 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairc411eb92017-07-25 09:39:30 -04007#include "fpdfsdk/pwl/cpwl_wnd.h"
Lei Zhangfac46f82017-06-02 14:20:04 -07008
Lei Zhang606346f2015-06-19 18:11:07 -07009#include <map>
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -040010#include <sstream>
tsepez0d164f82017-01-09 07:28:13 -080011#include <vector>
Lei Zhang606346f2015-06-19 18:11:07 -070012
Dan Sinclair0b7378a2017-07-17 12:05:40 -040013#include "core/fxge/cfx_renderdevice.h"
Dan Sinclairc411eb92017-07-25 09:39:30 -040014#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
tsepez36eb4bd2016-10-03 15:24:27 -070015#include "third_party/base/ptr_util.h"
tsepez0d164f82017-01-09 07:28:13 -080016#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017
Dan Sinclaira9e28432017-07-05 14:18:14 -040018namespace {
19
20constexpr float kDefaultFontSize = 9.0f;
21constexpr int kInvalidationInflate = 2;
22
23} // namespace
24
weili625ad662016-06-15 11:21:33 -070025PWL_CREATEPARAM::PWL_CREATEPARAM()
26 : rcRectWnd(0, 0, 0, 0),
27 pSystemHandler(nullptr),
28 pFontMap(nullptr),
29 pProvider(nullptr),
30 pFocusHandler(nullptr),
31 dwFlags(0),
32 sBackgroundColor(),
dsinclair8faac622016-09-15 12:41:50 -070033 pAttachedWidget(nullptr),
weili625ad662016-06-15 11:21:33 -070034 nBorderStyle(BorderStyle::SOLID),
35 dwBorderWidth(1),
36 sBorderColor(),
37 sTextColor(),
weili625ad662016-06-15 11:21:33 -070038 nTransparency(255),
Dan Sinclaira9e28432017-07-05 14:18:14 -040039 fFontSize(kDefaultFontSize),
weili625ad662016-06-15 11:21:33 -070040 sDash(3, 0, 0),
41 pAttachedData(nullptr),
42 pParentWnd(nullptr),
43 pMsgControl(nullptr),
Lei Zhangfac46f82017-06-02 14:20:04 -070044 eCursorType(FXCT_ARROW) {}
weili625ad662016-06-15 11:21:33 -070045
46PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default;
47
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048class CPWL_MsgControl {
49 friend class CPWL_Wnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051 public:
Lei Zhangc2fb35f2016-01-05 16:46:58 -080052 explicit CPWL_MsgControl(CPWL_Wnd* pWnd) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 m_pCreatedWnd = pWnd;
54 Default();
55 }
56
Dan Sinclairf766ad22016-03-14 13:51:24 -040057 ~CPWL_MsgControl() { Default(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058
59 void Default() {
tsepez0d164f82017-01-09 07:28:13 -080060 m_aMousePath.clear();
61 m_aKeyboardPath.clear();
thestig1cd352e2016-06-07 17:53:06 -070062 m_pMainMouseWnd = nullptr;
63 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 }
65
tsepez4cf55152016-11-02 14:37:54 -070066 bool IsWndCreated(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067 return m_pCreatedWnd == pWnd;
68 }
69
tsepez4cf55152016-11-02 14:37:54 -070070 bool IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 return pWnd == m_pMainMouseWnd;
72 }
73
tsepez4cf55152016-11-02 14:37:54 -070074 bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -080075 return pWnd && pdfium::ContainsValue(m_aMousePath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 }
77
tsepez4cf55152016-11-02 14:37:54 -070078 bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 return pWnd == m_pMainKeyboardWnd;
80 }
81
tsepez4cf55152016-11-02 14:37:54 -070082 bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -080083 return pWnd && pdfium::ContainsValue(m_aKeyboardPath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 }
85
86 void SetFocus(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -080087 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 if (pWnd) {
89 m_pMainKeyboardWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 CPWL_Wnd* pParent = pWnd;
91 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -080092 m_aKeyboardPath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 pParent = pParent->GetParentWindow();
94 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095 pWnd->OnSetFocus();
Tom Sepez2f2ffec2015-07-23 14:42:09 -070096 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070098
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 void KillFocus() {
tsepez0d164f82017-01-09 07:28:13 -0800100 if (!m_aKeyboardPath.empty())
101 if (CPWL_Wnd* pWnd = m_aKeyboardPath[0])
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 pWnd->OnKillFocus();
103
thestig1cd352e2016-06-07 17:53:06 -0700104 m_pMainKeyboardWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800105 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 }
107
108 void SetCapture(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -0800109 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 if (pWnd) {
111 m_pMainMouseWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 CPWL_Wnd* pParent = pWnd;
113 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -0800114 m_aMousePath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115 pParent = pParent->GetParentWindow();
116 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700117 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 void ReleaseCapture() {
thestig1cd352e2016-06-07 17:53:06 -0700121 m_pMainMouseWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800122 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700124
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 private:
tsepez0d164f82017-01-09 07:28:13 -0800126 std::vector<CPWL_Wnd*> m_aMousePath;
127 std::vector<CPWL_Wnd*> m_aKeyboardPath;
Tom Sepezd0409af2017-05-25 15:53:57 -0700128 CFX_UnownedPtr<CPWL_Wnd> m_pCreatedWnd;
129 CFX_UnownedPtr<CPWL_Wnd> m_pMainMouseWnd;
130 CFX_UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700131};
132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133CPWL_Wnd::CPWL_Wnd()
Lei Zhangfac46f82017-06-02 14:20:04 -0700134 : m_rcWindow(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 m_rcClip(),
tsepez4cf55152016-11-02 14:37:54 -0700136 m_bCreated(false),
137 m_bVisible(false),
138 m_bNotifying(false),
139 m_bEnabled(true) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140
141CPWL_Wnd::~CPWL_Wnd() {
Lei Zhangb45324b2017-05-22 17:05:40 -0700142 ASSERT(!m_bCreated);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143}
144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145CFX_ByteString CPWL_Wnd::GetClassName() const {
146 return "CPWL_Wnd";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700147}
148
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700150 if (IsValid())
151 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152
Lei Zhangfac46f82017-06-02 14:20:04 -0700153 m_sPrivateParam = cp;
154 OnCreate(m_sPrivateParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155
Lei Zhangfac46f82017-06-02 14:20:04 -0700156 m_sPrivateParam.rcRectWnd.Normalize();
157 m_rcWindow = m_sPrivateParam.rcRectWnd;
dan sinclairadf922f2017-07-12 21:56:27 -0400158 m_rcClip = m_rcWindow;
159 if (!m_rcClip.IsEmpty()) {
160 m_rcClip.Inflate(1.0f, 1.0f);
161 m_rcClip.Normalize();
162 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700163 CreateMsgControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164
Lei Zhangfac46f82017-06-02 14:20:04 -0700165 if (m_sPrivateParam.pParentWnd)
Dan Sinclaire5e889e2017-07-05 08:45:40 -0400166 m_sPrivateParam.pParentWnd->AddChild(this);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167
Lei Zhangfac46f82017-06-02 14:20:04 -0700168 PWL_CREATEPARAM ccp = m_sPrivateParam;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169
Lei Zhangfac46f82017-06-02 14:20:04 -0700170 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
171 CreateScrollBar(ccp);
172 CreateChildWnd(ccp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173
Lei Zhangfac46f82017-06-02 14:20:04 -0700174 m_bVisible = HasFlag(PWS_VISIBLE);
175 OnCreated();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176
Lei Zhangfac46f82017-06-02 14:20:04 -0700177 RePosChildWnd();
178 m_bCreated = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700179}
180
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700182
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183void CPWL_Wnd::OnCreated() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185void CPWL_Wnd::OnDestroy() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700186
Lei Zhangab5537d2016-01-06 14:58:14 -0800187void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) {
188 if (m_sPrivateParam.pFocusHandler == handler)
189 m_sPrivateParam.pFocusHandler = nullptr;
190}
191
192void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500193 if (m_sPrivateParam.pProvider.Get() == provider)
194 m_sPrivateParam.pProvider.Reset();
Lei Zhangab5537d2016-01-06 14:58:14 -0800195}
196
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197void CPWL_Wnd::Destroy() {
198 KillFocus();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 OnDestroy();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 if (m_bCreated) {
Lei Zhang35162562017-06-09 01:04:52 -0700201 m_pVScrollBar = nullptr;
tsepez6745f962017-01-04 10:09:45 -0800202 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
203 if (CPWL_Wnd* pChild = *it) {
204 *it = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 pChild->Destroy();
206 delete pChild;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207 }
208 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209 if (m_sPrivateParam.pParentWnd)
Dan Sinclaire5e889e2017-07-05 08:45:40 -0400210 m_sPrivateParam.pParentWnd->RemoveChild(this);
tsepez6745f962017-01-04 10:09:45 -0800211
tsepez4cf55152016-11-02 14:37:54 -0700212 m_bCreated = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 DestroyMsgControl();
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500215 m_sPrivateParam.Reset();
tsepez6745f962017-01-04 10:09:45 -0800216 m_Children.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700218
tsepez4cf55152016-11-02 14:37:54 -0700219void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700220 if (!IsValid())
221 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700222
Lei Zhangfac46f82017-06-02 14:20:04 -0700223 CFX_FloatRect rcOld = GetWindowRect();
224 m_rcWindow = rcNew;
225 m_rcWindow.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226
Lei Zhangfac46f82017-06-02 14:20:04 -0700227 if (bReset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
229 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700230 RePosChildWnd();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700231 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700233 if (bRefresh)
234 InvalidateRectMove(rcOld, rcNew);
235
236 m_sPrivateParam.rcRectWnd = m_rcWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700237}
238
Tom Sepez281a9ea2016-02-26 14:24:28 -0800239void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
240 const CFX_FloatRect& rcNew) {
241 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 InvalidateRect(&rcUnion);
245}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700246
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800248 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 if (IsValid() && IsVisible()) {
250 DrawThisAppearance(pDevice, pUser2Device);
251 DrawChildAppearance(pDevice, pUser2Device);
252 }
253}
254
255void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800256 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800257 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700258 if (rectWnd.IsEmpty())
259 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260
Lei Zhangfac46f82017-06-02 14:20:04 -0700261 if (HasFlag(PWS_BACKGROUND)) {
dan sinclaird6aff2f2017-07-13 21:36:29 -0400262 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
Dan Sinclair0b7378a2017-07-17 12:05:40 -0400263 pDevice->DrawFillRect(pUser2Device, rectWnd.GetDeflated(width, width),
264 GetBackgroundColor(), GetTransparency());
Lei Zhangfac46f82017-06-02 14:20:04 -0700265 }
266
267 if (HasFlag(PWS_BORDER)) {
Dan Sinclair0b7378a2017-07-17 12:05:40 -0400268 pDevice->DrawBorder(pUser2Device, rectWnd,
269 static_cast<float>(GetBorderWidth()), GetBorderColor(),
270 GetBorderLeftTopColor(GetBorderStyle()),
271 GetBorderRightBottomColor(GetBorderStyle()),
272 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700274}
275
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800277 CFX_Matrix* pUser2Device) {
tsepez6745f962017-01-04 10:09:45 -0800278 for (CPWL_Wnd* pChild : m_Children) {
279 if (!pChild)
280 continue;
281
282 CFX_Matrix mt = pChild->GetChildMatrix();
283 if (mt.IsIdentity()) {
284 pChild->DrawAppearance(pDevice, pUser2Device);
285 } else {
286 mt.Concat(*pUser2Device);
287 pChild->DrawAppearance(pDevice, &mt);
Lei Zhang60f507b2015-06-13 00:41:00 -0700288 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700290}
291
Tom Sepez281a9ea2016-02-26 14:24:28 -0800292void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700293 if (!IsValid())
294 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700295
Lei Zhangfac46f82017-06-02 14:20:04 -0700296 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
297
298 if (!HasFlag(PWS_NOREFRESHCLIP)) {
299 CFX_FloatRect rcClip = GetClipRect();
300 if (!rcClip.IsEmpty()) {
301 rcRefresh.Intersect(rcClip);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700302 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700303 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700304
Lei Zhangfac46f82017-06-02 14:20:04 -0700305 FX_RECT rcWin = PWLtoWnd(rcRefresh);
Dan Sinclaira9e28432017-07-05 14:18:14 -0400306 rcWin.left -= kInvalidationInflate;
307 rcWin.top -= kInvalidationInflate;
308 rcWin.right += kInvalidationInflate;
309 rcWin.bottom += kInvalidationInflate;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310
Lei Zhangfac46f82017-06-02 14:20:04 -0700311 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
312 if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>(
313 m_sPrivateParam.pAttachedWidget.Get())) {
314 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700315 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700317}
318
tsepez6745f962017-01-04 10:09:45 -0800319#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
320 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
321 if (!IsValid() || !IsVisible() || !IsEnabled()) \
322 return false; \
323 if (!IsWndCaptureKeyboard(this)) \
324 return false; \
Lei Zhang375c2762017-03-10 14:37:14 -0800325 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800326 if (pChild && IsWndCaptureKeyboard(pChild)) \
327 return pChild->key_method_name(nChar, nFlag); \
328 } \
329 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700330 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700331
332PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700333PWL_IMPLEMENT_KEY_METHOD(OnChar)
tsepez6745f962017-01-04 10:09:45 -0800334#undef PWL_IMPLEMENT_KEY_METHOD
335
336#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Dan Sinclairf528eee2017-02-14 11:52:07 -0500337 bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \
tsepez6745f962017-01-04 10:09:45 -0800338 if (!IsValid() || !IsVisible() || !IsEnabled()) \
339 return false; \
340 if (IsWndCaptureMouse(this)) { \
Lei Zhang375c2762017-03-10 14:37:14 -0800341 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800342 if (pChild && IsWndCaptureMouse(pChild)) { \
343 return pChild->mouse_method_name(pChild->ParentToChild(point), \
344 nFlag); \
345 } \
346 } \
347 SetCursor(); \
348 return false; \
349 } \
Lei Zhang375c2762017-03-10 14:37:14 -0800350 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800351 if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \
352 return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \
353 } \
354 } \
355 if (WndHitTest(point)) \
356 SetCursor(); \
357 return false; \
358 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700359
360PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
361PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
362PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700363PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
364PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
365PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
tsepez6745f962017-01-04 10:09:45 -0800366#undef PWL_IMPLEMENT_MOUSE_METHOD
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367
Diana Gagedce2d722017-06-20 11:17:11 -0700368CFX_WideString CPWL_Wnd::GetSelectedText() {
369 return CFX_WideString();
370}
371
Diana Gage1c7f1422017-07-24 11:19:52 -0700372void CPWL_Wnd::DeleteSelectedText() {}
373
tsepez4cf55152016-11-02 14:37:54 -0700374bool CPWL_Wnd::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500375 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700376 uint32_t nFlag) {
tsepez6745f962017-01-04 10:09:45 -0800377 if (!IsValid() || !IsVisible() || !IsEnabled())
378 return false;
379
380 SetCursor();
381 if (!IsWndCaptureKeyboard(this))
382 return false;
383
Lei Zhang375c2762017-03-10 14:37:14 -0800384 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800385 if (pChild && IsWndCaptureKeyboard(pChild))
386 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387 }
tsepez4cf55152016-11-02 14:37:54 -0700388 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389}
390
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800392 m_Children.push_back(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700393}
394
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800396 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
397 if (*it && *it == pWnd) {
398 m_Children.erase(std::next(it).base());
399 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700400 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700401 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700402}
403
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400404void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {}
405
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400406void CPWL_Wnd::SetScrollPosition(float pos) {}
407
Dan Sinclair63fbd8d2017-07-05 14:10:36 -0400408void CPWL_Wnd::ScrollWindowVertically(float pos) {}
409
Dan Sinclair7f6bec92017-07-05 14:13:16 -0400410void CPWL_Wnd::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {}
411
412void CPWL_Wnd::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {}
413
414void CPWL_Wnd::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) {}
415
tsepez4cf55152016-11-02 14:37:54 -0700416bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 return m_bCreated;
418}
419
Lei Zhang7457e382016-01-06 23:00:34 -0800420const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421 return m_sPrivateParam;
422}
423
424CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
425 return m_sPrivateParam.pParentWnd;
426}
427
Tom Sepez281a9ea2016-02-26 14:24:28 -0800428CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 return m_rcWindow;
430}
431
Tom Sepez281a9ea2016-02-26 14:24:28 -0800432CFX_FloatRect CPWL_Wnd::GetClientRect() const {
433 CFX_FloatRect rcWindow = GetWindowRect();
dan sinclairadf922f2017-07-12 21:56:27 -0400434
dan sinclaird6aff2f2017-07-13 21:36:29 -0400435 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
436 CFX_FloatRect rcClient = rcWindow.GetDeflated(width, width);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
438 rcClient.right -= pVSB->GetScrollBarWidth();
439
440 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800441 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442}
443
Dan Sinclairf528eee2017-02-14 11:52:07 -0500444CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800445 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500446 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
447 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448}
449
tsepez4cf55152016-11-02 14:37:54 -0700450bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
452}
453
tsepezc3255f52016-03-25 14:52:27 -0700454void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 m_sPrivateParam.dwFlags &= ~dwFlags;
456}
457
tsepezc3255f52016-03-25 14:52:27 -0700458void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459 m_sPrivateParam.dwFlags |= dwFlags;
460}
461
Dan Sinclair7f55a542017-07-13 14:17:10 -0400462CFX_Color CPWL_Wnd::GetBackgroundColor() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 return m_sPrivateParam.sBackgroundColor;
464}
465
Dan Sinclair7f55a542017-07-13 14:17:10 -0400466void CPWL_Wnd::SetBackgroundColor(const CFX_Color& color) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 m_sPrivateParam.sBackgroundColor = color;
468}
469
Dan Sinclair7f55a542017-07-13 14:17:10 -0400470CFX_Color CPWL_Wnd::GetTextColor() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 return m_sPrivateParam.sTextColor;
472}
473
dsinclair92cb5e52016-05-16 11:38:28 -0700474BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 return m_sPrivateParam.nBorderStyle;
476}
477
dsinclair92cb5e52016-05-16 11:38:28 -0700478void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 if (HasFlag(PWS_BORDER))
480 m_sPrivateParam.nBorderStyle = nBorderStyle;
481}
482
483int32_t CPWL_Wnd::GetBorderWidth() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700484 return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485}
486
487int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 return 0;
489}
490
Dan Sinclair7f55a542017-07-13 14:17:10 -0400491CFX_Color CPWL_Wnd::GetBorderColor() const {
492 return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493}
494
Lei Zhang7457e382016-01-06 23:00:34 -0800495const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 return m_sPrivateParam.sDash;
497}
498
499void* CPWL_Wnd::GetAttachedData() const {
500 return m_sPrivateParam.pAttachedData;
501}
502
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700504 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505}
506
507void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
508 CreateVScrollBar(cp);
509}
510
511void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700512 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
513 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514
Lei Zhangfac46f82017-06-02 14:20:04 -0700515 PWL_CREATEPARAM scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516
Lei Zhangfac46f82017-06-02 14:20:04 -0700517 // flags
518 scp.dwFlags =
519 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520
Lei Zhangfac46f82017-06-02 14:20:04 -0700521 scp.pParentWnd = this;
522 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
523 scp.eCursorType = FXCT_ARROW;
524 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
525
526 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
527 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528}
529
530void CPWL_Wnd::SetCapture() {
531 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
532 pMsgCtrl->SetCapture(this);
533}
534
535void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800536 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800537 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800539 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
541 pMsgCtrl->ReleaseCapture();
542}
543
544void CPWL_Wnd::SetFocus() {
545 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
546 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
547 pMsgCtrl->KillFocus();
548 pMsgCtrl->SetFocus(this);
549 }
550}
551
552void CPWL_Wnd::KillFocus() {
553 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
554 if (pMsgCtrl->IsWndCaptureKeyboard(this))
555 pMsgCtrl->KillFocus();
556 }
557}
558
559void CPWL_Wnd::OnSetFocus() {}
560
561void CPWL_Wnd::OnKillFocus() {}
562
Dan Sinclairf528eee2017-02-14 11:52:07 -0500563bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500564 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565}
566
Dan Sinclairf528eee2017-02-14 11:52:07 -0500567bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500568 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569}
570
571const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700572 auto* pParent = m_sPrivateParam.pParentWnd;
573 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574}
575
tsepez4cf55152016-11-02 14:37:54 -0700576void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800577 if (!IsValid())
578 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579
Lei Zhang375c2762017-03-10 14:37:14 -0800580 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800581 if (pChild)
582 pChild->SetVisible(bVisible);
583 }
584 if (bVisible != m_bVisible) {
585 m_bVisible = bVisible;
586 RePosChildWnd();
587 InvalidateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700589}
590
Tom Sepez281a9ea2016-02-26 14:24:28 -0800591void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592 m_rcClip = rect;
593 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700594}
595
Tom Sepez281a9ea2016-02-26 14:24:28 -0800596const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700598}
599
tsepez4cf55152016-11-02 14:37:54 -0700600bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700602}
603
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700605 CPWL_ScrollBar* pVSB = GetVScrollBar();
606 if (!pVSB)
607 return;
608
dan sinclairadf922f2017-07-12 21:56:27 -0400609 CFX_FloatRect rcContent = GetWindowRect();
610 if (!rcContent.IsEmpty()) {
611 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
612 rcContent.Deflate(width, width);
613 rcContent.Normalize();
614 }
Tom Sepez281a9ea2016-02-26 14:24:28 -0800615 CFX_FloatRect rcVScroll =
616 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
617 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700618 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700619}
620
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
622
623void CPWL_Wnd::SetCursor() {
624 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700625 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626 int32_t nCursorType = GetCreationParam().eCursorType;
627 pSH->SetCursor(nCursorType);
628 }
629 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700630}
631
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700632void CPWL_Wnd::CreateMsgControl() {
633 if (!m_sPrivateParam.pMsgControl)
634 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635}
636
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700637void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700638 CPWL_MsgControl* pMsgControl = GetMsgControl();
639 if (pMsgControl && pMsgControl->IsWndCreated(this))
640 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700641}
642
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
644 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645}
646
tsepez4cf55152016-11-02 14:37:54 -0700647bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700649}
650
tsepez4cf55152016-11-02 14:37:54 -0700651bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700652 CPWL_MsgControl* pCtrl = GetMsgControl();
653 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700654}
655
tsepez4cf55152016-11-02 14:37:54 -0700656bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700657 CPWL_MsgControl* pCtrl = GetMsgControl();
658 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700659}
660
tsepez4cf55152016-11-02 14:37:54 -0700661bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700662 CPWL_MsgControl* pCtrl = GetMsgControl();
663 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700664}
665
Tom Sepez281a9ea2016-02-26 14:24:28 -0800666CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
dan sinclairadf922f2017-07-12 21:56:27 -0400667 CFX_FloatRect rect = GetWindowRect();
668 if (!rect.IsEmpty()) {
669 rect.Inflate(1.0f, 1.0f);
670 rect.Normalize();
671 }
672 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700673}
674
Dan Sinclair05df0752017-03-14 14:43:42 -0400675float CPWL_Wnd::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677}
678
Dan Sinclair05df0752017-03-14 14:43:42 -0400679void CPWL_Wnd::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681}
682
dsinclairb9590102016-04-27 06:38:59 -0700683CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685}
686
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
688 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700689}
690
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691IPWL_Provider* CPWL_Wnd::GetProvider() const {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500692 return m_sPrivateParam.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693}
694
dsinclairc7a73492016-04-05 12:01:42 -0700695IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700697}
698
Dan Sinclair7f55a542017-07-13 14:17:10 -0400699CFX_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700701 case BorderStyle::BEVELED:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400702 return CFX_Color(COLORTYPE_GRAY, 1);
dsinclair92cb5e52016-05-16 11:38:28 -0700703 case BorderStyle::INSET:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400704 return CFX_Color(COLORTYPE_GRAY, 0.5f);
dsinclair92cb5e52016-05-16 11:38:28 -0700705 default:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400706 return CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700708}
709
Dan Sinclair7f55a542017-07-13 14:17:10 -0400710CFX_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700712 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500713 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700714 case BorderStyle::INSET:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400715 return CFX_Color(COLORTYPE_GRAY, 0.75f);
dsinclair92cb5e52016-05-16 11:38:28 -0700716 default:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400717 return CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700719}
720
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721int32_t CPWL_Wnd::GetTransparency() {
722 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700723}
724
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800726 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800727 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700731}
732
Tom Sepez60d909e2015-12-10 15:34:55 -0800733CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
734 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800735 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700738}
739
Tom Sepez281a9ea2016-02-26 14:24:28 -0800740FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
741 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800742 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 mt.TransformRect(rcTemp);
744 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
745 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700746}
747
Dan Sinclairf528eee2017-02-14 11:52:07 -0500748CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800749 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 if (mt.IsIdentity())
751 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700752
Nicolas Penab21f1742017-06-29 12:02:06 -0400753 CFX_Matrix inverse = mt.GetInverse();
754 if (!inverse.IsIdentity())
755 mt = inverse;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500756 return mt.Transform(point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700757}
758
Tom Sepez281a9ea2016-02-26 14:24:28 -0800759CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800760 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761 if (mt.IsIdentity())
762 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700763
Nicolas Penab21f1742017-06-29 12:02:06 -0400764 CFX_Matrix inverse = mt.GetInverse();
765 if (!inverse.IsIdentity())
766 mt = inverse;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800767 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768 mt.TransformRect(rc);
769 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700770}
771
Tom Sepez60d909e2015-12-10 15:34:55 -0800772CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700773 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700774 if (HasFlag(PWS_CHILD)) {
775 const CPWL_Wnd* pParent = this;
776 while (pParent) {
777 mt.Concat(pParent->GetChildMatrix());
778 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700779 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780 }
781 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700782}
783
Tom Sepez60d909e2015-12-10 15:34:55 -0800784CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700785 return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700786}
787
Tom Sepez60d909e2015-12-10 15:34:55 -0800788void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700789 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700790}
791
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700792const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800793 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700794 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795}
796
tsepez4cf55152016-11-02 14:37:54 -0700797void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800798 if (m_bEnabled == bEnable)
799 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700800
Lei Zhang375c2762017-03-10 14:37:14 -0800801 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800802 if (pChild)
803 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700804 }
tsepez6745f962017-01-04 10:09:45 -0800805 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700806}