blob: 2a0a0aabbbf244730500331967d974383e84bdbd [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
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached,
dsinclairb9590102016-04-27 06:38:59 -070020 CFX_SystemHandler* pSystemHandler)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021 : m_nTimerID(0), m_pAttached(pAttached), m_pSystemHandler(pSystemHandler) {
Lei Zhang96660d62015-12-14 18:27:25 -080022 ASSERT(m_pAttached);
23 ASSERT(m_pSystemHandler);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024}
25
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026CPWL_Timer::~CPWL_Timer() {
27 KillPWLTimer();
28}
29
30int32_t CPWL_Timer::SetPWLTimer(int32_t nElapse) {
31 if (m_nTimerID != 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -070032 KillPWLTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033 m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc);
34
35 GetPWLTimeMap()[m_nTimerID] = this;
36 return m_nTimerID;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037}
38
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039void CPWL_Timer::KillPWLTimer() {
40 if (m_nTimerID == 0)
41 return;
Lei Zhang606346f2015-06-19 18:11:07 -070042
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 m_pSystemHandler->KillTimer(m_nTimerID);
44 GetPWLTimeMap().erase(m_nTimerID);
45 m_nTimerID = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046}
47
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048void CPWL_Timer::TimerProc(int32_t idEvent) {
49 auto it = GetPWLTimeMap().find(idEvent);
50 if (it == GetPWLTimeMap().end())
51 return;
Lei Zhang606346f2015-06-19 18:11:07 -070052
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 CPWL_Timer* pTimer = it->second;
54 if (pTimer->m_pAttached)
55 pTimer->m_pAttached->TimerProc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056}
57
thestig1cd352e2016-06-07 17:53:06 -070058CPWL_TimerHandler::CPWL_TimerHandler() : m_pTimer(nullptr) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059
60CPWL_TimerHandler::~CPWL_TimerHandler() {
61 delete m_pTimer;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062}
63
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064void CPWL_TimerHandler::BeginTimer(int32_t nElapse) {
65 if (!m_pTimer)
66 m_pTimer = new CPWL_Timer(this, GetSystemHandler());
67
68 if (m_pTimer)
69 m_pTimer->SetPWLTimer(nElapse);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070}
71
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072void CPWL_TimerHandler::EndTimer() {
73 if (m_pTimer)
74 m_pTimer->KillPWLTimer();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075}
76
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077void CPWL_TimerHandler::TimerProc() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079class CPWL_MsgControl {
80 friend class CPWL_Wnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 public:
Lei Zhangc2fb35f2016-01-05 16:46:58 -080083 explicit CPWL_MsgControl(CPWL_Wnd* pWnd) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 m_pCreatedWnd = pWnd;
85 Default();
86 }
87
Dan Sinclairf766ad22016-03-14 13:51:24 -040088 ~CPWL_MsgControl() { Default(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089
90 void Default() {
91 m_aMousePath.RemoveAll();
92 m_aKeyboardPath.RemoveAll();
thestig1cd352e2016-06-07 17:53:06 -070093 m_pMainMouseWnd = nullptr;
94 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095 }
96
97 FX_BOOL IsWndCreated(const CPWL_Wnd* pWnd) const {
98 return m_pCreatedWnd == pWnd;
99 }
100
101 FX_BOOL IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
102 return pWnd == m_pMainMouseWnd;
103 }
104
105 FX_BOOL IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800106 if (pWnd) {
107 for (int32_t i = 0, sz = m_aMousePath.GetSize(); i < sz; i++) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 if (m_aMousePath.GetAt(i) == pWnd)
109 return TRUE;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800110 }
111 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112
113 return FALSE;
114 }
115
116 FX_BOOL IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
117 return pWnd == m_pMainKeyboardWnd;
118 }
119
120 FX_BOOL IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800121 if (pWnd) {
122 for (int32_t i = 0, sz = m_aKeyboardPath.GetSize(); i < sz; i++) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 if (m_aKeyboardPath.GetAt(i) == pWnd)
124 return TRUE;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800125 }
126 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127
128 return FALSE;
129 }
130
131 void SetFocus(CPWL_Wnd* pWnd) {
132 m_aKeyboardPath.RemoveAll();
133
134 if (pWnd) {
135 m_pMainKeyboardWnd = pWnd;
136
137 CPWL_Wnd* pParent = pWnd;
138 while (pParent) {
139 m_aKeyboardPath.Add(pParent);
140 pParent = pParent->GetParentWindow();
141 }
142
143 pWnd->OnSetFocus();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700144 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700146
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147 void KillFocus() {
148 if (m_aKeyboardPath.GetSize() > 0)
149 if (CPWL_Wnd* pWnd = m_aKeyboardPath.GetAt(0))
150 pWnd->OnKillFocus();
151
thestig1cd352e2016-06-07 17:53:06 -0700152 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700153 m_aKeyboardPath.RemoveAll();
154 }
155
156 void SetCapture(CPWL_Wnd* pWnd) {
157 m_aMousePath.RemoveAll();
158
159 if (pWnd) {
160 m_pMainMouseWnd = pWnd;
161
162 CPWL_Wnd* pParent = pWnd;
163 while (pParent) {
164 m_aMousePath.Add(pParent);
165 pParent = pParent->GetParentWindow();
166 }
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 ReleaseCapture() {
thestig1cd352e2016-06-07 17:53:06 -0700171 m_pMainMouseWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 m_aMousePath.RemoveAll();
173 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700174
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 private:
176 CFX_ArrayTemplate<CPWL_Wnd*> m_aMousePath;
177 CFX_ArrayTemplate<CPWL_Wnd*> m_aKeyboardPath;
178 CPWL_Wnd* m_pCreatedWnd;
179 CPWL_Wnd* m_pMainMouseWnd;
180 CPWL_Wnd* m_pMainKeyboardWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700181};
182
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183CPWL_Wnd::CPWL_Wnd()
thestig1cd352e2016-06-07 17:53:06 -0700184 : m_pVScrollBar(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 m_rcWindow(),
186 m_rcClip(),
187 m_bCreated(FALSE),
188 m_bVisible(FALSE),
189 m_bNotifying(FALSE),
190 m_bEnabled(TRUE) {}
191
192CPWL_Wnd::~CPWL_Wnd() {
193 ASSERT(m_bCreated == FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700194}
195
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196CFX_ByteString CPWL_Wnd::GetClassName() const {
197 return "CPWL_Wnd";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700198}
199
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) {
201 if (!IsValid()) {
202 m_sPrivateParam = cp;
203
204 OnCreate(m_sPrivateParam);
205
206 m_sPrivateParam.rcRectWnd.Normalize();
207 m_rcWindow = m_sPrivateParam.rcRectWnd;
208 m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f);
209
210 CreateMsgControl();
211
212 if (m_sPrivateParam.pParentWnd)
213 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD);
214
215 PWL_CREATEPARAM ccp = m_sPrivateParam;
216
217 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
Tom Sepez60d909e2015-12-10 15:34:55 -0800218 ccp.mtChild = CFX_Matrix(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219
220 CreateScrollBar(ccp);
221 CreateChildWnd(ccp);
222
223 m_bVisible = HasFlag(PWS_VISIBLE);
224
225 OnCreated();
226
227 RePosChildWnd();
228 m_bCreated = TRUE;
229 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700230}
231
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234void CPWL_Wnd::OnCreated() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700235
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236void CPWL_Wnd::OnDestroy() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700237
Lei Zhangab5537d2016-01-06 14:58:14 -0800238void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) {
239 if (m_sPrivateParam.pFocusHandler == handler)
240 m_sPrivateParam.pFocusHandler = nullptr;
241}
242
243void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) {
244 if (m_sPrivateParam.pProvider == provider)
245 m_sPrivateParam.pProvider = nullptr;
246}
247
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248void CPWL_Wnd::Destroy() {
249 KillFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700250
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 OnDestroy();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700252
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253 if (m_bCreated) {
254 for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
255 if (CPWL_Wnd* pChild = m_aChildren[i]) {
256 pChild->Destroy();
257 delete pChild;
thestig1cd352e2016-06-07 17:53:06 -0700258 pChild = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259 }
260 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700261
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262 if (m_sPrivateParam.pParentWnd)
263 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD);
264 m_bCreated = FALSE;
265 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700266
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700267 DestroyMsgControl();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700268
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269 FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM));
270 m_aChildren.RemoveAll();
thestig1cd352e2016-06-07 17:53:06 -0700271 m_pVScrollBar = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700273
Tom Sepez281a9ea2016-02-26 14:24:28 -0800274void CPWL_Wnd::Move(const CFX_FloatRect& rcNew,
275 FX_BOOL bReset,
276 FX_BOOL bRefresh) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 if (IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800278 CFX_FloatRect rcOld = GetWindowRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700279
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 m_rcWindow = rcNew;
281 m_rcWindow.Normalize();
282
283 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
284 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
285 if (bReset) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700286 RePosChildWnd();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700288 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289 if (bRefresh) {
290 InvalidateRectMove(rcOld, rcNew);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700291 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700292
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 m_sPrivateParam.rcRectWnd = m_rcWindow;
294 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700295}
296
Tom Sepez281a9ea2016-02-26 14:24:28 -0800297void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
298 const CFX_FloatRect& rcNew) {
299 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700301
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 InvalidateRect(&rcUnion);
303}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700304
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) {
306 if (IsValid() && IsVisible()) {
307 GetThisAppearanceStream(sAppStream);
308 GetChildAppearanceStream(sAppStream);
309 }
310}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700311
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312// if don't set,Get default apperance stream
313void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800314 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315 if (!rectWnd.IsEmpty()) {
316 CFX_ByteTextBuf sThis;
317
318 if (HasFlag(PWS_BACKGROUND))
319 sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor());
320
321 if (HasFlag(PWS_BORDER)) {
322 sThis << CPWL_Utils::GetBorderAppStream(
323 rectWnd, (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
324 GetBorderLeftTopColor(GetBorderStyle()),
325 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
326 GetBorderDash());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700327 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328
329 sAppStream << sThis;
330 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700331}
332
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) {
334 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
335 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
336 pChild->GetAppearanceStream(sAppStream);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700337 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700338 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700339}
340
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800342 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343 if (IsValid() && IsVisible()) {
344 DrawThisAppearance(pDevice, pUser2Device);
345 DrawChildAppearance(pDevice, pUser2Device);
346 }
347}
348
349void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800350 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800351 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352 if (!rectWnd.IsEmpty()) {
353 if (HasFlag(PWS_BACKGROUND)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800354 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355 rectWnd, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
356 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
357 GetBackgroundColor(), GetTransparency());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700358 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359
360 if (HasFlag(PWS_BORDER))
Lei Zhang7457e382016-01-06 23:00:34 -0800361 CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd,
362 (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
363 GetBorderLeftTopColor(GetBorderStyle()),
364 GetBorderRightBottomColor(GetBorderStyle()),
365 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367}
368
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800370 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
372 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
Tom Sepez60d909e2015-12-10 15:34:55 -0800373 CFX_Matrix mt = pChild->GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374 if (mt.IsIdentity()) {
375 pChild->DrawAppearance(pDevice, pUser2Device);
376 } else {
377 mt.Concat(*pUser2Device);
378 pChild->DrawAppearance(pDevice, &mt);
379 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700380 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700382}
383
Tom Sepez281a9ea2016-02-26 14:24:28 -0800384void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385 if (IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800386 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387
388 if (!HasFlag(PWS_NOREFRESHCLIP)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800389 CFX_FloatRect rcClip = GetClipRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390 if (!rcClip.IsEmpty()) {
391 rcRefresh.Intersect(rcClip);
392 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700393 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700394
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395 FX_RECT rcWin = PWLtoWnd(rcRefresh);
396 rcWin.left -= PWL_INVALIDATE_INFLATE;
397 rcWin.top -= PWL_INVALIDATE_INFLATE;
398 rcWin.right += PWL_INVALIDATE_INFLATE;
399 rcWin.bottom += PWL_INVALIDATE_INFLATE;
400
dsinclairb9590102016-04-27 06:38:59 -0700401 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402 if (FX_HWND hWnd = GetAttachedHWnd()) {
403 pSH->InvalidateRect(hWnd, rcWin);
404 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700405 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700407}
408
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
tsepezc3255f52016-03-25 14:52:27 -0700410 FX_BOOL CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411 if (IsValid() && IsVisible() && IsEnabled()) { \
412 if (IsWndCaptureKeyboard(this)) { \
413 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
414 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
415 if (IsWndCaptureKeyboard(pChild)) { \
416 return pChild->key_method_name(nChar, nFlag); \
417 } \
418 } \
419 } \
420 } \
421 } \
422 return FALSE; \
423 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700424
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
Tom Sepez281a9ea2016-02-26 14:24:28 -0800426 FX_BOOL CPWL_Wnd::mouse_method_name(const CFX_FloatPoint& point, \
tsepezc3255f52016-03-25 14:52:27 -0700427 uint32_t nFlag) { \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 if (IsValid() && IsVisible() && IsEnabled()) { \
429 if (IsWndCaptureMouse(this)) { \
430 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
431 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
432 if (IsWndCaptureMouse(pChild)) { \
433 return pChild->mouse_method_name(pChild->ParentToChild(point), \
434 nFlag); \
435 } \
436 } \
437 } \
438 SetCursor(); \
439 } else { \
440 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
441 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
442 if (pChild->WndHitTest(pChild->ParentToChild(point))) { \
443 return pChild->mouse_method_name(pChild->ParentToChild(point), \
444 nFlag); \
445 } \
446 } \
447 } \
448 if (WndHitTest(point)) \
449 SetCursor(); \
450 } \
451 } \
452 return FALSE; \
453 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700454
455PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
456PWL_IMPLEMENT_KEY_METHOD(OnKeyUp)
457PWL_IMPLEMENT_KEY_METHOD(OnChar)
458
459PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
460PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
461PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
462PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk)
463PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown)
464PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700465PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
466PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
467PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
468
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469FX_BOOL CPWL_Wnd::OnMouseWheel(short zDelta,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800470 const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700471 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472 if (IsValid() && IsVisible() && IsEnabled()) {
473 SetCursor();
474 if (IsWndCaptureKeyboard(this)) {
475 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
476 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
477 if (IsWndCaptureKeyboard(pChild)) {
478 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point),
479 nFlag);
480 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700481 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700483 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700484 }
485 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700486}
487
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
489 m_aChildren.Add(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490}
491
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
493 for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
494 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
495 if (pChild == pWnd) {
496 m_aChildren.RemoveAt(i);
497 break;
498 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700499 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700501}
502
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700504 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 intptr_t wParam,
506 intptr_t lParam) {
507 switch (msg) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700508 case PNM_ADDCHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 AddChild(pWnd);
510 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700511 case PNM_REMOVECHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512 RemoveChild(pWnd);
513 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700514 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 break;
516 }
517}
518
519FX_BOOL CPWL_Wnd::IsValid() const {
520 return m_bCreated;
521}
522
Lei Zhang7457e382016-01-06 23:00:34 -0800523const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 return m_sPrivateParam;
525}
526
527CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
528 return m_sPrivateParam.pParentWnd;
529}
530
Tom Sepez281a9ea2016-02-26 14:24:28 -0800531CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 return m_rcWindow;
533}
534
Tom Sepez281a9ea2016-02-26 14:24:28 -0800535CFX_FloatRect CPWL_Wnd::GetClientRect() const {
536 CFX_FloatRect rcWindow = GetWindowRect();
537 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 rcWindow, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
539 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
540 rcClient.right -= pVSB->GetScrollBarWidth();
541
542 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800543 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544}
545
Tom Sepez281a9ea2016-02-26 14:24:28 -0800546CFX_FloatPoint CPWL_Wnd::GetCenterPoint() const {
547 CFX_FloatRect rcClient = GetClientRect();
548 return CFX_FloatPoint((rcClient.left + rcClient.right) * 0.5f,
549 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550}
551
tsepezc3255f52016-03-25 14:52:27 -0700552FX_BOOL CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
554}
555
tsepezc3255f52016-03-25 14:52:27 -0700556void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 m_sPrivateParam.dwFlags &= ~dwFlags;
558}
559
tsepezc3255f52016-03-25 14:52:27 -0700560void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 m_sPrivateParam.dwFlags |= dwFlags;
562}
563
564CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
565 return m_sPrivateParam.sBackgroundColor;
566}
567
568void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
569 m_sPrivateParam.sBackgroundColor = color;
570}
571
572void CPWL_Wnd::SetTextColor(const CPWL_Color& color) {
573 m_sPrivateParam.sTextColor = color;
574}
575
576void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color& color) {
577 m_sPrivateParam.sTextStrokeColor = color;
578}
579
580CPWL_Color CPWL_Wnd::GetTextColor() const {
581 return m_sPrivateParam.sTextColor;
582}
583
584CPWL_Color CPWL_Wnd::GetTextStrokeColor() const {
585 return m_sPrivateParam.sTextStrokeColor;
586}
587
dsinclair92cb5e52016-05-16 11:38:28 -0700588BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 return m_sPrivateParam.nBorderStyle;
590}
591
dsinclair92cb5e52016-05-16 11:38:28 -0700592void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593 if (HasFlag(PWS_BORDER))
594 m_sPrivateParam.nBorderStyle = nBorderStyle;
595}
596
597int32_t CPWL_Wnd::GetBorderWidth() const {
598 if (HasFlag(PWS_BORDER))
599 return m_sPrivateParam.dwBorderWidth;
600
601 return 0;
602}
603
604int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 return 0;
606}
607
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608CPWL_Color CPWL_Wnd::GetBorderColor() const {
609 if (HasFlag(PWS_BORDER))
610 return m_sPrivateParam.sBorderColor;
611
612 return CPWL_Color();
613}
614
Lei Zhang7457e382016-01-06 23:00:34 -0800615const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 return m_sPrivateParam.sDash;
617}
618
619void* CPWL_Wnd::GetAttachedData() const {
620 return m_sPrivateParam.pAttachedData;
621}
622
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
624 if (HasFlag(PWS_VSCROLL))
625 return m_pVScrollBar;
626
thestig1cd352e2016-06-07 17:53:06 -0700627 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628}
629
630void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
631 CreateVScrollBar(cp);
632}
633
634void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
635 if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) {
636 PWL_CREATEPARAM scp = cp;
637
638 // flags
639 scp.dwFlags =
640 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
641
642 scp.pParentWnd = this;
643 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
644 scp.eCursorType = FXCT_ARROW;
645 scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY;
646
Lei Zhange00660b2015-08-13 15:40:18 -0700647 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
648 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 }
650}
651
652void CPWL_Wnd::SetCapture() {
653 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
654 pMsgCtrl->SetCapture(this);
655}
656
657void CPWL_Wnd::ReleaseCapture() {
658 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++)
659 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
660 pChild->ReleaseCapture();
661
662 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
663 pMsgCtrl->ReleaseCapture();
664}
665
666void CPWL_Wnd::SetFocus() {
667 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
668 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
669 pMsgCtrl->KillFocus();
670 pMsgCtrl->SetFocus(this);
671 }
672}
673
674void CPWL_Wnd::KillFocus() {
675 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
676 if (pMsgCtrl->IsWndCaptureKeyboard(this))
677 pMsgCtrl->KillFocus();
678 }
679}
680
681void CPWL_Wnd::OnSetFocus() {}
682
683void CPWL_Wnd::OnKillFocus() {}
684
Tom Sepez281a9ea2016-02-26 14:24:28 -0800685FX_BOOL CPWL_Wnd::WndHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 return IsValid() && IsVisible() && GetWindowRect().Contains(point.x, point.y);
687}
688
Tom Sepez281a9ea2016-02-26 14:24:28 -0800689FX_BOOL CPWL_Wnd::ClientHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 return IsValid() && IsVisible() && GetClientRect().Contains(point.x, point.y);
691}
692
693const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
694 if (m_sPrivateParam.pParentWnd)
695 return m_sPrivateParam.pParentWnd->GetRootWnd();
696
697 return this;
698}
699
700void CPWL_Wnd::SetVisible(FX_BOOL bVisible) {
701 if (IsValid()) {
702 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
703 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
704 pChild->SetVisible(bVisible);
705 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700706 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707
708 if (bVisible != m_bVisible) {
709 m_bVisible = bVisible;
710 RePosChildWnd();
711 InvalidateRect();
712 }
713 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700714}
715
Tom Sepez281a9ea2016-02-26 14:24:28 -0800716void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717 m_rcClip = rect;
718 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700719}
720
Tom Sepez281a9ea2016-02-26 14:24:28 -0800721const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700723}
724
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725FX_BOOL CPWL_Wnd::IsReadOnly() const {
726 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700727}
728
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729void CPWL_Wnd::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800730 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
732
733 CPWL_ScrollBar* pVSB = GetVScrollBar();
734
Tom Sepez281a9ea2016-02-26 14:24:28 -0800735 CFX_FloatRect rcVScroll =
736 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
737 rcContent.right - 1.0f, rcContent.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738
739 if (pVSB)
740 pVSB->Move(rcVScroll, TRUE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700741}
742
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
744
745void CPWL_Wnd::SetCursor() {
746 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700747 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748 int32_t nCursorType = GetCreationParam().eCursorType;
749 pSH->SetCursor(nCursorType);
750 }
751 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700752}
753
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700754void CPWL_Wnd::CreateMsgControl() {
755 if (!m_sPrivateParam.pMsgControl)
756 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700757}
758
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700759void CPWL_Wnd::DestroyMsgControl() {
760 if (CPWL_MsgControl* pMsgControl = GetMsgControl())
761 if (pMsgControl->IsWndCreated(this))
762 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700763}
764
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700765CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
766 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700767}
768
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769FX_BOOL CPWL_Wnd::IsCaptureMouse() const {
770 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700771}
772
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700773FX_BOOL CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
774 if (CPWL_MsgControl* pCtrl = GetMsgControl())
775 return pCtrl->IsWndCaptureMouse(pWnd);
776
777 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700778}
779
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780FX_BOOL CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
781 if (CPWL_MsgControl* pCtrl = GetMsgControl())
782 return pCtrl->IsWndCaptureKeyboard(pWnd);
783
784 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700785}
786
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700787FX_BOOL CPWL_Wnd::IsFocused() const {
788 if (CPWL_MsgControl* pCtrl = GetMsgControl())
789 return pCtrl->IsMainCaptureKeyboard(this);
790
791 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700792}
793
Tom Sepez281a9ea2016-02-26 14:24:28 -0800794CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700796}
797
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798FX_FLOAT CPWL_Wnd::GetFontSize() const {
799 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700800}
801
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize) {
803 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700804}
805
dsinclairb9590102016-04-27 06:38:59 -0700806CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700807 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700808}
809
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700810IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
811 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700812}
813
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700814IPWL_Provider* CPWL_Wnd::GetProvider() const {
815 return m_sPrivateParam.pProvider;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700816}
817
dsinclairc7a73492016-04-05 12:01:42 -0700818IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700819 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700820}
821
dsinclair92cb5e52016-05-16 11:38:28 -0700822CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700823 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700824 case BorderStyle::BEVELED:
825 return CPWL_Color(COLORTYPE_GRAY, 1);
826 case BorderStyle::INSET:
827 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
828 default:
829 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700830 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700831}
832
dsinclair92cb5e52016-05-16 11:38:28 -0700833CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700834 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700835 case BorderStyle::BEVELED:
836 return CPWL_Utils::DevideColor(GetBackgroundColor(), 2);
837 case BorderStyle::INSET:
838 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
839 default:
840 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700842}
843
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844int32_t CPWL_Wnd::GetTransparency() {
845 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700846}
847
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
849 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
850 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
851 pChild->SetTransparency(nTransparency);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700852 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700853 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700854
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700855 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700856}
857
Tom Sepez60d909e2015-12-10 15:34:55 -0800858CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
859 CFX_Matrix mt = GetChildToRoot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700860
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700861 if (IPWL_Provider* pProvider = GetProvider()) {
862 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700863 return mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864 }
865
866 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700867}
868
Tom Sepez281a9ea2016-02-26 14:24:28 -0800869void CPWL_Wnd::PWLtoWnd(const CFX_FloatPoint& point,
870 int32_t& x,
871 int32_t& y) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800872 CFX_Matrix mt = GetWindowMatrix();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800873 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700874 mt.Transform(pt.x, pt.y);
875 x = (int32_t)(pt.x + 0.5);
876 y = (int32_t)(pt.y + 0.5);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700877}
878
Tom Sepez281a9ea2016-02-26 14:24:28 -0800879FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
880 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800881 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700882 mt.TransformRect(rcTemp);
883 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
884 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700885}
886
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700887FX_HWND CPWL_Wnd::GetAttachedHWnd() const {
888 return m_sPrivateParam.hAttachedWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700889}
890
Tom Sepez281a9ea2016-02-26 14:24:28 -0800891CFX_FloatPoint CPWL_Wnd::ChildToParent(const CFX_FloatPoint& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800892 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700893 if (mt.IsIdentity())
894 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700895
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 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700899}
900
Tom Sepez281a9ea2016-02-26 14:24:28 -0800901CFX_FloatRect CPWL_Wnd::ChildToParent(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800902 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700903 if (mt.IsIdentity())
904 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700905
Tom Sepez281a9ea2016-02-26 14:24:28 -0800906 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700907 mt.TransformRect(rc);
908 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700909}
910
Tom Sepez281a9ea2016-02-26 14:24:28 -0800911CFX_FloatPoint CPWL_Wnd::ParentToChild(const CFX_FloatPoint& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800912 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700913 if (mt.IsIdentity())
914 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700915
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700916 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800917 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700918 mt.Transform(pt.x, pt.y);
919 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700920}
921
Tom Sepez281a9ea2016-02-26 14:24:28 -0800922CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800923 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700924 if (mt.IsIdentity())
925 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700926
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700927 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800928 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700929 mt.TransformRect(rc);
930 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700931}
932
Tom Sepez60d909e2015-12-10 15:34:55 -0800933CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
934 CFX_Matrix mt(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700935 if (HasFlag(PWS_CHILD)) {
936 const CPWL_Wnd* pParent = this;
937 while (pParent) {
938 mt.Concat(pParent->GetChildMatrix());
939 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700940 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700941 }
942 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700943}
944
Tom Sepez60d909e2015-12-10 15:34:55 -0800945CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700946 if (HasFlag(PWS_CHILD))
947 return m_sPrivateParam.mtChild;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700948
Tom Sepez60d909e2015-12-10 15:34:55 -0800949 return CFX_Matrix(1, 0, 0, 1, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700950}
951
Tom Sepez60d909e2015-12-10 15:34:55 -0800952void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700953 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700954}
955
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700956const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
957 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
958 return pMsgCtrl->m_pMainKeyboardWnd;
959 }
960
thestig1cd352e2016-06-07 17:53:06 -0700961 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700962}
963
964void CPWL_Wnd::EnableWindow(FX_BOOL bEnable) {
965 if (m_bEnabled != bEnable) {
966 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
967 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
968 pChild->EnableWindow(bEnable);
969 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700970 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700971
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700972 m_bEnabled = bEnable;
973
974 if (bEnable)
975 OnEnabled();
976 else
977 OnDisabled();
978 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700979}
980
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700981FX_BOOL CPWL_Wnd::IsEnabled() {
982 return m_bEnabled;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700983}
984
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700985void CPWL_Wnd::OnEnabled() {}
986
987void CPWL_Wnd::OnDisabled() {}
988
tsepezc3255f52016-03-25 14:52:27 -0700989FX_BOOL CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -0700990 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700991 return pSystemHandler->IsCTRLKeyDown(nFlag);
992 }
993
994 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700995}
996
tsepezc3255f52016-03-25 14:52:27 -0700997FX_BOOL CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -0700998 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700999 return pSystemHandler->IsSHIFTKeyDown(nFlag);
1000 }
1001
1002 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001003}
1004
tsepezc3255f52016-03-25 14:52:27 -07001005FX_BOOL CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001006 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001007 return pSystemHandler->IsALTKeyDown(nFlag);
1008 }
1009
1010 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001011}