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