blob: b6c8d2f9218f494f745381a596de3e635f2a0154 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dan sinclair89e904b2016-03-23 19:29:15 -04007#include "fpdfsdk/pdfwindow/PWL_ComboBox.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
dsinclair74a34fc2016-09-29 16:41:42 -07009#include "core/fxge/cfx_pathdata.h"
10#include "core/fxge/cfx_renderdevice.h"
dsinclair0bb385b2016-09-29 17:03:59 -070011#include "fpdfsdk/fxedit/fxet_list.h"
dan sinclair89e904b2016-03-23 19:29:15 -040012#include "fpdfsdk/pdfwindow/PWL_Edit.h"
13#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h"
14#include "fpdfsdk/pdfwindow/PWL_ListBox.h"
15#include "fpdfsdk/pdfwindow/PWL_Utils.h"
16#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080017#include "public/fpdf_fwlevent.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019#define PWLCB_DEFAULTFONTSIZE 12.0f
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Dan Sinclairf528eee2017-02-14 11:52:07 -050021bool CPWL_CBListBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022 CPWL_Wnd::OnLButtonUp(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023
dsinclair36177512016-07-19 10:16:10 -070024 if (!m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -070025 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026
dsinclair36177512016-07-19 10:16:10 -070027 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -070028 m_bMouseDown = false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070029
dsinclair36177512016-07-19 10:16:10 -070030 if (!ClientHitTest(point))
tsepez4cf55152016-11-02 14:37:54 -070031 return true;
dsinclair36177512016-07-19 10:16:10 -070032 if (CPWL_Wnd* pParent = GetParentWindow())
33 pParent->OnNotify(this, PNM_LBUTTONUP, 0, PWL_MAKEDWORD(point.x, point.y));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034
tsepez4cf55152016-11-02 14:37:54 -070035 bool bExit = false;
36 OnNotifySelChanged(false, bExit, nFlag);
dsinclair36177512016-07-19 10:16:10 -070037
38 return !bExit;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039}
40
tsepez4cf55152016-11-02 14:37:54 -070041bool CPWL_CBListBox::OnKeyDownWithExit(uint16_t nChar,
42 bool& bExit,
43 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044 switch (nChar) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 case FWL_VKEY_Up:
46 case FWL_VKEY_Down:
47 case FWL_VKEY_Home:
48 case FWL_VKEY_Left:
49 case FWL_VKEY_End:
50 case FWL_VKEY_Right:
51 break;
dsinclair36177512016-07-19 10:16:10 -070052 default:
tsepez4cf55152016-11-02 14:37:54 -070053 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070055
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056 switch (nChar) {
57 case FWL_VKEY_Up:
58 m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
59 break;
60 case FWL_VKEY_Down:
61 m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
62 break;
63 case FWL_VKEY_Home:
64 m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
65 break;
66 case FWL_VKEY_Left:
67 m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
68 break;
69 case FWL_VKEY_End:
70 m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
71 break;
72 case FWL_VKEY_Right:
73 m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
74 break;
75 case FWL_VKEY_Delete:
76 break;
77 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078
tsepez4cf55152016-11-02 14:37:54 -070079 OnNotifySelChanged(true, bExit, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080
tsepez4cf55152016-11-02 14:37:54 -070081 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082}
83
tsepez4cf55152016-11-02 14:37:54 -070084bool CPWL_CBListBox::OnCharWithExit(uint16_t nChar,
85 bool& bExit,
86 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 if (!m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)))
tsepez4cf55152016-11-02 14:37:54 -070088 return false;
dsinclair36177512016-07-19 10:16:10 -070089 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow())
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 pComboBox->SetSelectText();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091
tsepez4cf55152016-11-02 14:37:54 -070092 OnNotifySelChanged(true, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093
tsepez4cf55152016-11-02 14:37:54 -070094 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095}
96
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097void CPWL_CBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
98 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070099
Tom Sepez281a9ea2016-02-26 14:24:28 -0800100 CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700101
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 if (IsVisible() && !rectWnd.IsEmpty()) {
103 CFX_ByteTextBuf sButton;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700104
Dan Sinclairf528eee2017-02-14 11:52:07 -0500105 CFX_PointF ptCenter = GetCenterPoint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700106
Dan Sinclairf528eee2017-02-14 11:52:07 -0500107 CFX_PointF pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,
108 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
109 CFX_PointF pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,
110 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
111 CFX_PointF pt3(ptCenter.x,
112 ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114 if (IsFloatBigger(rectWnd.right - rectWnd.left,
115 PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) &&
116 IsFloatBigger(rectWnd.top - rectWnd.bottom,
117 PWL_CBBUTTON_TRIANGLE_HALFLEN)) {
118 sButton << "0 g\n";
119 sButton << pt1.x << " " << pt1.y << " m\n";
120 sButton << pt2.x << " " << pt2.y << " l\n";
121 sButton << pt3.x << " " << pt3.y << " l\n";
122 sButton << pt1.x << " " << pt1.y << " l f\n";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124 sAppStream << "q\n" << sButton << "Q\n";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700125 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700127}
128
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800130 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132
Tom Sepez281a9ea2016-02-26 14:24:28 -0800133 CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 if (IsVisible() && !rectWnd.IsEmpty()) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500136 CFX_PointF ptCenter = GetCenterPoint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137
Dan Sinclairf528eee2017-02-14 11:52:07 -0500138 CFX_PointF pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,
139 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
140 CFX_PointF pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,
141 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
142 CFX_PointF pt3(ptCenter.x,
143 ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 if (IsFloatBigger(rectWnd.right - rectWnd.left,
146 PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) &&
147 IsFloatBigger(rectWnd.top - rectWnd.bottom,
148 PWL_CBBUTTON_TRIANGLE_HALFLEN)) {
149 CFX_PathData path;
dan sinclairb147e072017-02-22 19:56:15 -0500150 path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false);
151 path.AppendPoint(pt2, FXPT_TYPE::LineTo, false);
152 path.AppendPoint(pt3, FXPT_TYPE::LineTo, false);
153 path.AppendPoint(pt1, FXPT_TYPE::LineTo, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700154
thestig1cd352e2016-06-07 17:53:06 -0700155 pDevice->DrawPath(&path, pUser2Device, nullptr,
Dan Sinclairfc54e052017-02-23 09:59:05 -0500156 PWL_DEFAULT_BLACKCOLOR.ToFXColor(GetTransparency()), 0,
157 FXFILL_ALTERNATE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700158 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700160}
161
Dan Sinclairf528eee2017-02-14 11:52:07 -0500162bool CPWL_CBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700164
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 SetCapture();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700166
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 if (CPWL_Wnd* pParent = GetParentWindow()) {
168 pParent->OnNotify(this, PNM_LBUTTONDOWN, 0,
169 PWL_MAKEDWORD(point.x, point.y));
170 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700171
tsepez4cf55152016-11-02 14:37:54 -0700172 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700173}
174
Dan Sinclairf528eee2017-02-14 11:52:07 -0500175bool CPWL_CBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 CPWL_Wnd::OnLButtonUp(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700177
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 ReleaseCapture();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700179
tsepez4cf55152016-11-02 14:37:54 -0700180 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700181}
182
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183CPWL_ComboBox::CPWL_ComboBox()
Tom Sepez45b9ae12017-05-18 08:34:03 -0700184 : m_pEdit(nullptr),
185 m_pButton(nullptr),
186 m_pList(nullptr),
187 m_bPopup(false),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 m_nPopupWhere(0),
189 m_nSelectItem(-1),
thestig1cd352e2016-06-07 17:53:06 -0700190 m_pFillerNotify(nullptr) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191
Tom Sepezb084c1f2017-05-12 14:04:06 -0700192CPWL_ComboBox::~CPWL_ComboBox() {}
193
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194CFX_ByteString CPWL_ComboBox::GetClassName() const {
195 return "CPWL_ComboBox";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700196}
197
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM& cp) {
199 cp.dwFlags &= ~PWS_HSCROLL;
200 cp.dwFlags &= ~PWS_VSCROLL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201}
202
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203void CPWL_ComboBox::SetFocus() {
204 if (m_pEdit)
205 m_pEdit->SetFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700206}
207
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208void CPWL_ComboBox::KillFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700209 SetPopup(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 CPWL_Wnd::KillFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211}
212
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213CFX_WideString CPWL_ComboBox::GetText() const {
214 if (m_pEdit) {
215 return m_pEdit->GetText();
216 }
217 return CFX_WideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700218}
219
tsepez067990c2016-09-13 06:46:40 -0700220void CPWL_ComboBox::SetText(const CFX_WideString& text) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221 if (m_pEdit)
222 m_pEdit->SetText(text);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700223}
224
tsepez067990c2016-09-13 06:46:40 -0700225void CPWL_ComboBox::AddString(const CFX_WideString& str) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226 if (m_pList)
Dan Sinclair3ebd1212016-03-09 09:59:23 -0500227 m_pList->AddString(str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700228}
229
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230int32_t CPWL_ComboBox::GetSelect() const {
231 return m_nSelectItem;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700232}
233
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234void CPWL_ComboBox::SetSelect(int32_t nItemIndex) {
235 if (m_pList)
236 m_pList->Select(nItemIndex);
237
tsepez067990c2016-09-13 06:46:40 -0700238 m_pEdit->SetText(m_pList->GetText());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239 m_nSelectItem = nItemIndex;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700240}
241
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242void CPWL_ComboBox::SetEditSel(int32_t nStartChar, int32_t nEndChar) {
tsepez067990c2016-09-13 06:46:40 -0700243 if (m_pEdit)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 m_pEdit->SetSel(nStartChar, nEndChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245}
246
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247void CPWL_ComboBox::GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const {
248 nStartChar = -1;
249 nEndChar = -1;
250
tsepez067990c2016-09-13 06:46:40 -0700251 if (m_pEdit)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 m_pEdit->GetSel(nStartChar, nEndChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700253}
254
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255void CPWL_ComboBox::Clear() {
tsepez067990c2016-09-13 06:46:40 -0700256 if (m_pEdit)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257 m_pEdit->Clear();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700258}
259
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) {
261 CreateEdit(cp);
262 CreateButton(cp);
263 CreateListBox(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700264}
265
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) {
Tom Sepezb084c1f2017-05-12 14:04:06 -0700267 if (m_pEdit)
268 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269
Tom Sepez45b9ae12017-05-18 08:34:03 -0700270 m_pEdit = new CPWL_CBEdit();
Tom Sepezcc205132017-05-16 14:01:47 -0700271 m_pEdit->AttachFFLData(m_pFormFiller.Get());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272
Tom Sepezb084c1f2017-05-12 14:04:06 -0700273 PWL_CREATEPARAM ecp = cp;
274 ecp.pParentWnd = this;
275 ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER |
276 PES_AUTOSCROLL | PES_UNDO;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277
Tom Sepezb084c1f2017-05-12 14:04:06 -0700278 if (HasFlag(PWS_AUTOFONTSIZE))
279 ecp.dwFlags |= PWS_AUTOFONTSIZE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280
Tom Sepezb084c1f2017-05-12 14:04:06 -0700281 if (!HasFlag(PCBS_ALLOWCUSTOMTEXT))
282 ecp.dwFlags |= PWS_READONLY;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283
Tom Sepezb084c1f2017-05-12 14:04:06 -0700284 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
285 ecp.dwBorderWidth = 0;
286 ecp.nBorderStyle = BorderStyle::SOLID;
287 m_pEdit->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700288}
289
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) {
Tom Sepezb084c1f2017-05-12 14:04:06 -0700291 if (m_pButton)
292 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700293
Tom Sepez45b9ae12017-05-18 08:34:03 -0700294 m_pButton = new CPWL_CBButton;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700295
Tom Sepezb084c1f2017-05-12 14:04:06 -0700296 PWL_CREATEPARAM bcp = cp;
297 bcp.pParentWnd = this;
298 bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND;
299 bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR;
300 bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
301 bcp.dwBorderWidth = 2;
302 bcp.nBorderStyle = BorderStyle::BEVELED;
303 bcp.eCursorType = FXCT_ARROW;
304 m_pButton->Create(bcp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700305}
306
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) {
Tom Sepezb084c1f2017-05-12 14:04:06 -0700308 if (m_pList)
309 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700310
Tom Sepez45b9ae12017-05-18 08:34:03 -0700311 m_pList = new CPWL_CBListBox();
Tom Sepezcc205132017-05-16 14:01:47 -0700312 m_pList->AttachFFLData(m_pFormFiller.Get());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700313
Tom Sepezb084c1f2017-05-12 14:04:06 -0700314 PWL_CREATEPARAM lcp = cp;
315 lcp.pParentWnd = this;
316 lcp.dwFlags =
317 PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL;
318 lcp.nBorderStyle = BorderStyle::SOLID;
319 lcp.dwBorderWidth = 1;
320 lcp.eCursorType = FXCT_ARROW;
321 lcp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322
Tom Sepezb084c1f2017-05-12 14:04:06 -0700323 if (cp.dwFlags & PWS_AUTOFONTSIZE)
324 lcp.fFontSize = PWLCB_DEFAULTFONTSIZE;
325 else
326 lcp.fFontSize = cp.fFontSize;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327
Tom Sepezb084c1f2017-05-12 14:04:06 -0700328 if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT)
329 lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
330
331 if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT)
332 lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
333
334 m_pList->Create(lcp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335}
336
337void CPWL_ComboBox::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800338 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700339
340 if (m_bPopup) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800341 CFX_FloatRect rclient = GetClientRect();
342 CFX_FloatRect rcButton = rclient;
343 CFX_FloatRect rcEdit = rcClient;
344 CFX_FloatRect rcList = CPWL_Wnd::GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345
Dan Sinclair05df0752017-03-14 14:43:42 -0400346 float fOldWindowHeight = m_rcOldWindow.Height();
347 float fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348
349 switch (m_nPopupWhere) {
350 case 0:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700351 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700352
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353 if (rcButton.left < rclient.left)
354 rcButton.left = rclient.left;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700355
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356 rcButton.bottom = rcButton.top - fOldClientHeight;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700357
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700358 rcEdit.right = rcButton.left - 1.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700359
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 if (rcEdit.left < rclient.left)
361 rcEdit.left = rclient.left;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700362
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700363 if (rcEdit.right < rcEdit.left)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 rcEdit.right = rcEdit.left;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700365
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 rcEdit.bottom = rcEdit.top - fOldClientHeight;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368 rcList.top -= fOldWindowHeight;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700369
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700370 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371 case 1:
372 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
373
374 if (rcButton.left < rclient.left)
375 rcButton.left = rclient.left;
376
377 rcButton.top = rcButton.bottom + fOldClientHeight;
378
379 rcEdit.right = rcButton.left - 1.0f;
380
381 if (rcEdit.left < rclient.left)
382 rcEdit.left = rclient.left;
383
384 if (rcEdit.right < rcEdit.left)
385 rcEdit.right = rcEdit.left;
386
387 rcEdit.top = rcEdit.bottom + fOldClientHeight;
388
389 rcList.bottom += fOldWindowHeight;
390
391 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700392 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700393
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394 if (m_pButton)
tsepez4cf55152016-11-02 14:37:54 -0700395 m_pButton->Move(rcButton, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396
397 if (m_pEdit)
tsepez4cf55152016-11-02 14:37:54 -0700398 m_pEdit->Move(rcEdit, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399
400 if (m_pList) {
tsepez4cf55152016-11-02 14:37:54 -0700401 m_pList->SetVisible(true);
402 m_pList->Move(rcList, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700403 m_pList->ScrollToListItem(m_nSelectItem);
404 }
405 } else {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800406 CFX_FloatRect rcButton = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407
408 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
409
410 if (rcButton.left < rcClient.left)
411 rcButton.left = rcClient.left;
412
413 if (m_pButton)
tsepez4cf55152016-11-02 14:37:54 -0700414 m_pButton->Move(rcButton, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415
Tom Sepez281a9ea2016-02-26 14:24:28 -0800416 CFX_FloatRect rcEdit = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 rcEdit.right = rcButton.left - 1.0f;
418
419 if (rcEdit.left < rcClient.left)
420 rcEdit.left = rcClient.left;
421
422 if (rcEdit.right < rcEdit.left)
423 rcEdit.right = rcEdit.left;
424
425 if (m_pEdit)
tsepez4cf55152016-11-02 14:37:54 -0700426 m_pEdit->Move(rcEdit, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427
428 if (m_pList)
tsepez4cf55152016-11-02 14:37:54 -0700429 m_pList->SetVisible(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700431}
432
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433void CPWL_ComboBox::SelectAll() {
434 if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT))
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700435 m_pEdit->SelectAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700436}
437
Tom Sepez281a9ea2016-02-26 14:24:28 -0800438CFX_FloatRect CPWL_ComboBox::GetFocusRect() const {
439 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700440}
441
tsepez4cf55152016-11-02 14:37:54 -0700442void CPWL_ComboBox::SetPopup(bool bPopup) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443 if (!m_pList)
444 return;
445 if (bPopup == m_bPopup)
446 return;
Dan Sinclair05df0752017-03-14 14:43:42 -0400447 float fListHeight = m_pList->GetContentRect().Height();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448 if (!IsFloatBigger(fListHeight, 0.0f))
449 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700450
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 if (bPopup) {
452 if (m_pFillerNotify) {
Tom Sepez51da0932015-11-25 16:05:49 -0800453#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700454 bool bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, 0);
456 if (bExit)
457 return;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800458#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459 int32_t nWhere = 0;
Dan Sinclair05df0752017-03-14 14:43:42 -0400460 float fPopupRet = 0.0f;
461 float fPopupMin = 0.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 if (m_pList->GetCount() > 3)
463 fPopupMin =
464 m_pList->GetFirstHeight() * 3 + m_pList->GetBorderWidth() * 2;
Dan Sinclair05df0752017-03-14 14:43:42 -0400465 float fPopupMax = fListHeight + m_pList->GetBorderWidth() * 2;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax,
467 nWhere, fPopupRet);
468
469 if (IsFloatBigger(fPopupRet, 0.0f)) {
470 m_bPopup = bPopup;
471
Tom Sepez281a9ea2016-02-26 14:24:28 -0800472 CFX_FloatRect rcWindow = CPWL_Wnd::GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 m_rcOldWindow = rcWindow;
474 switch (nWhere) {
475 default:
476 case 0:
477 rcWindow.bottom -= fPopupRet;
478 break;
479 case 1:
480 rcWindow.top += fPopupRet;
481 break;
482 }
483
484 m_nPopupWhere = nWhere;
tsepez4cf55152016-11-02 14:37:54 -0700485 Move(rcWindow, true, true);
Tom Sepez51da0932015-11-25 16:05:49 -0800486#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700487 bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, 0);
489 if (bExit)
490 return;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800491#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 }
493 }
494 } else {
495 m_bPopup = bPopup;
tsepez4cf55152016-11-02 14:37:54 -0700496 Move(m_rcOldWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 }
498}
499
tsepez4cf55152016-11-02 14:37:54 -0700500bool CPWL_ComboBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 if (!m_pList)
tsepez4cf55152016-11-02 14:37:54 -0700502 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 if (!m_pEdit)
tsepez4cf55152016-11-02 14:37:54 -0700504 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505
506 m_nSelectItem = -1;
507
508 switch (nChar) {
509 case FWL_VKEY_Up:
510 if (m_pList->GetCurSel() > 0) {
tsepez4cf55152016-11-02 14:37:54 -0700511 bool bExit = false;
Tom Sepez51da0932015-11-25 16:05:49 -0800512#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 if (m_pFillerNotify) {
514 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
515 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700516 return false;
517 bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
519 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700520 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800522#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) {
524 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700525 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 SetSelectText();
527 }
528 }
tsepez4cf55152016-11-02 14:37:54 -0700529 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 case FWL_VKEY_Down:
531 if (m_pList->GetCurSel() < m_pList->GetCount() - 1) {
tsepez4cf55152016-11-02 14:37:54 -0700532 bool bExit = false;
Tom Sepez51da0932015-11-25 16:05:49 -0800533#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 if (m_pFillerNotify) {
535 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
536 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700537 return false;
538 bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
540 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700541 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800543#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) {
545 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700546 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 SetSelectText();
548 }
549 }
tsepez4cf55152016-11-02 14:37:54 -0700550 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551 }
552
553 if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
554 return m_pEdit->OnKeyDown(nChar, nFlag);
555
tsepez4cf55152016-11-02 14:37:54 -0700556 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557}
558
tsepez4cf55152016-11-02 14:37:54 -0700559bool CPWL_ComboBox::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 if (!m_pList)
tsepez4cf55152016-11-02 14:37:54 -0700561 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562
563 if (!m_pEdit)
tsepez4cf55152016-11-02 14:37:54 -0700564 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565
566 m_nSelectItem = -1;
567 if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
568 return m_pEdit->OnChar(nChar, nFlag);
569
tsepez4cf55152016-11-02 14:37:54 -0700570 bool bExit = false;
Tom Sepez51da0932015-11-25 16:05:49 -0800571#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 if (m_pFillerNotify) {
573 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
574 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700575 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576
577 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
578 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700579 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800581#endif // PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700582 return m_pList->OnCharWithExit(nChar, bExit, nFlag) ? bExit : false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583}
584
585void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700586 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587 intptr_t wParam,
588 intptr_t lParam) {
589 switch (msg) {
590 case PNM_LBUTTONDOWN:
Tom Sepez45b9ae12017-05-18 08:34:03 -0700591 if (pWnd == m_pButton) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592 SetPopup(!m_bPopup);
593 return;
594 }
595 break;
596 case PNM_LBUTTONUP:
597 if (m_pEdit && m_pList) {
Tom Sepez45b9ae12017-05-18 08:34:03 -0700598 if (pWnd == m_pList) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599 SetSelectText();
600 SelectAll();
601 m_pEdit->SetFocus();
tsepez4cf55152016-11-02 14:37:54 -0700602 SetPopup(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603 return;
604 }
605 }
Tom Sepezb084c1f2017-05-12 14:04:06 -0700606 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 }
608
609 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
610}
611
tsepez4cf55152016-11-02 14:37:54 -0700612bool CPWL_ComboBox::IsPopup() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613 return m_bPopup;
614}
615
616void CPWL_ComboBox::SetSelectText() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617 m_pEdit->SelectAll();
tsepez067990c2016-09-13 06:46:40 -0700618 m_pEdit->ReplaceSel(m_pList->GetText());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619 m_pEdit->SelectAll();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 m_nSelectItem = m_pList->GetCurSel();
621}
622
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) {
624 m_pFillerNotify = pNotify;
625
626 if (m_pEdit)
627 m_pEdit->SetFillerNotify(pNotify);
628
629 if (m_pList)
630 m_pList->SetFillerNotify(pNotify);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700631}