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