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