blob: 5adf4561f290f27c13de84cd910729f86615e9ea [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()
thestig1cd352e2016-06-07 17:53:06 -0700184 : m_pEdit(nullptr),
185 m_pButton(nullptr),
186 m_pList(nullptr),
tsepez4cf55152016-11-02 14:37:54 -0700187 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
192CFX_ByteString CPWL_ComboBox::GetClassName() const {
193 return "CPWL_ComboBox";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700194}
195
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM& cp) {
197 cp.dwFlags &= ~PWS_HSCROLL;
198 cp.dwFlags &= ~PWS_VSCROLL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199}
200
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201void CPWL_ComboBox::SetFocus() {
202 if (m_pEdit)
203 m_pEdit->SetFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700204}
205
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206void CPWL_ComboBox::KillFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700207 SetPopup(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 CPWL_Wnd::KillFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209}
210
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211CFX_WideString CPWL_ComboBox::GetText() const {
212 if (m_pEdit) {
213 return m_pEdit->GetText();
214 }
215 return CFX_WideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216}
217
tsepez067990c2016-09-13 06:46:40 -0700218void CPWL_ComboBox::SetText(const CFX_WideString& text) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219 if (m_pEdit)
220 m_pEdit->SetText(text);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700221}
222
tsepez067990c2016-09-13 06:46:40 -0700223void CPWL_ComboBox::AddString(const CFX_WideString& str) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 if (m_pList)
Dan Sinclair3ebd1212016-03-09 09:59:23 -0500225 m_pList->AddString(str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700226}
227
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228int32_t CPWL_ComboBox::GetSelect() const {
229 return m_nSelectItem;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700230}
231
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232void CPWL_ComboBox::SetSelect(int32_t nItemIndex) {
233 if (m_pList)
234 m_pList->Select(nItemIndex);
235
tsepez067990c2016-09-13 06:46:40 -0700236 m_pEdit->SetText(m_pList->GetText());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 m_nSelectItem = nItemIndex;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700238}
239
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240void CPWL_ComboBox::SetEditSel(int32_t nStartChar, int32_t nEndChar) {
tsepez067990c2016-09-13 06:46:40 -0700241 if (m_pEdit)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242 m_pEdit->SetSel(nStartChar, nEndChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243}
244
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245void CPWL_ComboBox::GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const {
246 nStartChar = -1;
247 nEndChar = -1;
248
tsepez067990c2016-09-13 06:46:40 -0700249 if (m_pEdit)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250 m_pEdit->GetSel(nStartChar, nEndChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700251}
252
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253void CPWL_ComboBox::Clear() {
tsepez067990c2016-09-13 06:46:40 -0700254 if (m_pEdit)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 m_pEdit->Clear();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700256}
257
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) {
259 CreateEdit(cp);
260 CreateButton(cp);
261 CreateListBox(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700262}
263
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) {
265 if (!m_pEdit) {
266 m_pEdit = new CPWL_CBEdit;
267 m_pEdit->AttachFFLData(m_pFormFiller);
268
269 PWL_CREATEPARAM ecp = cp;
270 ecp.pParentWnd = this;
271 ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER |
272 PES_AUTOSCROLL | PES_UNDO;
273
274 if (HasFlag(PWS_AUTOFONTSIZE))
275 ecp.dwFlags |= PWS_AUTOFONTSIZE;
276
277 if (!HasFlag(PCBS_ALLOWCUSTOMTEXT))
278 ecp.dwFlags |= PWS_READONLY;
279
Tom Sepez281a9ea2016-02-26 14:24:28 -0800280 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700281 ecp.dwBorderWidth = 0;
dsinclair92cb5e52016-05-16 11:38:28 -0700282 ecp.nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283
284 m_pEdit->Create(ecp);
285 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700286}
287
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) {
289 if (!m_pButton) {
290 m_pButton = new CPWL_CBButton;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 PWL_CREATEPARAM bcp = cp;
293 bcp.pParentWnd = this;
294 bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND;
295 bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR;
296 bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
297 bcp.dwBorderWidth = 2;
dsinclair92cb5e52016-05-16 11:38:28 -0700298 bcp.nBorderStyle = BorderStyle::BEVELED;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299 bcp.eCursorType = FXCT_ARROW;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700300
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301 m_pButton->Create(bcp);
302 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700303}
304
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) {
306 if (!m_pList) {
307 m_pList = new CPWL_CBListBox;
308 m_pList->AttachFFLData(m_pFormFiller);
309 PWL_CREATEPARAM lcp = cp;
310 lcp.pParentWnd = this;
311 lcp.dwFlags =
312 PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL;
dsinclair92cb5e52016-05-16 11:38:28 -0700313 lcp.nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314 lcp.dwBorderWidth = 1;
315 lcp.eCursorType = FXCT_ARROW;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800316 lcp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700317
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318 if (cp.dwFlags & PWS_AUTOFONTSIZE)
319 lcp.fFontSize = PWLCB_DEFAULTFONTSIZE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700320 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321 lcp.fFontSize = cp.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700322
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT)
324 lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
325
326 if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT)
327 lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
328
329 m_pList->Create(lcp);
330 }
331}
332
333void CPWL_ComboBox::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800334 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335
336 if (m_bPopup) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800337 CFX_FloatRect rclient = GetClientRect();
338 CFX_FloatRect rcButton = rclient;
339 CFX_FloatRect rcEdit = rcClient;
340 CFX_FloatRect rcList = CPWL_Wnd::GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341
Dan Sinclair05df0752017-03-14 14:43:42 -0400342 float fOldWindowHeight = m_rcOldWindow.Height();
343 float fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344
345 switch (m_nPopupWhere) {
346 case 0:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700347 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700348
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349 if (rcButton.left < rclient.left)
350 rcButton.left = rclient.left;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700351
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352 rcButton.bottom = rcButton.top - fOldClientHeight;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700353
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700354 rcEdit.right = rcButton.left - 1.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700355
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356 if (rcEdit.left < rclient.left)
357 rcEdit.left = rclient.left;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700358
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700359 if (rcEdit.right < rcEdit.left)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 rcEdit.right = rcEdit.left;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700361
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362 rcEdit.bottom = rcEdit.top - fOldClientHeight;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700363
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 rcList.top -= fOldWindowHeight;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700365
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700366 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367 case 1:
368 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
369
370 if (rcButton.left < rclient.left)
371 rcButton.left = rclient.left;
372
373 rcButton.top = rcButton.bottom + fOldClientHeight;
374
375 rcEdit.right = rcButton.left - 1.0f;
376
377 if (rcEdit.left < rclient.left)
378 rcEdit.left = rclient.left;
379
380 if (rcEdit.right < rcEdit.left)
381 rcEdit.right = rcEdit.left;
382
383 rcEdit.top = rcEdit.bottom + fOldClientHeight;
384
385 rcList.bottom += fOldWindowHeight;
386
387 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700388 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390 if (m_pButton)
tsepez4cf55152016-11-02 14:37:54 -0700391 m_pButton->Move(rcButton, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392
393 if (m_pEdit)
tsepez4cf55152016-11-02 14:37:54 -0700394 m_pEdit->Move(rcEdit, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395
396 if (m_pList) {
tsepez4cf55152016-11-02 14:37:54 -0700397 m_pList->SetVisible(true);
398 m_pList->Move(rcList, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399 m_pList->ScrollToListItem(m_nSelectItem);
400 }
401 } else {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800402 CFX_FloatRect rcButton = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700403
404 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
405
406 if (rcButton.left < rcClient.left)
407 rcButton.left = rcClient.left;
408
409 if (m_pButton)
tsepez4cf55152016-11-02 14:37:54 -0700410 m_pButton->Move(rcButton, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411
Tom Sepez281a9ea2016-02-26 14:24:28 -0800412 CFX_FloatRect rcEdit = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700413 rcEdit.right = rcButton.left - 1.0f;
414
415 if (rcEdit.left < rcClient.left)
416 rcEdit.left = rcClient.left;
417
418 if (rcEdit.right < rcEdit.left)
419 rcEdit.right = rcEdit.left;
420
421 if (m_pEdit)
tsepez4cf55152016-11-02 14:37:54 -0700422 m_pEdit->Move(rcEdit, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423
424 if (m_pList)
tsepez4cf55152016-11-02 14:37:54 -0700425 m_pList->SetVisible(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700427}
428
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429void CPWL_ComboBox::SelectAll() {
430 if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT))
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700431 m_pEdit->SelectAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700432}
433
Tom Sepez281a9ea2016-02-26 14:24:28 -0800434CFX_FloatRect CPWL_ComboBox::GetFocusRect() const {
435 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700436}
437
tsepez4cf55152016-11-02 14:37:54 -0700438void CPWL_ComboBox::SetPopup(bool bPopup) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 if (!m_pList)
440 return;
441 if (bPopup == m_bPopup)
442 return;
Dan Sinclair05df0752017-03-14 14:43:42 -0400443 float fListHeight = m_pList->GetContentRect().Height();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 if (!IsFloatBigger(fListHeight, 0.0f))
445 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700446
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447 if (bPopup) {
448 if (m_pFillerNotify) {
Tom Sepez51da0932015-11-25 16:05:49 -0800449#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700450 bool bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, 0);
452 if (bExit)
453 return;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800454#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 int32_t nWhere = 0;
Dan Sinclair05df0752017-03-14 14:43:42 -0400456 float fPopupRet = 0.0f;
457 float fPopupMin = 0.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 if (m_pList->GetCount() > 3)
459 fPopupMin =
460 m_pList->GetFirstHeight() * 3 + m_pList->GetBorderWidth() * 2;
Dan Sinclair05df0752017-03-14 14:43:42 -0400461 float fPopupMax = fListHeight + m_pList->GetBorderWidth() * 2;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax,
463 nWhere, fPopupRet);
464
465 if (IsFloatBigger(fPopupRet, 0.0f)) {
466 m_bPopup = bPopup;
467
Tom Sepez281a9ea2016-02-26 14:24:28 -0800468 CFX_FloatRect rcWindow = CPWL_Wnd::GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 m_rcOldWindow = rcWindow;
470 switch (nWhere) {
471 default:
472 case 0:
473 rcWindow.bottom -= fPopupRet;
474 break;
475 case 1:
476 rcWindow.top += fPopupRet;
477 break;
478 }
479
480 m_nPopupWhere = nWhere;
tsepez4cf55152016-11-02 14:37:54 -0700481 Move(rcWindow, true, true);
Tom Sepez51da0932015-11-25 16:05:49 -0800482#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700483 bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700484 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, 0);
485 if (bExit)
486 return;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800487#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 }
489 }
490 } else {
491 m_bPopup = bPopup;
tsepez4cf55152016-11-02 14:37:54 -0700492 Move(m_rcOldWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 }
494}
495
tsepez4cf55152016-11-02 14:37:54 -0700496bool CPWL_ComboBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 if (!m_pList)
tsepez4cf55152016-11-02 14:37:54 -0700498 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499 if (!m_pEdit)
tsepez4cf55152016-11-02 14:37:54 -0700500 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501
502 m_nSelectItem = -1;
503
504 switch (nChar) {
505 case FWL_VKEY_Up:
506 if (m_pList->GetCurSel() > 0) {
tsepez4cf55152016-11-02 14:37:54 -0700507 bool bExit = false;
Tom Sepez51da0932015-11-25 16:05:49 -0800508#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 if (m_pFillerNotify) {
510 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
511 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700512 return false;
513 bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
515 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700516 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800518#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519 if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) {
520 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700521 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 SetSelectText();
523 }
524 }
tsepez4cf55152016-11-02 14:37:54 -0700525 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 case FWL_VKEY_Down:
527 if (m_pList->GetCurSel() < m_pList->GetCount() - 1) {
tsepez4cf55152016-11-02 14:37:54 -0700528 bool bExit = false;
Tom Sepez51da0932015-11-25 16:05:49 -0800529#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 if (m_pFillerNotify) {
531 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
532 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700533 return false;
534 bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
536 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700537 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800539#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) {
541 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700542 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543 SetSelectText();
544 }
545 }
tsepez4cf55152016-11-02 14:37:54 -0700546 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 }
548
549 if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
550 return m_pEdit->OnKeyDown(nChar, nFlag);
551
tsepez4cf55152016-11-02 14:37:54 -0700552 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553}
554
tsepez4cf55152016-11-02 14:37:54 -0700555bool CPWL_ComboBox::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556 if (!m_pList)
tsepez4cf55152016-11-02 14:37:54 -0700557 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558
559 if (!m_pEdit)
tsepez4cf55152016-11-02 14:37:54 -0700560 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561
562 m_nSelectItem = -1;
563 if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
564 return m_pEdit->OnChar(nChar, nFlag);
565
tsepez4cf55152016-11-02 14:37:54 -0700566 bool bExit = false;
Tom Sepez51da0932015-11-25 16:05:49 -0800567#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700568 if (m_pFillerNotify) {
569 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
570 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700571 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572
573 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
574 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700575 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800577#endif // PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700578 return m_pList->OnCharWithExit(nChar, bExit, nFlag) ? bExit : false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579}
580
581void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -0700582 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583 intptr_t wParam,
584 intptr_t lParam) {
585 switch (msg) {
586 case PNM_LBUTTONDOWN:
587 if (pWnd == m_pButton) {
588 SetPopup(!m_bPopup);
589 return;
590 }
591 break;
592 case PNM_LBUTTONUP:
593 if (m_pEdit && m_pList) {
594 if (pWnd == m_pList) {
595 SetSelectText();
596 SelectAll();
597 m_pEdit->SetFocus();
tsepez4cf55152016-11-02 14:37:54 -0700598 SetPopup(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599 return;
600 }
601 }
602 }
603
604 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
605}
606
tsepez4cf55152016-11-02 14:37:54 -0700607bool CPWL_ComboBox::IsPopup() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608 return m_bPopup;
609}
610
611void CPWL_ComboBox::SetSelectText() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 m_pEdit->SelectAll();
tsepez067990c2016-09-13 06:46:40 -0700613 m_pEdit->ReplaceSel(m_pList->GetText());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 m_pEdit->SelectAll();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615 m_nSelectItem = m_pList->GetCurSel();
616}
617
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) {
619 m_pFillerNotify = pNotify;
620
621 if (m_pEdit)
622 m_pEdit->SetFillerNotify(pNotify);
623
624 if (m_pList)
625 m_pList->SetFillerNotify(pNotify);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700626}