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