John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | 633a3b7 | 2017-06-02 15:27:22 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/pdfwindow/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 | |
Lei Zhang | 633a3b7 | 2017-06-02 15:27:22 -0700 | [diff] [blame] | 13 | #include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h" |
| 14 | #include "fpdfsdk/pdfwindow/cpwl_utils.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 | |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 247 | void CPWL_Wnd::GetAppearanceStream(std::ostringstream* psAppStream) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 248 | if (IsValid() && IsVisible()) { |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 249 | GetThisAppearanceStream(psAppStream); |
| 250 | GetChildAppearanceStream(psAppStream); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 253 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 254 | // if don't set,Get default apperance stream |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 255 | void CPWL_Wnd::GetThisAppearanceStream(std::ostringstream* psAppStream) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 256 | CFX_FloatRect rectWnd = GetWindowRect(); |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 257 | if (rectWnd.IsEmpty()) |
| 258 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 259 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 260 | if (HasFlag(PWS_BACKGROUND)) |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 261 | *psAppStream << CPWL_Utils::GetRectFillAppStream(rectWnd, |
| 262 | GetBackgroundColor()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 263 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 264 | if (HasFlag(PWS_BORDER)) { |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 265 | *psAppStream << CPWL_Utils::GetBorderAppStream( |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 266 | rectWnd, (float)GetBorderWidth(), GetBorderColor(), |
| 267 | GetBorderLeftTopColor(GetBorderStyle()), |
| 268 | GetBorderRightBottomColor(GetBorderStyle()), GetBorderStyle(), |
| 269 | GetBorderDash()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 273 | void CPWL_Wnd::GetChildAppearanceStream(std::ostringstream* psAppStream) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 274 | for (CPWL_Wnd* pChild : m_Children) { |
| 275 | if (pChild) |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 276 | pChild->GetAppearanceStream(psAppStream); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 280 | void CPWL_Wnd::DrawAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 281 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 282 | if (IsValid() && IsVisible()) { |
| 283 | DrawThisAppearance(pDevice, pUser2Device); |
| 284 | DrawChildAppearance(pDevice, pUser2Device); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | void CPWL_Wnd::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 289 | CFX_Matrix* pUser2Device) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 290 | CFX_FloatRect rectWnd = GetWindowRect(); |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 291 | if (rectWnd.IsEmpty()) |
| 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 | if (HasFlag(PWS_BACKGROUND)) { |
dan sinclair | adf922f | 2017-07-12 21:56:27 -0400 | [diff] [blame^] | 295 | CFX_FloatRect rcClient = rectWnd; |
| 296 | if (!rcClient.IsEmpty()) { |
| 297 | float width = |
| 298 | static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); |
| 299 | rcClient.Deflate(width, width); |
| 300 | rcClient.Normalize(); |
| 301 | } |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 302 | CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient, |
| 303 | GetBackgroundColor(), GetTransparency()); |
| 304 | } |
| 305 | |
| 306 | if (HasFlag(PWS_BORDER)) { |
| 307 | CPWL_Utils::DrawBorder(pDevice, pUser2Device, rectWnd, |
| 308 | (float)GetBorderWidth(), GetBorderColor(), |
| 309 | GetBorderLeftTopColor(GetBorderStyle()), |
| 310 | GetBorderRightBottomColor(GetBorderStyle()), |
| 311 | GetBorderStyle(), GetTransparency()); |
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 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 315 | void CPWL_Wnd::DrawChildAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 316 | CFX_Matrix* pUser2Device) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 317 | for (CPWL_Wnd* pChild : m_Children) { |
| 318 | if (!pChild) |
| 319 | continue; |
| 320 | |
| 321 | CFX_Matrix mt = pChild->GetChildMatrix(); |
| 322 | if (mt.IsIdentity()) { |
| 323 | pChild->DrawAppearance(pDevice, pUser2Device); |
| 324 | } else { |
| 325 | mt.Concat(*pUser2Device); |
| 326 | pChild->DrawAppearance(pDevice, &mt); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 327 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 328 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 331 | void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 332 | if (!IsValid()) |
| 333 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 334 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 335 | CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect(); |
| 336 | |
| 337 | if (!HasFlag(PWS_NOREFRESHCLIP)) { |
| 338 | CFX_FloatRect rcClip = GetClipRect(); |
| 339 | if (!rcClip.IsEmpty()) { |
| 340 | rcRefresh.Intersect(rcClip); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 341 | } |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 342 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 343 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 344 | FX_RECT rcWin = PWLtoWnd(rcRefresh); |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 345 | rcWin.left -= kInvalidationInflate; |
| 346 | rcWin.top -= kInvalidationInflate; |
| 347 | rcWin.right += kInvalidationInflate; |
| 348 | rcWin.bottom += kInvalidationInflate; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 349 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 350 | if (CFX_SystemHandler* pSH = GetSystemHandler()) { |
| 351 | if (CPDFSDK_Widget* widget = static_cast<CPDFSDK_Widget*>( |
| 352 | m_sPrivateParam.pAttachedWidget.Get())) { |
| 353 | pSH->InvalidateRect(widget, rcWin); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 354 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 355 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 356 | } |
| 357 | |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 358 | #define PWL_IMPLEMENT_KEY_METHOD(key_method_name) \ |
| 359 | bool CPWL_Wnd::key_method_name(uint16_t nChar, uint32_t nFlag) { \ |
| 360 | if (!IsValid() || !IsVisible() || !IsEnabled()) \ |
| 361 | return false; \ |
| 362 | if (!IsWndCaptureKeyboard(this)) \ |
| 363 | return false; \ |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 364 | for (auto* pChild : m_Children) { \ |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 365 | if (pChild && IsWndCaptureKeyboard(pChild)) \ |
| 366 | return pChild->key_method_name(nChar, nFlag); \ |
| 367 | } \ |
| 368 | return false; \ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 369 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 370 | |
| 371 | PWL_IMPLEMENT_KEY_METHOD(OnKeyDown) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 372 | PWL_IMPLEMENT_KEY_METHOD(OnChar) |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 373 | #undef PWL_IMPLEMENT_KEY_METHOD |
| 374 | |
| 375 | #define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name) \ |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 376 | bool CPWL_Wnd::mouse_method_name(const CFX_PointF& point, uint32_t nFlag) { \ |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 377 | if (!IsValid() || !IsVisible() || !IsEnabled()) \ |
| 378 | return false; \ |
| 379 | if (IsWndCaptureMouse(this)) { \ |
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 && IsWndCaptureMouse(pChild)) { \ |
| 382 | return pChild->mouse_method_name(pChild->ParentToChild(point), \ |
| 383 | nFlag); \ |
| 384 | } \ |
| 385 | } \ |
| 386 | SetCursor(); \ |
| 387 | return false; \ |
| 388 | } \ |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 389 | for (auto* pChild : m_Children) { \ |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 390 | if (pChild && pChild->WndHitTest(pChild->ParentToChild(point))) { \ |
| 391 | return pChild->mouse_method_name(pChild->ParentToChild(point), nFlag); \ |
| 392 | } \ |
| 393 | } \ |
| 394 | if (WndHitTest(point)) \ |
| 395 | SetCursor(); \ |
| 396 | return false; \ |
| 397 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 398 | |
| 399 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDblClk) |
| 400 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonDown) |
| 401 | PWL_IMPLEMENT_MOUSE_METHOD(OnLButtonUp) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 402 | PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonDown) |
| 403 | PWL_IMPLEMENT_MOUSE_METHOD(OnRButtonUp) |
| 404 | PWL_IMPLEMENT_MOUSE_METHOD(OnMouseMove) |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 405 | #undef PWL_IMPLEMENT_MOUSE_METHOD |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 406 | |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 407 | CFX_WideString CPWL_Wnd::GetSelectedText() { |
| 408 | return CFX_WideString(); |
| 409 | } |
| 410 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 411 | bool CPWL_Wnd::OnMouseWheel(short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 412 | const CFX_PointF& point, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 413 | uint32_t nFlag) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 414 | if (!IsValid() || !IsVisible() || !IsEnabled()) |
| 415 | return false; |
| 416 | |
| 417 | SetCursor(); |
| 418 | if (!IsWndCaptureKeyboard(this)) |
| 419 | return false; |
| 420 | |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 421 | for (auto* pChild : m_Children) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 422 | if (pChild && IsWndCaptureKeyboard(pChild)) |
| 423 | return pChild->OnMouseWheel(zDelta, pChild->ParentToChild(point), nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 424 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 425 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | void CPWL_Wnd::AddChild(CPWL_Wnd* pWnd) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 429 | m_Children.push_back(pWnd); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 432 | void CPWL_Wnd::RemoveChild(CPWL_Wnd* pWnd) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 433 | for (auto it = m_Children.rbegin(); it != m_Children.rend(); ++it) { |
| 434 | if (*it && *it == pWnd) { |
| 435 | m_Children.erase(std::next(it).base()); |
| 436 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 437 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 438 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Dan Sinclair | fb00ec2 | 2017-07-05 09:28:15 -0400 | [diff] [blame] | 441 | void CPWL_Wnd::SetScrollInfo(const PWL_SCROLL_INFO& info) {} |
| 442 | |
Dan Sinclair | 7e0336e | 2017-07-05 09:39:50 -0400 | [diff] [blame] | 443 | void CPWL_Wnd::SetScrollPosition(float pos) {} |
| 444 | |
Dan Sinclair | 63fbd8d | 2017-07-05 14:10:36 -0400 | [diff] [blame] | 445 | void CPWL_Wnd::ScrollWindowVertically(float pos) {} |
| 446 | |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 447 | void CPWL_Wnd::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {} |
| 448 | |
| 449 | void CPWL_Wnd::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {} |
| 450 | |
| 451 | void CPWL_Wnd::NotifyMouseMove(CPWL_Wnd* child, const CFX_PointF& pos) {} |
| 452 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 453 | bool CPWL_Wnd::IsValid() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 454 | return m_bCreated; |
| 455 | } |
| 456 | |
Lei Zhang | 7457e38 | 2016-01-06 23:00:34 -0800 | [diff] [blame] | 457 | const PWL_CREATEPARAM& CPWL_Wnd::GetCreationParam() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 458 | return m_sPrivateParam; |
| 459 | } |
| 460 | |
| 461 | CPWL_Wnd* CPWL_Wnd::GetParentWindow() const { |
| 462 | return m_sPrivateParam.pParentWnd; |
| 463 | } |
| 464 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 465 | CFX_FloatRect CPWL_Wnd::GetWindowRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | return m_rcWindow; |
| 467 | } |
| 468 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 469 | CFX_FloatRect CPWL_Wnd::GetClientRect() const { |
| 470 | CFX_FloatRect rcWindow = GetWindowRect(); |
dan sinclair | adf922f | 2017-07-12 21:56:27 -0400 | [diff] [blame^] | 471 | CFX_FloatRect rcClient = rcWindow; |
| 472 | if (!rcClient.IsEmpty()) { |
| 473 | float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); |
| 474 | rcClient.Deflate(width, width); |
| 475 | rcClient.Normalize(); |
| 476 | } |
| 477 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 478 | if (CPWL_ScrollBar* pVSB = GetVScrollBar()) |
| 479 | rcClient.right -= pVSB->GetScrollBarWidth(); |
| 480 | |
| 481 | rcClient.Normalize(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 482 | return rcWindow.Contains(rcClient) ? rcClient : CFX_FloatRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 485 | CFX_PointF CPWL_Wnd::GetCenterPoint() const { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 486 | CFX_FloatRect rcClient = GetClientRect(); |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 487 | return CFX_PointF((rcClient.left + rcClient.right) * 0.5f, |
| 488 | (rcClient.top + rcClient.bottom) * 0.5f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 489 | } |
| 490 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 491 | bool CPWL_Wnd::HasFlag(uint32_t dwFlags) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 492 | return (m_sPrivateParam.dwFlags & dwFlags) != 0; |
| 493 | } |
| 494 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 495 | void CPWL_Wnd::RemoveFlag(uint32_t dwFlags) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 496 | m_sPrivateParam.dwFlags &= ~dwFlags; |
| 497 | } |
| 498 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 499 | void CPWL_Wnd::AddFlag(uint32_t dwFlags) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 500 | m_sPrivateParam.dwFlags |= dwFlags; |
| 501 | } |
| 502 | |
| 503 | CPWL_Color CPWL_Wnd::GetBackgroundColor() const { |
| 504 | return m_sPrivateParam.sBackgroundColor; |
| 505 | } |
| 506 | |
| 507 | void CPWL_Wnd::SetBackgroundColor(const CPWL_Color& color) { |
| 508 | m_sPrivateParam.sBackgroundColor = color; |
| 509 | } |
| 510 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 511 | CPWL_Color CPWL_Wnd::GetTextColor() const { |
| 512 | return m_sPrivateParam.sTextColor; |
| 513 | } |
| 514 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 515 | BorderStyle CPWL_Wnd::GetBorderStyle() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 516 | return m_sPrivateParam.nBorderStyle; |
| 517 | } |
| 518 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 519 | void CPWL_Wnd::SetBorderStyle(BorderStyle nBorderStyle) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 520 | if (HasFlag(PWS_BORDER)) |
| 521 | m_sPrivateParam.nBorderStyle = nBorderStyle; |
| 522 | } |
| 523 | |
| 524 | int32_t CPWL_Wnd::GetBorderWidth() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 525 | return HasFlag(PWS_BORDER) ? m_sPrivateParam.dwBorderWidth : 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | int32_t CPWL_Wnd::GetInnerBorderWidth() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 529 | return 0; |
| 530 | } |
| 531 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 532 | CPWL_Color CPWL_Wnd::GetBorderColor() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 533 | return HasFlag(PWS_BORDER) ? m_sPrivateParam.sBorderColor : CPWL_Color(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Lei Zhang | 7457e38 | 2016-01-06 23:00:34 -0800 | [diff] [blame] | 536 | const CPWL_Dash& CPWL_Wnd::GetBorderDash() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 537 | return m_sPrivateParam.sDash; |
| 538 | } |
| 539 | |
| 540 | void* CPWL_Wnd::GetAttachedData() const { |
| 541 | return m_sPrivateParam.pAttachedData; |
| 542 | } |
| 543 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 544 | CPWL_ScrollBar* CPWL_Wnd::GetVScrollBar() const { |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 545 | return HasFlag(PWS_VSCROLL) ? m_pVScrollBar.Get() : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | void CPWL_Wnd::CreateScrollBar(const PWL_CREATEPARAM& cp) { |
| 549 | CreateVScrollBar(cp); |
| 550 | } |
| 551 | |
| 552 | void CPWL_Wnd::CreateVScrollBar(const PWL_CREATEPARAM& cp) { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 553 | if (m_pVScrollBar || !HasFlag(PWS_VSCROLL)) |
| 554 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 555 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 556 | PWL_CREATEPARAM scp = cp; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 557 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 558 | // flags |
| 559 | scp.dwFlags = |
| 560 | PWS_CHILD | PWS_BACKGROUND | PWS_AUTOTRANSPARENT | PWS_NOREFRESHCLIP; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 562 | scp.pParentWnd = this; |
| 563 | scp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; |
| 564 | scp.eCursorType = FXCT_ARROW; |
| 565 | scp.nTransparency = PWL_SCROLLBAR_TRANSPARENCY; |
| 566 | |
| 567 | m_pVScrollBar = new CPWL_ScrollBar(SBT_VSCROLL); |
| 568 | m_pVScrollBar->Create(scp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | void CPWL_Wnd::SetCapture() { |
| 572 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) |
| 573 | pMsgCtrl->SetCapture(this); |
| 574 | } |
| 575 | |
| 576 | void CPWL_Wnd::ReleaseCapture() { |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 577 | for (auto* pChild : m_Children) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 578 | if (pChild) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 579 | pChild->ReleaseCapture(); |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 580 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 581 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) |
| 582 | pMsgCtrl->ReleaseCapture(); |
| 583 | } |
| 584 | |
| 585 | void CPWL_Wnd::SetFocus() { |
| 586 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 587 | if (!pMsgCtrl->IsMainCaptureKeyboard(this)) |
| 588 | pMsgCtrl->KillFocus(); |
| 589 | pMsgCtrl->SetFocus(this); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | void CPWL_Wnd::KillFocus() { |
| 594 | if (CPWL_MsgControl* pMsgCtrl = GetMsgControl()) { |
| 595 | if (pMsgCtrl->IsWndCaptureKeyboard(this)) |
| 596 | pMsgCtrl->KillFocus(); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | void CPWL_Wnd::OnSetFocus() {} |
| 601 | |
| 602 | void CPWL_Wnd::OnKillFocus() {} |
| 603 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 604 | bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 605 | return IsValid() && IsVisible() && GetWindowRect().Contains(point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 608 | bool CPWL_Wnd::ClientHitTest(const CFX_PointF& point) const { |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 609 | return IsValid() && IsVisible() && GetClientRect().Contains(point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | const CPWL_Wnd* CPWL_Wnd::GetRootWnd() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 613 | auto* pParent = m_sPrivateParam.pParentWnd; |
| 614 | return pParent ? pParent->GetRootWnd() : this; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 615 | } |
| 616 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 617 | void CPWL_Wnd::SetVisible(bool bVisible) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 618 | if (!IsValid()) |
| 619 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 620 | |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 621 | for (auto* pChild : m_Children) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 622 | if (pChild) |
| 623 | pChild->SetVisible(bVisible); |
| 624 | } |
| 625 | if (bVisible != m_bVisible) { |
| 626 | m_bVisible = bVisible; |
| 627 | RePosChildWnd(); |
| 628 | InvalidateRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 629 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 632 | void CPWL_Wnd::SetClipRect(const CFX_FloatRect& rect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 633 | m_rcClip = rect; |
| 634 | m_rcClip.Normalize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 637 | const CFX_FloatRect& CPWL_Wnd::GetClipRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 638 | return m_rcClip; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 639 | } |
| 640 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 641 | bool CPWL_Wnd::IsReadOnly() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 642 | return HasFlag(PWS_READONLY); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | void CPWL_Wnd::RePosChildWnd() { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 646 | CPWL_ScrollBar* pVSB = GetVScrollBar(); |
| 647 | if (!pVSB) |
| 648 | return; |
| 649 | |
dan sinclair | adf922f | 2017-07-12 21:56:27 -0400 | [diff] [blame^] | 650 | CFX_FloatRect rcContent = GetWindowRect(); |
| 651 | if (!rcContent.IsEmpty()) { |
| 652 | float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth()); |
| 653 | rcContent.Deflate(width, width); |
| 654 | rcContent.Normalize(); |
| 655 | } |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 656 | CFX_FloatRect rcVScroll = |
| 657 | CFX_FloatRect(rcContent.right - PWL_SCROLLBAR_WIDTH, rcContent.bottom, |
| 658 | rcContent.right - 1.0f, rcContent.top); |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 659 | pVSB->Move(rcVScroll, true, false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 662 | void CPWL_Wnd::CreateChildWnd(const PWL_CREATEPARAM& cp) {} |
| 663 | |
| 664 | void CPWL_Wnd::SetCursor() { |
| 665 | if (IsValid()) { |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 666 | if (CFX_SystemHandler* pSH = GetSystemHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 667 | int32_t nCursorType = GetCreationParam().eCursorType; |
| 668 | pSH->SetCursor(nCursorType); |
| 669 | } |
| 670 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 673 | void CPWL_Wnd::CreateMsgControl() { |
| 674 | if (!m_sPrivateParam.pMsgControl) |
| 675 | m_sPrivateParam.pMsgControl = new CPWL_MsgControl(this); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 678 | void CPWL_Wnd::DestroyMsgControl() { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 679 | CPWL_MsgControl* pMsgControl = GetMsgControl(); |
| 680 | if (pMsgControl && pMsgControl->IsWndCreated(this)) |
| 681 | delete pMsgControl; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 684 | CPWL_MsgControl* CPWL_Wnd::GetMsgControl() const { |
| 685 | return m_sPrivateParam.pMsgControl; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 686 | } |
| 687 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 688 | bool CPWL_Wnd::IsCaptureMouse() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 689 | return IsWndCaptureMouse(this); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 690 | } |
| 691 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 692 | bool CPWL_Wnd::IsWndCaptureMouse(const CPWL_Wnd* pWnd) const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 693 | CPWL_MsgControl* pCtrl = GetMsgControl(); |
| 694 | return pCtrl ? pCtrl->IsWndCaptureMouse(pWnd) : false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 695 | } |
| 696 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 697 | bool CPWL_Wnd::IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 698 | CPWL_MsgControl* pCtrl = GetMsgControl(); |
| 699 | return pCtrl ? pCtrl->IsWndCaptureKeyboard(pWnd) : false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 700 | } |
| 701 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 702 | bool CPWL_Wnd::IsFocused() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 703 | CPWL_MsgControl* pCtrl = GetMsgControl(); |
| 704 | return pCtrl ? pCtrl->IsMainCaptureKeyboard(this) : false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 707 | CFX_FloatRect CPWL_Wnd::GetFocusRect() const { |
dan sinclair | adf922f | 2017-07-12 21:56:27 -0400 | [diff] [blame^] | 708 | CFX_FloatRect rect = GetWindowRect(); |
| 709 | if (!rect.IsEmpty()) { |
| 710 | rect.Inflate(1.0f, 1.0f); |
| 711 | rect.Normalize(); |
| 712 | } |
| 713 | return rect; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 716 | float CPWL_Wnd::GetFontSize() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 717 | return m_sPrivateParam.fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 720 | void CPWL_Wnd::SetFontSize(float fFontSize) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 721 | m_sPrivateParam.fFontSize = fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 722 | } |
| 723 | |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 724 | CFX_SystemHandler* CPWL_Wnd::GetSystemHandler() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 725 | return m_sPrivateParam.pSystemHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 728 | IPWL_FocusHandler* CPWL_Wnd::GetFocusHandler() const { |
| 729 | return m_sPrivateParam.pFocusHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 732 | IPWL_Provider* CPWL_Wnd::GetProvider() const { |
Dan Sinclair | bc8dcc3 | 2017-01-19 13:53:02 -0500 | [diff] [blame] | 733 | return m_sPrivateParam.pProvider.Get(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 734 | } |
| 735 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 736 | IPVT_FontMap* CPWL_Wnd::GetFontMap() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 737 | return m_sPrivateParam.pFontMap; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 738 | } |
| 739 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 740 | CPWL_Color CPWL_Wnd::GetBorderLeftTopColor(BorderStyle nBorderStyle) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 741 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 742 | case BorderStyle::BEVELED: |
| 743 | return CPWL_Color(COLORTYPE_GRAY, 1); |
| 744 | case BorderStyle::INSET: |
| 745 | return CPWL_Color(COLORTYPE_GRAY, 0.5f); |
| 746 | default: |
| 747 | return CPWL_Color(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 748 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 749 | } |
| 750 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 751 | CPWL_Color CPWL_Wnd::GetBorderRightBottomColor(BorderStyle nBorderStyle) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 752 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 753 | case BorderStyle::BEVELED: |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 754 | return GetBackgroundColor() / 2.0f; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 755 | case BorderStyle::INSET: |
| 756 | return CPWL_Color(COLORTYPE_GRAY, 0.75f); |
| 757 | default: |
| 758 | return CPWL_Color(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 759 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 762 | int32_t CPWL_Wnd::GetTransparency() { |
| 763 | return m_sPrivateParam.nTransparency; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 766 | void CPWL_Wnd::SetTransparency(int32_t nTransparency) { |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 767 | for (auto* pChild : m_Children) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 768 | if (pChild) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 769 | pChild->SetTransparency(nTransparency); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 770 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 771 | m_sPrivateParam.nTransparency = nTransparency; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 774 | CFX_Matrix CPWL_Wnd::GetWindowMatrix() const { |
| 775 | CFX_Matrix mt = GetChildToRoot(); |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 776 | if (IPWL_Provider* pProvider = GetProvider()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 777 | mt.Concat(pProvider->GetWindowMatrix(GetAttachedData())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 778 | return mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 781 | FX_RECT CPWL_Wnd::PWLtoWnd(const CFX_FloatRect& rect) const { |
| 782 | CFX_FloatRect rcTemp = rect; |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 783 | CFX_Matrix mt = GetWindowMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 784 | mt.TransformRect(rcTemp); |
| 785 | return FX_RECT((int32_t)(rcTemp.left + 0.5), (int32_t)(rcTemp.bottom + 0.5), |
| 786 | (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] | 787 | } |
| 788 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 789 | CFX_PointF CPWL_Wnd::ParentToChild(const CFX_PointF& point) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 790 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 791 | if (mt.IsIdentity()) |
| 792 | return point; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 793 | |
Nicolas Pena | b21f174 | 2017-06-29 12:02:06 -0400 | [diff] [blame] | 794 | CFX_Matrix inverse = mt.GetInverse(); |
| 795 | if (!inverse.IsIdentity()) |
| 796 | mt = inverse; |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 797 | return mt.Transform(point); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 800 | CFX_FloatRect CPWL_Wnd::ParentToChild(const CFX_FloatRect& rect) const { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 801 | CFX_Matrix mt = GetChildMatrix(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 802 | if (mt.IsIdentity()) |
| 803 | return rect; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 804 | |
Nicolas Pena | b21f174 | 2017-06-29 12:02:06 -0400 | [diff] [blame] | 805 | CFX_Matrix inverse = mt.GetInverse(); |
| 806 | if (!inverse.IsIdentity()) |
| 807 | mt = inverse; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 808 | CFX_FloatRect rc = rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 809 | mt.TransformRect(rc); |
| 810 | return rc; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 813 | CFX_Matrix CPWL_Wnd::GetChildToRoot() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 814 | CFX_Matrix mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 815 | if (HasFlag(PWS_CHILD)) { |
| 816 | const CPWL_Wnd* pParent = this; |
| 817 | while (pParent) { |
| 818 | mt.Concat(pParent->GetChildMatrix()); |
| 819 | pParent = pParent->GetParentWindow(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 820 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 821 | } |
| 822 | return mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 825 | CFX_Matrix CPWL_Wnd::GetChildMatrix() const { |
Lei Zhang | fac46f8 | 2017-06-02 14:20:04 -0700 | [diff] [blame] | 826 | return HasFlag(PWS_CHILD) ? m_sPrivateParam.mtChild : CFX_Matrix(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 829 | void CPWL_Wnd::SetChildMatrix(const CFX_Matrix& mt) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 830 | m_sPrivateParam.mtChild = mt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 833 | const CPWL_Wnd* CPWL_Wnd::GetFocused() const { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 834 | CPWL_MsgControl* pMsgCtrl = GetMsgControl(); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 835 | return pMsgCtrl ? pMsgCtrl->m_pMainKeyboardWnd.Get() : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 836 | } |
| 837 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 838 | void CPWL_Wnd::EnableWindow(bool bEnable) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 839 | if (m_bEnabled == bEnable) |
| 840 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 841 | |
Lei Zhang | 375c276 | 2017-03-10 14:37:14 -0800 | [diff] [blame] | 842 | for (auto* pChild : m_Children) { |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 843 | if (pChild) |
| 844 | pChild->EnableWindow(bEnable); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 845 | } |
tsepez | 6745f96 | 2017-01-04 10:09:45 -0800 | [diff] [blame] | 846 | m_bEnabled = bEnable; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 847 | } |
| 848 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 849 | bool CPWL_Wnd::IsCTRLpressed(uint32_t nFlag) const { |
Dan Sinclair | 90b7326 | 2017-02-23 14:38:48 -0500 | [diff] [blame] | 850 | CFX_SystemHandler* pSystemHandler = GetSystemHandler(); |
| 851 | return pSystemHandler && pSystemHandler->IsCTRLKeyDown(nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 852 | } |
| 853 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 854 | bool CPWL_Wnd::IsSHIFTpressed(uint32_t nFlag) const { |
Dan Sinclair | 90b7326 | 2017-02-23 14:38:48 -0500 | [diff] [blame] | 855 | CFX_SystemHandler* pSystemHandler = GetSystemHandler(); |
| 856 | return pSystemHandler && pSystemHandler->IsSHIFTKeyDown(nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 857 | } |
| 858 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 859 | bool CPWL_Wnd::IsALTpressed(uint32_t nFlag) const { |
Dan Sinclair | 90b7326 | 2017-02-23 14:38:48 -0500 | [diff] [blame] | 860 | CFX_SystemHandler* pSystemHandler = GetSystemHandler(); |
| 861 | return pSystemHandler && pSystemHandler->IsALTKeyDown(nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 862 | } |