blob: e99d71b1deb2fa1d878d7643b2a09b8c7e6a548d [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
weili625ad662016-06-15 11:21:33 -070018PWL_CREATEPARAM::PWL_CREATEPARAM()
19 : rcRectWnd(0, 0, 0, 0),
20 pSystemHandler(nullptr),
21 pFontMap(nullptr),
22 pProvider(nullptr),
23 pFocusHandler(nullptr),
24 dwFlags(0),
25 sBackgroundColor(),
dsinclair8faac622016-09-15 12:41:50 -070026 pAttachedWidget(nullptr),
weili625ad662016-06-15 11:21:33 -070027 nBorderStyle(BorderStyle::SOLID),
28 dwBorderWidth(1),
29 sBorderColor(),
30 sTextColor(),
weili625ad662016-06-15 11:21:33 -070031 nTransparency(255),
32 fFontSize(PWL_DEFAULT_FONTSIZE),
33 sDash(3, 0, 0),
34 pAttachedData(nullptr),
35 pParentWnd(nullptr),
36 pMsgControl(nullptr),
Lei Zhangfac46f82017-06-02 14:20:04 -070037 eCursorType(FXCT_ARROW) {}
weili625ad662016-06-15 11:21:33 -070038
39PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default;
40
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041class CPWL_MsgControl {
42 friend class CPWL_Wnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044 public:
Lei Zhangc2fb35f2016-01-05 16:46:58 -080045 explicit CPWL_MsgControl(CPWL_Wnd* pWnd) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046 m_pCreatedWnd = pWnd;
47 Default();
48 }
49
Dan Sinclairf766ad22016-03-14 13:51:24 -040050 ~CPWL_MsgControl() { Default(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051
52 void Default() {
tsepez0d164f82017-01-09 07:28:13 -080053 m_aMousePath.clear();
54 m_aKeyboardPath.clear();
thestig1cd352e2016-06-07 17:53:06 -070055 m_pMainMouseWnd = nullptr;
56 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 }
58
tsepez4cf55152016-11-02 14:37:54 -070059 bool IsWndCreated(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060 return m_pCreatedWnd == pWnd;
61 }
62
tsepez4cf55152016-11-02 14:37:54 -070063 bool IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 return pWnd == m_pMainMouseWnd;
65 }
66
tsepez4cf55152016-11-02 14:37:54 -070067 bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -080068 return pWnd && pdfium::ContainsValue(m_aMousePath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 }
70
tsepez4cf55152016-11-02 14:37:54 -070071 bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 return pWnd == m_pMainKeyboardWnd;
73 }
74
tsepez4cf55152016-11-02 14:37:54 -070075 bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -080076 return pWnd && pdfium::ContainsValue(m_aKeyboardPath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077 }
78
79 void SetFocus(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -080080 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 if (pWnd) {
82 m_pMainKeyboardWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 CPWL_Wnd* pParent = pWnd;
84 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -080085 m_aKeyboardPath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 pParent = pParent->GetParentWindow();
87 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 pWnd->OnSetFocus();
Tom Sepez2f2ffec2015-07-23 14:42:09 -070089 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070091
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 void KillFocus() {
tsepez0d164f82017-01-09 07:28:13 -080093 if (!m_aKeyboardPath.empty())
94 if (CPWL_Wnd* pWnd = m_aKeyboardPath[0])
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095 pWnd->OnKillFocus();
96
thestig1cd352e2016-06-07 17:53:06 -070097 m_pMainKeyboardWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -080098 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 }
100
101 void SetCapture(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -0800102 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103 if (pWnd) {
104 m_pMainMouseWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105 CPWL_Wnd* pParent = pWnd;
106 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -0800107 m_aMousePath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 pParent = pParent->GetParentWindow();
109 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700110 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700112
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 void ReleaseCapture() {
thestig1cd352e2016-06-07 17:53:06 -0700114 m_pMainMouseWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800115 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700117
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118 private:
tsepez0d164f82017-01-09 07:28:13 -0800119 std::vector<CPWL_Wnd*> m_aMousePath;
120 std::vector<CPWL_Wnd*> m_aKeyboardPath;
Tom Sepezd0409af2017-05-25 15:53:57 -0700121 CFX_UnownedPtr<CPWL_Wnd> m_pCreatedWnd;
122 CFX_UnownedPtr<CPWL_Wnd> m_pMainMouseWnd;
123 CFX_UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700124};
125
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126CPWL_Wnd::CPWL_Wnd()
Lei Zhangfac46f82017-06-02 14:20:04 -0700127 : m_rcWindow(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128 m_rcClip(),
tsepez4cf55152016-11-02 14:37:54 -0700129 m_bCreated(false),
130 m_bVisible(false),
131 m_bNotifying(false),
132 m_bEnabled(true) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133
134CPWL_Wnd::~CPWL_Wnd() {
Lei Zhangb45324b2017-05-22 17:05:40 -0700135 ASSERT(!m_bCreated);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700136}
137
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138CFX_ByteString CPWL_Wnd::GetClassName() const {
139 return "CPWL_Wnd";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700140}
141
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700142void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700143 if (IsValid())
144 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145
Lei Zhangfac46f82017-06-02 14:20:04 -0700146 m_sPrivateParam = cp;
147 OnCreate(m_sPrivateParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148
Lei Zhangfac46f82017-06-02 14:20:04 -0700149 m_sPrivateParam.rcRectWnd.Normalize();
150 m_rcWindow = m_sPrivateParam.rcRectWnd;
151 m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f);
152 CreateMsgControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700153
Lei Zhangfac46f82017-06-02 14:20:04 -0700154 if (m_sPrivateParam.pParentWnd)
Dan Sinclaire5e889e2017-07-05 08:45:40 -0400155 m_sPrivateParam.pParentWnd->AddChild(this);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156
Lei Zhangfac46f82017-06-02 14:20:04 -0700157 PWL_CREATEPARAM ccp = m_sPrivateParam;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700158
Lei Zhangfac46f82017-06-02 14:20:04 -0700159 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
160 CreateScrollBar(ccp);
161 CreateChildWnd(ccp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162
Lei Zhangfac46f82017-06-02 14:20:04 -0700163 m_bVisible = HasFlag(PWS_VISIBLE);
164 OnCreated();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165
Lei Zhangfac46f82017-06-02 14:20:04 -0700166 RePosChildWnd();
167 m_bCreated = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700168}
169
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172void CPWL_Wnd::OnCreated() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700173
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174void CPWL_Wnd::OnDestroy() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700175
Lei Zhangab5537d2016-01-06 14:58:14 -0800176void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) {
177 if (m_sPrivateParam.pFocusHandler == handler)
178 m_sPrivateParam.pFocusHandler = nullptr;
179}
180
181void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500182 if (m_sPrivateParam.pProvider.Get() == provider)
183 m_sPrivateParam.pProvider.Reset();
Lei Zhangab5537d2016-01-06 14:58:14 -0800184}
185
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186void CPWL_Wnd::Destroy() {
187 KillFocus();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 OnDestroy();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 if (m_bCreated) {
Lei Zhang35162562017-06-09 01:04:52 -0700190 m_pVScrollBar = nullptr;
tsepez6745f962017-01-04 10:09:45 -0800191 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
192 if (CPWL_Wnd* pChild = *it) {
193 *it = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194 pChild->Destroy();
195 delete pChild;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 }
197 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 if (m_sPrivateParam.pParentWnd)
Dan Sinclaire5e889e2017-07-05 08:45:40 -0400199 m_sPrivateParam.pParentWnd->RemoveChild(this);
tsepez6745f962017-01-04 10:09:45 -0800200
tsepez4cf55152016-11-02 14:37:54 -0700201 m_bCreated = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 DestroyMsgControl();
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500204 m_sPrivateParam.Reset();
tsepez6745f962017-01-04 10:09:45 -0800205 m_Children.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700207
tsepez4cf55152016-11-02 14:37:54 -0700208void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700209 if (!IsValid())
210 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211
Lei Zhangfac46f82017-06-02 14:20:04 -0700212 CFX_FloatRect rcOld = GetWindowRect();
213 m_rcWindow = rcNew;
214 m_rcWindow.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215
Lei Zhangfac46f82017-06-02 14:20:04 -0700216 if (bReset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
218 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700219 RePosChildWnd();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700220 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700222 if (bRefresh)
223 InvalidateRectMove(rcOld, rcNew);
224
225 m_sPrivateParam.rcRectWnd = m_rcWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700226}
227
Tom Sepez281a9ea2016-02-26 14:24:28 -0800228void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
229 const CFX_FloatRect& rcNew) {
230 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700232
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233 InvalidateRect(&rcUnion);
234}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700235
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400236void CPWL_Wnd::GetAppearanceStream(std::ostringstream* psAppStream) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 if (IsValid() && IsVisible()) {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400238 GetThisAppearanceStream(psAppStream);
239 GetChildAppearanceStream(psAppStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 }
241}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700242
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243// if don't set,Get default apperance stream
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400244void CPWL_Wnd::GetThisAppearanceStream(std::ostringstream* psAppStream) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800245 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700246 if (rectWnd.IsEmpty())
247 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248
Lei Zhangfac46f82017-06-02 14:20:04 -0700249 if (HasFlag(PWS_BACKGROUND))
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400250 *psAppStream << CPWL_Utils::GetRectFillAppStream(rectWnd,
251 GetBackgroundColor());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252
Lei Zhangfac46f82017-06-02 14:20:04 -0700253 if (HasFlag(PWS_BORDER)) {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400254 *psAppStream << CPWL_Utils::GetBorderAppStream(
Lei Zhangfac46f82017-06-02 14:20:04 -0700255 rectWnd, (float)GetBorderWidth(), GetBorderColor(),
256 GetBorderLeftTopColor(GetBorderStyle()),
257 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
258 GetBorderDash());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700260}
261
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400262void CPWL_Wnd::GetChildAppearanceStream(std::ostringstream* psAppStream) {
tsepez6745f962017-01-04 10:09:45 -0800263 for (CPWL_Wnd* pChild : m_Children) {
264 if (pChild)
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400265 pChild->GetAppearanceStream(psAppStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700267}
268
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800270 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271 if (IsValid() && IsVisible()) {
272 DrawThisAppearance(pDevice, pUser2Device);
273 DrawChildAppearance(pDevice, pUser2Device);
274 }
275}
276
277void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800278 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800279 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700280 if (rectWnd.IsEmpty())
281 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282
Lei Zhangfac46f82017-06-02 14:20:04 -0700283 if (HasFlag(PWS_BACKGROUND)) {
284 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
285 rectWnd, (float)(GetBorderWidth() + GetInnerBorderWidth()));
286 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
287 GetBackgroundColor(), GetTransparency());
288 }
289
290 if (HasFlag(PWS_BORDER)) {
291 CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd,
292 (float)GetBorderWidth(), GetBorderColor(),
293 GetBorderLeftTopColor(GetBorderStyle()),
294 GetBorderRightBottomColor(GetBorderStyle()),
295 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700297}
298
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800300 CFX_Matrix* pUser2Device) {
tsepez6745f962017-01-04 10:09:45 -0800301 for (CPWL_Wnd* pChild : m_Children) {
302 if (!pChild)
303 continue;
304
305 CFX_Matrix mt = pChild->GetChildMatrix();
306 if (mt.IsIdentity()) {
307 pChild->DrawAppearance(pDevice, pUser2Device);
308 } else {
309 mt.Concat(*pUser2Device);
310 pChild->DrawAppearance(pDevice, &mt);
Lei Zhang60f507b2015-06-13 00:41:00 -0700311 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700313}
314
Tom Sepez281a9ea2016-02-26 14:24:28 -0800315void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700316 if (!IsValid())
317 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318
Lei Zhangfac46f82017-06-02 14:20:04 -0700319 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
320
321 if (!HasFlag(PWS_NOREFRESHCLIP)) {
322 CFX_FloatRect rcClip = GetClipRect();
323 if (!rcClip.IsEmpty()) {
324 rcRefresh.Intersect(rcClip);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700325 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700326 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700327
Lei Zhangfac46f82017-06-02 14:20:04 -0700328 FX_RECT rcWin = PWLtoWnd(rcRefresh);
329 rcWin.left -= PWL_INVALIDATE_INFLATE;
330 rcWin.top -= PWL_INVALIDATE_INFLATE;
331 rcWin.right += PWL_INVALIDATE_INFLATE;
332 rcWin.bottom += PWL_INVALIDATE_INFLATE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333
Lei Zhangfac46f82017-06-02 14:20:04 -0700334 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
335 if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>(
336 m_sPrivateParam.pAttachedWidget.Get())) {
337 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700338 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700339 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700340}
341
tsepez6745f962017-01-04 10:09:45 -0800342#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
343 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
344 if (!IsValid() || !IsVisible() || !IsEnabled()) \
345 return false; \
346 if (!IsWndCaptureKeyboard(this)) \
347 return false; \
Lei Zhang375c2762017-03-10 14:37:14 -0800348 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800349 if (pChild && IsWndCaptureKeyboard(pChild)) \
350 return pChild->key_method_name(nChar, nFlag); \
351 } \
352 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700354
355PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700356PWL_IMPLEMENT_KEY_METHOD(OnChar)
tsepez6745f962017-01-04 10:09:45 -0800357#undef PWL_IMPLEMENT_KEY_METHOD
358
359#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Dan Sinclairf528eee2017-02-14 11:52:07 -0500360 bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \
tsepez6745f962017-01-04 10:09:45 -0800361 if (!IsValid() || !IsVisible() || !IsEnabled()) \
362 return false; \
363 if (IsWndCaptureMouse(this)) { \
Lei Zhang375c2762017-03-10 14:37:14 -0800364 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800365 if (pChild && IsWndCaptureMouse(pChild)) { \
366 return pChild->mouse_method_name(pChild->ParentToChild(point), \
367 nFlag); \
368 } \
369 } \
370 SetCursor(); \
371 return false; \
372 } \
Lei Zhang375c2762017-03-10 14:37:14 -0800373 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800374 if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \
375 return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \
376 } \
377 } \
378 if (WndHitTest(point)) \
379 SetCursor(); \
380 return false; \
381 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700382
383PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
384PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
385PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700386PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
387PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
388PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
tsepez6745f962017-01-04 10:09:45 -0800389#undef PWL_IMPLEMENT_MOUSE_METHOD
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700390
Diana Gagedce2d722017-06-20 11:17:11 -0700391CFX_WideString CPWL_Wnd::GetSelectedText() {
392 return CFX_WideString();
393}
394
tsepez4cf55152016-11-02 14:37:54 -0700395bool CPWL_Wnd::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500396 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700397 uint32_t nFlag) {
tsepez6745f962017-01-04 10:09:45 -0800398 if (!IsValid() || !IsVisible() || !IsEnabled())
399 return false;
400
401 SetCursor();
402 if (!IsWndCaptureKeyboard(this))
403 return false;
404
Lei Zhang375c2762017-03-10 14:37:14 -0800405 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800406 if (pChild && IsWndCaptureKeyboard(pChild))
407 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408 }
tsepez4cf55152016-11-02 14:37:54 -0700409 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700410}
411
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800413 m_Children.push_back(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700414}
415
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800417 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
418 if (*it && *it == pWnd) {
419 m_Children.erase(std::next(it).base());
420 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700421 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700423}
424
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700426 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 intptr_t wParam,
Dan Sinclaire5e889e2017-07-05 08:45:40 -0400428 intptr_t lParam) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429
tsepez4cf55152016-11-02 14:37:54 -0700430bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431 return m_bCreated;
432}
433
Lei Zhang7457e382016-01-06 23:00:34 -0800434const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 return m_sPrivateParam;
436}
437
438CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
439 return m_sPrivateParam.pParentWnd;
440}
441
Tom Sepez281a9ea2016-02-26 14:24:28 -0800442CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443 return m_rcWindow;
444}
445
Tom Sepez281a9ea2016-02-26 14:24:28 -0800446CFX_FloatRect CPWL_Wnd::GetClientRect() const {
447 CFX_FloatRect rcWindow = GetWindowRect();
448 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400449 rcWindow, (float)(GetBorderWidth() + GetInnerBorderWidth()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
451 rcClient.right -= pVSB->GetScrollBarWidth();
452
453 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800454 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455}
456
Dan Sinclairf528eee2017-02-14 11:52:07 -0500457CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800458 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500459 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
460 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461}
462
tsepez4cf55152016-11-02 14:37:54 -0700463bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
465}
466
tsepezc3255f52016-03-25 14:52:27 -0700467void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 m_sPrivateParam.dwFlags &= ~dwFlags;
469}
470
tsepezc3255f52016-03-25 14:52:27 -0700471void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472 m_sPrivateParam.dwFlags |= dwFlags;
473}
474
475CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
476 return m_sPrivateParam.sBackgroundColor;
477}
478
479void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
480 m_sPrivateParam.sBackgroundColor = color;
481}
482
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483CPWL_Color CPWL_Wnd::GetTextColor() const {
484 return m_sPrivateParam.sTextColor;
485}
486
dsinclair92cb5e52016-05-16 11:38:28 -0700487BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 return m_sPrivateParam.nBorderStyle;
489}
490
dsinclair92cb5e52016-05-16 11:38:28 -0700491void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 if (HasFlag(PWS_BORDER))
493 m_sPrivateParam.nBorderStyle = nBorderStyle;
494}
495
496int32_t CPWL_Wnd::GetBorderWidth() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700497 return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498}
499
500int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 return 0;
502}
503
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504CPWL_Color CPWL_Wnd::GetBorderColor() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700505 return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506}
507
Lei Zhang7457e382016-01-06 23:00:34 -0800508const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 return m_sPrivateParam.sDash;
510}
511
512void* CPWL_Wnd::GetAttachedData() const {
513 return m_sPrivateParam.pAttachedData;
514}
515
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700517 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518}
519
520void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
521 CreateVScrollBar(cp);
522}
523
524void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700525 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
526 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527
Lei Zhangfac46f82017-06-02 14:20:04 -0700528 PWL_CREATEPARAM scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529
Lei Zhangfac46f82017-06-02 14:20:04 -0700530 // flags
531 scp.dwFlags =
532 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533
Lei Zhangfac46f82017-06-02 14:20:04 -0700534 scp.pParentWnd = this;
535 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
536 scp.eCursorType = FXCT_ARROW;
537 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
538
539 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
540 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541}
542
543void CPWL_Wnd::SetCapture() {
544 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
545 pMsgCtrl->SetCapture(this);
546}
547
548void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800549 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800550 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800552 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
554 pMsgCtrl->ReleaseCapture();
555}
556
557void CPWL_Wnd::SetFocus() {
558 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
559 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
560 pMsgCtrl->KillFocus();
561 pMsgCtrl->SetFocus(this);
562 }
563}
564
565void CPWL_Wnd::KillFocus() {
566 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
567 if (pMsgCtrl->IsWndCaptureKeyboard(this))
568 pMsgCtrl->KillFocus();
569 }
570}
571
572void CPWL_Wnd::OnSetFocus() {}
573
574void CPWL_Wnd::OnKillFocus() {}
575
Dan Sinclairf528eee2017-02-14 11:52:07 -0500576bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500577 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578}
579
Dan Sinclairf528eee2017-02-14 11:52:07 -0500580bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500581 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582}
583
584const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700585 auto* pParent = m_sPrivateParam.pParentWnd;
586 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587}
588
tsepez4cf55152016-11-02 14:37:54 -0700589void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800590 if (!IsValid())
591 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592
Lei Zhang375c2762017-03-10 14:37:14 -0800593 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800594 if (pChild)
595 pChild->SetVisible(bVisible);
596 }
597 if (bVisible != m_bVisible) {
598 m_bVisible = bVisible;
599 RePosChildWnd();
600 InvalidateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700602}
603
Tom Sepez281a9ea2016-02-26 14:24:28 -0800604void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 m_rcClip = rect;
606 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607}
608
Tom Sepez281a9ea2016-02-26 14:24:28 -0800609const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611}
612
tsepez4cf55152016-11-02 14:37:54 -0700613bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615}
616
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700618 CPWL_ScrollBar* pVSB = GetVScrollBar();
619 if (!pVSB)
620 return;
621
Tom Sepez281a9ea2016-02-26 14:24:28 -0800622 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400623 GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth()));
Tom Sepez281a9ea2016-02-26 14:24:28 -0800624 CFX_FloatRect rcVScroll =
625 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
626 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700627 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700628}
629
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
631
632void CPWL_Wnd::SetCursor() {
633 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700634 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635 int32_t nCursorType = GetCreationParam().eCursorType;
636 pSH->SetCursor(nCursorType);
637 }
638 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700639}
640
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700641void CPWL_Wnd::CreateMsgControl() {
642 if (!m_sPrivateParam.pMsgControl)
643 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700644}
645
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700647 CPWL_MsgControl* pMsgControl = GetMsgControl();
648 if (pMsgControl && pMsgControl->IsWndCreated(this))
649 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700650}
651
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
653 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700654}
655
tsepez4cf55152016-11-02 14:37:54 -0700656bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700657 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700658}
659
tsepez4cf55152016-11-02 14:37:54 -0700660bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700661 CPWL_MsgControl* pCtrl = GetMsgControl();
662 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700663}
664
tsepez4cf55152016-11-02 14:37:54 -0700665bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700666 CPWL_MsgControl* pCtrl = GetMsgControl();
667 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700668}
669
tsepez4cf55152016-11-02 14:37:54 -0700670bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700671 CPWL_MsgControl* pCtrl = GetMsgControl();
672 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700673}
674
Tom Sepez281a9ea2016-02-26 14:24:28 -0800675CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677}
678
Dan Sinclair05df0752017-03-14 14:43:42 -0400679float CPWL_Wnd::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681}
682
Dan Sinclair05df0752017-03-14 14:43:42 -0400683void CPWL_Wnd::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685}
686
dsinclairb9590102016-04-27 06:38:59 -0700687CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700689}
690
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
692 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693}
694
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695IPWL_Provider* CPWL_Wnd::GetProvider() const {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500696 return m_sPrivateParam.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700697}
698
dsinclairc7a73492016-04-05 12:01:42 -0700699IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700701}
702
dsinclair92cb5e52016-05-16 11:38:28 -0700703CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700705 case BorderStyle::BEVELED:
706 return CPWL_Color(COLORTYPE_GRAY, 1);
707 case BorderStyle::INSET:
708 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
709 default:
710 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700712}
713
dsinclair92cb5e52016-05-16 11:38:28 -0700714CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700716 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500717 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700718 case BorderStyle::INSET:
719 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
720 default:
721 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700723}
724
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725int32_t CPWL_Wnd::GetTransparency() {
726 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700727}
728
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800730 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800731 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700733 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700735}
736
Tom Sepez60d909e2015-12-10 15:34:55 -0800737CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
738 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800739 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700741 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700742}
743
Tom Sepez281a9ea2016-02-26 14:24:28 -0800744FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
745 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800746 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 mt.TransformRect(rcTemp);
748 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
749 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700750}
751
Dan Sinclairf528eee2017-02-14 11:52:07 -0500752CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800753 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700754 if (mt.IsIdentity())
755 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700756
Nicolas Penab21f1742017-06-29 12:02:06 -0400757 CFX_Matrix inverse = mt.GetInverse();
758 if (!inverse.IsIdentity())
759 mt = inverse;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500760 return mt.Transform(point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700761}
762
Tom Sepez281a9ea2016-02-26 14:24:28 -0800763CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800764 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700765 if (mt.IsIdentity())
766 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700767
Nicolas Penab21f1742017-06-29 12:02:06 -0400768 CFX_Matrix inverse = mt.GetInverse();
769 if (!inverse.IsIdentity())
770 mt = inverse;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800771 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772 mt.TransformRect(rc);
773 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700774}
775
Tom Sepez60d909e2015-12-10 15:34:55 -0800776CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700777 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700778 if (HasFlag(PWS_CHILD)) {
779 const CPWL_Wnd* pParent = this;
780 while (pParent) {
781 mt.Concat(pParent->GetChildMatrix());
782 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700783 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784 }
785 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700786}
787
Tom Sepez60d909e2015-12-10 15:34:55 -0800788CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700789 return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700790}
791
Tom Sepez60d909e2015-12-10 15:34:55 -0800792void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700794}
795
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700796const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800797 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700798 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700799}
800
tsepez4cf55152016-11-02 14:37:54 -0700801void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800802 if (m_bEnabled == bEnable)
803 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700804
Lei Zhang375c2762017-03-10 14:37:14 -0800805 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800806 if (pChild)
807 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700808 }
tsepez6745f962017-01-04 10:09:45 -0800809 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700810}
811
tsepez4cf55152016-11-02 14:37:54 -0700812bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500813 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
814 return pSystemHandler && pSystemHandler->IsCTRLKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700815}
816
tsepez4cf55152016-11-02 14:37:54 -0700817bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500818 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
819 return pSystemHandler && pSystemHandler->IsSHIFTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700820}
821
tsepez4cf55152016-11-02 14:37:54 -0700822bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500823 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
824 return pSystemHandler && pSystemHandler->IsALTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700825}