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