blob: 552c901f06bc4f88f40ff92eca3f5c4c2f4150ff [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 sinclairadf922f2017-07-12 21:56:27 -0400295 CFX_FloatRect rcClient = rectWnd;
296 if (!rcClient.IsEmpty()) {
297 float width =
298 static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
299 rcClient.Deflate(width, width);
300 rcClient.Normalize();
301 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700302 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
303 GetBackgroundColor(), GetTransparency());
304 }
305
306 if (HasFlag(PWS_BORDER)) {
307 CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd,
308 (float)GetBorderWidth(), GetBorderColor(),
309 GetBorderLeftTopColor(GetBorderStyle()),
310 GetBorderRightBottomColor(GetBorderStyle()),
311 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700313}
314
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800316 CFX_Matrix* pUser2Device) {
tsepez6745f962017-01-04 10:09:45 -0800317 for (CPWL_Wnd* pChild : m_Children) {
318 if (!pChild)
319 continue;
320
321 CFX_Matrix mt = pChild->GetChildMatrix();
322 if (mt.IsIdentity()) {
323 pChild->DrawAppearance(pDevice, pUser2Device);
324 } else {
325 mt.Concat(*pUser2Device);
326 pChild->DrawAppearance(pDevice, &mt);
Lei Zhang60f507b2015-06-13 00:41:00 -0700327 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700329}
330
Tom Sepez281a9ea2016-02-26 14:24:28 -0800331void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700332 if (!IsValid())
333 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334
Lei Zhangfac46f82017-06-02 14:20:04 -0700335 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
336
337 if (!HasFlag(PWS_NOREFRESHCLIP)) {
338 CFX_FloatRect rcClip = GetClipRect();
339 if (!rcClip.IsEmpty()) {
340 rcRefresh.Intersect(rcClip);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700341 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700342 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700343
Lei Zhangfac46f82017-06-02 14:20:04 -0700344 FX_RECT rcWin = PWLtoWnd(rcRefresh);
Dan Sinclaira9e28432017-07-05 14:18:14 -0400345 rcWin.left -= kInvalidationInflate;
346 rcWin.top -= kInvalidationInflate;
347 rcWin.right += kInvalidationInflate;
348 rcWin.bottom += kInvalidationInflate;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349
Lei Zhangfac46f82017-06-02 14:20:04 -0700350 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
351 if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>(
352 m_sPrivateParam.pAttachedWidget.Get())) {
353 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700354 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700356}
357
tsepez6745f962017-01-04 10:09:45 -0800358#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
359 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
360 if (!IsValid() || !IsVisible() || !IsEnabled()) \
361 return false; \
362 if (!IsWndCaptureKeyboard(this)) \
363 return false; \
Lei Zhang375c2762017-03-10 14:37:14 -0800364 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800365 if (pChild && IsWndCaptureKeyboard(pChild)) \
366 return pChild->key_method_name(nChar, nFlag); \
367 } \
368 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700370
371PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700372PWL_IMPLEMENT_KEY_METHOD(OnChar)
tsepez6745f962017-01-04 10:09:45 -0800373#undef PWL_IMPLEMENT_KEY_METHOD
374
375#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Dan Sinclairf528eee2017-02-14 11:52:07 -0500376 bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \
tsepez6745f962017-01-04 10:09:45 -0800377 if (!IsValid() || !IsVisible() || !IsEnabled()) \
378 return false; \
379 if (IsWndCaptureMouse(this)) { \
Lei Zhang375c2762017-03-10 14:37:14 -0800380 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800381 if (pChild && IsWndCaptureMouse(pChild)) { \
382 return pChild->mouse_method_name(pChild->ParentToChild(point), \
383 nFlag); \
384 } \
385 } \
386 SetCursor(); \
387 return false; \
388 } \
Lei Zhang375c2762017-03-10 14:37:14 -0800389 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800390 if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \
391 return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \
392 } \
393 } \
394 if (WndHitTest(point)) \
395 SetCursor(); \
396 return false; \
397 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700398
399PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
400PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
401PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700402PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
403PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
404PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
tsepez6745f962017-01-04 10:09:45 -0800405#undef PWL_IMPLEMENT_MOUSE_METHOD
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700406
Diana Gagedce2d722017-06-20 11:17:11 -0700407CFX_WideString CPWL_Wnd::GetSelectedText() {
408 return CFX_WideString();
409}
410
tsepez4cf55152016-11-02 14:37:54 -0700411bool CPWL_Wnd::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500412 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700413 uint32_t nFlag) {
tsepez6745f962017-01-04 10:09:45 -0800414 if (!IsValid() || !IsVisible() || !IsEnabled())
415 return false;
416
417 SetCursor();
418 if (!IsWndCaptureKeyboard(this))
419 return false;
420
Lei Zhang375c2762017-03-10 14:37:14 -0800421 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800422 if (pChild && IsWndCaptureKeyboard(pChild))
423 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424 }
tsepez4cf55152016-11-02 14:37:54 -0700425 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700426}
427
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800429 m_Children.push_back(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700430}
431
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800433 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
434 if (*it && *it == pWnd) {
435 m_Children.erase(std::next(it).base());
436 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700437 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700439}
440
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400441void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {}
442
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400443void CPWL_Wnd::SetScrollPosition(float pos) {}
444
Dan Sinclair63fbd8d2017-07-05 14:10:36 -0400445void CPWL_Wnd::ScrollWindowVertically(float pos) {}
446
Dan Sinclair7f6bec92017-07-05 14:13:16 -0400447void CPWL_Wnd::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {}
448
449void CPWL_Wnd::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {}
450
451void CPWL_Wnd::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) {}
452
tsepez4cf55152016-11-02 14:37:54 -0700453bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454 return m_bCreated;
455}
456
Lei Zhang7457e382016-01-06 23:00:34 -0800457const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 return m_sPrivateParam;
459}
460
461CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
462 return m_sPrivateParam.pParentWnd;
463}
464
Tom Sepez281a9ea2016-02-26 14:24:28 -0800465CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 return m_rcWindow;
467}
468
Tom Sepez281a9ea2016-02-26 14:24:28 -0800469CFX_FloatRect CPWL_Wnd::GetClientRect() const {
470 CFX_FloatRect rcWindow = GetWindowRect();
dan sinclairadf922f2017-07-12 21:56:27 -0400471 CFX_FloatRect rcClient = rcWindow;
472 if (!rcClient.IsEmpty()) {
473 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
474 rcClient.Deflate(width, width);
475 rcClient.Normalize();
476 }
477
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
479 rcClient.right -= pVSB->GetScrollBarWidth();
480
481 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800482 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483}
484
Dan Sinclairf528eee2017-02-14 11:52:07 -0500485CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800486 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500487 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
488 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489}
490
tsepez4cf55152016-11-02 14:37:54 -0700491bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
493}
494
tsepezc3255f52016-03-25 14:52:27 -0700495void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 m_sPrivateParam.dwFlags &= ~dwFlags;
497}
498
tsepezc3255f52016-03-25 14:52:27 -0700499void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 m_sPrivateParam.dwFlags |= dwFlags;
501}
502
503CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
504 return m_sPrivateParam.sBackgroundColor;
505}
506
507void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
508 m_sPrivateParam.sBackgroundColor = color;
509}
510
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511CPWL_Color CPWL_Wnd::GetTextColor() const {
512 return m_sPrivateParam.sTextColor;
513}
514
dsinclair92cb5e52016-05-16 11:38:28 -0700515BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516 return m_sPrivateParam.nBorderStyle;
517}
518
dsinclair92cb5e52016-05-16 11:38:28 -0700519void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520 if (HasFlag(PWS_BORDER))
521 m_sPrivateParam.nBorderStyle = nBorderStyle;
522}
523
524int32_t CPWL_Wnd::GetBorderWidth() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700525 return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526}
527
528int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529 return 0;
530}
531
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532CPWL_Color CPWL_Wnd::GetBorderColor() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700533 return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534}
535
Lei Zhang7457e382016-01-06 23:00:34 -0800536const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 return m_sPrivateParam.sDash;
538}
539
540void* CPWL_Wnd::GetAttachedData() const {
541 return m_sPrivateParam.pAttachedData;
542}
543
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700545 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546}
547
548void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
549 CreateVScrollBar(cp);
550}
551
552void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700553 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
554 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555
Lei Zhangfac46f82017-06-02 14:20:04 -0700556 PWL_CREATEPARAM scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557
Lei Zhangfac46f82017-06-02 14:20:04 -0700558 // flags
559 scp.dwFlags =
560 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561
Lei Zhangfac46f82017-06-02 14:20:04 -0700562 scp.pParentWnd = this;
563 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
564 scp.eCursorType = FXCT_ARROW;
565 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
566
567 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
568 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569}
570
571void CPWL_Wnd::SetCapture() {
572 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
573 pMsgCtrl->SetCapture(this);
574}
575
576void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800577 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800578 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800580 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
582 pMsgCtrl->ReleaseCapture();
583}
584
585void CPWL_Wnd::SetFocus() {
586 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
587 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
588 pMsgCtrl->KillFocus();
589 pMsgCtrl->SetFocus(this);
590 }
591}
592
593void CPWL_Wnd::KillFocus() {
594 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
595 if (pMsgCtrl->IsWndCaptureKeyboard(this))
596 pMsgCtrl->KillFocus();
597 }
598}
599
600void CPWL_Wnd::OnSetFocus() {}
601
602void CPWL_Wnd::OnKillFocus() {}
603
Dan Sinclairf528eee2017-02-14 11:52:07 -0500604bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500605 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606}
607
Dan Sinclairf528eee2017-02-14 11:52:07 -0500608bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500609 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610}
611
612const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700613 auto* pParent = m_sPrivateParam.pParentWnd;
614 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615}
616
tsepez4cf55152016-11-02 14:37:54 -0700617void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800618 if (!IsValid())
619 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620
Lei Zhang375c2762017-03-10 14:37:14 -0800621 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800622 if (pChild)
623 pChild->SetVisible(bVisible);
624 }
625 if (bVisible != m_bVisible) {
626 m_bVisible = bVisible;
627 RePosChildWnd();
628 InvalidateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700630}
631
Tom Sepez281a9ea2016-02-26 14:24:28 -0800632void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633 m_rcClip = rect;
634 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635}
636
Tom Sepez281a9ea2016-02-26 14:24:28 -0800637const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700639}
640
tsepez4cf55152016-11-02 14:37:54 -0700641bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700642 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700643}
644
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700646 CPWL_ScrollBar* pVSB = GetVScrollBar();
647 if (!pVSB)
648 return;
649
dan sinclairadf922f2017-07-12 21:56:27 -0400650 CFX_FloatRect rcContent = GetWindowRect();
651 if (!rcContent.IsEmpty()) {
652 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
653 rcContent.Deflate(width, width);
654 rcContent.Normalize();
655 }
Tom Sepez281a9ea2016-02-26 14:24:28 -0800656 CFX_FloatRect rcVScroll =
657 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
658 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700659 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700660}
661
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700662void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
663
664void CPWL_Wnd::SetCursor() {
665 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700666 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 int32_t nCursorType = GetCreationParam().eCursorType;
668 pSH->SetCursor(nCursorType);
669 }
670 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700671}
672
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673void CPWL_Wnd::CreateMsgControl() {
674 if (!m_sPrivateParam.pMsgControl)
675 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700676}
677
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700679 CPWL_MsgControl* pMsgControl = GetMsgControl();
680 if (pMsgControl && pMsgControl->IsWndCreated(this))
681 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700682}
683
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
685 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700686}
687
tsepez4cf55152016-11-02 14:37:54 -0700688bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700690}
691
tsepez4cf55152016-11-02 14:37:54 -0700692bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700693 CPWL_MsgControl* pCtrl = GetMsgControl();
694 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700695}
696
tsepez4cf55152016-11-02 14:37:54 -0700697bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700698 CPWL_MsgControl* pCtrl = GetMsgControl();
699 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700700}
701
tsepez4cf55152016-11-02 14:37:54 -0700702bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700703 CPWL_MsgControl* pCtrl = GetMsgControl();
704 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705}
706
Tom Sepez281a9ea2016-02-26 14:24:28 -0800707CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
dan sinclairadf922f2017-07-12 21:56:27 -0400708 CFX_FloatRect rect = GetWindowRect();
709 if (!rect.IsEmpty()) {
710 rect.Inflate(1.0f, 1.0f);
711 rect.Normalize();
712 }
713 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700714}
715
Dan Sinclair05df0752017-03-14 14:43:42 -0400716float CPWL_Wnd::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700718}
719
Dan Sinclair05df0752017-03-14 14:43:42 -0400720void CPWL_Wnd::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700722}
723
dsinclairb9590102016-04-27 06:38:59 -0700724CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700726}
727
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
729 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700730}
731
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732IPWL_Provider* CPWL_Wnd::GetProvider() const {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500733 return m_sPrivateParam.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700734}
735
dsinclairc7a73492016-04-05 12:01:42 -0700736IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700738}
739
dsinclair92cb5e52016-05-16 11:38:28 -0700740CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700741 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700742 case BorderStyle::BEVELED:
743 return CPWL_Color(COLORTYPE_GRAY, 1);
744 case BorderStyle::INSET:
745 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
746 default:
747 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700749}
750
dsinclair92cb5e52016-05-16 11:38:28 -0700751CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700752 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700753 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500754 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700755 case BorderStyle::INSET:
756 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
757 default:
758 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700759 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700760}
761
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700762int32_t CPWL_Wnd::GetTransparency() {
763 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700764}
765
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700766void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800767 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800768 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700770 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700771 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700772}
773
Tom Sepez60d909e2015-12-10 15:34:55 -0800774CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
775 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800776 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700777 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700778 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700779}
780
Tom Sepez281a9ea2016-02-26 14:24:28 -0800781FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
782 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800783 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784 mt.TransformRect(rcTemp);
785 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
786 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700787}
788
Dan Sinclairf528eee2017-02-14 11:52:07 -0500789CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800790 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700791 if (mt.IsIdentity())
792 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700793
Nicolas Penab21f1742017-06-29 12:02:06 -0400794 CFX_Matrix inverse = mt.GetInverse();
795 if (!inverse.IsIdentity())
796 mt = inverse;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500797 return mt.Transform(point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700798}
799
Tom Sepez281a9ea2016-02-26 14:24:28 -0800800CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800801 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802 if (mt.IsIdentity())
803 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700804
Nicolas Penab21f1742017-06-29 12:02:06 -0400805 CFX_Matrix inverse = mt.GetInverse();
806 if (!inverse.IsIdentity())
807 mt = inverse;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800808 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700809 mt.TransformRect(rc);
810 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700811}
812
Tom Sepez60d909e2015-12-10 15:34:55 -0800813CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700814 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700815 if (HasFlag(PWS_CHILD)) {
816 const CPWL_Wnd* pParent = this;
817 while (pParent) {
818 mt.Concat(pParent->GetChildMatrix());
819 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700820 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700821 }
822 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700823}
824
Tom Sepez60d909e2015-12-10 15:34:55 -0800825CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700826 return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700827}
828
Tom Sepez60d909e2015-12-10 15:34:55 -0800829void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700830 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700831}
832
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700833const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800834 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700835 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836}
837
tsepez4cf55152016-11-02 14:37:54 -0700838void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800839 if (m_bEnabled == bEnable)
840 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700841
Lei Zhang375c2762017-03-10 14:37:14 -0800842 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800843 if (pChild)
844 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700845 }
tsepez6745f962017-01-04 10:09:45 -0800846 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700847}
848
tsepez4cf55152016-11-02 14:37:54 -0700849bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500850 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
851 return pSystemHandler && pSystemHandler->IsCTRLKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700852}
853
tsepez4cf55152016-11-02 14:37:54 -0700854bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500855 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
856 return pSystemHandler && pSystemHandler->IsSHIFTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700857}
858
tsepez4cf55152016-11-02 14:37:54 -0700859bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500860 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
861 return pSystemHandler && pSystemHandler->IsALTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700862}