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