blob: e680652bb3e3aee513ced1eaa1b467419deb813a [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
thestig1cd352e2016-06-07 17:53:06 -070083CPWL_TimerHandler::CPWL_TimerHandler() : m_pTimer(nullptr) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084
85CPWL_TimerHandler::~CPWL_TimerHandler() {
86 delete m_pTimer;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087}
88
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089void CPWL_TimerHandler::BeginTimer(int32_t nElapse) {
90 if (!m_pTimer)
91 m_pTimer = new CPWL_Timer(this, GetSystemHandler());
92
93 if (m_pTimer)
94 m_pTimer->SetPWLTimer(nElapse);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095}
96
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097void CPWL_TimerHandler::EndTimer() {
98 if (m_pTimer)
99 m_pTimer->KillPWLTimer();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100}
101
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102void CPWL_TimerHandler::TimerProc() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700103
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104class CPWL_MsgControl {
105 friend class CPWL_Wnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700106
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 public:
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800108 explicit CPWL_MsgControl(CPWL_Wnd* pWnd) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109 m_pCreatedWnd = pWnd;
110 Default();
111 }
112
Dan Sinclairf766ad22016-03-14 13:51:24 -0400113 ~CPWL_MsgControl() { Default(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114
115 void Default() {
116 m_aMousePath.RemoveAll();
117 m_aKeyboardPath.RemoveAll();
thestig1cd352e2016-06-07 17:53:06 -0700118 m_pMainMouseWnd = nullptr;
119 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 }
121
122 FX_BOOL IsWndCreated(const CPWL_Wnd* pWnd) const {
123 return m_pCreatedWnd == pWnd;
124 }
125
126 FX_BOOL IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
127 return pWnd == m_pMainMouseWnd;
128 }
129
130 FX_BOOL IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800131 if (pWnd) {
132 for (int32_t i = 0, sz = m_aMousePath.GetSize(); i < sz; i++) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 if (m_aMousePath.GetAt(i) == pWnd)
134 return TRUE;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800135 }
136 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137
138 return FALSE;
139 }
140
141 FX_BOOL IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
142 return pWnd == m_pMainKeyboardWnd;
143 }
144
145 FX_BOOL IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800146 if (pWnd) {
147 for (int32_t i = 0, sz = m_aKeyboardPath.GetSize(); i < sz; i++) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 if (m_aKeyboardPath.GetAt(i) == pWnd)
149 return TRUE;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800150 }
151 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152
153 return FALSE;
154 }
155
156 void SetFocus(CPWL_Wnd* pWnd) {
157 m_aKeyboardPath.RemoveAll();
158
159 if (pWnd) {
160 m_pMainKeyboardWnd = pWnd;
161
162 CPWL_Wnd* pParent = pWnd;
163 while (pParent) {
164 m_aKeyboardPath.Add(pParent);
165 pParent = pParent->GetParentWindow();
166 }
167
168 pWnd->OnSetFocus();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700169 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 void KillFocus() {
173 if (m_aKeyboardPath.GetSize() > 0)
174 if (CPWL_Wnd* pWnd = m_aKeyboardPath.GetAt(0))
175 pWnd->OnKillFocus();
176
thestig1cd352e2016-06-07 17:53:06 -0700177 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 m_aKeyboardPath.RemoveAll();
179 }
180
181 void SetCapture(CPWL_Wnd* pWnd) {
182 m_aMousePath.RemoveAll();
183
184 if (pWnd) {
185 m_pMainMouseWnd = pWnd;
186
187 CPWL_Wnd* pParent = pWnd;
188 while (pParent) {
189 m_aMousePath.Add(pParent);
190 pParent = pParent->GetParentWindow();
191 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700192 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700194
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 void ReleaseCapture() {
thestig1cd352e2016-06-07 17:53:06 -0700196 m_pMainMouseWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 m_aMousePath.RemoveAll();
198 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 private:
201 CFX_ArrayTemplate<CPWL_Wnd*> m_aMousePath;
202 CFX_ArrayTemplate<CPWL_Wnd*> m_aKeyboardPath;
203 CPWL_Wnd* m_pCreatedWnd;
204 CPWL_Wnd* m_pMainMouseWnd;
205 CPWL_Wnd* m_pMainKeyboardWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700206};
207
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208CPWL_Wnd::CPWL_Wnd()
thestig1cd352e2016-06-07 17:53:06 -0700209 : m_pVScrollBar(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 m_rcWindow(),
211 m_rcClip(),
212 m_bCreated(FALSE),
213 m_bVisible(FALSE),
214 m_bNotifying(FALSE),
215 m_bEnabled(TRUE) {}
216
217CPWL_Wnd::~CPWL_Wnd() {
218 ASSERT(m_bCreated == FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700219}
220
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221CFX_ByteString CPWL_Wnd::GetClassName() const {
222 return "CPWL_Wnd";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700223}
224
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) {
226 if (!IsValid()) {
227 m_sPrivateParam = cp;
228
229 OnCreate(m_sPrivateParam);
230
231 m_sPrivateParam.rcRectWnd.Normalize();
232 m_rcWindow = m_sPrivateParam.rcRectWnd;
233 m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f);
234
235 CreateMsgControl();
236
237 if (m_sPrivateParam.pParentWnd)
238 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD);
239
240 PWL_CREATEPARAM ccp = m_sPrivateParam;
241
242 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
Tom Sepez60d909e2015-12-10 15:34:55 -0800243 ccp.mtChild = CFX_Matrix(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244
245 CreateScrollBar(ccp);
246 CreateChildWnd(ccp);
247
248 m_bVisible = HasFlag(PWS_VISIBLE);
249
250 OnCreated();
251
252 RePosChildWnd();
253 m_bCreated = TRUE;
254 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700255}
256
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700258
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259void CPWL_Wnd::OnCreated() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700260
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261void CPWL_Wnd::OnDestroy() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700262
Lei Zhangab5537d2016-01-06 14:58:14 -0800263void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) {
264 if (m_sPrivateParam.pFocusHandler == handler)
265 m_sPrivateParam.pFocusHandler = nullptr;
266}
267
268void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) {
269 if (m_sPrivateParam.pProvider == provider)
270 m_sPrivateParam.pProvider = nullptr;
271}
272
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273void CPWL_Wnd::Destroy() {
274 KillFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700275
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 OnDestroy();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700277
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278 if (m_bCreated) {
279 for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
280 if (CPWL_Wnd* pChild = m_aChildren[i]) {
281 pChild->Destroy();
282 delete pChild;
thestig1cd352e2016-06-07 17:53:06 -0700283 pChild = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284 }
285 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700286
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 if (m_sPrivateParam.pParentWnd)
288 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD);
289 m_bCreated = FALSE;
290 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 DestroyMsgControl();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700293
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM));
295 m_aChildren.RemoveAll();
thestig1cd352e2016-06-07 17:53:06 -0700296 m_pVScrollBar = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700298
Tom Sepez281a9ea2016-02-26 14:24:28 -0800299void CPWL_Wnd::Move(const CFX_FloatRect& rcNew,
300 FX_BOOL bReset,
301 FX_BOOL bRefresh) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 if (IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800303 CFX_FloatRect rcOld = GetWindowRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700304
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305 m_rcWindow = rcNew;
306 m_rcWindow.Normalize();
307
308 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
309 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
310 if (bReset) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700311 RePosChildWnd();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700313 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314 if (bRefresh) {
315 InvalidateRectMove(rcOld, rcNew);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700316 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700317
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318 m_sPrivateParam.rcRectWnd = m_rcWindow;
319 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700320}
321
Tom Sepez281a9ea2016-02-26 14:24:28 -0800322void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
323 const CFX_FloatRect& rcNew) {
324 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700326
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327 InvalidateRect(&rcUnion);
328}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700329
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700330void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) {
331 if (IsValid() && IsVisible()) {
332 GetThisAppearanceStream(sAppStream);
333 GetChildAppearanceStream(sAppStream);
334 }
335}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700336
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337// if don't set,Get default apperance stream
338void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800339 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340 if (!rectWnd.IsEmpty()) {
341 CFX_ByteTextBuf sThis;
342
343 if (HasFlag(PWS_BACKGROUND))
344 sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor());
345
346 if (HasFlag(PWS_BORDER)) {
347 sThis << CPWL_Utils::GetBorderAppStream(
348 rectWnd, (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
349 GetBorderLeftTopColor(GetBorderStyle()),
350 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
351 GetBorderDash());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700352 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353
354 sAppStream << sThis;
355 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700356}
357
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) {
359 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
360 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
361 pChild->GetAppearanceStream(sAppStream);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700362 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700363 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700364}
365
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800367 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368 if (IsValid() && IsVisible()) {
369 DrawThisAppearance(pDevice, pUser2Device);
370 DrawChildAppearance(pDevice, pUser2Device);
371 }
372}
373
374void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800375 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800376 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377 if (!rectWnd.IsEmpty()) {
378 if (HasFlag(PWS_BACKGROUND)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800379 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380 rectWnd, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
381 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
382 GetBackgroundColor(), GetTransparency());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700383 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384
385 if (HasFlag(PWS_BORDER))
Lei Zhang7457e382016-01-06 23:00:34 -0800386 CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd,
387 (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
388 GetBorderLeftTopColor(GetBorderStyle()),
389 GetBorderRightBottomColor(GetBorderStyle()),
390 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700392}
393
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800395 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
397 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
Tom Sepez60d909e2015-12-10 15:34:55 -0800398 CFX_Matrix mt = pChild->GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399 if (mt.IsIdentity()) {
400 pChild->DrawAppearance(pDevice, pUser2Device);
401 } else {
402 mt.Concat(*pUser2Device);
403 pChild->DrawAppearance(pDevice, &mt);
404 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700405 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700407}
408
Tom Sepez281a9ea2016-02-26 14:24:28 -0800409void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410 if (IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800411 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412
413 if (!HasFlag(PWS_NOREFRESHCLIP)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800414 CFX_FloatRect rcClip = GetClipRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415 if (!rcClip.IsEmpty()) {
416 rcRefresh.Intersect(rcClip);
417 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700418 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700419
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700420 FX_RECT rcWin = PWLtoWnd(rcRefresh);
421 rcWin.left -= PWL_INVALIDATE_INFLATE;
422 rcWin.top -= PWL_INVALIDATE_INFLATE;
423 rcWin.right += PWL_INVALIDATE_INFLATE;
424 rcWin.bottom += PWL_INVALIDATE_INFLATE;
425
dsinclairb9590102016-04-27 06:38:59 -0700426 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 if (FX_HWND hWnd = GetAttachedHWnd()) {
428 pSH->InvalidateRect(hWnd, rcWin);
429 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700430 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700432}
433
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
tsepezc3255f52016-03-25 14:52:27 -0700435 FX_BOOL CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 if (IsValid() && IsVisible() && IsEnabled()) { \
437 if (IsWndCaptureKeyboard(this)) { \
438 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
439 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
440 if (IsWndCaptureKeyboard(pChild)) { \
441 return pChild->key_method_name(nChar, nFlag); \
442 } \
443 } \
444 } \
445 } \
446 } \
447 return FALSE; \
448 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700449
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Tom Sepez281a9ea2016-02-26 14:24:28 -0800451 FX_BOOL CPWL_Wnd::mouse_method_name(const CFX_FloatPoint& point, \
tsepezc3255f52016-03-25 14:52:27 -0700452 uint32_t nFlag) { \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 if (IsValid() && IsVisible() && IsEnabled()) { \
454 if (IsWndCaptureMouse(this)) { \
455 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
456 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
457 if (IsWndCaptureMouse(pChild)) { \
458 return pChild->mouse_method_name(pChild->ParentToChild(point), \
459 nFlag); \
460 } \
461 } \
462 } \
463 SetCursor(); \
464 } else { \
465 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
466 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
467 if (pChild->WndHitTest(pChild->ParentToChild(point))) { \
468 return pChild->mouse_method_name(pChild->ParentToChild(point), \
469 nFlag); \
470 } \
471 } \
472 } \
473 if (WndHitTest(point)) \
474 SetCursor(); \
475 } \
476 } \
477 return FALSE; \
478 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700479
480PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
481PWL_IMPLEMENT_KEY_METHOD(OnKeyUp)
482PWL_IMPLEMENT_KEY_METHOD(OnChar)
483
484PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
485PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
486PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
487PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk)
488PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown)
489PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
491PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
492PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
493
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494FX_BOOL CPWL_Wnd::OnMouseWheel(short zDelta,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800495 const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700496 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 if (IsValid() && IsVisible() && IsEnabled()) {
498 SetCursor();
499 if (IsWndCaptureKeyboard(this)) {
500 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
501 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
502 if (IsWndCaptureKeyboard(pChild)) {
503 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point),
504 nFlag);
505 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700506 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700508 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 }
510 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700511}
512
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
514 m_aChildren.Add(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700515}
516
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
518 for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
519 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
520 if (pChild == pWnd) {
521 m_aChildren.RemoveAt(i);
522 break;
523 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700524 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700526}
527
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700529 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 intptr_t wParam,
531 intptr_t lParam) {
532 switch (msg) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700533 case PNM_ADDCHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 AddChild(pWnd);
535 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700536 case PNM_REMOVECHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 RemoveChild(pWnd);
538 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700539 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 break;
541 }
542}
543
544FX_BOOL CPWL_Wnd::IsValid() const {
545 return m_bCreated;
546}
547
Lei Zhang7457e382016-01-06 23:00:34 -0800548const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549 return m_sPrivateParam;
550}
551
552CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
553 return m_sPrivateParam.pParentWnd;
554}
555
Tom Sepez281a9ea2016-02-26 14:24:28 -0800556CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 return m_rcWindow;
558}
559
Tom Sepez281a9ea2016-02-26 14:24:28 -0800560CFX_FloatRect CPWL_Wnd::GetClientRect() const {
561 CFX_FloatRect rcWindow = GetWindowRect();
562 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 rcWindow, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
564 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
565 rcClient.right -= pVSB->GetScrollBarWidth();
566
567 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800568 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569}
570
Tom Sepez281a9ea2016-02-26 14:24:28 -0800571CFX_FloatPoint CPWL_Wnd::GetCenterPoint() const {
572 CFX_FloatRect rcClient = GetClientRect();
573 return CFX_FloatPoint((rcClient.left + rcClient.right) * 0.5f,
574 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575}
576
tsepezc3255f52016-03-25 14:52:27 -0700577FX_BOOL CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
579}
580
tsepezc3255f52016-03-25 14:52:27 -0700581void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582 m_sPrivateParam.dwFlags &= ~dwFlags;
583}
584
tsepezc3255f52016-03-25 14:52:27 -0700585void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 m_sPrivateParam.dwFlags |= dwFlags;
587}
588
589CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
590 return m_sPrivateParam.sBackgroundColor;
591}
592
593void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
594 m_sPrivateParam.sBackgroundColor = color;
595}
596
597void CPWL_Wnd::SetTextColor(const CPWL_Color& color) {
598 m_sPrivateParam.sTextColor = color;
599}
600
601void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color& color) {
602 m_sPrivateParam.sTextStrokeColor = color;
603}
604
605CPWL_Color CPWL_Wnd::GetTextColor() const {
606 return m_sPrivateParam.sTextColor;
607}
608
609CPWL_Color CPWL_Wnd::GetTextStrokeColor() const {
610 return m_sPrivateParam.sTextStrokeColor;
611}
612
dsinclair92cb5e52016-05-16 11:38:28 -0700613BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 return m_sPrivateParam.nBorderStyle;
615}
616
dsinclair92cb5e52016-05-16 11:38:28 -0700617void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618 if (HasFlag(PWS_BORDER))
619 m_sPrivateParam.nBorderStyle = nBorderStyle;
620}
621
622int32_t CPWL_Wnd::GetBorderWidth() const {
623 if (HasFlag(PWS_BORDER))
624 return m_sPrivateParam.dwBorderWidth;
625
626 return 0;
627}
628
629int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630 return 0;
631}
632
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633CPWL_Color CPWL_Wnd::GetBorderColor() const {
634 if (HasFlag(PWS_BORDER))
635 return m_sPrivateParam.sBorderColor;
636
637 return CPWL_Color();
638}
639
Lei Zhang7457e382016-01-06 23:00:34 -0800640const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700641 return m_sPrivateParam.sDash;
642}
643
644void* CPWL_Wnd::GetAttachedData() const {
645 return m_sPrivateParam.pAttachedData;
646}
647
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
649 if (HasFlag(PWS_VSCROLL))
650 return m_pVScrollBar;
651
thestig1cd352e2016-06-07 17:53:06 -0700652 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653}
654
655void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
656 CreateVScrollBar(cp);
657}
658
659void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
660 if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) {
661 PWL_CREATEPARAM scp = cp;
662
663 // flags
664 scp.dwFlags =
665 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
666
667 scp.pParentWnd = this;
668 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
669 scp.eCursorType = FXCT_ARROW;
670 scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY;
671
Lei Zhange00660b2015-08-13 15:40:18 -0700672 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
673 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700674 }
675}
676
677void CPWL_Wnd::SetCapture() {
678 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
679 pMsgCtrl->SetCapture(this);
680}
681
682void CPWL_Wnd::ReleaseCapture() {
683 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++)
684 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
685 pChild->ReleaseCapture();
686
687 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
688 pMsgCtrl->ReleaseCapture();
689}
690
691void CPWL_Wnd::SetFocus() {
692 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
693 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
694 pMsgCtrl->KillFocus();
695 pMsgCtrl->SetFocus(this);
696 }
697}
698
699void CPWL_Wnd::KillFocus() {
700 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
701 if (pMsgCtrl->IsWndCaptureKeyboard(this))
702 pMsgCtrl->KillFocus();
703 }
704}
705
706void CPWL_Wnd::OnSetFocus() {}
707
708void CPWL_Wnd::OnKillFocus() {}
709
Tom Sepez281a9ea2016-02-26 14:24:28 -0800710FX_BOOL CPWL_Wnd::WndHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 return IsValid() && IsVisible() && GetWindowRect().Contains(point.x, point.y);
712}
713
Tom Sepez281a9ea2016-02-26 14:24:28 -0800714FX_BOOL CPWL_Wnd::ClientHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715 return IsValid() && IsVisible() && GetClientRect().Contains(point.x, point.y);
716}
717
718const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
719 if (m_sPrivateParam.pParentWnd)
720 return m_sPrivateParam.pParentWnd->GetRootWnd();
721
722 return this;
723}
724
725void CPWL_Wnd::SetVisible(FX_BOOL bVisible) {
726 if (IsValid()) {
727 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
728 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
729 pChild->SetVisible(bVisible);
730 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700731 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732
733 if (bVisible != m_bVisible) {
734 m_bVisible = bVisible;
735 RePosChildWnd();
736 InvalidateRect();
737 }
738 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700739}
740
Tom Sepez281a9ea2016-02-26 14:24:28 -0800741void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742 m_rcClip = rect;
743 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700744}
745
Tom Sepez281a9ea2016-02-26 14:24:28 -0800746const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700748}
749
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750FX_BOOL CPWL_Wnd::IsReadOnly() const {
751 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700752}
753
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700754void CPWL_Wnd::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800755 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
757
758 CPWL_ScrollBar* pVSB = GetVScrollBar();
759
Tom Sepez281a9ea2016-02-26 14:24:28 -0800760 CFX_FloatRect rcVScroll =
761 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
762 rcContent.right - 1.0f, rcContent.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700763
764 if (pVSB)
765 pVSB->Move(rcVScroll, TRUE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766}
767
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
769
770void CPWL_Wnd::SetCursor() {
771 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700772 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700773 int32_t nCursorType = GetCreationParam().eCursorType;
774 pSH->SetCursor(nCursorType);
775 }
776 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700777}
778
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700779void CPWL_Wnd::CreateMsgControl() {
780 if (!m_sPrivateParam.pMsgControl)
781 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700782}
783
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784void CPWL_Wnd::DestroyMsgControl() {
785 if (CPWL_MsgControl* pMsgControl = GetMsgControl())
786 if (pMsgControl->IsWndCreated(this))
787 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700788}
789
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
791 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700792}
793
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700794FX_BOOL CPWL_Wnd::IsCaptureMouse() const {
795 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700796}
797
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798FX_BOOL CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
799 if (CPWL_MsgControl* pCtrl = GetMsgControl())
800 return pCtrl->IsWndCaptureMouse(pWnd);
801
802 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700803}
804
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700805FX_BOOL CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
806 if (CPWL_MsgControl* pCtrl = GetMsgControl())
807 return pCtrl->IsWndCaptureKeyboard(pWnd);
808
809 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700810}
811
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700812FX_BOOL CPWL_Wnd::IsFocused() const {
813 if (CPWL_MsgControl* pCtrl = GetMsgControl())
814 return pCtrl->IsMainCaptureKeyboard(this);
815
816 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700817}
818
Tom Sepez281a9ea2016-02-26 14:24:28 -0800819CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700820 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700821}
822
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700823FX_FLOAT CPWL_Wnd::GetFontSize() const {
824 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700825}
826
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700827void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize) {
828 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700829}
830
dsinclairb9590102016-04-27 06:38:59 -0700831CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700832 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700833}
834
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700835IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
836 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700837}
838
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839IPWL_Provider* CPWL_Wnd::GetProvider() const {
840 return m_sPrivateParam.pProvider;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700841}
842
dsinclairc7a73492016-04-05 12:01:42 -0700843IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700845}
846
dsinclair92cb5e52016-05-16 11:38:28 -0700847CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700849 case BorderStyle::BEVELED:
850 return CPWL_Color(COLORTYPE_GRAY, 1);
851 case BorderStyle::INSET:
852 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
853 default:
854 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700855 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700856}
857
dsinclair92cb5e52016-05-16 11:38:28 -0700858CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700859 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700860 case BorderStyle::BEVELED:
861 return CPWL_Utils::DevideColor(GetBackgroundColor(), 2);
862 case BorderStyle::INSET:
863 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
864 default:
865 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700866 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700867}
868
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700869int32_t CPWL_Wnd::GetTransparency() {
870 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700871}
872
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700873void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
874 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
875 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
876 pChild->SetTransparency(nTransparency);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700877 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700879
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881}
882
Tom Sepez60d909e2015-12-10 15:34:55 -0800883CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
884 CFX_Matrix mt = GetChildToRoot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700885
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886 if (IPWL_Provider* pProvider = GetProvider()) {
887 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700888 return mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700889 }
890
891 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700892}
893
Tom Sepez281a9ea2016-02-26 14:24:28 -0800894void CPWL_Wnd::PWLtoWnd(const CFX_FloatPoint& point,
895 int32_t& x,
896 int32_t& y) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800897 CFX_Matrix mt = GetWindowMatrix();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800898 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700899 mt.Transform(pt.x, pt.y);
900 x = (int32_t)(pt.x + 0.5);
901 y = (int32_t)(pt.y + 0.5);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700902}
903
Tom Sepez281a9ea2016-02-26 14:24:28 -0800904FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
905 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800906 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700907 mt.TransformRect(rcTemp);
908 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
909 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700910}
911
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700912FX_HWND CPWL_Wnd::GetAttachedHWnd() const {
913 return m_sPrivateParam.hAttachedWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700914}
915
Tom Sepez281a9ea2016-02-26 14:24:28 -0800916CFX_FloatPoint CPWL_Wnd::ChildToParent(const CFX_FloatPoint& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800917 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700918 if (mt.IsIdentity())
919 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700920
Tom Sepez281a9ea2016-02-26 14:24:28 -0800921 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700922 mt.Transform(pt.x, pt.y);
923 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700924}
925
Tom Sepez281a9ea2016-02-26 14:24:28 -0800926CFX_FloatRect CPWL_Wnd::ChildToParent(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800927 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700928 if (mt.IsIdentity())
929 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700930
Tom Sepez281a9ea2016-02-26 14:24:28 -0800931 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700932 mt.TransformRect(rc);
933 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700934}
935
Tom Sepez281a9ea2016-02-26 14:24:28 -0800936CFX_FloatPoint CPWL_Wnd::ParentToChild(const CFX_FloatPoint& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800937 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700938 if (mt.IsIdentity())
939 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700940
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700941 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800942 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700943 mt.Transform(pt.x, pt.y);
944 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700945}
946
Tom Sepez281a9ea2016-02-26 14:24:28 -0800947CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800948 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700949 if (mt.IsIdentity())
950 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700951
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700952 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800953 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700954 mt.TransformRect(rc);
955 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700956}
957
weili625ad662016-06-15 11:21:33 -0700958FX_FLOAT CPWL_Wnd::GetItemHeight(FX_FLOAT fLimitWidth) {
959 return 0;
960}
961
962FX_FLOAT CPWL_Wnd::GetItemLeftMargin() {
963 return 0;
964}
965
966FX_FLOAT CPWL_Wnd::GetItemRightMargin() {
967 return 0;
968}
969
Tom Sepez60d909e2015-12-10 15:34:55 -0800970CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
971 CFX_Matrix mt(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700972 if (HasFlag(PWS_CHILD)) {
973 const CPWL_Wnd* pParent = this;
974 while (pParent) {
975 mt.Concat(pParent->GetChildMatrix());
976 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700977 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700978 }
979 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700980}
981
Tom Sepez60d909e2015-12-10 15:34:55 -0800982CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700983 if (HasFlag(PWS_CHILD))
984 return m_sPrivateParam.mtChild;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700985
Tom Sepez60d909e2015-12-10 15:34:55 -0800986 return CFX_Matrix(1, 0, 0, 1, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700987}
988
Tom Sepez60d909e2015-12-10 15:34:55 -0800989void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700990 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700991}
992
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700993const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
994 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
995 return pMsgCtrl->m_pMainKeyboardWnd;
996 }
997
thestig1cd352e2016-06-07 17:53:06 -0700998 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700999}
1000
1001void CPWL_Wnd::EnableWindow(FX_BOOL bEnable) {
1002 if (m_bEnabled != bEnable) {
1003 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
1004 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
1005 pChild->EnableWindow(bEnable);
1006 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001007 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001008
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001009 m_bEnabled = bEnable;
1010
1011 if (bEnable)
1012 OnEnabled();
1013 else
1014 OnDisabled();
1015 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001016}
1017
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001018FX_BOOL CPWL_Wnd::IsEnabled() {
1019 return m_bEnabled;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001020}
1021
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001022void CPWL_Wnd::OnEnabled() {}
1023
1024void CPWL_Wnd::OnDisabled() {}
1025
tsepezc3255f52016-03-25 14:52:27 -07001026FX_BOOL CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001027 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001028 return pSystemHandler->IsCTRLKeyDown(nFlag);
1029 }
1030
1031 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001032}
1033
tsepezc3255f52016-03-25 14:52:27 -07001034FX_BOOL CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001035 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001036 return pSystemHandler->IsSHIFTKeyDown(nFlag);
1037 }
1038
1039 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001040}
1041
tsepezc3255f52016-03-25 14:52:27 -07001042FX_BOOL CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001043 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001044 return pSystemHandler->IsALTKeyDown(nFlag);
1045 }
1046
1047 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001048}