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) { |
| 250 | if (m_sPrivateParam.pProvider == provider) |
| 251 | m_sPrivateParam.pProvider = nullptr; |
| 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(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 271 | FXSYS_memset(&m_sPrivateParam, 0, sizeof(PWL_CREATEPARAM)); |
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()) { |
dsinclair | 8faac62 | 2016-09-15 12:41:50 -0700 | [diff] [blame] | 402 | if (CPDFSDK_Widget* widget = m_sPrivateParam.pAttachedWidget) |
| 403 | pSH->InvalidateRect(widget, rcWin); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 404 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 405 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 406 | } |
| 407 | |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 408 | #define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \ |
| 409 | bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \ |
| 410 | if (!IsValid() || !IsVisible() || !IsEnabled()) \ |
| 411 | return false; \ |
| 412 | if (!IsWndCaptureKeyboard(this)) \ |
| 413 | return false; \ |
| 414 | for (const auto& pChild : m_Children) { \ |
| 415 | if (pChild && IsWndCaptureKeyboard(pChild)) \ |
| 416 | return pChild->key_method_name(nChar, nFlag); \ |
| 417 | } \ |
| 418 | return false; \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 419 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 420 | |
| 421 | PWL_IMPLEMENT_KEY_METHOD(OnKeyDown) |
| 422 | PWL_IMPLEMENT_KEY_METHOD(OnKeyUp) |
| 423 | PWL_IMPLEMENT_KEY_METHOD(OnChar) |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 424 | #undef PWL_IMPLEMENT_KEY_METHOD |
| 425 | |
| 426 | #define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \ |
| 427 | bool CPWL_Wnd::mouse_method_name(const CFX_FloatPoint& point, \ |
| 428 | uint32_t nFlag) { \ |
| 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, |
| 463 | const CFX_FloatPoint& point, |
| 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 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 535 | CFX_FloatPoint CPWL_Wnd::GetCenterPoint() const { |
| 536 | CFX_FloatRect rcClient = GetClientRect(); |
| 537 | return CFX_FloatPoint((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 | |
| 561 | void CPWL_Wnd::SetTextColor(const CPWL_Color& color) { |
| 562 | m_sPrivateParam.sTextColor = color; |
| 563 | } |
| 564 | |
| 565 | void CPWL_Wnd::SetTextStrokeColor(const CPWL_Color& color) { |
| 566 | m_sPrivateParam.sTextStrokeColor = color; |
| 567 | } |
| 568 | |
| 569 | CPWL_Color CPWL_Wnd::GetTextColor() const { |
| 570 | return m_sPrivateParam.sTextColor; |
| 571 | } |
| 572 | |
| 573 | CPWL_Color CPWL_Wnd::GetTextStrokeColor() const { |
| 574 | return m_sPrivateParam.sTextStrokeColor; |
| 575 | } |
| 576 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 577 | BorderStyle CPWL_Wnd::GetBorderStyle() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 578 | return m_sPrivateParam.nBorderStyle; |
| 579 | } |
| 580 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 581 | void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 582 | if (HasFlag(PWS_BORDER)) |
| 583 | m_sPrivateParam.nBorderStyle = nBorderStyle; |
| 584 | } |
| 585 | |
| 586 | int32_t CPWL_Wnd::GetBorderWidth() const { |
| 587 | if (HasFlag(PWS_BORDER)) |
| 588 | return m_sPrivateParam.dwBorderWidth; |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | int32_t CPWL_Wnd::GetInnerBorderWidth() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 594 | return 0; |
| 595 | } |
| 596 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 597 | CPWL_Color CPWL_Wnd::GetBorderColor() const { |
| 598 | if (HasFlag(PWS_BORDER)) |
| 599 | return m_sPrivateParam.sBorderColor; |
| 600 | |
| 601 | return CPWL_Color(); |
| 602 | } |
| 603 | |
Lei Zhang | 7457e38 | 2016-01-06 23:00:34 -0800 | [diff] [blame] | 604 | const CPWL_Dash& CPWL_Wnd::GetBorderDash() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 605 | return m_sPrivateParam.sDash; |
| 606 | } |
| 607 | |
| 608 | void* CPWL_Wnd::GetAttachedData() const { |
| 609 | return m_sPrivateParam.pAttachedData; |
| 610 | } |
| 611 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 612 | CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const { |
| 613 | if (HasFlag(PWS_VSCROLL)) |
| 614 | return m_pVScrollBar; |
| 615 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 616 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) { |
| 620 | CreateVScrollBar(cp); |
| 621 | } |
| 622 | |
| 623 | void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) { |
| 624 | if (!m_pVScrollBar && HasFlag(PWS_VSCROLL)) { |
| 625 | PWL_CREATEPARAM scp = cp; |
| 626 | |
| 627 | // flags |
| 628 | scp.dwFlags = |
| 629 | PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP; |
| 630 | |
| 631 | scp.pParentWnd = this; |
| 632 | scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; |
| 633 | scp.eCursorType = FXCT_ARROW; |
| 634 | scp.nTransparency = PWL_SCROLLBAR_TRANSPARANCY; |
| 635 | |
Lei Zhang | e00660b | 2015-08-13 15:40:18 -0700 | [diff] [blame] | 636 | m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL); |
| 637 | m_pVScrollBar->Create(scp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
| 641 | void CPWL_Wnd::SetCapture() { |
| 642 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) |
| 643 | pMsgCtrl->SetCapture(this); |
| 644 | } |
| 645 | |
| 646 | void CPWL_Wnd::ReleaseCapture() { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 647 | for (const auto& pChild : m_Children) { |
| 648 | if (pChild) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 649 | pChild->ReleaseCapture(); |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 650 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 651 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) |
| 652 | pMsgCtrl->ReleaseCapture(); |
| 653 | } |
| 654 | |
| 655 | void CPWL_Wnd::SetFocus() { |
| 656 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 657 | if (!pMsgCtrl->IsMainCaptureKeyboard(this)) |
| 658 | pMsgCtrl->KillFocus(); |
| 659 | pMsgCtrl->SetFocus(this); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | void CPWL_Wnd::KillFocus() { |
| 664 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 665 | if (pMsgCtrl->IsWndCaptureKeyboard(this)) |
| 666 | pMsgCtrl->KillFocus(); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | void CPWL_Wnd::OnSetFocus() {} |
| 671 | |
| 672 | void CPWL_Wnd::OnKillFocus() {} |
| 673 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 674 | bool CPWL_Wnd::WndHitTest(const CFX_FloatPoint& point) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 675 | return IsValid() && IsVisible() && GetWindowRect().Contains(point.x, point.y); |
| 676 | } |
| 677 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 678 | bool CPWL_Wnd::ClientHitTest(const CFX_FloatPoint& point) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 679 | return IsValid() && IsVisible() && GetClientRect().Contains(point.x, point.y); |
| 680 | } |
| 681 | |
| 682 | const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const { |
| 683 | if (m_sPrivateParam.pParentWnd) |
| 684 | return m_sPrivateParam.pParentWnd->GetRootWnd(); |
| 685 | |
| 686 | return this; |
| 687 | } |
| 688 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 689 | void CPWL_Wnd::SetVisible(bool bVisible) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 690 | if (!IsValid()) |
| 691 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 692 | |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 693 | for (const auto& pChild : m_Children) { |
| 694 | if (pChild) |
| 695 | pChild->SetVisible(bVisible); |
| 696 | } |
| 697 | if (bVisible != m_bVisible) { |
| 698 | m_bVisible = bVisible; |
| 699 | RePosChildWnd(); |
| 700 | InvalidateRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 701 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 704 | void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 705 | m_rcClip = rect; |
| 706 | m_rcClip.Normalize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 709 | const CFX_FloatRect& CPWL_Wnd::GetClipRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 710 | return m_rcClip; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 711 | } |
| 712 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 713 | bool CPWL_Wnd::IsReadOnly() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 714 | return HasFlag(PWS_READONLY); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 717 | void CPWL_Wnd::RePosChildWnd() { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 718 | CFX_FloatRect rcContent = CPWL_Utils::DeflateRect( |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 719 | GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth())); |
| 720 | |
| 721 | CPWL_ScrollBar* pVSB = GetVScrollBar(); |
| 722 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 723 | CFX_FloatRect rcVScroll = |
| 724 | CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom, |
| 725 | rcContent.right - 1.0f, rcContent.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 726 | |
| 727 | if (pVSB) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 728 | pVSB->Move(rcVScroll, true, false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 731 | void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {} |
| 732 | |
| 733 | void CPWL_Wnd::SetCursor() { |
| 734 | if (IsValid()) { |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 735 | if (CFX_SystemHandler* pSH = GetSystemHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 736 | int32_t nCursorType = GetCreationParam().eCursorType; |
| 737 | pSH->SetCursor(nCursorType); |
| 738 | } |
| 739 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 742 | void CPWL_Wnd::CreateMsgControl() { |
| 743 | if (!m_sPrivateParam.pMsgControl) |
| 744 | m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 747 | void CPWL_Wnd::DestroyMsgControl() { |
| 748 | if (CPWL_MsgControl* pMsgControl = GetMsgControl()) |
| 749 | if (pMsgControl->IsWndCreated(this)) |
| 750 | delete pMsgControl; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 753 | CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const { |
| 754 | return m_sPrivateParam.pMsgControl; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 755 | } |
| 756 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 757 | bool CPWL_Wnd::IsCaptureMouse() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 758 | return IsWndCaptureMouse(this); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 759 | } |
| 760 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 761 | bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 762 | if (CPWL_MsgControl* pCtrl = GetMsgControl()) |
| 763 | return pCtrl->IsWndCaptureMouse(pWnd); |
| 764 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 765 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 766 | } |
| 767 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 768 | bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 769 | if (CPWL_MsgControl* pCtrl = GetMsgControl()) |
| 770 | return pCtrl->IsWndCaptureKeyboard(pWnd); |
| 771 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 772 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 773 | } |
| 774 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 775 | bool CPWL_Wnd::IsFocused() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 776 | if (CPWL_MsgControl* pCtrl = GetMsgControl()) |
| 777 | return pCtrl->IsMainCaptureKeyboard(this); |
| 778 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 779 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 782 | CFX_FloatRect CPWL_Wnd::GetFocusRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 783 | return CPWL_Utils::InflateRect(GetWindowRect(), 1); |
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 | FX_FLOAT CPWL_Wnd::GetFontSize() const { |
| 787 | return m_sPrivateParam.fFontSize; |
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 | void CPWL_Wnd::SetFontSize(FX_FLOAT fFontSize) { |
| 791 | m_sPrivateParam.fFontSize = fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 792 | } |
| 793 | |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 794 | CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 795 | return m_sPrivateParam.pSystemHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 798 | IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const { |
| 799 | return m_sPrivateParam.pFocusHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 802 | IPWL_Provider* CPWL_Wnd::GetProvider() const { |
| 803 | return m_sPrivateParam.pProvider; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 804 | } |
| 805 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 806 | IPVT_FontMap* CPWL_Wnd::GetFontMap() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 807 | return m_sPrivateParam.pFontMap; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 808 | } |
| 809 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 810 | CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 811 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 812 | case BorderStyle::BEVELED: |
| 813 | return CPWL_Color(COLORTYPE_GRAY, 1); |
| 814 | case BorderStyle::INSET: |
| 815 | return CPWL_Color(COLORTYPE_GRAY, 0.5f); |
| 816 | default: |
| 817 | return CPWL_Color(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 818 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 819 | } |
| 820 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 821 | CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 822 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 823 | case BorderStyle::BEVELED: |
| 824 | return CPWL_Utils::DevideColor(GetBackgroundColor(), 2); |
| 825 | case BorderStyle::INSET: |
| 826 | return CPWL_Color(COLORTYPE_GRAY, 0.75f); |
| 827 | default: |
| 828 | return CPWL_Color(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 829 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 832 | int32_t CPWL_Wnd::GetTransparency() { |
| 833 | return m_sPrivateParam.nTransparency; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 834 | } |
| 835 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 836 | void CPWL_Wnd::SetTransparency(int32_t nTransparency) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 837 | for (const auto& pChild : m_Children) { |
| 838 | if (pChild) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 839 | pChild->SetTransparency(nTransparency); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 840 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 841 | m_sPrivateParam.nTransparency = nTransparency; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 844 | CFX_Matrix CPWL_Wnd::GetWindowMatrix() const { |
| 845 | CFX_Matrix mt = GetChildToRoot(); |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 846 | if (IPWL_Provider* pProvider = GetProvider()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 847 | mt.Concat(pProvider->GetWindowMatrix(GetAttachedData())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 848 | |
| 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 | void CPWL_Wnd::PWLtoWnd(const CFX_FloatPoint& point, |
| 853 | int32_t& x, |
| 854 | int32_t& y) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 855 | CFX_Matrix mt = GetWindowMatrix(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 856 | CFX_FloatPoint pt = point; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 857 | mt.Transform(pt.x, pt.y); |
| 858 | x = (int32_t)(pt.x + 0.5); |
| 859 | y = (int32_t)(pt.y + 0.5); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 860 | } |
| 861 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 862 | FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const { |
| 863 | CFX_FloatRect rcTemp = rect; |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 864 | CFX_Matrix mt = GetWindowMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 865 | mt.TransformRect(rcTemp); |
| 866 | return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5), |
| 867 | (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] | 868 | } |
| 869 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 870 | CFX_FloatPoint CPWL_Wnd::ChildToParent(const CFX_FloatPoint& point) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 871 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 872 | if (mt.IsIdentity()) |
| 873 | return point; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 874 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 875 | CFX_FloatPoint pt = point; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 876 | mt.Transform(pt.x, pt.y); |
| 877 | return pt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 880 | CFX_FloatRect CPWL_Wnd::ChildToParent(const CFX_FloatRect& rect) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 881 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 882 | if (mt.IsIdentity()) |
| 883 | return rect; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 884 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 885 | CFX_FloatRect rc = rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 886 | mt.TransformRect(rc); |
| 887 | return rc; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 890 | CFX_FloatPoint CPWL_Wnd::ParentToChild(const CFX_FloatPoint& point) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 891 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 892 | if (mt.IsIdentity()) |
| 893 | return point; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 894 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 895 | mt.SetReverse(mt); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 896 | CFX_FloatPoint pt = point; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 897 | mt.Transform(pt.x, pt.y); |
| 898 | return pt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 901 | CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 902 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 903 | if (mt.IsIdentity()) |
| 904 | return rect; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 905 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 906 | mt.SetReverse(mt); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 907 | CFX_FloatRect rc = rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 908 | mt.TransformRect(rc); |
| 909 | return rc; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 910 | } |
| 911 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 912 | FX_FLOAT CPWL_Wnd::GetItemHeight(FX_FLOAT fLimitWidth) { |
| 913 | return 0; |
| 914 | } |
| 915 | |
| 916 | FX_FLOAT CPWL_Wnd::GetItemLeftMargin() { |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | FX_FLOAT CPWL_Wnd::GetItemRightMargin() { |
| 921 | return 0; |
| 922 | } |
| 923 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 924 | CFX_Matrix CPWL_Wnd::GetChildToRoot() const { |
| 925 | CFX_Matrix mt(1, 0, 0, 1, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 926 | if (HasFlag(PWS_CHILD)) { |
| 927 | const CPWL_Wnd* pParent = this; |
| 928 | while (pParent) { |
| 929 | mt.Concat(pParent->GetChildMatrix()); |
| 930 | pParent = pParent->GetParentWindow(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 931 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 932 | } |
| 933 | return mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 936 | CFX_Matrix CPWL_Wnd::GetChildMatrix() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 937 | if (HasFlag(PWS_CHILD)) |
| 938 | return m_sPrivateParam.mtChild; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 939 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 940 | return CFX_Matrix(1, 0, 0, 1, 0, 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 943 | void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 944 | m_sPrivateParam.mtChild = mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 947 | const CPWL_Wnd* CPWL_Wnd::GetFocused() const { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 948 | CPWL_MsgControl* pMsgCtrl = GetMsgControl(); |
| 949 | return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 950 | } |
| 951 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 952 | void CPWL_Wnd::EnableWindow(bool bEnable) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 953 | if (m_bEnabled == bEnable) |
| 954 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 955 | |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 956 | for (const auto& pChild : m_Children) { |
| 957 | if (pChild) |
| 958 | pChild->EnableWindow(bEnable); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 959 | } |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 960 | m_bEnabled = bEnable; |
| 961 | if (bEnable) |
| 962 | OnEnabled(); |
| 963 | else |
| 964 | OnDisabled(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 965 | } |
| 966 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 967 | bool CPWL_Wnd::IsEnabled() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 968 | return m_bEnabled; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 971 | void CPWL_Wnd::OnEnabled() {} |
| 972 | |
| 973 | void CPWL_Wnd::OnDisabled() {} |
| 974 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 975 | bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const { |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 976 | if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 977 | return pSystemHandler->IsCTRLKeyDown(nFlag); |
| 978 | } |
| 979 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 980 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 981 | } |
| 982 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 983 | bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const { |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 984 | if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 985 | return pSystemHandler->IsSHIFTKeyDown(nFlag); |
| 986 | } |
| 987 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 988 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 989 | } |
| 990 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 991 | bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const { |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 992 | if (CFX_SystemHandler* pSystemHandler = GetSystemHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 993 | return pSystemHandler->IsALTKeyDown(nFlag); |
| 994 | } |
| 995 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 996 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 997 | } |