blob: 151921bc8ed7f5d02d4b6e0127af90743ab32244 [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 Zhangfac46f82017-06-02 14:20:04 -07007#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
8
Lei Zhang606346f2015-06-19 18:11:07 -07009#include <map>
tsepez0d164f82017-01-09 07:28:13 -080010#include <vector>
Lei Zhang606346f2015-06-19 18:11:07 -070011
dan sinclair89e904b2016-03-23 19:29:15 -040012#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
13#include "fpdfsdk/pdfwindow/PWL_Utils.h"
tsepez36eb4bd2016-10-03 15:24:27 -070014#include "third_party/base/ptr_util.h"
tsepez0d164f82017-01-09 07:28:13 -080015#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070016
weili625ad662016-06-15 11:21:33 -070017PWL_CREATEPARAM::PWL_CREATEPARAM()
18 : rcRectWnd(0, 0, 0, 0),
19 pSystemHandler(nullptr),
20 pFontMap(nullptr),
21 pProvider(nullptr),
22 pFocusHandler(nullptr),
23 dwFlags(0),
24 sBackgroundColor(),
dsinclair8faac622016-09-15 12:41:50 -070025 pAttachedWidget(nullptr),
weili625ad662016-06-15 11:21:33 -070026 nBorderStyle(BorderStyle::SOLID),
27 dwBorderWidth(1),
28 sBorderColor(),
29 sTextColor(),
weili625ad662016-06-15 11:21:33 -070030 nTransparency(255),
31 fFontSize(PWL_DEFAULT_FONTSIZE),
32 sDash(3, 0, 0),
33 pAttachedData(nullptr),
34 pParentWnd(nullptr),
35 pMsgControl(nullptr),
Lei Zhangfac46f82017-06-02 14:20:04 -070036 eCursorType(FXCT_ARROW) {}
weili625ad662016-06-15 11:21:33 -070037
38PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default;
39
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040class CPWL_MsgControl {
41 friend class CPWL_Wnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 public:
Lei Zhangc2fb35f2016-01-05 16:46:58 -080044 explicit CPWL_MsgControl(CPWL_Wnd* pWnd) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 m_pCreatedWnd = pWnd;
46 Default();
47 }
48
Dan Sinclairf766ad22016-03-14 13:51:24 -040049 ~CPWL_MsgControl() { Default(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050
51 void Default() {
tsepez0d164f82017-01-09 07:28:13 -080052 m_aMousePath.clear();
53 m_aKeyboardPath.clear();
thestig1cd352e2016-06-07 17:53:06 -070054 m_pMainMouseWnd = nullptr;
55 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056 }
57
tsepez4cf55152016-11-02 14:37:54 -070058 bool IsWndCreated(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 return m_pCreatedWnd == pWnd;
60 }
61
tsepez4cf55152016-11-02 14:37:54 -070062 bool IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063 return pWnd == m_pMainMouseWnd;
64 }
65
tsepez4cf55152016-11-02 14:37:54 -070066 bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -080067 return pWnd && pdfium::ContainsValue(m_aMousePath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 }
69
tsepez4cf55152016-11-02 14:37:54 -070070 bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 return pWnd == m_pMainKeyboardWnd;
72 }
73
tsepez4cf55152016-11-02 14:37:54 -070074 bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -080075 return pWnd && pdfium::ContainsValue(m_aKeyboardPath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 }
77
78 void SetFocus(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -080079 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 if (pWnd) {
81 m_pMainKeyboardWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 CPWL_Wnd* pParent = pWnd;
83 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -080084 m_aKeyboardPath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 pParent = pParent->GetParentWindow();
86 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 pWnd->OnSetFocus();
Tom Sepez2f2ffec2015-07-23 14:42:09 -070088 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 void KillFocus() {
tsepez0d164f82017-01-09 07:28:13 -080092 if (!m_aKeyboardPath.empty())
93 if (CPWL_Wnd* pWnd = m_aKeyboardPath[0])
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 pWnd->OnKillFocus();
95
thestig1cd352e2016-06-07 17:53:06 -070096 m_pMainKeyboardWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -080097 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098 }
99
100 void SetCapture(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -0800101 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 if (pWnd) {
103 m_pMainMouseWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 CPWL_Wnd* pParent = pWnd;
105 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -0800106 m_aMousePath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 pParent = pParent->GetParentWindow();
108 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700109 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 void ReleaseCapture() {
thestig1cd352e2016-06-07 17:53:06 -0700113 m_pMainMouseWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800114 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700116
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 private:
tsepez0d164f82017-01-09 07:28:13 -0800118 std::vector<CPWL_Wnd*> m_aMousePath;
119 std::vector<CPWL_Wnd*> m_aKeyboardPath;
Tom Sepezd0409af2017-05-25 15:53:57 -0700120 CFX_UnownedPtr<CPWL_Wnd> m_pCreatedWnd;
121 CFX_UnownedPtr<CPWL_Wnd> m_pMainMouseWnd;
122 CFX_UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123};
124
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125CPWL_Wnd::CPWL_Wnd()
Lei Zhangfac46f82017-06-02 14:20:04 -0700126 : m_rcWindow(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 m_rcClip(),
tsepez4cf55152016-11-02 14:37:54 -0700128 m_bCreated(false),
129 m_bVisible(false),
130 m_bNotifying(false),
131 m_bEnabled(true) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132
133CPWL_Wnd::~CPWL_Wnd() {
Lei Zhangb45324b2017-05-22 17:05:40 -0700134 ASSERT(!m_bCreated);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135}
136
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137CFX_ByteString CPWL_Wnd::GetClassName() const {
138 return "CPWL_Wnd";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700139}
140
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700142 if (IsValid())
143 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144
Lei Zhangfac46f82017-06-02 14:20:04 -0700145 m_sPrivateParam = cp;
146 OnCreate(m_sPrivateParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147
Lei Zhangfac46f82017-06-02 14:20:04 -0700148 m_sPrivateParam.rcRectWnd.Normalize();
149 m_rcWindow = m_sPrivateParam.rcRectWnd;
150 m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f);
151 CreateMsgControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152
Lei Zhangfac46f82017-06-02 14:20:04 -0700153 if (m_sPrivateParam.pParentWnd)
154 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155
Lei Zhangfac46f82017-06-02 14:20:04 -0700156 PWL_CREATEPARAM ccp = m_sPrivateParam;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157
Lei Zhangfac46f82017-06-02 14:20:04 -0700158 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
159 CreateScrollBar(ccp);
160 CreateChildWnd(ccp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161
Lei Zhangfac46f82017-06-02 14:20:04 -0700162 m_bVisible = HasFlag(PWS_VISIBLE);
163 OnCreated();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164
Lei Zhangfac46f82017-06-02 14:20:04 -0700165 RePosChildWnd();
166 m_bCreated = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700167}
168
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700170
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171void CPWL_Wnd::OnCreated() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700172
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173void CPWL_Wnd::OnDestroy() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700174
Lei Zhangab5537d2016-01-06 14:58:14 -0800175void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) {
176 if (m_sPrivateParam.pFocusHandler == handler)
177 m_sPrivateParam.pFocusHandler = nullptr;
178}
179
180void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500181 if (m_sPrivateParam.pProvider.Get() == provider)
182 m_sPrivateParam.pProvider.Reset();
Lei Zhangab5537d2016-01-06 14:58:14 -0800183}
184
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185void CPWL_Wnd::Destroy() {
186 KillFocus();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 OnDestroy();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 if (m_bCreated) {
tsepez6745f962017-01-04 10:09:45 -0800189 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
190 if (CPWL_Wnd* pChild = *it) {
191 *it = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 pChild->Destroy();
193 delete pChild;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194 }
195 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 if (m_sPrivateParam.pParentWnd)
197 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD);
tsepez6745f962017-01-04 10:09:45 -0800198
tsepez4cf55152016-11-02 14:37:54 -0700199 m_bCreated = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201 DestroyMsgControl();
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500202 m_sPrivateParam.Reset();
tsepez6745f962017-01-04 10:09:45 -0800203 m_Children.clear();
thestig1cd352e2016-06-07 17:53:06 -0700204 m_pVScrollBar = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700206
tsepez4cf55152016-11-02 14:37:54 -0700207void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700208 if (!IsValid())
209 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700210
Lei Zhangfac46f82017-06-02 14:20:04 -0700211 CFX_FloatRect rcOld = GetWindowRect();
212 m_rcWindow = rcNew;
213 m_rcWindow.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214
Lei Zhangfac46f82017-06-02 14:20:04 -0700215 if (bReset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
217 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700218 RePosChildWnd();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700219 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700221 if (bRefresh)
222 InvalidateRectMove(rcOld, rcNew);
223
224 m_sPrivateParam.rcRectWnd = m_rcWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700225}
226
Tom Sepez281a9ea2016-02-26 14:24:28 -0800227void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
228 const CFX_FloatRect& rcNew) {
229 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700231
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 InvalidateRect(&rcUnion);
233}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700234
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700235void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) {
236 if (IsValid() && IsVisible()) {
237 GetThisAppearanceStream(sAppStream);
238 GetChildAppearanceStream(sAppStream);
239 }
240}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700241
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242// if don't set,Get default apperance stream
243void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800244 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700245 if (rectWnd.IsEmpty())
246 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247
Lei Zhangfac46f82017-06-02 14:20:04 -0700248 CFX_ByteTextBuf sThis;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249
Lei Zhangfac46f82017-06-02 14:20:04 -0700250 if (HasFlag(PWS_BACKGROUND))
251 sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252
Lei Zhangfac46f82017-06-02 14:20:04 -0700253 if (HasFlag(PWS_BORDER)) {
254 sThis << CPWL_Utils::GetBorderAppStream(
255 rectWnd, (float)GetBorderWidth(), GetBorderColor(),
256 GetBorderLeftTopColor(GetBorderStyle()),
257 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
258 GetBorderDash());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700260
261 sAppStream << sThis;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700262}
263
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) {
tsepez6745f962017-01-04 10:09:45 -0800265 for (CPWL_Wnd* pChild : m_Children) {
266 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700267 pChild->GetAppearanceStream(sAppStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269}
270
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800272 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273 if (IsValid() && IsVisible()) {
274 DrawThisAppearance(pDevice, pUser2Device);
275 DrawChildAppearance(pDevice, pUser2Device);
276 }
277}
278
279void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800280 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800281 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700282 if (rectWnd.IsEmpty())
283 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284
Lei Zhangfac46f82017-06-02 14:20:04 -0700285 if (HasFlag(PWS_BACKGROUND)) {
286 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
287 rectWnd, (float)(GetBorderWidth() + GetInnerBorderWidth()));
288 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
289 GetBackgroundColor(), GetTransparency());
290 }
291
292 if (HasFlag(PWS_BORDER)) {
293 CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd,
294 (float)GetBorderWidth(), GetBorderColor(),
295 GetBorderLeftTopColor(GetBorderStyle()),
296 GetBorderRightBottomColor(GetBorderStyle()),
297 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700299}
300
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800302 CFX_Matrix* pUser2Device) {
tsepez6745f962017-01-04 10:09:45 -0800303 for (CPWL_Wnd* pChild : m_Children) {
304 if (!pChild)
305 continue;
306
307 CFX_Matrix mt = pChild->GetChildMatrix();
308 if (mt.IsIdentity()) {
309 pChild->DrawAppearance(pDevice, pUser2Device);
310 } else {
311 mt.Concat(*pUser2Device);
312 pChild->DrawAppearance(pDevice, &mt);
Lei Zhang60f507b2015-06-13 00:41:00 -0700313 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700315}
316
Tom Sepez281a9ea2016-02-26 14:24:28 -0800317void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700318 if (!IsValid())
319 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320
Lei Zhangfac46f82017-06-02 14:20:04 -0700321 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
322
323 if (!HasFlag(PWS_NOREFRESHCLIP)) {
324 CFX_FloatRect rcClip = GetClipRect();
325 if (!rcClip.IsEmpty()) {
326 rcRefresh.Intersect(rcClip);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700327 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700328 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700329
Lei Zhangfac46f82017-06-02 14:20:04 -0700330 FX_RECT rcWin = PWLtoWnd(rcRefresh);
331 rcWin.left -= PWL_INVALIDATE_INFLATE;
332 rcWin.top -= PWL_INVALIDATE_INFLATE;
333 rcWin.right += PWL_INVALIDATE_INFLATE;
334 rcWin.bottom += PWL_INVALIDATE_INFLATE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335
Lei Zhangfac46f82017-06-02 14:20:04 -0700336 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
337 if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>(
338 m_sPrivateParam.pAttachedWidget.Get())) {
339 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700340 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700342}
343
tsepez6745f962017-01-04 10:09:45 -0800344#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
345 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
346 if (!IsValid() || !IsVisible() || !IsEnabled()) \
347 return false; \
348 if (!IsWndCaptureKeyboard(this)) \
349 return false; \
Lei Zhang375c2762017-03-10 14:37:14 -0800350 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800351 if (pChild && IsWndCaptureKeyboard(pChild)) \
352 return pChild->key_method_name(nChar, nFlag); \
353 } \
354 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700356
357PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700358PWL_IMPLEMENT_KEY_METHOD(OnChar)
tsepez6745f962017-01-04 10:09:45 -0800359#undef PWL_IMPLEMENT_KEY_METHOD
360
361#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Dan Sinclairf528eee2017-02-14 11:52:07 -0500362 bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \
tsepez6745f962017-01-04 10:09:45 -0800363 if (!IsValid() || !IsVisible() || !IsEnabled()) \
364 return false; \
365 if (IsWndCaptureMouse(this)) { \
Lei Zhang375c2762017-03-10 14:37:14 -0800366 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800367 if (pChild && IsWndCaptureMouse(pChild)) { \
368 return pChild->mouse_method_name(pChild->ParentToChild(point), \
369 nFlag); \
370 } \
371 } \
372 SetCursor(); \
373 return false; \
374 } \
Lei Zhang375c2762017-03-10 14:37:14 -0800375 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800376 if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \
377 return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \
378 } \
379 } \
380 if (WndHitTest(point)) \
381 SetCursor(); \
382 return false; \
383 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700384
385PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
386PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
387PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700388PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
389PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
390PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
tsepez6745f962017-01-04 10:09:45 -0800391#undef PWL_IMPLEMENT_MOUSE_METHOD
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700392
tsepez4cf55152016-11-02 14:37:54 -0700393bool CPWL_Wnd::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500394 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700395 uint32_t nFlag) {
tsepez6745f962017-01-04 10:09:45 -0800396 if (!IsValid() || !IsVisible() || !IsEnabled())
397 return false;
398
399 SetCursor();
400 if (!IsWndCaptureKeyboard(this))
401 return false;
402
Lei Zhang375c2762017-03-10 14:37:14 -0800403 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800404 if (pChild && IsWndCaptureKeyboard(pChild))
405 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406 }
tsepez4cf55152016-11-02 14:37:54 -0700407 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700408}
409
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800411 m_Children.push_back(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700412}
413
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800415 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
416 if (*it && *it == pWnd) {
417 m_Children.erase(std::next(it).base());
418 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700419 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700420 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700421}
422
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700424 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 intptr_t wParam,
426 intptr_t lParam) {
427 switch (msg) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700428 case PNM_ADDCHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 AddChild(pWnd);
430 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700431 case PNM_REMOVECHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432 RemoveChild(pWnd);
433 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700434 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 break;
436 }
437}
438
tsepez4cf55152016-11-02 14:37:54 -0700439bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 return m_bCreated;
441}
442
Lei Zhang7457e382016-01-06 23:00:34 -0800443const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 return m_sPrivateParam;
445}
446
447CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
448 return m_sPrivateParam.pParentWnd;
449}
450
Tom Sepez281a9ea2016-02-26 14:24:28 -0800451CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452 return m_rcWindow;
453}
454
Tom Sepez281a9ea2016-02-26 14:24:28 -0800455CFX_FloatRect CPWL_Wnd::GetClientRect() const {
456 CFX_FloatRect rcWindow = GetWindowRect();
457 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400458 rcWindow, (float)(GetBorderWidth() + GetInnerBorderWidth()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
460 rcClient.right -= pVSB->GetScrollBarWidth();
461
462 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800463 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464}
465
Dan Sinclairf528eee2017-02-14 11:52:07 -0500466CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800467 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500468 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
469 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470}
471
tsepez4cf55152016-11-02 14:37:54 -0700472bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
474}
475
tsepezc3255f52016-03-25 14:52:27 -0700476void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 m_sPrivateParam.dwFlags &= ~dwFlags;
478}
479
tsepezc3255f52016-03-25 14:52:27 -0700480void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481 m_sPrivateParam.dwFlags |= dwFlags;
482}
483
484CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
485 return m_sPrivateParam.sBackgroundColor;
486}
487
488void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
489 m_sPrivateParam.sBackgroundColor = color;
490}
491
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492CPWL_Color CPWL_Wnd::GetTextColor() const {
493 return m_sPrivateParam.sTextColor;
494}
495
dsinclair92cb5e52016-05-16 11:38:28 -0700496BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 return m_sPrivateParam.nBorderStyle;
498}
499
dsinclair92cb5e52016-05-16 11:38:28 -0700500void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 if (HasFlag(PWS_BORDER))
502 m_sPrivateParam.nBorderStyle = nBorderStyle;
503}
504
505int32_t CPWL_Wnd::GetBorderWidth() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700506 return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507}
508
509int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510 return 0;
511}
512
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513CPWL_Color CPWL_Wnd::GetBorderColor() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700514 return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515}
516
Lei Zhang7457e382016-01-06 23:00:34 -0800517const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518 return m_sPrivateParam.sDash;
519}
520
521void* CPWL_Wnd::GetAttachedData() const {
522 return m_sPrivateParam.pAttachedData;
523}
524
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700526 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527}
528
529void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
530 CreateVScrollBar(cp);
531}
532
533void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700534 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
535 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536
Lei Zhangfac46f82017-06-02 14:20:04 -0700537 PWL_CREATEPARAM scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538
Lei Zhangfac46f82017-06-02 14:20:04 -0700539 // flags
540 scp.dwFlags =
541 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542
Lei Zhangfac46f82017-06-02 14:20:04 -0700543 scp.pParentWnd = this;
544 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
545 scp.eCursorType = FXCT_ARROW;
546 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
547
548 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
549 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550}
551
552void CPWL_Wnd::SetCapture() {
553 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
554 pMsgCtrl->SetCapture(this);
555}
556
557void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800558 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800559 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800561 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
563 pMsgCtrl->ReleaseCapture();
564}
565
566void CPWL_Wnd::SetFocus() {
567 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
568 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
569 pMsgCtrl->KillFocus();
570 pMsgCtrl->SetFocus(this);
571 }
572}
573
574void CPWL_Wnd::KillFocus() {
575 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
576 if (pMsgCtrl->IsWndCaptureKeyboard(this))
577 pMsgCtrl->KillFocus();
578 }
579}
580
581void CPWL_Wnd::OnSetFocus() {}
582
583void CPWL_Wnd::OnKillFocus() {}
584
Dan Sinclairf528eee2017-02-14 11:52:07 -0500585bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500586 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587}
588
Dan Sinclairf528eee2017-02-14 11:52:07 -0500589bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500590 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591}
592
593const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700594 auto* pParent = m_sPrivateParam.pParentWnd;
595 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700596}
597
tsepez4cf55152016-11-02 14:37:54 -0700598void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800599 if (!IsValid())
600 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601
Lei Zhang375c2762017-03-10 14:37:14 -0800602 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800603 if (pChild)
604 pChild->SetVisible(bVisible);
605 }
606 if (bVisible != m_bVisible) {
607 m_bVisible = bVisible;
608 RePosChildWnd();
609 InvalidateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611}
612
Tom Sepez281a9ea2016-02-26 14:24:28 -0800613void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 m_rcClip = rect;
615 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700616}
617
Tom Sepez281a9ea2016-02-26 14:24:28 -0800618const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700620}
621
tsepez4cf55152016-11-02 14:37:54 -0700622bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700624}
625
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700627 CPWL_ScrollBar* pVSB = GetVScrollBar();
628 if (!pVSB)
629 return;
630
Tom Sepez281a9ea2016-02-26 14:24:28 -0800631 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400632 GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth()));
Tom Sepez281a9ea2016-02-26 14:24:28 -0800633 CFX_FloatRect rcVScroll =
634 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
635 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700636 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700637}
638
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
640
641void CPWL_Wnd::SetCursor() {
642 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700643 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644 int32_t nCursorType = GetCreationParam().eCursorType;
645 pSH->SetCursor(nCursorType);
646 }
647 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700648}
649
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650void CPWL_Wnd::CreateMsgControl() {
651 if (!m_sPrivateParam.pMsgControl)
652 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700653}
654
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700655void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700656 CPWL_MsgControl* pMsgControl = GetMsgControl();
657 if (pMsgControl && pMsgControl->IsWndCreated(this))
658 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700659}
660
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700661CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
662 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700663}
664
tsepez4cf55152016-11-02 14:37:54 -0700665bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700667}
668
tsepez4cf55152016-11-02 14:37:54 -0700669bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700670 CPWL_MsgControl* pCtrl = GetMsgControl();
671 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672}
673
tsepez4cf55152016-11-02 14:37:54 -0700674bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700675 CPWL_MsgControl* pCtrl = GetMsgControl();
676 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677}
678
tsepez4cf55152016-11-02 14:37:54 -0700679bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700680 CPWL_MsgControl* pCtrl = GetMsgControl();
681 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700682}
683
Tom Sepez281a9ea2016-02-26 14:24:28 -0800684CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700686}
687
Dan Sinclair05df0752017-03-14 14:43:42 -0400688float CPWL_Wnd::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700690}
691
Dan Sinclair05df0752017-03-14 14:43:42 -0400692void CPWL_Wnd::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700694}
695
dsinclairb9590102016-04-27 06:38:59 -0700696CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700698}
699
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
701 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700702}
703
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704IPWL_Provider* CPWL_Wnd::GetProvider() const {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500705 return m_sPrivateParam.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700706}
707
dsinclairc7a73492016-04-05 12:01:42 -0700708IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700710}
711
dsinclair92cb5e52016-05-16 11:38:28 -0700712CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700714 case BorderStyle::BEVELED:
715 return CPWL_Color(COLORTYPE_GRAY, 1);
716 case BorderStyle::INSET:
717 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
718 default:
719 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700720 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700721}
722
dsinclair92cb5e52016-05-16 11:38:28 -0700723CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700725 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500726 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700727 case BorderStyle::INSET:
728 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
729 default:
730 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700732}
733
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734int32_t CPWL_Wnd::GetTransparency() {
735 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700736}
737
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800739 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800740 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700741 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700744}
745
Tom Sepez60d909e2015-12-10 15:34:55 -0800746CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
747 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800748 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751}
752
Tom Sepez281a9ea2016-02-26 14:24:28 -0800753FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
754 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800755 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756 mt.TransformRect(rcTemp);
757 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
758 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759}
760
Dan Sinclairf528eee2017-02-14 11:52:07 -0500761CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800762 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700763 if (mt.IsIdentity())
764 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700765
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700766 mt.SetReverse(mt);
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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800776 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700777 mt.TransformRect(rc);
778 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700779}
780
Tom Sepez60d909e2015-12-10 15:34:55 -0800781CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700782 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700783 if (HasFlag(PWS_CHILD)) {
784 const CPWL_Wnd* pParent = this;
785 while (pParent) {
786 mt.Concat(pParent->GetChildMatrix());
787 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700788 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700789 }
790 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700791}
792
Tom Sepez60d909e2015-12-10 15:34:55 -0800793CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700794 return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700795}
796
Tom Sepez60d909e2015-12-10 15:34:55 -0800797void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700799}
800
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700801const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800802 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700803 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700804}
805
tsepez4cf55152016-11-02 14:37:54 -0700806void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800807 if (m_bEnabled == bEnable)
808 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700809
Lei Zhang375c2762017-03-10 14:37:14 -0800810 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800811 if (pChild)
812 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700813 }
tsepez6745f962017-01-04 10:09:45 -0800814 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700815}
816
tsepez4cf55152016-11-02 14:37:54 -0700817bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500818 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
819 return pSystemHandler && pSystemHandler->IsCTRLKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700820}
821
tsepez4cf55152016-11-02 14:37:54 -0700822bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500823 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
824 return pSystemHandler && pSystemHandler->IsSHIFTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700825}
826
tsepez4cf55152016-11-02 14:37:54 -0700827bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
Dan Sinclair90b73262017-02-23 14:38:48 -0500828 CFX_SystemHandler* pSystemHandler = GetSystemHandler();
829 return pSystemHandler && pSystemHandler->IsALTKeyDown(nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700830}