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