blob: e26df4d1998d569b2deeb1094f824dbb89880b12 [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
weili625ad662016-06-15 11:21:33 -070024PWL_CREATEPARAM::PWL_CREATEPARAM()
25 : 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
45PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default;
46
Ryan Harrison022d13b2017-09-15 14:35:41 -040047class CPWL_MsgControl : public CFX_Observable<CPWL_MsgControl> {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048 friend class CPWL_Wnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070049
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050 public:
Lei Zhangc2fb35f2016-01-05 16:46:58 -080051 explicit CPWL_MsgControl(CPWL_Wnd* pWnd) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052 m_pCreatedWnd = pWnd;
53 Default();
54 }
55
Dan Sinclairf766ad22016-03-14 13:51:24 -040056 ~CPWL_MsgControl() { Default(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057
58 void Default() {
tsepez0d164f82017-01-09 07:28:13 -080059 m_aMousePath.clear();
60 m_aKeyboardPath.clear();
thestig1cd352e2016-06-07 17:53:06 -070061 m_pMainMouseWnd = nullptr;
62 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063 }
64
tsepez4cf55152016-11-02 14:37:54 -070065 bool IsWndCreated(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 return m_pCreatedWnd == pWnd;
67 }
68
tsepez4cf55152016-11-02 14:37:54 -070069 bool IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070070 return pWnd == m_pMainMouseWnd;
71 }
72
tsepez4cf55152016-11-02 14:37:54 -070073 bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -080074 return pWnd && pdfium::ContainsValue(m_aMousePath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 }
76
tsepez4cf55152016-11-02 14:37:54 -070077 bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 return pWnd == m_pMainKeyboardWnd;
79 }
80
tsepez4cf55152016-11-02 14:37:54 -070081 bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -080082 return pWnd && pdfium::ContainsValue(m_aKeyboardPath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 }
84
85 void SetFocus(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -080086 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 if (pWnd) {
88 m_pMainKeyboardWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 CPWL_Wnd* pParent = pWnd;
90 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -080091 m_aKeyboardPath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 pParent = pParent->GetParentWindow();
93 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 pWnd->OnSetFocus();
Tom Sepez2f2ffec2015-07-23 14:42:09 -070095 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070097
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098 void KillFocus() {
Ryan Harrison022d13b2017-09-15 14:35:41 -040099 ObservedPtr observed_ptr = ObservedPtr(this);
tsepez0d164f82017-01-09 07:28:13 -0800100 if (!m_aKeyboardPath.empty())
101 if (CPWL_Wnd* pWnd = m_aKeyboardPath[0])
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 pWnd->OnKillFocus();
Ryan Harrison022d13b2017-09-15 14:35:41 -0400103 if (!observed_ptr)
104 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105
thestig1cd352e2016-06-07 17:53:06 -0700106 m_pMainKeyboardWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800107 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 }
109
110 void SetCapture(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -0800111 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 if (pWnd) {
113 m_pMainMouseWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114 CPWL_Wnd* pParent = pWnd;
115 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -0800116 m_aMousePath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 pParent = pParent->GetParentWindow();
118 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700119 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122 void ReleaseCapture() {
thestig1cd352e2016-06-07 17:53:06 -0700123 m_pMainMouseWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800124 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700126
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 private:
tsepez0d164f82017-01-09 07:28:13 -0800128 std::vector<CPWL_Wnd*> m_aMousePath;
129 std::vector<CPWL_Wnd*> m_aKeyboardPath;
Tom Sepezd0409af2017-05-25 15:53:57 -0700130 CFX_UnownedPtr<CPWL_Wnd> m_pCreatedWnd;
131 CFX_UnownedPtr<CPWL_Wnd> m_pMainMouseWnd;
132 CFX_UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700133};
134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135CPWL_Wnd::CPWL_Wnd()
Lei Zhangfac46f82017-06-02 14:20:04 -0700136 : m_rcWindow(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137 m_rcClip(),
tsepez4cf55152016-11-02 14:37:54 -0700138 m_bCreated(false),
139 m_bVisible(false),
140 m_bNotifying(false),
141 m_bEnabled(true) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700142
143CPWL_Wnd::~CPWL_Wnd() {
Lei Zhangb45324b2017-05-22 17:05:40 -0700144 ASSERT(!m_bCreated);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145}
146
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147CFX_ByteString CPWL_Wnd::GetClassName() const {
148 return "CPWL_Wnd";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700149}
150
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700152 if (IsValid())
153 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154
Lei Zhangfac46f82017-06-02 14:20:04 -0700155 m_sPrivateParam = cp;
156 OnCreate(m_sPrivateParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157
Lei Zhangfac46f82017-06-02 14:20:04 -0700158 m_sPrivateParam.rcRectWnd.Normalize();
159 m_rcWindow = m_sPrivateParam.rcRectWnd;
dan sinclairadf922f2017-07-12 21:56:27 -0400160 m_rcClip = m_rcWindow;
161 if (!m_rcClip.IsEmpty()) {
162 m_rcClip.Inflate(1.0f, 1.0f);
163 m_rcClip.Normalize();
164 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700165 CreateMsgControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166
Lei Zhangfac46f82017-06-02 14:20:04 -0700167 if (m_sPrivateParam.pParentWnd)
Dan Sinclaire5e889e2017-07-05 08:45:40 -0400168 m_sPrivateParam.pParentWnd->AddChild(this);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169
Lei Zhangfac46f82017-06-02 14:20:04 -0700170 PWL_CREATEPARAM ccp = m_sPrivateParam;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171
Lei Zhangfac46f82017-06-02 14:20:04 -0700172 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
173 CreateScrollBar(ccp);
174 CreateChildWnd(ccp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175
Lei Zhangfac46f82017-06-02 14:20:04 -0700176 m_bVisible = HasFlag(PWS_VISIBLE);
177 OnCreated();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178
Lei Zhangfac46f82017-06-02 14:20:04 -0700179 RePosChildWnd();
180 m_bCreated = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700181}
182
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185void CPWL_Wnd::OnCreated() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700186
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187void CPWL_Wnd::OnDestroy() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700188
Lei Zhangab5537d2016-01-06 14:58:14 -0800189void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) {
190 if (m_sPrivateParam.pFocusHandler == handler)
191 m_sPrivateParam.pFocusHandler = nullptr;
192}
193
194void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500195 if (m_sPrivateParam.pProvider.Get() == provider)
196 m_sPrivateParam.pProvider.Reset();
Lei Zhangab5537d2016-01-06 14:58:14 -0800197}
198
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199void CPWL_Wnd::Destroy() {
200 KillFocus();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201 OnDestroy();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 if (m_bCreated) {
Lei Zhang35162562017-06-09 01:04:52 -0700203 m_pVScrollBar = nullptr;
tsepez6745f962017-01-04 10:09:45 -0800204 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
205 if (CPWL_Wnd* pChild = *it) {
206 *it = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207 pChild->Destroy();
208 delete pChild;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209 }
210 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 if (m_sPrivateParam.pParentWnd)
Dan Sinclaire5e889e2017-07-05 08:45:40 -0400212 m_sPrivateParam.pParentWnd->RemoveChild(this);
tsepez6745f962017-01-04 10:09:45 -0800213
tsepez4cf55152016-11-02 14:37:54 -0700214 m_bCreated = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 DestroyMsgControl();
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500217 m_sPrivateParam.Reset();
tsepez6745f962017-01-04 10:09:45 -0800218 m_Children.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700220
tsepez4cf55152016-11-02 14:37:54 -0700221void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700222 if (!IsValid())
223 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700224
Lei Zhangfac46f82017-06-02 14:20:04 -0700225 CFX_FloatRect rcOld = GetWindowRect();
226 m_rcWindow = rcNew;
227 m_rcWindow.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228
Lei Zhangfac46f82017-06-02 14:20:04 -0700229 if (bReset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
231 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700232 RePosChildWnd();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700233 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700235 if (bRefresh)
236 InvalidateRectMove(rcOld, rcNew);
237
238 m_sPrivateParam.rcRectWnd = m_rcWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239}
240
Tom Sepez281a9ea2016-02-26 14:24:28 -0800241void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
242 const CFX_FloatRect& rcNew) {
243 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 InvalidateRect(&rcUnion);
247}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700248
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Lei Zhangeb14e042017-08-15 13:56:43 -0700250 const CFX_Matrix& mtUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 if (IsValid() && IsVisible()) {
Lei Zhangeb14e042017-08-15 13:56:43 -0700252 DrawThisAppearance(pDevice, mtUser2Device);
253 DrawChildAppearance(pDevice, mtUser2Device);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 }
255}
256
257void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Lei Zhangeb14e042017-08-15 13:56:43 -0700258 const CFX_Matrix& mtUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800259 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700260 if (rectWnd.IsEmpty())
261 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262
Lei Zhangfac46f82017-06-02 14:20:04 -0700263 if (HasFlag(PWS_BACKGROUND)) {
dan sinclaird6aff2f2017-07-13 21:36:29 -0400264 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
Lei Zhangeb14e042017-08-15 13:56:43 -0700265 pDevice->DrawFillRect(&mtUser2Device, rectWnd.GetDeflated(width, width),
Dan Sinclair0b7378a2017-07-17 12:05:40 -0400266 GetBackgroundColor(), GetTransparency());
Lei Zhangfac46f82017-06-02 14:20:04 -0700267 }
268
269 if (HasFlag(PWS_BORDER)) {
Lei Zhangeb14e042017-08-15 13:56:43 -0700270 pDevice->DrawBorder(&mtUser2Device, rectWnd,
Dan Sinclair0b7378a2017-07-17 12:05:40 -0400271 static_cast<float>(GetBorderWidth()), GetBorderColor(),
272 GetBorderLeftTopColor(GetBorderStyle()),
273 GetBorderRightBottomColor(GetBorderStyle()),
274 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700276}
277
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Lei Zhangeb14e042017-08-15 13:56:43 -0700279 const CFX_Matrix& mtUser2Device) {
tsepez6745f962017-01-04 10:09:45 -0800280 for (CPWL_Wnd* pChild : m_Children) {
281 if (!pChild)
282 continue;
283
284 CFX_Matrix mt = pChild->GetChildMatrix();
285 if (mt.IsIdentity()) {
Lei Zhangeb14e042017-08-15 13:56:43 -0700286 pChild->DrawAppearance(pDevice, mtUser2Device);
tsepez6745f962017-01-04 10:09:45 -0800287 } else {
Lei Zhangeb14e042017-08-15 13:56:43 -0700288 mt.Concat(mtUser2Device);
289 pChild->DrawAppearance(pDevice, mt);
Lei Zhang60f507b2015-06-13 00:41:00 -0700290 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700292}
293
Tom Sepez281a9ea2016-02-26 14:24:28 -0800294void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700295 if (!IsValid())
296 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297
Lei Zhangfac46f82017-06-02 14:20:04 -0700298 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
299
300 if (!HasFlag(PWS_NOREFRESHCLIP)) {
301 CFX_FloatRect rcClip = GetClipRect();
302 if (!rcClip.IsEmpty()) {
303 rcRefresh.Intersect(rcClip);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700304 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700305 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700306
Lei Zhang77f9bff2017-08-29 11:34:12 -0700307 CFX_FloatRect rcWin = PWLtoWnd(rcRefresh);
308 rcWin.Inflate(1, 1);
309 rcWin.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310
Lei Zhangfac46f82017-06-02 14:20:04 -0700311 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
312 if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>(
313 m_sPrivateParam.pAttachedWidget.Get())) {
314 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700315 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700317}
318
tsepez6745f962017-01-04 10:09:45 -0800319#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
320 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
321 if (!IsValid() || !IsVisible() || !IsEnabled()) \
322 return false; \
323 if (!IsWndCaptureKeyboard(this)) \
324 return false; \
Lei Zhang375c2762017-03-10 14:37:14 -0800325 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800326 if (pChild && IsWndCaptureKeyboard(pChild)) \
327 return pChild->key_method_name(nChar, nFlag); \
328 } \
329 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700330 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700331
332PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700333PWL_IMPLEMENT_KEY_METHOD(OnChar)
tsepez6745f962017-01-04 10:09:45 -0800334#undef PWL_IMPLEMENT_KEY_METHOD
335
336#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Dan Sinclairf528eee2017-02-14 11:52:07 -0500337 bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \
tsepez6745f962017-01-04 10:09:45 -0800338 if (!IsValid() || !IsVisible() || !IsEnabled()) \
339 return false; \
340 if (IsWndCaptureMouse(this)) { \
Lei Zhang375c2762017-03-10 14:37:14 -0800341 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800342 if (pChild && IsWndCaptureMouse(pChild)) { \
343 return pChild->mouse_method_name(pChild->ParentToChild(point), \
344 nFlag); \
345 } \
346 } \
347 SetCursor(); \
348 return false; \
349 } \
Lei Zhang375c2762017-03-10 14:37:14 -0800350 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800351 if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \
352 return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \
353 } \
354 } \
355 if (WndHitTest(point)) \
356 SetCursor(); \
357 return false; \
358 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700359
360PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
361PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
362PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700363PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
364PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
365PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
tsepez6745f962017-01-04 10:09:45 -0800366#undef PWL_IMPLEMENT_MOUSE_METHOD
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367
Diana Gagedce2d722017-06-20 11:17:11 -0700368CFX_WideString CPWL_Wnd::GetSelectedText() {
369 return CFX_WideString();
370}
371
Diana Gageab390972017-07-28 17:07:39 -0700372void CPWL_Wnd::ReplaceSelection(const CFX_WideString& text) {}
Diana Gage1c7f1422017-07-24 11:19:52 -0700373
tsepez4cf55152016-11-02 14:37:54 -0700374bool CPWL_Wnd::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500375 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700376 uint32_t nFlag) {
tsepez6745f962017-01-04 10:09:45 -0800377 if (!IsValid() || !IsVisible() || !IsEnabled())
378 return false;
379
380 SetCursor();
381 if (!IsWndCaptureKeyboard(this))
382 return false;
383
Lei Zhang375c2762017-03-10 14:37:14 -0800384 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800385 if (pChild && IsWndCaptureKeyboard(pChild))
386 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387 }
tsepez4cf55152016-11-02 14:37:54 -0700388 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389}
390
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800392 m_Children.push_back(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700393}
394
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800396 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
397 if (*it && *it == pWnd) {
398 m_Children.erase(std::next(it).base());
399 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700400 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700401 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700402}
403
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400404void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {}
405
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400406void CPWL_Wnd::SetScrollPosition(float pos) {}
407
Dan Sinclair63fbd8d2017-07-05 14:10:36 -0400408void CPWL_Wnd::ScrollWindowVertically(float pos) {}
409
Dan Sinclair7f6bec92017-07-05 14:13:16 -0400410void CPWL_Wnd::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {}
411
412void CPWL_Wnd::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {}
413
414void CPWL_Wnd::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) {}
415
tsepez4cf55152016-11-02 14:37:54 -0700416bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 return m_bCreated;
418}
419
Lei Zhang7457e382016-01-06 23:00:34 -0800420const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421 return m_sPrivateParam;
422}
423
424CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
425 return m_sPrivateParam.pParentWnd;
426}
427
Tom Sepez281a9ea2016-02-26 14:24:28 -0800428CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 return m_rcWindow;
430}
431
Tom Sepez281a9ea2016-02-26 14:24:28 -0800432CFX_FloatRect CPWL_Wnd::GetClientRect() const {
433 CFX_FloatRect rcWindow = GetWindowRect();
dan sinclairadf922f2017-07-12 21:56:27 -0400434
dan sinclaird6aff2f2017-07-13 21:36:29 -0400435 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
436 CFX_FloatRect rcClient = rcWindow.GetDeflated(width, width);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
438 rcClient.right -= pVSB->GetScrollBarWidth();
439
440 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800441 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442}
443
Dan Sinclairf528eee2017-02-14 11:52:07 -0500444CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800445 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500446 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
447 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448}
449
tsepez4cf55152016-11-02 14:37:54 -0700450bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
452}
453
tsepezc3255f52016-03-25 14:52:27 -0700454void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 m_sPrivateParam.dwFlags &= ~dwFlags;
456}
457
tsepezc3255f52016-03-25 14:52:27 -0700458void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459 m_sPrivateParam.dwFlags |= dwFlags;
460}
461
Dan Sinclair7f55a542017-07-13 14:17:10 -0400462CFX_Color CPWL_Wnd::GetBackgroundColor() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 return m_sPrivateParam.sBackgroundColor;
464}
465
Dan Sinclair7f55a542017-07-13 14:17:10 -0400466void CPWL_Wnd::SetBackgroundColor(const CFX_Color& color) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 m_sPrivateParam.sBackgroundColor = color;
468}
469
Dan Sinclair7f55a542017-07-13 14:17:10 -0400470CFX_Color CPWL_Wnd::GetTextColor() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 return m_sPrivateParam.sTextColor;
472}
473
dsinclair92cb5e52016-05-16 11:38:28 -0700474BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 return m_sPrivateParam.nBorderStyle;
476}
477
dsinclair92cb5e52016-05-16 11:38:28 -0700478void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 if (HasFlag(PWS_BORDER))
480 m_sPrivateParam.nBorderStyle = nBorderStyle;
481}
482
483int32_t CPWL_Wnd::GetBorderWidth() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700484 return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485}
486
487int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 return 0;
489}
490
Dan Sinclair7f55a542017-07-13 14:17:10 -0400491CFX_Color CPWL_Wnd::GetBorderColor() const {
492 return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493}
494
Lei Zhang7457e382016-01-06 23:00:34 -0800495const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 return m_sPrivateParam.sDash;
497}
498
499void* CPWL_Wnd::GetAttachedData() const {
500 return m_sPrivateParam.pAttachedData;
501}
502
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700504 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505}
506
507void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
508 CreateVScrollBar(cp);
509}
510
511void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700512 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
513 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514
Lei Zhangfac46f82017-06-02 14:20:04 -0700515 PWL_CREATEPARAM scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516
Lei Zhangfac46f82017-06-02 14:20:04 -0700517 // flags
518 scp.dwFlags =
519 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520
Lei Zhangfac46f82017-06-02 14:20:04 -0700521 scp.pParentWnd = this;
522 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
523 scp.eCursorType = FXCT_ARROW;
524 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
525
526 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
527 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528}
529
530void CPWL_Wnd::SetCapture() {
531 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
532 pMsgCtrl->SetCapture(this);
533}
534
535void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800536 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800537 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800539 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
541 pMsgCtrl->ReleaseCapture();
542}
543
544void CPWL_Wnd::SetFocus() {
545 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
546 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
547 pMsgCtrl->KillFocus();
548 pMsgCtrl->SetFocus(this);
549 }
550}
551
552void CPWL_Wnd::KillFocus() {
553 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
554 if (pMsgCtrl->IsWndCaptureKeyboard(this))
555 pMsgCtrl->KillFocus();
556 }
557}
558
559void CPWL_Wnd::OnSetFocus() {}
560
561void CPWL_Wnd::OnKillFocus() {}
562
Dan Sinclairf528eee2017-02-14 11:52:07 -0500563bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500564 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565}
566
Dan Sinclairf528eee2017-02-14 11:52:07 -0500567bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500568 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569}
570
571const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700572 auto* pParent = m_sPrivateParam.pParentWnd;
573 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574}
575
tsepez4cf55152016-11-02 14:37:54 -0700576void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800577 if (!IsValid())
578 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579
Lei Zhang375c2762017-03-10 14:37:14 -0800580 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800581 if (pChild)
582 pChild->SetVisible(bVisible);
583 }
584 if (bVisible != m_bVisible) {
585 m_bVisible = bVisible;
586 RePosChildWnd();
Lei Zhang33c03002017-08-15 11:18:19 -0700587 InvalidateRect(nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700589}
590
Tom Sepez281a9ea2016-02-26 14:24:28 -0800591void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592 m_rcClip = rect;
593 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700594}
595
Tom Sepez281a9ea2016-02-26 14:24:28 -0800596const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700598}
599
tsepez4cf55152016-11-02 14:37:54 -0700600bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700602}
603
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700605 CPWL_ScrollBar* pVSB = GetVScrollBar();
606 if (!pVSB)
607 return;
608
dan sinclairadf922f2017-07-12 21:56:27 -0400609 CFX_FloatRect rcContent = GetWindowRect();
610 if (!rcContent.IsEmpty()) {
611 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
612 rcContent.Deflate(width, width);
613 rcContent.Normalize();
614 }
Tom Sepez281a9ea2016-02-26 14:24:28 -0800615 CFX_FloatRect rcVScroll =
616 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
617 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700618 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700619}
620
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
622
623void CPWL_Wnd::SetCursor() {
624 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700625 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626 int32_t nCursorType = GetCreationParam().eCursorType;
627 pSH->SetCursor(nCursorType);
628 }
629 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700630}
631
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700632void CPWL_Wnd::CreateMsgControl() {
633 if (!m_sPrivateParam.pMsgControl)
634 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635}
636
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700637void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700638 CPWL_MsgControl* pMsgControl = GetMsgControl();
639 if (pMsgControl && pMsgControl->IsWndCreated(this))
640 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700641}
642
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
644 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645}
646
tsepez4cf55152016-11-02 14:37:54 -0700647bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700649}
650
tsepez4cf55152016-11-02 14:37:54 -0700651bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700652 CPWL_MsgControl* pCtrl = GetMsgControl();
653 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700654}
655
tsepez4cf55152016-11-02 14:37:54 -0700656bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700657 CPWL_MsgControl* pCtrl = GetMsgControl();
658 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700659}
660
tsepez4cf55152016-11-02 14:37:54 -0700661bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700662 CPWL_MsgControl* pCtrl = GetMsgControl();
663 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700664}
665
Tom Sepez281a9ea2016-02-26 14:24:28 -0800666CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
dan sinclairadf922f2017-07-12 21:56:27 -0400667 CFX_FloatRect rect = GetWindowRect();
668 if (!rect.IsEmpty()) {
669 rect.Inflate(1.0f, 1.0f);
670 rect.Normalize();
671 }
672 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700673}
674
Dan Sinclair05df0752017-03-14 14:43:42 -0400675float CPWL_Wnd::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677}
678
Dan Sinclair05df0752017-03-14 14:43:42 -0400679void CPWL_Wnd::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681}
682
dsinclairb9590102016-04-27 06:38:59 -0700683CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685}
686
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
688 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700689}
690
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691IPWL_Provider* CPWL_Wnd::GetProvider() const {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500692 return m_sPrivateParam.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693}
694
dsinclairc7a73492016-04-05 12:01:42 -0700695IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700697}
698
Dan Sinclair7f55a542017-07-13 14:17:10 -0400699CFX_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700701 case BorderStyle::BEVELED:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400702 return CFX_Color(COLORTYPE_GRAY, 1);
dsinclair92cb5e52016-05-16 11:38:28 -0700703 case BorderStyle::INSET:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400704 return CFX_Color(COLORTYPE_GRAY, 0.5f);
dsinclair92cb5e52016-05-16 11:38:28 -0700705 default:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400706 return CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700708}
709
Dan Sinclair7f55a542017-07-13 14:17:10 -0400710CFX_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700712 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500713 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700714 case BorderStyle::INSET:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400715 return CFX_Color(COLORTYPE_GRAY, 0.75f);
dsinclair92cb5e52016-05-16 11:38:28 -0700716 default:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400717 return CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700719}
720
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721int32_t CPWL_Wnd::GetTransparency() {
722 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700723}
724
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800726 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800727 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700731}
732
Tom Sepez60d909e2015-12-10 15:34:55 -0800733CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
734 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800735 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700738}
739
Lei Zhang77f9bff2017-08-29 11:34:12 -0700740CFX_FloatRect CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800741 CFX_Matrix mt = GetWindowMatrix();
Lei Zhang77f9bff2017-08-29 11:34:12 -0700742 return mt.TransformRect(rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700743}
744
Dan Sinclairf528eee2017-02-14 11:52:07 -0500745CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800746 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 if (mt.IsIdentity())
748 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700749
Nicolas Penab21f1742017-06-29 12:02:06 -0400750 CFX_Matrix inverse = mt.GetInverse();
751 if (!inverse.IsIdentity())
752 mt = inverse;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500753 return mt.Transform(point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700754}
755
Tom Sepez281a9ea2016-02-26 14:24:28 -0800756CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) 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 rect;
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;
Jane Liu878b27d2017-08-22 10:50:06 -0400764
765 return mt.TransformRect(rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766}
767
Tom Sepez60d909e2015-12-10 15:34:55 -0800768CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700769 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700770 if (HasFlag(PWS_CHILD)) {
771 const CPWL_Wnd* pParent = this;
772 while (pParent) {
773 mt.Concat(pParent->GetChildMatrix());
774 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700775 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700776 }
777 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700778}
779
Tom Sepez60d909e2015-12-10 15:34:55 -0800780CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700781 return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700782}
783
Tom Sepez60d909e2015-12-10 15:34:55 -0800784void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700786}
787
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700788const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800789 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700790 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700791}
792
tsepez4cf55152016-11-02 14:37:54 -0700793void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800794 if (m_bEnabled == bEnable)
795 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700796
Lei Zhang375c2762017-03-10 14:37:14 -0800797 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800798 if (pChild)
799 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800 }
tsepez6745f962017-01-04 10:09:45 -0800801 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700802}