blob: 6e2e75c5a116db621ffa583362c5dd24efdea017 [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;
158 m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f);
159 CreateMsgControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160
Lei Zhangfac46f82017-06-02 14:20:04 -0700161 if (m_sPrivateParam.pParentWnd)
Dan Sinclaire5e889e2017-07-05 08:45:40 -0400162 m_sPrivateParam.pParentWnd->AddChild(this);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163
Lei Zhangfac46f82017-06-02 14:20:04 -0700164 PWL_CREATEPARAM ccp = m_sPrivateParam;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165
Lei Zhangfac46f82017-06-02 14:20:04 -0700166 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
167 CreateScrollBar(ccp);
168 CreateChildWnd(ccp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169
Lei Zhangfac46f82017-06-02 14:20:04 -0700170 m_bVisible = HasFlag(PWS_VISIBLE);
171 OnCreated();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172
Lei Zhangfac46f82017-06-02 14:20:04 -0700173 RePosChildWnd();
174 m_bCreated = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700175}
176
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179void CPWL_Wnd::OnCreated() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700180
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181void CPWL_Wnd::OnDestroy() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700182
Lei Zhangab5537d2016-01-06 14:58:14 -0800183void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) {
184 if (m_sPrivateParam.pFocusHandler == handler)
185 m_sPrivateParam.pFocusHandler = nullptr;
186}
187
188void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500189 if (m_sPrivateParam.pProvider.Get() == provider)
190 m_sPrivateParam.pProvider.Reset();
Lei Zhangab5537d2016-01-06 14:58:14 -0800191}
192
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193void CPWL_Wnd::Destroy() {
194 KillFocus();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 OnDestroy();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 if (m_bCreated) {
Lei Zhang35162562017-06-09 01:04:52 -0700197 m_pVScrollBar = nullptr;
tsepez6745f962017-01-04 10:09:45 -0800198 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
199 if (CPWL_Wnd* pChild = *it) {
200 *it = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201 pChild->Destroy();
202 delete pChild;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 }
204 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 if (m_sPrivateParam.pParentWnd)
Dan Sinclaire5e889e2017-07-05 08:45:40 -0400206 m_sPrivateParam.pParentWnd->RemoveChild(this);
tsepez6745f962017-01-04 10:09:45 -0800207
tsepez4cf55152016-11-02 14:37:54 -0700208 m_bCreated = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 DestroyMsgControl();
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500211 m_sPrivateParam.Reset();
tsepez6745f962017-01-04 10:09:45 -0800212 m_Children.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700214
tsepez4cf55152016-11-02 14:37:54 -0700215void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700216 if (!IsValid())
217 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700218
Lei Zhangfac46f82017-06-02 14:20:04 -0700219 CFX_FloatRect rcOld = GetWindowRect();
220 m_rcWindow = rcNew;
221 m_rcWindow.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222
Lei Zhangfac46f82017-06-02 14:20:04 -0700223 if (bReset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
225 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700226 RePosChildWnd();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700227 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700229 if (bRefresh)
230 InvalidateRectMove(rcOld, rcNew);
231
232 m_sPrivateParam.rcRectWnd = m_rcWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233}
234
Tom Sepez281a9ea2016-02-26 14:24:28 -0800235void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
236 const CFX_FloatRect& rcNew) {
237 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 InvalidateRect(&rcUnion);
241}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700242
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400243void CPWL_Wnd::GetAppearanceStream(std::ostringstream* psAppStream) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 if (IsValid() && IsVisible()) {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400245 GetThisAppearanceStream(psAppStream);
246 GetChildAppearanceStream(psAppStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247 }
248}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700249
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250// if don't set,Get default apperance stream
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400251void CPWL_Wnd::GetThisAppearanceStream(std::ostringstream* psAppStream) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800252 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700253 if (rectWnd.IsEmpty())
254 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255
Lei Zhangfac46f82017-06-02 14:20:04 -0700256 if (HasFlag(PWS_BACKGROUND))
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400257 *psAppStream << CPWL_Utils::GetRectFillAppStream(rectWnd,
258 GetBackgroundColor());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259
Lei Zhangfac46f82017-06-02 14:20:04 -0700260 if (HasFlag(PWS_BORDER)) {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400261 *psAppStream << CPWL_Utils::GetBorderAppStream(
Lei Zhangfac46f82017-06-02 14:20:04 -0700262 rectWnd, (float)GetBorderWidth(), GetBorderColor(),
263 GetBorderLeftTopColor(GetBorderStyle()),
264 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
265 GetBorderDash());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700267}
268
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400269void CPWL_Wnd::GetChildAppearanceStream(std::ostringstream* psAppStream) {
tsepez6745f962017-01-04 10:09:45 -0800270 for (CPWL_Wnd* pChild : m_Children) {
271 if (pChild)
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400272 pChild->GetAppearanceStream(psAppStream);
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::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800277 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278 if (IsValid() && IsVisible()) {
279 DrawThisAppearance(pDevice, pUser2Device);
280 DrawChildAppearance(pDevice, pUser2Device);
281 }
282}
283
284void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800285 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800286 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700287 if (rectWnd.IsEmpty())
288 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289
Lei Zhangfac46f82017-06-02 14:20:04 -0700290 if (HasFlag(PWS_BACKGROUND)) {
291 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
292 rectWnd, (float)(GetBorderWidth() + GetInnerBorderWidth()));
293 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
294 GetBackgroundColor(), GetTransparency());
295 }
296
297 if (HasFlag(PWS_BORDER)) {
298 CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd,
299 (float)GetBorderWidth(), GetBorderColor(),
300 GetBorderLeftTopColor(GetBorderStyle()),
301 GetBorderRightBottomColor(GetBorderStyle()),
302 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700304}
305
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800307 CFX_Matrix* pUser2Device) {
tsepez6745f962017-01-04 10:09:45 -0800308 for (CPWL_Wnd* pChild : m_Children) {
309 if (!pChild)
310 continue;
311
312 CFX_Matrix mt = pChild->GetChildMatrix();
313 if (mt.IsIdentity()) {
314 pChild->DrawAppearance(pDevice, pUser2Device);
315 } else {
316 mt.Concat(*pUser2Device);
317 pChild->DrawAppearance(pDevice, &mt);
Lei Zhang60f507b2015-06-13 00:41:00 -0700318 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700320}
321
Tom Sepez281a9ea2016-02-26 14:24:28 -0800322void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700323 if (!IsValid())
324 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325
Lei Zhangfac46f82017-06-02 14:20:04 -0700326 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
327
328 if (!HasFlag(PWS_NOREFRESHCLIP)) {
329 CFX_FloatRect rcClip = GetClipRect();
330 if (!rcClip.IsEmpty()) {
331 rcRefresh.Intersect(rcClip);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700332 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700333 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700334
Lei Zhangfac46f82017-06-02 14:20:04 -0700335 FX_RECT rcWin = PWLtoWnd(rcRefresh);
Dan Sinclaira9e28432017-07-05 14:18:14 -0400336 rcWin.left -= kInvalidationInflate;
337 rcWin.top -= kInvalidationInflate;
338 rcWin.right += kInvalidationInflate;
339 rcWin.bottom += kInvalidationInflate;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340
Lei Zhangfac46f82017-06-02 14:20:04 -0700341 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
342 if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>(
343 m_sPrivateParam.pAttachedWidget.Get())) {
344 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700345 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700346 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700347}
348
tsepez6745f962017-01-04 10:09:45 -0800349#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
350 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
351 if (!IsValid() || !IsVisible() || !IsEnabled()) \
352 return false; \
353 if (!IsWndCaptureKeyboard(this)) \
354 return false; \
Lei Zhang375c2762017-03-10 14:37:14 -0800355 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800356 if (pChild && IsWndCaptureKeyboard(pChild)) \
357 return pChild->key_method_name(nChar, nFlag); \
358 } \
359 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700361
362PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700363PWL_IMPLEMENT_KEY_METHOD(OnChar)
tsepez6745f962017-01-04 10:09:45 -0800364#undef PWL_IMPLEMENT_KEY_METHOD
365
366#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Dan Sinclairf528eee2017-02-14 11:52:07 -0500367 bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \
tsepez6745f962017-01-04 10:09:45 -0800368 if (!IsValid() || !IsVisible() || !IsEnabled()) \
369 return false; \
370 if (IsWndCaptureMouse(this)) { \
Lei Zhang375c2762017-03-10 14:37:14 -0800371 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800372 if (pChild && IsWndCaptureMouse(pChild)) { \
373 return pChild->mouse_method_name(pChild->ParentToChild(point), \
374 nFlag); \
375 } \
376 } \
377 SetCursor(); \
378 return false; \
379 } \
Lei Zhang375c2762017-03-10 14:37:14 -0800380 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800381 if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \
382 return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \
383 } \
384 } \
385 if (WndHitTest(point)) \
386 SetCursor(); \
387 return false; \
388 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389
390PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
391PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
392PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700393PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
394PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
395PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
tsepez6745f962017-01-04 10:09:45 -0800396#undef PWL_IMPLEMENT_MOUSE_METHOD
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700397
Diana Gagedce2d722017-06-20 11:17:11 -0700398CFX_WideString CPWL_Wnd::GetSelectedText() {
399 return CFX_WideString();
400}
401
tsepez4cf55152016-11-02 14:37:54 -0700402bool CPWL_Wnd::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500403 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700404 uint32_t nFlag) {
tsepez6745f962017-01-04 10:09:45 -0800405 if (!IsValid() || !IsVisible() || !IsEnabled())
406 return false;
407
408 SetCursor();
409 if (!IsWndCaptureKeyboard(this))
410 return false;
411
Lei Zhang375c2762017-03-10 14:37:14 -0800412 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800413 if (pChild && IsWndCaptureKeyboard(pChild))
414 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415 }
tsepez4cf55152016-11-02 14:37:54 -0700416 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700417}
418
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800420 m_Children.push_back(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700421}
422
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800424 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
425 if (*it && *it == pWnd) {
426 m_Children.erase(std::next(it).base());
427 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700428 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700430}
431
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400432void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {}
433
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400434void CPWL_Wnd::SetScrollPosition(float pos) {}
435
Dan Sinclair63fbd8d2017-07-05 14:10:36 -0400436void CPWL_Wnd::ScrollWindowVertically(float pos) {}
437
Dan Sinclair7f6bec92017-07-05 14:13:16 -0400438void CPWL_Wnd::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {}
439
440void CPWL_Wnd::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {}
441
442void CPWL_Wnd::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) {}
443
tsepez4cf55152016-11-02 14:37:54 -0700444bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445 return m_bCreated;
446}
447
Lei Zhang7457e382016-01-06 23:00:34 -0800448const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 return m_sPrivateParam;
450}
451
452CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
453 return m_sPrivateParam.pParentWnd;
454}
455
Tom Sepez281a9ea2016-02-26 14:24:28 -0800456CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457 return m_rcWindow;
458}
459
Tom Sepez281a9ea2016-02-26 14:24:28 -0800460CFX_FloatRect CPWL_Wnd::GetClientRect() const {
461 CFX_FloatRect rcWindow = GetWindowRect();
462 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400463 rcWindow, (float)(GetBorderWidth() + GetInnerBorderWidth()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
465 rcClient.right -= pVSB->GetScrollBarWidth();
466
467 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800468 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469}
470
Dan Sinclairf528eee2017-02-14 11:52:07 -0500471CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800472 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500473 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
474 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475}
476
tsepez4cf55152016-11-02 14:37:54 -0700477bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
479}
480
tsepezc3255f52016-03-25 14:52:27 -0700481void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 m_sPrivateParam.dwFlags &= ~dwFlags;
483}
484
tsepezc3255f52016-03-25 14:52:27 -0700485void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486 m_sPrivateParam.dwFlags |= dwFlags;
487}
488
489CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
490 return m_sPrivateParam.sBackgroundColor;
491}
492
493void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
494 m_sPrivateParam.sBackgroundColor = color;
495}
496
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497CPWL_Color CPWL_Wnd::GetTextColor() const {
498 return m_sPrivateParam.sTextColor;
499}
500
dsinclair92cb5e52016-05-16 11:38:28 -0700501BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 return m_sPrivateParam.nBorderStyle;
503}
504
dsinclair92cb5e52016-05-16 11:38:28 -0700505void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 if (HasFlag(PWS_BORDER))
507 m_sPrivateParam.nBorderStyle = nBorderStyle;
508}
509
510int32_t CPWL_Wnd::GetBorderWidth() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700511 return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512}
513
514int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 return 0;
516}
517
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518CPWL_Color CPWL_Wnd::GetBorderColor() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700519 return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520}
521
Lei Zhang7457e382016-01-06 23:00:34 -0800522const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 return m_sPrivateParam.sDash;
524}
525
526void* CPWL_Wnd::GetAttachedData() const {
527 return m_sPrivateParam.pAttachedData;
528}
529
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700531 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532}
533
534void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
535 CreateVScrollBar(cp);
536}
537
538void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700539 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
540 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541
Lei Zhangfac46f82017-06-02 14:20:04 -0700542 PWL_CREATEPARAM scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543
Lei Zhangfac46f82017-06-02 14:20:04 -0700544 // flags
545 scp.dwFlags =
546 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547
Lei Zhangfac46f82017-06-02 14:20:04 -0700548 scp.pParentWnd = this;
549 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
550 scp.eCursorType = FXCT_ARROW;
551 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
552
553 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
554 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555}
556
557void CPWL_Wnd::SetCapture() {
558 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
559 pMsgCtrl->SetCapture(this);
560}
561
562void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800563 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800564 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800566 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
568 pMsgCtrl->ReleaseCapture();
569}
570
571void CPWL_Wnd::SetFocus() {
572 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
573 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
574 pMsgCtrl->KillFocus();
575 pMsgCtrl->SetFocus(this);
576 }
577}
578
579void CPWL_Wnd::KillFocus() {
580 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
581 if (pMsgCtrl->IsWndCaptureKeyboard(this))
582 pMsgCtrl->KillFocus();
583 }
584}
585
586void CPWL_Wnd::OnSetFocus() {}
587
588void CPWL_Wnd::OnKillFocus() {}
589
Dan Sinclairf528eee2017-02-14 11:52:07 -0500590bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500591 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592}
593
Dan Sinclairf528eee2017-02-14 11:52:07 -0500594bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500595 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700596}
597
598const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700599 auto* pParent = m_sPrivateParam.pParentWnd;
600 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601}
602
tsepez4cf55152016-11-02 14:37:54 -0700603void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800604 if (!IsValid())
605 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606
Lei Zhang375c2762017-03-10 14:37:14 -0800607 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800608 if (pChild)
609 pChild->SetVisible(bVisible);
610 }
611 if (bVisible != m_bVisible) {
612 m_bVisible = bVisible;
613 RePosChildWnd();
614 InvalidateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700616}
617
Tom Sepez281a9ea2016-02-26 14:24:28 -0800618void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619 m_rcClip = rect;
620 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700621}
622
Tom Sepez281a9ea2016-02-26 14:24:28 -0800623const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700625}
626
tsepez4cf55152016-11-02 14:37:54 -0700627bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629}
630
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700632 CPWL_ScrollBar* pVSB = GetVScrollBar();
633 if (!pVSB)
634 return;
635
Tom Sepez281a9ea2016-02-26 14:24:28 -0800636 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400637 GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth()));
Tom Sepez281a9ea2016-02-26 14:24:28 -0800638 CFX_FloatRect rcVScroll =
639 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
640 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700641 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700642}
643
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
645
646void CPWL_Wnd::SetCursor() {
647 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700648 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 int32_t nCursorType = GetCreationParam().eCursorType;
650 pSH->SetCursor(nCursorType);
651 }
652 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700653}
654
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700655void CPWL_Wnd::CreateMsgControl() {
656 if (!m_sPrivateParam.pMsgControl)
657 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700658}
659
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700661 CPWL_MsgControl* pMsgControl = GetMsgControl();
662 if (pMsgControl && pMsgControl->IsWndCreated(this))
663 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700664}
665
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
667 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700668}
669
tsepez4cf55152016-11-02 14:37:54 -0700670bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672}
673
tsepez4cf55152016-11-02 14:37:54 -0700674bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700675 CPWL_MsgControl* pCtrl = GetMsgControl();
676 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677}
678
tsepez4cf55152016-11-02 14:37:54 -0700679bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700680 CPWL_MsgControl* pCtrl = GetMsgControl();
681 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700682}
683
tsepez4cf55152016-11-02 14:37:54 -0700684bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700685 CPWL_MsgControl* pCtrl = GetMsgControl();
686 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700687}
688
Tom Sepez281a9ea2016-02-26 14:24:28 -0800689CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700691}
692
Dan Sinclair05df0752017-03-14 14:43:42 -0400693float CPWL_Wnd::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700695}
696
Dan Sinclair05df0752017-03-14 14:43:42 -0400697void CPWL_Wnd::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700699}
700
dsinclairb9590102016-04-27 06:38:59 -0700701CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700703}
704
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
706 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700707}
708
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709IPWL_Provider* CPWL_Wnd::GetProvider() const {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500710 return m_sPrivateParam.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700711}
712
dsinclairc7a73492016-04-05 12:01:42 -0700713IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700715}
716
dsinclair92cb5e52016-05-16 11:38:28 -0700717CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700719 case BorderStyle::BEVELED:
720 return CPWL_Color(COLORTYPE_GRAY, 1);
721 case BorderStyle::INSET:
722 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
723 default:
724 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700726}
727
dsinclair92cb5e52016-05-16 11:38:28 -0700728CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700730 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500731 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700732 case BorderStyle::INSET:
733 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
734 default:
735 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700737}
738
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739int32_t CPWL_Wnd::GetTransparency() {
740 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700741}
742
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800744 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800745 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700746 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700749}
750
Tom Sepez60d909e2015-12-10 15:34:55 -0800751CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
752 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800753 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700754 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700755 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700756}
757
Tom Sepez281a9ea2016-02-26 14:24:28 -0800758FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
759 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800760 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761 mt.TransformRect(rcTemp);
762 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
763 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700764}
765
Dan Sinclairf528eee2017-02-14 11:52:07 -0500766CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800767 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768 if (mt.IsIdentity())
769 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700770
Nicolas Penab21f1742017-06-29 12:02:06 -0400771 CFX_Matrix inverse = mt.GetInverse();
772 if (!inverse.IsIdentity())
773 mt = inverse;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500774 return mt.Transform(point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700775}
776
Tom Sepez281a9ea2016-02-26 14:24:28 -0800777CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800778 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700779 if (mt.IsIdentity())
780 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700781
Nicolas Penab21f1742017-06-29 12:02:06 -0400782 CFX_Matrix inverse = mt.GetInverse();
783 if (!inverse.IsIdentity())
784 mt = inverse;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800785 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700786 mt.TransformRect(rc);
787 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700788}
789
Tom Sepez60d909e2015-12-10 15:34:55 -0800790CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700791 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700792 if (HasFlag(PWS_CHILD)) {
793 const CPWL_Wnd* pParent = this;
794 while (pParent) {
795 mt.Concat(pParent->GetChildMatrix());
796 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700797 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798 }
799 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700800}
801
Tom Sepez60d909e2015-12-10 15:34:55 -0800802CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700803 return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700804}
805
Tom Sepez60d909e2015-12-10 15:34:55 -0800806void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700807 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700808}
809
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700810const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800811 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700812 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700813}
814
tsepez4cf55152016-11-02 14:37:54 -0700815void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800816 if (m_bEnabled == bEnable)
817 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700818
Lei Zhang375c2762017-03-10 14:37:14 -0800819 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800820 if (pChild)
821 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700822 }
tsepez6745f962017-01-04 10:09:45 -0800823 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700824}
825
tsepez4cf55152016-11-02 14:37:54 -0700826bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500827 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
828 return pSystemHandler && pSystemHandler->IsCTRLKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700829}
830
tsepez4cf55152016-11-02 14:37:54 -0700831bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500832 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
833 return pSystemHandler && pSystemHandler->IsSHIFTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700834}
835
tsepez4cf55152016-11-02 14:37:54 -0700836bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500837 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
838 return pSystemHandler && pSystemHandler->IsALTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700839}