blob: 78a4363aa557784d2e12f1321f9e1708345e2a19 [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"
tsepez36eb4bd2016-10-03 15:24:27 -070012#include "third_party/base/ptr_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013
Nico Weber9d8ec5a2015-08-04 13:00:21 -070014static std::map<int32_t, CPWL_Timer*>& GetPWLTimeMap() {
Bruce Dawson26d96ff2015-01-05 15:31:49 -080015 // Leak the object at shutdown.
Lei Zhang606346f2015-06-19 18:11:07 -070016 static auto timeMap = new std::map<int32_t, CPWL_Timer*>;
Bruce Dawson26d96ff2015-01-05 15:31:49 -080017 return *timeMap;
18}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019
weili625ad662016-06-15 11:21:33 -070020PWL_CREATEPARAM::PWL_CREATEPARAM()
21 : rcRectWnd(0, 0, 0, 0),
22 pSystemHandler(nullptr),
23 pFontMap(nullptr),
24 pProvider(nullptr),
25 pFocusHandler(nullptr),
26 dwFlags(0),
27 sBackgroundColor(),
dsinclair8faac622016-09-15 12:41:50 -070028 pAttachedWidget(nullptr),
weili625ad662016-06-15 11:21:33 -070029 nBorderStyle(BorderStyle::SOLID),
30 dwBorderWidth(1),
31 sBorderColor(),
32 sTextColor(),
33 sTextStrokeColor(),
34 nTransparency(255),
35 fFontSize(PWL_DEFAULT_FONTSIZE),
36 sDash(3, 0, 0),
37 pAttachedData(nullptr),
38 pParentWnd(nullptr),
39 pMsgControl(nullptr),
40 eCursorType(FXCT_ARROW),
41 mtChild(1, 0, 0, 1, 0, 0) {}
42
43PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default;
44
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached,
dsinclairb9590102016-04-27 06:38:59 -070046 CFX_SystemHandler* pSystemHandler)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 : m_nTimerID(0), m_pAttached(pAttached), m_pSystemHandler(pSystemHandler) {
Lei Zhang96660d62015-12-14 18:27:25 -080048 ASSERT(m_pAttached);
49 ASSERT(m_pSystemHandler);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050}
51
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052CPWL_Timer::~CPWL_Timer() {
53 KillPWLTimer();
54}
55
56int32_t CPWL_Timer::SetPWLTimer(int32_t nElapse) {
57 if (m_nTimerID != 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -070058 KillPWLTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc);
60
61 GetPWLTimeMap()[m_nTimerID] = this;
62 return m_nTimerID;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070063}
64
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065void CPWL_Timer::KillPWLTimer() {
66 if (m_nTimerID == 0)
67 return;
Lei Zhang606346f2015-06-19 18:11:07 -070068
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 m_pSystemHandler->KillTimer(m_nTimerID);
70 GetPWLTimeMap().erase(m_nTimerID);
71 m_nTimerID = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072}
73
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074void CPWL_Timer::TimerProc(int32_t idEvent) {
75 auto it = GetPWLTimeMap().find(idEvent);
76 if (it == GetPWLTimeMap().end())
77 return;
Lei Zhang606346f2015-06-19 18:11:07 -070078
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 CPWL_Timer* pTimer = it->second;
80 if (pTimer->m_pAttached)
81 pTimer->m_pAttached->TimerProc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070082}
83
weili2d5b0202016-08-03 11:06:49 -070084CPWL_TimerHandler::CPWL_TimerHandler() {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085
weili2d5b0202016-08-03 11:06:49 -070086CPWL_TimerHandler::~CPWL_TimerHandler() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088void CPWL_TimerHandler::BeginTimer(int32_t nElapse) {
89 if (!m_pTimer)
tsepez36eb4bd2016-10-03 15:24:27 -070090 m_pTimer = pdfium::MakeUnique<CPWL_Timer>(this, GetSystemHandler());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091
tsepez36eb4bd2016-10-03 15:24:27 -070092 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
tsepez4cf55152016-11-02 14:37:54 -0700120 bool IsWndCreated(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 return m_pCreatedWnd == pWnd;
122 }
123
tsepez4cf55152016-11-02 14:37:54 -0700124 bool IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 return pWnd == m_pMainMouseWnd;
126 }
127
tsepez4cf55152016-11-02 14:37:54 -0700128 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)
tsepez4cf55152016-11-02 14:37:54 -0700132 return true;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800133 }
134 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135
tsepez4cf55152016-11-02 14:37:54 -0700136 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137 }
138
tsepez4cf55152016-11-02 14:37:54 -0700139 bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140 return pWnd == m_pMainKeyboardWnd;
141 }
142
tsepez4cf55152016-11-02 14:37:54 -0700143 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)
tsepez4cf55152016-11-02 14:37:54 -0700147 return true;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800148 }
149 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150
tsepez4cf55152016-11-02 14:37:54 -0700151 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152 }
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(),
tsepez4cf55152016-11-02 14:37:54 -0700210 m_bCreated(false),
211 m_bVisible(false),
212 m_bNotifying(false),
213 m_bEnabled(true) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214
215CPWL_Wnd::~CPWL_Wnd() {
tsepez4cf55152016-11-02 14:37:54 -0700216 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();
tsepez4cf55152016-11-02 14:37:54 -0700251 m_bCreated = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 }
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);
tsepez4cf55152016-11-02 14:37:54 -0700287 m_bCreated = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 }
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
tsepez4cf55152016-11-02 14:37:54 -0700297void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 if (IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800299 CFX_FloatRect rcOld = GetWindowRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700300
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301 m_rcWindow = rcNew;
302 m_rcWindow.Normalize();
303
304 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
305 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
306 if (bReset) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700307 RePosChildWnd();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700308 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700309 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310 if (bRefresh) {
311 InvalidateRectMove(rcOld, rcNew);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700312 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700313
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314 m_sPrivateParam.rcRectWnd = m_rcWindow;
315 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700316}
317
Tom Sepez281a9ea2016-02-26 14:24:28 -0800318void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
319 const CFX_FloatRect& rcNew) {
320 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700322
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 InvalidateRect(&rcUnion);
324}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700325
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) {
327 if (IsValid() && IsVisible()) {
328 GetThisAppearanceStream(sAppStream);
329 GetChildAppearanceStream(sAppStream);
330 }
331}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700332
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333// if don't set,Get default apperance stream
334void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800335 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336 if (!rectWnd.IsEmpty()) {
337 CFX_ByteTextBuf sThis;
338
339 if (HasFlag(PWS_BACKGROUND))
340 sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor());
341
342 if (HasFlag(PWS_BORDER)) {
343 sThis << CPWL_Utils::GetBorderAppStream(
344 rectWnd, (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
345 GetBorderLeftTopColor(GetBorderStyle()),
346 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
347 GetBorderDash());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700348 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349
350 sAppStream << sThis;
351 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700352}
353
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) {
355 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
356 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
357 pChild->GetAppearanceStream(sAppStream);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700358 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700360}
361
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800363 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 if (IsValid() && IsVisible()) {
365 DrawThisAppearance(pDevice, pUser2Device);
366 DrawChildAppearance(pDevice, pUser2Device);
367 }
368}
369
370void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800371 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800372 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373 if (!rectWnd.IsEmpty()) {
374 if (HasFlag(PWS_BACKGROUND)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800375 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376 rectWnd, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
377 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
378 GetBackgroundColor(), GetTransparency());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700379 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380
381 if (HasFlag(PWS_BORDER))
Lei Zhang7457e382016-01-06 23:00:34 -0800382 CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd,
383 (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
384 GetBorderLeftTopColor(GetBorderStyle()),
385 GetBorderRightBottomColor(GetBorderStyle()),
386 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700388}
389
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800391 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
393 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
Tom Sepez60d909e2015-12-10 15:34:55 -0800394 CFX_Matrix mt = pChild->GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395 if (mt.IsIdentity()) {
396 pChild->DrawAppearance(pDevice, pUser2Device);
397 } else {
398 mt.Concat(*pUser2Device);
399 pChild->DrawAppearance(pDevice, &mt);
400 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700401 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700403}
404
Tom Sepez281a9ea2016-02-26 14:24:28 -0800405void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406 if (IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800407 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408
409 if (!HasFlag(PWS_NOREFRESHCLIP)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800410 CFX_FloatRect rcClip = GetClipRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411 if (!rcClip.IsEmpty()) {
412 rcRefresh.Intersect(rcClip);
413 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700414 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700415
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416 FX_RECT rcWin = PWLtoWnd(rcRefresh);
417 rcWin.left -= PWL_INVALIDATE_INFLATE;
418 rcWin.top -= PWL_INVALIDATE_INFLATE;
419 rcWin.right += PWL_INVALIDATE_INFLATE;
420 rcWin.bottom += PWL_INVALIDATE_INFLATE;
421
dsinclairb9590102016-04-27 06:38:59 -0700422 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
dsinclair8faac622016-09-15 12:41:50 -0700423 if (CPDFSDK_Widget* widget = m_sPrivateParam.pAttachedWidget)
424 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700425 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700427}
428
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
tsepez4cf55152016-11-02 14:37:54 -0700430 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431 if (IsValid() && IsVisible() && IsEnabled()) { \
432 if (IsWndCaptureKeyboard(this)) { \
433 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
434 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
435 if (IsWndCaptureKeyboard(pChild)) { \
436 return pChild->key_method_name(nChar, nFlag); \
437 } \
438 } \
439 } \
440 } \
441 } \
tsepez4cf55152016-11-02 14:37:54 -0700442 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700444
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
tsepez4cf55152016-11-02 14:37:54 -0700446 bool CPWL_Wnd::mouse_method_name(const CFX_FloatPoint& point, \
447 uint32_t nFlag) { \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448 if (IsValid() && IsVisible() && IsEnabled()) { \
449 if (IsWndCaptureMouse(this)) { \
450 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
451 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
452 if (IsWndCaptureMouse(pChild)) { \
453 return pChild->mouse_method_name(pChild->ParentToChild(point), \
454 nFlag); \
455 } \
456 } \
457 } \
458 SetCursor(); \
459 } else { \
460 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
461 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
462 if (pChild->WndHitTest(pChild->ParentToChild(point))) { \
463 return pChild->mouse_method_name(pChild->ParentToChild(point), \
464 nFlag); \
465 } \
466 } \
467 } \
468 if (WndHitTest(point)) \
469 SetCursor(); \
470 } \
471 } \
tsepez4cf55152016-11-02 14:37:54 -0700472 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700474
475PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
476PWL_IMPLEMENT_KEY_METHOD(OnKeyUp)
477PWL_IMPLEMENT_KEY_METHOD(OnChar)
478
479PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
480PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
481PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
482PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk)
483PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown)
484PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700485PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
486PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
487PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
488
tsepez4cf55152016-11-02 14:37:54 -0700489bool CPWL_Wnd::OnMouseWheel(short zDelta,
490 const CFX_FloatPoint& point,
491 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 if (IsValid() && IsVisible() && IsEnabled()) {
493 SetCursor();
494 if (IsWndCaptureKeyboard(this)) {
495 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
496 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
497 if (IsWndCaptureKeyboard(pChild)) {
498 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point),
499 nFlag);
500 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700501 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700503 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504 }
tsepez4cf55152016-11-02 14:37:54 -0700505 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700506}
507
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
509 m_aChildren.Add(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700510}
511
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
513 for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
514 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
515 if (pChild == pWnd) {
516 m_aChildren.RemoveAt(i);
517 break;
518 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700519 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700521}
522
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700524 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 intptr_t wParam,
526 intptr_t lParam) {
527 switch (msg) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700528 case PNM_ADDCHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529 AddChild(pWnd);
530 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700531 case PNM_REMOVECHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 RemoveChild(pWnd);
533 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700534 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 break;
536 }
537}
538
tsepez4cf55152016-11-02 14:37:54 -0700539bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 return m_bCreated;
541}
542
Lei Zhang7457e382016-01-06 23:00:34 -0800543const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 return m_sPrivateParam;
545}
546
547CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
548 return m_sPrivateParam.pParentWnd;
549}
550
Tom Sepez281a9ea2016-02-26 14:24:28 -0800551CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 return m_rcWindow;
553}
554
Tom Sepez281a9ea2016-02-26 14:24:28 -0800555CFX_FloatRect CPWL_Wnd::GetClientRect() const {
556 CFX_FloatRect rcWindow = GetWindowRect();
557 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 rcWindow, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
559 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
560 rcClient.right -= pVSB->GetScrollBarWidth();
561
562 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800563 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564}
565
Tom Sepez281a9ea2016-02-26 14:24:28 -0800566CFX_FloatPoint CPWL_Wnd::GetCenterPoint() const {
567 CFX_FloatRect rcClient = GetClientRect();
568 return CFX_FloatPoint((rcClient.left + rcClient.right) * 0.5f,
569 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570}
571
tsepez4cf55152016-11-02 14:37:54 -0700572bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
574}
575
tsepezc3255f52016-03-25 14:52:27 -0700576void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577 m_sPrivateParam.dwFlags &= ~dwFlags;
578}
579
tsepezc3255f52016-03-25 14:52:27 -0700580void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581 m_sPrivateParam.dwFlags |= dwFlags;
582}
583
584CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
585 return m_sPrivateParam.sBackgroundColor;
586}
587
588void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
589 m_sPrivateParam.sBackgroundColor = color;
590}
591
592void CPWL_Wnd::SetTextColor(const CPWL_Color& color) {
593 m_sPrivateParam.sTextColor = color;
594}
595
596void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color& color) {
597 m_sPrivateParam.sTextStrokeColor = color;
598}
599
600CPWL_Color CPWL_Wnd::GetTextColor() const {
601 return m_sPrivateParam.sTextColor;
602}
603
604CPWL_Color CPWL_Wnd::GetTextStrokeColor() const {
605 return m_sPrivateParam.sTextStrokeColor;
606}
607
dsinclair92cb5e52016-05-16 11:38:28 -0700608BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 return m_sPrivateParam.nBorderStyle;
610}
611
dsinclair92cb5e52016-05-16 11:38:28 -0700612void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613 if (HasFlag(PWS_BORDER))
614 m_sPrivateParam.nBorderStyle = nBorderStyle;
615}
616
617int32_t CPWL_Wnd::GetBorderWidth() const {
618 if (HasFlag(PWS_BORDER))
619 return m_sPrivateParam.dwBorderWidth;
620
621 return 0;
622}
623
624int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 return 0;
626}
627
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628CPWL_Color CPWL_Wnd::GetBorderColor() const {
629 if (HasFlag(PWS_BORDER))
630 return m_sPrivateParam.sBorderColor;
631
632 return CPWL_Color();
633}
634
Lei Zhang7457e382016-01-06 23:00:34 -0800635const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636 return m_sPrivateParam.sDash;
637}
638
639void* CPWL_Wnd::GetAttachedData() const {
640 return m_sPrivateParam.pAttachedData;
641}
642
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
644 if (HasFlag(PWS_VSCROLL))
645 return m_pVScrollBar;
646
thestig1cd352e2016-06-07 17:53:06 -0700647 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648}
649
650void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
651 CreateVScrollBar(cp);
652}
653
654void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
655 if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) {
656 PWL_CREATEPARAM scp = cp;
657
658 // flags
659 scp.dwFlags =
660 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
661
662 scp.pParentWnd = this;
663 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
664 scp.eCursorType = FXCT_ARROW;
665 scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY;
666
Lei Zhange00660b2015-08-13 15:40:18 -0700667 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
668 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669 }
670}
671
672void CPWL_Wnd::SetCapture() {
673 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
674 pMsgCtrl->SetCapture(this);
675}
676
677void CPWL_Wnd::ReleaseCapture() {
678 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++)
679 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
680 pChild->ReleaseCapture();
681
682 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
683 pMsgCtrl->ReleaseCapture();
684}
685
686void CPWL_Wnd::SetFocus() {
687 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
688 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
689 pMsgCtrl->KillFocus();
690 pMsgCtrl->SetFocus(this);
691 }
692}
693
694void CPWL_Wnd::KillFocus() {
695 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
696 if (pMsgCtrl->IsWndCaptureKeyboard(this))
697 pMsgCtrl->KillFocus();
698 }
699}
700
701void CPWL_Wnd::OnSetFocus() {}
702
703void CPWL_Wnd::OnKillFocus() {}
704
tsepez4cf55152016-11-02 14:37:54 -0700705bool CPWL_Wnd::WndHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 return IsValid() && IsVisible() && GetWindowRect().Contains(point.x, point.y);
707}
708
tsepez4cf55152016-11-02 14:37:54 -0700709bool CPWL_Wnd::ClientHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710 return IsValid() && IsVisible() && GetClientRect().Contains(point.x, point.y);
711}
712
713const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
714 if (m_sPrivateParam.pParentWnd)
715 return m_sPrivateParam.pParentWnd->GetRootWnd();
716
717 return this;
718}
719
tsepez4cf55152016-11-02 14:37:54 -0700720void CPWL_Wnd::SetVisible(bool bVisible) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721 if (IsValid()) {
722 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
723 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
724 pChild->SetVisible(bVisible);
725 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700726 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727
728 if (bVisible != m_bVisible) {
729 m_bVisible = bVisible;
730 RePosChildWnd();
731 InvalidateRect();
732 }
733 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700734}
735
Tom Sepez281a9ea2016-02-26 14:24:28 -0800736void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 m_rcClip = rect;
738 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700739}
740
Tom Sepez281a9ea2016-02-26 14:24:28 -0800741const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700743}
744
tsepez4cf55152016-11-02 14:37:54 -0700745bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700746 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700747}
748
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749void CPWL_Wnd::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800750 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
752
753 CPWL_ScrollBar* pVSB = GetVScrollBar();
754
Tom Sepez281a9ea2016-02-26 14:24:28 -0800755 CFX_FloatRect rcVScroll =
756 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
757 rcContent.right - 1.0f, rcContent.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758
759 if (pVSB)
tsepez4cf55152016-11-02 14:37:54 -0700760 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700761}
762
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700763void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
764
765void CPWL_Wnd::SetCursor() {
766 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700767 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768 int32_t nCursorType = GetCreationParam().eCursorType;
769 pSH->SetCursor(nCursorType);
770 }
771 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700772}
773
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700774void CPWL_Wnd::CreateMsgControl() {
775 if (!m_sPrivateParam.pMsgControl)
776 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700777}
778
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700779void CPWL_Wnd::DestroyMsgControl() {
780 if (CPWL_MsgControl* pMsgControl = GetMsgControl())
781 if (pMsgControl->IsWndCreated(this))
782 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700783}
784
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
786 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700787}
788
tsepez4cf55152016-11-02 14:37:54 -0700789bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700791}
792
tsepez4cf55152016-11-02 14:37:54 -0700793bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700794 if (CPWL_MsgControl* pCtrl = GetMsgControl())
795 return pCtrl->IsWndCaptureMouse(pWnd);
796
tsepez4cf55152016-11-02 14:37:54 -0700797 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700798}
799
tsepez4cf55152016-11-02 14:37:54 -0700800bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700801 if (CPWL_MsgControl* pCtrl = GetMsgControl())
802 return pCtrl->IsWndCaptureKeyboard(pWnd);
803
tsepez4cf55152016-11-02 14:37:54 -0700804 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700805}
806
tsepez4cf55152016-11-02 14:37:54 -0700807bool CPWL_Wnd::IsFocused() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700808 if (CPWL_MsgControl* pCtrl = GetMsgControl())
809 return pCtrl->IsMainCaptureKeyboard(this);
810
tsepez4cf55152016-11-02 14:37:54 -0700811 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700812}
813
Tom Sepez281a9ea2016-02-26 14:24:28 -0800814CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700815 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700816}
817
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818FX_FLOAT CPWL_Wnd::GetFontSize() const {
819 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700820}
821
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700822void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize) {
823 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700824}
825
dsinclairb9590102016-04-27 06:38:59 -0700826CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700827 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700828}
829
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700830IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
831 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700832}
833
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700834IPWL_Provider* CPWL_Wnd::GetProvider() const {
835 return m_sPrivateParam.pProvider;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700836}
837
dsinclairc7a73492016-04-05 12:01:42 -0700838IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700840}
841
dsinclair92cb5e52016-05-16 11:38:28 -0700842CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700843 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700844 case BorderStyle::BEVELED:
845 return CPWL_Color(COLORTYPE_GRAY, 1);
846 case BorderStyle::INSET:
847 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
848 default:
849 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700850 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700851}
852
dsinclair92cb5e52016-05-16 11:38:28 -0700853CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700854 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700855 case BorderStyle::BEVELED:
856 return CPWL_Utils::DevideColor(GetBackgroundColor(), 2);
857 case BorderStyle::INSET:
858 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
859 default:
860 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700861 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700862}
863
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864int32_t CPWL_Wnd::GetTransparency() {
865 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700866}
867
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700868void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
869 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
870 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
871 pChild->SetTransparency(nTransparency);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700872 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700873 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700874
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700875 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700876}
877
Tom Sepez60d909e2015-12-10 15:34:55 -0800878CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
879 CFX_Matrix mt = GetChildToRoot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700880
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700881 if (IPWL_Provider* pProvider = GetProvider()) {
882 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700883 return mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700884 }
885
886 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700887}
888
Tom Sepez281a9ea2016-02-26 14:24:28 -0800889void CPWL_Wnd::PWLtoWnd(const CFX_FloatPoint& point,
890 int32_t& x,
891 int32_t& y) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800892 CFX_Matrix mt = GetWindowMatrix();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800893 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700894 mt.Transform(pt.x, pt.y);
895 x = (int32_t)(pt.x + 0.5);
896 y = (int32_t)(pt.y + 0.5);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700897}
898
Tom Sepez281a9ea2016-02-26 14:24:28 -0800899FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
900 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800901 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700902 mt.TransformRect(rcTemp);
903 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
904 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700905}
906
Tom Sepez281a9ea2016-02-26 14:24:28 -0800907CFX_FloatPoint CPWL_Wnd::ChildToParent(const CFX_FloatPoint& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800908 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700909 if (mt.IsIdentity())
910 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700911
Tom Sepez281a9ea2016-02-26 14:24:28 -0800912 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700913 mt.Transform(pt.x, pt.y);
914 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700915}
916
Tom Sepez281a9ea2016-02-26 14:24:28 -0800917CFX_FloatRect CPWL_Wnd::ChildToParent(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800918 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700919 if (mt.IsIdentity())
920 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700921
Tom Sepez281a9ea2016-02-26 14:24:28 -0800922 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700923 mt.TransformRect(rc);
924 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700925}
926
Tom Sepez281a9ea2016-02-26 14:24:28 -0800927CFX_FloatPoint CPWL_Wnd::ParentToChild(const CFX_FloatPoint& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800928 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700929 if (mt.IsIdentity())
930 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700931
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700932 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800933 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700934 mt.Transform(pt.x, pt.y);
935 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700936}
937
Tom Sepez281a9ea2016-02-26 14:24:28 -0800938CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800939 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700940 if (mt.IsIdentity())
941 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700942
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700943 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800944 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700945 mt.TransformRect(rc);
946 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700947}
948
weili625ad662016-06-15 11:21:33 -0700949FX_FLOAT CPWL_Wnd::GetItemHeight(FX_FLOAT fLimitWidth) {
950 return 0;
951}
952
953FX_FLOAT CPWL_Wnd::GetItemLeftMargin() {
954 return 0;
955}
956
957FX_FLOAT CPWL_Wnd::GetItemRightMargin() {
958 return 0;
959}
960
Tom Sepez60d909e2015-12-10 15:34:55 -0800961CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
962 CFX_Matrix mt(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700963 if (HasFlag(PWS_CHILD)) {
964 const CPWL_Wnd* pParent = this;
965 while (pParent) {
966 mt.Concat(pParent->GetChildMatrix());
967 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700968 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700969 }
970 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700971}
972
Tom Sepez60d909e2015-12-10 15:34:55 -0800973CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974 if (HasFlag(PWS_CHILD))
975 return m_sPrivateParam.mtChild;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700976
Tom Sepez60d909e2015-12-10 15:34:55 -0800977 return CFX_Matrix(1, 0, 0, 1, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700978}
979
Tom Sepez60d909e2015-12-10 15:34:55 -0800980void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700981 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700982}
983
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700984const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
985 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
986 return pMsgCtrl->m_pMainKeyboardWnd;
987 }
988
thestig1cd352e2016-06-07 17:53:06 -0700989 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700990}
991
tsepez4cf55152016-11-02 14:37:54 -0700992void CPWL_Wnd::EnableWindow(bool bEnable) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700993 if (m_bEnabled != bEnable) {
994 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
995 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
996 pChild->EnableWindow(bEnable);
997 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700998 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700999
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001000 m_bEnabled = bEnable;
1001
1002 if (bEnable)
1003 OnEnabled();
1004 else
1005 OnDisabled();
1006 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001007}
1008
tsepez4cf55152016-11-02 14:37:54 -07001009bool CPWL_Wnd::IsEnabled() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001010 return m_bEnabled;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001011}
1012
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001013void CPWL_Wnd::OnEnabled() {}
1014
1015void CPWL_Wnd::OnDisabled() {}
1016
tsepez4cf55152016-11-02 14:37:54 -07001017bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001018 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001019 return pSystemHandler->IsCTRLKeyDown(nFlag);
1020 }
1021
tsepez4cf55152016-11-02 14:37:54 -07001022 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001023}
1024
tsepez4cf55152016-11-02 14:37:54 -07001025bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001026 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001027 return pSystemHandler->IsSHIFTKeyDown(nFlag);
1028 }
1029
tsepez4cf55152016-11-02 14:37:54 -07001030 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001031}
1032
tsepez4cf55152016-11-02 14:37:54 -07001033bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001034 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001035 return pSystemHandler->IsALTKeyDown(nFlag);
1036 }
1037
tsepez4cf55152016-11-02 14:37:54 -07001038 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001039}