blob: 401fed3f9c15ef8e555d6c87447d4515d812f2a8 [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
Dan Sinclairc411eb92017-07-25 09:39:30 -04007#include "fpdfsdk/pwl/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
Dan Sinclair0b7378a2017-07-17 12:05:40 -040013#include "core/fxge/cfx_renderdevice.h"
Dan Sinclairc411eb92017-07-25 09:39:30 -040014#include "fpdfsdk/pwl/cpwl_scroll_bar.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
Dan Sinclaira9e28432017-07-05 14:18:14 -040018namespace {
19
20constexpr float kDefaultFontSize = 9.0f;
Dan Sinclaira9e28432017-07-05 14:18:14 -040021
22} // namespace
23
Tom Sepezbf157302017-09-15 13:26:32 -070024CPWL_Wnd::CreateParams::CreateParams()
weili625ad662016-06-15 11:21:33 -070025 : rcRectWnd(0, 0, 0, 0),
26 pSystemHandler(nullptr),
27 pFontMap(nullptr),
28 pProvider(nullptr),
29 pFocusHandler(nullptr),
30 dwFlags(0),
31 sBackgroundColor(),
dsinclair8faac622016-09-15 12:41:50 -070032 pAttachedWidget(nullptr),
weili625ad662016-06-15 11:21:33 -070033 nBorderStyle(BorderStyle::SOLID),
34 dwBorderWidth(1),
35 sBorderColor(),
36 sTextColor(),
weili625ad662016-06-15 11:21:33 -070037 nTransparency(255),
Dan Sinclaira9e28432017-07-05 14:18:14 -040038 fFontSize(kDefaultFontSize),
weili625ad662016-06-15 11:21:33 -070039 sDash(3, 0, 0),
40 pAttachedData(nullptr),
41 pParentWnd(nullptr),
42 pMsgControl(nullptr),
Lei Zhangfac46f82017-06-02 14:20:04 -070043 eCursorType(FXCT_ARROW) {}
weili625ad662016-06-15 11:21:33 -070044
Tom Sepezbf157302017-09-15 13:26:32 -070045CPWL_Wnd::CreateParams::CreateParams(const CreateParams& other) = default;
weili625ad662016-06-15 11:21:33 -070046
Tom Sepez134ac912017-09-15 15:32:01 -070047CPWL_Wnd::CreateParams::~CreateParams() = default;
48
Ryan Harrison022d13b2017-09-15 14:35:41 -040049class CPWL_MsgControl : public CFX_Observable<CPWL_MsgControl> {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050 friend class CPWL_Wnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070051
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052 public:
Lei Zhangc2fb35f2016-01-05 16:46:58 -080053 explicit CPWL_MsgControl(CPWL_Wnd* pWnd) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 m_pCreatedWnd = pWnd;
55 Default();
56 }
57
Dan Sinclairf766ad22016-03-14 13:51:24 -040058 ~CPWL_MsgControl() { Default(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059
60 void Default() {
tsepez0d164f82017-01-09 07:28:13 -080061 m_aMousePath.clear();
62 m_aKeyboardPath.clear();
thestig1cd352e2016-06-07 17:53:06 -070063 m_pMainMouseWnd = nullptr;
64 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065 }
66
tsepez4cf55152016-11-02 14:37:54 -070067 bool IsWndCreated(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 return m_pCreatedWnd == pWnd;
69 }
70
tsepez4cf55152016-11-02 14:37:54 -070071 bool IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 return pWnd == m_pMainMouseWnd;
73 }
74
tsepez4cf55152016-11-02 14:37:54 -070075 bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -080076 return pWnd && pdfium::ContainsValue(m_aMousePath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077 }
78
tsepez4cf55152016-11-02 14:37:54 -070079 bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 return pWnd == m_pMainKeyboardWnd;
81 }
82
tsepez4cf55152016-11-02 14:37:54 -070083 bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -080084 return pWnd && pdfium::ContainsValue(m_aKeyboardPath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 }
86
87 void SetFocus(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -080088 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 if (pWnd) {
90 m_pMainKeyboardWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 CPWL_Wnd* pParent = pWnd;
92 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -080093 m_aKeyboardPath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 pParent = pParent->GetParentWindow();
95 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096 pWnd->OnSetFocus();
Tom Sepez2f2ffec2015-07-23 14:42:09 -070097 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100 void KillFocus() {
Ryan Harrison022d13b2017-09-15 14:35:41 -0400101 ObservedPtr observed_ptr = ObservedPtr(this);
tsepez0d164f82017-01-09 07:28:13 -0800102 if (!m_aKeyboardPath.empty())
103 if (CPWL_Wnd* pWnd = m_aKeyboardPath[0])
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 pWnd->OnKillFocus();
Ryan Harrison022d13b2017-09-15 14:35:41 -0400105 if (!observed_ptr)
106 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107
thestig1cd352e2016-06-07 17:53:06 -0700108 m_pMainKeyboardWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800109 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 }
111
112 void SetCapture(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -0800113 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114 if (pWnd) {
115 m_pMainMouseWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 CPWL_Wnd* pParent = pWnd;
117 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -0800118 m_aMousePath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119 pParent = pParent->GetParentWindow();
120 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700121 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124 void ReleaseCapture() {
thestig1cd352e2016-06-07 17:53:06 -0700125 m_pMainMouseWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800126 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700128
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 private:
tsepez0d164f82017-01-09 07:28:13 -0800130 std::vector<CPWL_Wnd*> m_aMousePath;
131 std::vector<CPWL_Wnd*> m_aKeyboardPath;
Tom Sepezd0409af2017-05-25 15:53:57 -0700132 CFX_UnownedPtr<CPWL_Wnd> m_pCreatedWnd;
133 CFX_UnownedPtr<CPWL_Wnd> m_pMainMouseWnd;
134 CFX_UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135};
136
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137CPWL_Wnd::CPWL_Wnd()
Lei Zhangfac46f82017-06-02 14:20:04 -0700138 : m_rcWindow(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139 m_rcClip(),
tsepez4cf55152016-11-02 14:37:54 -0700140 m_bCreated(false),
141 m_bVisible(false),
142 m_bNotifying(false),
143 m_bEnabled(true) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144
145CPWL_Wnd::~CPWL_Wnd() {
Lei Zhangb45324b2017-05-22 17:05:40 -0700146 ASSERT(!m_bCreated);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700147}
148
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149CFX_ByteString CPWL_Wnd::GetClassName() const {
150 return "CPWL_Wnd";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700151}
152
Tom Sepezbf157302017-09-15 13:26:32 -0700153void CPWL_Wnd::Create(const CreateParams& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700154 if (IsValid())
155 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156
Tom Sepezbf157302017-09-15 13:26:32 -0700157 m_CreationParams = cp;
158 OnCreate(&m_CreationParams);
159 m_CreationParams.rcRectWnd.Normalize();
160 m_rcWindow = m_CreationParams.rcRectWnd;
dan sinclairadf922f2017-07-12 21:56:27 -0400161 m_rcClip = m_rcWindow;
162 if (!m_rcClip.IsEmpty()) {
163 m_rcClip.Inflate(1.0f, 1.0f);
164 m_rcClip.Normalize();
165 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700166 CreateMsgControl();
Tom Sepezbf157302017-09-15 13:26:32 -0700167 if (m_CreationParams.pParentWnd)
168 m_CreationParams.pParentWnd->AddChild(this);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169
Tom Sepezbf157302017-09-15 13:26:32 -0700170 CreateParams ccp = m_CreationParams;
Lei Zhangfac46f82017-06-02 14:20:04 -0700171 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
172 CreateScrollBar(ccp);
173 CreateChildWnd(ccp);
Lei Zhangfac46f82017-06-02 14:20:04 -0700174 m_bVisible = HasFlag(PWS_VISIBLE);
175 OnCreated();
Lei Zhangfac46f82017-06-02 14:20:04 -0700176 RePosChildWnd();
177 m_bCreated = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178}
179
Tom Sepezbf157302017-09-15 13:26:32 -0700180void CPWL_Wnd::OnCreate(CreateParams* pParamsToAdjust) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700181
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182void CPWL_Wnd::OnCreated() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700183
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184void CPWL_Wnd::OnDestroy() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700185
Tom Sepez134ac912017-09-15 15:32:01 -0700186void CPWL_Wnd::InvalidateFocusHandler(FocusHandlerIface* handler) {
Tom Sepezbf157302017-09-15 13:26:32 -0700187 if (m_CreationParams.pFocusHandler == handler)
188 m_CreationParams.pFocusHandler = nullptr;
Lei Zhangab5537d2016-01-06 14:58:14 -0800189}
190
Tom Sepez134ac912017-09-15 15:32:01 -0700191void CPWL_Wnd::InvalidateProvider(ProviderIface* provider) {
Tom Sepezbf157302017-09-15 13:26:32 -0700192 if (m_CreationParams.pProvider.Get() == provider)
193 m_CreationParams.pProvider.Reset();
Lei Zhangab5537d2016-01-06 14:58:14 -0800194}
195
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196void CPWL_Wnd::Destroy() {
197 KillFocus();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 OnDestroy();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 if (m_bCreated) {
Lei Zhang35162562017-06-09 01:04:52 -0700200 m_pVScrollBar = nullptr;
tsepez6745f962017-01-04 10:09:45 -0800201 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
202 if (CPWL_Wnd* pChild = *it) {
203 *it = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204 pChild->Destroy();
205 delete pChild;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 }
207 }
Tom Sepezbf157302017-09-15 13:26:32 -0700208 if (m_CreationParams.pParentWnd)
209 m_CreationParams.pParentWnd->RemoveChild(this);
tsepez6745f962017-01-04 10:09:45 -0800210
tsepez4cf55152016-11-02 14:37:54 -0700211 m_bCreated = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 DestroyMsgControl();
tsepez6745f962017-01-04 10:09:45 -0800214 m_Children.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216
tsepez4cf55152016-11-02 14:37:54 -0700217void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700218 if (!IsValid())
219 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700220
Lei Zhangfac46f82017-06-02 14:20:04 -0700221 CFX_FloatRect rcOld = GetWindowRect();
222 m_rcWindow = rcNew;
223 m_rcWindow.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224
Lei Zhangfac46f82017-06-02 14:20:04 -0700225 if (bReset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
227 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700228 RePosChildWnd();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700229 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700231 if (bRefresh)
232 InvalidateRectMove(rcOld, rcNew);
233
Tom Sepezbf157302017-09-15 13:26:32 -0700234 m_CreationParams.rcRectWnd = m_rcWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700235}
236
Tom Sepez281a9ea2016-02-26 14:24:28 -0800237void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
238 const CFX_FloatRect& rcNew) {
239 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700241
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242 InvalidateRect(&rcUnion);
243}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Lei Zhangeb14e042017-08-15 13:56:43 -0700246 const CFX_Matrix& mtUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247 if (IsValid() && IsVisible()) {
Lei Zhangeb14e042017-08-15 13:56:43 -0700248 DrawThisAppearance(pDevice, mtUser2Device);
249 DrawChildAppearance(pDevice, mtUser2Device);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250 }
251}
252
253void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Lei Zhangeb14e042017-08-15 13:56:43 -0700254 const CFX_Matrix& mtUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800255 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700256 if (rectWnd.IsEmpty())
257 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258
Lei Zhangfac46f82017-06-02 14:20:04 -0700259 if (HasFlag(PWS_BACKGROUND)) {
dan sinclaird6aff2f2017-07-13 21:36:29 -0400260 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
Lei Zhangeb14e042017-08-15 13:56:43 -0700261 pDevice->DrawFillRect(&mtUser2Device, rectWnd.GetDeflated(width, width),
Dan Sinclair0b7378a2017-07-17 12:05:40 -0400262 GetBackgroundColor(), GetTransparency());
Lei Zhangfac46f82017-06-02 14:20:04 -0700263 }
264
265 if (HasFlag(PWS_BORDER)) {
Lei Zhangeb14e042017-08-15 13:56:43 -0700266 pDevice->DrawBorder(&mtUser2Device, rectWnd,
Dan Sinclair0b7378a2017-07-17 12:05:40 -0400267 static_cast<float>(GetBorderWidth()), GetBorderColor(),
268 GetBorderLeftTopColor(GetBorderStyle()),
269 GetBorderRightBottomColor(GetBorderStyle()),
270 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700272}
273
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Lei Zhangeb14e042017-08-15 13:56:43 -0700275 const CFX_Matrix& mtUser2Device) {
tsepez6745f962017-01-04 10:09:45 -0800276 for (CPWL_Wnd* pChild : m_Children) {
277 if (!pChild)
278 continue;
279
280 CFX_Matrix mt = pChild->GetChildMatrix();
281 if (mt.IsIdentity()) {
Lei Zhangeb14e042017-08-15 13:56:43 -0700282 pChild->DrawAppearance(pDevice, mtUser2Device);
tsepez6745f962017-01-04 10:09:45 -0800283 } else {
Lei Zhangeb14e042017-08-15 13:56:43 -0700284 mt.Concat(mtUser2Device);
285 pChild->DrawAppearance(pDevice, mt);
Lei Zhang60f507b2015-06-13 00:41:00 -0700286 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700288}
289
Tom Sepez281a9ea2016-02-26 14:24:28 -0800290void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700291 if (!IsValid())
292 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293
Lei Zhangfac46f82017-06-02 14:20:04 -0700294 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
295
296 if (!HasFlag(PWS_NOREFRESHCLIP)) {
297 CFX_FloatRect rcClip = GetClipRect();
298 if (!rcClip.IsEmpty()) {
299 rcRefresh.Intersect(rcClip);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700300 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700301 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700302
Lei Zhang77f9bff2017-08-29 11:34:12 -0700303 CFX_FloatRect rcWin = PWLtoWnd(rcRefresh);
304 rcWin.Inflate(1, 1);
305 rcWin.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306
Lei Zhangfac46f82017-06-02 14:20:04 -0700307 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
308 if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>(
Tom Sepezbf157302017-09-15 13:26:32 -0700309 m_CreationParams.pAttachedWidget.Get())) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700310 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700311 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700313}
314
tsepez6745f962017-01-04 10:09:45 -0800315#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
316 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
317 if (!IsValid() || !IsVisible() || !IsEnabled()) \
318 return false; \
319 if (!IsWndCaptureKeyboard(this)) \
320 return false; \
Lei Zhang375c2762017-03-10 14:37:14 -0800321 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800322 if (pChild && IsWndCaptureKeyboard(pChild)) \
323 return pChild->key_method_name(nChar, nFlag); \
324 } \
325 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700327
328PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700329PWL_IMPLEMENT_KEY_METHOD(OnChar)
tsepez6745f962017-01-04 10:09:45 -0800330#undef PWL_IMPLEMENT_KEY_METHOD
331
332#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Dan Sinclairf528eee2017-02-14 11:52:07 -0500333 bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \
tsepez6745f962017-01-04 10:09:45 -0800334 if (!IsValid() || !IsVisible() || !IsEnabled()) \
335 return false; \
336 if (IsWndCaptureMouse(this)) { \
Lei Zhang375c2762017-03-10 14:37:14 -0800337 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800338 if (pChild && IsWndCaptureMouse(pChild)) { \
339 return pChild->mouse_method_name(pChild->ParentToChild(point), \
340 nFlag); \
341 } \
342 } \
343 SetCursor(); \
344 return false; \
345 } \
Lei Zhang375c2762017-03-10 14:37:14 -0800346 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800347 if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \
348 return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \
349 } \
350 } \
351 if (WndHitTest(point)) \
352 SetCursor(); \
353 return false; \
354 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700355
356PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
357PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
358PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700359PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
360PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
361PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
tsepez6745f962017-01-04 10:09:45 -0800362#undef PWL_IMPLEMENT_MOUSE_METHOD
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700363
Diana Gagedce2d722017-06-20 11:17:11 -0700364CFX_WideString CPWL_Wnd::GetSelectedText() {
365 return CFX_WideString();
366}
367
Diana Gageab390972017-07-28 17:07:39 -0700368void CPWL_Wnd::ReplaceSelection(const CFX_WideString& text) {}
Diana Gage1c7f1422017-07-24 11:19:52 -0700369
tsepez4cf55152016-11-02 14:37:54 -0700370bool CPWL_Wnd::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500371 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700372 uint32_t nFlag) {
tsepez6745f962017-01-04 10:09:45 -0800373 if (!IsValid() || !IsVisible() || !IsEnabled())
374 return false;
375
376 SetCursor();
377 if (!IsWndCaptureKeyboard(this))
378 return false;
379
Lei Zhang375c2762017-03-10 14:37:14 -0800380 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800381 if (pChild && IsWndCaptureKeyboard(pChild))
382 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383 }
tsepez4cf55152016-11-02 14:37:54 -0700384 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700385}
386
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800388 m_Children.push_back(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389}
390
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800392 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
393 if (*it && *it == pWnd) {
394 m_Children.erase(std::next(it).base());
395 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700396 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700397 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700398}
399
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400400void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {}
401
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400402void CPWL_Wnd::SetScrollPosition(float pos) {}
403
Dan Sinclair63fbd8d2017-07-05 14:10:36 -0400404void CPWL_Wnd::ScrollWindowVertically(float pos) {}
405
Dan Sinclair7f6bec92017-07-05 14:13:16 -0400406void CPWL_Wnd::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {}
407
408void CPWL_Wnd::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {}
409
410void CPWL_Wnd::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) {}
411
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700413 return m_CreationParams.pParentWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414}
415
Tom Sepez281a9ea2016-02-26 14:24:28 -0800416CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 return m_rcWindow;
418}
419
Tom Sepez281a9ea2016-02-26 14:24:28 -0800420CFX_FloatRect CPWL_Wnd::GetClientRect() const {
421 CFX_FloatRect rcWindow = GetWindowRect();
dan sinclairadf922f2017-07-12 21:56:27 -0400422
dan sinclaird6aff2f2017-07-13 21:36:29 -0400423 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
424 CFX_FloatRect rcClient = rcWindow.GetDeflated(width, width);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
426 rcClient.right -= pVSB->GetScrollBarWidth();
427
428 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800429 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430}
431
Dan Sinclairf528eee2017-02-14 11:52:07 -0500432CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800433 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500434 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
435 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436}
437
tsepez4cf55152016-11-02 14:37:54 -0700438bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Tom Sepezbf157302017-09-15 13:26:32 -0700439 return (m_CreationParams.dwFlags & dwFlags) != 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440}
441
tsepezc3255f52016-03-25 14:52:27 -0700442void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Tom Sepezbf157302017-09-15 13:26:32 -0700443 m_CreationParams.dwFlags &= ~dwFlags;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444}
445
tsepezc3255f52016-03-25 14:52:27 -0700446void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Tom Sepezbf157302017-09-15 13:26:32 -0700447 m_CreationParams.dwFlags |= dwFlags;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448}
449
Dan Sinclair7f55a542017-07-13 14:17:10 -0400450CFX_Color CPWL_Wnd::GetBackgroundColor() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700451 return m_CreationParams.sBackgroundColor;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452}
453
Dan Sinclair7f55a542017-07-13 14:17:10 -0400454void CPWL_Wnd::SetBackgroundColor(const CFX_Color& color) {
Tom Sepezbf157302017-09-15 13:26:32 -0700455 m_CreationParams.sBackgroundColor = color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456}
457
Dan Sinclair7f55a542017-07-13 14:17:10 -0400458CFX_Color CPWL_Wnd::GetTextColor() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700459 return m_CreationParams.sTextColor;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460}
461
dsinclair92cb5e52016-05-16 11:38:28 -0700462BorderStyle CPWL_Wnd::GetBorderStyle() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700463 return m_CreationParams.nBorderStyle;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464}
465
dsinclair92cb5e52016-05-16 11:38:28 -0700466void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 if (HasFlag(PWS_BORDER))
Tom Sepezbf157302017-09-15 13:26:32 -0700468 m_CreationParams.nBorderStyle = nBorderStyle;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469}
470
471int32_t CPWL_Wnd::GetBorderWidth() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700472 return HasFlag(PWS_BORDER) ? m_CreationParams.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473}
474
475int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476 return 0;
477}
478
Dan Sinclair7f55a542017-07-13 14:17:10 -0400479CFX_Color CPWL_Wnd::GetBorderColor() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700480 return HasFlag(PWS_BORDER) ? m_CreationParams.sBorderColor : CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481}
482
Lei Zhang7457e382016-01-06 23:00:34 -0800483const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700484 return m_CreationParams.sDash;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485}
486
Tom Sepez134ac912017-09-15 15:32:01 -0700487CPWL_Wnd::PrivateData* CPWL_Wnd::GetAttachedData() const {
488 return m_CreationParams.pAttachedData.Get();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489}
490
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700491CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700492 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493}
494
Tom Sepezbf157302017-09-15 13:26:32 -0700495void CPWL_Wnd::CreateScrollBar(const CreateParams& cp) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 CreateVScrollBar(cp);
497}
498
Tom Sepezbf157302017-09-15 13:26:32 -0700499void CPWL_Wnd::CreateVScrollBar(const CreateParams& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700500 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
501 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502
Tom Sepezbf157302017-09-15 13:26:32 -0700503 CreateParams scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504
Lei Zhangfac46f82017-06-02 14:20:04 -0700505 // flags
506 scp.dwFlags =
507 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508
Lei Zhangfac46f82017-06-02 14:20:04 -0700509 scp.pParentWnd = this;
510 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
511 scp.eCursorType = FXCT_ARROW;
512 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
513
514 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
515 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516}
517
518void CPWL_Wnd::SetCapture() {
519 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
520 pMsgCtrl->SetCapture(this);
521}
522
523void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800524 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800525 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800527 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
529 pMsgCtrl->ReleaseCapture();
530}
531
532void CPWL_Wnd::SetFocus() {
533 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
534 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
535 pMsgCtrl->KillFocus();
536 pMsgCtrl->SetFocus(this);
537 }
538}
539
540void CPWL_Wnd::KillFocus() {
541 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
542 if (pMsgCtrl->IsWndCaptureKeyboard(this))
543 pMsgCtrl->KillFocus();
544 }
545}
546
547void CPWL_Wnd::OnSetFocus() {}
548
549void CPWL_Wnd::OnKillFocus() {}
550
Dan Sinclairf528eee2017-02-14 11:52:07 -0500551bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500552 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553}
554
Dan Sinclairf528eee2017-02-14 11:52:07 -0500555bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500556 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557}
558
559const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700560 auto* pParent = m_CreationParams.pParentWnd;
Lei Zhangfac46f82017-06-02 14:20:04 -0700561 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562}
563
tsepez4cf55152016-11-02 14:37:54 -0700564void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800565 if (!IsValid())
566 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567
Lei Zhang375c2762017-03-10 14:37:14 -0800568 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800569 if (pChild)
570 pChild->SetVisible(bVisible);
571 }
572 if (bVisible != m_bVisible) {
573 m_bVisible = bVisible;
574 RePosChildWnd();
Lei Zhang33c03002017-08-15 11:18:19 -0700575 InvalidateRect(nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700577}
578
Tom Sepez281a9ea2016-02-26 14:24:28 -0800579void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 m_rcClip = rect;
581 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700582}
583
Tom Sepez281a9ea2016-02-26 14:24:28 -0800584const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700586}
587
tsepez4cf55152016-11-02 14:37:54 -0700588bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700590}
591
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700593 CPWL_ScrollBar* pVSB = GetVScrollBar();
594 if (!pVSB)
595 return;
596
dan sinclairadf922f2017-07-12 21:56:27 -0400597 CFX_FloatRect rcContent = GetWindowRect();
598 if (!rcContent.IsEmpty()) {
599 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
600 rcContent.Deflate(width, width);
601 rcContent.Normalize();
602 }
Tom Sepez281a9ea2016-02-26 14:24:28 -0800603 CFX_FloatRect rcVScroll =
604 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
605 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700606 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607}
608
Tom Sepezbf157302017-09-15 13:26:32 -0700609void CPWL_Wnd::CreateChildWnd(const CreateParams& cp) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610
611void CPWL_Wnd::SetCursor() {
612 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700613 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Tom Sepezbf157302017-09-15 13:26:32 -0700614 int32_t nCursorType = GetCreationParams().eCursorType;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615 pSH->SetCursor(nCursorType);
616 }
617 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700618}
619
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620void CPWL_Wnd::CreateMsgControl() {
Tom Sepezbf157302017-09-15 13:26:32 -0700621 if (!m_CreationParams.pMsgControl)
622 m_CreationParams.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700623}
624
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700626 CPWL_MsgControl* pMsgControl = GetMsgControl();
627 if (pMsgControl && pMsgControl->IsWndCreated(this))
628 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629}
630
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700632 return m_CreationParams.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700633}
634
tsepez4cf55152016-11-02 14:37:54 -0700635bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700637}
638
tsepez4cf55152016-11-02 14:37:54 -0700639bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700640 CPWL_MsgControl* pCtrl = GetMsgControl();
641 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700642}
643
tsepez4cf55152016-11-02 14:37:54 -0700644bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700645 CPWL_MsgControl* pCtrl = GetMsgControl();
646 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700647}
648
tsepez4cf55152016-11-02 14:37:54 -0700649bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700650 CPWL_MsgControl* pCtrl = GetMsgControl();
651 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700652}
653
Tom Sepez281a9ea2016-02-26 14:24:28 -0800654CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
dan sinclairadf922f2017-07-12 21:56:27 -0400655 CFX_FloatRect rect = GetWindowRect();
656 if (!rect.IsEmpty()) {
657 rect.Inflate(1.0f, 1.0f);
658 rect.Normalize();
659 }
660 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700661}
662
Dan Sinclair05df0752017-03-14 14:43:42 -0400663float CPWL_Wnd::GetFontSize() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700664 return m_CreationParams.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700665}
666
Dan Sinclair05df0752017-03-14 14:43:42 -0400667void CPWL_Wnd::SetFontSize(float fFontSize) {
Tom Sepezbf157302017-09-15 13:26:32 -0700668 m_CreationParams.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700669}
670
dsinclairb9590102016-04-27 06:38:59 -0700671CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700672 return m_CreationParams.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700673}
674
Tom Sepez134ac912017-09-15 15:32:01 -0700675CPWL_Wnd::FocusHandlerIface* CPWL_Wnd::GetFocusHandler() const {
676 return m_CreationParams.pFocusHandler.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677}
678
Tom Sepez134ac912017-09-15 15:32:01 -0700679CPWL_Wnd::ProviderIface* CPWL_Wnd::GetProvider() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700680 return m_CreationParams.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681}
682
dsinclairc7a73492016-04-05 12:01:42 -0700683IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700684 return m_CreationParams.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685}
686
Dan Sinclair7f55a542017-07-13 14:17:10 -0400687CFX_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700689 case BorderStyle::BEVELED:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400690 return CFX_Color(COLORTYPE_GRAY, 1);
dsinclair92cb5e52016-05-16 11:38:28 -0700691 case BorderStyle::INSET:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400692 return CFX_Color(COLORTYPE_GRAY, 0.5f);
dsinclair92cb5e52016-05-16 11:38:28 -0700693 default:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400694 return CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700696}
697
Dan Sinclair7f55a542017-07-13 14:17:10 -0400698CFX_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700699 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700700 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500701 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700702 case BorderStyle::INSET:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400703 return CFX_Color(COLORTYPE_GRAY, 0.75f);
dsinclair92cb5e52016-05-16 11:38:28 -0700704 default:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400705 return CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700707}
708
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709int32_t CPWL_Wnd::GetTransparency() {
Tom Sepezbf157302017-09-15 13:26:32 -0700710 return m_CreationParams.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700711}
712
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800714 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800715 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717 }
Tom Sepezbf157302017-09-15 13:26:32 -0700718 m_CreationParams.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700719}
720
Tom Sepez60d909e2015-12-10 15:34:55 -0800721CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
722 CFX_Matrix mt = GetChildToRoot();
Tom Sepez134ac912017-09-15 15:32:01 -0700723 if (ProviderIface* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700726}
727
Lei Zhang77f9bff2017-08-29 11:34:12 -0700728CFX_FloatRect CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800729 CFX_Matrix mt = GetWindowMatrix();
Lei Zhang77f9bff2017-08-29 11:34:12 -0700730 return mt.TransformRect(rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700731}
732
Dan Sinclairf528eee2017-02-14 11:52:07 -0500733CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800734 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700735 if (mt.IsIdentity())
736 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700737
Nicolas Penab21f1742017-06-29 12:02:06 -0400738 CFX_Matrix inverse = mt.GetInverse();
739 if (!inverse.IsIdentity())
740 mt = inverse;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500741 return mt.Transform(point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700742}
743
Tom Sepez281a9ea2016-02-26 14:24:28 -0800744CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800745 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700746 if (mt.IsIdentity())
747 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700748
Nicolas Penab21f1742017-06-29 12:02:06 -0400749 CFX_Matrix inverse = mt.GetInverse();
750 if (!inverse.IsIdentity())
751 mt = inverse;
Jane Liu878b27d2017-08-22 10:50:06 -0400752
753 return mt.TransformRect(rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700754}
755
Tom Sepez60d909e2015-12-10 15:34:55 -0800756CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700757 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 if (HasFlag(PWS_CHILD)) {
759 const CPWL_Wnd* pParent = this;
760 while (pParent) {
761 mt.Concat(pParent->GetChildMatrix());
762 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700763 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700764 }
765 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766}
767
Tom Sepez60d909e2015-12-10 15:34:55 -0800768CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Tom Sepezbf157302017-09-15 13:26:32 -0700769 return HasFlag(PWS_CHILD) ? m_CreationParams.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700770}
771
Tom Sepez60d909e2015-12-10 15:34:55 -0800772void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Tom Sepezbf157302017-09-15 13:26:32 -0700773 m_CreationParams.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700774}
775
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700776const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800777 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700778 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700779}
780
tsepez4cf55152016-11-02 14:37:54 -0700781void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800782 if (m_bEnabled == bEnable)
783 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700784
Lei Zhang375c2762017-03-10 14:37:14 -0800785 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800786 if (pChild)
787 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700788 }
tsepez6745f962017-01-04 10:09:45 -0800789 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700790}