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 | |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 9 | #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" |
| 10 | #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
| 11 | #include "fpdfsdk/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 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 88 | ~CPWL_MsgControl() { Default(); } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | |
| 90 | void Default() { |
| 91 | m_aMousePath.RemoveAll(); |
| 92 | m_aKeyboardPath.RemoveAll(); |
| 93 | m_pMainMouseWnd = NULL; |
| 94 | m_pMainKeyboardWnd = NULL; |
| 95 | } |
| 96 | |
| 97 | FX_BOOL IsWndCreated(const CPWL_Wnd* pWnd) const { |
| 98 | return m_pCreatedWnd == pWnd; |
| 99 | } |
| 100 | |
| 101 | FX_BOOL IsMainCaptureMouse(const CPWL_Wnd* pWnd) const { |
| 102 | return pWnd == m_pMainMouseWnd; |
| 103 | } |
| 104 | |
| 105 | FX_BOOL IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 106 | if (pWnd) { |
| 107 | for (int32_t i = 0, sz = m_aMousePath.GetSize(); i < sz; i++) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | if (m_aMousePath.GetAt(i) == pWnd) |
| 109 | return TRUE; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 110 | } |
| 111 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 112 | |
| 113 | return FALSE; |
| 114 | } |
| 115 | |
| 116 | FX_BOOL IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const { |
| 117 | return pWnd == m_pMainKeyboardWnd; |
| 118 | } |
| 119 | |
| 120 | FX_BOOL IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 121 | if (pWnd) { |
| 122 | for (int32_t i = 0, sz = m_aKeyboardPath.GetSize(); i < sz; i++) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | if (m_aKeyboardPath.GetAt(i) == pWnd) |
| 124 | return TRUE; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 125 | } |
| 126 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 127 | |
| 128 | return FALSE; |
| 129 | } |
| 130 | |
| 131 | void SetFocus(CPWL_Wnd* pWnd) { |
| 132 | m_aKeyboardPath.RemoveAll(); |
| 133 | |
| 134 | if (pWnd) { |
| 135 | m_pMainKeyboardWnd = pWnd; |
| 136 | |
| 137 | CPWL_Wnd* pParent = pWnd; |
| 138 | while (pParent) { |
| 139 | m_aKeyboardPath.Add(pParent); |
| 140 | pParent = pParent->GetParentWindow(); |
| 141 | } |
| 142 | |
| 143 | pWnd->OnSetFocus(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 144 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 146 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 147 | void KillFocus() { |
| 148 | if (m_aKeyboardPath.GetSize() > 0) |
| 149 | if (CPWL_Wnd* pWnd = m_aKeyboardPath.GetAt(0)) |
| 150 | pWnd->OnKillFocus(); |
| 151 | |
| 152 | m_pMainKeyboardWnd = NULL; |
| 153 | m_aKeyboardPath.RemoveAll(); |
| 154 | } |
| 155 | |
| 156 | void SetCapture(CPWL_Wnd* pWnd) { |
| 157 | m_aMousePath.RemoveAll(); |
| 158 | |
| 159 | if (pWnd) { |
| 160 | m_pMainMouseWnd = pWnd; |
| 161 | |
| 162 | CPWL_Wnd* pParent = pWnd; |
| 163 | while (pParent) { |
| 164 | m_aMousePath.Add(pParent); |
| 165 | pParent = pParent->GetParentWindow(); |
| 166 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 167 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 168 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 169 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | void ReleaseCapture() { |
| 171 | m_pMainMouseWnd = NULL; |
| 172 | m_aMousePath.RemoveAll(); |
| 173 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 174 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | private: |
| 176 | CFX_ArrayTemplate<CPWL_Wnd*> m_aMousePath; |
| 177 | CFX_ArrayTemplate<CPWL_Wnd*> m_aKeyboardPath; |
| 178 | CPWL_Wnd* m_pCreatedWnd; |
| 179 | CPWL_Wnd* m_pMainMouseWnd; |
| 180 | CPWL_Wnd* m_pMainKeyboardWnd; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | CPWL_Wnd::CPWL_Wnd() |
| 184 | : m_pVScrollBar(NULL), |
| 185 | m_rcWindow(), |
| 186 | m_rcClip(), |
| 187 | m_bCreated(FALSE), |
| 188 | m_bVisible(FALSE), |
| 189 | m_bNotifying(FALSE), |
| 190 | m_bEnabled(TRUE) {} |
| 191 | |
| 192 | CPWL_Wnd::~CPWL_Wnd() { |
| 193 | ASSERT(m_bCreated == FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 196 | CFX_ByteString CPWL_Wnd::GetClassName() const { |
| 197 | return "CPWL_Wnd"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) { |
| 201 | if (!IsValid()) { |
| 202 | m_sPrivateParam = cp; |
| 203 | |
| 204 | OnCreate(m_sPrivateParam); |
| 205 | |
| 206 | m_sPrivateParam.rcRectWnd.Normalize(); |
| 207 | m_rcWindow = m_sPrivateParam.rcRectWnd; |
| 208 | m_rcClip = CPWL_Utils::InflateRect(m_rcWindow, 1.0f); |
| 209 | |
| 210 | CreateMsgControl(); |
| 211 | |
| 212 | if (m_sPrivateParam.pParentWnd) |
| 213 | m_sPrivateParam.pParentWnd->OnNotify(this, PNM_ADDCHILD); |
| 214 | |
| 215 | PWL_CREATEPARAM ccp = m_sPrivateParam; |
| 216 | |
| 217 | ccp.dwFlags &= 0xFFFF0000L; // remove sub styles |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 218 | ccp.mtChild = CFX_Matrix(1, 0, 0, 1, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 219 | |
| 220 | CreateScrollBar(ccp); |
| 221 | CreateChildWnd(ccp); |
| 222 | |
| 223 | m_bVisible = HasFlag(PWS_VISIBLE); |
| 224 | |
| 225 | OnCreated(); |
| 226 | |
| 227 | RePosChildWnd(); |
| 228 | m_bCreated = TRUE; |
| 229 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 233 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 234 | void CPWL_Wnd::OnCreated() {} |
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::OnDestroy() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 237 | |
Lei Zhang | ab5537d | 2016-01-06 14:58:14 -0800 | [diff] [blame] | 238 | void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) { |
| 239 | if (m_sPrivateParam.pFocusHandler == handler) |
| 240 | m_sPrivateParam.pFocusHandler = nullptr; |
| 241 | } |
| 242 | |
| 243 | void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) { |
| 244 | if (m_sPrivateParam.pProvider == provider) |
| 245 | m_sPrivateParam.pProvider = nullptr; |
| 246 | } |
| 247 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 248 | void CPWL_Wnd::Destroy() { |
| 249 | KillFocus(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 250 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 251 | OnDestroy(); |
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 | if (m_bCreated) { |
| 254 | for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) { |
| 255 | if (CPWL_Wnd* pChild = m_aChildren[i]) { |
| 256 | pChild->Destroy(); |
| 257 | delete pChild; |
| 258 | pChild = NULL; |
| 259 | } |
| 260 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 261 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 262 | if (m_sPrivateParam.pParentWnd) |
| 263 | m_sPrivateParam.pParentWnd->OnNotify(this, PNM_REMOVECHILD); |
| 264 | m_bCreated = FALSE; |
| 265 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 266 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 267 | DestroyMsgControl(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 268 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 269 | FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM)); |
| 270 | m_aChildren.RemoveAll(); |
| 271 | m_pVScrollBar = NULL; |
| 272 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 273 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 274 | void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, |
| 275 | FX_BOOL bReset, |
| 276 | FX_BOOL bRefresh) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | if (IsValid()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 278 | CFX_FloatRect 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 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 297 | void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld, |
| 298 | const CFX_FloatRect& rcNew) { |
| 299 | CFX_FloatRect rcUnion = rcOld; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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_ByteTextBuf& sAppStream) { |
| 306 | if (IsValid() && IsVisible()) { |
| 307 | GetThisAppearanceStream(sAppStream); |
| 308 | GetChildAppearanceStream(sAppStream); |
| 309 | } |
| 310 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 311 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 312 | // if don't set,Get default apperance stream |
| 313 | void CPWL_Wnd::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 314 | CFX_FloatRect rectWnd = GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 315 | if (!rectWnd.IsEmpty()) { |
| 316 | CFX_ByteTextBuf sThis; |
| 317 | |
| 318 | if (HasFlag(PWS_BACKGROUND)) |
| 319 | sThis << CPWL_Utils::GetRectFillAppStream(rectWnd, GetBackgroundColor()); |
| 320 | |
| 321 | if (HasFlag(PWS_BORDER)) { |
| 322 | sThis << CPWL_Utils::GetBorderAppStream( |
| 323 | rectWnd, (FX_FLOAT)GetBorderWidth(), GetBorderColor(), |
| 324 | GetBorderLeftTopColor(GetBorderStyle()), |
| 325 | GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(), |
| 326 | GetBorderDash()); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 327 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 328 | |
| 329 | sAppStream << sThis; |
| 330 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 333 | void CPWL_Wnd::GetChildAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 334 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 335 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 336 | pChild->GetAppearanceStream(sAppStream); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 337 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 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::DrawAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 342 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 343 | if (IsValid() && IsVisible()) { |
| 344 | DrawThisAppearance(pDevice, pUser2Device); |
| 345 | DrawChildAppearance(pDevice, pUser2Device); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 350 | CFX_Matrix* pUser2Device) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 351 | CFX_FloatRect rectWnd = GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 352 | if (!rectWnd.IsEmpty()) { |
| 353 | if (HasFlag(PWS_BACKGROUND)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 354 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 355 | rectWnd, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth())); |
| 356 | CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient, |
| 357 | GetBackgroundColor(), GetTransparency()); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 358 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 359 | |
| 360 | if (HasFlag(PWS_BORDER)) |
Lei Zhang | 7457e38 | 2016-01-06 23:00:34 -0800 | [diff] [blame] | 361 | CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd, |
| 362 | (FX_FLOAT)GetBorderWidth(), GetBorderColor(), |
| 363 | GetBorderLeftTopColor(GetBorderStyle()), |
| 364 | GetBorderRightBottomColor(GetBorderStyle()), |
| 365 | GetBorderStyle(), GetTransparency()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 366 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 369 | void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 370 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 371 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 372 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 373 | CFX_Matrix mt = pChild->GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 374 | if (mt.IsIdentity()) { |
| 375 | pChild->DrawAppearance(pDevice, pUser2Device); |
| 376 | } else { |
| 377 | mt.Concat(*pUser2Device); |
| 378 | pChild->DrawAppearance(pDevice, &mt); |
| 379 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 380 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 381 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 384 | void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 385 | if (IsValid()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 386 | CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 387 | |
| 388 | if (!HasFlag(PWS_NOREFRESHCLIP)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 389 | CFX_FloatRect rcClip = GetClipRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 390 | if (!rcClip.IsEmpty()) { |
| 391 | rcRefresh.Intersect(rcClip); |
| 392 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 393 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 394 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 395 | FX_RECT rcWin = PWLtoWnd(rcRefresh); |
| 396 | rcWin.left -= PWL_INVALIDATE_INFLATE; |
| 397 | rcWin.top -= PWL_INVALIDATE_INFLATE; |
| 398 | rcWin.right += PWL_INVALIDATE_INFLATE; |
| 399 | rcWin.bottom += PWL_INVALIDATE_INFLATE; |
| 400 | |
| 401 | if (IFX_SystemHandler* pSH = GetSystemHandler()) { |
| 402 | if (FX_HWND hWnd = GetAttachedHWnd()) { |
| 403 | pSH->InvalidateRect(hWnd, rcWin); |
| 404 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 405 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 406 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 409 | #define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \ |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 410 | FX_BOOL CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 411 | if (IsValid() && IsVisible() && IsEnabled()) { \ |
| 412 | if (IsWndCaptureKeyboard(this)) { \ |
| 413 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \ |
| 414 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \ |
| 415 | if (IsWndCaptureKeyboard(pChild)) { \ |
| 416 | return pChild->key_method_name(nChar, nFlag); \ |
| 417 | } \ |
| 418 | } \ |
| 419 | } \ |
| 420 | } \ |
| 421 | } \ |
| 422 | return FALSE; \ |
| 423 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 424 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 425 | #define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \ |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 426 | FX_BOOL CPWL_Wnd::mouse_method_name(const CFX_FloatPoint& point, \ |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 427 | uint32_t nFlag) { \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | if (IsValid() && IsVisible() && IsEnabled()) { \ |
| 429 | if (IsWndCaptureMouse(this)) { \ |
| 430 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \ |
| 431 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \ |
| 432 | if (IsWndCaptureMouse(pChild)) { \ |
| 433 | return pChild->mouse_method_name(pChild->ParentToChild(point), \ |
| 434 | nFlag); \ |
| 435 | } \ |
| 436 | } \ |
| 437 | } \ |
| 438 | SetCursor(); \ |
| 439 | } else { \ |
| 440 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { \ |
| 441 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { \ |
| 442 | if (pChild->WndHitTest(pChild->ParentToChild(point))) { \ |
| 443 | return pChild->mouse_method_name(pChild->ParentToChild(point), \ |
| 444 | nFlag); \ |
| 445 | } \ |
| 446 | } \ |
| 447 | } \ |
| 448 | if (WndHitTest(point)) \ |
| 449 | SetCursor(); \ |
| 450 | } \ |
| 451 | } \ |
| 452 | return FALSE; \ |
| 453 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 454 | |
| 455 | PWL_IMPLEMENT_KEY_METHOD(OnKeyDown) |
| 456 | PWL_IMPLEMENT_KEY_METHOD(OnKeyUp) |
| 457 | PWL_IMPLEMENT_KEY_METHOD(OnChar) |
| 458 | |
| 459 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk) |
| 460 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown) |
| 461 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp) |
| 462 | PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDblClk) |
| 463 | PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonDown) |
| 464 | PWL_IMPLEMENT_MOUSE_METHOD(OnMButtonUp) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 465 | PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown) |
| 466 | PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp) |
| 467 | PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove) |
| 468 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 469 | FX_BOOL CPWL_Wnd::OnMouseWheel(short zDelta, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 470 | const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 471 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 472 | if (IsValid() && IsVisible() && IsEnabled()) { |
| 473 | SetCursor(); |
| 474 | if (IsWndCaptureKeyboard(this)) { |
| 475 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 476 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 477 | if (IsWndCaptureKeyboard(pChild)) { |
| 478 | return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), |
| 479 | nFlag); |
| 480 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 481 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 482 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 483 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 484 | } |
| 485 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 488 | void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) { |
| 489 | m_aChildren.Add(pWnd); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 492 | void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) { |
| 493 | for (int32_t i = m_aChildren.GetSize() - 1; i >= 0; i--) { |
| 494 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 495 | if (pChild == pWnd) { |
| 496 | m_aChildren.RemoveAt(i); |
| 497 | break; |
| 498 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 499 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 500 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 503 | void CPWL_Wnd::OnNotify(CPWL_Wnd* pWnd, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 504 | uint32_t msg, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 505 | intptr_t wParam, |
| 506 | intptr_t lParam) { |
| 507 | switch (msg) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 508 | case PNM_ADDCHILD: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 509 | AddChild(pWnd); |
| 510 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 511 | case PNM_REMOVECHILD: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 512 | RemoveChild(pWnd); |
| 513 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 514 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 515 | break; |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | FX_BOOL CPWL_Wnd::IsValid() const { |
| 520 | return m_bCreated; |
| 521 | } |
| 522 | |
Lei Zhang | 7457e38 | 2016-01-06 23:00:34 -0800 | [diff] [blame] | 523 | const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 524 | return m_sPrivateParam; |
| 525 | } |
| 526 | |
| 527 | CPWL_Wnd* CPWL_Wnd::GetParentWindow() const { |
| 528 | return m_sPrivateParam.pParentWnd; |
| 529 | } |
| 530 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 531 | CFX_FloatRect CPWL_Wnd::GetWindowRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 532 | return m_rcWindow; |
| 533 | } |
| 534 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 535 | CFX_FloatRect CPWL_Wnd::GetClientRect() const { |
| 536 | CFX_FloatRect rcWindow = GetWindowRect(); |
| 537 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 538 | rcWindow, (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth())); |
| 539 | if (CPWL_ScrollBar* pVSB = GetVScrollBar()) |
| 540 | rcClient.right -= pVSB->GetScrollBarWidth(); |
| 541 | |
| 542 | rcClient.Normalize(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 543 | return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 546 | CFX_FloatPoint CPWL_Wnd::GetCenterPoint() const { |
| 547 | CFX_FloatRect rcClient = GetClientRect(); |
| 548 | return CFX_FloatPoint((rcClient.left + rcClient.right) * 0.5f, |
| 549 | (rcClient.top + rcClient.bottom) * 0.5f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | } |
| 551 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 552 | FX_BOOL CPWL_Wnd::HasFlag(uint32_t dwFlags) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 553 | return (m_sPrivateParam.dwFlags & dwFlags) != 0; |
| 554 | } |
| 555 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 556 | void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 557 | m_sPrivateParam.dwFlags &= ~dwFlags; |
| 558 | } |
| 559 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 560 | void CPWL_Wnd::AddFlag(uint32_t dwFlags) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | m_sPrivateParam.dwFlags |= dwFlags; |
| 562 | } |
| 563 | |
| 564 | CPWL_Color CPWL_Wnd::GetBackgroundColor() const { |
| 565 | return m_sPrivateParam.sBackgroundColor; |
| 566 | } |
| 567 | |
| 568 | void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) { |
| 569 | m_sPrivateParam.sBackgroundColor = color; |
| 570 | } |
| 571 | |
| 572 | void CPWL_Wnd::SetTextColor(const CPWL_Color& color) { |
| 573 | m_sPrivateParam.sTextColor = color; |
| 574 | } |
| 575 | |
| 576 | void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color& color) { |
| 577 | m_sPrivateParam.sTextStrokeColor = color; |
| 578 | } |
| 579 | |
| 580 | CPWL_Color CPWL_Wnd::GetTextColor() const { |
| 581 | return m_sPrivateParam.sTextColor; |
| 582 | } |
| 583 | |
| 584 | CPWL_Color CPWL_Wnd::GetTextStrokeColor() const { |
| 585 | return m_sPrivateParam.sTextStrokeColor; |
| 586 | } |
| 587 | |
| 588 | int32_t CPWL_Wnd::GetBorderStyle() const { |
| 589 | return m_sPrivateParam.nBorderStyle; |
| 590 | } |
| 591 | |
| 592 | void CPWL_Wnd::SetBorderStyle(int32_t nBorderStyle) { |
| 593 | if (HasFlag(PWS_BORDER)) |
| 594 | m_sPrivateParam.nBorderStyle = nBorderStyle; |
| 595 | } |
| 596 | |
| 597 | int32_t CPWL_Wnd::GetBorderWidth() const { |
| 598 | if (HasFlag(PWS_BORDER)) |
| 599 | return m_sPrivateParam.dwBorderWidth; |
| 600 | |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | int32_t CPWL_Wnd::GetInnerBorderWidth() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 605 | return 0; |
| 606 | } |
| 607 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 608 | CPWL_Color CPWL_Wnd::GetBorderColor() const { |
| 609 | if (HasFlag(PWS_BORDER)) |
| 610 | return m_sPrivateParam.sBorderColor; |
| 611 | |
| 612 | return CPWL_Color(); |
| 613 | } |
| 614 | |
Lei Zhang | 7457e38 | 2016-01-06 23:00:34 -0800 | [diff] [blame] | 615 | const CPWL_Dash& CPWL_Wnd::GetBorderDash() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 616 | return m_sPrivateParam.sDash; |
| 617 | } |
| 618 | |
| 619 | void* CPWL_Wnd::GetAttachedData() const { |
| 620 | return m_sPrivateParam.pAttachedData; |
| 621 | } |
| 622 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 623 | CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const { |
| 624 | if (HasFlag(PWS_VSCROLL)) |
| 625 | return m_pVScrollBar; |
| 626 | |
| 627 | return NULL; |
| 628 | } |
| 629 | |
| 630 | void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) { |
| 631 | CreateVScrollBar(cp); |
| 632 | } |
| 633 | |
| 634 | void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) { |
| 635 | if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) { |
| 636 | PWL_CREATEPARAM scp = cp; |
| 637 | |
| 638 | // flags |
| 639 | scp.dwFlags = |
| 640 | PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP; |
| 641 | |
| 642 | scp.pParentWnd = this; |
| 643 | scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; |
| 644 | scp.eCursorType = FXCT_ARROW; |
| 645 | scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY; |
| 646 | |
Lei Zhang | e00660b | 2015-08-13 15:40:18 -0700 | [diff] [blame] | 647 | m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL); |
| 648 | m_pVScrollBar->Create(scp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
| 652 | void CPWL_Wnd::SetCapture() { |
| 653 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) |
| 654 | pMsgCtrl->SetCapture(this); |
| 655 | } |
| 656 | |
| 657 | void CPWL_Wnd::ReleaseCapture() { |
| 658 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) |
| 659 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) |
| 660 | pChild->ReleaseCapture(); |
| 661 | |
| 662 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) |
| 663 | pMsgCtrl->ReleaseCapture(); |
| 664 | } |
| 665 | |
| 666 | void CPWL_Wnd::SetFocus() { |
| 667 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 668 | if (!pMsgCtrl->IsMainCaptureKeyboard(this)) |
| 669 | pMsgCtrl->KillFocus(); |
| 670 | pMsgCtrl->SetFocus(this); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | void CPWL_Wnd::KillFocus() { |
| 675 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 676 | if (pMsgCtrl->IsWndCaptureKeyboard(this)) |
| 677 | pMsgCtrl->KillFocus(); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | void CPWL_Wnd::OnSetFocus() {} |
| 682 | |
| 683 | void CPWL_Wnd::OnKillFocus() {} |
| 684 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 685 | FX_BOOL CPWL_Wnd::WndHitTest(const CFX_FloatPoint& point) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 686 | return IsValid() && IsVisible() && GetWindowRect().Contains(point.x, point.y); |
| 687 | } |
| 688 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 689 | FX_BOOL CPWL_Wnd::ClientHitTest(const CFX_FloatPoint& point) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 690 | return IsValid() && IsVisible() && GetClientRect().Contains(point.x, point.y); |
| 691 | } |
| 692 | |
| 693 | const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const { |
| 694 | if (m_sPrivateParam.pParentWnd) |
| 695 | return m_sPrivateParam.pParentWnd->GetRootWnd(); |
| 696 | |
| 697 | return this; |
| 698 | } |
| 699 | |
| 700 | void CPWL_Wnd::SetVisible(FX_BOOL bVisible) { |
| 701 | if (IsValid()) { |
| 702 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 703 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 704 | pChild->SetVisible(bVisible); |
| 705 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 706 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 707 | |
| 708 | if (bVisible != m_bVisible) { |
| 709 | m_bVisible = bVisible; |
| 710 | RePosChildWnd(); |
| 711 | InvalidateRect(); |
| 712 | } |
| 713 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 716 | void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 717 | m_rcClip = rect; |
| 718 | m_rcClip.Normalize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 721 | const CFX_FloatRect& CPWL_Wnd::GetClipRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 722 | return m_rcClip; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 725 | FX_BOOL CPWL_Wnd::IsReadOnly() const { |
| 726 | return HasFlag(PWS_READONLY); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 729 | void CPWL_Wnd::RePosChildWnd() { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 730 | CFX_FloatRect rcContent = CPWL_Utils::DeflateRect( |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 731 | GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth())); |
| 732 | |
| 733 | CPWL_ScrollBar* pVSB = GetVScrollBar(); |
| 734 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 735 | CFX_FloatRect rcVScroll = |
| 736 | CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom, |
| 737 | rcContent.right - 1.0f, rcContent.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 738 | |
| 739 | if (pVSB) |
| 740 | pVSB->Move(rcVScroll, TRUE, FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 743 | void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {} |
| 744 | |
| 745 | void CPWL_Wnd::SetCursor() { |
| 746 | if (IsValid()) { |
| 747 | if (IFX_SystemHandler* pSH = GetSystemHandler()) { |
| 748 | int32_t nCursorType = GetCreationParam().eCursorType; |
| 749 | pSH->SetCursor(nCursorType); |
| 750 | } |
| 751 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 754 | void CPWL_Wnd::CreateMsgControl() { |
| 755 | if (!m_sPrivateParam.pMsgControl) |
| 756 | m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 759 | void CPWL_Wnd::DestroyMsgControl() { |
| 760 | if (CPWL_MsgControl* pMsgControl = GetMsgControl()) |
| 761 | if (pMsgControl->IsWndCreated(this)) |
| 762 | delete pMsgControl; |
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 | CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const { |
| 766 | return m_sPrivateParam.pMsgControl; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 769 | FX_BOOL CPWL_Wnd::IsCaptureMouse() const { |
| 770 | return IsWndCaptureMouse(this); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 773 | FX_BOOL CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { |
| 774 | if (CPWL_MsgControl* pCtrl = GetMsgControl()) |
| 775 | return pCtrl->IsWndCaptureMouse(pWnd); |
| 776 | |
| 777 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 780 | FX_BOOL CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { |
| 781 | if (CPWL_MsgControl* pCtrl = GetMsgControl()) |
| 782 | return pCtrl->IsWndCaptureKeyboard(pWnd); |
| 783 | |
| 784 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 787 | FX_BOOL CPWL_Wnd::IsFocused() const { |
| 788 | if (CPWL_MsgControl* pCtrl = GetMsgControl()) |
| 789 | return pCtrl->IsMainCaptureKeyboard(this); |
| 790 | |
| 791 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 794 | CFX_FloatRect CPWL_Wnd::GetFocusRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 795 | return CPWL_Utils::InflateRect(GetWindowRect(), 1); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 798 | FX_FLOAT CPWL_Wnd::GetFontSize() const { |
| 799 | return m_sPrivateParam.fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 802 | void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize) { |
| 803 | m_sPrivateParam.fFontSize = fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 806 | IFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const { |
| 807 | return m_sPrivateParam.pSystemHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 810 | IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const { |
| 811 | return m_sPrivateParam.pFocusHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 814 | IPWL_Provider* CPWL_Wnd::GetProvider() const { |
| 815 | return m_sPrivateParam.pProvider; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 818 | IFX_Edit_FontMap* CPWL_Wnd::GetFontMap() const { |
| 819 | return m_sPrivateParam.pFontMap; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 822 | CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(int32_t nBorderStyle) const { |
| 823 | CPWL_Color color; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 824 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 825 | switch (nBorderStyle) { |
| 826 | case PBS_SOLID: |
| 827 | break; |
| 828 | case PBS_DASH: |
| 829 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 830 | case PBS_BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 831 | color = CPWL_Color(COLORTYPE_GRAY, 1); |
| 832 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 833 | case PBS_INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 834 | color = CPWL_Color(COLORTYPE_GRAY, 0.5f); |
| 835 | break; |
| 836 | case PBS_UNDERLINED: |
| 837 | break; |
| 838 | } |
| 839 | |
| 840 | return color; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 843 | CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(int32_t nBorderStyle) const { |
| 844 | CPWL_Color color; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 845 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 846 | switch (nBorderStyle) { |
| 847 | case PBS_SOLID: |
| 848 | break; |
| 849 | case PBS_DASH: |
| 850 | break; |
| 851 | case PBS_BEVELED: |
| 852 | color = CPWL_Utils::DevideColor(GetBackgroundColor(), 2); |
| 853 | break; |
| 854 | case PBS_INSET: |
| 855 | color = CPWL_Color(COLORTYPE_GRAY, 0.75f); |
| 856 | break; |
| 857 | case PBS_UNDERLINED: |
| 858 | break; |
| 859 | } |
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 | return color; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 864 | int32_t CPWL_Wnd::GetTransparency() { |
| 865 | return m_sPrivateParam.nTransparency; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 868 | void CPWL_Wnd::SetTransparency(int32_t nTransparency) { |
| 869 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 870 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 871 | pChild->SetTransparency(nTransparency); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 872 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 873 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 874 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 875 | m_sPrivateParam.nTransparency = nTransparency; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 878 | CFX_Matrix CPWL_Wnd::GetWindowMatrix() const { |
| 879 | CFX_Matrix mt = GetChildToRoot(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 880 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 881 | if (IPWL_Provider* pProvider = GetProvider()) { |
| 882 | mt.Concat(pProvider->GetWindowMatrix(GetAttachedData())); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 883 | return mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | return mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 889 | void CPWL_Wnd::PWLtoWnd(const CFX_FloatPoint& point, |
| 890 | int32_t& x, |
| 891 | int32_t& y) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 892 | CFX_Matrix mt = GetWindowMatrix(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 893 | CFX_FloatPoint pt = point; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 894 | mt.Transform(pt.x, pt.y); |
| 895 | x = (int32_t)(pt.x + 0.5); |
| 896 | y = (int32_t)(pt.y + 0.5); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 899 | FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const { |
| 900 | CFX_FloatRect rcTemp = rect; |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 901 | CFX_Matrix mt = GetWindowMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 902 | mt.TransformRect(rcTemp); |
| 903 | return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5), |
| 904 | (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 907 | FX_HWND CPWL_Wnd::GetAttachedHWnd() const { |
| 908 | return m_sPrivateParam.hAttachedWnd; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 911 | CFX_FloatPoint CPWL_Wnd::ChildToParent(const CFX_FloatPoint& point) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 912 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 913 | if (mt.IsIdentity()) |
| 914 | return point; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 915 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 916 | CFX_FloatPoint pt = point; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 917 | mt.Transform(pt.x, pt.y); |
| 918 | return pt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 921 | CFX_FloatRect CPWL_Wnd::ChildToParent(const CFX_FloatRect& rect) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 922 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 923 | if (mt.IsIdentity()) |
| 924 | return rect; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 925 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 926 | CFX_FloatRect rc = rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 927 | mt.TransformRect(rc); |
| 928 | return rc; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 931 | CFX_FloatPoint CPWL_Wnd::ParentToChild(const CFX_FloatPoint& point) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 932 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 933 | if (mt.IsIdentity()) |
| 934 | return point; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 935 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 936 | mt.SetReverse(mt); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 937 | CFX_FloatPoint pt = point; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 938 | mt.Transform(pt.x, pt.y); |
| 939 | return pt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 940 | } |
| 941 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 942 | CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 943 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 944 | if (mt.IsIdentity()) |
| 945 | return rect; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 946 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 947 | mt.SetReverse(mt); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 948 | CFX_FloatRect rc = rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 949 | mt.TransformRect(rc); |
| 950 | return rc; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 953 | CFX_Matrix CPWL_Wnd::GetChildToRoot() const { |
| 954 | CFX_Matrix mt(1, 0, 0, 1, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 955 | if (HasFlag(PWS_CHILD)) { |
| 956 | const CPWL_Wnd* pParent = this; |
| 957 | while (pParent) { |
| 958 | mt.Concat(pParent->GetChildMatrix()); |
| 959 | pParent = pParent->GetParentWindow(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 960 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 961 | } |
| 962 | return mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 965 | CFX_Matrix CPWL_Wnd::GetChildMatrix() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 966 | if (HasFlag(PWS_CHILD)) |
| 967 | return m_sPrivateParam.mtChild; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 968 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 969 | return CFX_Matrix(1, 0, 0, 1, 0, 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 972 | void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 973 | m_sPrivateParam.mtChild = mt; |
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 | const CPWL_Wnd* CPWL_Wnd::GetFocused() const { |
| 977 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 978 | return pMsgCtrl->m_pMainKeyboardWnd; |
| 979 | } |
| 980 | |
| 981 | return NULL; |
| 982 | } |
| 983 | |
| 984 | void CPWL_Wnd::EnableWindow(FX_BOOL bEnable) { |
| 985 | if (m_bEnabled != bEnable) { |
| 986 | for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
| 987 | if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
| 988 | pChild->EnableWindow(bEnable); |
| 989 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 990 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 991 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 992 | m_bEnabled = bEnable; |
| 993 | |
| 994 | if (bEnable) |
| 995 | OnEnabled(); |
| 996 | else |
| 997 | OnDisabled(); |
| 998 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1001 | FX_BOOL CPWL_Wnd::IsEnabled() { |
| 1002 | return m_bEnabled; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1005 | void CPWL_Wnd::OnEnabled() {} |
| 1006 | |
| 1007 | void CPWL_Wnd::OnDisabled() {} |
| 1008 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1009 | FX_BOOL CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1010 | if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) { |
| 1011 | return pSystemHandler->IsCTRLKeyDown(nFlag); |
| 1012 | } |
| 1013 | |
| 1014 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1017 | FX_BOOL CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1018 | if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) { |
| 1019 | return pSystemHandler->IsSHIFTKeyDown(nFlag); |
| 1020 | } |
| 1021 | |
| 1022 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1025 | FX_BOOL CPWL_Wnd::IsALTpressed(uint32_t nFlag) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1026 | if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) { |
| 1027 | return pSystemHandler->IsALTKeyDown(nFlag); |
| 1028 | } |
| 1029 | |
| 1030 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1033 | FX_BOOL CPWL_Wnd::IsINSERTpressed(uint32_t nFlag) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1034 | if (IFX_SystemHandler* pSystemHandler = GetSystemHandler()) { |
| 1035 | return pSystemHandler->IsINSERTKeyDown(nFlag); |
| 1036 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1037 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1038 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1039 | } |