blob: 3ebccca2632a7fe0347dba314bff9d04e484dee0 [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 Sinclairc411eb92017-07-25 09:39:30 -04007#include "fpdfsdk/pwl/cpwl_combo_box.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
Lei Zhang7bef7c82017-05-31 23:52:00 -07009#include <algorithm>
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -040010#include <sstream>
Lei Zhang7bef7c82017-05-31 23:52:00 -070011
dsinclair74a34fc2016-09-29 16:41:42 -070012#include "core/fxge/cfx_pathdata.h"
13#include "core/fxge/cfx_renderdevice.h"
Dan Sinclairc411eb92017-07-25 09:39:30 -040014#include "fpdfsdk/pwl/cpwl_edit.h"
15#include "fpdfsdk/pwl/cpwl_edit_ctrl.h"
16#include "fpdfsdk/pwl/cpwl_list_box.h"
17#include "fpdfsdk/pwl/cpwl_list_impl.h"
18#include "fpdfsdk/pwl/cpwl_wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080019#include "public/fpdf_fwlevent.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Dan Sinclaira9e28432017-07-05 14:18:14 -040021namespace {
22
23constexpr float kDefaultFontSize = 12.0f;
24constexpr float kTriangleHalfLength = 3.0f;
Dan Sinclair951b1112017-10-02 10:38:55 -040025constexpr int kDefaultButtonWidth = 13;
Dan Sinclaira9e28432017-07-05 14:18:14 -040026
27} // namespace
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028
Dan Sinclairf528eee2017-02-14 11:52:07 -050029bool CPWL_CBListBox::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070030 CPWL_Wnd::OnLButtonUp(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
dsinclair36177512016-07-19 10:16:10 -070032 if (!m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -070033 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034
dsinclair36177512016-07-19 10:16:10 -070035 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -070036 m_bMouseDown = false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070037
dsinclair36177512016-07-19 10:16:10 -070038 if (!ClientHitTest(point))
tsepez4cf55152016-11-02 14:37:54 -070039 return true;
dsinclair36177512016-07-19 10:16:10 -070040 if (CPWL_Wnd* pParent = GetParentWindow())
Dan Sinclair7f6bec92017-07-05 14:13:16 -040041 pParent->NotifyLButtonUp(this, point);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042
Dan Sinclair2b444412017-07-06 13:56:35 -040043 return !OnNotifySelectionChanged(false, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044}
45
Dan Sinclair07dbf432017-07-06 11:47:26 -040046bool CPWL_CBListBox::IsMovementKey(uint16_t nChar) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 switch (nChar) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048 case FWL_VKEY_Up:
49 case FWL_VKEY_Down:
50 case FWL_VKEY_Home:
51 case FWL_VKEY_Left:
52 case FWL_VKEY_End:
53 case FWL_VKEY_Right:
Dan Sinclair07dbf432017-07-06 11:47:26 -040054 return true;
dsinclair36177512016-07-19 10:16:10 -070055 default:
tsepez4cf55152016-11-02 14:37:54 -070056 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 }
Dan Sinclair07dbf432017-07-06 11:47:26 -040058}
59
60bool CPWL_CBListBox::OnMovementKeyDown(uint16_t nChar, uint32_t nFlag) {
61 ASSERT(IsMovementKey(nChar));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063 switch (nChar) {
64 case FWL_VKEY_Up:
65 m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
66 break;
67 case FWL_VKEY_Down:
68 m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
69 break;
70 case FWL_VKEY_Home:
71 m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
72 break;
73 case FWL_VKEY_Left:
74 m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
75 break;
76 case FWL_VKEY_End:
77 m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
78 break;
79 case FWL_VKEY_Right:
80 m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
81 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 }
Dan Sinclair2b444412017-07-06 13:56:35 -040083 return OnNotifySelectionChanged(true, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084}
85
Dan Sinclair16fea942017-07-06 11:56:37 -040086bool CPWL_CBListBox::IsChar(uint16_t nChar, uint32_t nFlag) const {
87 return m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
88}
89
90bool CPWL_CBListBox::OnCharNotify(uint16_t nChar, uint32_t nFlag) {
dsinclair36177512016-07-19 10:16:10 -070091 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow())
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 pComboBox->SetSelectText();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093
Dan Sinclair2b444412017-07-06 13:56:35 -040094 return OnNotifySelectionChanged(true, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095}
96
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice,
Lei Zhangeb14e042017-08-15 13:56:43 -070098 const CFX_Matrix& mtUser2Device) {
99 CPWL_Wnd::DrawThisAppearance(pDevice, mtUser2Device);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100
Tom Sepez281a9ea2016-02-26 14:24:28 -0800101 CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700102
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400103 if (!IsVisible() || rectWnd.IsEmpty())
104 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700105
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400106 CFX_PointF ptCenter = GetCenterPoint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107
Dan Sinclaira9e28432017-07-05 14:18:14 -0400108 CFX_PointF pt1(ptCenter.x - kTriangleHalfLength,
109 ptCenter.y + kTriangleHalfLength * 0.5f);
110 CFX_PointF pt2(ptCenter.x + kTriangleHalfLength,
111 ptCenter.y + kTriangleHalfLength * 0.5f);
112 CFX_PointF pt3(ptCenter.x, ptCenter.y - kTriangleHalfLength * 0.5f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113
Dan Sinclaira9e28432017-07-05 14:18:14 -0400114 if (IsFloatBigger(rectWnd.right - rectWnd.left, kTriangleHalfLength * 2) &&
115 IsFloatBigger(rectWnd.top - rectWnd.bottom, kTriangleHalfLength)) {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400116 CFX_PathData path;
117 path.AppendPoint(pt1, FXPT_TYPE::MoveTo, false);
118 path.AppendPoint(pt2, FXPT_TYPE::LineTo, false);
119 path.AppendPoint(pt3, FXPT_TYPE::LineTo, false);
120 path.AppendPoint(pt1, FXPT_TYPE::LineTo, false);
121
Lei Zhangeb14e042017-08-15 13:56:43 -0700122 pDevice->DrawPath(&path, &mtUser2Device, nullptr,
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400123 PWL_DEFAULT_BLACKCOLOR.ToFXColor(GetTransparency()), 0,
124 FXFILL_ALTERNATE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700126}
127
Dan Sinclairf528eee2017-02-14 11:52:07 -0500128bool CPWL_CBButton::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 SetCapture();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132
Dan Sinclair7f6bec92017-07-05 14:13:16 -0400133 if (CPWL_Wnd* pParent = GetParentWindow())
134 pParent->NotifyLButtonDown(this, point);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700135
tsepez4cf55152016-11-02 14:37:54 -0700136 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137}
138
Dan Sinclairf528eee2017-02-14 11:52:07 -0500139bool CPWL_CBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140 CPWL_Wnd::OnLButtonUp(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700142 ReleaseCapture();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143
tsepez4cf55152016-11-02 14:37:54 -0700144 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145}
146
Lei Zhang35162562017-06-09 01:04:52 -0700147CPWL_ComboBox::CPWL_ComboBox() {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148
Tom Sepezb084c1f2017-05-12 14:04:06 -0700149CPWL_ComboBox::~CPWL_ComboBox() {}
150
Ryan Harrison275e2602017-09-18 14:23:18 -0400151ByteString CPWL_ComboBox::GetClassName() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152 return "CPWL_ComboBox";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700153}
154
Tom Sepezbf157302017-09-15 13:26:32 -0700155void CPWL_ComboBox::OnCreate(CreateParams* pParamsToAdjust) {
156 pParamsToAdjust->dwFlags &= ~PWS_HSCROLL;
157 pParamsToAdjust->dwFlags &= ~PWS_VSCROLL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700158}
159
Lei Zhang35162562017-06-09 01:04:52 -0700160void CPWL_ComboBox::OnDestroy() {
161 // Until cleanup takes place in the virtual destructor for CPWL_Wnd
162 // subclasses, implement the virtual OnDestroy method that does the
163 // cleanup first, then invokes the superclass OnDestroy ... gee,
164 // like a dtor would.
165 m_pList.Release();
166 m_pButton.Release();
167 m_pEdit.Release();
168 CPWL_Wnd::OnDestroy();
169}
170
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171void CPWL_ComboBox::SetFocus() {
172 if (m_pEdit)
173 m_pEdit->SetFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700174}
175
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176void CPWL_ComboBox::KillFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700177 SetPopup(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 CPWL_Wnd::KillFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700179}
180
Ryan Harrison275e2602017-09-18 14:23:18 -0400181WideString CPWL_ComboBox::GetSelectedText() {
Diana Gagedce2d722017-06-20 11:17:11 -0700182 if (m_pEdit)
183 return m_pEdit->GetSelectedText();
184
Ryan Harrison275e2602017-09-18 14:23:18 -0400185 return WideString();
Diana Gagedce2d722017-06-20 11:17:11 -0700186}
187
Ryan Harrison275e2602017-09-18 14:23:18 -0400188void CPWL_ComboBox::ReplaceSelection(const WideString& text) {
Diana Gage1c7f1422017-07-24 11:19:52 -0700189 if (m_pEdit)
Diana Gageab390972017-07-28 17:07:39 -0700190 m_pEdit->ReplaceSelection(text);
Diana Gage1c7f1422017-07-24 11:19:52 -0700191}
192
Ryan Harrison275e2602017-09-18 14:23:18 -0400193WideString CPWL_ComboBox::GetText() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194 if (m_pEdit) {
195 return m_pEdit->GetText();
196 }
Ryan Harrison275e2602017-09-18 14:23:18 -0400197 return WideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700198}
199
Ryan Harrison275e2602017-09-18 14:23:18 -0400200void CPWL_ComboBox::SetText(const WideString& text) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201 if (m_pEdit)
202 m_pEdit->SetText(text);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700203}
204
Ryan Harrison275e2602017-09-18 14:23:18 -0400205void CPWL_ComboBox::AddString(const WideString& str) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 if (m_pList)
Dan Sinclair3ebd1212016-03-09 09:59:23 -0500207 m_pList->AddString(str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700208}
209
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210int32_t CPWL_ComboBox::GetSelect() const {
211 return m_nSelectItem;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700212}
213
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214void CPWL_ComboBox::SetSelect(int32_t nItemIndex) {
215 if (m_pList)
216 m_pList->Select(nItemIndex);
217
tsepez067990c2016-09-13 06:46:40 -0700218 m_pEdit->SetText(m_pList->GetText());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219 m_nSelectItem = nItemIndex;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700220}
221
Diana Gage4d02e902017-07-20 17:20:31 -0700222void CPWL_ComboBox::SetEditSelection(int32_t nStartChar, int32_t nEndChar) {
tsepez067990c2016-09-13 06:46:40 -0700223 if (m_pEdit)
Diana Gage4d02e902017-07-20 17:20:31 -0700224 m_pEdit->SetSelection(nStartChar, nEndChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700225}
226
Diana Gage4d02e902017-07-20 17:20:31 -0700227void CPWL_ComboBox::GetEditSelection(int32_t& nStartChar,
228 int32_t& nEndChar) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 nStartChar = -1;
230 nEndChar = -1;
231
tsepez067990c2016-09-13 06:46:40 -0700232 if (m_pEdit)
Diana Gage4d02e902017-07-20 17:20:31 -0700233 m_pEdit->GetSelection(nStartChar, nEndChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700234}
235
Diana Gage22bf7a52017-07-21 11:33:18 -0700236void CPWL_ComboBox::ClearSelection() {
tsepez067990c2016-09-13 06:46:40 -0700237 if (m_pEdit)
Diana Gage22bf7a52017-07-21 11:33:18 -0700238 m_pEdit->ClearSelection();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239}
240
Tom Sepezbf157302017-09-15 13:26:32 -0700241void CPWL_ComboBox::CreateChildWnd(const CreateParams& cp) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242 CreateEdit(cp);
243 CreateButton(cp);
244 CreateListBox(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245}
246
Tom Sepezbf157302017-09-15 13:26:32 -0700247void CPWL_ComboBox::CreateEdit(const CreateParams& cp) {
Tom Sepezb084c1f2017-05-12 14:04:06 -0700248 if (m_pEdit)
249 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250
Dan Sinclair0fdd1ae2017-07-05 16:00:48 -0400251 m_pEdit = new CPWL_Edit();
Tom Sepezcc205132017-05-16 14:01:47 -0700252 m_pEdit->AttachFFLData(m_pFormFiller.Get());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253
Tom Sepezbf157302017-09-15 13:26:32 -0700254 CreateParams ecp = cp;
Tom Sepezb084c1f2017-05-12 14:04:06 -0700255 ecp.pParentWnd = this;
256 ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER |
257 PES_AUTOSCROLL | PES_UNDO;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258
Tom Sepezb084c1f2017-05-12 14:04:06 -0700259 if (HasFlag(PWS_AUTOFONTSIZE))
260 ecp.dwFlags |= PWS_AUTOFONTSIZE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261
Tom Sepezb084c1f2017-05-12 14:04:06 -0700262 if (!HasFlag(PCBS_ALLOWCUSTOMTEXT))
263 ecp.dwFlags |= PWS_READONLY;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264
Lei Zhangd24236a2017-06-29 18:28:58 -0700265 ecp.rcRectWnd = CFX_FloatRect();
Tom Sepezb084c1f2017-05-12 14:04:06 -0700266 ecp.dwBorderWidth = 0;
267 ecp.nBorderStyle = BorderStyle::SOLID;
268 m_pEdit->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269}
270
Tom Sepezbf157302017-09-15 13:26:32 -0700271void CPWL_ComboBox::CreateButton(const CreateParams& cp) {
Tom Sepezb084c1f2017-05-12 14:04:06 -0700272 if (m_pButton)
273 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700274
Tom Sepez45b9ae12017-05-18 08:34:03 -0700275 m_pButton = new CPWL_CBButton;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700276
Tom Sepezbf157302017-09-15 13:26:32 -0700277 CreateParams bcp = cp;
Tom Sepezb084c1f2017-05-12 14:04:06 -0700278 bcp.pParentWnd = this;
279 bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND;
Dan Sinclair7f55a542017-07-13 14:17:10 -0400280 bcp.sBackgroundColor = CFX_Color(COLORTYPE_RGB, 220.0f / 255.0f,
281 220.0f / 255.0f, 220.0f / 255.0f);
Tom Sepezb084c1f2017-05-12 14:04:06 -0700282 bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
283 bcp.dwBorderWidth = 2;
284 bcp.nBorderStyle = BorderStyle::BEVELED;
285 bcp.eCursorType = FXCT_ARROW;
286 m_pButton->Create(bcp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700287}
288
Tom Sepezbf157302017-09-15 13:26:32 -0700289void CPWL_ComboBox::CreateListBox(const CreateParams& cp) {
Tom Sepezb084c1f2017-05-12 14:04:06 -0700290 if (m_pList)
291 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700292
Tom Sepez45b9ae12017-05-18 08:34:03 -0700293 m_pList = new CPWL_CBListBox();
Tom Sepezcc205132017-05-16 14:01:47 -0700294 m_pList->AttachFFLData(m_pFormFiller.Get());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700295
Tom Sepezbf157302017-09-15 13:26:32 -0700296 CreateParams lcp = cp;
Tom Sepezb084c1f2017-05-12 14:04:06 -0700297 lcp.pParentWnd = this;
298 lcp.dwFlags =
299 PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL;
300 lcp.nBorderStyle = BorderStyle::SOLID;
301 lcp.dwBorderWidth = 1;
302 lcp.eCursorType = FXCT_ARROW;
Lei Zhangd24236a2017-06-29 18:28:58 -0700303 lcp.rcRectWnd = CFX_FloatRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304
Tom Sepezb084c1f2017-05-12 14:04:06 -0700305 if (cp.dwFlags & PWS_AUTOFONTSIZE)
Dan Sinclaira9e28432017-07-05 14:18:14 -0400306 lcp.fFontSize = kDefaultFontSize;
Tom Sepezb084c1f2017-05-12 14:04:06 -0700307 else
308 lcp.fFontSize = cp.fFontSize;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309
Tom Sepezb084c1f2017-05-12 14:04:06 -0700310 if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT)
311 lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
312
313 if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT)
314 lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
315
316 m_pList->Create(lcp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317}
318
319void CPWL_ComboBox::RePosChildWnd() {
Lei Zhang7bef7c82017-05-31 23:52:00 -0700320 const CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321 if (m_bPopup) {
Lei Zhang7bef7c82017-05-31 23:52:00 -0700322 const float fOldWindowHeight = m_rcOldWindow.Height();
323 const float fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2;
324
Tom Sepez281a9ea2016-02-26 14:24:28 -0800325 CFX_FloatRect rcList = CPWL_Wnd::GetWindowRect();
Lei Zhang7bef7c82017-05-31 23:52:00 -0700326 CFX_FloatRect rcButton = rcClient;
327 rcButton.left =
Dan Sinclair951b1112017-10-02 10:38:55 -0400328 std::max(rcButton.right - kDefaultButtonWidth, rcClient.left);
Lei Zhang7bef7c82017-05-31 23:52:00 -0700329 CFX_FloatRect rcEdit = rcClient;
330 rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left);
331 if (m_bBottom) {
332 rcButton.bottom = rcButton.top - fOldClientHeight;
333 rcEdit.bottom = rcEdit.top - fOldClientHeight;
334 rcList.top -= fOldWindowHeight;
335 } else {
336 rcButton.top = rcButton.bottom + fOldClientHeight;
337 rcEdit.top = rcEdit.bottom + fOldClientHeight;
338 rcList.bottom += fOldWindowHeight;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700339 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700340
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341 if (m_pButton)
tsepez4cf55152016-11-02 14:37:54 -0700342 m_pButton->Move(rcButton, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343
344 if (m_pEdit)
tsepez4cf55152016-11-02 14:37:54 -0700345 m_pEdit->Move(rcEdit, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700346
347 if (m_pList) {
tsepez4cf55152016-11-02 14:37:54 -0700348 m_pList->SetVisible(true);
349 m_pList->Move(rcList, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350 m_pList->ScrollToListItem(m_nSelectItem);
351 }
Lei Zhang7bef7c82017-05-31 23:52:00 -0700352 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353 }
Lei Zhang7bef7c82017-05-31 23:52:00 -0700354
355 CFX_FloatRect rcButton = rcClient;
Dan Sinclair951b1112017-10-02 10:38:55 -0400356 rcButton.left = std::max(rcButton.right - kDefaultButtonWidth, rcClient.left);
Lei Zhang7bef7c82017-05-31 23:52:00 -0700357
358 if (m_pButton)
359 m_pButton->Move(rcButton, true, false);
360
361 CFX_FloatRect rcEdit = rcClient;
362 rcEdit.right = std::max(rcButton.left - 1.0f, rcEdit.left);
363
364 if (m_pEdit)
365 m_pEdit->Move(rcEdit, true, false);
366
367 if (m_pList)
368 m_pList->SetVisible(false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700369}
370
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371void CPWL_ComboBox::SelectAll() {
372 if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT))
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700373 m_pEdit->SelectAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700374}
375
Tom Sepez281a9ea2016-02-26 14:24:28 -0800376CFX_FloatRect CPWL_ComboBox::GetFocusRect() const {
377 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700378}
379
tsepez4cf55152016-11-02 14:37:54 -0700380void CPWL_ComboBox::SetPopup(bool bPopup) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381 if (!m_pList)
382 return;
383 if (bPopup == m_bPopup)
384 return;
Dan Sinclair05df0752017-03-14 14:43:42 -0400385 float fListHeight = m_pList->GetContentRect().Height();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386 if (!IsFloatBigger(fListHeight, 0.0f))
387 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700388
Lei Zhang7bef7c82017-05-31 23:52:00 -0700389 if (!bPopup) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390 m_bPopup = bPopup;
tsepez4cf55152016-11-02 14:37:54 -0700391 Move(m_rcOldWindow, true, true);
Lei Zhang7bef7c82017-05-31 23:52:00 -0700392 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393 }
Lei Zhang7bef7c82017-05-31 23:52:00 -0700394
395 if (!m_pFillerNotify)
396 return;
397
398#ifdef PDF_ENABLE_XFA
Dan Sinclair5fe98082017-07-06 11:13:02 -0400399 if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), 0))
Lei Zhang7bef7c82017-05-31 23:52:00 -0700400 return;
401#endif // PDF_ENABLE_XFA
402
403 float fBorderWidth = m_pList->GetBorderWidth() * 2;
404 float fPopupMin = 0.0f;
405 if (m_pList->GetCount() > 3)
406 fPopupMin = m_pList->GetFirstHeight() * 3 + fBorderWidth;
407 float fPopupMax = fListHeight + fBorderWidth;
408
409 bool bBottom;
410 float fPopupRet;
411 m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax,
412 &bBottom, &fPopupRet);
413 if (!IsFloatBigger(fPopupRet, 0.0f))
414 return;
415
416 m_rcOldWindow = CPWL_Wnd::GetWindowRect();
417 m_bPopup = bPopup;
418 m_bBottom = bBottom;
419
420 CFX_FloatRect rcWindow = m_rcOldWindow;
421 if (bBottom)
422 rcWindow.bottom -= fPopupRet;
423 else
424 rcWindow.top += fPopupRet;
425
426 Move(rcWindow, true, true);
427#ifdef PDF_ENABLE_XFA
Dan Sinclair5fe98082017-07-06 11:13:02 -0400428 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), 0);
Lei Zhang7bef7c82017-05-31 23:52:00 -0700429#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430}
431
tsepez4cf55152016-11-02 14:37:54 -0700432bool CPWL_ComboBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433 if (!m_pList)
tsepez4cf55152016-11-02 14:37:54 -0700434 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 if (!m_pEdit)
tsepez4cf55152016-11-02 14:37:54 -0700436 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437
438 m_nSelectItem = -1;
439
440 switch (nChar) {
441 case FWL_VKEY_Up:
442 if (m_pList->GetCurSel() > 0) {
Tom Sepez51da0932015-11-25 16:05:49 -0800443#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 if (m_pFillerNotify) {
Dan Sinclair5fe98082017-07-06 11:13:02 -0400445 if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700446 return false;
Dan Sinclair5fe98082017-07-06 11:13:02 -0400447 if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700448 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800450#endif // PDF_ENABLE_XFA
Dan Sinclair07dbf432017-07-06 11:47:26 -0400451 if (m_pList->IsMovementKey(nChar)) {
452 if (m_pList->OnMovementKeyDown(nChar, nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700453 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454 SetSelectText();
455 }
456 }
tsepez4cf55152016-11-02 14:37:54 -0700457 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 case FWL_VKEY_Down:
459 if (m_pList->GetCurSel() < m_pList->GetCount() - 1) {
Tom Sepez51da0932015-11-25 16:05:49 -0800460#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 if (m_pFillerNotify) {
Dan Sinclair5fe98082017-07-06 11:13:02 -0400462 if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700463 return false;
Dan Sinclair5fe98082017-07-06 11:13:02 -0400464 if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700465 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800467#endif // PDF_ENABLE_XFA
Dan Sinclair07dbf432017-07-06 11:47:26 -0400468 if (m_pList->IsMovementKey(nChar)) {
469 if (m_pList->OnMovementKeyDown(nChar, nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700470 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 SetSelectText();
472 }
473 }
tsepez4cf55152016-11-02 14:37:54 -0700474 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 }
476
477 if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
478 return m_pEdit->OnKeyDown(nChar, nFlag);
479
tsepez4cf55152016-11-02 14:37:54 -0700480 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481}
482
tsepez4cf55152016-11-02 14:37:54 -0700483bool CPWL_ComboBox::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700484 if (!m_pList)
tsepez4cf55152016-11-02 14:37:54 -0700485 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486
487 if (!m_pEdit)
tsepez4cf55152016-11-02 14:37:54 -0700488 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489
490 m_nSelectItem = -1;
491 if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
492 return m_pEdit->OnChar(nChar, nFlag);
493
Tom Sepez51da0932015-11-25 16:05:49 -0800494#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 if (m_pFillerNotify) {
Dan Sinclair5fe98082017-07-06 11:13:02 -0400496 if (m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700497 return false;
Dan Sinclair5fe98082017-07-06 11:13:02 -0400498 if (m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700499 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800501#endif // PDF_ENABLE_XFA
Dan Sinclair16fea942017-07-06 11:56:37 -0400502 if (!m_pList->IsChar(nChar, nFlag))
503 return false;
504 return m_pList->OnCharNotify(nChar, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505}
506
Dan Sinclair7f6bec92017-07-05 14:13:16 -0400507void CPWL_ComboBox::NotifyLButtonDown(CPWL_Wnd* child, const CFX_PointF& pos) {
508 if (child == m_pButton)
509 SetPopup(!m_bPopup);
510}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511
Dan Sinclair7f6bec92017-07-05 14:13:16 -0400512void CPWL_ComboBox::NotifyLButtonUp(CPWL_Wnd* child, const CFX_PointF& pos) {
513 if (!m_pEdit || !m_pList || child != m_pList)
514 return;
515
516 SetSelectText();
517 SelectAll();
518 m_pEdit->SetFocus();
519 SetPopup(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520}
521
tsepez4cf55152016-11-02 14:37:54 -0700522bool CPWL_ComboBox::IsPopup() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 return m_bPopup;
524}
525
526void CPWL_ComboBox::SetSelectText() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 m_pEdit->SelectAll();
tsepez067990c2016-09-13 06:46:40 -0700528 m_pEdit->ReplaceSel(m_pList->GetText());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529 m_pEdit->SelectAll();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 m_nSelectItem = m_pList->GetCurSel();
531}
532
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) {
534 m_pFillerNotify = pNotify;
535
536 if (m_pEdit)
537 m_pEdit->SetFillerNotify(pNotify);
538
539 if (m_pList)
540 m_pList->SetFillerNotify(pNotify);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700541}