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