John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // 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 Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 7 | #include <map> |
| 8 | |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 9 | #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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 12 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 13 | static std::map<int32_t, CPWL_Timer*>& GetPWLTimeMap() { |
Bruce Dawson | 26d96ff | 2015-01-05 15:31:49 -0800 | [diff] [blame] | 14 | // Leak the object at shutdown. |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 15 | static auto timeMap = new std::map<int32_t, CPWL_Timer*>; |
Bruce Dawson | 26d96ff | 2015-01-05 15:31:49 -0800 | [diff] [blame] | 16 | return *timeMap; |
| 17 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 18 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 19 | CPWL_Timer::CPWL_Timer(CPWL_TimerHandler* pAttached, |
| 20 | IFX_SystemHandler* pSystemHandler) |
| 21 | : m_nTimerID(0), m_pAttached(pAttached), m_pSystemHandler(pSystemHandler) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 22 | ASSERT(m_pAttached); |
| 23 | ASSERT(m_pSystemHandler); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | CPWL_Timer::~CPWL_Timer() { |
| 27 | KillPWLTimer(); |
| 28 | } |
| 29 | |
| 30 | int32_t CPWL_Timer::SetPWLTimer(int32_t nElapse) { |
| 31 | if (m_nTimerID != 0) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 32 | KillPWLTimer(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc); |
| 34 | |
| 35 | GetPWLTimeMap()[m_nTimerID] = this; |
| 36 | return m_nTimerID; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | void CPWL_Timer::KillPWLTimer() { |
| 40 | if (m_nTimerID == 0) |
| 41 | return; |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 42 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 43 | m_pSystemHandler->KillTimer(m_nTimerID); |
| 44 | GetPWLTimeMap().erase(m_nTimerID); |
| 45 | m_nTimerID = 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | void CPWL_Timer::TimerProc(int32_t idEvent) { |
| 49 | auto it = GetPWLTimeMap().find(idEvent); |
| 50 | if (it == GetPWLTimeMap().end()) |
| 51 | return; |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 52 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | CPWL_Timer* pTimer = it->second; |
| 54 | if (pTimer->m_pAttached) |
| 55 | pTimer->m_pAttached->TimerProc(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | CPWL_TimerHandler::CPWL_TimerHandler() : m_pTimer(NULL) {} |
| 59 | |
| 60 | CPWL_TimerHandler::~CPWL_TimerHandler() { |
| 61 | delete m_pTimer; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | void 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | void CPWL_TimerHandler::EndTimer() { |
| 73 | if (m_pTimer) |
| 74 | m_pTimer->KillPWLTimer(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 77 | void CPWL_TimerHandler::TimerProc() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 78 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | class CPWL_MsgControl { |
| 80 | friend class CPWL_Wnd; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 81 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 82 | public: |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 83 | explicit CPWL_MsgControl(CPWL_Wnd* pWnd) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | m_pCreatedWnd = pWnd; |
| 85 | Default(); |
| 86 | } |
| 87 | |
| 88 | ~CPWL_MsgControl() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | 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 Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 108 | if (pWnd) { |
| 109 | for (int32_t i = 0, sz = m_aMousePath.GetSize(); i < sz; i++) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | if (m_aMousePath.GetAt(i) == pWnd) |
| 111 | return TRUE; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 112 | } |
| 113 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 114 | |
| 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 Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 123 | if (pWnd) { |
| 124 | for (int32_t i = 0, sz = m_aKeyboardPath.GetSize(); i < sz; i++) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 125 | if (m_aKeyboardPath.GetAt(i) == pWnd) |
| 126 | return TRUE; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 127 | } |
| 128 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 129 | |
| 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 Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 146 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 147 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 148 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 149 | 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 Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 169 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 171 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 172 | void ReleaseCapture() { |
| 173 | m_pMainMouseWnd = NULL; |
| 174 | m_aMousePath.RemoveAll(); |
| 175 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 176 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | CPWL_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 | |
| 194 | CPWL_Wnd::~CPWL_Wnd() { |
| 195 | ASSERT(m_bCreated == FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 198 | CFX_ByteString CPWL_Wnd::GetClassName() const { |
| 199 | return "CPWL_Wnd"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 202 | void 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 Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 220 | ccp.mtChild = CFX_Matrix(1, 0, 0, 1, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 221 | |
| 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-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 234 | void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 235 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 236 | void CPWL_Wnd::OnCreated() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 237 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 238 | void CPWL_Wnd::OnDestroy() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 239 | |
Lei Zhang | ab5537d | 2016-01-06 14:58:14 -0800 | [diff] [blame^] | 240 | void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) { |
| 241 | if (m_sPrivateParam.pFocusHandler == handler) |
| 242 | m_sPrivateParam.pFocusHandler = nullptr; |
| 243 | } |
| 244 | |
| 245 | void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) { |
| 246 | if (m_sPrivateParam.pProvider == provider) |
| 247 | m_sPrivateParam.pProvider = nullptr; |
| 248 | } |
| 249 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 250 | void CPWL_Wnd::Destroy() { |
| 251 | KillFocus(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 252 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 253 | OnDestroy(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 254 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 255 | if (m_bCreated) { |
| 256 | for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) { |
| 257 | if (CPWL_Wnd* pChild = m_aChildren[i]) { |
| 258 | pChild->Destroy(); |
| 259 | delete pChild; |
| 260 | pChild = NULL; |
| 261 | } |
| 262 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 263 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 264 | if (m_sPrivateParam.pParentWnd) |
| 265 | m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD); |
| 266 | m_bCreated = FALSE; |
| 267 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 268 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 269 | DestroyMsgControl(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 270 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 271 | FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM)); |
| 272 | m_aChildren.RemoveAll(); |
| 273 | m_pVScrollBar = NULL; |
| 274 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 275 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | void CPWL_Wnd::Move(const CPDF_Rect& rcNew, FX_BOOL bReset, FX_BOOL bRefresh) { |
| 277 | if (IsValid()) { |
| 278 | CPDF_Rect rcOld = GetWindowRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 279 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 280 | 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 Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 286 | RePosChildWnd(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 287 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 288 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 289 | if (bRefresh) { |
| 290 | InvalidateRectMove(rcOld, rcNew); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 291 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 292 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 293 | m_sPrivateParam.rcRectWnd = m_rcWindow; |
| 294 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 297 | void CPWL_Wnd::InvalidateRectMove(const CPDF_Rect& rcOld, |
| 298 | const CPDF_Rect& rcNew) { |
| 299 | CPDF_Rect rcUnion = rcOld; |
| 300 | rcUnion.Union(rcNew); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 301 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 302 | InvalidateRect(&rcUnion); |
| 303 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 304 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 305 | void CPWL_Wnd::GetAppearanceStream(CFX_ByteString& sAppStream) { |
| 306 | if (IsValid()) { |
| 307 | CFX_ByteTextBuf sTextBuf; |
| 308 | GetAppearanceStream(sTextBuf); |
| 309 | sAppStream += sTextBuf.GetByteString(); |
| 310 | } |
| 311 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 312 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | void CPWL_Wnd::GetAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 314 | if (IsValid() && IsVisible()) { |
| 315 | GetThisAppearanceStream(sAppStream); |
| 316 | GetChildAppearanceStream(sAppStream); |
| 317 | } |
| 318 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 319 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | // if don't set,Get default apperance stream |
| 321 | void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 322 | CPDF_Rect rectWnd = GetWindowRect(); |
| 323 | if (!rectWnd.IsEmpty()) { |
| 324 | CFX_ByteTextBuf sThis; |
| 325 | |
| 326 | if (HasFlag(PWS_BACKGROUND)) |
| 327 | sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor()); |
| 328 | |
| 329 | if (HasFlag(PWS_BORDER)) { |
| 330 | sThis << CPWL_Utils::GetBorderAppStream( |
| 331 | rectWnd, (FX_FLOAT)GetBorderWidth(), GetBorderColor(), |
| 332 | GetBorderLeftTopColor(GetBorderStyle()), |
| 333 | GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(), |
| 334 | GetBorderDash()); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 335 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 336 | |
| 337 | sAppStream << sThis; |
| 338 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 341 | void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 342 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 343 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 344 | pChild->GetAppearanceStream(sAppStream); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 345 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 346 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 349 | void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 350 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 351 | if (IsValid() && IsVisible()) { |
| 352 | DrawThisAppearance(pDevice, pUser2Device); |
| 353 | DrawChildAppearance(pDevice, pUser2Device); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 358 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 359 | CPDF_Rect rectWnd = GetWindowRect(); |
| 360 | if (!rectWnd.IsEmpty()) { |
| 361 | if (HasFlag(PWS_BACKGROUND)) { |
| 362 | CPDF_Rect rcClient = CPWL_Utils::DeflateRect( |
| 363 | rectWnd, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth())); |
| 364 | CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient, |
| 365 | GetBackgroundColor(), GetTransparency()); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 366 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 367 | |
| 368 | if (HasFlag(PWS_BORDER)) |
| 369 | CPWL_Utils::DrawBorder( |
| 370 | pDevice, pUser2Device, rectWnd, (FX_FLOAT)GetBorderWidth(), |
| 371 | GetBorderColor(), GetBorderLeftTopColor(GetBorderStyle()), |
| 372 | GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(), |
| 373 | GetBorderDash(), GetTransparency()); |
| 374 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 377 | void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 378 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 379 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 380 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 381 | CFX_Matrix mt = pChild->GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 382 | if (mt.IsIdentity()) { |
| 383 | pChild->DrawAppearance(pDevice, pUser2Device); |
| 384 | } else { |
| 385 | mt.Concat(*pUser2Device); |
| 386 | pChild->DrawAppearance(pDevice, &mt); |
| 387 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 388 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 389 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 392 | void CPWL_Wnd::InvalidateRect(CPDF_Rect* pRect) { |
| 393 | if (IsValid()) { |
| 394 | CPDF_Rect rcRefresh = pRect ? *pRect : GetWindowRect(); |
| 395 | |
| 396 | if (!HasFlag(PWS_NOREFRESHCLIP)) { |
| 397 | CPDF_Rect rcClip = GetClipRect(); |
| 398 | if (!rcClip.IsEmpty()) { |
| 399 | rcRefresh.Intersect(rcClip); |
| 400 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 401 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 402 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 403 | FX_RECT rcWin = PWLtoWnd(rcRefresh); |
| 404 | rcWin.left -= PWL_INVALIDATE_INFLATE; |
| 405 | rcWin.top -= PWL_INVALIDATE_INFLATE; |
| 406 | rcWin.right += PWL_INVALIDATE_INFLATE; |
| 407 | rcWin.bottom += PWL_INVALIDATE_INFLATE; |
| 408 | |
| 409 | if (IFX_SystemHandler* pSH = GetSystemHandler()) { |
| 410 | if (FX_HWND hWnd = GetAttachedHWnd()) { |
| 411 | pSH->InvalidateRect(hWnd, rcWin); |
| 412 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 413 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 414 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 417 | #define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \ |
| 418 | FX_BOOL CPWL_Wnd::key_method_name(FX_WORD nChar, FX_DWORD nFlag) { \ |
| 419 | if (IsValid() && IsVisible() && IsEnabled()) { \ |
| 420 | if (IsWndCaptureKeyboard(this)) { \ |
| 421 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \ |
| 422 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \ |
| 423 | if (IsWndCaptureKeyboard(pChild)) { \ |
| 424 | return pChild->key_method_name(nChar, nFlag); \ |
| 425 | } \ |
| 426 | } \ |
| 427 | } \ |
| 428 | } \ |
| 429 | } \ |
| 430 | return FALSE; \ |
| 431 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 432 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 433 | #define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \ |
| 434 | FX_BOOL CPWL_Wnd::mouse_method_name(const CPDF_Point& point, \ |
| 435 | FX_DWORD nFlag) { \ |
| 436 | if (IsValid() && IsVisible() && IsEnabled()) { \ |
| 437 | if (IsWndCaptureMouse(this)) { \ |
| 438 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \ |
| 439 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \ |
| 440 | if (IsWndCaptureMouse(pChild)) { \ |
| 441 | return pChild->mouse_method_name(pChild->ParentToChild(point), \ |
| 442 | nFlag); \ |
| 443 | } \ |
| 444 | } \ |
| 445 | } \ |
| 446 | SetCursor(); \ |
| 447 | } else { \ |
| 448 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \ |
| 449 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \ |
| 450 | if (pChild->WndHitTest(pChild->ParentToChild(point))) { \ |
| 451 | return pChild->mouse_method_name(pChild->ParentToChild(point), \ |
| 452 | nFlag); \ |
| 453 | } \ |
| 454 | } \ |
| 455 | } \ |
| 456 | if (WndHitTest(point)) \ |
| 457 | SetCursor(); \ |
| 458 | } \ |
| 459 | } \ |
| 460 | return FALSE; \ |
| 461 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 462 | |
| 463 | PWL_IMPLEMENT_KEY_METHOD(OnKeyDown) |
| 464 | PWL_IMPLEMENT_KEY_METHOD(OnKeyUp) |
| 465 | PWL_IMPLEMENT_KEY_METHOD(OnChar) |
| 466 | |
| 467 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk) |
| 468 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown) |
| 469 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp) |
| 470 | PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk) |
| 471 | PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown) |
| 472 | PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 473 | PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown) |
| 474 | PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp) |
| 475 | PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove) |
| 476 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 477 | FX_BOOL CPWL_Wnd::OnMouseWheel(short zDelta, |
| 478 | const CPDF_Point& point, |
| 479 | FX_DWORD nFlag) { |
| 480 | if (IsValid() && IsVisible() && IsEnabled()) { |
| 481 | SetCursor(); |
| 482 | if (IsWndCaptureKeyboard(this)) { |
| 483 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 484 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 485 | if (IsWndCaptureKeyboard(pChild)) { |
| 486 | return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), |
| 487 | nFlag); |
| 488 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 489 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 490 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 491 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 492 | } |
| 493 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 496 | void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) { |
| 497 | m_aChildren.Add(pWnd); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 500 | void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) { |
| 501 | for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) { |
| 502 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 503 | if (pChild == pWnd) { |
| 504 | m_aChildren.RemoveAt(i); |
| 505 | break; |
| 506 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 507 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 508 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 511 | void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd, |
| 512 | FX_DWORD msg, |
| 513 | intptr_t wParam, |
| 514 | intptr_t lParam) { |
| 515 | switch (msg) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 516 | case PNM_ADDCHILD: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 517 | AddChild(pWnd); |
| 518 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 519 | case PNM_REMOVECHILD: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 520 | RemoveChild(pWnd); |
| 521 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 522 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 523 | break; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | FX_BOOL CPWL_Wnd::IsValid() const { |
| 528 | return m_bCreated; |
| 529 | } |
| 530 | |
| 531 | PWL_CREATEPARAM CPWL_Wnd::GetCreationParam() const { |
| 532 | return m_sPrivateParam; |
| 533 | } |
| 534 | |
| 535 | CPWL_Wnd* CPWL_Wnd::GetParentWindow() const { |
| 536 | return m_sPrivateParam.pParentWnd; |
| 537 | } |
| 538 | |
| 539 | CPDF_Rect CPWL_Wnd::GetOriginWindowRect() const { |
| 540 | return m_sPrivateParam.rcRectWnd; |
| 541 | } |
| 542 | |
| 543 | CPDF_Rect CPWL_Wnd::GetWindowRect() const { |
| 544 | return m_rcWindow; |
| 545 | } |
| 546 | |
| 547 | CPDF_Rect CPWL_Wnd::GetClientRect() const { |
| 548 | CPDF_Rect rcWindow = GetWindowRect(); |
| 549 | CPDF_Rect rcClient = CPWL_Utils::DeflateRect( |
| 550 | rcWindow, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth())); |
| 551 | if (CPWL_ScrollBar* pVSB = GetVScrollBar()) |
| 552 | rcClient.right -= pVSB->GetScrollBarWidth(); |
| 553 | |
| 554 | rcClient.Normalize(); |
| 555 | return rcWindow.Contains(rcClient) ? rcClient : CPDF_Rect(); |
| 556 | } |
| 557 | |
| 558 | CPDF_Point CPWL_Wnd::GetCenterPoint() const { |
| 559 | CPDF_Rect rcClient = GetClientRect(); |
| 560 | return CPDF_Point((rcClient.left + rcClient.right) * 0.5f, |
| 561 | (rcClient.top + rcClient.bottom) * 0.5f); |
| 562 | } |
| 563 | |
| 564 | CPDF_Rect CPWL_Wnd::GetClientCenterSquare() const { |
| 565 | return CPWL_Utils::GetCenterSquare(GetClientRect()); |
| 566 | } |
| 567 | |
| 568 | CPDF_Rect CPWL_Wnd::GetWindowCenterSquare() const { |
| 569 | return CPWL_Utils::GetCenterSquare( |
| 570 | CPWL_Utils::DeflateRect(GetWindowRect(), 0.1f)); |
| 571 | } |
| 572 | |
| 573 | FX_BOOL CPWL_Wnd::HasFlag(FX_DWORD dwFlags) const { |
| 574 | return (m_sPrivateParam.dwFlags & dwFlags) != 0; |
| 575 | } |
| 576 | |
| 577 | void CPWL_Wnd::RemoveFlag(FX_DWORD dwFlags) { |
| 578 | m_sPrivateParam.dwFlags &= ~dwFlags; |
| 579 | } |
| 580 | |
| 581 | void CPWL_Wnd::AddFlag(FX_DWORD dwFlags) { |
| 582 | m_sPrivateParam.dwFlags |= dwFlags; |
| 583 | } |
| 584 | |
| 585 | CPWL_Color CPWL_Wnd::GetBackgroundColor() const { |
| 586 | return m_sPrivateParam.sBackgroundColor; |
| 587 | } |
| 588 | |
| 589 | void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) { |
| 590 | m_sPrivateParam.sBackgroundColor = color; |
| 591 | } |
| 592 | |
| 593 | void CPWL_Wnd::SetTextColor(const CPWL_Color& color) { |
| 594 | m_sPrivateParam.sTextColor = color; |
| 595 | } |
| 596 | |
| 597 | void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color& color) { |
| 598 | m_sPrivateParam.sTextStrokeColor = color; |
| 599 | } |
| 600 | |
| 601 | CPWL_Color CPWL_Wnd::GetTextColor() const { |
| 602 | return m_sPrivateParam.sTextColor; |
| 603 | } |
| 604 | |
| 605 | CPWL_Color CPWL_Wnd::GetTextStrokeColor() const { |
| 606 | return m_sPrivateParam.sTextStrokeColor; |
| 607 | } |
| 608 | |
| 609 | int32_t CPWL_Wnd::GetBorderStyle() const { |
| 610 | return m_sPrivateParam.nBorderStyle; |
| 611 | } |
| 612 | |
| 613 | void CPWL_Wnd::SetBorderStyle(int32_t nBorderStyle) { |
| 614 | if (HasFlag(PWS_BORDER)) |
| 615 | m_sPrivateParam.nBorderStyle = nBorderStyle; |
| 616 | } |
| 617 | |
| 618 | int32_t CPWL_Wnd::GetBorderWidth() const { |
| 619 | if (HasFlag(PWS_BORDER)) |
| 620 | return m_sPrivateParam.dwBorderWidth; |
| 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | int32_t CPWL_Wnd::GetInnerBorderWidth() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | void CPWL_Wnd::SetBorderWidth(int32_t nBorderWidth) { |
| 630 | if (HasFlag(PWS_BORDER)) |
| 631 | m_sPrivateParam.dwBorderWidth = nBorderWidth; |
| 632 | } |
| 633 | |
| 634 | CPWL_Color CPWL_Wnd::GetBorderColor() const { |
| 635 | if (HasFlag(PWS_BORDER)) |
| 636 | return m_sPrivateParam.sBorderColor; |
| 637 | |
| 638 | return CPWL_Color(); |
| 639 | } |
| 640 | |
| 641 | void CPWL_Wnd::SetBorderColor(const CPWL_Color& color) { |
| 642 | if (HasFlag(PWS_BORDER)) |
| 643 | m_sPrivateParam.sBorderColor = color; |
| 644 | } |
| 645 | |
| 646 | CPWL_Dash CPWL_Wnd::GetBorderDash() const { |
| 647 | return m_sPrivateParam.sDash; |
| 648 | } |
| 649 | |
| 650 | void* CPWL_Wnd::GetAttachedData() const { |
| 651 | return m_sPrivateParam.pAttachedData; |
| 652 | } |
| 653 | |
| 654 | void CPWL_Wnd::SetBorderDash(const CPWL_Dash& sDash) { |
| 655 | if (HasFlag(PWS_BORDER)) |
| 656 | m_sPrivateParam.sDash = sDash; |
| 657 | } |
| 658 | |
| 659 | CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const { |
| 660 | if (HasFlag(PWS_VSCROLL)) |
| 661 | return m_pVScrollBar; |
| 662 | |
| 663 | return NULL; |
| 664 | } |
| 665 | |
| 666 | void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) { |
| 667 | CreateVScrollBar(cp); |
| 668 | } |
| 669 | |
| 670 | void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) { |
| 671 | if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) { |
| 672 | PWL_CREATEPARAM scp = cp; |
| 673 | |
| 674 | // flags |
| 675 | scp.dwFlags = |
| 676 | PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP; |
| 677 | |
| 678 | scp.pParentWnd = this; |
| 679 | scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; |
| 680 | scp.eCursorType = FXCT_ARROW; |
| 681 | scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY; |
| 682 | |
Lei Zhang | e00660b | 2015-08-13 15:40:18 -0700 | [diff] [blame] | 683 | m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL); |
| 684 | m_pVScrollBar->Create(scp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
| 688 | void CPWL_Wnd::SetCapture() { |
| 689 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) |
| 690 | pMsgCtrl->SetCapture(this); |
| 691 | } |
| 692 | |
| 693 | void CPWL_Wnd::ReleaseCapture() { |
| 694 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) |
| 695 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) |
| 696 | pChild->ReleaseCapture(); |
| 697 | |
| 698 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) |
| 699 | pMsgCtrl->ReleaseCapture(); |
| 700 | } |
| 701 | |
| 702 | void CPWL_Wnd::SetFocus() { |
| 703 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 704 | if (!pMsgCtrl->IsMainCaptureKeyboard(this)) |
| 705 | pMsgCtrl->KillFocus(); |
| 706 | pMsgCtrl->SetFocus(this); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | void CPWL_Wnd::KillFocus() { |
| 711 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 712 | if (pMsgCtrl->IsWndCaptureKeyboard(this)) |
| 713 | pMsgCtrl->KillFocus(); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | void CPWL_Wnd::OnSetFocus() {} |
| 718 | |
| 719 | void CPWL_Wnd::OnKillFocus() {} |
| 720 | |
| 721 | FX_BOOL CPWL_Wnd::WndHitTest(const CPDF_Point& point) const { |
| 722 | return IsValid() && IsVisible() && GetWindowRect().Contains(point.x, point.y); |
| 723 | } |
| 724 | |
| 725 | FX_BOOL CPWL_Wnd::ClientHitTest(const CPDF_Point& point) const { |
| 726 | return IsValid() && IsVisible() && GetClientRect().Contains(point.x, point.y); |
| 727 | } |
| 728 | |
| 729 | const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const { |
| 730 | if (m_sPrivateParam.pParentWnd) |
| 731 | return m_sPrivateParam.pParentWnd->GetRootWnd(); |
| 732 | |
| 733 | return this; |
| 734 | } |
| 735 | |
| 736 | void CPWL_Wnd::SetVisible(FX_BOOL bVisible) { |
| 737 | if (IsValid()) { |
| 738 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 739 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 740 | pChild->SetVisible(bVisible); |
| 741 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 742 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 743 | |
| 744 | if (bVisible != m_bVisible) { |
| 745 | m_bVisible = bVisible; |
| 746 | RePosChildWnd(); |
| 747 | InvalidateRect(); |
| 748 | } |
| 749 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 750 | } |
| 751 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 752 | void CPWL_Wnd::SetClipRect(const CPDF_Rect& rect) { |
| 753 | m_rcClip = rect; |
| 754 | m_rcClip.Normalize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 755 | } |
| 756 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 757 | CPDF_Rect CPWL_Wnd::GetClipRect() const { |
| 758 | return m_rcClip; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 761 | FX_BOOL CPWL_Wnd::IsReadOnly() const { |
| 762 | return HasFlag(PWS_READONLY); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 765 | void CPWL_Wnd::RePosChildWnd() { |
| 766 | CPDF_Rect rcContent = CPWL_Utils::DeflateRect( |
| 767 | GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth())); |
| 768 | |
| 769 | CPWL_ScrollBar* pVSB = GetVScrollBar(); |
| 770 | |
| 771 | CPDF_Rect rcVScroll = |
| 772 | CPDF_Rect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom, |
| 773 | rcContent.right - 1.0f, rcContent.top); |
| 774 | |
| 775 | if (pVSB) |
| 776 | pVSB->Move(rcVScroll, TRUE, FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 779 | void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {} |
| 780 | |
| 781 | void CPWL_Wnd::SetCursor() { |
| 782 | if (IsValid()) { |
| 783 | if (IFX_SystemHandler* pSH = GetSystemHandler()) { |
| 784 | int32_t nCursorType = GetCreationParam().eCursorType; |
| 785 | pSH->SetCursor(nCursorType); |
| 786 | } |
| 787 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 790 | void CPWL_Wnd::CreateMsgControl() { |
| 791 | if (!m_sPrivateParam.pMsgControl) |
| 792 | m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 795 | void CPWL_Wnd::DestroyMsgControl() { |
| 796 | if (CPWL_MsgControl* pMsgControl = GetMsgControl()) |
| 797 | if (pMsgControl->IsWndCreated(this)) |
| 798 | delete pMsgControl; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 801 | CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const { |
| 802 | return m_sPrivateParam.pMsgControl; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 805 | FX_BOOL CPWL_Wnd::IsCaptureMouse() const { |
| 806 | return IsWndCaptureMouse(this); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 809 | FX_BOOL CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { |
| 810 | if (CPWL_MsgControl* pCtrl = GetMsgControl()) |
| 811 | return pCtrl->IsWndCaptureMouse(pWnd); |
| 812 | |
| 813 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 816 | FX_BOOL CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { |
| 817 | if (CPWL_MsgControl* pCtrl = GetMsgControl()) |
| 818 | return pCtrl->IsWndCaptureKeyboard(pWnd); |
| 819 | |
| 820 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 823 | FX_BOOL CPWL_Wnd::IsFocused() const { |
| 824 | if (CPWL_MsgControl* pCtrl = GetMsgControl()) |
| 825 | return pCtrl->IsMainCaptureKeyboard(this); |
| 826 | |
| 827 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 830 | CPDF_Rect CPWL_Wnd::GetFocusRect() const { |
| 831 | return CPWL_Utils::InflateRect(GetWindowRect(), 1); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 834 | FX_FLOAT CPWL_Wnd::GetFontSize() const { |
| 835 | return m_sPrivateParam.fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 838 | void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize) { |
| 839 | m_sPrivateParam.fFontSize = fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 842 | IFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const { |
| 843 | return m_sPrivateParam.pSystemHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 846 | IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const { |
| 847 | return m_sPrivateParam.pFocusHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 850 | IPWL_Provider* CPWL_Wnd::GetProvider() const { |
| 851 | return m_sPrivateParam.pProvider; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 854 | IFX_Edit_FontMap* CPWL_Wnd::GetFontMap() const { |
| 855 | return m_sPrivateParam.pFontMap; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 858 | CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(int32_t nBorderStyle) const { |
| 859 | CPWL_Color color; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 860 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 861 | switch (nBorderStyle) { |
| 862 | case PBS_SOLID: |
| 863 | break; |
| 864 | case PBS_DASH: |
| 865 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 866 | case PBS_BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 867 | color = CPWL_Color(COLORTYPE_GRAY, 1); |
| 868 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 869 | case PBS_INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 870 | color = CPWL_Color(COLORTYPE_GRAY, 0.5f); |
| 871 | break; |
| 872 | case PBS_UNDERLINED: |
| 873 | break; |
| 874 | } |
| 875 | |
| 876 | return color; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 879 | CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(int32_t nBorderStyle) const { |
| 880 | CPWL_Color color; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 881 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 882 | switch (nBorderStyle) { |
| 883 | case PBS_SOLID: |
| 884 | break; |
| 885 | case PBS_DASH: |
| 886 | break; |
| 887 | case PBS_BEVELED: |
| 888 | color = CPWL_Utils::DevideColor(GetBackgroundColor(), 2); |
| 889 | break; |
| 890 | case PBS_INSET: |
| 891 | color = CPWL_Color(COLORTYPE_GRAY, 0.75f); |
| 892 | break; |
| 893 | case PBS_UNDERLINED: |
| 894 | break; |
| 895 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 896 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 897 | return color; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 898 | } |
| 899 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 900 | int32_t CPWL_Wnd::GetTransparency() { |
| 901 | return m_sPrivateParam.nTransparency; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 904 | void CPWL_Wnd::SetTransparency(int32_t nTransparency) { |
| 905 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 906 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 907 | pChild->SetTransparency(nTransparency); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 908 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 909 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 910 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 911 | m_sPrivateParam.nTransparency = nTransparency; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 914 | CFX_Matrix CPWL_Wnd::GetWindowMatrix() const { |
| 915 | CFX_Matrix mt = GetChildToRoot(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 916 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 917 | if (IPWL_Provider* pProvider = GetProvider()) { |
| 918 | mt.Concat(pProvider->GetWindowMatrix(GetAttachedData())); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 919 | return mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | return mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 925 | void CPWL_Wnd::PWLtoWnd(const CPDF_Point& point, int32_t& x, int32_t& y) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 926 | CFX_Matrix mt = GetWindowMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 927 | CPDF_Point pt = point; |
| 928 | mt.Transform(pt.x, pt.y); |
| 929 | x = (int32_t)(pt.x + 0.5); |
| 930 | y = (int32_t)(pt.y + 0.5); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 931 | } |
| 932 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 933 | FX_RECT CPWL_Wnd::PWLtoWnd(const CPDF_Rect& rect) const { |
| 934 | CPDF_Rect rcTemp = rect; |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 935 | CFX_Matrix mt = GetWindowMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 936 | mt.TransformRect(rcTemp); |
| 937 | return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5), |
| 938 | (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 941 | FX_HWND CPWL_Wnd::GetAttachedHWnd() const { |
| 942 | return m_sPrivateParam.hAttachedWnd; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 943 | } |
| 944 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 945 | CPDF_Point CPWL_Wnd::ChildToParent(const CPDF_Point& point) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 946 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 947 | if (mt.IsIdentity()) |
| 948 | return point; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 949 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 950 | CPDF_Point pt = point; |
| 951 | mt.Transform(pt.x, pt.y); |
| 952 | return pt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 955 | CPDF_Rect CPWL_Wnd::ChildToParent(const CPDF_Rect& rect) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 956 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 957 | if (mt.IsIdentity()) |
| 958 | return rect; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 959 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 960 | CPDF_Rect rc = rect; |
| 961 | mt.TransformRect(rc); |
| 962 | return rc; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 965 | CPDF_Point CPWL_Wnd::ParentToChild(const CPDF_Point& point) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 966 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 967 | if (mt.IsIdentity()) |
| 968 | return point; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 969 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 970 | mt.SetReverse(mt); |
| 971 | CPDF_Point pt = point; |
| 972 | mt.Transform(pt.x, pt.y); |
| 973 | return pt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 974 | } |
| 975 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 976 | CPDF_Rect CPWL_Wnd::ParentToChild(const CPDF_Rect& rect) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 977 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 978 | if (mt.IsIdentity()) |
| 979 | return rect; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 980 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 981 | mt.SetReverse(mt); |
| 982 | CPDF_Rect rc = rect; |
| 983 | mt.TransformRect(rc); |
| 984 | return rc; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 987 | CFX_Matrix CPWL_Wnd::GetChildToRoot() const { |
| 988 | CFX_Matrix mt(1, 0, 0, 1, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 989 | if (HasFlag(PWS_CHILD)) { |
| 990 | const CPWL_Wnd* pParent = this; |
| 991 | while (pParent) { |
| 992 | mt.Concat(pParent->GetChildMatrix()); |
| 993 | pParent = pParent->GetParentWindow(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 994 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 995 | } |
| 996 | return mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 997 | } |
| 998 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 999 | CFX_Matrix CPWL_Wnd::GetChildMatrix() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1000 | if (HasFlag(PWS_CHILD)) |
| 1001 | return m_sPrivateParam.mtChild; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1002 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1003 | return CFX_Matrix(1, 0, 0, 1, 0, 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1006 | void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1007 | m_sPrivateParam.mtChild = mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1010 | const CPWL_Wnd* CPWL_Wnd::GetFocused() const { |
| 1011 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 1012 | return pMsgCtrl->m_pMainKeyboardWnd; |
| 1013 | } |
| 1014 | |
| 1015 | return NULL; |
| 1016 | } |
| 1017 | |
| 1018 | void CPWL_Wnd::EnableWindow(FX_BOOL bEnable) { |
| 1019 | if (m_bEnabled != bEnable) { |
| 1020 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 1021 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 1022 | pChild->EnableWindow(bEnable); |
| 1023 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1024 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1025 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1026 | m_bEnabled = bEnable; |
| 1027 | |
| 1028 | if (bEnable) |
| 1029 | OnEnabled(); |
| 1030 | else |
| 1031 | OnDisabled(); |
| 1032 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1035 | FX_BOOL CPWL_Wnd::IsEnabled() { |
| 1036 | return m_bEnabled; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1039 | void CPWL_Wnd::OnEnabled() {} |
| 1040 | |
| 1041 | void CPWL_Wnd::OnDisabled() {} |
| 1042 | |
| 1043 | FX_BOOL CPWL_Wnd::IsCTRLpressed(FX_DWORD nFlag) const { |
| 1044 | if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) { |
| 1045 | return pSystemHandler->IsCTRLKeyDown(nFlag); |
| 1046 | } |
| 1047 | |
| 1048 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1051 | FX_BOOL CPWL_Wnd::IsSHIFTpressed(FX_DWORD nFlag) const { |
| 1052 | if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) { |
| 1053 | return pSystemHandler->IsSHIFTKeyDown(nFlag); |
| 1054 | } |
| 1055 | |
| 1056 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1059 | FX_BOOL CPWL_Wnd::IsALTpressed(FX_DWORD nFlag) const { |
| 1060 | if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) { |
| 1061 | return pSystemHandler->IsALTKeyDown(nFlag); |
| 1062 | } |
| 1063 | |
| 1064 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1067 | FX_BOOL CPWL_Wnd::IsINSERTpressed(FX_DWORD nFlag) const { |
| 1068 | if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) { |
| 1069 | return pSystemHandler->IsINSERTKeyDown(nFlag); |
| 1070 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1071 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1072 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1073 | } |