blob: c9dc89c07e03c7c00176b13ebfbad2fd7260f1de [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();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273 OnDestroy();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 if (m_bCreated) {
tsepez6745f962017-01-04 10:09:45 -0800275 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
276 if (CPWL_Wnd* pChild = *it) {
277 *it = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278 pChild->Destroy();
279 delete pChild;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 }
281 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 if (m_sPrivateParam.pParentWnd)
283 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD);
tsepez6745f962017-01-04 10:09:45 -0800284
tsepez4cf55152016-11-02 14:37:54 -0700285 m_bCreated = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 DestroyMsgControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM));
tsepez6745f962017-01-04 10:09:45 -0800289 m_Children.clear();
thestig1cd352e2016-06-07 17:53:06 -0700290 m_pVScrollBar = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700292
tsepez4cf55152016-11-02 14:37:54 -0700293void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 if (IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800295 CFX_FloatRect rcOld = GetWindowRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700296
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297 m_rcWindow = rcNew;
298 m_rcWindow.Normalize();
299
300 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
301 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
302 if (bReset) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700303 RePosChildWnd();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700305 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306 if (bRefresh) {
307 InvalidateRectMove(rcOld, rcNew);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700308 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700309
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310 m_sPrivateParam.rcRectWnd = m_rcWindow;
311 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700312}
313
Tom Sepez281a9ea2016-02-26 14:24:28 -0800314void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld,
315 const CFX_FloatRect& rcNew) {
316 CFX_FloatRect rcUnion = rcOld;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700318
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319 InvalidateRect(&rcUnion);
320}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700321
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) {
323 if (IsValid() && IsVisible()) {
324 GetThisAppearanceStream(sAppStream);
325 GetChildAppearanceStream(sAppStream);
326 }
327}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700328
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329// if don't set,Get default apperance stream
330void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800331 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700332 if (!rectWnd.IsEmpty()) {
333 CFX_ByteTextBuf sThis;
334
335 if (HasFlag(PWS_BACKGROUND))
336 sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor());
337
338 if (HasFlag(PWS_BORDER)) {
339 sThis << CPWL_Utils::GetBorderAppStream(
340 rectWnd, (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
341 GetBorderLeftTopColor(GetBorderStyle()),
342 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
343 GetBorderDash());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700344 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345
346 sAppStream << sThis;
347 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700348}
349
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) {
tsepez6745f962017-01-04 10:09:45 -0800351 for (CPWL_Wnd* pChild : m_Children) {
352 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353 pChild->GetAppearanceStream(sAppStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700355}
356
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800358 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 if (IsValid() && IsVisible()) {
360 DrawThisAppearance(pDevice, pUser2Device);
361 DrawChildAppearance(pDevice, pUser2Device);
362 }
363}
364
365void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800366 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800367 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368 if (!rectWnd.IsEmpty()) {
369 if (HasFlag(PWS_BACKGROUND)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800370 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371 rectWnd, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
372 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
373 GetBackgroundColor(), GetTransparency());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700374 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375
376 if (HasFlag(PWS_BORDER))
Lei Zhang7457e382016-01-06 23:00:34 -0800377 CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd,
378 (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
379 GetBorderLeftTopColor(GetBorderStyle()),
380 GetBorderRightBottomColor(GetBorderStyle()),
381 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700382 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700383}
384
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800386 CFX_Matrix* pUser2Device) {
tsepez6745f962017-01-04 10:09:45 -0800387 for (CPWL_Wnd* pChild : m_Children) {
388 if (!pChild)
389 continue;
390
391 CFX_Matrix mt = pChild->GetChildMatrix();
392 if (mt.IsIdentity()) {
393 pChild->DrawAppearance(pDevice, pUser2Device);
394 } else {
395 mt.Concat(*pUser2Device);
396 pChild->DrawAppearance(pDevice, &mt);
Lei Zhang60f507b2015-06-13 00:41:00 -0700397 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700399}
400
Tom Sepez281a9ea2016-02-26 14:24:28 -0800401void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402 if (IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800403 CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404
405 if (!HasFlag(PWS_NOREFRESHCLIP)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800406 CFX_FloatRect rcClip = GetClipRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407 if (!rcClip.IsEmpty()) {
408 rcRefresh.Intersect(rcClip);
409 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700410 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700411
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412 FX_RECT rcWin = PWLtoWnd(rcRefresh);
413 rcWin.left -= PWL_INVALIDATE_INFLATE;
414 rcWin.top -= PWL_INVALIDATE_INFLATE;
415 rcWin.right += PWL_INVALIDATE_INFLATE;
416 rcWin.bottom += PWL_INVALIDATE_INFLATE;
417
dsinclairb9590102016-04-27 06:38:59 -0700418 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
dsinclair8faac622016-09-15 12:41:50 -0700419 if (CPDFSDK_Widget* widget = m_sPrivateParam.pAttachedWidget)
420 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700421 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700423}
424
tsepez6745f962017-01-04 10:09:45 -0800425#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
426 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
427 if (!IsValid() || !IsVisible() || !IsEnabled()) \
428 return false; \
429 if (!IsWndCaptureKeyboard(this)) \
430 return false; \
431 for (const auto& pChild : m_Children) { \
432 if (pChild && IsWndCaptureKeyboard(pChild)) \
433 return pChild->key_method_name(nChar, nFlag); \
434 } \
435 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700437
438PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
439PWL_IMPLEMENT_KEY_METHOD(OnKeyUp)
440PWL_IMPLEMENT_KEY_METHOD(OnChar)
tsepez6745f962017-01-04 10:09:45 -0800441#undef PWL_IMPLEMENT_KEY_METHOD
442
443#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
444 bool CPWL_Wnd::mouse_method_name(const CFX_FloatPoint& point, \
445 uint32_t nFlag) { \
446 if (!IsValid() || !IsVisible() || !IsEnabled()) \
447 return false; \
448 if (IsWndCaptureMouse(this)) { \
449 for (const auto& pChild : m_Children) { \
450 if (pChild && IsWndCaptureMouse(pChild)) { \
451 return pChild->mouse_method_name(pChild->ParentToChild(point), \
452 nFlag); \
453 } \
454 } \
455 SetCursor(); \
456 return false; \
457 } \
458 for (const auto& pChild : m_Children) { \
459 if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \
460 return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \
461 } \
462 } \
463 if (WndHitTest(point)) \
464 SetCursor(); \
465 return false; \
466 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700467
468PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
469PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
470PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
471PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk)
472PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown)
473PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700474PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
475PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
476PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
tsepez6745f962017-01-04 10:09:45 -0800477#undef PWL_IMPLEMENT_MOUSE_METHOD
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700478
tsepez4cf55152016-11-02 14:37:54 -0700479bool CPWL_Wnd::OnMouseWheel(short zDelta,
480 const CFX_FloatPoint& point,
481 uint32_t nFlag) {
tsepez6745f962017-01-04 10:09:45 -0800482 if (!IsValid() || !IsVisible() || !IsEnabled())
483 return false;
484
485 SetCursor();
486 if (!IsWndCaptureKeyboard(this))
487 return false;
488
489 for (const auto& pChild : m_Children) {
490 if (pChild && IsWndCaptureKeyboard(pChild))
491 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 }
tsepez4cf55152016-11-02 14:37:54 -0700493 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700494}
495
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800497 m_Children.push_back(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700498}
499
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800501 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
502 if (*it && *it == pWnd) {
503 m_Children.erase(std::next(it).base());
504 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700505 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700507}
508
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700510 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 intptr_t wParam,
512 intptr_t lParam) {
513 switch (msg) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700514 case PNM_ADDCHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 AddChild(pWnd);
516 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700517 case PNM_REMOVECHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518 RemoveChild(pWnd);
519 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700520 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 break;
522 }
523}
524
tsepez4cf55152016-11-02 14:37:54 -0700525bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 return m_bCreated;
527}
528
Lei Zhang7457e382016-01-06 23:00:34 -0800529const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 return m_sPrivateParam;
531}
532
533CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
534 return m_sPrivateParam.pParentWnd;
535}
536
Tom Sepez281a9ea2016-02-26 14:24:28 -0800537CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 return m_rcWindow;
539}
540
Tom Sepez281a9ea2016-02-26 14:24:28 -0800541CFX_FloatRect CPWL_Wnd::GetClientRect() const {
542 CFX_FloatRect rcWindow = GetWindowRect();
543 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 rcWindow, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
545 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
546 rcClient.right -= pVSB->GetScrollBarWidth();
547
548 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800549 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550}
551
Tom Sepez281a9ea2016-02-26 14:24:28 -0800552CFX_FloatPoint CPWL_Wnd::GetCenterPoint() const {
553 CFX_FloatRect rcClient = GetClientRect();
554 return CFX_FloatPoint((rcClient.left + rcClient.right) * 0.5f,
555 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556}
557
tsepez4cf55152016-11-02 14:37:54 -0700558bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
560}
561
tsepezc3255f52016-03-25 14:52:27 -0700562void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 m_sPrivateParam.dwFlags &= ~dwFlags;
564}
565
tsepezc3255f52016-03-25 14:52:27 -0700566void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 m_sPrivateParam.dwFlags |= dwFlags;
568}
569
570CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
571 return m_sPrivateParam.sBackgroundColor;
572}
573
574void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
575 m_sPrivateParam.sBackgroundColor = color;
576}
577
578void CPWL_Wnd::SetTextColor(const CPWL_Color& color) {
579 m_sPrivateParam.sTextColor = color;
580}
581
582void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color& color) {
583 m_sPrivateParam.sTextStrokeColor = color;
584}
585
586CPWL_Color CPWL_Wnd::GetTextColor() const {
587 return m_sPrivateParam.sTextColor;
588}
589
590CPWL_Color CPWL_Wnd::GetTextStrokeColor() const {
591 return m_sPrivateParam.sTextStrokeColor;
592}
593
dsinclair92cb5e52016-05-16 11:38:28 -0700594BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595 return m_sPrivateParam.nBorderStyle;
596}
597
dsinclair92cb5e52016-05-16 11:38:28 -0700598void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599 if (HasFlag(PWS_BORDER))
600 m_sPrivateParam.nBorderStyle = nBorderStyle;
601}
602
603int32_t CPWL_Wnd::GetBorderWidth() const {
604 if (HasFlag(PWS_BORDER))
605 return m_sPrivateParam.dwBorderWidth;
606
607 return 0;
608}
609
610int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611 return 0;
612}
613
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614CPWL_Color CPWL_Wnd::GetBorderColor() const {
615 if (HasFlag(PWS_BORDER))
616 return m_sPrivateParam.sBorderColor;
617
618 return CPWL_Color();
619}
620
Lei Zhang7457e382016-01-06 23:00:34 -0800621const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 return m_sPrivateParam.sDash;
623}
624
625void* CPWL_Wnd::GetAttachedData() const {
626 return m_sPrivateParam.pAttachedData;
627}
628
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
630 if (HasFlag(PWS_VSCROLL))
631 return m_pVScrollBar;
632
thestig1cd352e2016-06-07 17:53:06 -0700633 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634}
635
636void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
637 CreateVScrollBar(cp);
638}
639
640void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
641 if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) {
642 PWL_CREATEPARAM scp = cp;
643
644 // flags
645 scp.dwFlags =
646 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
647
648 scp.pParentWnd = this;
649 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
650 scp.eCursorType = FXCT_ARROW;
651 scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY;
652
Lei Zhange00660b2015-08-13 15:40:18 -0700653 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
654 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700655 }
656}
657
658void CPWL_Wnd::SetCapture() {
659 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
660 pMsgCtrl->SetCapture(this);
661}
662
663void CPWL_Wnd::ReleaseCapture() {
tsepez6745f962017-01-04 10:09:45 -0800664 for (const auto& pChild : m_Children) {
665 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800667 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
669 pMsgCtrl->ReleaseCapture();
670}
671
672void CPWL_Wnd::SetFocus() {
673 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
674 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
675 pMsgCtrl->KillFocus();
676 pMsgCtrl->SetFocus(this);
677 }
678}
679
680void CPWL_Wnd::KillFocus() {
681 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
682 if (pMsgCtrl->IsWndCaptureKeyboard(this))
683 pMsgCtrl->KillFocus();
684 }
685}
686
687void CPWL_Wnd::OnSetFocus() {}
688
689void CPWL_Wnd::OnKillFocus() {}
690
tsepez4cf55152016-11-02 14:37:54 -0700691bool CPWL_Wnd::WndHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 return IsValid() && IsVisible() && GetWindowRect().Contains(point.x, point.y);
693}
694
tsepez4cf55152016-11-02 14:37:54 -0700695bool CPWL_Wnd::ClientHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 return IsValid() && IsVisible() && GetClientRect().Contains(point.x, point.y);
697}
698
699const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
700 if (m_sPrivateParam.pParentWnd)
701 return m_sPrivateParam.pParentWnd->GetRootWnd();
702
703 return this;
704}
705
tsepez4cf55152016-11-02 14:37:54 -0700706void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800707 if (!IsValid())
708 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709
tsepez6745f962017-01-04 10:09:45 -0800710 for (const auto& pChild : m_Children) {
711 if (pChild)
712 pChild->SetVisible(bVisible);
713 }
714 if (bVisible != m_bVisible) {
715 m_bVisible = bVisible;
716 RePosChildWnd();
717 InvalidateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700719}
720
Tom Sepez281a9ea2016-02-26 14:24:28 -0800721void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 m_rcClip = rect;
723 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700724}
725
Tom Sepez281a9ea2016-02-26 14:24:28 -0800726const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700728}
729
tsepez4cf55152016-11-02 14:37:54 -0700730bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700732}
733
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734void CPWL_Wnd::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800735 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
737
738 CPWL_ScrollBar* pVSB = GetVScrollBar();
739
Tom Sepez281a9ea2016-02-26 14:24:28 -0800740 CFX_FloatRect rcVScroll =
741 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
742 rcContent.right - 1.0f, rcContent.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743
744 if (pVSB)
tsepez4cf55152016-11-02 14:37:54 -0700745 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700746}
747
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
749
750void CPWL_Wnd::SetCursor() {
751 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700752 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753 int32_t nCursorType = GetCreationParam().eCursorType;
754 pSH->SetCursor(nCursorType);
755 }
756 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700757}
758
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700759void CPWL_Wnd::CreateMsgControl() {
760 if (!m_sPrivateParam.pMsgControl)
761 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700762}
763
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700764void CPWL_Wnd::DestroyMsgControl() {
765 if (CPWL_MsgControl* pMsgControl = GetMsgControl())
766 if (pMsgControl->IsWndCreated(this))
767 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700768}
769
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700770CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
771 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700772}
773
tsepez4cf55152016-11-02 14:37:54 -0700774bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700776}
777
tsepez4cf55152016-11-02 14:37:54 -0700778bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700779 if (CPWL_MsgControl* pCtrl = GetMsgControl())
780 return pCtrl->IsWndCaptureMouse(pWnd);
781
tsepez4cf55152016-11-02 14:37:54 -0700782 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700783}
784
tsepez4cf55152016-11-02 14:37:54 -0700785bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700786 if (CPWL_MsgControl* pCtrl = GetMsgControl())
787 return pCtrl->IsWndCaptureKeyboard(pWnd);
788
tsepez4cf55152016-11-02 14:37:54 -0700789 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700790}
791
tsepez4cf55152016-11-02 14:37:54 -0700792bool CPWL_Wnd::IsFocused() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793 if (CPWL_MsgControl* pCtrl = GetMsgControl())
794 return pCtrl->IsMainCaptureKeyboard(this);
795
tsepez4cf55152016-11-02 14:37:54 -0700796 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700797}
798
Tom Sepez281a9ea2016-02-26 14:24:28 -0800799CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700801}
802
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803FX_FLOAT CPWL_Wnd::GetFontSize() const {
804 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700805}
806
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700807void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize) {
808 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700809}
810
dsinclairb9590102016-04-27 06:38:59 -0700811CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700812 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700813}
814
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700815IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
816 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700817}
818
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700819IPWL_Provider* CPWL_Wnd::GetProvider() const {
820 return m_sPrivateParam.pProvider;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700821}
822
dsinclairc7a73492016-04-05 12:01:42 -0700823IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700824 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700825}
826
dsinclair92cb5e52016-05-16 11:38:28 -0700827CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700828 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700829 case BorderStyle::BEVELED:
830 return CPWL_Color(COLORTYPE_GRAY, 1);
831 case BorderStyle::INSET:
832 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
833 default:
834 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700835 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700836}
837
dsinclair92cb5e52016-05-16 11:38:28 -0700838CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700840 case BorderStyle::BEVELED:
841 return CPWL_Utils::DevideColor(GetBackgroundColor(), 2);
842 case BorderStyle::INSET:
843 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
844 default:
845 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700846 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700847}
848
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700849int32_t CPWL_Wnd::GetTransparency() {
850 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700851}
852
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700853void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
tsepez6745f962017-01-04 10:09:45 -0800854 for (const auto& pChild : m_Children) {
855 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700856 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700857 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700858 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700859}
860
Tom Sepez60d909e2015-12-10 15:34:55 -0800861CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
862 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800863 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700865
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
Tom Sepez281a9ea2016-02-26 14:24:28 -0800887CFX_FloatPoint CPWL_Wnd::ChildToParent(const CFX_FloatPoint& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800888 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700889 if (mt.IsIdentity())
890 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700891
Tom Sepez281a9ea2016-02-26 14:24:28 -0800892 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700893 mt.Transform(pt.x, pt.y);
894 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700895}
896
Tom Sepez281a9ea2016-02-26 14:24:28 -0800897CFX_FloatRect CPWL_Wnd::ChildToParent(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800898 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700899 if (mt.IsIdentity())
900 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700901
Tom Sepez281a9ea2016-02-26 14:24:28 -0800902 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700903 mt.TransformRect(rc);
904 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700905}
906
Tom Sepez281a9ea2016-02-26 14:24:28 -0800907CFX_FloatPoint CPWL_Wnd::ParentToChild(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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700912 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800913 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700914 mt.Transform(pt.x, pt.y);
915 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700916}
917
Tom Sepez281a9ea2016-02-26 14:24:28 -0800918CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800919 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700920 if (mt.IsIdentity())
921 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700922
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700923 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800924 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700925 mt.TransformRect(rc);
926 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700927}
928
weili625ad662016-06-15 11:21:33 -0700929FX_FLOAT CPWL_Wnd::GetItemHeight(FX_FLOAT fLimitWidth) {
930 return 0;
931}
932
933FX_FLOAT CPWL_Wnd::GetItemLeftMargin() {
934 return 0;
935}
936
937FX_FLOAT CPWL_Wnd::GetItemRightMargin() {
938 return 0;
939}
940
Tom Sepez60d909e2015-12-10 15:34:55 -0800941CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
942 CFX_Matrix mt(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700943 if (HasFlag(PWS_CHILD)) {
944 const CPWL_Wnd* pParent = this;
945 while (pParent) {
946 mt.Concat(pParent->GetChildMatrix());
947 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700948 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700949 }
950 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700951}
952
Tom Sepez60d909e2015-12-10 15:34:55 -0800953CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700954 if (HasFlag(PWS_CHILD))
955 return m_sPrivateParam.mtChild;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700956
Tom Sepez60d909e2015-12-10 15:34:55 -0800957 return CFX_Matrix(1, 0, 0, 1, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700958}
959
Tom Sepez60d909e2015-12-10 15:34:55 -0800960void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700961 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700962}
963
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700964const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800965 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
966 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700967}
968
tsepez4cf55152016-11-02 14:37:54 -0700969void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800970 if (m_bEnabled == bEnable)
971 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700972
tsepez6745f962017-01-04 10:09:45 -0800973 for (const auto& pChild : m_Children) {
974 if (pChild)
975 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700976 }
tsepez6745f962017-01-04 10:09:45 -0800977 m_bEnabled = bEnable;
978 if (bEnable)
979 OnEnabled();
980 else
981 OnDisabled();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700982}
983
tsepez4cf55152016-11-02 14:37:54 -0700984bool CPWL_Wnd::IsEnabled() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700985 return m_bEnabled;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700986}
987
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700988void CPWL_Wnd::OnEnabled() {}
989
990void CPWL_Wnd::OnDisabled() {}
991
tsepez4cf55152016-11-02 14:37:54 -0700992bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -0700993 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700994 return pSystemHandler->IsCTRLKeyDown(nFlag);
995 }
996
tsepez4cf55152016-11-02 14:37:54 -0700997 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700998}
999
tsepez4cf55152016-11-02 14:37:54 -07001000bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001001 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001002 return pSystemHandler->IsSHIFTKeyDown(nFlag);
1003 }
1004
tsepez4cf55152016-11-02 14:37:54 -07001005 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001006}
1007
tsepez4cf55152016-11-02 14:37:54 -07001008bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -07001009 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001010 return pSystemHandler->IsALTKeyDown(nFlag);
1011 }
1012
tsepez4cf55152016-11-02 14:37:54 -07001013 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001014}