blob: cf9ce0a5fb260a49ab4c25f2ace1a97e474c0aa6 [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
Lei Zhangbde53d22015-11-12 22:21:30 -08007#include "fpdfsdk/include/pdfwindow/PWL_ComboBox.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
Dan Sinclairaa403d32016-03-15 14:57:22 -04009#include "core/include/fxge/fx_ge.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080010#include "fpdfsdk/include/pdfwindow/PWL_Edit.h"
11#include "fpdfsdk/include/pdfwindow/PWL_EditCtrl.h"
12#include "fpdfsdk/include/pdfwindow/PWL_ListBox.h"
13#include "fpdfsdk/include/pdfwindow/PWL_Utils.h"
14#include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080015#include "public/fpdf_fwlevent.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070016
Nico Weber9d8ec5a2015-08-04 13:00:21 -070017#define PWLCB_DEFAULTFONTSIZE 12.0f
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
20#define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
21#define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
22#define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023
Tom Sepez281a9ea2016-02-26 14:24:28 -080024FX_BOOL CPWL_CBListBox::OnLButtonUp(const CFX_FloatPoint& point,
25 FX_DWORD nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026 CPWL_Wnd::OnLButtonUp(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028 if (m_bMouseDown) {
29 ReleaseCapture();
30 m_bMouseDown = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032 if (ClientHitTest(point)) {
33 if (CPWL_Wnd* pParent = GetParentWindow()) {
34 pParent->OnNotify(this, PNM_LBUTTONUP, 0,
35 PWL_MAKEDWORD(point.x, point.y));
36 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070037
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038 FX_BOOL bExit = FALSE;
39 OnNotifySelChanged(FALSE, bExit, nFlag);
40 if (bExit)
Tom Sepez2f2ffec2015-07-23 14:42:09 -070041 return FALSE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -070042 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046}
47
Tom Sepez62a70f92016-03-21 15:00:20 -070048FX_BOOL CPWL_CBListBox::OnKeyDownWithExit(uint16_t nChar,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 FX_BOOL& bExit,
50 FX_DWORD nFlag) {
51 if (!m_pList)
52 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070053
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 switch (nChar) {
55 default:
56 return FALSE;
57 case FWL_VKEY_Up:
58 case FWL_VKEY_Down:
59 case FWL_VKEY_Home:
60 case FWL_VKEY_Left:
61 case FWL_VKEY_End:
62 case FWL_VKEY_Right:
63 break;
64 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 switch (nChar) {
67 case FWL_VKEY_Up:
68 m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
69 break;
70 case FWL_VKEY_Down:
71 m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
72 break;
73 case FWL_VKEY_Home:
74 m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
75 break;
76 case FWL_VKEY_Left:
77 m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
78 break;
79 case FWL_VKEY_End:
80 m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
81 break;
82 case FWL_VKEY_Right:
83 m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
84 break;
85 case FWL_VKEY_Delete:
86 break;
87 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070088
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 OnNotifySelChanged(TRUE, bExit, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 return TRUE;
92}
93
Tom Sepez62a70f92016-03-21 15:00:20 -070094FX_BOOL CPWL_CBListBox::OnCharWithExit(uint16_t nChar,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095 FX_BOOL& bExit,
96 FX_DWORD nFlag) {
97 if (!m_pList)
98 return FALSE;
99
100 if (!m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)))
101 return FALSE;
102
103 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow()) {
104 pComboBox->SetSelectText();
105 }
106
107 OnNotifySelChanged(TRUE, bExit, nFlag);
108
109 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700110}
111
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112void CPWL_CBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
113 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700114
Tom Sepez281a9ea2016-02-26 14:24:28 -0800115 CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700116
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 if (IsVisible() && !rectWnd.IsEmpty()) {
118 CFX_ByteTextBuf sButton;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119
Tom Sepez281a9ea2016-02-26 14:24:28 -0800120 CFX_FloatPoint ptCenter = GetCenterPoint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121
Tom Sepez281a9ea2016-02-26 14:24:28 -0800122 CFX_FloatPoint pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,
123 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
124 CFX_FloatPoint pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,
125 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
126 CFX_FloatPoint pt3(ptCenter.x,
127 ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700128
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 if (IsFloatBigger(rectWnd.right - rectWnd.left,
130 PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) &&
131 IsFloatBigger(rectWnd.top - rectWnd.bottom,
132 PWL_CBBUTTON_TRIANGLE_HALFLEN)) {
133 sButton << "0 g\n";
134 sButton << pt1.x << " " << pt1.y << " m\n";
135 sButton << pt2.x << " " << pt2.y << " l\n";
136 sButton << pt3.x << " " << pt3.y << " l\n";
137 sButton << pt1.x << " " << pt1.y << " l f\n";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700138
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139 sAppStream << "q\n" << sButton << "Q\n";
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700140 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700142}
143
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800145 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700147
Tom Sepez281a9ea2016-02-26 14:24:28 -0800148 CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700149
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150 if (IsVisible() && !rectWnd.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800151 CFX_FloatPoint ptCenter = GetCenterPoint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700152
Tom Sepez281a9ea2016-02-26 14:24:28 -0800153 CFX_FloatPoint pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,
154 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
155 CFX_FloatPoint pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,
156 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
157 CFX_FloatPoint pt3(ptCenter.x,
158 ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 if (IsFloatBigger(rectWnd.right - rectWnd.left,
161 PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) &&
162 IsFloatBigger(rectWnd.top - rectWnd.bottom,
163 PWL_CBBUTTON_TRIANGLE_HALFLEN)) {
164 CFX_PathData path;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700165
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 path.SetPointCount(4);
167 path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
168 path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
169 path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
170 path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 pDevice->DrawPath(&path, pUser2Device, NULL,
173 CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_BLACKCOLOR,
174 GetTransparency()),
175 0, FXFILL_ALTERNATE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700176 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178}
179
Tom Sepez281a9ea2016-02-26 14:24:28 -0800180FX_BOOL CPWL_CBButton::OnLButtonDown(const CFX_FloatPoint& point,
181 FX_DWORD nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700183
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 SetCapture();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700185
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186 if (CPWL_Wnd* pParent = GetParentWindow()) {
187 pParent->OnNotify(this, PNM_LBUTTONDOWN, 0,
188 PWL_MAKEDWORD(point.x, point.y));
189 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700190
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700192}
193
Tom Sepez281a9ea2016-02-26 14:24:28 -0800194FX_BOOL CPWL_CBButton::OnLButtonUp(const CFX_FloatPoint& point,
195 FX_DWORD nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 CPWL_Wnd::OnLButtonUp(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700197
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 ReleaseCapture();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201}
202
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203CPWL_ComboBox::CPWL_ComboBox()
204 : m_pEdit(NULL),
205 m_pButton(NULL),
206 m_pList(NULL),
207 m_bPopup(FALSE),
208 m_nPopupWhere(0),
209 m_nSelectItem(-1),
210 m_pFillerNotify(NULL) {}
211
212CFX_ByteString CPWL_ComboBox::GetClassName() const {
213 return "CPWL_ComboBox";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700214}
215
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM& cp) {
217 cp.dwFlags &= ~PWS_HSCROLL;
218 cp.dwFlags &= ~PWS_VSCROLL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700219}
220
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221void CPWL_ComboBox::SetFocus() {
222 if (m_pEdit)
223 m_pEdit->SetFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700224}
225
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226void CPWL_ComboBox::KillFocus() {
227 SetPopup(FALSE);
228 CPWL_Wnd::KillFocus();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229}
230
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231CFX_WideString CPWL_ComboBox::GetText() const {
232 if (m_pEdit) {
233 return m_pEdit->GetText();
234 }
235 return CFX_WideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700236}
237
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238void CPWL_ComboBox::SetText(const FX_WCHAR* text) {
239 if (m_pEdit)
240 m_pEdit->SetText(text);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700241}
242
Dan Sinclair3ebd1212016-03-09 09:59:23 -0500243void CPWL_ComboBox::AddString(const FX_WCHAR* str) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 if (m_pList)
Dan Sinclair3ebd1212016-03-09 09:59:23 -0500245 m_pList->AddString(str);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700246}
247
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248int32_t CPWL_ComboBox::GetSelect() const {
249 return m_nSelectItem;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700250}
251
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252void CPWL_ComboBox::SetSelect(int32_t nItemIndex) {
253 if (m_pList)
254 m_pList->Select(nItemIndex);
255
256 m_pEdit->SetText(m_pList->GetText().c_str());
257
258 m_nSelectItem = nItemIndex;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700259}
260
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261void CPWL_ComboBox::SetEditSel(int32_t nStartChar, int32_t nEndChar) {
262 if (m_pEdit) {
263 m_pEdit->SetSel(nStartChar, nEndChar);
264 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700265}
266
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700267void CPWL_ComboBox::GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const {
268 nStartChar = -1;
269 nEndChar = -1;
270
271 if (m_pEdit) {
272 m_pEdit->GetSel(nStartChar, nEndChar);
273 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700274}
275
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276void CPWL_ComboBox::Clear() {
277 if (m_pEdit) {
278 m_pEdit->Clear();
279 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700280}
281
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) {
283 CreateEdit(cp);
284 CreateButton(cp);
285 CreateListBox(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700286}
287
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) {
289 if (!m_pEdit) {
290 m_pEdit = new CPWL_CBEdit;
291 m_pEdit->AttachFFLData(m_pFormFiller);
292
293 PWL_CREATEPARAM ecp = cp;
294 ecp.pParentWnd = this;
295 ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER |
296 PES_AUTOSCROLL | PES_UNDO;
297
298 if (HasFlag(PWS_AUTOFONTSIZE))
299 ecp.dwFlags |= PWS_AUTOFONTSIZE;
300
301 if (!HasFlag(PCBS_ALLOWCUSTOMTEXT))
302 ecp.dwFlags |= PWS_READONLY;
303
Tom Sepez281a9ea2016-02-26 14:24:28 -0800304 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305 ecp.dwBorderWidth = 0;
306 ecp.nBorderStyle = PBS_SOLID;
307
308 m_pEdit->Create(ecp);
309 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700310}
311
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) {
313 if (!m_pButton) {
314 m_pButton = new CPWL_CBButton;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700315
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316 PWL_CREATEPARAM bcp = cp;
317 bcp.pParentWnd = this;
318 bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND;
319 bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR;
320 bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
321 bcp.dwBorderWidth = 2;
322 bcp.nBorderStyle = PBS_BEVELED;
323 bcp.eCursorType = FXCT_ARROW;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700324
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325 m_pButton->Create(bcp);
326 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700327}
328
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) {
330 if (!m_pList) {
331 m_pList = new CPWL_CBListBox;
332 m_pList->AttachFFLData(m_pFormFiller);
333 PWL_CREATEPARAM lcp = cp;
334 lcp.pParentWnd = this;
335 lcp.dwFlags =
336 PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL;
337 lcp.nBorderStyle = PBS_SOLID;
338 lcp.dwBorderWidth = 1;
339 lcp.eCursorType = FXCT_ARROW;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800340 lcp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700341
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342 if (cp.dwFlags & PWS_AUTOFONTSIZE)
343 lcp.fFontSize = PWLCB_DEFAULTFONTSIZE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700344 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345 lcp.fFontSize = cp.fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700346
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700347 if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT)
348 lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
349
350 if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT)
351 lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
352
353 m_pList->Create(lcp);
354 }
355}
356
357void CPWL_ComboBox::RePosChildWnd() {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800358 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359
360 if (m_bPopup) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800361 CFX_FloatRect rclient = GetClientRect();
362 CFX_FloatRect rcButton = rclient;
363 CFX_FloatRect rcEdit = rcClient;
364 CFX_FloatRect rcList = CPWL_Wnd::GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365
366 FX_FLOAT fOldWindowHeight = m_rcOldWindow.Height();
367 FX_FLOAT fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2;
368
369 switch (m_nPopupWhere) {
370 case 0:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700371 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700372
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373 if (rcButton.left < rclient.left)
374 rcButton.left = rclient.left;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700375
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376 rcButton.bottom = rcButton.top - fOldClientHeight;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700377
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700378 rcEdit.right = rcButton.left - 1.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700379
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380 if (rcEdit.left < rclient.left)
381 rcEdit.left = rclient.left;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700382
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700383 if (rcEdit.right < rcEdit.left)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384 rcEdit.right = rcEdit.left;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700385
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386 rcEdit.bottom = rcEdit.top - fOldClientHeight;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700387
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 rcList.top -= fOldWindowHeight;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700390 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391 case 1:
392 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
393
394 if (rcButton.left < rclient.left)
395 rcButton.left = rclient.left;
396
397 rcButton.top = rcButton.bottom + fOldClientHeight;
398
399 rcEdit.right = rcButton.left - 1.0f;
400
401 if (rcEdit.left < rclient.left)
402 rcEdit.left = rclient.left;
403
404 if (rcEdit.right < rcEdit.left)
405 rcEdit.right = rcEdit.left;
406
407 rcEdit.top = rcEdit.bottom + fOldClientHeight;
408
409 rcList.bottom += fOldWindowHeight;
410
411 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700412 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700413
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414 if (m_pButton)
415 m_pButton->Move(rcButton, TRUE, FALSE);
416
417 if (m_pEdit)
418 m_pEdit->Move(rcEdit, TRUE, FALSE);
419
420 if (m_pList) {
421 m_pList->SetVisible(TRUE);
422 m_pList->Move(rcList, TRUE, FALSE);
423 m_pList->ScrollToListItem(m_nSelectItem);
424 }
425 } else {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800426 CFX_FloatRect rcButton = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427
428 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
429
430 if (rcButton.left < rcClient.left)
431 rcButton.left = rcClient.left;
432
433 if (m_pButton)
434 m_pButton->Move(rcButton, TRUE, FALSE);
435
Tom Sepez281a9ea2016-02-26 14:24:28 -0800436 CFX_FloatRect rcEdit = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 rcEdit.right = rcButton.left - 1.0f;
438
439 if (rcEdit.left < rcClient.left)
440 rcEdit.left = rcClient.left;
441
442 if (rcEdit.right < rcEdit.left)
443 rcEdit.right = rcEdit.left;
444
445 if (m_pEdit)
446 m_pEdit->Move(rcEdit, TRUE, FALSE);
447
448 if (m_pList)
449 m_pList->SetVisible(FALSE);
450 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700451}
452
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453void CPWL_ComboBox::SelectAll() {
454 if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT))
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700455 m_pEdit->SelectAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700456}
457
Tom Sepez281a9ea2016-02-26 14:24:28 -0800458CFX_FloatRect CPWL_ComboBox::GetFocusRect() const {
459 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700460}
461
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462void CPWL_ComboBox::SetPopup(FX_BOOL bPopup) {
463 if (!m_pList)
464 return;
465 if (bPopup == m_bPopup)
466 return;
467 FX_FLOAT fListHeight = m_pList->GetContentRect().Height();
468 if (!IsFloatBigger(fListHeight, 0.0f))
469 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700470
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 if (bPopup) {
472 if (m_pFillerNotify) {
Tom Sepez51da0932015-11-25 16:05:49 -0800473#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474 FX_BOOL bExit = FALSE;
475 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, 0);
476 if (bExit)
477 return;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800478#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 int32_t nWhere = 0;
480 FX_FLOAT fPopupRet = 0.0f;
481 FX_FLOAT fPopupMin = 0.0f;
482 if (m_pList->GetCount() > 3)
483 fPopupMin =
484 m_pList->GetFirstHeight() * 3 + m_pList->GetBorderWidth() * 2;
485 FX_FLOAT fPopupMax = fListHeight + m_pList->GetBorderWidth() * 2;
486 m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax,
487 nWhere, fPopupRet);
488
489 if (IsFloatBigger(fPopupRet, 0.0f)) {
490 m_bPopup = bPopup;
491
Tom Sepez281a9ea2016-02-26 14:24:28 -0800492 CFX_FloatRect rcWindow = CPWL_Wnd::GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 m_rcOldWindow = rcWindow;
494 switch (nWhere) {
495 default:
496 case 0:
497 rcWindow.bottom -= fPopupRet;
498 break;
499 case 1:
500 rcWindow.top += fPopupRet;
501 break;
502 }
503
504 m_nPopupWhere = nWhere;
505 Move(rcWindow, TRUE, TRUE);
Tom Sepez51da0932015-11-25 16:05:49 -0800506#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 bExit = FALSE;
508 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, 0);
509 if (bExit)
510 return;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800511#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512 }
513 }
514 } else {
515 m_bPopup = bPopup;
516 Move(m_rcOldWindow, TRUE, TRUE);
517 }
518}
519
Tom Sepez62a70f92016-03-21 15:00:20 -0700520FX_BOOL CPWL_ComboBox::OnKeyDown(uint16_t nChar, FX_DWORD nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 if (!m_pList)
522 return FALSE;
523 if (!m_pEdit)
524 return FALSE;
525
526 m_nSelectItem = -1;
527
528 switch (nChar) {
529 case FWL_VKEY_Up:
530 if (m_pList->GetCurSel() > 0) {
531 FX_BOOL bExit = FALSE;
Tom Sepez51da0932015-11-25 16:05:49 -0800532#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 if (m_pFillerNotify) {
534 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
535 if (bExit)
536 return FALSE;
537 bExit = FALSE;
538 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
539 if (bExit)
540 return FALSE;
541 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800542#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543 if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) {
544 if (bExit)
545 return FALSE;
546 SetSelectText();
547 }
548 }
549 return TRUE;
550 case FWL_VKEY_Down:
551 if (m_pList->GetCurSel() < m_pList->GetCount() - 1) {
552 FX_BOOL bExit = FALSE;
Tom Sepez51da0932015-11-25 16:05:49 -0800553#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700554 if (m_pFillerNotify) {
555 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
556 if (bExit)
557 return FALSE;
558 bExit = FALSE;
559 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
560 if (bExit)
561 return FALSE;
562 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800563#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564 if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) {
565 if (bExit)
566 return FALSE;
567 SetSelectText();
568 }
569 }
570 return TRUE;
571 }
572
573 if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
574 return m_pEdit->OnKeyDown(nChar, nFlag);
575
576 return FALSE;
577}
578
Tom Sepez62a70f92016-03-21 15:00:20 -0700579FX_BOOL CPWL_ComboBox::OnChar(uint16_t nChar, FX_DWORD nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 if (!m_pList)
581 return FALSE;
582
583 if (!m_pEdit)
584 return FALSE;
585
586 m_nSelectItem = -1;
587 if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
588 return m_pEdit->OnChar(nChar, nFlag);
589
590 FX_BOOL bExit = FALSE;
Tom Sepez51da0932015-11-25 16:05:49 -0800591#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592 if (m_pFillerNotify) {
593 m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
594 if (bExit)
595 return FALSE;
596
597 m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
598 if (bExit)
599 return FALSE;
600 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800601#endif // PDF_ENABLE_XFA
Tom Sepezdfbf8e72015-10-14 14:17:26 -0700602 return m_pList->OnCharWithExit(nChar, bExit, nFlag) ? bExit : FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603}
604
605void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd,
606 FX_DWORD msg,
607 intptr_t wParam,
608 intptr_t lParam) {
609 switch (msg) {
610 case PNM_LBUTTONDOWN:
611 if (pWnd == m_pButton) {
612 SetPopup(!m_bPopup);
613 return;
614 }
615 break;
616 case PNM_LBUTTONUP:
617 if (m_pEdit && m_pList) {
618 if (pWnd == m_pList) {
619 SetSelectText();
620 SelectAll();
621 m_pEdit->SetFocus();
622 SetPopup(FALSE);
623 return;
624 }
625 }
626 }
627
628 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
629}
630
631FX_BOOL CPWL_ComboBox::IsPopup() const {
632 return m_bPopup;
633}
634
635void CPWL_ComboBox::SetSelectText() {
636 CFX_WideString swText = m_pList->GetText();
637 m_pEdit->SelectAll();
638 m_pEdit->ReplaceSel(m_pList->GetText().c_str());
639 m_pEdit->SelectAll();
640
641 m_nSelectItem = m_pList->GetCurSel();
642}
643
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) {
645 m_pFillerNotify = pNotify;
646
647 if (m_pEdit)
648 m_pEdit->SetFillerNotify(pNotify);
649
650 if (m_pList)
651 m_pList->SetFillerNotify(pNotify);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700652}