blob: 863b9aab9aae5290b58024aee6face55ff69ce62 [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
Lei Zhang633a3b72017-06-02 15:27:22 -07007#include "fpdfsdk/pdfwindow/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
Lei Zhang633a3b72017-06-02 15:27:22 -070013#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h"
14#include "fpdfsdk/pdfwindow/cpwl_utils.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
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400247void CPWL_Wnd::GetAppearanceStream(std::ostringstream* psAppStream) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 if (IsValid() && IsVisible()) {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400249 GetThisAppearanceStream(psAppStream);
250 GetChildAppearanceStream(psAppStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 }
252}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700253
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254// if don't set,Get default apperance stream
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400255void CPWL_Wnd::GetThisAppearanceStream(std::ostringstream* psAppStream) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800256 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700257 if (rectWnd.IsEmpty())
258 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259
Lei Zhangfac46f82017-06-02 14:20:04 -0700260 if (HasFlag(PWS_BACKGROUND))
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400261 *psAppStream << CPWL_Utils::GetRectFillAppStream(rectWnd,
262 GetBackgroundColor());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263
Lei Zhangfac46f82017-06-02 14:20:04 -0700264 if (HasFlag(PWS_BORDER)) {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400265 *psAppStream << CPWL_Utils::GetBorderAppStream(
Lei Zhangfac46f82017-06-02 14:20:04 -0700266 rectWnd, (float)GetBorderWidth(), GetBorderColor(),
267 GetBorderLeftTopColor(GetBorderStyle()),
268 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
269 GetBorderDash());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700271}
272
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400273void CPWL_Wnd::GetChildAppearanceStream(std::ostringstream* psAppStream) {
tsepez6745f962017-01-04 10:09:45 -0800274 for (CPWL_Wnd* pChild : m_Children) {
275 if (pChild)
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400276 pChild->GetAppearanceStream(psAppStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700278}
279
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800281 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 if (IsValid() && IsVisible()) {
283 DrawThisAppearance(pDevice, pUser2Device);
284 DrawChildAppearance(pDevice, pUser2Device);
285 }
286}
287
288void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800289 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800290 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700291 if (rectWnd.IsEmpty())
292 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293
Lei Zhangfac46f82017-06-02 14:20:04 -0700294 if (HasFlag(PWS_BACKGROUND)) {
dan sinclaird6aff2f2017-07-13 21:36:29 -0400295 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
296 CPWL_Utils::DrawFillRect(pDevice, pUser2Device,
297 rectWnd.GetDeflated(width, width),
Lei Zhangfac46f82017-06-02 14:20:04 -0700298 GetBackgroundColor(), GetTransparency());
299 }
300
301 if (HasFlag(PWS_BORDER)) {
302 CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd,
303 (float)GetBorderWidth(), GetBorderColor(),
304 GetBorderLeftTopColor(GetBorderStyle()),
305 GetBorderRightBottomColor(GetBorderStyle()),
306 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700308}
309
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800311 CFX_Matrix* pUser2Device) {
tsepez6745f962017-01-04 10:09:45 -0800312 for (CPWL_Wnd* pChild : m_Children) {
313 if (!pChild)
314 continue;
315
316 CFX_Matrix mt = pChild->GetChildMatrix();
317 if (mt.IsIdentity()) {
318 pChild->DrawAppearance(pDevice, pUser2Device);
319 } else {
320 mt.Concat(*pUser2Device);
321 pChild->DrawAppearance(pDevice, &mt);
Lei Zhang60f507b2015-06-13 00:41:00 -0700322 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700324}
325
Tom Sepez281a9ea2016-02-26 14:24:28 -0800326void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700327 if (!IsValid())
328 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329
Lei Zhangfac46f82017-06-02 14:20:04 -0700330 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
331
332 if (!HasFlag(PWS_NOREFRESHCLIP)) {
333 CFX_FloatRect rcClip = GetClipRect();
334 if (!rcClip.IsEmpty()) {
335 rcRefresh.Intersect(rcClip);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700336 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700337 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700338
Lei Zhangfac46f82017-06-02 14:20:04 -0700339 FX_RECT rcWin = PWLtoWnd(rcRefresh);
Dan Sinclaira9e28432017-07-05 14:18:14 -0400340 rcWin.left -= kInvalidationInflate;
341 rcWin.top -= kInvalidationInflate;
342 rcWin.right += kInvalidationInflate;
343 rcWin.bottom += kInvalidationInflate;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344
Lei Zhangfac46f82017-06-02 14:20:04 -0700345 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
346 if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>(
347 m_sPrivateParam.pAttachedWidget.Get())) {
348 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700349 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700351}
352
tsepez6745f962017-01-04 10:09:45 -0800353#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
354 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
355 if (!IsValid() || !IsVisible() || !IsEnabled()) \
356 return false; \
357 if (!IsWndCaptureKeyboard(this)) \
358 return false; \
Lei Zhang375c2762017-03-10 14:37:14 -0800359 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800360 if (pChild && IsWndCaptureKeyboard(pChild)) \
361 return pChild->key_method_name(nChar, nFlag); \
362 } \
363 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700365
366PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367PWL_IMPLEMENT_KEY_METHOD(OnChar)
tsepez6745f962017-01-04 10:09:45 -0800368#undef PWL_IMPLEMENT_KEY_METHOD
369
370#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Dan Sinclairf528eee2017-02-14 11:52:07 -0500371 bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \
tsepez6745f962017-01-04 10:09:45 -0800372 if (!IsValid() || !IsVisible() || !IsEnabled()) \
373 return false; \
374 if (IsWndCaptureMouse(this)) { \
Lei Zhang375c2762017-03-10 14:37:14 -0800375 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800376 if (pChild && IsWndCaptureMouse(pChild)) { \
377 return pChild->mouse_method_name(pChild->ParentToChild(point), \
378 nFlag); \
379 } \
380 } \
381 SetCursor(); \
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 && pChild->WndHitTest(pChild->ParentToChild(point))) { \
386 return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \
387 } \
388 } \
389 if (WndHitTest(point)) \
390 SetCursor(); \
391 return false; \
392 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700393
394PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
395PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
396PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700397PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
398PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
399PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
tsepez6745f962017-01-04 10:09:45 -0800400#undef PWL_IMPLEMENT_MOUSE_METHOD
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700401
Diana Gagedce2d722017-06-20 11:17:11 -0700402CFX_WideString CPWL_Wnd::GetSelectedText() {
403 return CFX_WideString();
404}
405
tsepez4cf55152016-11-02 14:37:54 -0700406bool CPWL_Wnd::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500407 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700408 uint32_t nFlag) {
tsepez6745f962017-01-04 10:09:45 -0800409 if (!IsValid() || !IsVisible() || !IsEnabled())
410 return false;
411
412 SetCursor();
413 if (!IsWndCaptureKeyboard(this))
414 return false;
415
Lei Zhang375c2762017-03-10 14:37:14 -0800416 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800417 if (pChild && IsWndCaptureKeyboard(pChild))
418 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419 }
tsepez4cf55152016-11-02 14:37:54 -0700420 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700421}
422
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800424 m_Children.push_back(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700425}
426
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800428 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
429 if (*it && *it == pWnd) {
430 m_Children.erase(std::next(it).base());
431 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700432 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700434}
435
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400436void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {}
437
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400438void CPWL_Wnd::SetScrollPosition(float pos) {}
439
Dan Sinclair63fbd8d2017-07-05 14:10:36 -0400440void CPWL_Wnd::ScrollWindowVertically(float pos) {}
441
Dan Sinclair7f6bec92017-07-05 14:13:16 -0400442void CPWL_Wnd::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {}
443
444void CPWL_Wnd::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {}
445
446void CPWL_Wnd::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) {}
447
tsepez4cf55152016-11-02 14:37:54 -0700448bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 return m_bCreated;
450}
451
Lei Zhang7457e382016-01-06 23:00:34 -0800452const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 return m_sPrivateParam;
454}
455
456CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
457 return m_sPrivateParam.pParentWnd;
458}
459
Tom Sepez281a9ea2016-02-26 14:24:28 -0800460CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 return m_rcWindow;
462}
463
Tom Sepez281a9ea2016-02-26 14:24:28 -0800464CFX_FloatRect CPWL_Wnd::GetClientRect() const {
465 CFX_FloatRect rcWindow = GetWindowRect();
dan sinclairadf922f2017-07-12 21:56:27 -0400466
dan sinclaird6aff2f2017-07-13 21:36:29 -0400467 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
468 CFX_FloatRect rcClient = rcWindow.GetDeflated(width, width);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
470 rcClient.right -= pVSB->GetScrollBarWidth();
471
472 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800473 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474}
475
Dan Sinclairf528eee2017-02-14 11:52:07 -0500476CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800477 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500478 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
479 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480}
481
tsepez4cf55152016-11-02 14:37:54 -0700482bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
484}
485
tsepezc3255f52016-03-25 14:52:27 -0700486void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487 m_sPrivateParam.dwFlags &= ~dwFlags;
488}
489
tsepezc3255f52016-03-25 14:52:27 -0700490void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700491 m_sPrivateParam.dwFlags |= dwFlags;
492}
493
Dan Sinclair7f55a542017-07-13 14:17:10 -0400494CFX_Color CPWL_Wnd::GetBackgroundColor() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 return m_sPrivateParam.sBackgroundColor;
496}
497
Dan Sinclair7f55a542017-07-13 14:17:10 -0400498void CPWL_Wnd::SetBackgroundColor(const CFX_Color& color) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499 m_sPrivateParam.sBackgroundColor = color;
500}
501
Dan Sinclair7f55a542017-07-13 14:17:10 -0400502CFX_Color CPWL_Wnd::GetTextColor() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 return m_sPrivateParam.sTextColor;
504}
505
dsinclair92cb5e52016-05-16 11:38:28 -0700506BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 return m_sPrivateParam.nBorderStyle;
508}
509
dsinclair92cb5e52016-05-16 11:38:28 -0700510void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 if (HasFlag(PWS_BORDER))
512 m_sPrivateParam.nBorderStyle = nBorderStyle;
513}
514
515int32_t CPWL_Wnd::GetBorderWidth() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700516 return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517}
518
519int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520 return 0;
521}
522
Dan Sinclair7f55a542017-07-13 14:17:10 -0400523CFX_Color CPWL_Wnd::GetBorderColor() const {
524 return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525}
526
Lei Zhang7457e382016-01-06 23:00:34 -0800527const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 return m_sPrivateParam.sDash;
529}
530
531void* CPWL_Wnd::GetAttachedData() const {
532 return m_sPrivateParam.pAttachedData;
533}
534
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700536 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537}
538
539void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
540 CreateVScrollBar(cp);
541}
542
543void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700544 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
545 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546
Lei Zhangfac46f82017-06-02 14:20:04 -0700547 PWL_CREATEPARAM scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548
Lei Zhangfac46f82017-06-02 14:20:04 -0700549 // flags
550 scp.dwFlags =
551 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552
Lei Zhangfac46f82017-06-02 14:20:04 -0700553 scp.pParentWnd = this;
554 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
555 scp.eCursorType = FXCT_ARROW;
556 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
557
558 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
559 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560}
561
562void CPWL_Wnd::SetCapture() {
563 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
564 pMsgCtrl->SetCapture(this);
565}
566
567void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800568 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800569 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800571 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
573 pMsgCtrl->ReleaseCapture();
574}
575
576void CPWL_Wnd::SetFocus() {
577 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
578 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
579 pMsgCtrl->KillFocus();
580 pMsgCtrl->SetFocus(this);
581 }
582}
583
584void CPWL_Wnd::KillFocus() {
585 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
586 if (pMsgCtrl->IsWndCaptureKeyboard(this))
587 pMsgCtrl->KillFocus();
588 }
589}
590
591void CPWL_Wnd::OnSetFocus() {}
592
593void CPWL_Wnd::OnKillFocus() {}
594
Dan Sinclairf528eee2017-02-14 11:52:07 -0500595bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500596 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597}
598
Dan Sinclairf528eee2017-02-14 11:52:07 -0500599bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500600 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601}
602
603const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700604 auto* pParent = m_sPrivateParam.pParentWnd;
605 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606}
607
tsepez4cf55152016-11-02 14:37:54 -0700608void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800609 if (!IsValid())
610 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611
Lei Zhang375c2762017-03-10 14:37:14 -0800612 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800613 if (pChild)
614 pChild->SetVisible(bVisible);
615 }
616 if (bVisible != m_bVisible) {
617 m_bVisible = bVisible;
618 RePosChildWnd();
619 InvalidateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700621}
622
Tom Sepez281a9ea2016-02-26 14:24:28 -0800623void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 m_rcClip = rect;
625 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700626}
627
Tom Sepez281a9ea2016-02-26 14:24:28 -0800628const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700630}
631
tsepez4cf55152016-11-02 14:37:54 -0700632bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634}
635
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700637 CPWL_ScrollBar* pVSB = GetVScrollBar();
638 if (!pVSB)
639 return;
640
dan sinclairadf922f2017-07-12 21:56:27 -0400641 CFX_FloatRect rcContent = GetWindowRect();
642 if (!rcContent.IsEmpty()) {
643 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
644 rcContent.Deflate(width, width);
645 rcContent.Normalize();
646 }
Tom Sepez281a9ea2016-02-26 14:24:28 -0800647 CFX_FloatRect rcVScroll =
648 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
649 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700650 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700651}
652
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
654
655void CPWL_Wnd::SetCursor() {
656 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700657 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700658 int32_t nCursorType = GetCreationParam().eCursorType;
659 pSH->SetCursor(nCursorType);
660 }
661 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700662}
663
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700664void CPWL_Wnd::CreateMsgControl() {
665 if (!m_sPrivateParam.pMsgControl)
666 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700667}
668
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700670 CPWL_MsgControl* pMsgControl = GetMsgControl();
671 if (pMsgControl && pMsgControl->IsWndCreated(this))
672 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700673}
674
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
676 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677}
678
tsepez4cf55152016-11-02 14:37:54 -0700679bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681}
682
tsepez4cf55152016-11-02 14:37:54 -0700683bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700684 CPWL_MsgControl* pCtrl = GetMsgControl();
685 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700686}
687
tsepez4cf55152016-11-02 14:37:54 -0700688bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700689 CPWL_MsgControl* pCtrl = GetMsgControl();
690 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700691}
692
tsepez4cf55152016-11-02 14:37:54 -0700693bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700694 CPWL_MsgControl* pCtrl = GetMsgControl();
695 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700696}
697
Tom Sepez281a9ea2016-02-26 14:24:28 -0800698CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
dan sinclairadf922f2017-07-12 21:56:27 -0400699 CFX_FloatRect rect = GetWindowRect();
700 if (!rect.IsEmpty()) {
701 rect.Inflate(1.0f, 1.0f);
702 rect.Normalize();
703 }
704 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705}
706
Dan Sinclair05df0752017-03-14 14:43:42 -0400707float CPWL_Wnd::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700708 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700709}
710
Dan Sinclair05df0752017-03-14 14:43:42 -0400711void CPWL_Wnd::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700712 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700713}
714
dsinclairb9590102016-04-27 06:38:59 -0700715CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700717}
718
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
720 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700721}
722
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700723IPWL_Provider* CPWL_Wnd::GetProvider() const {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500724 return m_sPrivateParam.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700725}
726
dsinclairc7a73492016-04-05 12:01:42 -0700727IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700729}
730
Dan Sinclair7f55a542017-07-13 14:17:10 -0400731CFX_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700733 case BorderStyle::BEVELED:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400734 return CFX_Color(COLORTYPE_GRAY, 1);
dsinclair92cb5e52016-05-16 11:38:28 -0700735 case BorderStyle::INSET:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400736 return CFX_Color(COLORTYPE_GRAY, 0.5f);
dsinclair92cb5e52016-05-16 11:38:28 -0700737 default:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400738 return CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700740}
741
Dan Sinclair7f55a542017-07-13 14:17:10 -0400742CFX_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700744 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500745 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700746 case BorderStyle::INSET:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400747 return CFX_Color(COLORTYPE_GRAY, 0.75f);
dsinclair92cb5e52016-05-16 11:38:28 -0700748 default:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400749 return CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751}
752
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753int32_t CPWL_Wnd::GetTransparency() {
754 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700755}
756
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700757void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800758 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800759 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700760 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700762 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700763}
764
Tom Sepez60d909e2015-12-10 15:34:55 -0800765CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
766 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800767 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700770}
771
Tom Sepez281a9ea2016-02-26 14:24:28 -0800772FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
773 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800774 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775 mt.TransformRect(rcTemp);
776 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
777 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700778}
779
Dan Sinclairf528eee2017-02-14 11:52:07 -0500780CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800781 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700782 if (mt.IsIdentity())
783 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700784
Nicolas Penab21f1742017-06-29 12:02:06 -0400785 CFX_Matrix inverse = mt.GetInverse();
786 if (!inverse.IsIdentity())
787 mt = inverse;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500788 return mt.Transform(point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700789}
790
Tom Sepez281a9ea2016-02-26 14:24:28 -0800791CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800792 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793 if (mt.IsIdentity())
794 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700795
Nicolas Penab21f1742017-06-29 12:02:06 -0400796 CFX_Matrix inverse = mt.GetInverse();
797 if (!inverse.IsIdentity())
798 mt = inverse;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800799 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800 mt.TransformRect(rc);
801 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700802}
803
Tom Sepez60d909e2015-12-10 15:34:55 -0800804CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700805 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806 if (HasFlag(PWS_CHILD)) {
807 const CPWL_Wnd* pParent = this;
808 while (pParent) {
809 mt.Concat(pParent->GetChildMatrix());
810 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700811 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700812 }
813 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700814}
815
Tom Sepez60d909e2015-12-10 15:34:55 -0800816CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700817 return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700818}
819
Tom Sepez60d909e2015-12-10 15:34:55 -0800820void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700821 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700822}
823
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700824const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800825 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700826 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700827}
828
tsepez4cf55152016-11-02 14:37:54 -0700829void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800830 if (m_bEnabled == bEnable)
831 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700832
Lei Zhang375c2762017-03-10 14:37:14 -0800833 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800834 if (pChild)
835 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836 }
tsepez6745f962017-01-04 10:09:45 -0800837 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700838}
839
tsepez4cf55152016-11-02 14:37:54 -0700840bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500841 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
842 return pSystemHandler && pSystemHandler->IsCTRLKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700843}
844
tsepez4cf55152016-11-02 14:37:54 -0700845bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500846 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
847 return pSystemHandler && pSystemHandler->IsSHIFTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700848}
849
tsepez4cf55152016-11-02 14:37:54 -0700850bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500851 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
852 return pSystemHandler && pSystemHandler->IsALTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700853}