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