blob: f407dfc1e963e31eca04bbd54077ad36568831da [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
tsepez4cf55152016-11-02 14:37:54 -0700434bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 return m_bCreated;
436}
437
Lei Zhang7457e382016-01-06 23:00:34 -0800438const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 return m_sPrivateParam;
440}
441
442CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
443 return m_sPrivateParam.pParentWnd;
444}
445
Tom Sepez281a9ea2016-02-26 14:24:28 -0800446CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447 return m_rcWindow;
448}
449
Tom Sepez281a9ea2016-02-26 14:24:28 -0800450CFX_FloatRect CPWL_Wnd::GetClientRect() const {
451 CFX_FloatRect rcWindow = GetWindowRect();
452 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400453 rcWindow, (float)(GetBorderWidth() + GetInnerBorderWidth()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
455 rcClient.right -= pVSB->GetScrollBarWidth();
456
457 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800458 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459}
460
Dan Sinclairf528eee2017-02-14 11:52:07 -0500461CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800462 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500463 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
464 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465}
466
tsepez4cf55152016-11-02 14:37:54 -0700467bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
469}
470
tsepezc3255f52016-03-25 14:52:27 -0700471void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472 m_sPrivateParam.dwFlags &= ~dwFlags;
473}
474
tsepezc3255f52016-03-25 14:52:27 -0700475void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476 m_sPrivateParam.dwFlags |= dwFlags;
477}
478
479CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
480 return m_sPrivateParam.sBackgroundColor;
481}
482
483void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
484 m_sPrivateParam.sBackgroundColor = color;
485}
486
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487CPWL_Color CPWL_Wnd::GetTextColor() const {
488 return m_sPrivateParam.sTextColor;
489}
490
dsinclair92cb5e52016-05-16 11:38:28 -0700491BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 return m_sPrivateParam.nBorderStyle;
493}
494
dsinclair92cb5e52016-05-16 11:38:28 -0700495void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 if (HasFlag(PWS_BORDER))
497 m_sPrivateParam.nBorderStyle = nBorderStyle;
498}
499
500int32_t CPWL_Wnd::GetBorderWidth() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700501 return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502}
503
504int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 return 0;
506}
507
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508CPWL_Color CPWL_Wnd::GetBorderColor() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700509 return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510}
511
Lei Zhang7457e382016-01-06 23:00:34 -0800512const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 return m_sPrivateParam.sDash;
514}
515
516void* CPWL_Wnd::GetAttachedData() const {
517 return m_sPrivateParam.pAttachedData;
518}
519
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700521 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522}
523
524void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
525 CreateVScrollBar(cp);
526}
527
528void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700529 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
530 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700531
Lei Zhangfac46f82017-06-02 14:20:04 -0700532 PWL_CREATEPARAM scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533
Lei Zhangfac46f82017-06-02 14:20:04 -0700534 // flags
535 scp.dwFlags =
536 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537
Lei Zhangfac46f82017-06-02 14:20:04 -0700538 scp.pParentWnd = this;
539 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
540 scp.eCursorType = FXCT_ARROW;
541 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
542
543 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
544 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545}
546
547void CPWL_Wnd::SetCapture() {
548 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
549 pMsgCtrl->SetCapture(this);
550}
551
552void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800553 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800554 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800556 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
558 pMsgCtrl->ReleaseCapture();
559}
560
561void CPWL_Wnd::SetFocus() {
562 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
563 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
564 pMsgCtrl->KillFocus();
565 pMsgCtrl->SetFocus(this);
566 }
567}
568
569void CPWL_Wnd::KillFocus() {
570 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
571 if (pMsgCtrl->IsWndCaptureKeyboard(this))
572 pMsgCtrl->KillFocus();
573 }
574}
575
576void CPWL_Wnd::OnSetFocus() {}
577
578void CPWL_Wnd::OnKillFocus() {}
579
Dan Sinclairf528eee2017-02-14 11:52:07 -0500580bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500581 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582}
583
Dan Sinclairf528eee2017-02-14 11:52:07 -0500584bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500585 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586}
587
588const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700589 auto* pParent = m_sPrivateParam.pParentWnd;
590 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591}
592
tsepez4cf55152016-11-02 14:37:54 -0700593void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800594 if (!IsValid())
595 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700596
Lei Zhang375c2762017-03-10 14:37:14 -0800597 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800598 if (pChild)
599 pChild->SetVisible(bVisible);
600 }
601 if (bVisible != m_bVisible) {
602 m_bVisible = bVisible;
603 RePosChildWnd();
604 InvalidateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700606}
607
Tom Sepez281a9ea2016-02-26 14:24:28 -0800608void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 m_rcClip = rect;
610 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611}
612
Tom Sepez281a9ea2016-02-26 14:24:28 -0800613const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615}
616
tsepez4cf55152016-11-02 14:37:54 -0700617bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700619}
620
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700622 CPWL_ScrollBar* pVSB = GetVScrollBar();
623 if (!pVSB)
624 return;
625
Tom Sepez281a9ea2016-02-26 14:24:28 -0800626 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400627 GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth()));
Tom Sepez281a9ea2016-02-26 14:24:28 -0800628 CFX_FloatRect rcVScroll =
629 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
630 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700631 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632}
633
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
635
636void CPWL_Wnd::SetCursor() {
637 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700638 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639 int32_t nCursorType = GetCreationParam().eCursorType;
640 pSH->SetCursor(nCursorType);
641 }
642 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700643}
644
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645void CPWL_Wnd::CreateMsgControl() {
646 if (!m_sPrivateParam.pMsgControl)
647 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700648}
649
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700651 CPWL_MsgControl* pMsgControl = GetMsgControl();
652 if (pMsgControl && pMsgControl->IsWndCreated(this))
653 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700654}
655
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700656CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
657 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700658}
659
tsepez4cf55152016-11-02 14:37:54 -0700660bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700661 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700662}
663
tsepez4cf55152016-11-02 14:37:54 -0700664bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700665 CPWL_MsgControl* pCtrl = GetMsgControl();
666 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700667}
668
tsepez4cf55152016-11-02 14:37:54 -0700669bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700670 CPWL_MsgControl* pCtrl = GetMsgControl();
671 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672}
673
tsepez4cf55152016-11-02 14:37:54 -0700674bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700675 CPWL_MsgControl* pCtrl = GetMsgControl();
676 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677}
678
Tom Sepez281a9ea2016-02-26 14:24:28 -0800679CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681}
682
Dan Sinclair05df0752017-03-14 14:43:42 -0400683float CPWL_Wnd::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685}
686
Dan Sinclair05df0752017-03-14 14:43:42 -0400687void CPWL_Wnd::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700689}
690
dsinclairb9590102016-04-27 06:38:59 -0700691CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693}
694
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
696 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700697}
698
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700699IPWL_Provider* CPWL_Wnd::GetProvider() const {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500700 return m_sPrivateParam.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700701}
702
dsinclairc7a73492016-04-05 12:01:42 -0700703IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705}
706
dsinclair92cb5e52016-05-16 11:38:28 -0700707CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700708 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700709 case BorderStyle::BEVELED:
710 return CPWL_Color(COLORTYPE_GRAY, 1);
711 case BorderStyle::INSET:
712 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
713 default:
714 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700716}
717
dsinclair92cb5e52016-05-16 11:38:28 -0700718CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700720 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500721 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700722 case BorderStyle::INSET:
723 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
724 default:
725 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700726 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700727}
728
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729int32_t CPWL_Wnd::GetTransparency() {
730 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700731}
732
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700733void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800734 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800735 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700739}
740
Tom Sepez60d909e2015-12-10 15:34:55 -0800741CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
742 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800743 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700744 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700745 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700746}
747
Tom Sepez281a9ea2016-02-26 14:24:28 -0800748FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
749 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800750 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751 mt.TransformRect(rcTemp);
752 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
753 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700754}
755
Dan Sinclairf528eee2017-02-14 11:52:07 -0500756CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800757 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 if (mt.IsIdentity())
759 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700760
Nicolas Penab21f1742017-06-29 12:02:06 -0400761 CFX_Matrix inverse = mt.GetInverse();
762 if (!inverse.IsIdentity())
763 mt = inverse;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500764 return mt.Transform(point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700765}
766
Tom Sepez281a9ea2016-02-26 14:24:28 -0800767CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800768 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769 if (mt.IsIdentity())
770 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700771
Nicolas Penab21f1742017-06-29 12:02:06 -0400772 CFX_Matrix inverse = mt.GetInverse();
773 if (!inverse.IsIdentity())
774 mt = inverse;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800775 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700776 mt.TransformRect(rc);
777 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700778}
779
Tom Sepez60d909e2015-12-10 15:34:55 -0800780CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700781 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700782 if (HasFlag(PWS_CHILD)) {
783 const CPWL_Wnd* pParent = this;
784 while (pParent) {
785 mt.Concat(pParent->GetChildMatrix());
786 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700787 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700788 }
789 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700790}
791
Tom Sepez60d909e2015-12-10 15:34:55 -0800792CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700793 return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700794}
795
Tom Sepez60d909e2015-12-10 15:34:55 -0800796void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700797 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700798}
799
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800801 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700802 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803}
804
tsepez4cf55152016-11-02 14:37:54 -0700805void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800806 if (m_bEnabled == bEnable)
807 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700808
Lei Zhang375c2762017-03-10 14:37:14 -0800809 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800810 if (pChild)
811 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700812 }
tsepez6745f962017-01-04 10:09:45 -0800813 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700814}
815
tsepez4cf55152016-11-02 14:37:54 -0700816bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500817 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
818 return pSystemHandler && pSystemHandler->IsCTRLKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700819}
820
tsepez4cf55152016-11-02 14:37:54 -0700821bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500822 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
823 return pSystemHandler && pSystemHandler->IsSHIFTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700824}
825
tsepez4cf55152016-11-02 14:37:54 -0700826bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500827 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
828 return pSystemHandler && pSystemHandler->IsALTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700829}