blob: 51c30a5f8c28c94bfb589bdcd21fce72405db82f [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
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400430void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {}
431
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400432void CPWL_Wnd::SetScrollPosition(float pos) {}
433
Dan Sinclair63fbd8d2017-07-05 14:10:36 -0400434void CPWL_Wnd::ScrollWindowVertically(float pos) {}
435
tsepez4cf55152016-11-02 14:37:54 -0700436bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 return m_bCreated;
438}
439
Lei Zhang7457e382016-01-06 23:00:34 -0800440const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441 return m_sPrivateParam;
442}
443
444CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
445 return m_sPrivateParam.pParentWnd;
446}
447
Tom Sepez281a9ea2016-02-26 14:24:28 -0800448CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 return m_rcWindow;
450}
451
Tom Sepez281a9ea2016-02-26 14:24:28 -0800452CFX_FloatRect CPWL_Wnd::GetClientRect() const {
453 CFX_FloatRect rcWindow = GetWindowRect();
454 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400455 rcWindow, (float)(GetBorderWidth() + GetInnerBorderWidth()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
457 rcClient.right -= pVSB->GetScrollBarWidth();
458
459 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800460 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461}
462
Dan Sinclairf528eee2017-02-14 11:52:07 -0500463CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800464 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500465 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
466 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467}
468
tsepez4cf55152016-11-02 14:37:54 -0700469bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
471}
472
tsepezc3255f52016-03-25 14:52:27 -0700473void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474 m_sPrivateParam.dwFlags &= ~dwFlags;
475}
476
tsepezc3255f52016-03-25 14:52:27 -0700477void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 m_sPrivateParam.dwFlags |= dwFlags;
479}
480
481CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
482 return m_sPrivateParam.sBackgroundColor;
483}
484
485void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
486 m_sPrivateParam.sBackgroundColor = color;
487}
488
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489CPWL_Color CPWL_Wnd::GetTextColor() const {
490 return m_sPrivateParam.sTextColor;
491}
492
dsinclair92cb5e52016-05-16 11:38:28 -0700493BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 return m_sPrivateParam.nBorderStyle;
495}
496
dsinclair92cb5e52016-05-16 11:38:28 -0700497void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 if (HasFlag(PWS_BORDER))
499 m_sPrivateParam.nBorderStyle = nBorderStyle;
500}
501
502int32_t CPWL_Wnd::GetBorderWidth() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700503 return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504}
505
506int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 return 0;
508}
509
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510CPWL_Color CPWL_Wnd::GetBorderColor() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700511 return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512}
513
Lei Zhang7457e382016-01-06 23:00:34 -0800514const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 return m_sPrivateParam.sDash;
516}
517
518void* CPWL_Wnd::GetAttachedData() const {
519 return m_sPrivateParam.pAttachedData;
520}
521
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700523 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524}
525
526void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
527 CreateVScrollBar(cp);
528}
529
530void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700531 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
532 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533
Lei Zhangfac46f82017-06-02 14:20:04 -0700534 PWL_CREATEPARAM scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535
Lei Zhangfac46f82017-06-02 14:20:04 -0700536 // flags
537 scp.dwFlags =
538 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539
Lei Zhangfac46f82017-06-02 14:20:04 -0700540 scp.pParentWnd = this;
541 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
542 scp.eCursorType = FXCT_ARROW;
543 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
544
545 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
546 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547}
548
549void CPWL_Wnd::SetCapture() {
550 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
551 pMsgCtrl->SetCapture(this);
552}
553
554void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800555 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800556 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800558 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
560 pMsgCtrl->ReleaseCapture();
561}
562
563void CPWL_Wnd::SetFocus() {
564 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
565 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
566 pMsgCtrl->KillFocus();
567 pMsgCtrl->SetFocus(this);
568 }
569}
570
571void CPWL_Wnd::KillFocus() {
572 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
573 if (pMsgCtrl->IsWndCaptureKeyboard(this))
574 pMsgCtrl->KillFocus();
575 }
576}
577
578void CPWL_Wnd::OnSetFocus() {}
579
580void CPWL_Wnd::OnKillFocus() {}
581
Dan Sinclairf528eee2017-02-14 11:52:07 -0500582bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500583 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584}
585
Dan Sinclairf528eee2017-02-14 11:52:07 -0500586bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500587 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588}
589
590const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700591 auto* pParent = m_sPrivateParam.pParentWnd;
592 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593}
594
tsepez4cf55152016-11-02 14:37:54 -0700595void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800596 if (!IsValid())
597 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598
Lei Zhang375c2762017-03-10 14:37:14 -0800599 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800600 if (pChild)
601 pChild->SetVisible(bVisible);
602 }
603 if (bVisible != m_bVisible) {
604 m_bVisible = bVisible;
605 RePosChildWnd();
606 InvalidateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700608}
609
Tom Sepez281a9ea2016-02-26 14:24:28 -0800610void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611 m_rcClip = rect;
612 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700613}
614
Tom Sepez281a9ea2016-02-26 14:24:28 -0800615const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700617}
618
tsepez4cf55152016-11-02 14:37:54 -0700619bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700621}
622
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700624 CPWL_ScrollBar* pVSB = GetVScrollBar();
625 if (!pVSB)
626 return;
627
Tom Sepez281a9ea2016-02-26 14:24:28 -0800628 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400629 GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth()));
Tom Sepez281a9ea2016-02-26 14:24:28 -0800630 CFX_FloatRect rcVScroll =
631 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
632 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700633 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634}
635
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
637
638void CPWL_Wnd::SetCursor() {
639 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700640 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700641 int32_t nCursorType = GetCreationParam().eCursorType;
642 pSH->SetCursor(nCursorType);
643 }
644 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645}
646
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647void CPWL_Wnd::CreateMsgControl() {
648 if (!m_sPrivateParam.pMsgControl)
649 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700650}
651
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700653 CPWL_MsgControl* pMsgControl = GetMsgControl();
654 if (pMsgControl && pMsgControl->IsWndCreated(this))
655 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700656}
657
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700658CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
659 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700660}
661
tsepez4cf55152016-11-02 14:37:54 -0700662bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700664}
665
tsepez4cf55152016-11-02 14:37:54 -0700666bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700667 CPWL_MsgControl* pCtrl = GetMsgControl();
668 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700669}
670
tsepez4cf55152016-11-02 14:37:54 -0700671bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700672 CPWL_MsgControl* pCtrl = GetMsgControl();
673 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700674}
675
tsepez4cf55152016-11-02 14:37:54 -0700676bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700677 CPWL_MsgControl* pCtrl = GetMsgControl();
678 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700679}
680
Tom Sepez281a9ea2016-02-26 14:24:28 -0800681CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700682 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700683}
684
Dan Sinclair05df0752017-03-14 14:43:42 -0400685float CPWL_Wnd::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700687}
688
Dan Sinclair05df0752017-03-14 14:43:42 -0400689void CPWL_Wnd::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700691}
692
dsinclairb9590102016-04-27 06:38:59 -0700693CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700695}
696
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
698 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700699}
700
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701IPWL_Provider* CPWL_Wnd::GetProvider() const {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500702 return m_sPrivateParam.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700703}
704
dsinclairc7a73492016-04-05 12:01:42 -0700705IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700707}
708
dsinclair92cb5e52016-05-16 11:38:28 -0700709CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700711 case BorderStyle::BEVELED:
712 return CPWL_Color(COLORTYPE_GRAY, 1);
713 case BorderStyle::INSET:
714 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
715 default:
716 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700718}
719
dsinclair92cb5e52016-05-16 11:38:28 -0700720CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700722 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500723 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700724 case BorderStyle::INSET:
725 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
726 default:
727 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700729}
730
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731int32_t CPWL_Wnd::GetTransparency() {
732 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700733}
734
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700735void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800736 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800737 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700741}
742
Tom Sepez60d909e2015-12-10 15:34:55 -0800743CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
744 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800745 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700746 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700748}
749
Tom Sepez281a9ea2016-02-26 14:24:28 -0800750FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
751 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800752 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753 mt.TransformRect(rcTemp);
754 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
755 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700756}
757
Dan Sinclairf528eee2017-02-14 11:52:07 -0500758CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800759 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700760 if (mt.IsIdentity())
761 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700762
Nicolas Penab21f1742017-06-29 12:02:06 -0400763 CFX_Matrix inverse = mt.GetInverse();
764 if (!inverse.IsIdentity())
765 mt = inverse;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500766 return mt.Transform(point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700767}
768
Tom Sepez281a9ea2016-02-26 14:24:28 -0800769CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800770 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700771 if (mt.IsIdentity())
772 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700773
Nicolas Penab21f1742017-06-29 12:02:06 -0400774 CFX_Matrix inverse = mt.GetInverse();
775 if (!inverse.IsIdentity())
776 mt = inverse;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800777 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700778 mt.TransformRect(rc);
779 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700780}
781
Tom Sepez60d909e2015-12-10 15:34:55 -0800782CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700783 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784 if (HasFlag(PWS_CHILD)) {
785 const CPWL_Wnd* pParent = this;
786 while (pParent) {
787 mt.Concat(pParent->GetChildMatrix());
788 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700789 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790 }
791 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700792}
793
Tom Sepez60d909e2015-12-10 15:34:55 -0800794CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700795 return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700796}
797
Tom Sepez60d909e2015-12-10 15:34:55 -0800798void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700799 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700800}
801
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800803 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700804 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700805}
806
tsepez4cf55152016-11-02 14:37:54 -0700807void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800808 if (m_bEnabled == bEnable)
809 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700810
Lei Zhang375c2762017-03-10 14:37:14 -0800811 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800812 if (pChild)
813 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700814 }
tsepez6745f962017-01-04 10:09:45 -0800815 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700816}
817
tsepez4cf55152016-11-02 14:37:54 -0700818bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500819 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
820 return pSystemHandler && pSystemHandler->IsCTRLKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700821}
822
tsepez4cf55152016-11-02 14:37:54 -0700823bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500824 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
825 return pSystemHandler && pSystemHandler->IsSHIFTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700826}
827
tsepez4cf55152016-11-02 14:37:54 -0700828bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500829 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
830 return pSystemHandler && pSystemHandler->IsALTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700831}