blob: 53c692dada7f6bd0ae7a79e5a2c45dae985307f3 [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
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047class CPWL_MsgControl {
48 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() {
tsepez0d164f82017-01-09 07:28:13 -080099 if (!m_aKeyboardPath.empty())
100 if (CPWL_Wnd* pWnd = m_aKeyboardPath[0])
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 pWnd->OnKillFocus();
102
thestig1cd352e2016-06-07 17:53:06 -0700103 m_pMainKeyboardWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800104 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105 }
106
107 void SetCapture(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -0800108 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109 if (pWnd) {
110 m_pMainMouseWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111 CPWL_Wnd* pParent = pWnd;
112 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -0800113 m_aMousePath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114 pParent = pParent->GetParentWindow();
115 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700116 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700118
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119 void ReleaseCapture() {
thestig1cd352e2016-06-07 17:53:06 -0700120 m_pMainMouseWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800121 m_aMousePath.clear();
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 private:
tsepez0d164f82017-01-09 07:28:13 -0800125 std::vector<CPWL_Wnd*> m_aMousePath;
126 std::vector<CPWL_Wnd*> m_aKeyboardPath;
Tom Sepezd0409af2017-05-25 15:53:57 -0700127 CFX_UnownedPtr<CPWL_Wnd> m_pCreatedWnd;
128 CFX_UnownedPtr<CPWL_Wnd> m_pMainMouseWnd;
129 CFX_UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130};
131
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132CPWL_Wnd::CPWL_Wnd()
Lei Zhangfac46f82017-06-02 14:20:04 -0700133 : m_rcWindow(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134 m_rcClip(),
tsepez4cf55152016-11-02 14:37:54 -0700135 m_bCreated(false),
136 m_bVisible(false),
137 m_bNotifying(false),
138 m_bEnabled(true) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139
140CPWL_Wnd::~CPWL_Wnd() {
Lei Zhangb45324b2017-05-22 17:05:40 -0700141 ASSERT(!m_bCreated);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700142}
143
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144CFX_ByteString CPWL_Wnd::GetClassName() const {
145 return "CPWL_Wnd";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700146}
147
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700149 if (IsValid())
150 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151
Lei Zhangfac46f82017-06-02 14:20:04 -0700152 m_sPrivateParam = cp;
153 OnCreate(m_sPrivateParam);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154
Lei Zhangfac46f82017-06-02 14:20:04 -0700155 m_sPrivateParam.rcRectWnd.Normalize();
156 m_rcWindow = m_sPrivateParam.rcRectWnd;
dan sinclairadf922f2017-07-12 21:56:27 -0400157 m_rcClip = m_rcWindow;
158 if (!m_rcClip.IsEmpty()) {
159 m_rcClip.Inflate(1.0f, 1.0f);
160 m_rcClip.Normalize();
161 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700162 CreateMsgControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163
Lei Zhangfac46f82017-06-02 14:20:04 -0700164 if (m_sPrivateParam.pParentWnd)
Dan Sinclaire5e889e2017-07-05 08:45:40 -0400165 m_sPrivateParam.pParentWnd->AddChild(this);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166
Lei Zhangfac46f82017-06-02 14:20:04 -0700167 PWL_CREATEPARAM ccp = m_sPrivateParam;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168
Lei Zhangfac46f82017-06-02 14:20:04 -0700169 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
170 CreateScrollBar(ccp);
171 CreateChildWnd(ccp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172
Lei Zhangfac46f82017-06-02 14:20:04 -0700173 m_bVisible = HasFlag(PWS_VISIBLE);
174 OnCreated();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175
Lei Zhangfac46f82017-06-02 14:20:04 -0700176 RePosChildWnd();
177 m_bCreated = true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178}
179
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
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
Lei Zhangab5537d2016-01-06 14:58:14 -0800186void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) {
187 if (m_sPrivateParam.pFocusHandler == handler)
188 m_sPrivateParam.pFocusHandler = nullptr;
189}
190
191void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500192 if (m_sPrivateParam.pProvider.Get() == provider)
193 m_sPrivateParam.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 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 if (m_sPrivateParam.pParentWnd)
Dan Sinclaire5e889e2017-07-05 08:45:40 -0400209 m_sPrivateParam.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();
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500214 m_sPrivateParam.Reset();
tsepez6745f962017-01-04 10:09:45 -0800215 m_Children.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700217
tsepez4cf55152016-11-02 14:37:54 -0700218void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700219 if (!IsValid())
220 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700221
Lei Zhangfac46f82017-06-02 14:20:04 -0700222 CFX_FloatRect rcOld = GetWindowRect();
223 m_rcWindow = rcNew;
224 m_rcWindow.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225
Lei Zhangfac46f82017-06-02 14:20:04 -0700226 if (bReset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
228 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700229 RePosChildWnd();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700230 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700232 if (bRefresh)
233 InvalidateRectMove(rcOld, rcNew);
234
235 m_sPrivateParam.rcRectWnd = m_rcWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700236}
237
Tom Sepez281a9ea2016-02-26 14:24:28 -0800238void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
239 const CFX_FloatRect& rcNew) {
240 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700241 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700242
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 InvalidateRect(&rcUnion);
244}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Lei Zhangeb14e042017-08-15 13:56:43 -0700247 const CFX_Matrix& mtUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 if (IsValid() && IsVisible()) {
Lei Zhangeb14e042017-08-15 13:56:43 -0700249 DrawThisAppearance(pDevice, mtUser2Device);
250 DrawChildAppearance(pDevice, mtUser2Device);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 }
252}
253
254void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Lei Zhangeb14e042017-08-15 13:56:43 -0700255 const CFX_Matrix& mtUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800256 CFX_FloatRect rectWnd = GetWindowRect();
Lei Zhangfac46f82017-06-02 14:20:04 -0700257 if (rectWnd.IsEmpty())
258 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259
Lei Zhangfac46f82017-06-02 14:20:04 -0700260 if (HasFlag(PWS_BACKGROUND)) {
dan sinclaird6aff2f2017-07-13 21:36:29 -0400261 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
Lei Zhangeb14e042017-08-15 13:56:43 -0700262 pDevice->DrawFillRect(&mtUser2Device, rectWnd.GetDeflated(width, width),
Dan Sinclair0b7378a2017-07-17 12:05:40 -0400263 GetBackgroundColor(), GetTransparency());
Lei Zhangfac46f82017-06-02 14:20:04 -0700264 }
265
266 if (HasFlag(PWS_BORDER)) {
Lei Zhangeb14e042017-08-15 13:56:43 -0700267 pDevice->DrawBorder(&mtUser2Device, rectWnd,
Dan Sinclair0b7378a2017-07-17 12:05:40 -0400268 static_cast<float>(GetBorderWidth()), GetBorderColor(),
269 GetBorderLeftTopColor(GetBorderStyle()),
270 GetBorderRightBottomColor(GetBorderStyle()),
271 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700273}
274
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Lei Zhangeb14e042017-08-15 13:56:43 -0700276 const CFX_Matrix& mtUser2Device) {
tsepez6745f962017-01-04 10:09:45 -0800277 for (CPWL_Wnd* pChild : m_Children) {
278 if (!pChild)
279 continue;
280
281 CFX_Matrix mt = pChild->GetChildMatrix();
282 if (mt.IsIdentity()) {
Lei Zhangeb14e042017-08-15 13:56:43 -0700283 pChild->DrawAppearance(pDevice, mtUser2Device);
tsepez6745f962017-01-04 10:09:45 -0800284 } else {
Lei Zhangeb14e042017-08-15 13:56:43 -0700285 mt.Concat(mtUser2Device);
286 pChild->DrawAppearance(pDevice, mt);
Lei Zhang60f507b2015-06-13 00:41:00 -0700287 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700289}
290
Tom Sepez281a9ea2016-02-26 14:24:28 -0800291void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700292 if (!IsValid())
293 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294
Lei Zhangfac46f82017-06-02 14:20:04 -0700295 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
296
297 if (!HasFlag(PWS_NOREFRESHCLIP)) {
298 CFX_FloatRect rcClip = GetClipRect();
299 if (!rcClip.IsEmpty()) {
300 rcRefresh.Intersect(rcClip);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700301 }
Lei Zhangfac46f82017-06-02 14:20:04 -0700302 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700303
Lei Zhang77f9bff2017-08-29 11:34:12 -0700304 CFX_FloatRect rcWin = PWLtoWnd(rcRefresh);
305 rcWin.Inflate(1, 1);
306 rcWin.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307
Lei Zhangfac46f82017-06-02 14:20:04 -0700308 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
309 if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>(
310 m_sPrivateParam.pAttachedWidget.Get())) {
311 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700312 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700314}
315
tsepez6745f962017-01-04 10:09:45 -0800316#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
317 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
318 if (!IsValid() || !IsVisible() || !IsEnabled()) \
319 return false; \
320 if (!IsWndCaptureKeyboard(this)) \
321 return false; \
Lei Zhang375c2762017-03-10 14:37:14 -0800322 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800323 if (pChild && IsWndCaptureKeyboard(pChild)) \
324 return pChild->key_method_name(nChar, nFlag); \
325 } \
326 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700328
329PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700330PWL_IMPLEMENT_KEY_METHOD(OnChar)
tsepez6745f962017-01-04 10:09:45 -0800331#undef PWL_IMPLEMENT_KEY_METHOD
332
333#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Dan Sinclairf528eee2017-02-14 11:52:07 -0500334 bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \
tsepez6745f962017-01-04 10:09:45 -0800335 if (!IsValid() || !IsVisible() || !IsEnabled()) \
336 return false; \
337 if (IsWndCaptureMouse(this)) { \
Lei Zhang375c2762017-03-10 14:37:14 -0800338 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800339 if (pChild && IsWndCaptureMouse(pChild)) { \
340 return pChild->mouse_method_name(pChild->ParentToChild(point), \
341 nFlag); \
342 } \
343 } \
344 SetCursor(); \
345 return false; \
346 } \
Lei Zhang375c2762017-03-10 14:37:14 -0800347 for (auto* pChild : m_Children) { \
tsepez6745f962017-01-04 10:09:45 -0800348 if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \
349 return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \
350 } \
351 } \
352 if (WndHitTest(point)) \
353 SetCursor(); \
354 return false; \
355 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700356
357PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
358PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
359PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700360PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
361PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
362PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
tsepez6745f962017-01-04 10:09:45 -0800363#undef PWL_IMPLEMENT_MOUSE_METHOD
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700364
Diana Gagedce2d722017-06-20 11:17:11 -0700365CFX_WideString CPWL_Wnd::GetSelectedText() {
366 return CFX_WideString();
367}
368
Diana Gageab390972017-07-28 17:07:39 -0700369void CPWL_Wnd::ReplaceSelection(const CFX_WideString& text) {}
Diana Gage1c7f1422017-07-24 11:19:52 -0700370
tsepez4cf55152016-11-02 14:37:54 -0700371bool CPWL_Wnd::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500372 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700373 uint32_t nFlag) {
tsepez6745f962017-01-04 10:09:45 -0800374 if (!IsValid() || !IsVisible() || !IsEnabled())
375 return false;
376
377 SetCursor();
378 if (!IsWndCaptureKeyboard(this))
379 return false;
380
Lei Zhang375c2762017-03-10 14:37:14 -0800381 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800382 if (pChild && IsWndCaptureKeyboard(pChild))
383 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384 }
tsepez4cf55152016-11-02 14:37:54 -0700385 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700386}
387
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800389 m_Children.push_back(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700390}
391
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800393 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
394 if (*it && *it == pWnd) {
395 m_Children.erase(std::next(it).base());
396 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700397 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700399}
400
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400401void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {}
402
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400403void CPWL_Wnd::SetScrollPosition(float pos) {}
404
Dan Sinclair63fbd8d2017-07-05 14:10:36 -0400405void CPWL_Wnd::ScrollWindowVertically(float pos) {}
406
Dan Sinclair7f6bec92017-07-05 14:13:16 -0400407void CPWL_Wnd::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {}
408
409void CPWL_Wnd::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {}
410
411void CPWL_Wnd::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) {}
412
tsepez4cf55152016-11-02 14:37:54 -0700413bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414 return m_bCreated;
415}
416
Lei Zhang7457e382016-01-06 23:00:34 -0800417const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418 return m_sPrivateParam;
419}
420
421CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
422 return m_sPrivateParam.pParentWnd;
423}
424
Tom Sepez281a9ea2016-02-26 14:24:28 -0800425CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426 return m_rcWindow;
427}
428
Tom Sepez281a9ea2016-02-26 14:24:28 -0800429CFX_FloatRect CPWL_Wnd::GetClientRect() const {
430 CFX_FloatRect rcWindow = GetWindowRect();
dan sinclairadf922f2017-07-12 21:56:27 -0400431
dan sinclaird6aff2f2017-07-13 21:36:29 -0400432 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
433 CFX_FloatRect rcClient = rcWindow.GetDeflated(width, width);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
435 rcClient.right -= pVSB->GetScrollBarWidth();
436
437 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800438 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439}
440
Dan Sinclairf528eee2017-02-14 11:52:07 -0500441CFX_PointF CPWL_Wnd::GetCenterPoint() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800442 CFX_FloatRect rcClient = GetClientRect();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500443 return CFX_PointF((rcClient.left + rcClient.right) * 0.5f,
444 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445}
446
tsepez4cf55152016-11-02 14:37:54 -0700447bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
449}
450
tsepezc3255f52016-03-25 14:52:27 -0700451void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452 m_sPrivateParam.dwFlags &= ~dwFlags;
453}
454
tsepezc3255f52016-03-25 14:52:27 -0700455void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 m_sPrivateParam.dwFlags |= dwFlags;
457}
458
Dan Sinclair7f55a542017-07-13 14:17:10 -0400459CFX_Color CPWL_Wnd::GetBackgroundColor() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 return m_sPrivateParam.sBackgroundColor;
461}
462
Dan Sinclair7f55a542017-07-13 14:17:10 -0400463void CPWL_Wnd::SetBackgroundColor(const CFX_Color& color) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464 m_sPrivateParam.sBackgroundColor = color;
465}
466
Dan Sinclair7f55a542017-07-13 14:17:10 -0400467CFX_Color CPWL_Wnd::GetTextColor() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 return m_sPrivateParam.sTextColor;
469}
470
dsinclair92cb5e52016-05-16 11:38:28 -0700471BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472 return m_sPrivateParam.nBorderStyle;
473}
474
dsinclair92cb5e52016-05-16 11:38:28 -0700475void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476 if (HasFlag(PWS_BORDER))
477 m_sPrivateParam.nBorderStyle = nBorderStyle;
478}
479
480int32_t CPWL_Wnd::GetBorderWidth() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700481 return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482}
483
484int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 return 0;
486}
487
Dan Sinclair7f55a542017-07-13 14:17:10 -0400488CFX_Color CPWL_Wnd::GetBorderColor() const {
489 return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490}
491
Lei Zhang7457e382016-01-06 23:00:34 -0800492const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 return m_sPrivateParam.sDash;
494}
495
496void* CPWL_Wnd::GetAttachedData() const {
497 return m_sPrivateParam.pAttachedData;
498}
499
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
Tom Sepezd0409af2017-05-25 15:53:57 -0700501 return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502}
503
504void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
505 CreateVScrollBar(cp);
506}
507
508void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
Lei Zhangfac46f82017-06-02 14:20:04 -0700509 if (m_pVScrollBar || !HasFlag(PWS_VSCROLL))
510 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511
Lei Zhangfac46f82017-06-02 14:20:04 -0700512 PWL_CREATEPARAM scp = cp;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513
Lei Zhangfac46f82017-06-02 14:20:04 -0700514 // flags
515 scp.dwFlags =
516 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517
Lei Zhangfac46f82017-06-02 14:20:04 -0700518 scp.pParentWnd = this;
519 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
520 scp.eCursorType = FXCT_ARROW;
521 scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY;
522
523 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
524 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525}
526
527void CPWL_Wnd::SetCapture() {
528 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
529 pMsgCtrl->SetCapture(this);
530}
531
532void CPWL_Wnd::ReleaseCapture() {
Lei Zhang375c2762017-03-10 14:37:14 -0800533 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800534 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800536 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
538 pMsgCtrl->ReleaseCapture();
539}
540
541void CPWL_Wnd::SetFocus() {
542 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
543 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
544 pMsgCtrl->KillFocus();
545 pMsgCtrl->SetFocus(this);
546 }
547}
548
549void CPWL_Wnd::KillFocus() {
550 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
551 if (pMsgCtrl->IsWndCaptureKeyboard(this))
552 pMsgCtrl->KillFocus();
553 }
554}
555
556void CPWL_Wnd::OnSetFocus() {}
557
558void CPWL_Wnd::OnKillFocus() {}
559
Dan Sinclairf528eee2017-02-14 11:52:07 -0500560bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500561 return IsValid() && IsVisible() && GetWindowRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562}
563
Dan Sinclairf528eee2017-02-14 11:52:07 -0500564bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const {
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500565 return IsValid() && IsVisible() && GetClientRect().Contains(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566}
567
568const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700569 auto* pParent = m_sPrivateParam.pParentWnd;
570 return pParent ? pParent->GetRootWnd() : this;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571}
572
tsepez4cf55152016-11-02 14:37:54 -0700573void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800574 if (!IsValid())
575 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576
Lei Zhang375c2762017-03-10 14:37:14 -0800577 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800578 if (pChild)
579 pChild->SetVisible(bVisible);
580 }
581 if (bVisible != m_bVisible) {
582 m_bVisible = bVisible;
583 RePosChildWnd();
Lei Zhang33c03002017-08-15 11:18:19 -0700584 InvalidateRect(nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700586}
587
Tom Sepez281a9ea2016-02-26 14:24:28 -0800588void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 m_rcClip = rect;
590 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700591}
592
Tom Sepez281a9ea2016-02-26 14:24:28 -0800593const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700595}
596
tsepez4cf55152016-11-02 14:37:54 -0700597bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700599}
600
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601void CPWL_Wnd::RePosChildWnd() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700602 CPWL_ScrollBar* pVSB = GetVScrollBar();
603 if (!pVSB)
604 return;
605
dan sinclairadf922f2017-07-12 21:56:27 -0400606 CFX_FloatRect rcContent = GetWindowRect();
607 if (!rcContent.IsEmpty()) {
608 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
609 rcContent.Deflate(width, width);
610 rcContent.Normalize();
611 }
Tom Sepez281a9ea2016-02-26 14:24:28 -0800612 CFX_FloatRect rcVScroll =
613 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
614 rcContent.right - 1.0f, rcContent.top);
Lei Zhangfac46f82017-06-02 14:20:04 -0700615 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700616}
617
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
619
620void CPWL_Wnd::SetCursor() {
621 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700622 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 int32_t nCursorType = GetCreationParam().eCursorType;
624 pSH->SetCursor(nCursorType);
625 }
626 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700627}
628
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629void CPWL_Wnd::CreateMsgControl() {
630 if (!m_sPrivateParam.pMsgControl)
631 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632}
633
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634void CPWL_Wnd::DestroyMsgControl() {
Lei Zhangfac46f82017-06-02 14:20:04 -0700635 CPWL_MsgControl* pMsgControl = GetMsgControl();
636 if (pMsgControl && pMsgControl->IsWndCreated(this))
637 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700638}
639
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
641 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700642}
643
tsepez4cf55152016-11-02 14:37:54 -0700644bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700646}
647
tsepez4cf55152016-11-02 14:37:54 -0700648bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700649 CPWL_MsgControl* pCtrl = GetMsgControl();
650 return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700651}
652
tsepez4cf55152016-11-02 14:37:54 -0700653bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700654 CPWL_MsgControl* pCtrl = GetMsgControl();
655 return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700656}
657
tsepez4cf55152016-11-02 14:37:54 -0700658bool CPWL_Wnd::IsFocused() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700659 CPWL_MsgControl* pCtrl = GetMsgControl();
660 return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700661}
662
Tom Sepez281a9ea2016-02-26 14:24:28 -0800663CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
dan sinclairadf922f2017-07-12 21:56:27 -0400664 CFX_FloatRect rect = GetWindowRect();
665 if (!rect.IsEmpty()) {
666 rect.Inflate(1.0f, 1.0f);
667 rect.Normalize();
668 }
669 return rect;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700670}
671
Dan Sinclair05df0752017-03-14 14:43:42 -0400672float CPWL_Wnd::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700674}
675
Dan Sinclair05df0752017-03-14 14:43:42 -0400676void CPWL_Wnd::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700677 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700678}
679
dsinclairb9590102016-04-27 06:38:59 -0700680CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700682}
683
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
685 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700686}
687
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688IPWL_Provider* CPWL_Wnd::GetProvider() const {
Dan Sinclairbc8dcc32017-01-19 13:53:02 -0500689 return m_sPrivateParam.pProvider.Get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700690}
691
dsinclairc7a73492016-04-05 12:01:42 -0700692IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700694}
695
Dan Sinclair7f55a542017-07-13 14:17:10 -0400696CFX_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700698 case BorderStyle::BEVELED:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400699 return CFX_Color(COLORTYPE_GRAY, 1);
dsinclair92cb5e52016-05-16 11:38:28 -0700700 case BorderStyle::INSET:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400701 return CFX_Color(COLORTYPE_GRAY, 0.5f);
dsinclair92cb5e52016-05-16 11:38:28 -0700702 default:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400703 return CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705}
706
Dan Sinclair7f55a542017-07-13 14:17:10 -0400707CFX_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700708 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700709 case BorderStyle::BEVELED:
Dan Sinclairfc54e052017-02-23 09:59:05 -0500710 return GetBackgroundColor() / 2.0f;
dsinclair92cb5e52016-05-16 11:38:28 -0700711 case BorderStyle::INSET:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400712 return CFX_Color(COLORTYPE_GRAY, 0.75f);
dsinclair92cb5e52016-05-16 11:38:28 -0700713 default:
Dan Sinclair7f55a542017-07-13 14:17:10 -0400714 return CFX_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700716}
717
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718int32_t CPWL_Wnd::GetTransparency() {
719 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700720}
721
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
Lei Zhang375c2762017-03-10 14:37:14 -0800723 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800724 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700726 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700728}
729
Tom Sepez60d909e2015-12-10 15:34:55 -0800730CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
731 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800732 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700733 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700735}
736
Lei Zhang77f9bff2017-08-29 11:34:12 -0700737CFX_FloatRect CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800738 CFX_Matrix mt = GetWindowMatrix();
Lei Zhang77f9bff2017-08-29 11:34:12 -0700739 return mt.TransformRect(rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700740}
741
Dan Sinclairf528eee2017-02-14 11:52:07 -0500742CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800743 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700744 if (mt.IsIdentity())
745 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700746
Nicolas Penab21f1742017-06-29 12:02:06 -0400747 CFX_Matrix inverse = mt.GetInverse();
748 if (!inverse.IsIdentity())
749 mt = inverse;
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500750 return mt.Transform(point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751}
752
Tom Sepez281a9ea2016-02-26 14:24:28 -0800753CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800754 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700755 if (mt.IsIdentity())
756 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700757
Nicolas Penab21f1742017-06-29 12:02:06 -0400758 CFX_Matrix inverse = mt.GetInverse();
759 if (!inverse.IsIdentity())
760 mt = inverse;
Jane Liu878b27d2017-08-22 10:50:06 -0400761
762 return mt.TransformRect(rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700763}
764
Tom Sepez60d909e2015-12-10 15:34:55 -0800765CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700766 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700767 if (HasFlag(PWS_CHILD)) {
768 const CPWL_Wnd* pParent = this;
769 while (pParent) {
770 mt.Concat(pParent->GetChildMatrix());
771 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700772 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700773 }
774 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700775}
776
Tom Sepez60d909e2015-12-10 15:34:55 -0800777CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Lei Zhangfac46f82017-06-02 14:20:04 -0700778 return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700779}
780
Tom Sepez60d909e2015-12-10 15:34:55 -0800781void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700782 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700783}
784
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800786 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
Tom Sepezd0409af2017-05-25 15:53:57 -0700787 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700788}
789
tsepez4cf55152016-11-02 14:37:54 -0700790void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800791 if (m_bEnabled == bEnable)
792 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700793
Lei Zhang375c2762017-03-10 14:37:14 -0800794 for (auto* pChild : m_Children) {
tsepez6745f962017-01-04 10:09:45 -0800795 if (pChild)
796 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700797 }
tsepez6745f962017-01-04 10:09:45 -0800798 m_bEnabled = bEnable;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700799}