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" |
Lei Zhang | 633a3b7 | 2017-06-02 15:27:22 -0700 | [diff] [blame] | 18 | #include "fpdfsdk/pdfwindow/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, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 97 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
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 | |
| 121 | pDevice->DrawPath(&path, pUser2Device, nullptr, |
| 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 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 187 | CFX_WideString CPWL_ComboBox::GetText() const { |
| 188 | if (m_pEdit) { |
| 189 | return m_pEdit->GetText(); |
| 190 | } |
| 191 | return CFX_WideString(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 192 | } |
| 193 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 194 | void CPWL_ComboBox::SetText(const CFX_WideString& text) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 195 | if (m_pEdit) |
| 196 | m_pEdit->SetText(text); |
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::AddString(const CFX_WideString& str) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | if (m_pList) |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 201 | m_pList->AddString(str); |
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 | int32_t CPWL_ComboBox::GetSelect() const { |
| 205 | return m_nSelectItem; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 208 | void CPWL_ComboBox::SetSelect(int32_t nItemIndex) { |
| 209 | if (m_pList) |
| 210 | m_pList->Select(nItemIndex); |
| 211 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 212 | m_pEdit->SetText(m_pList->GetText()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | m_nSelectItem = nItemIndex; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame^] | 216 | void CPWL_ComboBox::SetEditSelection(int32_t nStartChar, int32_t nEndChar) { |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 217 | if (m_pEdit) |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame^] | 218 | m_pEdit->SetSelection(nStartChar, nEndChar); |
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::GetEditSelection(int32_t& nStartChar, |
| 222 | int32_t& nEndChar) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 223 | nStartChar = -1; |
| 224 | nEndChar = -1; |
| 225 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 226 | if (m_pEdit) |
Diana Gage | 4d02e90 | 2017-07-20 17:20:31 -0700 | [diff] [blame^] | 227 | m_pEdit->GetSelection(nStartChar, nEndChar); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 230 | void CPWL_ComboBox::Clear() { |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 231 | if (m_pEdit) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | m_pEdit->Clear(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 235 | void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) { |
| 236 | CreateEdit(cp); |
| 237 | CreateButton(cp); |
| 238 | CreateListBox(cp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 241 | void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) { |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 242 | if (m_pEdit) |
| 243 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | |
Dan Sinclair | 0fdd1ae | 2017-07-05 16:00:48 -0400 | [diff] [blame] | 245 | m_pEdit = new CPWL_Edit(); |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 246 | m_pEdit->AttachFFLData(m_pFormFiller.Get()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 247 | |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 248 | PWL_CREATEPARAM ecp = cp; |
| 249 | ecp.pParentWnd = this; |
| 250 | ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | |
| 251 | PES_AUTOSCROLL | PES_UNDO; |
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 | if (HasFlag(PWS_AUTOFONTSIZE)) |
| 254 | ecp.dwFlags |= PWS_AUTOFONTSIZE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 255 | |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 256 | if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 257 | ecp.dwFlags |= PWS_READONLY; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 258 | |
Lei Zhang | d24236a | 2017-06-29 18:28:58 -0700 | [diff] [blame] | 259 | ecp.rcRectWnd = CFX_FloatRect(); |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 260 | ecp.dwBorderWidth = 0; |
| 261 | ecp.nBorderStyle = BorderStyle::SOLID; |
| 262 | m_pEdit->Create(ecp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 265 | void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) { |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 266 | if (m_pButton) |
| 267 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 268 | |
Tom Sepez | 45b9ae1 | 2017-05-18 08:34:03 -0700 | [diff] [blame] | 269 | m_pButton = new CPWL_CBButton; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 270 | |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 271 | PWL_CREATEPARAM bcp = cp; |
| 272 | bcp.pParentWnd = this; |
| 273 | bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND; |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 274 | bcp.sBackgroundColor = CFX_Color(COLORTYPE_RGB, 220.0f / 255.0f, |
| 275 | 220.0f / 255.0f, 220.0f / 255.0f); |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 276 | bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; |
| 277 | bcp.dwBorderWidth = 2; |
| 278 | bcp.nBorderStyle = BorderStyle::BEVELED; |
| 279 | bcp.eCursorType = FXCT_ARROW; |
| 280 | m_pButton->Create(bcp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 283 | void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) { |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 284 | if (m_pList) |
| 285 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 286 | |
Tom Sepez | 45b9ae1 | 2017-05-18 08:34:03 -0700 | [diff] [blame] | 287 | m_pList = new CPWL_CBListBox(); |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 288 | m_pList->AttachFFLData(m_pFormFiller.Get()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 289 | |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 290 | PWL_CREATEPARAM lcp = cp; |
| 291 | lcp.pParentWnd = this; |
| 292 | lcp.dwFlags = |
| 293 | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL; |
| 294 | lcp.nBorderStyle = BorderStyle::SOLID; |
| 295 | lcp.dwBorderWidth = 1; |
| 296 | lcp.eCursorType = FXCT_ARROW; |
Lei Zhang | d24236a | 2017-06-29 18:28:58 -0700 | [diff] [blame] | 297 | lcp.rcRectWnd = CFX_FloatRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 298 | |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 299 | if (cp.dwFlags & PWS_AUTOFONTSIZE) |
Dan Sinclair | a9e2843 | 2017-07-05 14:18:14 -0400 | [diff] [blame] | 300 | lcp.fFontSize = kDefaultFontSize; |
Tom Sepez | b084c1f | 2017-05-12 14:04:06 -0700 | [diff] [blame] | 301 | else |
| 302 | lcp.fFontSize = cp.fFontSize; |
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.sBorderColor.nColorType == COLORTYPE_TRANSPARENT) |
| 305 | lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; |
| 306 | |
| 307 | if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT) |
| 308 | lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; |
| 309 | |
| 310 | m_pList->Create(lcp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | void CPWL_ComboBox::RePosChildWnd() { |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 314 | const CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 315 | if (m_bPopup) { |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 316 | const float fOldWindowHeight = m_rcOldWindow.Height(); |
| 317 | const float fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2; |
| 318 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 319 | CFX_FloatRect rcList = CPWL_Wnd::GetWindowRect(); |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 320 | CFX_FloatRect rcButton = rcClient; |
| 321 | rcButton.left = |
| 322 | std::max(rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH, rcClient.left); |
| 323 | CFX_FloatRect rcEdit = rcClient; |
| 324 | rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left); |
| 325 | if (m_bBottom) { |
| 326 | rcButton.bottom = rcButton.top - fOldClientHeight; |
| 327 | rcEdit.bottom = rcEdit.top - fOldClientHeight; |
| 328 | rcList.top -= fOldWindowHeight; |
| 329 | } else { |
| 330 | rcButton.top = rcButton.bottom + fOldClientHeight; |
| 331 | rcEdit.top = rcEdit.bottom + fOldClientHeight; |
| 332 | rcList.bottom += fOldWindowHeight; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 333 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 334 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 335 | if (m_pButton) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 336 | m_pButton->Move(rcButton, true, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 337 | |
| 338 | if (m_pEdit) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 339 | m_pEdit->Move(rcEdit, true, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 340 | |
| 341 | if (m_pList) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 342 | m_pList->SetVisible(true); |
| 343 | m_pList->Move(rcList, true, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 344 | m_pList->ScrollToListItem(m_nSelectItem); |
| 345 | } |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 346 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 347 | } |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 348 | |
| 349 | CFX_FloatRect rcButton = rcClient; |
| 350 | rcButton.left = |
| 351 | std::max(rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH, rcClient.left); |
| 352 | |
| 353 | if (m_pButton) |
| 354 | m_pButton->Move(rcButton, true, false); |
| 355 | |
| 356 | CFX_FloatRect rcEdit = rcClient; |
| 357 | rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left); |
| 358 | |
| 359 | if (m_pEdit) |
| 360 | m_pEdit->Move(rcEdit, true, false); |
| 361 | |
| 362 | if (m_pList) |
| 363 | m_pList->SetVisible(false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 366 | void CPWL_ComboBox::SelectAll() { |
| 367 | if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 368 | m_pEdit->SelectAll(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 371 | CFX_FloatRect CPWL_ComboBox::GetFocusRect() const { |
| 372 | return CFX_FloatRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 373 | } |
| 374 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 375 | void CPWL_ComboBox::SetPopup(bool bPopup) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 376 | if (!m_pList) |
| 377 | return; |
| 378 | if (bPopup == m_bPopup) |
| 379 | return; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 380 | float fListHeight = m_pList->GetContentRect().Height(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 381 | if (!IsFloatBigger(fListHeight, 0.0f)) |
| 382 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 383 | |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 384 | if (!bPopup) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 385 | m_bPopup = bPopup; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 386 | Move(m_rcOldWindow, true, true); |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 387 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 388 | } |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 389 | |
| 390 | if (!m_pFillerNotify) |
| 391 | return; |
| 392 | |
| 393 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 394 | if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), 0)) |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 395 | return; |
| 396 | #endif // PDF_ENABLE_XFA |
| 397 | |
| 398 | float fBorderWidth = m_pList->GetBorderWidth() * 2; |
| 399 | float fPopupMin = 0.0f; |
| 400 | if (m_pList->GetCount() > 3) |
| 401 | fPopupMin = m_pList->GetFirstHeight() * 3 + fBorderWidth; |
| 402 | float fPopupMax = fListHeight + fBorderWidth; |
| 403 | |
| 404 | bool bBottom; |
| 405 | float fPopupRet; |
| 406 | m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax, |
| 407 | &bBottom, &fPopupRet); |
| 408 | if (!IsFloatBigger(fPopupRet, 0.0f)) |
| 409 | return; |
| 410 | |
| 411 | m_rcOldWindow = CPWL_Wnd::GetWindowRect(); |
| 412 | m_bPopup = bPopup; |
| 413 | m_bBottom = bBottom; |
| 414 | |
| 415 | CFX_FloatRect rcWindow = m_rcOldWindow; |
| 416 | if (bBottom) |
| 417 | rcWindow.bottom -= fPopupRet; |
| 418 | else |
| 419 | rcWindow.top += fPopupRet; |
| 420 | |
| 421 | Move(rcWindow, true, true); |
| 422 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 423 | m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), 0); |
Lei Zhang | 7bef7c8 | 2017-05-31 23:52:00 -0700 | [diff] [blame] | 424 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 425 | } |
| 426 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 427 | bool CPWL_ComboBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | if (!m_pList) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 429 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 430 | if (!m_pEdit) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 431 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 432 | |
| 433 | m_nSelectItem = -1; |
| 434 | |
| 435 | switch (nChar) { |
| 436 | case FWL_VKEY_Up: |
| 437 | if (m_pList->GetCurSel() > 0) { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 438 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 439 | if (m_pFillerNotify) { |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 440 | if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 441 | return false; |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 442 | if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 443 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 444 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 445 | #endif // PDF_ENABLE_XFA |
Dan Sinclair | 07dbf43 | 2017-07-06 11:47:26 -0400 | [diff] [blame] | 446 | if (m_pList->IsMovementKey(nChar)) { |
| 447 | if (m_pList->OnMovementKeyDown(nChar, 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 | SetSelectText(); |
| 450 | } |
| 451 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 452 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 453 | case FWL_VKEY_Down: |
| 454 | if (m_pList->GetCurSel() < m_pList->GetCount() - 1) { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 455 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | if (m_pFillerNotify) { |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 457 | if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 458 | return false; |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 459 | if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 460 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 461 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 462 | #endif // PDF_ENABLE_XFA |
Dan Sinclair | 07dbf43 | 2017-07-06 11:47:26 -0400 | [diff] [blame] | 463 | if (m_pList->IsMovementKey(nChar)) { |
| 464 | if (m_pList->OnMovementKeyDown(nChar, 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 | SetSelectText(); |
| 467 | } |
| 468 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 469 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 473 | return m_pEdit->OnKeyDown(nChar, nFlag); |
| 474 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 475 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 476 | } |
| 477 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 478 | bool CPWL_ComboBox::OnChar(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | if (!m_pList) |
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 | if (!m_pEdit) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 483 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 484 | |
| 485 | m_nSelectItem = -1; |
| 486 | if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 487 | return m_pEdit->OnChar(nChar, nFlag); |
| 488 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 489 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 490 | if (m_pFillerNotify) { |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 491 | if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 492 | return false; |
Dan Sinclair | 5fe9808 | 2017-07-06 11:13:02 -0400 | [diff] [blame] | 493 | if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 494 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 495 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 496 | #endif // PDF_ENABLE_XFA |
Dan Sinclair | 16fea94 | 2017-07-06 11:56:37 -0400 | [diff] [blame] | 497 | if (!m_pList->IsChar(nChar, nFlag)) |
| 498 | return false; |
| 499 | return m_pList->OnCharNotify(nChar, nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 502 | void CPWL_ComboBox::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) { |
| 503 | if (child == m_pButton) |
| 504 | SetPopup(!m_bPopup); |
| 505 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 506 | |
Dan Sinclair | 7f6bec9 | 2017-07-05 14:13:16 -0400 | [diff] [blame] | 507 | void CPWL_ComboBox::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) { |
| 508 | if (!m_pEdit || !m_pList || child != m_pList) |
| 509 | return; |
| 510 | |
| 511 | SetSelectText(); |
| 512 | SelectAll(); |
| 513 | m_pEdit->SetFocus(); |
| 514 | SetPopup(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 515 | } |
| 516 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 517 | bool CPWL_ComboBox::IsPopup() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 518 | return m_bPopup; |
| 519 | } |
| 520 | |
| 521 | void CPWL_ComboBox::SetSelectText() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 522 | m_pEdit->SelectAll(); |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 523 | m_pEdit->ReplaceSel(m_pList->GetText()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 524 | m_pEdit->SelectAll(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 525 | m_nSelectItem = m_pList->GetCurSel(); |
| 526 | } |
| 527 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) { |
| 529 | m_pFillerNotify = pNotify; |
| 530 | |
| 531 | if (m_pEdit) |
| 532 | m_pEdit->SetFillerNotify(pNotify); |
| 533 | |
| 534 | if (m_pList) |
| 535 | m_pList->SetFillerNotify(pNotify); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 536 | } |