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