blob: 9c4e21713b8e7fc5b73daa86681f2e7032d35977 [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
Lei Zhangbde53d22015-11-12 22:21:30 -08009#include "fpdfsdk/include/pdfwindow/PWL_ScrollBar.h"
10#include "fpdfsdk/include/pdfwindow/PWL_Utils.h"
11#include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012
Nico Weber9d8ec5a2015-08-04 13:00:21 -070013static std::map<int32_t, CPWL_Timer*>& GetPWLTimeMap() {
Bruce Dawson26d96ff2015-01-05 15:31:49 -080014 // Leak the object at shutdown.
Lei Zhang606346f2015-06-19 18:11:07 -070015 static auto timeMap = new std::map<int32_t, CPWL_Timer*>;
Bruce Dawson26d96ff2015-01-05 15:31:49 -080016 return *timeMap;
17}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached,
20 IFX_SystemHandler* pSystemHandler)
21 : m_nTimerID(0), m_pAttached(pAttached), m_pSystemHandler(pSystemHandler) {
Lei Zhang96660d62015-12-14 18:27:25 -080022 ASSERT(m_pAttached);
23 ASSERT(m_pSystemHandler);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024}
25
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026CPWL_Timer::~CPWL_Timer() {
27 KillPWLTimer();
28}
29
30int32_t CPWL_Timer::SetPWLTimer(int32_t nElapse) {
31 if (m_nTimerID != 0)
Tom Sepez2f2ffec2015-07-23 14:42:09 -070032 KillPWLTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033 m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc);
34
35 GetPWLTimeMap()[m_nTimerID] = this;
36 return m_nTimerID;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037}
38
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039void CPWL_Timer::KillPWLTimer() {
40 if (m_nTimerID == 0)
41 return;
Lei Zhang606346f2015-06-19 18:11:07 -070042
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 m_pSystemHandler->KillTimer(m_nTimerID);
44 GetPWLTimeMap().erase(m_nTimerID);
45 m_nTimerID = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046}
47
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048void CPWL_Timer::TimerProc(int32_t idEvent) {
49 auto it = GetPWLTimeMap().find(idEvent);
50 if (it == GetPWLTimeMap().end())
51 return;
Lei Zhang606346f2015-06-19 18:11:07 -070052
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 CPWL_Timer* pTimer = it->second;
54 if (pTimer->m_pAttached)
55 pTimer->m_pAttached->TimerProc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056}
57
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058CPWL_TimerHandler::CPWL_TimerHandler() : m_pTimer(NULL) {}
59
60CPWL_TimerHandler::~CPWL_TimerHandler() {
61 delete m_pTimer;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062}
63
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064void CPWL_TimerHandler::BeginTimer(int32_t nElapse) {
65 if (!m_pTimer)
66 m_pTimer = new CPWL_Timer(this, GetSystemHandler());
67
68 if (m_pTimer)
69 m_pTimer->SetPWLTimer(nElapse);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070}
71
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072void CPWL_TimerHandler::EndTimer() {
73 if (m_pTimer)
74 m_pTimer->KillPWLTimer();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075}
76
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077void CPWL_TimerHandler::TimerProc() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079class CPWL_MsgControl {
80 friend class CPWL_Wnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 public:
Lei Zhangc2fb35f2016-01-05 16:46:58 -080083 explicit CPWL_MsgControl(CPWL_Wnd* pWnd) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 m_pCreatedWnd = pWnd;
85 Default();
86 }
87
88 ~CPWL_MsgControl() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 Default();
90 }
91
92 void Default() {
93 m_aMousePath.RemoveAll();
94 m_aKeyboardPath.RemoveAll();
95 m_pMainMouseWnd = NULL;
96 m_pMainKeyboardWnd = NULL;
97 }
98
99 FX_BOOL IsWndCreated(const CPWL_Wnd* pWnd) const {
100 return m_pCreatedWnd == pWnd;
101 }
102
103 FX_BOOL IsMainCaptureMouse(const CPWL_Wnd* pWnd) const {
104 return pWnd == m_pMainMouseWnd;
105 }
106
107 FX_BOOL IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800108 if (pWnd) {
109 for (int32_t i = 0, sz = m_aMousePath.GetSize(); i < sz; i++) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 if (m_aMousePath.GetAt(i) == pWnd)
111 return TRUE;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800112 }
113 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114
115 return FALSE;
116 }
117
118 FX_BOOL IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
119 return pWnd == m_pMainKeyboardWnd;
120 }
121
122 FX_BOOL IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800123 if (pWnd) {
124 for (int32_t i = 0, sz = m_aKeyboardPath.GetSize(); i < sz; i++) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 if (m_aKeyboardPath.GetAt(i) == pWnd)
126 return TRUE;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800127 }
128 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129
130 return FALSE;
131 }
132
133 void SetFocus(CPWL_Wnd* pWnd) {
134 m_aKeyboardPath.RemoveAll();
135
136 if (pWnd) {
137 m_pMainKeyboardWnd = pWnd;
138
139 CPWL_Wnd* pParent = pWnd;
140 while (pParent) {
141 m_aKeyboardPath.Add(pParent);
142 pParent = pParent->GetParentWindow();
143 }
144
145 pWnd->OnSetFocus();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700146 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700148
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 void KillFocus() {
150 if (m_aKeyboardPath.GetSize() > 0)
151 if (CPWL_Wnd* pWnd = m_aKeyboardPath.GetAt(0))
152 pWnd->OnKillFocus();
153
154 m_pMainKeyboardWnd = NULL;
155 m_aKeyboardPath.RemoveAll();
156 }
157
158 void SetCapture(CPWL_Wnd* pWnd) {
159 m_aMousePath.RemoveAll();
160
161 if (pWnd) {
162 m_pMainMouseWnd = pWnd;
163
164 CPWL_Wnd* pParent = pWnd;
165 while (pParent) {
166 m_aMousePath.Add(pParent);
167 pParent = pParent->GetParentWindow();
168 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700169 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 void ReleaseCapture() {
173 m_pMainMouseWnd = NULL;
174 m_aMousePath.RemoveAll();
175 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700176
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 private:
178 CFX_ArrayTemplate<CPWL_Wnd*> m_aMousePath;
179 CFX_ArrayTemplate<CPWL_Wnd*> m_aKeyboardPath;
180 CPWL_Wnd* m_pCreatedWnd;
181 CPWL_Wnd* m_pMainMouseWnd;
182 CPWL_Wnd* m_pMainKeyboardWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700183};
184
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185CPWL_Wnd::CPWL_Wnd()
186 : m_pVScrollBar(NULL),
187 m_rcWindow(),
188 m_rcClip(),
189 m_bCreated(FALSE),
190 m_bVisible(FALSE),
191 m_bNotifying(FALSE),
192 m_bEnabled(TRUE) {}
193
194CPWL_Wnd::~CPWL_Wnd() {
195 ASSERT(m_bCreated == FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700196}
197
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198CFX_ByteString CPWL_Wnd::GetClassName() const {
199 return "CPWL_Wnd";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700200}
201
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) {
203 if (!IsValid()) {
204 m_sPrivateParam = cp;
205
206 OnCreate(m_sPrivateParam);
207
208 m_sPrivateParam.rcRectWnd.Normalize();
209 m_rcWindow = m_sPrivateParam.rcRectWnd;
210 m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f);
211
212 CreateMsgControl();
213
214 if (m_sPrivateParam.pParentWnd)
215 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD);
216
217 PWL_CREATEPARAM ccp = m_sPrivateParam;
218
219 ccp.dwFlags &= 0xFFFF0000L; // remove sub styles
Tom Sepez60d909e2015-12-10 15:34:55 -0800220 ccp.mtChild = CFX_Matrix(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221
222 CreateScrollBar(ccp);
223 CreateChildWnd(ccp);
224
225 m_bVisible = HasFlag(PWS_VISIBLE);
226
227 OnCreated();
228
229 RePosChildWnd();
230 m_bCreated = TRUE;
231 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700232}
233
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700235
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236void CPWL_Wnd::OnCreated() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700237
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238void CPWL_Wnd::OnDestroy() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240void CPWL_Wnd::Destroy() {
241 KillFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700242
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 OnDestroy();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245 if (m_bCreated) {
246 for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
247 if (CPWL_Wnd* pChild = m_aChildren[i]) {
248 pChild->Destroy();
249 delete pChild;
250 pChild = NULL;
251 }
252 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700253
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 if (m_sPrivateParam.pParentWnd)
255 m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD);
256 m_bCreated = FALSE;
257 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700258
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259 DestroyMsgControl();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700260
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM));
262 m_aChildren.RemoveAll();
263 m_pVScrollBar = NULL;
264}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700265
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266void CPWL_Wnd::Move(const CPDF_Rect& rcNew, FX_BOOL bReset, FX_BOOL bRefresh) {
267 if (IsValid()) {
268 CPDF_Rect rcOld = GetWindowRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 m_rcWindow = rcNew;
271 m_rcWindow.Normalize();
272
273 if (rcOld.left != rcNew.left || rcOld.right != rcNew.right ||
274 rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) {
275 if (bReset) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700276 RePosChildWnd();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700278 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700279 if (bRefresh) {
280 InvalidateRectMove(rcOld, rcNew);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700281 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700282
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 m_sPrivateParam.rcRectWnd = m_rcWindow;
284 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700285}
286
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287void CPWL_Wnd::InvalidateRectMove(const CPDF_Rect& rcOld,
288 const CPDF_Rect& rcNew) {
289 CPDF_Rect rcUnion = rcOld;
290 rcUnion.Union(rcNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 InvalidateRect(&rcUnion);
293}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700294
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700295void CPWL_Wnd::GetAppearanceStream(CFX_ByteString& sAppStream) {
296 if (IsValid()) {
297 CFX_ByteTextBuf sTextBuf;
298 GetAppearanceStream(sTextBuf);
299 sAppStream += sTextBuf.GetByteString();
300 }
301}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700302
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) {
304 if (IsValid() && IsVisible()) {
305 GetThisAppearanceStream(sAppStream);
306 GetChildAppearanceStream(sAppStream);
307 }
308}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700309
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310// if don't set,Get default apperance stream
311void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
312 CPDF_Rect rectWnd = GetWindowRect();
313 if (!rectWnd.IsEmpty()) {
314 CFX_ByteTextBuf sThis;
315
316 if (HasFlag(PWS_BACKGROUND))
317 sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor());
318
319 if (HasFlag(PWS_BORDER)) {
320 sThis << CPWL_Utils::GetBorderAppStream(
321 rectWnd, (FX_FLOAT)GetBorderWidth(), GetBorderColor(),
322 GetBorderLeftTopColor(GetBorderStyle()),
323 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
324 GetBorderDash());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700325 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326
327 sAppStream << sThis;
328 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700329}
330
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) {
332 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
333 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
334 pChild->GetAppearanceStream(sAppStream);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700335 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700337}
338
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700339void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800340 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341 if (IsValid() && IsVisible()) {
342 DrawThisAppearance(pDevice, pUser2Device);
343 DrawChildAppearance(pDevice, pUser2Device);
344 }
345}
346
347void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800348 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349 CPDF_Rect rectWnd = GetWindowRect();
350 if (!rectWnd.IsEmpty()) {
351 if (HasFlag(PWS_BACKGROUND)) {
352 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(
353 rectWnd, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
354 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient,
355 GetBackgroundColor(), GetTransparency());
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700356 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357
358 if (HasFlag(PWS_BORDER))
359 CPWL_Utils::DrawBorder(
360 pDevice, pUser2Device, rectWnd, (FX_FLOAT)GetBorderWidth(),
361 GetBorderColor(), GetBorderLeftTopColor(GetBorderStyle()),
362 GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(),
363 GetBorderDash(), GetTransparency());
364 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700365}
366
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800368 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
370 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
Tom Sepez60d909e2015-12-10 15:34:55 -0800371 CFX_Matrix mt = pChild->GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700372 if (mt.IsIdentity()) {
373 pChild->DrawAppearance(pDevice, pUser2Device);
374 } else {
375 mt.Concat(*pUser2Device);
376 pChild->DrawAppearance(pDevice, &mt);
377 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700378 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700380}
381
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700382void CPWL_Wnd::InvalidateRect(CPDF_Rect* pRect) {
383 if (IsValid()) {
384 CPDF_Rect rcRefresh = pRect ? *pRect : GetWindowRect();
385
386 if (!HasFlag(PWS_NOREFRESHCLIP)) {
387 CPDF_Rect rcClip = GetClipRect();
388 if (!rcClip.IsEmpty()) {
389 rcRefresh.Intersect(rcClip);
390 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700391 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700392
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393 FX_RECT rcWin = PWLtoWnd(rcRefresh);
394 rcWin.left -= PWL_INVALIDATE_INFLATE;
395 rcWin.top -= PWL_INVALIDATE_INFLATE;
396 rcWin.right += PWL_INVALIDATE_INFLATE;
397 rcWin.bottom += PWL_INVALIDATE_INFLATE;
398
399 if (IFX_SystemHandler* pSH = GetSystemHandler()) {
400 if (FX_HWND hWnd = GetAttachedHWnd()) {
401 pSH->InvalidateRect(hWnd, rcWin);
402 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700403 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700405}
406
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407#define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \
408 FX_BOOL CPWL_Wnd::key_method_name(FX_WORD nChar, FX_DWORD nFlag) { \
409 if (IsValid() && IsVisible() && IsEnabled()) { \
410 if (IsWndCaptureKeyboard(this)) { \
411 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
412 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
413 if (IsWndCaptureKeyboard(pChild)) { \
414 return pChild->key_method_name(nChar, nFlag); \
415 } \
416 } \
417 } \
418 } \
419 } \
420 return FALSE; \
421 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700422
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \
424 FX_BOOL CPWL_Wnd::mouse_method_name(const CPDF_Point& point, \
425 FX_DWORD nFlag) { \
426 if (IsValid() && IsVisible() && IsEnabled()) { \
427 if (IsWndCaptureMouse(this)) { \
428 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
429 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
430 if (IsWndCaptureMouse(pChild)) { \
431 return pChild->mouse_method_name(pChild->ParentToChild(point), \
432 nFlag); \
433 } \
434 } \
435 } \
436 SetCursor(); \
437 } else { \
438 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \
439 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \
440 if (pChild->WndHitTest(pChild->ParentToChild(point))) { \
441 return pChild->mouse_method_name(pChild->ParentToChild(point), \
442 nFlag); \
443 } \
444 } \
445 } \
446 if (WndHitTest(point)) \
447 SetCursor(); \
448 } \
449 } \
450 return FALSE; \
451 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700452
453PWL_IMPLEMENT_KEY_METHOD(OnKeyDown)
454PWL_IMPLEMENT_KEY_METHOD(OnKeyUp)
455PWL_IMPLEMENT_KEY_METHOD(OnChar)
456
457PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk)
458PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown)
459PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp)
460PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk)
461PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown)
462PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700463PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown)
464PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp)
465PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove)
466
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467FX_BOOL CPWL_Wnd::OnMouseWheel(short zDelta,
468 const CPDF_Point& point,
469 FX_DWORD nFlag) {
470 if (IsValid() && IsVisible() && IsEnabled()) {
471 SetCursor();
472 if (IsWndCaptureKeyboard(this)) {
473 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
474 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
475 if (IsWndCaptureKeyboard(pChild)) {
476 return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point),
477 nFlag);
478 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700479 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700481 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 }
483 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700484}
485
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) {
487 m_aChildren.Add(pWnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700488}
489
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) {
491 for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) {
492 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
493 if (pChild == pWnd) {
494 m_aChildren.RemoveAt(i);
495 break;
496 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700497 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700499}
500
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd,
502 FX_DWORD msg,
503 intptr_t wParam,
504 intptr_t lParam) {
505 switch (msg) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700506 case PNM_ADDCHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 AddChild(pWnd);
508 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700509 case PNM_REMOVECHILD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510 RemoveChild(pWnd);
511 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700512 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 break;
514 }
515}
516
517FX_BOOL CPWL_Wnd::IsValid() const {
518 return m_bCreated;
519}
520
521PWL_CREATEPARAM CPWL_Wnd::GetCreationParam() const {
522 return m_sPrivateParam;
523}
524
525CPWL_Wnd* CPWL_Wnd::GetParentWindow() const {
526 return m_sPrivateParam.pParentWnd;
527}
528
529CPDF_Rect CPWL_Wnd::GetOriginWindowRect() const {
530 return m_sPrivateParam.rcRectWnd;
531}
532
533CPDF_Rect CPWL_Wnd::GetWindowRect() const {
534 return m_rcWindow;
535}
536
537CPDF_Rect CPWL_Wnd::GetClientRect() const {
538 CPDF_Rect rcWindow = GetWindowRect();
539 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(
540 rcWindow, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
541 if (CPWL_ScrollBar* pVSB = GetVScrollBar())
542 rcClient.right -= pVSB->GetScrollBarWidth();
543
544 rcClient.Normalize();
545 return rcWindow.Contains(rcClient) ? rcClient : CPDF_Rect();
546}
547
548CPDF_Point CPWL_Wnd::GetCenterPoint() const {
549 CPDF_Rect rcClient = GetClientRect();
550 return CPDF_Point((rcClient.left + rcClient.right) * 0.5f,
551 (rcClient.top + rcClient.bottom) * 0.5f);
552}
553
554CPDF_Rect CPWL_Wnd::GetClientCenterSquare() const {
555 return CPWL_Utils::GetCenterSquare(GetClientRect());
556}
557
558CPDF_Rect CPWL_Wnd::GetWindowCenterSquare() const {
559 return CPWL_Utils::GetCenterSquare(
560 CPWL_Utils::DeflateRect(GetWindowRect(), 0.1f));
561}
562
563FX_BOOL CPWL_Wnd::HasFlag(FX_DWORD dwFlags) const {
564 return (m_sPrivateParam.dwFlags & dwFlags) != 0;
565}
566
567void CPWL_Wnd::RemoveFlag(FX_DWORD dwFlags) {
568 m_sPrivateParam.dwFlags &= ~dwFlags;
569}
570
571void CPWL_Wnd::AddFlag(FX_DWORD dwFlags) {
572 m_sPrivateParam.dwFlags |= dwFlags;
573}
574
575CPWL_Color CPWL_Wnd::GetBackgroundColor() const {
576 return m_sPrivateParam.sBackgroundColor;
577}
578
579void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) {
580 m_sPrivateParam.sBackgroundColor = color;
581}
582
583void CPWL_Wnd::SetTextColor(const CPWL_Color& color) {
584 m_sPrivateParam.sTextColor = color;
585}
586
587void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color& color) {
588 m_sPrivateParam.sTextStrokeColor = color;
589}
590
591CPWL_Color CPWL_Wnd::GetTextColor() const {
592 return m_sPrivateParam.sTextColor;
593}
594
595CPWL_Color CPWL_Wnd::GetTextStrokeColor() const {
596 return m_sPrivateParam.sTextStrokeColor;
597}
598
599int32_t CPWL_Wnd::GetBorderStyle() const {
600 return m_sPrivateParam.nBorderStyle;
601}
602
603void CPWL_Wnd::SetBorderStyle(int32_t nBorderStyle) {
604 if (HasFlag(PWS_BORDER))
605 m_sPrivateParam.nBorderStyle = nBorderStyle;
606}
607
608int32_t CPWL_Wnd::GetBorderWidth() const {
609 if (HasFlag(PWS_BORDER))
610 return m_sPrivateParam.dwBorderWidth;
611
612 return 0;
613}
614
615int32_t CPWL_Wnd::GetInnerBorderWidth() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 return 0;
617}
618
619void CPWL_Wnd::SetBorderWidth(int32_t nBorderWidth) {
620 if (HasFlag(PWS_BORDER))
621 m_sPrivateParam.dwBorderWidth = nBorderWidth;
622}
623
624CPWL_Color CPWL_Wnd::GetBorderColor() const {
625 if (HasFlag(PWS_BORDER))
626 return m_sPrivateParam.sBorderColor;
627
628 return CPWL_Color();
629}
630
631void CPWL_Wnd::SetBorderColor(const CPWL_Color& color) {
632 if (HasFlag(PWS_BORDER))
633 m_sPrivateParam.sBorderColor = color;
634}
635
636CPWL_Dash CPWL_Wnd::GetBorderDash() const {
637 return m_sPrivateParam.sDash;
638}
639
640void* CPWL_Wnd::GetAttachedData() const {
641 return m_sPrivateParam.pAttachedData;
642}
643
644void CPWL_Wnd::SetBorderDash(const CPWL_Dash& sDash) {
645 if (HasFlag(PWS_BORDER))
646 m_sPrivateParam.sDash = sDash;
647}
648
649CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const {
650 if (HasFlag(PWS_VSCROLL))
651 return m_pVScrollBar;
652
653 return NULL;
654}
655
656void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) {
657 CreateVScrollBar(cp);
658}
659
660void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) {
661 if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) {
662 PWL_CREATEPARAM scp = cp;
663
664 // flags
665 scp.dwFlags =
666 PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP;
667
668 scp.pParentWnd = this;
669 scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
670 scp.eCursorType = FXCT_ARROW;
671 scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY;
672
Lei Zhange00660b2015-08-13 15:40:18 -0700673 m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL);
674 m_pVScrollBar->Create(scp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 }
676}
677
678void CPWL_Wnd::SetCapture() {
679 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
680 pMsgCtrl->SetCapture(this);
681}
682
683void CPWL_Wnd::ReleaseCapture() {
684 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++)
685 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))
686 pChild->ReleaseCapture();
687
688 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl())
689 pMsgCtrl->ReleaseCapture();
690}
691
692void CPWL_Wnd::SetFocus() {
693 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
694 if (!pMsgCtrl->IsMainCaptureKeyboard(this))
695 pMsgCtrl->KillFocus();
696 pMsgCtrl->SetFocus(this);
697 }
698}
699
700void CPWL_Wnd::KillFocus() {
701 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
702 if (pMsgCtrl->IsWndCaptureKeyboard(this))
703 pMsgCtrl->KillFocus();
704 }
705}
706
707void CPWL_Wnd::OnSetFocus() {}
708
709void CPWL_Wnd::OnKillFocus() {}
710
711FX_BOOL CPWL_Wnd::WndHitTest(const CPDF_Point& point) const {
712 return IsValid() && IsVisible() && GetWindowRect().Contains(point.x, point.y);
713}
714
715FX_BOOL CPWL_Wnd::ClientHitTest(const CPDF_Point& point) const {
716 return IsValid() && IsVisible() && GetClientRect().Contains(point.x, point.y);
717}
718
719const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const {
720 if (m_sPrivateParam.pParentWnd)
721 return m_sPrivateParam.pParentWnd->GetRootWnd();
722
723 return this;
724}
725
726void CPWL_Wnd::SetVisible(FX_BOOL bVisible) {
727 if (IsValid()) {
728 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
729 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
730 pChild->SetVisible(bVisible);
731 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700732 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700733
734 if (bVisible != m_bVisible) {
735 m_bVisible = bVisible;
736 RePosChildWnd();
737 InvalidateRect();
738 }
739 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700740}
741
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742void CPWL_Wnd::SetClipRect(const CPDF_Rect& rect) {
743 m_rcClip = rect;
744 m_rcClip.Normalize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700745}
746
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747CPDF_Rect CPWL_Wnd::GetClipRect() const {
748 return m_rcClip;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700749}
750
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751FX_BOOL CPWL_Wnd::IsReadOnly() const {
752 return HasFlag(PWS_READONLY);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700753}
754
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700755void CPWL_Wnd::RePosChildWnd() {
756 CPDF_Rect rcContent = CPWL_Utils::DeflateRect(
757 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
758
759 CPWL_ScrollBar* pVSB = GetVScrollBar();
760
761 CPDF_Rect rcVScroll =
762 CPDF_Rect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom,
763 rcContent.right - 1.0f, rcContent.top);
764
765 if (pVSB)
766 pVSB->Move(rcVScroll, TRUE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700767}
768
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {}
770
771void CPWL_Wnd::SetCursor() {
772 if (IsValid()) {
773 if (IFX_SystemHandler* pSH = GetSystemHandler()) {
774 int32_t nCursorType = GetCreationParam().eCursorType;
775 pSH->SetCursor(nCursorType);
776 }
777 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700778}
779
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780void CPWL_Wnd::CreateMsgControl() {
781 if (!m_sPrivateParam.pMsgControl)
782 m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700783}
784
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785void CPWL_Wnd::DestroyMsgControl() {
786 if (CPWL_MsgControl* pMsgControl = GetMsgControl())
787 if (pMsgControl->IsWndCreated(this))
788 delete pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700789}
790
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700791CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const {
792 return m_sPrivateParam.pMsgControl;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700793}
794
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795FX_BOOL CPWL_Wnd::IsCaptureMouse() const {
796 return IsWndCaptureMouse(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700797}
798
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700799FX_BOOL CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
800 if (CPWL_MsgControl* pCtrl = GetMsgControl())
801 return pCtrl->IsWndCaptureMouse(pWnd);
802
803 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700804}
805
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806FX_BOOL CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
807 if (CPWL_MsgControl* pCtrl = GetMsgControl())
808 return pCtrl->IsWndCaptureKeyboard(pWnd);
809
810 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700811}
812
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700813FX_BOOL CPWL_Wnd::IsFocused() const {
814 if (CPWL_MsgControl* pCtrl = GetMsgControl())
815 return pCtrl->IsMainCaptureKeyboard(this);
816
817 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700818}
819
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700820CPDF_Rect CPWL_Wnd::GetFocusRect() const {
821 return CPWL_Utils::InflateRect(GetWindowRect(), 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700822}
823
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700824FX_FLOAT CPWL_Wnd::GetFontSize() const {
825 return m_sPrivateParam.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700826}
827
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700828void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize) {
829 m_sPrivateParam.fFontSize = fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700830}
831
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700832IFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const {
833 return m_sPrivateParam.pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700834}
835
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const {
837 return m_sPrivateParam.pFocusHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700838}
839
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700840IPWL_Provider* CPWL_Wnd::GetProvider() const {
841 return m_sPrivateParam.pProvider;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700842}
843
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844IFX_Edit_FontMap* CPWL_Wnd::GetFontMap() const {
845 return m_sPrivateParam.pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700846}
847
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(int32_t nBorderStyle) const {
849 CPWL_Color color;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700850
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700851 switch (nBorderStyle) {
852 case PBS_SOLID:
853 break;
854 case PBS_DASH:
855 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700856 case PBS_BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700857 color = CPWL_Color(COLORTYPE_GRAY, 1);
858 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700859 case PBS_INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700860 color = CPWL_Color(COLORTYPE_GRAY, 0.5f);
861 break;
862 case PBS_UNDERLINED:
863 break;
864 }
865
866 return color;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700867}
868
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700869CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(int32_t nBorderStyle) const {
870 CPWL_Color color;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700871
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872 switch (nBorderStyle) {
873 case PBS_SOLID:
874 break;
875 case PBS_DASH:
876 break;
877 case PBS_BEVELED:
878 color = CPWL_Utils::DevideColor(GetBackgroundColor(), 2);
879 break;
880 case PBS_INSET:
881 color = CPWL_Color(COLORTYPE_GRAY, 0.75f);
882 break;
883 case PBS_UNDERLINED:
884 break;
885 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700886
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700887 return color;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700888}
889
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700890int32_t CPWL_Wnd::GetTransparency() {
891 return m_sPrivateParam.nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700892}
893
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700894void CPWL_Wnd::SetTransparency(int32_t nTransparency) {
895 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
896 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
897 pChild->SetTransparency(nTransparency);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700898 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700899 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700900
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700901 m_sPrivateParam.nTransparency = nTransparency;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700902}
903
Tom Sepez60d909e2015-12-10 15:34:55 -0800904CFX_Matrix CPWL_Wnd::GetWindowMatrix() const {
905 CFX_Matrix mt = GetChildToRoot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700906
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700907 if (IPWL_Provider* pProvider = GetProvider()) {
908 mt.Concat(pProvider->GetWindowMatrix(GetAttachedData()));
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700909 return mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700910 }
911
912 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700913}
914
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700915void CPWL_Wnd::PWLtoWnd(const CPDF_Point& point, int32_t& x, int32_t& y) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800916 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700917 CPDF_Point pt = point;
918 mt.Transform(pt.x, pt.y);
919 x = (int32_t)(pt.x + 0.5);
920 y = (int32_t)(pt.y + 0.5);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700921}
922
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700923FX_RECT CPWL_Wnd::PWLtoWnd(const CPDF_Rect& rect) const {
924 CPDF_Rect rcTemp = rect;
Tom Sepez60d909e2015-12-10 15:34:55 -0800925 CFX_Matrix mt = GetWindowMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700926 mt.TransformRect(rcTemp);
927 return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5),
928 (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700929}
930
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700931FX_HWND CPWL_Wnd::GetAttachedHWnd() const {
932 return m_sPrivateParam.hAttachedWnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700933}
934
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700935CPDF_Point CPWL_Wnd::ChildToParent(const CPDF_Point& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800936 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700937 if (mt.IsIdentity())
938 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700939
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700940 CPDF_Point pt = point;
941 mt.Transform(pt.x, pt.y);
942 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700943}
944
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700945CPDF_Rect CPWL_Wnd::ChildToParent(const CPDF_Rect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800946 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947 if (mt.IsIdentity())
948 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700949
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700950 CPDF_Rect rc = rect;
951 mt.TransformRect(rc);
952 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700953}
954
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700955CPDF_Point CPWL_Wnd::ParentToChild(const CPDF_Point& point) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800956 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700957 if (mt.IsIdentity())
958 return point;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700959
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700960 mt.SetReverse(mt);
961 CPDF_Point pt = point;
962 mt.Transform(pt.x, pt.y);
963 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700964}
965
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700966CPDF_Rect CPWL_Wnd::ParentToChild(const CPDF_Rect& rect) const {
Tom Sepez60d909e2015-12-10 15:34:55 -0800967 CFX_Matrix mt = GetChildMatrix();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700968 if (mt.IsIdentity())
969 return rect;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700970
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700971 mt.SetReverse(mt);
972 CPDF_Rect rc = rect;
973 mt.TransformRect(rc);
974 return rc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700975}
976
Tom Sepez60d909e2015-12-10 15:34:55 -0800977CFX_Matrix CPWL_Wnd::GetChildToRoot() const {
978 CFX_Matrix mt(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700979 if (HasFlag(PWS_CHILD)) {
980 const CPWL_Wnd* pParent = this;
981 while (pParent) {
982 mt.Concat(pParent->GetChildMatrix());
983 pParent = pParent->GetParentWindow();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700984 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700985 }
986 return mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700987}
988
Tom Sepez60d909e2015-12-10 15:34:55 -0800989CFX_Matrix CPWL_Wnd::GetChildMatrix() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700990 if (HasFlag(PWS_CHILD))
991 return m_sPrivateParam.mtChild;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700992
Tom Sepez60d909e2015-12-10 15:34:55 -0800993 return CFX_Matrix(1, 0, 0, 1, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700994}
995
Tom Sepez60d909e2015-12-10 15:34:55 -0800996void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700997 m_sPrivateParam.mtChild = mt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700998}
999
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001000const CPWL_Wnd* CPWL_Wnd::GetFocused() const {
1001 if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) {
1002 return pMsgCtrl->m_pMainKeyboardWnd;
1003 }
1004
1005 return NULL;
1006}
1007
1008void CPWL_Wnd::EnableWindow(FX_BOOL bEnable) {
1009 if (m_bEnabled != bEnable) {
1010 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
1011 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
1012 pChild->EnableWindow(bEnable);
1013 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001014 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001015
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001016 m_bEnabled = bEnable;
1017
1018 if (bEnable)
1019 OnEnabled();
1020 else
1021 OnDisabled();
1022 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001023}
1024
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001025FX_BOOL CPWL_Wnd::IsEnabled() {
1026 return m_bEnabled;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001027}
1028
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001029void CPWL_Wnd::OnEnabled() {}
1030
1031void CPWL_Wnd::OnDisabled() {}
1032
1033FX_BOOL CPWL_Wnd::IsCTRLpressed(FX_DWORD nFlag) const {
1034 if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
1035 return pSystemHandler->IsCTRLKeyDown(nFlag);
1036 }
1037
1038 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001039}
1040
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001041FX_BOOL CPWL_Wnd::IsSHIFTpressed(FX_DWORD nFlag) const {
1042 if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
1043 return pSystemHandler->IsSHIFTKeyDown(nFlag);
1044 }
1045
1046 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001047}
1048
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001049FX_BOOL CPWL_Wnd::IsALTpressed(FX_DWORD nFlag) const {
1050 if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
1051 return pSystemHandler->IsALTKeyDown(nFlag);
1052 }
1053
1054 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001055}
1056
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001057FX_BOOL CPWL_Wnd::IsINSERTpressed(FX_DWORD nFlag) const {
1058 if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) {
1059 return pSystemHandler->IsINSERTKeyDown(nFlag);
1060 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001061
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001062 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001063}