blob: 4a479de0dc18ff9a8aa3cb0e8ec9765b90c6d4d5 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhang60f507b2015-06-13 00:41:00 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhang606346f2015-06-19 18:11:07 -07007#include <map>
8
dan sinclair89e904b2016-03-23 19:29:15 -04009#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
10#include "fpdfsdk/pdfwindow/PWL_Utils.h"
11#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012
Nico Weber9d8ec5a2015-08-04 13:00:21 -070013static std::map<int32_t, CPWL_Timer*>& GetPWLTimeMap() {
Bruce Dawson26d96ff2015-01-05 15:31:49 -080014 // Leak the object at shutdown.
Lei Zhang606346f2015-06-19 18:11:07 -070015 static auto timeMap = new std::map<int32_t, CPWL_Timer*>;
Bruce Dawson26d96ff2015-01-05 15:31:49 -080016 return *timeMap;
17}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018
weili625ad662016-06-15 11:21:33 -070019PWL_CREATEPARAM::PWL_CREATEPARAM()
20 : rcRectWnd(0, 0, 0, 0),
21 pSystemHandler(nullptr),
22 pFontMap(nullptr),
23 pProvider(nullptr),
24 pFocusHandler(nullptr),
25 dwFlags(0),
26 sBackgroundColor(),
27 hAttachedWnd(nullptr),
28 nBorderStyle(BorderStyle::SOLID),
29 dwBorderWidth(1),
30 sBorderColor(),
31 sTextColor(),
32 sTextStrokeColor(),
33 nTransparency(255),
34 fFontSize(PWL_DEFAULT_FONTSIZE),
35 sDash(3, 0, 0),
36 pAttachedData(nullptr),
37 pParentWnd(nullptr),
38 pMsgControl(nullptr),
39 eCursorType(FXCT_ARROW),
40 mtChild(1, 0, 0, 1, 0, 0) {}
41
42PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default;
43
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached,
dsinclairb9590102016-04-27 06:38:59 -070045 CFX_SystemHandler* pSystemHandler)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046 : m_nTimerID(0), m_pAttached(pAttached), m_pSystemHandler(pSystemHandler) {
Lei Zhang96660d62015-12-14 18:27:25 -080047 ASSERT(m_pAttached);
48 ASSERT(m_pSystemHandler);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070049}
50
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051CPWL_Timer::~CPWL_Timer() {
52 KillPWLTimer();
53}
54
55int32_t CPWL_Timer::SetPWLTimer(int32_t nElapse) {
56 if (m_nTimerID != 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -070057 KillPWLTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058 m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc);
59
60 GetPWLTimeMap()[m_nTimerID] = this;
61 return m_nTimerID;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062}
63
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064void CPWL_Timer::KillPWLTimer() {
65 if (m_nTimerID == 0)
66 return;
Lei Zhang606346f2015-06-19 18:11:07 -070067
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 m_pSystemHandler->KillTimer(m_nTimerID);
69 GetPWLTimeMap().erase(m_nTimerID);
70 m_nTimerID = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071}
72
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073void CPWL_Timer::TimerProc(int32_t idEvent) {
74 auto it = GetPWLTimeMap().find(idEvent);
75 if (it == GetPWLTimeMap().end())
76 return;
Lei Zhang606346f2015-06-19 18:11:07 -070077
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 CPWL_Timer* pTimer = it->second;
79 if (pTimer->m_pAttached)
80 pTimer->m_pAttached->TimerProc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081}
82
weili2d5b0202016-08-03 11:06:49 -070083CPWL_TimerHandler::CPWL_TimerHandler() {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084
weili2d5b0202016-08-03 11:06:49 -070085CPWL_TimerHandler::~CPWL_TimerHandler() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087void CPWL_TimerHandler::BeginTimer(int32_t nElapse) {
88 if (!m_pTimer)
weili2d5b0202016-08-03 11:06:49 -070089 m_pTimer.reset(new CPWL_Timer(this, GetSystemHandler()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090
91 if (m_pTimer)
92 m_pTimer->SetPWLTimer(nElapse);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070093}
94
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095void CPWL_TimerHandler::EndTimer() {
96 if (m_pTimer)
97 m_pTimer->KillPWLTimer();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070098}
99
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100void CPWL_TimerHandler::TimerProc() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102class CPWL_MsgControl {
103 friend class CPWL_Wnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700104
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105 public:
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800106 explicit CPWL_MsgControl(CPWL_Wnd* pWnd) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 m_pCreatedWnd = pWnd;
108 Default();
109 }
110
Dan Sinclairf766ad22016-03-14 13:51:24 -0400111 ~CPWL_MsgControl() { Default(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112
113 void Default() {
114 m_aMousePath.RemoveAll();
115 m_aKeyboardPath.RemoveAll();
thestig1cd352e2016-06-07 17:53:06 -0700116 m_pMainMouseWnd = nullptr;
117 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118 }
119
120 FX_BOOL IsWndCreated(const CPWL_Wnd* pWnd) const {
121 return m_pCreatedWnd == pWnd;
122 }
123
124 FX_BOOL IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
125 return pWnd == m_pMainMouseWnd;
126 }
127
128 FX_BOOL IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800129 if (pWnd) {
130 for (int32_t i = 0, sz = m_aMousePath.GetSize(); i < sz; i++) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 if (m_aMousePath.GetAt(i) == pWnd)
132 return TRUE;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800133 }
134 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135
136 return FALSE;
137 }
138
139 FX_BOOL IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
140 return pWnd == m_pMainKeyboardWnd;
141 }
142
143 FX_BOOL IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800144 if (pWnd) {
145 for (int32_t i = 0, sz = m_aKeyboardPath.GetSize(); i < sz; i++) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 if (m_aKeyboardPath.GetAt(i) == pWnd)
147 return TRUE;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800148 }
149 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150
151 return FALSE;
152 }
153
154 void SetFocus(CPWL_Wnd* pWnd) {
155 m_aKeyboardPath.RemoveAll();
156
157 if (pWnd) {
158 m_pMainKeyboardWnd = pWnd;
159
160 CPWL_Wnd* pParent = pWnd;
161 while (pParent) {
162 m_aKeyboardPath.Add(pParent);
163 pParent = pParent->GetParentWindow();
164 }
165
166 pWnd->OnSetFocus();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700167 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700169
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 void KillFocus() {
171 if (m_aKeyboardPath.GetSize() > 0)
172 if (CPWL_Wnd* pWnd = m_aKeyboardPath.GetAt(0))
173 pWnd->OnKillFocus();
174
thestig1cd352e2016-06-07 17:53:06 -0700175 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 m_aKeyboardPath.RemoveAll();
177 }
178
179 void SetCapture(CPWL_Wnd* pWnd) {
180 m_aMousePath.RemoveAll();
181
182 if (pWnd) {
183 m_pMainMouseWnd = pWnd;
184
185 CPWL_Wnd* pParent = pWnd;
186 while (pParent) {
187 m_aMousePath.Add(pParent);
188 pParent = pParent->GetParentWindow();
189 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700190 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700192
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193 void ReleaseCapture() {
thestig1cd352e2016-06-07 17:53:06 -0700194 m_pMainMouseWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 m_aMousePath.RemoveAll();
196 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700197
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 private:
199 CFX_ArrayTemplate<CPWL_Wnd*> m_aMousePath;
200 CFX_ArrayTemplate<CPWL_Wnd*> m_aKeyboardPath;
201 CPWL_Wnd* m_pCreatedWnd;
202 CPWL_Wnd* m_pMainMouseWnd;
203 CPWL_Wnd* m_pMainKeyboardWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700204};
205
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206CPWL_Wnd::CPWL_Wnd()
thestig1cd352e2016-06-07 17:53:06 -0700207 : m_pVScrollBar(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 m_rcWindow(),
209 m_rcClip(),
210 m_bCreated(FALSE),
211 m_bVisible(FALSE),
212 m_bNotifying(FALSE),
213 m_bEnabled(TRUE) {}
214
215CPWL_Wnd::~CPWL_Wnd() {
216 ASSERT(m_bCreated == FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700217}
218
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219CFX_ByteString CPWL_Wnd::GetClassName() const {
220 return "CPWL_Wnd";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700221}
222
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) {
224 if (!IsValid()) {
225 m_sPrivateParam = cp;
226
227 OnCreate(m_sPrivateParam);
228
229 m_sPrivateParam.rcRectWnd.Normalize();
230 m_rcWindow = m_sPrivateParam.rcRectWnd;
231 m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f);
232
233 CreateMsgControl();
234
235 if (m_sPrivateParam.pParentWnd)
236 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD);
237
238 PWL_CREATEPARAM ccp = m_sPrivateParam;
239
240 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
Tom Sepez60d909e2015-12-10 15:34:55 -0800241 ccp.mtChild = CFX_Matrix(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242
243 CreateScrollBar(ccp);
244 CreateChildWnd(ccp);
245
246 m_bVisible = HasFlag(PWS_VISIBLE);
247
248 OnCreated();
249
250 RePosChildWnd();
251 m_bCreated = TRUE;
252 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700253}
254
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700256
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257void CPWL_Wnd::OnCreated() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700258
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259void CPWL_Wnd::OnDestroy() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700260
Lei Zhangab5537d2016-01-06 14:58:14 -0800261void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) {
262 if (m_sPrivateParam.pFocusHandler == handler)
263 m_sPrivateParam.pFocusHandler = nullptr;
264}
265
266void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) {
267 if (m_sPrivateParam.pProvider == provider)
268 m_sPrivateParam.pProvider = nullptr;
269}
270
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271void CPWL_Wnd::Destroy() {
272 KillFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700273
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 OnDestroy();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700275
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 if (m_bCreated) {
277 for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
278 if (CPWL_Wnd* pChild = m_aChildren[i]) {
279 pChild->Destroy();
280 delete pChild;
thestig1cd352e2016-06-07 17:53:06 -0700281 pChild = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 }
283 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700284
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 if (m_sPrivateParam.pParentWnd)
286 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD);
287 m_bCreated = FALSE;
288 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700289
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 DestroyMsgControl();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM));
293 m_aChildren.RemoveAll();
thestig1cd352e2016-06-07 17:53:06 -0700294 m_pVScrollBar = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700295}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700296
Tom Sepez281a9ea2016-02-26 14:24:28 -0800297void CPWL_Wnd::Move(const CFX_FloatRect& rcNew,
298 FX_BOOL bReset,
299 FX_BOOL bRefresh) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 if (IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800301 CFX_FloatRect rcOld = GetWindowRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700302
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 m_rcWindow = rcNew;
304 m_rcWindow.Normalize();
305
306 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
307 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
308 if (bReset) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700309 RePosChildWnd();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700311 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 if (bRefresh) {
313 InvalidateRectMove(rcOld, rcNew);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700314 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700315
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316 m_sPrivateParam.rcRectWnd = m_rcWindow;
317 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700318}
319
Tom Sepez281a9ea2016-02-26 14:24:28 -0800320void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
321 const CFX_FloatRect& rcNew) {
322 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700324
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325 InvalidateRect(&rcUnion);
326}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700327
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) {
329 if (IsValid() && IsVisible()) {
330 GetThisAppearanceStream(sAppStream);
331 GetChildAppearanceStream(sAppStream);
332 }
333}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700334
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335// if don't set,Get default apperance stream
336void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800337 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700338 if (!rectWnd.IsEmpty()) {
339 CFX_ByteTextBuf sThis;
340
341 if (HasFlag(PWS_BACKGROUND))
342 sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor());
343
344 if (HasFlag(PWS_BORDER)) {
345 sThis << CPWL_Utils::GetBorderAppStream(
346 rectWnd, (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
347 GetBorderLeftTopColor(GetBorderStyle()),
348 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
349 GetBorderDash());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700350 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700351
352 sAppStream << sThis;
353 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700354}
355
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) {
357 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
358 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
359 pChild->GetAppearanceStream(sAppStream);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700360 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700362}
363
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800365 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 if (IsValid() && IsVisible()) {
367 DrawThisAppearance(pDevice, pUser2Device);
368 DrawChildAppearance(pDevice, pUser2Device);
369 }
370}
371
372void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800373 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800374 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375 if (!rectWnd.IsEmpty()) {
376 if (HasFlag(PWS_BACKGROUND)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800377 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700378 rectWnd, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
379 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
380 GetBackgroundColor(), GetTransparency());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700381 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700382
383 if (HasFlag(PWS_BORDER))
Lei Zhang7457e382016-01-06 23:00:34 -0800384 CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd,
385 (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
386 GetBorderLeftTopColor(GetBorderStyle()),
387 GetBorderRightBottomColor(GetBorderStyle()),
388 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700390}
391
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800393 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
395 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
Tom Sepez60d909e2015-12-10 15:34:55 -0800396 CFX_Matrix mt = pChild->GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700397 if (mt.IsIdentity()) {
398 pChild->DrawAppearance(pDevice, pUser2Device);
399 } else {
400 mt.Concat(*pUser2Device);
401 pChild->DrawAppearance(pDevice, &mt);
402 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700403 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700405}
406
Tom Sepez281a9ea2016-02-26 14:24:28 -0800407void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408 if (IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800409 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410
411 if (!HasFlag(PWS_NOREFRESHCLIP)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800412 CFX_FloatRect rcClip = GetClipRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700413 if (!rcClip.IsEmpty()) {
414 rcRefresh.Intersect(rcClip);
415 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700416 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700417
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418 FX_RECT rcWin = PWLtoWnd(rcRefresh);
419 rcWin.left -= PWL_INVALIDATE_INFLATE;
420 rcWin.top -= PWL_INVALIDATE_INFLATE;
421 rcWin.right += PWL_INVALIDATE_INFLATE;
422 rcWin.bottom += PWL_INVALIDATE_INFLATE;
423
dsinclairb9590102016-04-27 06:38:59 -0700424 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 if (FX_HWND hWnd = GetAttachedHWnd()) {
426 pSH->InvalidateRect(hWnd, rcWin);
427 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700428 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700430}
431
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
tsepezc3255f52016-03-25 14:52:27 -0700433 FX_BOOL CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434 if (IsValid() && IsVisible() && IsEnabled()) { \
435 if (IsWndCaptureKeyboard(this)) { \
436 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
437 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
438 if (IsWndCaptureKeyboard(pChild)) { \
439 return pChild->key_method_name(nChar, nFlag); \
440 } \
441 } \
442 } \
443 } \
444 } \
445 return FALSE; \
446 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700447
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Tom Sepez281a9ea2016-02-26 14:24:28 -0800449 FX_BOOL CPWL_Wnd::mouse_method_name(const CFX_FloatPoint& point, \
tsepezc3255f52016-03-25 14:52:27 -0700450 uint32_t nFlag) { \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 if (IsValid() && IsVisible() && IsEnabled()) { \
452 if (IsWndCaptureMouse(this)) { \
453 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
454 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
455 if (IsWndCaptureMouse(pChild)) { \
456 return pChild->mouse_method_name(pChild->ParentToChild(point), \
457 nFlag); \
458 } \
459 } \
460 } \
461 SetCursor(); \
462 } else { \
463 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
464 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
465 if (pChild->WndHitTest(pChild->ParentToChild(point))) { \
466 return pChild->mouse_method_name(pChild->ParentToChild(point), \
467 nFlag); \
468 } \
469 } \
470 } \
471 if (WndHitTest(point)) \
472 SetCursor(); \
473 } \
474 } \
475 return FALSE; \
476 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700477
478PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
479PWL_IMPLEMENT_KEY_METHOD(OnKeyUp)
480PWL_IMPLEMENT_KEY_METHOD(OnChar)
481
482PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
483PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
484PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
485PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk)
486PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown)
487PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700488PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
489PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
490PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
491
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492FX_BOOL CPWL_Wnd::OnMouseWheel(short zDelta,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800493 const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700494 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 if (IsValid() && IsVisible() && IsEnabled()) {
496 SetCursor();
497 if (IsWndCaptureKeyboard(this)) {
498 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
499 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
500 if (IsWndCaptureKeyboard(pChild)) {
501 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point),
502 nFlag);
503 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700504 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700506 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 }
508 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700509}
510
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
512 m_aChildren.Add(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700513}
514
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
516 for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
517 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
518 if (pChild == pWnd) {
519 m_aChildren.RemoveAt(i);
520 break;
521 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700522 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700524}
525
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700527 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 intptr_t wParam,
529 intptr_t lParam) {
530 switch (msg) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700531 case PNM_ADDCHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 AddChild(pWnd);
533 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700534 case PNM_REMOVECHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 RemoveChild(pWnd);
536 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700537 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 break;
539 }
540}
541
542FX_BOOL CPWL_Wnd::IsValid() const {
543 return m_bCreated;
544}
545
Lei Zhang7457e382016-01-06 23:00:34 -0800546const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 return m_sPrivateParam;
548}
549
550CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
551 return m_sPrivateParam.pParentWnd;
552}
553
Tom Sepez281a9ea2016-02-26 14:24:28 -0800554CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 return m_rcWindow;
556}
557
Tom Sepez281a9ea2016-02-26 14:24:28 -0800558CFX_FloatRect CPWL_Wnd::GetClientRect() const {
559 CFX_FloatRect rcWindow = GetWindowRect();
560 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 rcWindow, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
562 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
563 rcClient.right -= pVSB->GetScrollBarWidth();
564
565 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800566 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567}
568
Tom Sepez281a9ea2016-02-26 14:24:28 -0800569CFX_FloatPoint CPWL_Wnd::GetCenterPoint() const {
570 CFX_FloatRect rcClient = GetClientRect();
571 return CFX_FloatPoint((rcClient.left + rcClient.right) * 0.5f,
572 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573}
574
tsepezc3255f52016-03-25 14:52:27 -0700575FX_BOOL CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
577}
578
tsepezc3255f52016-03-25 14:52:27 -0700579void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 m_sPrivateParam.dwFlags &= ~dwFlags;
581}
582
tsepezc3255f52016-03-25 14:52:27 -0700583void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584 m_sPrivateParam.dwFlags |= dwFlags;
585}
586
587CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
588 return m_sPrivateParam.sBackgroundColor;
589}
590
591void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
592 m_sPrivateParam.sBackgroundColor = color;
593}
594
595void CPWL_Wnd::SetTextColor(const CPWL_Color& color) {
596 m_sPrivateParam.sTextColor = color;
597}
598
599void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color& color) {
600 m_sPrivateParam.sTextStrokeColor = color;
601}
602
603CPWL_Color CPWL_Wnd::GetTextColor() const {
604 return m_sPrivateParam.sTextColor;
605}
606
607CPWL_Color CPWL_Wnd::GetTextStrokeColor() const {
608 return m_sPrivateParam.sTextStrokeColor;
609}
610
dsinclair92cb5e52016-05-16 11:38:28 -0700611BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 return m_sPrivateParam.nBorderStyle;
613}
614
dsinclair92cb5e52016-05-16 11:38:28 -0700615void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 if (HasFlag(PWS_BORDER))
617 m_sPrivateParam.nBorderStyle = nBorderStyle;
618}
619
620int32_t CPWL_Wnd::GetBorderWidth() const {
621 if (HasFlag(PWS_BORDER))
622 return m_sPrivateParam.dwBorderWidth;
623
624 return 0;
625}
626
627int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628 return 0;
629}
630
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631CPWL_Color CPWL_Wnd::GetBorderColor() const {
632 if (HasFlag(PWS_BORDER))
633 return m_sPrivateParam.sBorderColor;
634
635 return CPWL_Color();
636}
637
Lei Zhang7457e382016-01-06 23:00:34 -0800638const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639 return m_sPrivateParam.sDash;
640}
641
642void* CPWL_Wnd::GetAttachedData() const {
643 return m_sPrivateParam.pAttachedData;
644}
645
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
647 if (HasFlag(PWS_VSCROLL))
648 return m_pVScrollBar;
649
thestig1cd352e2016-06-07 17:53:06 -0700650 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700651}
652
653void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
654 CreateVScrollBar(cp);
655}
656
657void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
658 if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) {
659 PWL_CREATEPARAM scp = cp;
660
661 // flags
662 scp.dwFlags =
663 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
664
665 scp.pParentWnd = this;
666 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
667 scp.eCursorType = FXCT_ARROW;
668 scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY;
669
Lei Zhange00660b2015-08-13 15:40:18 -0700670 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
671 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700672 }
673}
674
675void CPWL_Wnd::SetCapture() {
676 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
677 pMsgCtrl->SetCapture(this);
678}
679
680void CPWL_Wnd::ReleaseCapture() {
681 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++)
682 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
683 pChild->ReleaseCapture();
684
685 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
686 pMsgCtrl->ReleaseCapture();
687}
688
689void CPWL_Wnd::SetFocus() {
690 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
691 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
692 pMsgCtrl->KillFocus();
693 pMsgCtrl->SetFocus(this);
694 }
695}
696
697void CPWL_Wnd::KillFocus() {
698 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
699 if (pMsgCtrl->IsWndCaptureKeyboard(this))
700 pMsgCtrl->KillFocus();
701 }
702}
703
704void CPWL_Wnd::OnSetFocus() {}
705
706void CPWL_Wnd::OnKillFocus() {}
707
Tom Sepez281a9ea2016-02-26 14:24:28 -0800708FX_BOOL CPWL_Wnd::WndHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 return IsValid() && IsVisible() && GetWindowRect().Contains(point.x, point.y);
710}
711
Tom Sepez281a9ea2016-02-26 14:24:28 -0800712FX_BOOL CPWL_Wnd::ClientHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713 return IsValid() && IsVisible() && GetClientRect().Contains(point.x, point.y);
714}
715
716const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
717 if (m_sPrivateParam.pParentWnd)
718 return m_sPrivateParam.pParentWnd->GetRootWnd();
719
720 return this;
721}
722
723void CPWL_Wnd::SetVisible(FX_BOOL bVisible) {
724 if (IsValid()) {
725 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
726 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
727 pChild->SetVisible(bVisible);
728 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700729 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730
731 if (bVisible != m_bVisible) {
732 m_bVisible = bVisible;
733 RePosChildWnd();
734 InvalidateRect();
735 }
736 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700737}
738
Tom Sepez281a9ea2016-02-26 14:24:28 -0800739void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 m_rcClip = rect;
741 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700742}
743
Tom Sepez281a9ea2016-02-26 14:24:28 -0800744const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700745 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700746}
747
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748FX_BOOL CPWL_Wnd::IsReadOnly() const {
749 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700750}
751
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700752void CPWL_Wnd::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800753 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700754 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
755
756 CPWL_ScrollBar* pVSB = GetVScrollBar();
757
Tom Sepez281a9ea2016-02-26 14:24:28 -0800758 CFX_FloatRect rcVScroll =
759 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
760 rcContent.right - 1.0f, rcContent.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761
762 if (pVSB)
763 pVSB->Move(rcVScroll, TRUE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700764}
765
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700766void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
767
768void CPWL_Wnd::SetCursor() {
769 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700770 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700771 int32_t nCursorType = GetCreationParam().eCursorType;
772 pSH->SetCursor(nCursorType);
773 }
774 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700775}
776
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700777void CPWL_Wnd::CreateMsgControl() {
778 if (!m_sPrivateParam.pMsgControl)
779 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700780}
781
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700782void CPWL_Wnd::DestroyMsgControl() {
783 if (CPWL_MsgControl* pMsgControl = GetMsgControl())
784 if (pMsgControl->IsWndCreated(this))
785 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700786}
787
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700788CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
789 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700790}
791
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700792FX_BOOL CPWL_Wnd::IsCaptureMouse() const {
793 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700794}
795
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700796FX_BOOL CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
797 if (CPWL_MsgControl* pCtrl = GetMsgControl())
798 return pCtrl->IsWndCaptureMouse(pWnd);
799
800 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700801}
802
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803FX_BOOL CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
804 if (CPWL_MsgControl* pCtrl = GetMsgControl())
805 return pCtrl->IsWndCaptureKeyboard(pWnd);
806
807 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700808}
809
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700810FX_BOOL CPWL_Wnd::IsFocused() const {
811 if (CPWL_MsgControl* pCtrl = GetMsgControl())
812 return pCtrl->IsMainCaptureKeyboard(this);
813
814 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700815}
816
Tom Sepez281a9ea2016-02-26 14:24:28 -0800817CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700819}
820
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700821FX_FLOAT CPWL_Wnd::GetFontSize() const {
822 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700823}
824
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize) {
826 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700827}
828
dsinclairb9590102016-04-27 06:38:59 -0700829CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700830 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700831}
832
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700833IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
834 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700835}
836
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700837IPWL_Provider* CPWL_Wnd::GetProvider() const {
838 return m_sPrivateParam.pProvider;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700839}
840
dsinclairc7a73492016-04-05 12:01:42 -0700841IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700843}
844
dsinclair92cb5e52016-05-16 11:38:28 -0700845CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700846 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700847 case BorderStyle::BEVELED:
848 return CPWL_Color(COLORTYPE_GRAY, 1);
849 case BorderStyle::INSET:
850 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
851 default:
852 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700853 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700854}
855
dsinclair92cb5e52016-05-16 11:38:28 -0700856CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700857 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700858 case BorderStyle::BEVELED:
859 return CPWL_Utils::DevideColor(GetBackgroundColor(), 2);
860 case BorderStyle::INSET:
861 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
862 default:
863 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700865}
866
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700867int32_t CPWL_Wnd::GetTransparency() {
868 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700869}
870
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700871void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
872 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
873 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
874 pChild->SetTransparency(nTransparency);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700875 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700876 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700877
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700879}
880
Tom Sepez60d909e2015-12-10 15:34:55 -0800881CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
882 CFX_Matrix mt = GetChildToRoot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700883
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700884 if (IPWL_Provider* pProvider = GetProvider()) {
885 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700886 return mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700887 }
888
889 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700890}
891
Tom Sepez281a9ea2016-02-26 14:24:28 -0800892void CPWL_Wnd::PWLtoWnd(const CFX_FloatPoint& point,
893 int32_t& x,
894 int32_t& y) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800895 CFX_Matrix mt = GetWindowMatrix();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800896 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700897 mt.Transform(pt.x, pt.y);
898 x = (int32_t)(pt.x + 0.5);
899 y = (int32_t)(pt.y + 0.5);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700900}
901
Tom Sepez281a9ea2016-02-26 14:24:28 -0800902FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
903 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800904 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700905 mt.TransformRect(rcTemp);
906 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
907 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700908}
909
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700910FX_HWND CPWL_Wnd::GetAttachedHWnd() const {
911 return m_sPrivateParam.hAttachedWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700912}
913
Tom Sepez281a9ea2016-02-26 14:24:28 -0800914CFX_FloatPoint CPWL_Wnd::ChildToParent(const CFX_FloatPoint& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800915 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700916 if (mt.IsIdentity())
917 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700918
Tom Sepez281a9ea2016-02-26 14:24:28 -0800919 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700920 mt.Transform(pt.x, pt.y);
921 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700922}
923
Tom Sepez281a9ea2016-02-26 14:24:28 -0800924CFX_FloatRect CPWL_Wnd::ChildToParent(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800925 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700926 if (mt.IsIdentity())
927 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700928
Tom Sepez281a9ea2016-02-26 14:24:28 -0800929 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700930 mt.TransformRect(rc);
931 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700932}
933
Tom Sepez281a9ea2016-02-26 14:24:28 -0800934CFX_FloatPoint CPWL_Wnd::ParentToChild(const CFX_FloatPoint& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800935 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700936 if (mt.IsIdentity())
937 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700938
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700939 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800940 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700941 mt.Transform(pt.x, pt.y);
942 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700943}
944
Tom Sepez281a9ea2016-02-26 14:24:28 -0800945CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800946 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947 if (mt.IsIdentity())
948 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700949
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700950 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800951 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700952 mt.TransformRect(rc);
953 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700954}
955
weili625ad662016-06-15 11:21:33 -0700956FX_FLOAT CPWL_Wnd::GetItemHeight(FX_FLOAT fLimitWidth) {
957 return 0;
958}
959
960FX_FLOAT CPWL_Wnd::GetItemLeftMargin() {
961 return 0;
962}
963
964FX_FLOAT CPWL_Wnd::GetItemRightMargin() {
965 return 0;
966}
967
Tom Sepez60d909e2015-12-10 15:34:55 -0800968CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
969 CFX_Matrix mt(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700970 if (HasFlag(PWS_CHILD)) {
971 const CPWL_Wnd* pParent = this;
972 while (pParent) {
973 mt.Concat(pParent->GetChildMatrix());
974 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700975 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700976 }
977 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700978}
979
Tom Sepez60d909e2015-12-10 15:34:55 -0800980CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700981 if (HasFlag(PWS_CHILD))
982 return m_sPrivateParam.mtChild;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700983
Tom Sepez60d909e2015-12-10 15:34:55 -0800984 return CFX_Matrix(1, 0, 0, 1, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700985}
986
Tom Sepez60d909e2015-12-10 15:34:55 -0800987void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700988 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700989}
990
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700991const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
992 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
993 return pMsgCtrl->m_pMainKeyboardWnd;
994 }
995
thestig1cd352e2016-06-07 17:53:06 -0700996 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700997}
998
999void CPWL_Wnd::EnableWindow(FX_BOOL bEnable) {
1000 if (m_bEnabled != bEnable) {
1001 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
1002 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
1003 pChild->EnableWindow(bEnable);
1004 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001005 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001006
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001007 m_bEnabled = bEnable;
1008
1009 if (bEnable)
1010 OnEnabled();
1011 else
1012 OnDisabled();
1013 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001014}
1015
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001016FX_BOOL CPWL_Wnd::IsEnabled() {
1017 return m_bEnabled;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001018}
1019
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001020void CPWL_Wnd::OnEnabled() {}
1021
1022void CPWL_Wnd::OnDisabled() {}
1023
tsepezc3255f52016-03-25 14:52:27 -07001024FX_BOOL CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001025 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001026 return pSystemHandler->IsCTRLKeyDown(nFlag);
1027 }
1028
1029 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001030}
1031
tsepezc3255f52016-03-25 14:52:27 -07001032FX_BOOL CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001033 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001034 return pSystemHandler->IsSHIFTKeyDown(nFlag);
1035 }
1036
1037 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001038}
1039
tsepezc3255f52016-03-25 14:52:27 -07001040FX_BOOL CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001041 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001042 return pSystemHandler->IsALTKeyDown(nFlag);
1043 }
1044
1045 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001046}