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; |
| 21 | constexpr int kInvalidationInflate = 2; |
| 22 | |
| 23 | } // namespace |
| 24 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 25 | PWL_CREATEPARAM::PWL_CREATEPARAM() |
| 26 | : rcRectWnd(0, 0, 0, 0), |
| 27 | pSystemHandler(nullptr), |
| 28 | pFontMap(nullptr), |
| 29 | pProvider(nullptr), |
| 30 | pFocusHandler(nullptr), |
| 31 | dwFlags(0), |
| 32 | sBackgroundColor(), |
dsinclair | 8faac62 | 2016-09-15 12:41:50 -0700 | [diff] [blame] | 33 | pAttachedWidget(nullptr), |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 34 | nBorderStyle(BorderStyle::SOLID), |
| 35 | dwBorderWidth(1), |
| 36 | sBorderColor(), |
| 37 | sTextColor(), |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 38 | nTransparency(255), |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 39 | fFontSize(kDefaultFontSize), |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 40 | sDash(3, 0, 0), |
| 41 | pAttachedData(nullptr), |
| 42 | pParentWnd(nullptr), |
| 43 | pMsgControl(nullptr), |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 44 | eCursorType(FXCT_ARROW) {} |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 45 | |
| 46 | PWL_CREATEPARAM::PWL_CREATEPARAM(const PWL_CREATEPARAM& other) = default; |
| 47 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | class CPWL_MsgControl { |
| 49 | friend class CPWL_Wnd; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | public: |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 52 | explicit CPWL_MsgControl(CPWL_Wnd* pWnd) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | m_pCreatedWnd = pWnd; |
| 54 | Default(); |
| 55 | } |
| 56 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 57 | ~CPWL_MsgControl() { Default(); } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | |
| 59 | void Default() { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 60 | m_aMousePath.clear(); |
| 61 | m_aKeyboardPath.clear(); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 62 | m_pMainMouseWnd = nullptr; |
| 63 | m_pMainKeyboardWnd = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | } |
| 65 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 66 | bool IsWndCreated(const CPWL_Wnd* pWnd) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | return m_pCreatedWnd == pWnd; |
| 68 | } |
| 69 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 70 | bool IsMainCaptureMouse(const CPWL_Wnd* pWnd) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | return pWnd == m_pMainMouseWnd; |
| 72 | } |
| 73 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 74 | bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 75 | return pWnd && pdfium::ContainsValue(m_aMousePath, pWnd); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | } |
| 77 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 78 | bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | return pWnd == m_pMainKeyboardWnd; |
| 80 | } |
| 81 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 82 | bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 83 | return pWnd && pdfium::ContainsValue(m_aKeyboardPath, pWnd); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void SetFocus(CPWL_Wnd* pWnd) { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 87 | m_aKeyboardPath.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 88 | if (pWnd) { |
| 89 | m_pMainKeyboardWnd = pWnd; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | CPWL_Wnd* pParent = pWnd; |
| 91 | while (pParent) { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 92 | m_aKeyboardPath.push_back(pParent); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 93 | pParent = pParent->GetParentWindow(); |
| 94 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 95 | pWnd->OnSetFocus(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 96 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 97 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 98 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | void KillFocus() { |
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(); |
| 103 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 104 | m_pMainKeyboardWnd = nullptr; |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 105 | m_aKeyboardPath.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void SetCapture(CPWL_Wnd* pWnd) { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 109 | m_aMousePath.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | if (pWnd) { |
| 111 | m_pMainMouseWnd = pWnd; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 112 | CPWL_Wnd* pParent = pWnd; |
| 113 | while (pParent) { |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 114 | m_aMousePath.push_back(pParent); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 115 | pParent = pParent->GetParentWindow(); |
| 116 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 117 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 118 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 119 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 120 | void ReleaseCapture() { |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 121 | m_pMainMouseWnd = nullptr; |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 122 | m_aMousePath.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 124 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 125 | private: |
tsepez | 0d164f8 | 2017-01-09 07:28:13 -0800 | [diff] [blame] | 126 | std::vector<CPWL_Wnd*> m_aMousePath; |
| 127 | std::vector<CPWL_Wnd*> m_aKeyboardPath; |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 128 | CFX_UnownedPtr<CPWL_Wnd> m_pCreatedWnd; |
| 129 | CFX_UnownedPtr<CPWL_Wnd> m_pMainMouseWnd; |
| 130 | CFX_UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 133 | CPWL_Wnd::CPWL_Wnd() |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 134 | : m_rcWindow(), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | m_rcClip(), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 136 | m_bCreated(false), |
| 137 | m_bVisible(false), |
| 138 | m_bNotifying(false), |
| 139 | m_bEnabled(true) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 140 | |
| 141 | CPWL_Wnd::~CPWL_Wnd() { |
Lei Zhang | b45324b | 2017-05-22 17:05:40 -0700 | [diff] [blame] | 142 | ASSERT(!m_bCreated); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | CFX_ByteString CPWL_Wnd::GetClassName() const { |
| 146 | return "CPWL_Wnd"; |
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 | void CPWL_Wnd::Create(const PWL_CREATEPARAM& cp) { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 150 | if (IsValid()) |
| 151 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 152 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 153 | m_sPrivateParam = cp; |
| 154 | OnCreate(m_sPrivateParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 155 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 156 | m_sPrivateParam.rcRectWnd.Normalize(); |
| 157 | m_rcWindow = m_sPrivateParam.rcRectWnd; |
dan sinclair | adf922f | 2017-07-12 21:56:27 -0400 | [diff] [blame] | 158 | m_rcClip = m_rcWindow; |
| 159 | if (!m_rcClip.IsEmpty()) { |
| 160 | m_rcClip.Inflate(1.0f, 1.0f); |
| 161 | m_rcClip.Normalize(); |
| 162 | } |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 163 | CreateMsgControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 165 | if (m_sPrivateParam.pParentWnd) |
Dan Sinclair | e5e889e | 2017-07-05 08:45:40 -0400 | [diff] [blame] | 166 | m_sPrivateParam.pParentWnd->AddChild(this); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 168 | PWL_CREATEPARAM ccp = m_sPrivateParam; |
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 | ccp.dwFlags &= 0xFFFF0000L; // remove sub styles |
| 171 | CreateScrollBar(ccp); |
| 172 | CreateChildWnd(ccp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 173 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 174 | m_bVisible = HasFlag(PWS_VISIBLE); |
| 175 | OnCreated(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 177 | RePosChildWnd(); |
| 178 | m_bCreated = true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 181 | void CPWL_Wnd::OnCreate(PWL_CREATEPARAM& cp) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 182 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | void CPWL_Wnd::OnCreated() {} |
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::OnDestroy() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 186 | |
Lei Zhang | ab5537d | 2016-01-06 14:58:14 -0800 | [diff] [blame] | 187 | void CPWL_Wnd::InvalidateFocusHandler(IPWL_FocusHandler* handler) { |
| 188 | if (m_sPrivateParam.pFocusHandler == handler) |
| 189 | m_sPrivateParam.pFocusHandler = nullptr; |
| 190 | } |
| 191 | |
| 192 | void CPWL_Wnd::InvalidateProvider(IPWL_Provider* provider) { |
Dan Sinclair | bc8dcc3 | 2017-01-19 13:53:02 -0500 | [diff] [blame] | 193 | if (m_sPrivateParam.pProvider.Get() == provider) |
| 194 | m_sPrivateParam.pProvider.Reset(); |
Lei Zhang | ab5537d | 2016-01-06 14:58:14 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 197 | void CPWL_Wnd::Destroy() { |
| 198 | KillFocus(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 199 | OnDestroy(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | if (m_bCreated) { |
Lei Zhang | 3516256 | 2017-06-09 01:04:52 -0700 | [diff] [blame] | 201 | m_pVScrollBar = nullptr; |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 202 | for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) { |
| 203 | if (CPWL_Wnd* pChild = *it) { |
| 204 | *it = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | pChild->Destroy(); |
| 206 | delete pChild; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 207 | } |
| 208 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | if (m_sPrivateParam.pParentWnd) |
Dan Sinclair | e5e889e | 2017-07-05 08:45:40 -0400 | [diff] [blame] | 210 | m_sPrivateParam.pParentWnd->RemoveChild(this); |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 211 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 212 | m_bCreated = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 214 | DestroyMsgControl(); |
Dan Sinclair | bc8dcc3 | 2017-01-19 13:53:02 -0500 | [diff] [blame] | 215 | m_sPrivateParam.Reset(); |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 216 | m_Children.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 217 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 218 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 219 | void CPWL_Wnd::Move(const CFX_FloatRect& rcNew, bool bReset, bool bRefresh) { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 220 | if (!IsValid()) |
| 221 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 222 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 223 | CFX_FloatRect rcOld = GetWindowRect(); |
| 224 | m_rcWindow = rcNew; |
| 225 | m_rcWindow.Normalize(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 226 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 227 | if (bReset) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 228 | if (rcOld.left != rcNew.left || rcOld.right != rcNew.right || |
| 229 | rcOld.top != rcNew.top || rcOld.bottom != rcNew.bottom) { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 230 | RePosChildWnd(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 231 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | } |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 233 | if (bRefresh) |
| 234 | InvalidateRectMove(rcOld, rcNew); |
| 235 | |
| 236 | m_sPrivateParam.rcRectWnd = m_rcWindow; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 239 | void CPWL_Wnd::InvalidateRectMove(const CFX_FloatRect& rcOld, |
| 240 | const CFX_FloatRect& rcNew) { |
| 241 | CFX_FloatRect rcUnion = rcOld; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 242 | rcUnion.Union(rcNew); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 243 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | InvalidateRect(&rcUnion); |
| 245 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 246 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 247 | void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 248 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | if (IsValid() && IsVisible()) { |
| 250 | DrawThisAppearance(pDevice, pUser2Device); |
| 251 | DrawChildAppearance(pDevice, pUser2Device); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 256 | CFX_Matrix* pUser2Device) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 257 | CFX_FloatRect rectWnd = GetWindowRect(); |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 258 | if (rectWnd.IsEmpty()) |
| 259 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 260 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 261 | if (HasFlag(PWS_BACKGROUND)) { |
dan sinclair | d6aff2f | 2017-07-13 21:36:29 -0400 | [diff] [blame] | 262 | float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 263 | pDevice->DrawFillRect(pUser2Device, rectWnd.GetDeflated(width, width), |
| 264 | GetBackgroundColor(), GetTransparency()); |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | if (HasFlag(PWS_BORDER)) { |
Dan Sinclair | 0b7378a | 2017-07-17 12:05:40 -0400 | [diff] [blame] | 268 | pDevice->DrawBorder(pUser2Device, rectWnd, |
| 269 | static_cast<float>(GetBorderWidth()), GetBorderColor(), |
| 270 | GetBorderLeftTopColor(GetBorderStyle()), |
| 271 | GetBorderRightBottomColor(GetBorderStyle()), |
| 272 | GetBorderStyle(), GetTransparency()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 273 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 277 | CFX_Matrix* pUser2Device) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 278 | for (CPWL_Wnd* pChild : m_Children) { |
| 279 | if (!pChild) |
| 280 | continue; |
| 281 | |
| 282 | CFX_Matrix mt = pChild->GetChildMatrix(); |
| 283 | if (mt.IsIdentity()) { |
| 284 | pChild->DrawAppearance(pDevice, pUser2Device); |
| 285 | } else { |
| 286 | mt.Concat(*pUser2Device); |
| 287 | pChild->DrawAppearance(pDevice, &mt); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 288 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 289 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 292 | void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 293 | if (!IsValid()) |
| 294 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 295 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 296 | CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect(); |
| 297 | |
| 298 | if (!HasFlag(PWS_NOREFRESHCLIP)) { |
| 299 | CFX_FloatRect rcClip = GetClipRect(); |
| 300 | if (!rcClip.IsEmpty()) { |
| 301 | rcRefresh.Intersect(rcClip); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 302 | } |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 303 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 304 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 305 | FX_RECT rcWin = PWLtoWnd(rcRefresh); |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 306 | rcWin.left -= kInvalidationInflate; |
| 307 | rcWin.top -= kInvalidationInflate; |
| 308 | rcWin.right += kInvalidationInflate; |
| 309 | rcWin.bottom += kInvalidationInflate; |
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 | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 372 | void CPWL_Wnd::DeleteSelectedText() {} |
| 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(); |
| 587 | InvalidateRect(); |
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 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 740 | FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const { |
| 741 | CFX_FloatRect rcTemp = rect; |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 742 | CFX_Matrix mt = GetWindowMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 743 | mt.TransformRect(rcTemp); |
| 744 | return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5), |
| 745 | (int32_t)(rcTemp.right + 0.5), (int32_t)(rcTemp.top + 0.5)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 748 | CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 749 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 750 | if (mt.IsIdentity()) |
| 751 | return point; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 752 | |
Nicolas Pena | b21f174 | 2017-06-29 12:02:06 -0400 | [diff] [blame] | 753 | CFX_Matrix inverse = mt.GetInverse(); |
| 754 | if (!inverse.IsIdentity()) |
| 755 | mt = inverse; |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 756 | return mt.Transform(point); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 759 | CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 760 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 761 | if (mt.IsIdentity()) |
| 762 | return rect; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 763 | |
Nicolas Pena | b21f174 | 2017-06-29 12:02:06 -0400 | [diff] [blame] | 764 | CFX_Matrix inverse = mt.GetInverse(); |
| 765 | if (!inverse.IsIdentity()) |
| 766 | mt = inverse; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 767 | CFX_FloatRect rc = rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 768 | mt.TransformRect(rc); |
| 769 | return rc; |
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 | CFX_Matrix CPWL_Wnd::GetChildToRoot() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 773 | CFX_Matrix mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 774 | if (HasFlag(PWS_CHILD)) { |
| 775 | const CPWL_Wnd* pParent = this; |
| 776 | while (pParent) { |
| 777 | mt.Concat(pParent->GetChildMatrix()); |
| 778 | pParent = pParent->GetParentWindow(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 779 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 780 | } |
| 781 | return mt; |
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 | CFX_Matrix CPWL_Wnd::GetChildMatrix() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 785 | return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 788 | void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 789 | m_sPrivateParam.mtChild = mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 792 | const CPWL_Wnd* CPWL_Wnd::GetFocused() const { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 793 | CPWL_MsgControl* pMsgCtrl = GetMsgControl(); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 794 | return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 795 | } |
| 796 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 797 | void CPWL_Wnd::EnableWindow(bool bEnable) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 798 | if (m_bEnabled == bEnable) |
| 799 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 800 | |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 801 | for (auto* pChild : m_Children) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 802 | if (pChild) |
| 803 | pChild->EnableWindow(bEnable); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 804 | } |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 805 | m_bEnabled = bEnable; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 806 | } |