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 | |
Dan Sinclair | c411eb9 | 2017-07-25 09:39:30 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/pwl/cpwl_wnd.h" |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 8 | |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 9 | #include <map> |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 10 | #include <sstream> |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 11 | #include <vector> |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 12 | |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 13 | #include "core/fxge/cfx_renderdevice.h" |
Dan Sinclair | c411eb9 | 2017-07-25 09:39:30 -0400 | [diff] [blame] | 14 | #include "fpdfsdk/pwl/cpwl_scroll_bar.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 15 | #include "third_party/base/ptr_util.h" |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 16 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 18 | namespace { |
| 19 | |
| 20 | constexpr float kDefaultFontSize = 9.0f; |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 21 | |
| 22 | } // namespace |
| 23 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 24 | PWL_CREATEPARAM::PWL_CREATEPARAM() |
| 25 | : rcRectWnd(0, 0, 0, 0), |
| 26 | pSystemHandler(nullptr), |
| 27 | pFontMap(nullptr), |
| 28 | pProvider(nullptr), |
| 29 | pFocusHandler(nullptr), |
| 30 | dwFlags(0), |
| 31 | sBackgroundColor(), |
dsinclair | 8faac62 | 2016-09-15 12:41:50 -0700 | [diff] [blame] | 32 | pAttachedWidget(nullptr), |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 33 | nBorderStyle(BorderStyle::SOLID), |
| 34 | dwBorderWidth(1), |
| 35 | sBorderColor(), |
| 36 | sTextColor(), |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 37 | nTransparency(255), |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 38 | fFontSize(kDefaultFontSize), |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 39 | sDash(3, 0, 0), |
| 40 | pAttachedData(nullptr), |
| 41 | pParentWnd(nullptr), |
| 42 | pMsgControl(nullptr), |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 43 | eCursorType(FXCT_ARROW) {} |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 44 | |
| 45 | PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default; |
| 46 | |
Ryan Harrison | 022d13b | 2017-09-15 14:35:41 -0400 | [diff] [blame^] | 47 | class CPWL_MsgControl : public CFX_Observable<CPWL_MsgControl> { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | friend class CPWL_Wnd; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 49 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | public: |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 51 | explicit CPWL_MsgControl(CPWL_Wnd* pWnd) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | m_pCreatedWnd = pWnd; |
| 53 | Default(); |
| 54 | } |
| 55 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 56 | ~CPWL_MsgControl() { Default(); } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | |
| 58 | void Default() { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 59 | m_aMousePath.clear(); |
| 60 | m_aKeyboardPath.clear(); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 61 | m_pMainMouseWnd = nullptr; |
| 62 | m_pMainKeyboardWnd = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | } |
| 64 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 65 | bool IsWndCreated(const CPWL_Wnd* pWnd) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 66 | return m_pCreatedWnd == pWnd; |
| 67 | } |
| 68 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 69 | bool IsMainCaptureMouse(const CPWL_Wnd* pWnd) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | return pWnd == m_pMainMouseWnd; |
| 71 | } |
| 72 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 73 | bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 74 | return pWnd && pdfium::ContainsValue(m_aMousePath, pWnd); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | } |
| 76 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 77 | bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 78 | return pWnd == m_pMainKeyboardWnd; |
| 79 | } |
| 80 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 81 | bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 82 | return pWnd && pdfium::ContainsValue(m_aKeyboardPath, pWnd); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void SetFocus(CPWL_Wnd* pWnd) { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 86 | m_aKeyboardPath.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | if (pWnd) { |
| 88 | m_pMainKeyboardWnd = pWnd; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | CPWL_Wnd* pParent = pWnd; |
| 90 | while (pParent) { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 91 | m_aKeyboardPath.push_back(pParent); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | pParent = pParent->GetParentWindow(); |
| 93 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | pWnd->OnSetFocus(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 95 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 97 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | void KillFocus() { |
Ryan Harrison | 022d13b | 2017-09-15 14:35:41 -0400 | [diff] [blame^] | 99 | ObservedPtr observed_ptr = ObservedPtr(this); |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 100 | if (!m_aKeyboardPath.empty()) |
| 101 | if (CPWL_Wnd* pWnd = m_aKeyboardPath[0]) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 102 | pWnd->OnKillFocus(); |
Ryan Harrison | 022d13b | 2017-09-15 14:35:41 -0400 | [diff] [blame^] | 103 | if (!observed_ptr) |
| 104 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 105 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 106 | m_pMainKeyboardWnd = nullptr; |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 107 | m_aKeyboardPath.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void SetCapture(CPWL_Wnd* pWnd) { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 111 | m_aMousePath.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 112 | if (pWnd) { |
| 113 | m_pMainMouseWnd = pWnd; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 114 | CPWL_Wnd* pParent = pWnd; |
| 115 | while (pParent) { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 116 | m_aMousePath.push_back(pParent); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 117 | pParent = pParent->GetParentWindow(); |
| 118 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 119 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 120 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 121 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 122 | void ReleaseCapture() { |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 123 | m_pMainMouseWnd = nullptr; |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 124 | m_aMousePath.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 125 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 126 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 127 | private: |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 128 | std::vector<CPWL_Wnd*> m_aMousePath; |
| 129 | std::vector<CPWL_Wnd*> m_aKeyboardPath; |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 130 | CFX_UnownedPtr<CPWL_Wnd> m_pCreatedWnd; |
| 131 | CFX_UnownedPtr<CPWL_Wnd> m_pMainMouseWnd; |
| 132 | CFX_UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | CPWL_Wnd::CPWL_Wnd() |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 136 | : m_rcWindow(), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 137 | m_rcClip(), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 138 | m_bCreated(false), |
| 139 | m_bVisible(false), |
| 140 | m_bNotifying(false), |
| 141 | m_bEnabled(true) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 142 | |
| 143 | CPWL_Wnd::~CPWL_Wnd() { |
Lei Zhang | b45324b | 2017-05-22 17:05:40 -0700 | [diff] [blame] | 144 | ASSERT(!m_bCreated); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 147 | CFX_ByteString CPWL_Wnd::GetClassName() const { |
| 148 | return "CPWL_Wnd"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 152 | if (IsValid()) |
| 153 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 154 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 155 | m_sPrivateParam = cp; |
| 156 | OnCreate(m_sPrivateParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 157 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 158 | m_sPrivateParam.rcRectWnd.Normalize(); |
| 159 | m_rcWindow = m_sPrivateParam.rcRectWnd; |
dan sinclair | adf922f | 2017-07-12 21:56:27 -0400 | [diff] [blame] | 160 | m_rcClip = m_rcWindow; |
| 161 | if (!m_rcClip.IsEmpty()) { |
| 162 | m_rcClip.Inflate(1.0f, 1.0f); |
| 163 | m_rcClip.Normalize(); |
| 164 | } |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 165 | CreateMsgControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 166 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 167 | if (m_sPrivateParam.pParentWnd) |
Dan Sinclair | e5e889e | 2017-07-05 08:45:40 -0400 | [diff] [blame] | 168 | m_sPrivateParam.pParentWnd->AddChild(this); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 170 | PWL_CREATEPARAM ccp = m_sPrivateParam; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 172 | ccp.dwFlags &= 0xFFFF0000L; // remove sub styles |
| 173 | CreateScrollBar(ccp); |
| 174 | CreateChildWnd(ccp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 176 | m_bVisible = HasFlag(PWS_VISIBLE); |
| 177 | OnCreated(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 179 | RePosChildWnd(); |
| 180 | m_bCreated = true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 184 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | void CPWL_Wnd::OnCreated() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 186 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 187 | void CPWL_Wnd::OnDestroy() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 188 | |
Lei Zhang | ab5537d | 2016-01-06 14:58:14 -0800 | [diff] [blame] | 189 | void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) { |
| 190 | if (m_sPrivateParam.pFocusHandler == handler) |
| 191 | m_sPrivateParam.pFocusHandler = nullptr; |
| 192 | } |
| 193 | |
| 194 | void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) { |
Dan Sinclair | bc8dcc3 | 2017-01-19 13:53:02 -0500 | [diff] [blame] | 195 | if (m_sPrivateParam.pProvider.Get() == provider) |
| 196 | m_sPrivateParam.pProvider.Reset(); |
Lei Zhang | ab5537d | 2016-01-06 14:58:14 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 199 | void CPWL_Wnd::Destroy() { |
| 200 | KillFocus(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 201 | OnDestroy(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 202 | if (m_bCreated) { |
Lei Zhang | 3516256 | 2017-06-09 01:04:52 -0700 | [diff] [blame] | 203 | m_pVScrollBar = nullptr; |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 204 | for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) { |
| 205 | if (CPWL_Wnd* pChild = *it) { |
| 206 | *it = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 207 | pChild->Destroy(); |
| 208 | delete pChild; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 211 | if (m_sPrivateParam.pParentWnd) |
Dan Sinclair | e5e889e | 2017-07-05 08:45:40 -0400 | [diff] [blame] | 212 | m_sPrivateParam.pParentWnd->RemoveChild(this); |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 213 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 214 | m_bCreated = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 215 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | DestroyMsgControl(); |
Dan Sinclair | bc8dcc3 | 2017-01-19 13:53:02 -0500 | [diff] [blame] | 217 | m_sPrivateParam.Reset(); |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 218 | m_Children.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 219 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 220 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 221 | void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 222 | if (!IsValid()) |
| 223 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 224 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 225 | CFX_FloatRect rcOld = GetWindowRect(); |
| 226 | m_rcWindow = rcNew; |
| 227 | m_rcWindow.Normalize(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 228 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 229 | if (bReset) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 230 | if (rcOld.left != rcNew.left || rcOld.right != rcNew.right || |
| 231 | rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 232 | RePosChildWnd(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 233 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 234 | } |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 235 | if (bRefresh) |
| 236 | InvalidateRectMove(rcOld, rcNew); |
| 237 | |
| 238 | m_sPrivateParam.rcRectWnd = m_rcWindow; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 241 | void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld, |
| 242 | const CFX_FloatRect& rcNew) { |
| 243 | CFX_FloatRect rcUnion = rcOld; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | rcUnion.Union(rcNew); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 245 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 246 | InvalidateRect(&rcUnion); |
| 247 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 248 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice, |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 250 | const CFX_Matrix& mtUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 251 | if (IsValid() && IsVisible()) { |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 252 | DrawThisAppearance(pDevice, mtUser2Device); |
| 253 | DrawChildAppearance(pDevice, mtUser2Device); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
| 257 | void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 258 | const CFX_Matrix& mtUser2Device) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 259 | CFX_FloatRect rectWnd = GetWindowRect(); |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 260 | if (rectWnd.IsEmpty()) |
| 261 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 262 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 263 | if (HasFlag(PWS_BACKGROUND)) { |
dan sinclair | d6aff2f | 2017-07-13 21:36:29 -0400 | [diff] [blame] | 264 | float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 265 | pDevice->DrawFillRect(&mtUser2Device, rectWnd.GetDeflated(width, width), |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 266 | GetBackgroundColor(), GetTransparency()); |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | if (HasFlag(PWS_BORDER)) { |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 270 | pDevice->DrawBorder(&mtUser2Device, rectWnd, |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 271 | static_cast<float>(GetBorderWidth()), GetBorderColor(), |
| 272 | GetBorderLeftTopColor(GetBorderStyle()), |
| 273 | GetBorderRightBottomColor(GetBorderStyle()), |
| 274 | GetBorderStyle(), GetTransparency()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 275 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 278 | void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice, |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 279 | const CFX_Matrix& mtUser2Device) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 280 | for (CPWL_Wnd* pChild : m_Children) { |
| 281 | if (!pChild) |
| 282 | continue; |
| 283 | |
| 284 | CFX_Matrix mt = pChild->GetChildMatrix(); |
| 285 | if (mt.IsIdentity()) { |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 286 | pChild->DrawAppearance(pDevice, mtUser2Device); |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 287 | } else { |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 288 | mt.Concat(mtUser2Device); |
| 289 | pChild->DrawAppearance(pDevice, mt); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 290 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 291 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 294 | void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 295 | if (!IsValid()) |
| 296 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 297 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 298 | CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect(); |
| 299 | |
| 300 | if (!HasFlag(PWS_NOREFRESHCLIP)) { |
| 301 | CFX_FloatRect rcClip = GetClipRect(); |
| 302 | if (!rcClip.IsEmpty()) { |
| 303 | rcRefresh.Intersect(rcClip); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 304 | } |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 305 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 306 | |
Lei Zhang | 77f9bff | 2017-08-29 11:34:12 -0700 | [diff] [blame] | 307 | CFX_FloatRect rcWin = PWLtoWnd(rcRefresh); |
| 308 | rcWin.Inflate(1, 1); |
| 309 | rcWin.Normalize(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 310 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 311 | if (CFX_SystemHandler* pSH = GetSystemHandler()) { |
| 312 | if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>( |
| 313 | m_sPrivateParam.pAttachedWidget.Get())) { |
| 314 | pSH->InvalidateRect(widget, rcWin); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 315 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 316 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 317 | } |
| 318 | |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 319 | #define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \ |
| 320 | bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \ |
| 321 | if (!IsValid() || !IsVisible() || !IsEnabled()) \ |
| 322 | return false; \ |
| 323 | if (!IsWndCaptureKeyboard(this)) \ |
| 324 | return false; \ |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 325 | for (auto* pChild : m_Children) { \ |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 326 | if (pChild && IsWndCaptureKeyboard(pChild)) \ |
| 327 | return pChild->key_method_name(nChar, nFlag); \ |
| 328 | } \ |
| 329 | return false; \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 330 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 331 | |
| 332 | PWL_IMPLEMENT_KEY_METHOD(OnKeyDown) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 333 | PWL_IMPLEMENT_KEY_METHOD(OnChar) |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 334 | #undef PWL_IMPLEMENT_KEY_METHOD |
| 335 | |
| 336 | #define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \ |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 337 | bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \ |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 338 | if (!IsValid() || !IsVisible() || !IsEnabled()) \ |
| 339 | return false; \ |
| 340 | if (IsWndCaptureMouse(this)) { \ |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 341 | for (auto* pChild : m_Children) { \ |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 342 | if (pChild && IsWndCaptureMouse(pChild)) { \ |
| 343 | return pChild->mouse_method_name(pChild->ParentToChild(point), \ |
| 344 | nFlag); \ |
| 345 | } \ |
| 346 | } \ |
| 347 | SetCursor(); \ |
| 348 | return false; \ |
| 349 | } \ |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 350 | for (auto* pChild : m_Children) { \ |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 351 | if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \ |
| 352 | return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \ |
| 353 | } \ |
| 354 | } \ |
| 355 | if (WndHitTest(point)) \ |
| 356 | SetCursor(); \ |
| 357 | return false; \ |
| 358 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 359 | |
| 360 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk) |
| 361 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown) |
| 362 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 363 | PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown) |
| 364 | PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp) |
| 365 | PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove) |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 366 | #undef PWL_IMPLEMENT_MOUSE_METHOD |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 367 | |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 368 | CFX_WideString CPWL_Wnd::GetSelectedText() { |
| 369 | return CFX_WideString(); |
| 370 | } |
| 371 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 372 | void CPWL_Wnd::ReplaceSelection(const CFX_WideString& text) {} |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 373 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 374 | bool CPWL_Wnd::OnMouseWheel(short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 375 | const CFX_PointF& point, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 376 | uint32_t nFlag) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 377 | if (!IsValid() || !IsVisible() || !IsEnabled()) |
| 378 | return false; |
| 379 | |
| 380 | SetCursor(); |
| 381 | if (!IsWndCaptureKeyboard(this)) |
| 382 | return false; |
| 383 | |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 384 | for (auto* pChild : m_Children) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 385 | if (pChild && IsWndCaptureKeyboard(pChild)) |
| 386 | return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 387 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 388 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 391 | void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 392 | m_Children.push_back(pWnd); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 395 | void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 396 | for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) { |
| 397 | if (*it && *it == pWnd) { |
| 398 | m_Children.erase(std::next(it).base()); |
| 399 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 400 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 401 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Dan Sinclair | fb00ec2 | 2017-07-05 09:28:15 -0400 | [diff] [blame] | 404 | void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {} |
| 405 | |
Dan Sinclair | 7e0336e | 2017-07-05 09:39:50 -0400 | [diff] [blame] | 406 | void CPWL_Wnd::SetScrollPosition(float pos) {} |
| 407 | |
Dan Sinclair | 63fbd8d | 2017-07-05 14:10:36 -0400 | [diff] [blame] | 408 | void CPWL_Wnd::ScrollWindowVertically(float pos) {} |
| 409 | |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 410 | void CPWL_Wnd::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {} |
| 411 | |
| 412 | void CPWL_Wnd::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {} |
| 413 | |
| 414 | void CPWL_Wnd::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) {} |
| 415 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 416 | bool CPWL_Wnd::IsValid() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 417 | return m_bCreated; |
| 418 | } |
| 419 | |
Lei Zhang | 7457e38 | 2016-01-06 23:00:34 -0800 | [diff] [blame] | 420 | const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 421 | return m_sPrivateParam; |
| 422 | } |
| 423 | |
| 424 | CPWL_Wnd* CPWL_Wnd::GetParentWindow() const { |
| 425 | return m_sPrivateParam.pParentWnd; |
| 426 | } |
| 427 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 428 | CFX_FloatRect CPWL_Wnd::GetWindowRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 429 | return m_rcWindow; |
| 430 | } |
| 431 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 432 | CFX_FloatRect CPWL_Wnd::GetClientRect() const { |
| 433 | CFX_FloatRect rcWindow = GetWindowRect(); |
dan sinclair | adf922f | 2017-07-12 21:56:27 -0400 | [diff] [blame] | 434 | |
dan sinclair | d6aff2f | 2017-07-13 21:36:29 -0400 | [diff] [blame] | 435 | float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); |
| 436 | CFX_FloatRect rcClient = rcWindow.GetDeflated(width, width); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 437 | if (CPWL_ScrollBar* pVSB = GetVScrollBar()) |
| 438 | rcClient.right -= pVSB->GetScrollBarWidth(); |
| 439 | |
| 440 | rcClient.Normalize(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 441 | return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 444 | CFX_PointF CPWL_Wnd::GetCenterPoint() const { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 445 | CFX_FloatRect rcClient = GetClientRect(); |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 446 | return CFX_PointF((rcClient.left + rcClient.right) * 0.5f, |
| 447 | (rcClient.top + rcClient.bottom) * 0.5f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 448 | } |
| 449 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 450 | bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 451 | return (m_sPrivateParam.dwFlags & dwFlags) != 0; |
| 452 | } |
| 453 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 454 | void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 455 | m_sPrivateParam.dwFlags &= ~dwFlags; |
| 456 | } |
| 457 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 458 | void CPWL_Wnd::AddFlag(uint32_t dwFlags) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 459 | m_sPrivateParam.dwFlags |= dwFlags; |
| 460 | } |
| 461 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 462 | CFX_Color CPWL_Wnd::GetBackgroundColor() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | return m_sPrivateParam.sBackgroundColor; |
| 464 | } |
| 465 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 466 | void CPWL_Wnd::SetBackgroundColor(const CFX_Color& color) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 467 | m_sPrivateParam.sBackgroundColor = color; |
| 468 | } |
| 469 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 470 | CFX_Color CPWL_Wnd::GetTextColor() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 471 | return m_sPrivateParam.sTextColor; |
| 472 | } |
| 473 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 474 | BorderStyle CPWL_Wnd::GetBorderStyle() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 475 | return m_sPrivateParam.nBorderStyle; |
| 476 | } |
| 477 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 478 | void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | if (HasFlag(PWS_BORDER)) |
| 480 | m_sPrivateParam.nBorderStyle = nBorderStyle; |
| 481 | } |
| 482 | |
| 483 | int32_t CPWL_Wnd::GetBorderWidth() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 484 | return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | int32_t CPWL_Wnd::GetInnerBorderWidth() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 488 | return 0; |
| 489 | } |
| 490 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 491 | CFX_Color CPWL_Wnd::GetBorderColor() const { |
| 492 | return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CFX_Color(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Lei Zhang | 7457e38 | 2016-01-06 23:00:34 -0800 | [diff] [blame] | 495 | const CPWL_Dash& CPWL_Wnd::GetBorderDash() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 496 | return m_sPrivateParam.sDash; |
| 497 | } |
| 498 | |
| 499 | void* CPWL_Wnd::GetAttachedData() const { |
| 500 | return m_sPrivateParam.pAttachedData; |
| 501 | } |
| 502 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 503 | CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const { |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 504 | return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) { |
| 508 | CreateVScrollBar(cp); |
| 509 | } |
| 510 | |
| 511 | void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 512 | if (m_pVScrollBar || !HasFlag(PWS_VSCROLL)) |
| 513 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 514 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 515 | PWL_CREATEPARAM scp = cp; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 516 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 517 | // flags |
| 518 | scp.dwFlags = |
| 519 | PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 520 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 521 | scp.pParentWnd = this; |
| 522 | scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; |
| 523 | scp.eCursorType = FXCT_ARROW; |
| 524 | scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY; |
| 525 | |
| 526 | m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL); |
| 527 | m_pVScrollBar->Create(scp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | void CPWL_Wnd::SetCapture() { |
| 531 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) |
| 532 | pMsgCtrl->SetCapture(this); |
| 533 | } |
| 534 | |
| 535 | void CPWL_Wnd::ReleaseCapture() { |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 536 | for (auto* pChild : m_Children) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 537 | if (pChild) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 538 | pChild->ReleaseCapture(); |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 539 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 540 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) |
| 541 | pMsgCtrl->ReleaseCapture(); |
| 542 | } |
| 543 | |
| 544 | void CPWL_Wnd::SetFocus() { |
| 545 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 546 | if (!pMsgCtrl->IsMainCaptureKeyboard(this)) |
| 547 | pMsgCtrl->KillFocus(); |
| 548 | pMsgCtrl->SetFocus(this); |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | void CPWL_Wnd::KillFocus() { |
| 553 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 554 | if (pMsgCtrl->IsWndCaptureKeyboard(this)) |
| 555 | pMsgCtrl->KillFocus(); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | void CPWL_Wnd::OnSetFocus() {} |
| 560 | |
| 561 | void CPWL_Wnd::OnKillFocus() {} |
| 562 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 563 | bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 564 | return IsValid() && IsVisible() && GetWindowRect().Contains(point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 567 | bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 568 | return IsValid() && IsVisible() && GetClientRect().Contains(point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 572 | auto* pParent = m_sPrivateParam.pParentWnd; |
| 573 | return pParent ? pParent->GetRootWnd() : this; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 574 | } |
| 575 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 576 | void CPWL_Wnd::SetVisible(bool bVisible) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 577 | if (!IsValid()) |
| 578 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 579 | |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 580 | for (auto* pChild : m_Children) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 581 | if (pChild) |
| 582 | pChild->SetVisible(bVisible); |
| 583 | } |
| 584 | if (bVisible != m_bVisible) { |
| 585 | m_bVisible = bVisible; |
| 586 | RePosChildWnd(); |
Lei Zhang | 33c0300 | 2017-08-15 11:18:19 -0700 | [diff] [blame] | 587 | InvalidateRect(nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 588 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 591 | void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 592 | m_rcClip = rect; |
| 593 | m_rcClip.Normalize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 596 | const CFX_FloatRect& CPWL_Wnd::GetClipRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 597 | return m_rcClip; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 598 | } |
| 599 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 600 | bool CPWL_Wnd::IsReadOnly() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | return HasFlag(PWS_READONLY); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 604 | void CPWL_Wnd::RePosChildWnd() { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 605 | CPWL_ScrollBar* pVSB = GetVScrollBar(); |
| 606 | if (!pVSB) |
| 607 | return; |
| 608 | |
dan sinclair | adf922f | 2017-07-12 21:56:27 -0400 | [diff] [blame] | 609 | CFX_FloatRect rcContent = GetWindowRect(); |
| 610 | if (!rcContent.IsEmpty()) { |
| 611 | float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); |
| 612 | rcContent.Deflate(width, width); |
| 613 | rcContent.Normalize(); |
| 614 | } |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 615 | CFX_FloatRect rcVScroll = |
| 616 | CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom, |
| 617 | rcContent.right - 1.0f, rcContent.top); |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 618 | pVSB->Move(rcVScroll, true, false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 621 | void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {} |
| 622 | |
| 623 | void CPWL_Wnd::SetCursor() { |
| 624 | if (IsValid()) { |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 625 | if (CFX_SystemHandler* pSH = GetSystemHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | int32_t nCursorType = GetCreationParam().eCursorType; |
| 627 | pSH->SetCursor(nCursorType); |
| 628 | } |
| 629 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 632 | void CPWL_Wnd::CreateMsgControl() { |
| 633 | if (!m_sPrivateParam.pMsgControl) |
| 634 | m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 637 | void CPWL_Wnd::DestroyMsgControl() { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 638 | CPWL_MsgControl* pMsgControl = GetMsgControl(); |
| 639 | if (pMsgControl && pMsgControl->IsWndCreated(this)) |
| 640 | delete pMsgControl; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 643 | CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const { |
| 644 | return m_sPrivateParam.pMsgControl; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 645 | } |
| 646 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 647 | bool CPWL_Wnd::IsCaptureMouse() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 648 | return IsWndCaptureMouse(this); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 649 | } |
| 650 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 651 | bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 652 | CPWL_MsgControl* pCtrl = GetMsgControl(); |
| 653 | return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 654 | } |
| 655 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 656 | bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 657 | CPWL_MsgControl* pCtrl = GetMsgControl(); |
| 658 | return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 659 | } |
| 660 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 661 | bool CPWL_Wnd::IsFocused() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 662 | CPWL_MsgControl* pCtrl = GetMsgControl(); |
| 663 | return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 666 | CFX_FloatRect CPWL_Wnd::GetFocusRect() const { |
dan sinclair | adf922f | 2017-07-12 21:56:27 -0400 | [diff] [blame] | 667 | CFX_FloatRect rect = GetWindowRect(); |
| 668 | if (!rect.IsEmpty()) { |
| 669 | rect.Inflate(1.0f, 1.0f); |
| 670 | rect.Normalize(); |
| 671 | } |
| 672 | return rect; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 675 | float CPWL_Wnd::GetFontSize() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 676 | return m_sPrivateParam.fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 679 | void CPWL_Wnd::SetFontSize(float fFontSize) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 680 | m_sPrivateParam.fFontSize = fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 681 | } |
| 682 | |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 683 | CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 684 | return m_sPrivateParam.pSystemHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 687 | IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const { |
| 688 | return m_sPrivateParam.pFocusHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 691 | IPWL_Provider* CPWL_Wnd::GetProvider() const { |
Dan Sinclair | bc8dcc3 | 2017-01-19 13:53:02 -0500 | [diff] [blame] | 692 | return m_sPrivateParam.pProvider.Get(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 693 | } |
| 694 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 695 | IPVT_FontMap* CPWL_Wnd::GetFontMap() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 696 | return m_sPrivateParam.pFontMap; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 699 | CFX_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 700 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 701 | case BorderStyle::BEVELED: |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 702 | return CFX_Color(COLORTYPE_GRAY, 1); |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 703 | case BorderStyle::INSET: |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 704 | return CFX_Color(COLORTYPE_GRAY, 0.5f); |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 705 | default: |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 706 | return CFX_Color(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 707 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 710 | CFX_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 711 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 712 | case BorderStyle::BEVELED: |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 713 | return GetBackgroundColor() / 2.0f; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 714 | case BorderStyle::INSET: |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 715 | return CFX_Color(COLORTYPE_GRAY, 0.75f); |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 716 | default: |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 717 | return CFX_Color(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 718 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 721 | int32_t CPWL_Wnd::GetTransparency() { |
| 722 | return m_sPrivateParam.nTransparency; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 725 | void CPWL_Wnd::SetTransparency(int32_t nTransparency) { |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 726 | for (auto* pChild : m_Children) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 727 | if (pChild) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 728 | pChild->SetTransparency(nTransparency); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 729 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 730 | m_sPrivateParam.nTransparency = nTransparency; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 733 | CFX_Matrix CPWL_Wnd::GetWindowMatrix() const { |
| 734 | CFX_Matrix mt = GetChildToRoot(); |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 735 | if (IPWL_Provider* pProvider = GetProvider()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 736 | mt.Concat(pProvider->GetWindowMatrix(GetAttachedData())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 737 | return mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Lei Zhang | 77f9bff | 2017-08-29 11:34:12 -0700 | [diff] [blame] | 740 | CFX_FloatRect CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 741 | CFX_Matrix mt = GetWindowMatrix(); |
Lei Zhang | 77f9bff | 2017-08-29 11:34:12 -0700 | [diff] [blame] | 742 | return mt.TransformRect(rect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 745 | CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 746 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 747 | if (mt.IsIdentity()) |
| 748 | return point; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 749 | |
Nicolas Pena | b21f174 | 2017-06-29 12:02:06 -0400 | [diff] [blame] | 750 | CFX_Matrix inverse = mt.GetInverse(); |
| 751 | if (!inverse.IsIdentity()) |
| 752 | mt = inverse; |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 753 | return mt.Transform(point); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 756 | CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 757 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 758 | if (mt.IsIdentity()) |
| 759 | return rect; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 760 | |
Nicolas Pena | b21f174 | 2017-06-29 12:02:06 -0400 | [diff] [blame] | 761 | CFX_Matrix inverse = mt.GetInverse(); |
| 762 | if (!inverse.IsIdentity()) |
| 763 | mt = inverse; |
Jane Liu | 878b27d | 2017-08-22 10:50:06 -0400 | [diff] [blame] | 764 | |
| 765 | return mt.TransformRect(rect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 768 | CFX_Matrix CPWL_Wnd::GetChildToRoot() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 769 | CFX_Matrix mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 770 | if (HasFlag(PWS_CHILD)) { |
| 771 | const CPWL_Wnd* pParent = this; |
| 772 | while (pParent) { |
| 773 | mt.Concat(pParent->GetChildMatrix()); |
| 774 | pParent = pParent->GetParentWindow(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 775 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 776 | } |
| 777 | return mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 780 | CFX_Matrix CPWL_Wnd::GetChildMatrix() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 781 | return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 784 | void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 785 | m_sPrivateParam.mtChild = mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 788 | const CPWL_Wnd* CPWL_Wnd::GetFocused() const { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 789 | CPWL_MsgControl* pMsgCtrl = GetMsgControl(); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 790 | return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 791 | } |
| 792 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 793 | void CPWL_Wnd::EnableWindow(bool bEnable) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 794 | if (m_bEnabled == bEnable) |
| 795 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 796 | |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 797 | for (auto* pChild : m_Children) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 798 | if (pChild) |
| 799 | pChild->EnableWindow(bEnable); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 800 | } |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 801 | m_bEnabled = bEnable; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 802 | } |