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