blob: d3b3b9b75488c3178c7a01cc60b65a1bba653047 [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>
tsepez0d164f82017-01-09 07:28:13 -08008#include <vector>
Lei Zhang606346f2015-06-19 18:11:07 -07009
dan sinclair89e904b2016-03-23 19:29:15 -040010#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
11#include "fpdfsdk/pdfwindow/PWL_Utils.h"
12#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
tsepez36eb4bd2016-10-03 15:24:27 -070013#include "third_party/base/ptr_util.h"
tsepez0d164f82017-01-09 07:28:13 -080014#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015
Nico Weber9d8ec5a2015-08-04 13:00:21 -070016static std::map<int32_t, CPWL_Timer*>& GetPWLTimeMap() {
Bruce Dawson26d96ff2015-01-05 15:31:49 -080017 // Leak the object at shutdown.
Lei Zhang606346f2015-06-19 18:11:07 -070018 static auto timeMap = new std::map<int32_t, CPWL_Timer*>;
Bruce Dawson26d96ff2015-01-05 15:31:49 -080019 return *timeMap;
20}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021
weili625ad662016-06-15 11:21:33 -070022PWL_CREATEPARAM::PWL_CREATEPARAM()
23 : rcRectWnd(0, 0, 0, 0),
24 pSystemHandler(nullptr),
25 pFontMap(nullptr),
26 pProvider(nullptr),
27 pFocusHandler(nullptr),
28 dwFlags(0),
29 sBackgroundColor(),
dsinclair8faac622016-09-15 12:41:50 -070030 pAttachedWidget(nullptr),
weili625ad662016-06-15 11:21:33 -070031 nBorderStyle(BorderStyle::SOLID),
32 dwBorderWidth(1),
33 sBorderColor(),
34 sTextColor(),
35 sTextStrokeColor(),
36 nTransparency(255),
37 fFontSize(PWL_DEFAULT_FONTSIZE),
38 sDash(3, 0, 0),
39 pAttachedData(nullptr),
40 pParentWnd(nullptr),
41 pMsgControl(nullptr),
42 eCursorType(FXCT_ARROW),
43 mtChild(1, 0, 0, 1, 0, 0) {}
44
45PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default;
46
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached,
dsinclairb9590102016-04-27 06:38:59 -070048 CFX_SystemHandler* pSystemHandler)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 : m_nTimerID(0), m_pAttached(pAttached), m_pSystemHandler(pSystemHandler) {
Lei Zhang96660d62015-12-14 18:27:25 -080050 ASSERT(m_pAttached);
51 ASSERT(m_pSystemHandler);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052}
53
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054CPWL_Timer::~CPWL_Timer() {
55 KillPWLTimer();
56}
57
58int32_t CPWL_Timer::SetPWLTimer(int32_t nElapse) {
59 if (m_nTimerID != 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -070060 KillPWLTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061 m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc);
62
63 GetPWLTimeMap()[m_nTimerID] = this;
64 return m_nTimerID;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067void CPWL_Timer::KillPWLTimer() {
68 if (m_nTimerID == 0)
69 return;
Lei Zhang606346f2015-06-19 18:11:07 -070070
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 m_pSystemHandler->KillTimer(m_nTimerID);
72 GetPWLTimeMap().erase(m_nTimerID);
73 m_nTimerID = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070074}
75
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076void CPWL_Timer::TimerProc(int32_t idEvent) {
77 auto it = GetPWLTimeMap().find(idEvent);
78 if (it == GetPWLTimeMap().end())
79 return;
Lei Zhang606346f2015-06-19 18:11:07 -070080
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 CPWL_Timer* pTimer = it->second;
82 if (pTimer->m_pAttached)
83 pTimer->m_pAttached->TimerProc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084}
85
weili2d5b0202016-08-03 11:06:49 -070086CPWL_TimerHandler::CPWL_TimerHandler() {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087
weili2d5b0202016-08-03 11:06:49 -070088CPWL_TimerHandler::~CPWL_TimerHandler() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090void CPWL_TimerHandler::BeginTimer(int32_t nElapse) {
91 if (!m_pTimer)
tsepez36eb4bd2016-10-03 15:24:27 -070092 m_pTimer = pdfium::MakeUnique<CPWL_Timer>(this, GetSystemHandler());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093
tsepez36eb4bd2016-10-03 15:24:27 -070094 m_pTimer->SetPWLTimer(nElapse);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095}
96
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097void CPWL_TimerHandler::EndTimer() {
98 if (m_pTimer)
99 m_pTimer->KillPWLTimer();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100}
101
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102void CPWL_TimerHandler::TimerProc() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700103
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104class CPWL_MsgControl {
105 friend class CPWL_Wnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700106
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 public:
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800108 explicit CPWL_MsgControl(CPWL_Wnd* pWnd) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109 m_pCreatedWnd = pWnd;
110 Default();
111 }
112
Dan Sinclairf766ad22016-03-14 13:51:24 -0400113 ~CPWL_MsgControl() { Default(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114
115 void Default() {
tsepez0d164f82017-01-09 07:28:13 -0800116 m_aMousePath.clear();
117 m_aKeyboardPath.clear();
thestig1cd352e2016-06-07 17:53:06 -0700118 m_pMainMouseWnd = nullptr;
119 m_pMainKeyboardWnd = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 }
121
tsepez4cf55152016-11-02 14:37:54 -0700122 bool IsWndCreated(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 return m_pCreatedWnd == pWnd;
124 }
125
tsepez4cf55152016-11-02 14:37:54 -0700126 bool IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 return pWnd == m_pMainMouseWnd;
128 }
129
tsepez4cf55152016-11-02 14:37:54 -0700130 bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -0800131 return pWnd && pdfium::ContainsValue(m_aMousePath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132 }
133
tsepez4cf55152016-11-02 14:37:54 -0700134 bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 return pWnd == m_pMainKeyboardWnd;
136 }
137
tsepez4cf55152016-11-02 14:37:54 -0700138 bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
tsepez0d164f82017-01-09 07:28:13 -0800139 return pWnd && pdfium::ContainsValue(m_aKeyboardPath, pWnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140 }
141
142 void SetFocus(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -0800143 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 if (pWnd) {
145 m_pMainKeyboardWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 CPWL_Wnd* pParent = pWnd;
147 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -0800148 m_aKeyboardPath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 pParent = pParent->GetParentWindow();
150 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 pWnd->OnSetFocus();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700152 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700153 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700154
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 void KillFocus() {
tsepez0d164f82017-01-09 07:28:13 -0800156 if (!m_aKeyboardPath.empty())
157 if (CPWL_Wnd* pWnd = m_aKeyboardPath[0])
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700158 pWnd->OnKillFocus();
159
thestig1cd352e2016-06-07 17:53:06 -0700160 m_pMainKeyboardWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800161 m_aKeyboardPath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162 }
163
164 void SetCapture(CPWL_Wnd* pWnd) {
tsepez0d164f82017-01-09 07:28:13 -0800165 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 if (pWnd) {
167 m_pMainMouseWnd = pWnd;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 CPWL_Wnd* pParent = pWnd;
169 while (pParent) {
tsepez0d164f82017-01-09 07:28:13 -0800170 m_aMousePath.push_back(pParent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 pParent = pParent->GetParentWindow();
172 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700173 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700175
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 void ReleaseCapture() {
thestig1cd352e2016-06-07 17:53:06 -0700177 m_pMainMouseWnd = nullptr;
tsepez0d164f82017-01-09 07:28:13 -0800178 m_aMousePath.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700180
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181 private:
tsepez0d164f82017-01-09 07:28:13 -0800182 std::vector<CPWL_Wnd*> m_aMousePath;
183 std::vector<CPWL_Wnd*> m_aKeyboardPath;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 CPWL_Wnd* m_pCreatedWnd;
185 CPWL_Wnd* m_pMainMouseWnd;
186 CPWL_Wnd* m_pMainKeyboardWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700187};
188
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189CPWL_Wnd::CPWL_Wnd()
thestig1cd352e2016-06-07 17:53:06 -0700190 : m_pVScrollBar(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 m_rcWindow(),
192 m_rcClip(),
tsepez4cf55152016-11-02 14:37:54 -0700193 m_bCreated(false),
194 m_bVisible(false),
195 m_bNotifying(false),
196 m_bEnabled(true) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197
198CPWL_Wnd::~CPWL_Wnd() {
tsepez4cf55152016-11-02 14:37:54 -0700199 ASSERT(m_bCreated == false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700200}
201
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202CFX_ByteString CPWL_Wnd::GetClassName() const {
203 return "CPWL_Wnd";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700204}
205
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) {
207 if (!IsValid()) {
208 m_sPrivateParam = cp;
209
210 OnCreate(m_sPrivateParam);
211
212 m_sPrivateParam.rcRectWnd.Normalize();
213 m_rcWindow = m_sPrivateParam.rcRectWnd;
214 m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f);
215
216 CreateMsgControl();
217
218 if (m_sPrivateParam.pParentWnd)
219 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD);
220
221 PWL_CREATEPARAM ccp = m_sPrivateParam;
222
223 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
Tom Sepez60d909e2015-12-10 15:34:55 -0800224 ccp.mtChild = CFX_Matrix(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225
226 CreateScrollBar(ccp);
227 CreateChildWnd(ccp);
228
229 m_bVisible = HasFlag(PWS_VISIBLE);
230
231 OnCreated();
232
233 RePosChildWnd();
tsepez4cf55152016-11-02 14:37:54 -0700234 m_bCreated = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700235 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700236}
237
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240void CPWL_Wnd::OnCreated() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700241
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242void CPWL_Wnd::OnDestroy() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243
Lei Zhangab5537d2016-01-06 14:58:14 -0800244void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) {
245 if (m_sPrivateParam.pFocusHandler == handler)
246 m_sPrivateParam.pFocusHandler = nullptr;
247}
248
249void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) {
250 if (m_sPrivateParam.pProvider == provider)
251 m_sPrivateParam.pProvider = nullptr;
252}
253
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254void CPWL_Wnd::Destroy() {
255 KillFocus();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256 OnDestroy();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257 if (m_bCreated) {
tsepez6745f962017-01-04 10:09:45 -0800258 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
259 if (CPWL_Wnd* pChild = *it) {
260 *it = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 pChild->Destroy();
262 delete pChild;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263 }
264 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265 if (m_sPrivateParam.pParentWnd)
266 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD);
tsepez6745f962017-01-04 10:09:45 -0800267
tsepez4cf55152016-11-02 14:37:54 -0700268 m_bCreated = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 DestroyMsgControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271 FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM));
tsepez6745f962017-01-04 10:09:45 -0800272 m_Children.clear();
thestig1cd352e2016-06-07 17:53:06 -0700273 m_pVScrollBar = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700275
tsepez4cf55152016-11-02 14:37:54 -0700276void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, 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) {
tsepez6745f962017-01-04 10:09:45 -0800334 for (CPWL_Wnd* pChild : m_Children) {
335 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336 pChild->GetAppearanceStream(sAppStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700338}
339
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800341 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342 if (IsValid() && IsVisible()) {
343 DrawThisAppearance(pDevice, pUser2Device);
344 DrawChildAppearance(pDevice, pUser2Device);
345 }
346}
347
348void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800349 CFX_Matrix* pUser2Device) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800350 CFX_FloatRect rectWnd = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700351 if (!rectWnd.IsEmpty()) {
352 if (HasFlag(PWS_BACKGROUND)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800353 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 rectWnd, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
355 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
356 GetBackgroundColor(), GetTransparency());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700357 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358
359 if (HasFlag(PWS_BORDER))
Lei Zhang7457e382016-01-06 23:00:34 -0800360 CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd,
361 (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
362 GetBorderLeftTopColor(GetBorderStyle()),
363 GetBorderRightBottomColor(GetBorderStyle()),
364 GetBorderStyle(), GetTransparency());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700366}
367
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800369 CFX_Matrix* pUser2Device) {
tsepez6745f962017-01-04 10:09:45 -0800370 for (CPWL_Wnd* pChild : m_Children) {
371 if (!pChild)
372 continue;
373
374 CFX_Matrix mt = pChild->GetChildMatrix();
375 if (mt.IsIdentity()) {
376 pChild->DrawAppearance(pDevice, pUser2Device);
377 } else {
378 mt.Concat(*pUser2Device);
379 pChild->DrawAppearance(pDevice, &mt);
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()) {
dsinclair8faac622016-09-15 12:41:50 -0700402 if (CPDFSDK_Widget* widget = m_sPrivateParam.pAttachedWidget)
403 pSH->InvalidateRect(widget, rcWin);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700404 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700405 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700406}
407
tsepez6745f962017-01-04 10:09:45 -0800408#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
409 bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \
410 if (!IsValid() || !IsVisible() || !IsEnabled()) \
411 return false; \
412 if (!IsWndCaptureKeyboard(this)) \
413 return false; \
414 for (const auto& pChild : m_Children) { \
415 if (pChild && IsWndCaptureKeyboard(pChild)) \
416 return pChild->key_method_name(nChar, nFlag); \
417 } \
418 return false; \
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700420
421PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
422PWL_IMPLEMENT_KEY_METHOD(OnKeyUp)
423PWL_IMPLEMENT_KEY_METHOD(OnChar)
tsepez6745f962017-01-04 10:09:45 -0800424#undef PWL_IMPLEMENT_KEY_METHOD
425
426#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
427 bool CPWL_Wnd::mouse_method_name(const CFX_FloatPoint& point, \
428 uint32_t nFlag) { \
429 if (!IsValid() || !IsVisible() || !IsEnabled()) \
430 return false; \
431 if (IsWndCaptureMouse(this)) { \
432 for (const auto& pChild : m_Children) { \
433 if (pChild && IsWndCaptureMouse(pChild)) { \
434 return pChild->mouse_method_name(pChild->ParentToChild(point), \
435 nFlag); \
436 } \
437 } \
438 SetCursor(); \
439 return false; \
440 } \
441 for (const auto& pChild : m_Children) { \
442 if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \
443 return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \
444 } \
445 } \
446 if (WndHitTest(point)) \
447 SetCursor(); \
448 return false; \
449 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700450
451PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
452PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
453PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
454PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk)
455PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown)
456PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700457PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
458PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
459PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
tsepez6745f962017-01-04 10:09:45 -0800460#undef PWL_IMPLEMENT_MOUSE_METHOD
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700461
tsepez4cf55152016-11-02 14:37:54 -0700462bool CPWL_Wnd::OnMouseWheel(short zDelta,
463 const CFX_FloatPoint& point,
464 uint32_t nFlag) {
tsepez6745f962017-01-04 10:09:45 -0800465 if (!IsValid() || !IsVisible() || !IsEnabled())
466 return false;
467
468 SetCursor();
469 if (!IsWndCaptureKeyboard(this))
470 return false;
471
472 for (const auto& pChild : m_Children) {
473 if (pChild && IsWndCaptureKeyboard(pChild))
474 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 }
tsepez4cf55152016-11-02 14:37:54 -0700476 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700477}
478
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800480 m_Children.push_back(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700481}
482
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
tsepez6745f962017-01-04 10:09:45 -0800484 for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) {
485 if (*it && *it == pWnd) {
486 m_Children.erase(std::next(it).base());
487 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700488 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490}
491
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700493 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 intptr_t wParam,
495 intptr_t lParam) {
496 switch (msg) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700497 case PNM_ADDCHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 AddChild(pWnd);
499 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700500 case PNM_REMOVECHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 RemoveChild(pWnd);
502 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700503 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504 break;
505 }
506}
507
tsepez4cf55152016-11-02 14:37:54 -0700508bool CPWL_Wnd::IsValid() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 return m_bCreated;
510}
511
Lei Zhang7457e382016-01-06 23:00:34 -0800512const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 return m_sPrivateParam;
514}
515
516CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
517 return m_sPrivateParam.pParentWnd;
518}
519
Tom Sepez281a9ea2016-02-26 14:24:28 -0800520CFX_FloatRect CPWL_Wnd::GetWindowRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 return m_rcWindow;
522}
523
Tom Sepez281a9ea2016-02-26 14:24:28 -0800524CFX_FloatRect CPWL_Wnd::GetClientRect() const {
525 CFX_FloatRect rcWindow = GetWindowRect();
526 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 rcWindow, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
528 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
529 rcClient.right -= pVSB->GetScrollBarWidth();
530
531 rcClient.Normalize();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800532 return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533}
534
Tom Sepez281a9ea2016-02-26 14:24:28 -0800535CFX_FloatPoint CPWL_Wnd::GetCenterPoint() const {
536 CFX_FloatRect rcClient = GetClientRect();
537 return CFX_FloatPoint((rcClient.left + rcClient.right) * 0.5f,
538 (rcClient.top + rcClient.bottom) * 0.5f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539}
540
tsepez4cf55152016-11-02 14:37:54 -0700541bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
543}
544
tsepezc3255f52016-03-25 14:52:27 -0700545void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546 m_sPrivateParam.dwFlags &= ~dwFlags;
547}
548
tsepezc3255f52016-03-25 14:52:27 -0700549void CPWL_Wnd::AddFlag(uint32_t dwFlags) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 m_sPrivateParam.dwFlags |= dwFlags;
551}
552
553CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
554 return m_sPrivateParam.sBackgroundColor;
555}
556
557void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
558 m_sPrivateParam.sBackgroundColor = color;
559}
560
561void CPWL_Wnd::SetTextColor(const CPWL_Color& color) {
562 m_sPrivateParam.sTextColor = color;
563}
564
565void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color& color) {
566 m_sPrivateParam.sTextStrokeColor = color;
567}
568
569CPWL_Color CPWL_Wnd::GetTextColor() const {
570 return m_sPrivateParam.sTextColor;
571}
572
573CPWL_Color CPWL_Wnd::GetTextStrokeColor() const {
574 return m_sPrivateParam.sTextStrokeColor;
575}
576
dsinclair92cb5e52016-05-16 11:38:28 -0700577BorderStyle CPWL_Wnd::GetBorderStyle() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578 return m_sPrivateParam.nBorderStyle;
579}
580
dsinclair92cb5e52016-05-16 11:38:28 -0700581void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582 if (HasFlag(PWS_BORDER))
583 m_sPrivateParam.nBorderStyle = nBorderStyle;
584}
585
586int32_t CPWL_Wnd::GetBorderWidth() const {
587 if (HasFlag(PWS_BORDER))
588 return m_sPrivateParam.dwBorderWidth;
589
590 return 0;
591}
592
593int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 return 0;
595}
596
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597CPWL_Color CPWL_Wnd::GetBorderColor() const {
598 if (HasFlag(PWS_BORDER))
599 return m_sPrivateParam.sBorderColor;
600
601 return CPWL_Color();
602}
603
Lei Zhang7457e382016-01-06 23:00:34 -0800604const CPWL_Dash& CPWL_Wnd::GetBorderDash() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 return m_sPrivateParam.sDash;
606}
607
608void* CPWL_Wnd::GetAttachedData() const {
609 return m_sPrivateParam.pAttachedData;
610}
611
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
613 if (HasFlag(PWS_VSCROLL))
614 return m_pVScrollBar;
615
thestig1cd352e2016-06-07 17:53:06 -0700616 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617}
618
619void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
620 CreateVScrollBar(cp);
621}
622
623void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
624 if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) {
625 PWL_CREATEPARAM scp = cp;
626
627 // flags
628 scp.dwFlags =
629 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
630
631 scp.pParentWnd = this;
632 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
633 scp.eCursorType = FXCT_ARROW;
634 scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY;
635
Lei Zhange00660b2015-08-13 15:40:18 -0700636 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
637 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638 }
639}
640
641void CPWL_Wnd::SetCapture() {
642 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
643 pMsgCtrl->SetCapture(this);
644}
645
646void CPWL_Wnd::ReleaseCapture() {
tsepez6745f962017-01-04 10:09:45 -0800647 for (const auto& pChild : m_Children) {
648 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 pChild->ReleaseCapture();
tsepez6745f962017-01-04 10:09:45 -0800650 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700651 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
652 pMsgCtrl->ReleaseCapture();
653}
654
655void CPWL_Wnd::SetFocus() {
656 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
657 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
658 pMsgCtrl->KillFocus();
659 pMsgCtrl->SetFocus(this);
660 }
661}
662
663void CPWL_Wnd::KillFocus() {
664 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
665 if (pMsgCtrl->IsWndCaptureKeyboard(this))
666 pMsgCtrl->KillFocus();
667 }
668}
669
670void CPWL_Wnd::OnSetFocus() {}
671
672void CPWL_Wnd::OnKillFocus() {}
673
tsepez4cf55152016-11-02 14:37:54 -0700674bool CPWL_Wnd::WndHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 return IsValid() && IsVisible() && GetWindowRect().Contains(point.x, point.y);
676}
677
tsepez4cf55152016-11-02 14:37:54 -0700678bool CPWL_Wnd::ClientHitTest(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700679 return IsValid() && IsVisible() && GetClientRect().Contains(point.x, point.y);
680}
681
682const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
683 if (m_sPrivateParam.pParentWnd)
684 return m_sPrivateParam.pParentWnd->GetRootWnd();
685
686 return this;
687}
688
tsepez4cf55152016-11-02 14:37:54 -0700689void CPWL_Wnd::SetVisible(bool bVisible) {
tsepez6745f962017-01-04 10:09:45 -0800690 if (!IsValid())
691 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692
tsepez6745f962017-01-04 10:09:45 -0800693 for (const auto& pChild : m_Children) {
694 if (pChild)
695 pChild->SetVisible(bVisible);
696 }
697 if (bVisible != m_bVisible) {
698 m_bVisible = bVisible;
699 RePosChildWnd();
700 InvalidateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700702}
703
Tom Sepez281a9ea2016-02-26 14:24:28 -0800704void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705 m_rcClip = rect;
706 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700707}
708
Tom Sepez281a9ea2016-02-26 14:24:28 -0800709const CFX_FloatRect& CPWL_Wnd::GetClipRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700711}
712
tsepez4cf55152016-11-02 14:37:54 -0700713bool CPWL_Wnd::IsReadOnly() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700715}
716
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717void CPWL_Wnd::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800718 CFX_FloatRect rcContent = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
720
721 CPWL_ScrollBar* pVSB = GetVScrollBar();
722
Tom Sepez281a9ea2016-02-26 14:24:28 -0800723 CFX_FloatRect rcVScroll =
724 CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
725 rcContent.right - 1.0f, rcContent.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700726
727 if (pVSB)
tsepez4cf55152016-11-02 14:37:54 -0700728 pVSB->Move(rcVScroll, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700729}
730
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
732
733void CPWL_Wnd::SetCursor() {
734 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -0700735 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736 int32_t nCursorType = GetCreationParam().eCursorType;
737 pSH->SetCursor(nCursorType);
738 }
739 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700740}
741
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742void CPWL_Wnd::CreateMsgControl() {
743 if (!m_sPrivateParam.pMsgControl)
744 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700745}
746
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747void CPWL_Wnd::DestroyMsgControl() {
748 if (CPWL_MsgControl* pMsgControl = GetMsgControl())
749 if (pMsgControl->IsWndCreated(this))
750 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751}
752
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
754 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700755}
756
tsepez4cf55152016-11-02 14:37:54 -0700757bool CPWL_Wnd::IsCaptureMouse() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759}
760
tsepez4cf55152016-11-02 14:37:54 -0700761bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700762 if (CPWL_MsgControl* pCtrl = GetMsgControl())
763 return pCtrl->IsWndCaptureMouse(pWnd);
764
tsepez4cf55152016-11-02 14:37:54 -0700765 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766}
767
tsepez4cf55152016-11-02 14:37:54 -0700768bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769 if (CPWL_MsgControl* pCtrl = GetMsgControl())
770 return pCtrl->IsWndCaptureKeyboard(pWnd);
771
tsepez4cf55152016-11-02 14:37:54 -0700772 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700773}
774
tsepez4cf55152016-11-02 14:37:54 -0700775bool CPWL_Wnd::IsFocused() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700776 if (CPWL_MsgControl* pCtrl = GetMsgControl())
777 return pCtrl->IsMainCaptureKeyboard(this);
778
tsepez4cf55152016-11-02 14:37:54 -0700779 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700780}
781
Tom Sepez281a9ea2016-02-26 14:24:28 -0800782CFX_FloatRect CPWL_Wnd::GetFocusRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700783 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700784}
785
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700786FX_FLOAT CPWL_Wnd::GetFontSize() const {
787 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700788}
789
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize) {
791 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700792}
793
dsinclairb9590102016-04-27 06:38:59 -0700794CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700796}
797
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
799 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700800}
801
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802IPWL_Provider* CPWL_Wnd::GetProvider() const {
803 return m_sPrivateParam.pProvider;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700804}
805
dsinclairc7a73492016-04-05 12:01:42 -0700806IPVT_FontMap* CPWL_Wnd::GetFontMap() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700807 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700808}
809
dsinclair92cb5e52016-05-16 11:38:28 -0700810CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700811 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700812 case BorderStyle::BEVELED:
813 return CPWL_Color(COLORTYPE_GRAY, 1);
814 case BorderStyle::INSET:
815 return CPWL_Color(COLORTYPE_GRAY, 0.5f);
816 default:
817 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700819}
820
dsinclair92cb5e52016-05-16 11:38:28 -0700821CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700822 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -0700823 case BorderStyle::BEVELED:
824 return CPWL_Utils::DevideColor(GetBackgroundColor(), 2);
825 case BorderStyle::INSET:
826 return CPWL_Color(COLORTYPE_GRAY, 0.75f);
827 default:
828 return CPWL_Color();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700829 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700830}
831
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700832int32_t CPWL_Wnd::GetTransparency() {
833 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700834}
835
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
tsepez6745f962017-01-04 10:09:45 -0800837 for (const auto& pChild : m_Children) {
838 if (pChild)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839 pChild->SetTransparency(nTransparency);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700840 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700842}
843
Tom Sepez60d909e2015-12-10 15:34:55 -0800844CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
845 CFX_Matrix mt = GetChildToRoot();
tsepez6745f962017-01-04 10:09:45 -0800846 if (IPWL_Provider* pProvider = GetProvider())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700847 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848
849 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700850}
851
Tom Sepez281a9ea2016-02-26 14:24:28 -0800852void CPWL_Wnd::PWLtoWnd(const CFX_FloatPoint& point,
853 int32_t& x,
854 int32_t& y) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800855 CFX_Matrix mt = GetWindowMatrix();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800856 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700857 mt.Transform(pt.x, pt.y);
858 x = (int32_t)(pt.x + 0.5);
859 y = (int32_t)(pt.y + 0.5);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700860}
861
Tom Sepez281a9ea2016-02-26 14:24:28 -0800862FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const {
863 CFX_FloatRect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800864 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700865 mt.TransformRect(rcTemp);
866 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
867 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700868}
869
Tom Sepez281a9ea2016-02-26 14:24:28 -0800870CFX_FloatPoint CPWL_Wnd::ChildToParent(const CFX_FloatPoint& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800871 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872 if (mt.IsIdentity())
873 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700874
Tom Sepez281a9ea2016-02-26 14:24:28 -0800875 CFX_FloatPoint pt = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700876 mt.Transform(pt.x, pt.y);
877 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700878}
879
Tom Sepez281a9ea2016-02-26 14:24:28 -0800880CFX_FloatRect CPWL_Wnd::ChildToParent(const CFX_FloatRect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800881 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700882 if (mt.IsIdentity())
883 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700884
Tom Sepez281a9ea2016-02-26 14:24:28 -0800885 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886 mt.TransformRect(rc);
887 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700888}
889
Tom Sepez281a9ea2016-02-26 14:24:28 -0800890CFX_FloatPoint CPWL_Wnd::ParentToChild(const CFX_FloatPoint& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800891 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700892 if (mt.IsIdentity())
893 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700894
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895 mt.SetReverse(mt);
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::ParentToChild(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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700906 mt.SetReverse(mt);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800907 CFX_FloatRect rc = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700908 mt.TransformRect(rc);
909 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700910}
911
weili625ad662016-06-15 11:21:33 -0700912FX_FLOAT CPWL_Wnd::GetItemHeight(FX_FLOAT fLimitWidth) {
913 return 0;
914}
915
916FX_FLOAT CPWL_Wnd::GetItemLeftMargin() {
917 return 0;
918}
919
920FX_FLOAT CPWL_Wnd::GetItemRightMargin() {
921 return 0;
922}
923
Tom Sepez60d909e2015-12-10 15:34:55 -0800924CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
925 CFX_Matrix mt(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700926 if (HasFlag(PWS_CHILD)) {
927 const CPWL_Wnd* pParent = this;
928 while (pParent) {
929 mt.Concat(pParent->GetChildMatrix());
930 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700931 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700932 }
933 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700934}
935
Tom Sepez60d909e2015-12-10 15:34:55 -0800936CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700937 if (HasFlag(PWS_CHILD))
938 return m_sPrivateParam.mtChild;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700939
Tom Sepez60d909e2015-12-10 15:34:55 -0800940 return CFX_Matrix(1, 0, 0, 1, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700941}
942
Tom Sepez60d909e2015-12-10 15:34:55 -0800943void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700944 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700945}
946
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
tsepez6745f962017-01-04 10:09:45 -0800948 CPWL_MsgControl* pMsgCtrl = GetMsgControl();
949 return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700950}
951
tsepez4cf55152016-11-02 14:37:54 -0700952void CPWL_Wnd::EnableWindow(bool bEnable) {
tsepez6745f962017-01-04 10:09:45 -0800953 if (m_bEnabled == bEnable)
954 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700955
tsepez6745f962017-01-04 10:09:45 -0800956 for (const auto& pChild : m_Children) {
957 if (pChild)
958 pChild->EnableWindow(bEnable);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700959 }
tsepez6745f962017-01-04 10:09:45 -0800960 m_bEnabled = bEnable;
961 if (bEnable)
962 OnEnabled();
963 else
964 OnDisabled();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700965}
966
tsepez4cf55152016-11-02 14:37:54 -0700967bool CPWL_Wnd::IsEnabled() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700968 return m_bEnabled;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700969}
970
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700971void CPWL_Wnd::OnEnabled() {}
972
973void CPWL_Wnd::OnDisabled() {}
974
tsepez4cf55152016-11-02 14:37:54 -0700975bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -0700976 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700977 return pSystemHandler->IsCTRLKeyDown(nFlag);
978 }
979
tsepez4cf55152016-11-02 14:37:54 -0700980 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700981}
982
tsepez4cf55152016-11-02 14:37:54 -0700983bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -0700984 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700985 return pSystemHandler->IsSHIFTKeyDown(nFlag);
986 }
987
tsepez4cf55152016-11-02 14:37:54 -0700988 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700989}
990
tsepez4cf55152016-11-02 14:37:54 -0700991bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const {
dsinclairb9590102016-04-27 06:38:59 -0700992 if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700993 return pSystemHandler->IsALTKeyDown(nFlag);
994 }
995
tsepez4cf55152016-11-02 14:37:54 -0700996 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700997}