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 | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | c411eb9 | 2017-07-25 09:39:30 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/pwl/cpwl_combo_box.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 8 | |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 9 | #include <algorithm> |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 10 | #include <sstream> |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 11 | |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 12 | #include "core/fxge/cfx_pathdata.h" |
| 13 | #include "core/fxge/cfx_renderdevice.h" |
Dan Sinclair | c411eb9 | 2017-07-25 09:39:30 -0400 | [diff] [blame] | 14 | #include "fpdfsdk/pwl/cpwl_edit.h" |
| 15 | #include "fpdfsdk/pwl/cpwl_edit_ctrl.h" |
| 16 | #include "fpdfsdk/pwl/cpwl_list_box.h" |
| 17 | #include "fpdfsdk/pwl/cpwl_list_impl.h" |
| 18 | #include "fpdfsdk/pwl/cpwl_wnd.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 19 | #include "public/fpdf_fwlevent.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 20 | |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 21 | namespace { |
| 22 | |
| 23 | constexpr float kDefaultFontSize = 12.0f; |
| 24 | constexpr float kTriangleHalfLength = 3.0f; |
Dan Sinclair | 951b111 | 2017-10-02 10:38:55 -0400 | [diff] [blame] | 25 | constexpr int kDefaultButtonWidth = 13; |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 26 | |
| 27 | } // namespace |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 28 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 29 | bool CPWL_CBListBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 30 | CPWL_Wnd::OnLButtonUp(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 31 | |
dsinclair | 3617751 | 2016-07-19 10:16:10 -0700 | [diff] [blame] | 32 | if (!m_bMouseDown) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 33 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | |
dsinclair | 3617751 | 2016-07-19 10:16:10 -0700 | [diff] [blame] | 35 | ReleaseCapture(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 36 | m_bMouseDown = false; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 37 | |
dsinclair | 3617751 | 2016-07-19 10:16:10 -0700 | [diff] [blame] | 38 | if (!ClientHitTest(point)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 39 | return true; |
dsinclair | 3617751 | 2016-07-19 10:16:10 -0700 | [diff] [blame] | 40 | if (CPWL_Wnd* pParent = GetParentWindow()) |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 41 | pParent->NotifyLButtonUp(this, point); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 42 | |
Dan Sinclair | 2b44441 | 2017-07-06 13:56:35 -0400 | [diff] [blame] | 43 | return !OnNotifySelectionChanged(false, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Dan Sinclair | 07dbf43 | 2017-07-06 11:47:26 -0400 | [diff] [blame] | 46 | bool CPWL_CBListBox::IsMovementKey(uint16_t nChar) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | switch (nChar) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | case FWL_VKEY_Up: |
| 49 | case FWL_VKEY_Down: |
| 50 | case FWL_VKEY_Home: |
| 51 | case FWL_VKEY_Left: |
| 52 | case FWL_VKEY_End: |
| 53 | case FWL_VKEY_Right: |
Dan Sinclair | 07dbf43 | 2017-07-06 11:47:26 -0400 | [diff] [blame] | 54 | return true; |
dsinclair | 3617751 | 2016-07-19 10:16:10 -0700 | [diff] [blame] | 55 | default: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 56 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | } |
Dan Sinclair | 07dbf43 | 2017-07-06 11:47:26 -0400 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | bool CPWL_CBListBox::OnMovementKeyDown(uint16_t nChar, uint32_t nFlag) { |
| 61 | ASSERT(IsMovementKey(nChar)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 62 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | switch (nChar) { |
| 64 | case FWL_VKEY_Up: |
| 65 | m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 66 | break; |
| 67 | case FWL_VKEY_Down: |
| 68 | m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 69 | break; |
| 70 | case FWL_VKEY_Home: |
| 71 | m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 72 | break; |
| 73 | case FWL_VKEY_Left: |
| 74 | m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 75 | break; |
| 76 | case FWL_VKEY_End: |
| 77 | m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 78 | break; |
| 79 | case FWL_VKEY_Right: |
| 80 | m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 81 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 82 | } |
Dan Sinclair | 2b44441 | 2017-07-06 13:56:35 -0400 | [diff] [blame] | 83 | return OnNotifySelectionChanged(true, nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Dan Sinclair | 16fea94 | 2017-07-06 11:56:37 -0400 | [diff] [blame] | 86 | bool CPWL_CBListBox::IsChar(uint16_t nChar, uint32_t nFlag) const { |
| 87 | return m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 88 | } |
| 89 | |
| 90 | bool CPWL_CBListBox::OnCharNotify(uint16_t nChar, uint32_t nFlag) { |
dsinclair | 3617751 | 2016-07-19 10:16:10 -0700 | [diff] [blame] | 91 | if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | pComboBox->SetSelectText(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 93 | |
Dan Sinclair | 2b44441 | 2017-07-06 13:56:35 -0400 | [diff] [blame] | 94 | return OnNotifySelectionChanged(true, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 97 | void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 98 | const CFX_Matrix& mtUser2Device) { |
| 99 | CPWL_Wnd::DrawThisAppearance(pDevice, mtUser2Device); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 100 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 101 | CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 102 | |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 103 | if (!IsVisible() || rectWnd.IsEmpty()) |
| 104 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 105 | |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 106 | CFX_PointF ptCenter = GetCenterPoint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 107 | |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 108 | CFX_PointF pt1(ptCenter.x - kTriangleHalfLength, |
| 109 | ptCenter.y + kTriangleHalfLength * 0.5f); |
| 110 | CFX_PointF pt2(ptCenter.x + kTriangleHalfLength, |
| 111 | ptCenter.y + kTriangleHalfLength * 0.5f); |
| 112 | CFX_PointF pt3(ptCenter.x, ptCenter.y - kTriangleHalfLength * 0.5f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 113 | |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 114 | if (IsFloatBigger(rectWnd.right - rectWnd.left, kTriangleHalfLength * 2) && |
| 115 | IsFloatBigger(rectWnd.top - rectWnd.bottom, kTriangleHalfLength)) { |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 116 | CFX_PathData path; |
| 117 | path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false); |
| 118 | path.AppendPoint(pt2, FXPT_TYPE::LineTo, false); |
| 119 | path.AppendPoint(pt3, FXPT_TYPE::LineTo, false); |
| 120 | path.AppendPoint(pt1, FXPT_TYPE::LineTo, false); |
| 121 | |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 122 | pDevice->DrawPath(&path, &mtUser2Device, nullptr, |
Henrique Nakashima | f1eae2c | 2017-06-29 11:18:49 -0400 | [diff] [blame] | 123 | PWL_DEFAULT_BLACKCOLOR.ToFXColor(GetTransparency()), 0, |
| 124 | FXFILL_ALTERNATE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 125 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 128 | bool CPWL_CBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 129 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 130 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 131 | SetCapture(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 132 | |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 133 | if (CPWL_Wnd* pParent = GetParentWindow()) |
| 134 | pParent->NotifyLButtonDown(this, point); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 135 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 136 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 139 | bool CPWL_CBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 140 | CPWL_Wnd::OnLButtonUp(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 141 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 142 | ReleaseCapture(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 143 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 144 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Lei Zhang | 3516256 | 2017-06-09 01:04:52 -0700 | [diff] [blame] | 147 | CPWL_ComboBox::CPWL_ComboBox() {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 148 | |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 149 | CPWL_ComboBox::~CPWL_ComboBox() {} |
| 150 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 151 | ByteString CPWL_ComboBox::GetClassName() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 152 | return "CPWL_ComboBox"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 155 | void CPWL_ComboBox::OnCreate(CreateParams* pParamsToAdjust) { |
| 156 | pParamsToAdjust->dwFlags &= ~PWS_HSCROLL; |
| 157 | pParamsToAdjust->dwFlags &= ~PWS_VSCROLL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Lei Zhang | 3516256 | 2017-06-09 01:04:52 -0700 | [diff] [blame] | 160 | void CPWL_ComboBox::OnDestroy() { |
| 161 | // Until cleanup takes place in the virtual destructor for CPWL_Wnd |
| 162 | // subclasses, implement the virtual OnDestroy method that does the |
| 163 | // cleanup first, then invokes the superclass OnDestroy ... gee, |
| 164 | // like a dtor would. |
| 165 | m_pList.Release(); |
| 166 | m_pButton.Release(); |
| 167 | m_pEdit.Release(); |
| 168 | CPWL_Wnd::OnDestroy(); |
| 169 | } |
| 170 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | void CPWL_ComboBox::SetFocus() { |
| 172 | if (m_pEdit) |
| 173 | m_pEdit->SetFocus(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | void CPWL_ComboBox::KillFocus() { |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 177 | if (!SetPopup(false)) |
| 178 | return; |
| 179 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 180 | CPWL_Wnd::KillFocus(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 183 | WideString CPWL_ComboBox::GetSelectedText() { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 184 | if (m_pEdit) |
| 185 | return m_pEdit->GetSelectedText(); |
| 186 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 187 | return WideString(); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 190 | void CPWL_ComboBox::ReplaceSelection(const WideString& text) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 191 | if (m_pEdit) |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 192 | m_pEdit->ReplaceSelection(text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 195 | WideString CPWL_ComboBox::GetText() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 196 | if (m_pEdit) { |
| 197 | return m_pEdit->GetText(); |
| 198 | } |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 199 | return WideString(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 202 | void CPWL_ComboBox::SetText(const WideString& text) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | if (m_pEdit) |
| 204 | m_pEdit->SetText(text); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 207 | void CPWL_ComboBox::AddString(const WideString& str) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 208 | if (m_pList) |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 209 | m_pList->AddString(str); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 212 | int32_t CPWL_ComboBox::GetSelect() const { |
| 213 | return m_nSelectItem; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | void CPWL_ComboBox::SetSelect(int32_t nItemIndex) { |
| 217 | if (m_pList) |
| 218 | m_pList->Select(nItemIndex); |
| 219 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 220 | m_pEdit->SetText(m_pList->GetText()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 221 | m_nSelectItem = nItemIndex; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 224 | void CPWL_ComboBox::SetEditSelection(int32_t nStartChar, int32_t nEndChar) { |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 225 | if (m_pEdit) |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 226 | m_pEdit->SetSelection(nStartChar, nEndChar); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 229 | void CPWL_ComboBox::GetEditSelection(int32_t& nStartChar, |
| 230 | int32_t& nEndChar) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 231 | nStartChar = -1; |
| 232 | nEndChar = -1; |
| 233 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 234 | if (m_pEdit) |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame] | 235 | m_pEdit->GetSelection(nStartChar, nEndChar); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Diana Gage | 22bf7a5 | 2017-07-21 11:33:18 -0700 | [diff] [blame] | 238 | void CPWL_ComboBox::ClearSelection() { |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 239 | if (m_pEdit) |
Diana Gage | 22bf7a5 | 2017-07-21 11:33:18 -0700 | [diff] [blame] | 240 | m_pEdit->ClearSelection(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 243 | void CPWL_ComboBox::CreateChildWnd(const CreateParams& cp) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | CreateEdit(cp); |
| 245 | CreateButton(cp); |
| 246 | CreateListBox(cp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 249 | void CPWL_ComboBox::CreateEdit(const CreateParams& cp) { |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 250 | if (m_pEdit) |
| 251 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 252 | |
Dan Sinclair | 0fdd1ae | 2017-07-05 16:00:48 -0400 | [diff] [blame] | 253 | m_pEdit = new CPWL_Edit(); |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 254 | m_pEdit->AttachFFLData(m_pFormFiller.Get()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 255 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 256 | CreateParams ecp = cp; |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 257 | ecp.pParentWnd = this; |
| 258 | ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | |
| 259 | PES_AUTOSCROLL | PES_UNDO; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 260 | |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 261 | if (HasFlag(PWS_AUTOFONTSIZE)) |
| 262 | ecp.dwFlags |= PWS_AUTOFONTSIZE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 263 | |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 264 | if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 265 | ecp.dwFlags |= PWS_READONLY; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 266 | |
Lei Zhang | d24236a | 2017-06-29 18:28:58 -0700 | [diff] [blame] | 267 | ecp.rcRectWnd = CFX_FloatRect(); |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 268 | ecp.dwBorderWidth = 0; |
| 269 | ecp.nBorderStyle = BorderStyle::SOLID; |
| 270 | m_pEdit->Create(ecp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 273 | void CPWL_ComboBox::CreateButton(const CreateParams& cp) { |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 274 | if (m_pButton) |
| 275 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 276 | |
Tom Sepez | 45b9ae1 | 2017-05-18 08:34:03 -0700 | [diff] [blame] | 277 | m_pButton = new CPWL_CBButton; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 278 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 279 | CreateParams bcp = cp; |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 280 | bcp.pParentWnd = this; |
| 281 | bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND; |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame^] | 282 | bcp.sBackgroundColor = CFX_Color(CFX_Color::kRGB, 220.0f / 255.0f, |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 283 | 220.0f / 255.0f, 220.0f / 255.0f); |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 284 | bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; |
| 285 | bcp.dwBorderWidth = 2; |
| 286 | bcp.nBorderStyle = BorderStyle::BEVELED; |
| 287 | bcp.eCursorType = FXCT_ARROW; |
| 288 | m_pButton->Create(bcp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 291 | void CPWL_ComboBox::CreateListBox(const CreateParams& cp) { |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 292 | if (m_pList) |
| 293 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 294 | |
Tom Sepez | 45b9ae1 | 2017-05-18 08:34:03 -0700 | [diff] [blame] | 295 | m_pList = new CPWL_CBListBox(); |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 296 | m_pList->AttachFFLData(m_pFormFiller.Get()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 297 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 298 | CreateParams lcp = cp; |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 299 | lcp.pParentWnd = this; |
| 300 | lcp.dwFlags = |
| 301 | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL; |
| 302 | lcp.nBorderStyle = BorderStyle::SOLID; |
| 303 | lcp.dwBorderWidth = 1; |
| 304 | lcp.eCursorType = FXCT_ARROW; |
Lei Zhang | d24236a | 2017-06-29 18:28:58 -0700 | [diff] [blame] | 305 | lcp.rcRectWnd = CFX_FloatRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 306 | |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 307 | if (cp.dwFlags & PWS_AUTOFONTSIZE) |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 308 | lcp.fFontSize = kDefaultFontSize; |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 309 | else |
| 310 | lcp.fFontSize = cp.fFontSize; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 311 | |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame^] | 312 | if (cp.sBorderColor.nColorType == CFX_Color::kTransparent) |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 313 | lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; |
| 314 | |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame^] | 315 | if (cp.sBackgroundColor.nColorType == CFX_Color::kTransparent) |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 316 | lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; |
| 317 | |
| 318 | m_pList->Create(lcp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 321 | bool CPWL_ComboBox::RePosChildWnd() { |
| 322 | ObservedPtr thisObserved(this); |
| 323 | |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 324 | const CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 325 | if (m_bPopup) { |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 326 | const float fOldWindowHeight = m_rcOldWindow.Height(); |
| 327 | const float fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2; |
| 328 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 329 | CFX_FloatRect rcList = CPWL_Wnd::GetWindowRect(); |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 330 | CFX_FloatRect rcButton = rcClient; |
| 331 | rcButton.left = |
Dan Sinclair | 951b111 | 2017-10-02 10:38:55 -0400 | [diff] [blame] | 332 | std::max(rcButton.right - kDefaultButtonWidth, rcClient.left); |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 333 | CFX_FloatRect rcEdit = rcClient; |
| 334 | rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left); |
| 335 | if (m_bBottom) { |
| 336 | rcButton.bottom = rcButton.top - fOldClientHeight; |
| 337 | rcEdit.bottom = rcEdit.top - fOldClientHeight; |
| 338 | rcList.top -= fOldWindowHeight; |
| 339 | } else { |
| 340 | rcButton.top = rcButton.bottom + fOldClientHeight; |
| 341 | rcEdit.top = rcEdit.bottom + fOldClientHeight; |
| 342 | rcList.bottom += fOldWindowHeight; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 343 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 344 | |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 345 | if (m_pButton) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 346 | m_pButton->Move(rcButton, true, false); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 347 | if (!thisObserved) |
| 348 | return false; |
| 349 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 350 | |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 351 | if (m_pEdit) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 352 | m_pEdit->Move(rcEdit, true, false); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 353 | if (!thisObserved) |
| 354 | return false; |
| 355 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 356 | |
| 357 | if (m_pList) { |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 358 | if (!m_pList->SetVisible(true) || !thisObserved) |
| 359 | return false; |
| 360 | |
| 361 | if (!m_pList->Move(rcList, true, false) || !thisObserved) |
| 362 | return false; |
| 363 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 364 | m_pList->ScrollToListItem(m_nSelectItem); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 365 | if (!thisObserved) |
| 366 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 367 | } |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 368 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 369 | } |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 370 | |
| 371 | CFX_FloatRect rcButton = rcClient; |
Dan Sinclair | 951b111 | 2017-10-02 10:38:55 -0400 | [diff] [blame] | 372 | rcButton.left = std::max(rcButton.right - kDefaultButtonWidth, rcClient.left); |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 373 | |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 374 | if (m_pButton) { |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 375 | m_pButton->Move(rcButton, true, false); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 376 | if (!thisObserved) |
| 377 | return false; |
| 378 | } |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 379 | |
| 380 | CFX_FloatRect rcEdit = rcClient; |
| 381 | rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left); |
| 382 | |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 383 | if (m_pEdit) { |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 384 | m_pEdit->Move(rcEdit, true, false); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 385 | if (!thisObserved) |
| 386 | return false; |
| 387 | } |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 388 | |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 389 | if (m_pList) { |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 390 | m_pList->SetVisible(false); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 391 | if (!thisObserved) |
| 392 | return false; |
| 393 | } |
| 394 | |
| 395 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 398 | void CPWL_ComboBox::SelectAll() { |
| 399 | if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 400 | m_pEdit->SelectAll(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 403 | CFX_FloatRect CPWL_ComboBox::GetFocusRect() const { |
| 404 | return CFX_FloatRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 407 | bool CPWL_ComboBox::SetPopup(bool bPopup) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 408 | if (!m_pList) |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 409 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 410 | if (bPopup == m_bPopup) |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 411 | return true; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 412 | float fListHeight = m_pList->GetContentRect().Height(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 413 | if (!IsFloatBigger(fListHeight, 0.0f)) |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 414 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 415 | |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 416 | if (!bPopup) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 417 | m_bPopup = bPopup; |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 418 | return Move(m_rcOldWindow, true, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 419 | } |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 420 | |
| 421 | if (!m_pFillerNotify) |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 422 | return true; |
| 423 | |
| 424 | ObservedPtr thisObserved(this); |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 425 | |
| 426 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 427 | if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), 0)) |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 428 | return !!thisObserved; |
| 429 | if (!thisObserved) |
| 430 | return false; |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 431 | #endif // PDF_ENABLE_XFA |
| 432 | |
| 433 | float fBorderWidth = m_pList->GetBorderWidth() * 2; |
| 434 | float fPopupMin = 0.0f; |
| 435 | if (m_pList->GetCount() > 3) |
| 436 | fPopupMin = m_pList->GetFirstHeight() * 3 + fBorderWidth; |
| 437 | float fPopupMax = fListHeight + fBorderWidth; |
| 438 | |
| 439 | bool bBottom; |
| 440 | float fPopupRet; |
| 441 | m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax, |
| 442 | &bBottom, &fPopupRet); |
| 443 | if (!IsFloatBigger(fPopupRet, 0.0f)) |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 444 | return true; |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 445 | |
| 446 | m_rcOldWindow = CPWL_Wnd::GetWindowRect(); |
| 447 | m_bPopup = bPopup; |
| 448 | m_bBottom = bBottom; |
| 449 | |
| 450 | CFX_FloatRect rcWindow = m_rcOldWindow; |
| 451 | if (bBottom) |
| 452 | rcWindow.bottom -= fPopupRet; |
| 453 | else |
| 454 | rcWindow.top += fPopupRet; |
| 455 | |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 456 | if (!Move(rcWindow, true, true)) |
| 457 | return false; |
| 458 | |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 459 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 460 | m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), 0); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 461 | if (!thisObserved) |
| 462 | return false; |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 463 | #endif // PDF_ENABLE_XFA |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 464 | |
| 465 | return !!thisObserved; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | } |
| 467 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 468 | bool CPWL_ComboBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 469 | if (!m_pList) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 470 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 471 | if (!m_pEdit) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 472 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | |
| 474 | m_nSelectItem = -1; |
| 475 | |
| 476 | switch (nChar) { |
| 477 | case FWL_VKEY_Up: |
| 478 | if (m_pList->GetCurSel() > 0) { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 479 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 480 | if (m_pFillerNotify) { |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 481 | if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 482 | return false; |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 483 | if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 484 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 485 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 486 | #endif // PDF_ENABLE_XFA |
Dan Sinclair | 07dbf43 | 2017-07-06 11:47:26 -0400 | [diff] [blame] | 487 | if (m_pList->IsMovementKey(nChar)) { |
| 488 | if (m_pList->OnMovementKeyDown(nChar, nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 489 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 490 | SetSelectText(); |
| 491 | } |
| 492 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 493 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 494 | case FWL_VKEY_Down: |
| 495 | if (m_pList->GetCurSel() < m_pList->GetCount() - 1) { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 496 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 497 | if (m_pFillerNotify) { |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 498 | if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 499 | return false; |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 500 | if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 501 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 502 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 503 | #endif // PDF_ENABLE_XFA |
Dan Sinclair | 07dbf43 | 2017-07-06 11:47:26 -0400 | [diff] [blame] | 504 | if (m_pList->IsMovementKey(nChar)) { |
| 505 | if (m_pList->OnMovementKeyDown(nChar, nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 506 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 507 | SetSelectText(); |
| 508 | } |
| 509 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 510 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 514 | return m_pEdit->OnKeyDown(nChar, nFlag); |
| 515 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 516 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 517 | } |
| 518 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 519 | bool CPWL_ComboBox::OnChar(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 520 | if (!m_pList) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 521 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 522 | |
| 523 | if (!m_pEdit) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 524 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 525 | |
| 526 | m_nSelectItem = -1; |
| 527 | if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 528 | return m_pEdit->OnChar(nChar, nFlag); |
| 529 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 530 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 531 | if (m_pFillerNotify) { |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 532 | if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 533 | return false; |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 534 | if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 535 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 536 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 537 | #endif // PDF_ENABLE_XFA |
Dan Sinclair | 16fea94 | 2017-07-06 11:56:37 -0400 | [diff] [blame] | 538 | if (!m_pList->IsChar(nChar, nFlag)) |
| 539 | return false; |
| 540 | return m_pList->OnCharNotify(nChar, nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 543 | void CPWL_ComboBox::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) { |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 544 | if (child == m_pButton) { |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 545 | SetPopup(!m_bPopup); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 546 | // Note, |this| may no longer be viable at this point. If more work needs to |
| 547 | // be done, check the return value of SetPopup(). |
| 548 | } |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 549 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 551 | void CPWL_ComboBox::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) { |
| 552 | if (!m_pEdit || !m_pList || child != m_pList) |
| 553 | return; |
| 554 | |
| 555 | SetSelectText(); |
| 556 | SelectAll(); |
| 557 | m_pEdit->SetFocus(); |
| 558 | SetPopup(false); |
Henrique Nakashima | 55469ae | 2017-10-04 11:08:45 -0400 | [diff] [blame] | 559 | // Note, |this| may no longer be viable at this point. If more work needs to |
| 560 | // be done, check the return value of SetPopup(). |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | } |
| 562 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 563 | bool CPWL_ComboBox::IsPopup() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 564 | return m_bPopup; |
| 565 | } |
| 566 | |
| 567 | void CPWL_ComboBox::SetSelectText() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 568 | m_pEdit->SelectAll(); |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 569 | m_pEdit->ReplaceSel(m_pList->GetText()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 570 | m_pEdit->SelectAll(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 571 | m_nSelectItem = m_pList->GetCurSel(); |
| 572 | } |
| 573 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 574 | void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) { |
| 575 | m_pFillerNotify = pNotify; |
| 576 | |
| 577 | if (m_pEdit) |
| 578 | m_pEdit->SetFillerNotify(pNotify); |
| 579 | |
| 580 | if (m_pList) |
| 581 | m_pList->SetFillerNotify(pNotify); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 582 | } |