blob: 564c98c9e224499a9cb5b858c2e2184f107d3195 [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
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400425void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {}
426
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400427void CPWL_Wnd::SetScrollPosition(float pos) {}
428
Dan Sinclair63fbd8d2017-07-05 14:10:36 -0400429void CPWL_Wnd::ScrollWindowVertically(float pos) {}
430
Dan Sinclair7f6bec92017-07-05 14:13:16 -0400431void CPWL_Wnd::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {}
432
433void CPWL_Wnd::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {}
434
435void CPWL_Wnd::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) {}
436
tsepez4cf55152016-11-02 14:37:54 -0700437bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438 return m_bCreated;
439}
440
Lei Zhang7457e382016-01-06 23:00:34 -0800441const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 return m_sPrivateParam;
443}
444
445CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
446 return m_sPrivateParam.pParentWnd;
447}
448
Tom Sepez281a9ea2016-02-26 14:24:28 -0800449CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450 return m_rcWindow;
451}
452
Tom Sepez281a9ea2016-02-26 14:24:28 -0800453CFX_FloatRect CPWL_Wnd::GetClientRect() const {
454 CFX_FloatRect rcWindow = GetWindowRect();
455 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400456 rcWindow, (float)(GetBorderWidth() + GetInnerBorderWidth()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
458 rcClient.right -= pVSB->GetScrollBarWidth();
459
460 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800461 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462}
463
Dan Sinclairf528eee2017-02-14 11:52:07 -0500464CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800465 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500466 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
467 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468}
469
tsepez4cf55152016-11-02 14:37:54 -0700470bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
472}
473
tsepezc3255f52016-03-25 14:52:27 -0700474void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 m_sPrivateParam.dwFlags &= ~dwFlags;
476}
477
tsepezc3255f52016-03-25 14:52:27 -0700478void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 m_sPrivateParam.dwFlags |= dwFlags;
480}
481
482CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
483 return m_sPrivateParam.sBackgroundColor;
484}
485
486void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
487 m_sPrivateParam.sBackgroundColor = color;
488}
489
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490CPWL_Color CPWL_Wnd::GetTextColor() const {
491 return m_sPrivateParam.sTextColor;
492}
493
dsinclair92cb5e52016-05-16 11:38:28 -0700494BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 return m_sPrivateParam.nBorderStyle;
496}
497
dsinclair92cb5e52016-05-16 11:38:28 -0700498void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499 if (HasFlag(PWS_BORDER))
500 m_sPrivateParam.nBorderStyle = nBorderStyle;
501}
502
503int32_t CPWL_Wnd::GetBorderWidth() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700504 return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505}
506
507int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508 return 0;
509}
510
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511CPWL_Color CPWL_Wnd::GetBorderColor() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700512 return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513}
514
Lei Zhang7457e382016-01-06 23:00:34 -0800515const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516 return m_sPrivateParam.sDash;
517}
518
519void* CPWL_Wnd::GetAttachedData() const {
520 return m_sPrivateParam.pAttachedData;
521}
522
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700524 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525}
526
527void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
528 CreateVScrollBar(cp);
529}
530
531void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700532 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
533 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534
Lei Zhangfac46f82017-06-02 14:20:04 -0700535 PWL_CREATEPARAM scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536
Lei Zhangfac46f82017-06-02 14:20:04 -0700537 // flags
538 scp.dwFlags =
539 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540
Lei Zhangfac46f82017-06-02 14:20:04 -0700541 scp.pParentWnd = this;
542 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
543 scp.eCursorType = FXCT_ARROW;
544 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
545
546 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
547 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548}
549
550void CPWL_Wnd::SetCapture() {
551 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
552 pMsgCtrl->SetCapture(this);
553}
554
555void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800556 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800557 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800559 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
561 pMsgCtrl->ReleaseCapture();
562}
563
564void CPWL_Wnd::SetFocus() {
565 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
566 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
567 pMsgCtrl->KillFocus();
568 pMsgCtrl->SetFocus(this);
569 }
570}
571
572void CPWL_Wnd::KillFocus() {
573 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
574 if (pMsgCtrl->IsWndCaptureKeyboard(this))
575 pMsgCtrl->KillFocus();
576 }
577}
578
579void CPWL_Wnd::OnSetFocus() {}
580
581void CPWL_Wnd::OnKillFocus() {}
582
Dan Sinclairf528eee2017-02-14 11:52:07 -0500583bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500584 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585}
586
Dan Sinclairf528eee2017-02-14 11:52:07 -0500587bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500588 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589}
590
591const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700592 auto* pParent = m_sPrivateParam.pParentWnd;
593 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594}
595
tsepez4cf55152016-11-02 14:37:54 -0700596void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800597 if (!IsValid())
598 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599
Lei Zhang375c2762017-03-10 14:37:14 -0800600 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800601 if (pChild)
602 pChild->SetVisible(bVisible);
603 }
604 if (bVisible != m_bVisible) {
605 m_bVisible = bVisible;
606 RePosChildWnd();
607 InvalidateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609}
610
Tom Sepez281a9ea2016-02-26 14:24:28 -0800611void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 m_rcClip = rect;
613 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700614}
615
Tom Sepez281a9ea2016-02-26 14:24:28 -0800616const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700618}
619
tsepez4cf55152016-11-02 14:37:54 -0700620bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700622}
623
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700625 CPWL_ScrollBar* pVSB = GetVScrollBar();
626 if (!pVSB)
627 return;
628
Tom Sepez281a9ea2016-02-26 14:24:28 -0800629 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400630 GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth()));
Tom Sepez281a9ea2016-02-26 14:24:28 -0800631 CFX_FloatRect rcVScroll =
632 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
633 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700634 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635}
636
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700637void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
638
639void CPWL_Wnd::SetCursor() {
640 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700641 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700642 int32_t nCursorType = GetCreationParam().eCursorType;
643 pSH->SetCursor(nCursorType);
644 }
645 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700646}
647
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648void CPWL_Wnd::CreateMsgControl() {
649 if (!m_sPrivateParam.pMsgControl)
650 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700651}
652
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700654 CPWL_MsgControl* pMsgControl = GetMsgControl();
655 if (pMsgControl && pMsgControl->IsWndCreated(this))
656 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700657}
658
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
660 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700661}
662
tsepez4cf55152016-11-02 14:37:54 -0700663bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700664 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700665}
666
tsepez4cf55152016-11-02 14:37:54 -0700667bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700668 CPWL_MsgControl* pCtrl = GetMsgControl();
669 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700670}
671
tsepez4cf55152016-11-02 14:37:54 -0700672bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700673 CPWL_MsgControl* pCtrl = GetMsgControl();
674 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700675}
676
tsepez4cf55152016-11-02 14:37:54 -0700677bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700678 CPWL_MsgControl* pCtrl = GetMsgControl();
679 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700680}
681
Tom Sepez281a9ea2016-02-26 14:24:28 -0800682CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700684}
685
Dan Sinclair05df0752017-03-14 14:43:42 -0400686float CPWL_Wnd::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700688}
689
Dan Sinclair05df0752017-03-14 14:43:42 -0400690void CPWL_Wnd::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700692}
693
dsinclairb9590102016-04-27 06:38:59 -0700694CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700696}
697
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
699 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700700}
701
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702IPWL_Provider* CPWL_Wnd::GetProvider() const {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500703 return m_sPrivateParam.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700704}
705
dsinclairc7a73492016-04-05 12:01:42 -0700706IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700708}
709
dsinclair92cb5e52016-05-16 11:38:28 -0700710CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700712 case BorderStyle::BEVELED:
713 return CPWL_Color(COLORTYPE_GRAY, 1);
714 case BorderStyle::INSET:
715 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
716 default:
717 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700719}
720
dsinclair92cb5e52016-05-16 11:38:28 -0700721CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700723 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500724 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700725 case BorderStyle::INSET:
726 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
727 default:
728 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700730}
731
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732int32_t CPWL_Wnd::GetTransparency() {
733 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700734}
735
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800737 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800738 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700741 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700742}
743
Tom Sepez60d909e2015-12-10 15:34:55 -0800744CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
745 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800746 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700749}
750
Tom Sepez281a9ea2016-02-26 14:24:28 -0800751FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
752 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800753 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700754 mt.TransformRect(rcTemp);
755 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
756 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700757}
758
Dan Sinclairf528eee2017-02-14 11:52:07 -0500759CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800760 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761 if (mt.IsIdentity())
762 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700763
Nicolas Penab21f1742017-06-29 12:02:06 -0400764 CFX_Matrix inverse = mt.GetInverse();
765 if (!inverse.IsIdentity())
766 mt = inverse;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500767 return mt.Transform(point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700768}
769
Tom Sepez281a9ea2016-02-26 14:24:28 -0800770CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800771 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772 if (mt.IsIdentity())
773 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700774
Nicolas Penab21f1742017-06-29 12:02:06 -0400775 CFX_Matrix inverse = mt.GetInverse();
776 if (!inverse.IsIdentity())
777 mt = inverse;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800778 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700779 mt.TransformRect(rc);
780 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700781}
782
Tom Sepez60d909e2015-12-10 15:34:55 -0800783CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700784 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785 if (HasFlag(PWS_CHILD)) {
786 const CPWL_Wnd* pParent = this;
787 while (pParent) {
788 mt.Concat(pParent->GetChildMatrix());
789 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700790 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700791 }
792 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700793}
794
Tom Sepez60d909e2015-12-10 15:34:55 -0800795CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700796 return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700797}
798
Tom Sepez60d909e2015-12-10 15:34:55 -0800799void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700801}
802
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800804 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700805 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806}
807
tsepez4cf55152016-11-02 14:37:54 -0700808void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800809 if (m_bEnabled == bEnable)
810 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700811
Lei Zhang375c2762017-03-10 14:37:14 -0800812 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800813 if (pChild)
814 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700815 }
tsepez6745f962017-01-04 10:09:45 -0800816 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700817}
818
tsepez4cf55152016-11-02 14:37:54 -0700819bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500820 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
821 return pSystemHandler && pSystemHandler->IsCTRLKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700822}
823
tsepez4cf55152016-11-02 14:37:54 -0700824bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500825 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
826 return pSystemHandler && pSystemHandler->IsSHIFTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700827}
828
tsepez4cf55152016-11-02 14:37:54 -0700829bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500830 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
831 return pSystemHandler && pSystemHandler->IsALTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700832}