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