Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/pdfwindow/PDFWindow.h" 7 #include "../../include/pdfwindow/PDFWindow.h"
8 #include "../../include/pdfwindow/PWL_Wnd.h" 8 #include "../../include/pdfwindow/PWL_Wnd.h"
9 #include "../../include/pdfwindow/PWL_EditCtrl.h" 9 #include "../../include/pdfwindow/PWL_EditCtrl.h"
10 #include "../../include/pdfwindow/PWL_Edit.h" 10 #include "../../include/pdfwindow/PWL_Edit.h"
11 #include "../../include/pdfwindow/PWL_ListBox.h" 11 #include "../../include/pdfwindow/PWL_ListBox.h"
12 #include "../../include/pdfwindow/PWL_ComboBox.h" 12 #include "../../include/pdfwindow/PWL_ComboBox.h"
13 #include "../../include/pdfwindow/PWL_Utils.h" 13 #include "../../include/pdfwindow/PWL_Utils.h"
14 14
15 #define PWLCB_DEFAULTFONTSIZE 12.0f 15 #define PWLCB_DEFAULTFONTSIZE 12.0f
16 16
17 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) 17 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
18 #define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) 18 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
19 #define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) 19 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
20 #define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb)) 20 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
21
22 21
23 /* ---------------------------- CPWL_CBListBox ---------------------------- */ 22 /* ---------------------------- CPWL_CBListBox ---------------------------- */
24 23
25 FX_BOOL CPWL_CBListBox::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag) 24 FX_BOOL CPWL_CBListBox::OnLButtonUp(const CPDF_Point& point, FX_DWORD nFlag) {
26 { 25 CPWL_Wnd::OnLButtonUp(point, nFlag);
27 CPWL_Wnd::OnLButtonUp(point,nFlag); 26
28 27 if (m_bMouseDown) {
29 if (m_bMouseDown) 28 ReleaseCapture();
30 { 29 m_bMouseDown = FALSE;
31 ReleaseCapture(); 30
32 m_bMouseDown = FALSE; 31 if (ClientHitTest(point)) {
33 32 if (CPWL_Wnd* pParent = GetParentWindow()) {
34 if (ClientHitTest(point)) 33 pParent->OnNotify(this, PNM_LBUTTONUP, 0,
35 { 34 PWL_MAKEDWORD(point.x, point.y));
36 if (CPWL_Wnd * pParent = GetParentWindow()) 35 }
37 { 36
38 pParent->OnNotify(this,PNM_LBUTTONUP,0,PWL_MAKEDWORD(point.x,poi nt.y)); 37 FX_BOOL bExit = FALSE;
39 } 38 OnNotifySelChanged(FALSE, bExit, nFlag);
40 39 if (bExit)
41 FX_BOOL bExit = FALSE; 40 return FALSE;
42 OnNotifySelChanged(FALSE,bExit, nFlag);
43 if (bExit) return FALSE;
44 }
45 } 41 }
46 42 }
47 return TRUE; 43
48 } 44 return TRUE;
49 45 }
50 FX_BOOL CPWL_CBListBox::OnKeyDownWithExit(FX_WORD nChar, FX_BOOL & bExit, FX_DWO RD nFlag) 46
51 { 47 FX_BOOL CPWL_CBListBox::OnKeyDownWithExit(FX_WORD nChar,
52 if (!m_pList) return FALSE; 48 FX_BOOL& bExit,
53 49 FX_DWORD nFlag) {
54 switch (nChar) 50 if (!m_pList)
55 { 51 return FALSE;
52
53 switch (nChar) {
56 default: 54 default:
57 return FALSE; 55 return FALSE;
58 case FWL_VKEY_Up: 56 case FWL_VKEY_Up:
59 case FWL_VKEY_Down: 57 case FWL_VKEY_Down:
60 case FWL_VKEY_Home: 58 case FWL_VKEY_Home:
61 case FWL_VKEY_Left: 59 case FWL_VKEY_Left:
62 case FWL_VKEY_End: 60 case FWL_VKEY_End:
63 case FWL_VKEY_Right: 61 case FWL_VKEY_Right:
62 break;
63 }
64
65 switch (nChar) {
66 case FWL_VKEY_Up:
67 m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
68 break;
69 case FWL_VKEY_Down:
70 m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
71 break;
72 case FWL_VKEY_Home:
73 m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
74 break;
75 case FWL_VKEY_Left:
76 m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
77 break;
78 case FWL_VKEY_End:
79 m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
80 break;
81 case FWL_VKEY_Right:
82 m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
83 break;
84 case FWL_VKEY_Delete:
85 break;
86 }
87
88 OnNotifySelChanged(TRUE, bExit, nFlag);
89
90 return TRUE;
91 }
92
93 FX_BOOL CPWL_CBListBox::OnCharWithExit(FX_WORD nChar,
94 FX_BOOL& bExit,
95 FX_DWORD nFlag) {
96 if (!m_pList)
97 return FALSE;
98
99 if (!m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)))
100 return FALSE;
101
102 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow()) {
103 pComboBox->SetSelectText();
104 }
105
106 OnNotifySelChanged(TRUE, bExit, nFlag);
107
108 return TRUE;
109 }
110
111 /* ---------------------------- CPWL_CBButton ---------------------------- */
112
113 void CPWL_CBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
114 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
115
116 CPDF_Rect rectWnd = CPWL_Wnd::GetWindowRect();
117
118 if (IsVisible() && !rectWnd.IsEmpty()) {
119 CFX_ByteTextBuf sButton;
120
121 CPDF_Point ptCenter = GetCenterPoint();
122
123 CPDF_Point pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,
124 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
125 CPDF_Point pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,
126 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
127 CPDF_Point pt3(ptCenter.x,
128 ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
129
130 if (IsFloatBigger(rectWnd.right - rectWnd.left,
131 PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) &&
132 IsFloatBigger(rectWnd.top - rectWnd.bottom,
133 PWL_CBBUTTON_TRIANGLE_HALFLEN)) {
134 sButton << "0 g\n";
135 sButton << pt1.x << " " << pt1.y << " m\n";
136 sButton << pt2.x << " " << pt2.y << " l\n";
137 sButton << pt3.x << " " << pt3.y << " l\n";
138 sButton << pt1.x << " " << pt1.y << " l f\n";
139
140 sAppStream << "q\n" << sButton << "Q\n";
141 }
142 }
143 }
144
145 void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice,
146 CPDF_Matrix* pUser2Device) {
147 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
148
149 CPDF_Rect rectWnd = CPWL_Wnd::GetWindowRect();
150
151 if (IsVisible() && !rectWnd.IsEmpty()) {
152 CPDF_Point ptCenter = GetCenterPoint();
153
154 CPDF_Point pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,
155 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
156 CPDF_Point pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,
157 ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
158 CPDF_Point pt3(ptCenter.x,
159 ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
160
161 if (IsFloatBigger(rectWnd.right - rectWnd.left,
162 PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) &&
163 IsFloatBigger(rectWnd.top - rectWnd.bottom,
164 PWL_CBBUTTON_TRIANGLE_HALFLEN)) {
165 CFX_PathData path;
166
167 path.SetPointCount(4);
168 path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
169 path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
170 path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
171 path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
172
173 pDevice->DrawPath(&path, pUser2Device, NULL,
174 CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_BLACKCOLOR,
175 GetTransparency()),
176 0, FXFILL_ALTERNATE);
177 }
178 }
179 }
180
181 FX_BOOL CPWL_CBButton::OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag) {
182 CPWL_Wnd::OnLButtonDown(point, nFlag);
183
184 SetCapture();
185
186 if (CPWL_Wnd* pParent = GetParentWindow()) {
187 pParent->OnNotify(this, PNM_LBUTTONDOWN, 0,
188 PWL_MAKEDWORD(point.x, point.y));
189 }
190
191 return TRUE;
192 }
193
194 FX_BOOL CPWL_CBButton::OnLButtonUp(const CPDF_Point& point, FX_DWORD nFlag) {
195 CPWL_Wnd::OnLButtonUp(point, nFlag);
196
197 ReleaseCapture();
198
199 return TRUE;
200 }
201
202 /* ---------------------------- CPWL_ComboBox ---------------------------- */
203
204 CPWL_ComboBox::CPWL_ComboBox()
205 : m_pEdit(NULL),
206 m_pButton(NULL),
207 m_pList(NULL),
208 m_bPopup(FALSE),
209 m_nPopupWhere(0),
210 m_nSelectItem(-1),
211 m_pFillerNotify(NULL) {}
212
213 CFX_ByteString CPWL_ComboBox::GetClassName() const {
214 return "CPWL_ComboBox";
215 }
216
217 void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM& cp) {
218 cp.dwFlags &= ~PWS_HSCROLL;
219 cp.dwFlags &= ~PWS_VSCROLL;
220 }
221
222 void CPWL_ComboBox::SetFocus() {
223 if (m_pEdit)
224 m_pEdit->SetFocus();
225 }
226
227 void CPWL_ComboBox::KillFocus() {
228 SetPopup(FALSE);
229 CPWL_Wnd::KillFocus();
230 }
231
232 CFX_WideString CPWL_ComboBox::GetText() const {
233 if (m_pEdit) {
234 return m_pEdit->GetText();
235 }
236 return CFX_WideString();
237 }
238
239 void CPWL_ComboBox::SetText(const FX_WCHAR* text) {
240 if (m_pEdit)
241 m_pEdit->SetText(text);
242 }
243
244 void CPWL_ComboBox::AddString(const FX_WCHAR* string) {
245 if (m_pList)
246 m_pList->AddString(string);
247 }
248
249 int32_t CPWL_ComboBox::GetSelect() const {
250 return m_nSelectItem;
251 }
252
253 void CPWL_ComboBox::SetSelect(int32_t nItemIndex) {
254 if (m_pList)
255 m_pList->Select(nItemIndex);
256
257 m_pEdit->SetText(m_pList->GetText().c_str());
258
259 m_nSelectItem = nItemIndex;
260 }
261
262 void CPWL_ComboBox::SetEditSel(int32_t nStartChar, int32_t nEndChar) {
263 if (m_pEdit) {
264 m_pEdit->SetSel(nStartChar, nEndChar);
265 }
266 }
267
268 void CPWL_ComboBox::GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const {
269 nStartChar = -1;
270 nEndChar = -1;
271
272 if (m_pEdit) {
273 m_pEdit->GetSel(nStartChar, nEndChar);
274 }
275 }
276
277 void CPWL_ComboBox::Clear() {
278 if (m_pEdit) {
279 m_pEdit->Clear();
280 }
281 }
282
283 void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) {
284 CreateEdit(cp);
285 CreateButton(cp);
286 CreateListBox(cp);
287 }
288
289 void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) {
290 if (!m_pEdit) {
291 m_pEdit = new CPWL_CBEdit;
292 m_pEdit->AttachFFLData(m_pFormFiller);
293
294 PWL_CREATEPARAM ecp = cp;
295 ecp.pParentWnd = this;
296 ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER |
297 PES_AUTOSCROLL | PES_UNDO;
298
299 if (HasFlag(PWS_AUTOFONTSIZE))
300 ecp.dwFlags |= PWS_AUTOFONTSIZE;
301
302 if (!HasFlag(PCBS_ALLOWCUSTOMTEXT))
303 ecp.dwFlags |= PWS_READONLY;
304
305 ecp.rcRectWnd = CPDF_Rect(0, 0, 0, 0);
306 ecp.dwBorderWidth = 0;
307 ecp.nBorderStyle = PBS_SOLID;
308
309 m_pEdit->Create(ecp);
310 }
311 }
312
313 void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) {
314 if (!m_pButton) {
315 m_pButton = new CPWL_CBButton;
316
317 PWL_CREATEPARAM bcp = cp;
318 bcp.pParentWnd = this;
319 bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND;
320 bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR;
321 bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
322 bcp.dwBorderWidth = 2;
323 bcp.nBorderStyle = PBS_BEVELED;
324 bcp.eCursorType = FXCT_ARROW;
325
326 m_pButton->Create(bcp);
327 }
328 }
329
330 void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) {
331 if (!m_pList) {
332 m_pList = new CPWL_CBListBox;
333 m_pList->AttachFFLData(m_pFormFiller);
334 PWL_CREATEPARAM lcp = cp;
335 lcp.pParentWnd = this;
336 lcp.dwFlags =
337 PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL;
338 lcp.nBorderStyle = PBS_SOLID;
339 lcp.dwBorderWidth = 1;
340 lcp.eCursorType = FXCT_ARROW;
341 lcp.rcRectWnd = CPDF_Rect(0, 0, 0, 0);
342
343 if (cp.dwFlags & PWS_AUTOFONTSIZE)
344 lcp.fFontSize = PWLCB_DEFAULTFONTSIZE;
345 else
346 lcp.fFontSize = cp.fFontSize;
347
348 if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT)
349 lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
350
351 if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT)
352 lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
353
354 m_pList->Create(lcp);
355 }
356 }
357
358 void CPWL_ComboBox::RePosChildWnd() {
359 CPDF_Rect rcClient = GetClientRect();
360
361 if (m_bPopup) {
362 CPDF_Rect rclient = GetClientRect();
363 CPDF_Rect rcButton = rclient;
364 CPDF_Rect rcEdit = rcClient;
365 CPDF_Rect rcList = CPWL_Wnd::GetWindowRect();
366
367 FX_FLOAT fOldWindowHeight = m_rcOldWindow.Height();
368 FX_FLOAT fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2;
369
370 switch (m_nPopupWhere) {
371 case 0:
372 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
373
374 if (rcButton.left < rclient.left)
375 rcButton.left = rclient.left;
376
377 rcButton.bottom = rcButton.top - 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.bottom = rcEdit.top - fOldClientHeight;
388
389 rcList.top -= fOldWindowHeight;
390
391 break;
392 case 1:
393 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
394
395 if (rcButton.left < rclient.left)
396 rcButton.left = rclient.left;
397
398 rcButton.top = rcButton.bottom + fOldClientHeight;
399
400 rcEdit.right = rcButton.left - 1.0f;
401
402 if (rcEdit.left < rclient.left)
403 rcEdit.left = rclient.left;
404
405 if (rcEdit.right < rcEdit.left)
406 rcEdit.right = rcEdit.left;
407
408 rcEdit.top = rcEdit.bottom + fOldClientHeight;
409
410 rcList.bottom += fOldWindowHeight;
411
64 break; 412 break;
65 } 413 }
66 414
67 switch (nChar) 415 if (m_pButton)
68 { 416 m_pButton->Move(rcButton, TRUE, FALSE);
69 case FWL_VKEY_Up: 417
70 m_pList->OnVK_UP(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag)); 418 if (m_pEdit)
71 break; 419 m_pEdit->Move(rcEdit, TRUE, FALSE);
72 case FWL_VKEY_Down: 420
73 m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag)); 421 if (m_pList) {
74 break; 422 m_pList->SetVisible(TRUE);
75 case FWL_VKEY_Home: 423 m_pList->Move(rcList, TRUE, FALSE);
76 m_pList->OnVK_HOME(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag)); 424 m_pList->ScrollToListItem(m_nSelectItem);
77 break;
78 case FWL_VKEY_Left:
79 m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
80 break;
81 case FWL_VKEY_End:
82 m_pList->OnVK_END(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
83 break;
84 case FWL_VKEY_Right:
85 m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
86 break;
87 case FWL_VKEY_Delete:
88 break;
89 } 425 }
90 426 } else {
91 OnNotifySelChanged(TRUE,bExit, nFlag); 427 CPDF_Rect rcButton = rcClient;
92 428
93 return TRUE; 429 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
94 } 430
95 431 if (rcButton.left < rcClient.left)
96 FX_BOOL CPWL_CBListBox::OnCharWithExit(FX_WORD nChar, FX_BOOL & bExit, FX_DWORD nFlag) 432 rcButton.left = rcClient.left;
97 { 433
98 if (!m_pList) return FALSE; 434 if (m_pButton)
99 435 m_pButton->Move(rcButton, TRUE, FALSE);
100 if (!m_pList->OnChar(nChar,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag))) retu rn FALSE; 436
101 437 CPDF_Rect rcEdit = rcClient;
102 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow()) 438 rcEdit.right = rcButton.left - 1.0f;
103 { 439
104 pComboBox->SetSelectText(); 440 if (rcEdit.left < rcClient.left)
105 } 441 rcEdit.left = rcClient.left;
106 442
107 OnNotifySelChanged(TRUE,bExit,nFlag); 443 if (rcEdit.right < rcEdit.left)
108 444 rcEdit.right = rcEdit.left;
109 return TRUE; 445
110 }
111
112 /* ---------------------------- CPWL_CBButton ---------------------------- */
113
114 void CPWL_CBButton::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
115 {
116 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
117
118 CPDF_Rect rectWnd = CPWL_Wnd::GetWindowRect();
119
120 if (IsVisible() && !rectWnd.IsEmpty())
121 {
122 CFX_ByteTextBuf sButton;
123
124 CPDF_Point ptCenter = GetCenterPoint();
125
126 CPDF_Point pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + P WL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
127 CPDF_Point pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + P WL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
128 CPDF_Point pt3(ptCenter.x,ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0 .5f);
129
130 if (IsFloatBigger(rectWnd.right - rectWnd.left,PWL_CBBUTTON_TRIANGLE_HAL FLEN * 2)
131 &&
132 IsFloatBigger(rectWnd.top - rectWnd.bottom,PWL_CBBUTTON_TRIANGLE_HAL FLEN)
133 )
134 {
135 sButton << "0 g\n";
136 sButton << pt1.x << " " << pt1.y << " m\n";
137 sButton << pt2.x << " " << pt2.y << " l\n";
138 sButton << pt3.x << " " << pt3.y << " l\n";
139 sButton << pt1.x << " " << pt1.y << " l f\n";
140
141 sAppStream << "q\n" << sButton << "Q\n";
142 }
143 }
144 }
145
146 void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* p User2Device)
147 {
148 CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
149
150 CPDF_Rect rectWnd = CPWL_Wnd::GetWindowRect();
151
152 if (IsVisible() && !rectWnd.IsEmpty())
153 {
154 CPDF_Point ptCenter = GetCenterPoint();
155
156 CPDF_Point pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + P WL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
157 CPDF_Point pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN,ptCenter.y + P WL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f);
158 CPDF_Point pt3(ptCenter.x,ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0 .5f);
159
160 if (IsFloatBigger(rectWnd.right - rectWnd.left,PWL_CBBUTTON_TRIANGLE_HAL FLEN * 2)
161 &&
162 IsFloatBigger(rectWnd.top - rectWnd.bottom,PWL_CBBUTTON_TRIANGLE_HAL FLEN)
163 )
164 {
165 CFX_PathData path;
166
167 path.SetPointCount(4);
168 path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO);
169 path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO);
170 path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO);
171 path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO);
172
173 pDevice->DrawPath(&path, pUser2Device, NULL,
174 CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_BLACKCOLOR,GetTranspar ency()),
175 0, FXFILL_ALTERNATE);
176 }
177 }
178 }
179
180 FX_BOOL CPWL_CBButton::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
181 {
182 CPWL_Wnd::OnLButtonDown(point,nFlag);
183
184 SetCapture();
185
186 if (CPWL_Wnd * pParent = GetParentWindow())
187 {
188 pParent->OnNotify(this,PNM_LBUTTONDOWN,0,PWL_MAKEDWORD(point.x,point.y)) ;
189 }
190
191 return TRUE;
192 }
193
194 FX_BOOL CPWL_CBButton::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
195 {
196 CPWL_Wnd::OnLButtonUp(point, nFlag);
197
198 ReleaseCapture();
199
200 return TRUE;
201 }
202
203 /* ---------------------------- CPWL_ComboBox ---------------------------- */
204
205 CPWL_ComboBox::CPWL_ComboBox() : m_pEdit(NULL),
206 m_pButton(NULL),
207 m_pList(NULL),
208 m_bPopup(FALSE),
209 m_nPopupWhere(0),
210 m_nSelectItem(-1),
211 m_pFillerNotify(NULL)
212 {
213 }
214
215 CFX_ByteString CPWL_ComboBox::GetClassName() const
216 {
217 return "CPWL_ComboBox";
218 }
219
220 void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM & cp)
221 {
222 cp.dwFlags &= ~PWS_HSCROLL;
223 cp.dwFlags &= ~PWS_VSCROLL;
224 }
225
226 void CPWL_ComboBox::SetFocus()
227 {
228 if (m_pEdit) 446 if (m_pEdit)
229 m_pEdit->SetFocus(); 447 m_pEdit->Move(rcEdit, TRUE, FALSE);
230 } 448
231
232 void CPWL_ComboBox::KillFocus()
233 {
234 SetPopup(FALSE);
235 CPWL_Wnd::KillFocus();
236 }
237
238 CFX_WideString CPWL_ComboBox::GetText() const
239 {
240 if (m_pEdit)
241 {
242 return m_pEdit->GetText();
243 }
244 return CFX_WideString();
245 }
246
247 void CPWL_ComboBox::SetText(const FX_WCHAR* text)
248 {
249 if (m_pEdit)
250 m_pEdit->SetText(text);
251 }
252
253 void CPWL_ComboBox::AddString(const FX_WCHAR* string)
254 {
255 if (m_pList) 449 if (m_pList)
256 m_pList->AddString(string); 450 m_pList->SetVisible(FALSE);
257 } 451 }
258 452 }
259 int32_t CPWL_ComboBox::GetSelect() const 453
260 { 454 void CPWL_ComboBox::SelectAll() {
261 return m_nSelectItem; 455 if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT))
262 } 456 m_pEdit->SelectAll();
263 457 }
264 void CPWL_ComboBox::SetSelect(int32_t nItemIndex) 458
265 { 459 CPDF_Rect CPWL_ComboBox::GetFocusRect() const {
266 if (m_pList) 460 return CPDF_Rect();
267 m_pList->Select(nItemIndex); 461 }
268 462
269 m_pEdit->SetText(m_pList->GetText().c_str()); 463 void CPWL_ComboBox::SetPopup(FX_BOOL bPopup) {
270 464 if (!m_pList)
271 m_nSelectItem = nItemIndex; 465 return;
272 } 466 if (bPopup == m_bPopup)
273 467 return;
274 void CPWL_ComboBox::SetEditSel(int32_t nStartChar,int32_t nEndChar) 468 FX_FLOAT fListHeight = m_pList->GetContentRect().Height();
275 { 469 if (!IsFloatBigger(fListHeight, 0.0f))
276 if (m_pEdit) 470 return;
277 { 471
278 m_pEdit->SetSel(nStartChar,nEndChar); 472 if (bPopup) {
279 } 473 if (m_pFillerNotify) {
280 } 474 int32_t nWhere = 0;
281 475 FX_FLOAT fPopupRet = 0.0f;
282 void CPWL_ComboBox::GetEditSel(int32_t & nStartChar, int32_t & nEndChar) const 476 FX_FLOAT fPopupMin = 0.0f;
283 { 477 if (m_pList->GetCount() > 3)
284 nStartChar = -1; 478 fPopupMin =
285 nEndChar = -1; 479 m_pList->GetFirstHeight() * 3 + m_pList->GetBorderWidth() * 2;
286 480 FX_FLOAT fPopupMax = fListHeight + m_pList->GetBorderWidth() * 2;
287 if (m_pEdit) 481 m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax,
288 { 482 nWhere, fPopupRet);
289 m_pEdit->GetSel(nStartChar,nEndChar); 483
290 } 484 if (IsFloatBigger(fPopupRet, 0.0f)) {
291 } 485 m_bPopup = bPopup;
292 486
293 void CPWL_ComboBox::Clear() 487 CPDF_Rect rcWindow = CPWL_Wnd::GetWindowRect();
294 { 488 m_rcOldWindow = rcWindow;
295 if (m_pEdit) 489 switch (nWhere) {
296 { 490 default:
297 m_pEdit->Clear(); 491 case 0:
298 } 492 rcWindow.bottom -= fPopupRet;
299 }
300
301 void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM & cp)
302 {
303 CreateEdit(cp);
304 CreateButton(cp);
305 CreateListBox(cp);
306 }
307
308 void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM & cp)
309 {
310 if (!m_pEdit)
311 {
312 m_pEdit = new CPWL_CBEdit;
313 m_pEdit->AttachFFLData(m_pFormFiller);
314
315 PWL_CREATEPARAM ecp = cp;
316 ecp.pParentWnd = this;
317 ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | PES_A UTOSCROLL | PES_UNDO;
318
319 if (HasFlag(PWS_AUTOFONTSIZE))
320 ecp.dwFlags |= PWS_AUTOFONTSIZE;
321
322 if (!HasFlag(PCBS_ALLOWCUSTOMTEXT))
323 ecp.dwFlags |= PWS_READONLY;
324
325 ecp.rcRectWnd = CPDF_Rect(0,0,0,0);
326 ecp.dwBorderWidth = 0;
327 ecp.nBorderStyle = PBS_SOLID;
328
329 m_pEdit->Create(ecp);
330 }
331 }
332
333 void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM & cp)
334 {
335 if (!m_pButton)
336 {
337 m_pButton = new CPWL_CBButton;
338
339 PWL_CREATEPARAM bcp = cp;
340 bcp.pParentWnd = this;
341 bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND;
342 bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR;
343 bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
344 bcp.dwBorderWidth = 2;
345 bcp.nBorderStyle = PBS_BEVELED;
346 bcp.eCursorType = FXCT_ARROW;
347
348 m_pButton->Create(bcp);
349 }
350 }
351
352 void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM & cp)
353 {
354 if (!m_pList)
355 {
356 m_pList = new CPWL_CBListBox;
357 m_pList->AttachFFLData(m_pFormFiller);
358 PWL_CREATEPARAM lcp = cp;
359 lcp.pParentWnd = this;
360 lcp.dwFlags = PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL;
361 lcp.nBorderStyle = PBS_SOLID;
362 lcp.dwBorderWidth = 1;
363 lcp.eCursorType = FXCT_ARROW;
364 lcp.rcRectWnd = CPDF_Rect(0,0,0,0);
365
366 if (cp.dwFlags & PWS_AUTOFONTSIZE)
367 lcp.fFontSize = PWLCB_DEFAULTFONTSIZE;
368 else
369 lcp.fFontSize = cp.fFontSize;
370
371 if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT)
372 lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
373
374 if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT)
375 lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
376
377 m_pList->Create(lcp);
378 }
379 }
380
381 void CPWL_ComboBox::RePosChildWnd()
382 {
383 CPDF_Rect rcClient = GetClientRect();
384
385 if (m_bPopup)
386 {
387 CPDF_Rect rclient = GetClientRect();
388 CPDF_Rect rcButton = rclient;
389 CPDF_Rect rcEdit = rcClient;
390 CPDF_Rect rcList = CPWL_Wnd::GetWindowRect();
391
392 FX_FLOAT fOldWindowHeight = m_rcOldWindow.Height();
393 FX_FLOAT fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2;
394
395 switch (m_nPopupWhere)
396 {
397 case 0:
398 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH;
399
400 if (rcButton.left < rclient.left)
401 rcButton.left = rclient.left;
402
403 rcButton.bottom = rcButton.top - fOldClientHeight;
404
405 rcEdit.right = rcButton.left - 1.0f;
406
407 if (rcEdit.left < rclient.left)
408 rcEdit.left = rclient.left;
409
410 if (rcEdit.right < rcEdit.left)
411 rcEdit.right = rcEdit.left;
412
413 rcEdit.bottom = rcEdit.top - fOldClientHeight;
414
415 rcList.top -= fOldWindowHeight;
416
417 break; 493 break;
418 case 1: 494 case 1:
419 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH; 495 rcWindow.top += fPopupRet;
420
421 if (rcButton.left < rclient.left)
422 rcButton.left = rclient.left;
423
424 rcButton.top = rcButton.bottom + fOldClientHeight;
425
426 rcEdit.right = rcButton.left - 1.0f;
427
428 if (rcEdit.left < rclient.left)
429 rcEdit.left = rclient.left;
430
431 if (rcEdit.right < rcEdit.left)
432 rcEdit.right = rcEdit.left;
433
434 rcEdit.top = rcEdit.bottom + fOldClientHeight;
435
436 rcList.bottom += fOldWindowHeight;
437
438 break; 496 break;
439 } 497 }
440 498
441 if (m_pButton) 499 m_nPopupWhere = nWhere;
442 m_pButton->Move(rcButton,TRUE,FALSE); 500 Move(rcWindow, TRUE, TRUE);
443 501 }
444 if (m_pEdit) 502 }
445 m_pEdit->Move(rcEdit,TRUE,FALSE); 503 } else {
446 504 m_bPopup = bPopup;
447 if (m_pList) 505 Move(m_rcOldWindow, TRUE, TRUE);
448 { 506 }
449 m_pList->SetVisible(TRUE); 507 }
450 m_pList->Move(rcList,TRUE,FALSE); 508
451 m_pList->ScrollToListItem(m_nSelectItem); 509 FX_BOOL CPWL_ComboBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) {
510 if (!m_pList)
511 return FALSE;
512 if (!m_pEdit)
513 return FALSE;
514
515 m_nSelectItem = -1;
516
517 switch (nChar) {
518 case FWL_VKEY_Up:
519 if (m_pList->GetCurSel() > 0) {
520 FX_BOOL bExit = FALSE;
521 if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) {
522 if (bExit)
523 return FALSE;
524 SetSelectText();
452 } 525 }
453 } 526 }
454 else 527 return TRUE;
455 { 528 case FWL_VKEY_Down:
456 CPDF_Rect rcButton = rcClient; 529 if (m_pList->GetCurSel() < m_pList->GetCount() - 1) {
457 530 FX_BOOL bExit = FALSE;
458 rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH; 531 if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) {
459 532 if (bExit)
460 if (rcButton.left < rcClient.left) 533 return FALSE;
461 rcButton.left = rcClient.left; 534 SetSelectText();
462
463 if (m_pButton)
464 m_pButton->Move(rcButton,TRUE,FALSE);
465
466 CPDF_Rect rcEdit = rcClient;
467 rcEdit.right = rcButton.left - 1.0f;
468
469 if (rcEdit.left < rcClient.left)
470 rcEdit.left = rcClient.left;
471
472 if (rcEdit.right < rcEdit.left)
473 rcEdit.right = rcEdit.left;
474
475 if (m_pEdit)
476 m_pEdit->Move(rcEdit,TRUE,FALSE);
477
478 if (m_pList)
479 m_pList->SetVisible(FALSE);
480 }
481 }
482
483 void CPWL_ComboBox::SelectAll()
484 {
485 if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT))
486 m_pEdit->SelectAll();
487 }
488
489 CPDF_Rect CPWL_ComboBox::GetFocusRect() const
490 {
491 return CPDF_Rect();
492 }
493
494 void CPWL_ComboBox::SetPopup(FX_BOOL bPopup)
495 {
496 if (!m_pList) return;
497 if (bPopup == m_bPopup) return;
498 FX_FLOAT fListHeight = m_pList->GetContentRect().Height();
499 if (!IsFloatBigger(fListHeight,0.0f)) return;
500
501 if (bPopup)
502 {
503 if (m_pFillerNotify)
504 {
505 int32_t nWhere = 0;
506 FX_FLOAT fPopupRet = 0.0f;
507 FX_FLOAT fPopupMin = 0.0f;
508 if (m_pList->GetCount() > 3)
509 fPopupMin = m_pList->GetFirstHeight() * 3 + m_pList->GetBorderWi dth() * 2;
510 FX_FLOAT fPopupMax = fListHeight + m_pList->GetBorderWidth() * 2;
511 m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin,fPopup Max,nWhere,fPopupRet);
512
513 if (IsFloatBigger(fPopupRet,0.0f))
514 {
515 m_bPopup = bPopup;
516
517 CPDF_Rect rcWindow = CPWL_Wnd::GetWindowRect();
518 m_rcOldWindow = rcWindow;
519 switch (nWhere)
520 {
521 default:
522 case 0:
523 rcWindow.bottom -= fPopupRet;
524 break;
525 case 1:
526 rcWindow.top += fPopupRet;
527 break;
528 }
529
530 m_nPopupWhere = nWhere;
531 Move(rcWindow, TRUE, TRUE);
532 }
533 } 535 }
534 } 536 }
535 else 537 return TRUE;
536 { 538 }
537 m_bPopup = bPopup; 539
538 Move(m_rcOldWindow, TRUE, TRUE); 540 if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
539 } 541 return m_pEdit->OnKeyDown(nChar, nFlag);
540 } 542
541 543 return FALSE;
542 FX_BOOL CPWL_ComboBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) 544 }
543 { 545
544 if (!m_pList) return FALSE; 546 FX_BOOL CPWL_ComboBox::OnChar(FX_WORD nChar, FX_DWORD nFlag) {
545 if (!m_pEdit) return FALSE; 547 if (!m_pList)
546 548 return FALSE;
547 m_nSelectItem = -1; 549
548 550 if (!m_pEdit)
549 switch (nChar) 551 return FALSE;
550 { 552
551 case FWL_VKEY_Up: 553 m_nSelectItem = -1;
552 if (m_pList->GetCurSel() > 0) 554 if (HasFlag(PCBS_ALLOWCUSTOMTEXT))
553 { 555 return m_pEdit->OnChar(nChar, nFlag);
554 FX_BOOL bExit = FALSE; 556
555 if (m_pList->OnKeyDownWithExit(nChar,bExit,nFlag)) 557 FX_BOOL bExit = FALSE;
556 { 558 return m_pList->OnCharWithExit(nChar, bExit, nFlag) ? bExit : FALSE;
557 if (bExit) return FALSE; 559 }
558 SetSelectText(); 560
559 } 561 void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd,
562 FX_DWORD msg,
563 intptr_t wParam,
564 intptr_t lParam) {
565 switch (msg) {
566 case PNM_LBUTTONDOWN:
567 if (pWnd == m_pButton) {
568 SetPopup(!m_bPopup);
569 return;
570 }
571 break;
572 case PNM_LBUTTONUP:
573 if (m_pEdit && m_pList) {
574 if (pWnd == m_pList) {
575 SetSelectText();
576 SelectAll();
577 m_pEdit->SetFocus();
578 SetPopup(FALSE);
579 return;
560 } 580 }
561 return TRUE; 581 }
562 case FWL_VKEY_Down: 582 }
563 if (m_pList->GetCurSel() < m_pList->GetCount() - 1) 583
564 { 584 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
565 FX_BOOL bExit = FALSE; 585 }
566 if (m_pList->OnKeyDownWithExit(nChar,bExit,nFlag)) 586
567 { 587 FX_BOOL CPWL_ComboBox::IsPopup() const {
568 if (bExit) return FALSE; 588 return m_bPopup;
569 SetSelectText(); 589 }
570 } 590
571 } 591 void CPWL_ComboBox::SetSelectText() {
572 return TRUE; 592 CFX_WideString swText = m_pList->GetText();
573 } 593 m_pEdit->SelectAll();
574 594 m_pEdit->ReplaceSel(m_pList->GetText().c_str());
575 if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) 595 m_pEdit->SelectAll();
576 return m_pEdit->OnKeyDown(nChar,nFlag); 596
577 597 m_nSelectItem = m_pList->GetCurSel();
578 return FALSE; 598 }
579 } 599
580 600 FX_BOOL CPWL_ComboBox::IsModified() const {
581 FX_BOOL CPWL_ComboBox::OnChar(FX_WORD nChar, FX_DWORD nFlag) 601 return m_pEdit->IsModified();
582 { 602 }
583 if (!m_pList) 603
584 return FALSE; 604 void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) {
585 605 m_pFillerNotify = pNotify;
586 if (!m_pEdit) 606
587 return FALSE; 607 if (m_pEdit)
588 608 m_pEdit->SetFillerNotify(pNotify);
589 m_nSelectItem = -1; 609
590 if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) 610 if (m_pList)
591 return m_pEdit->OnChar(nChar,nFlag); 611 m_pList->SetFillerNotify(pNotify);
592 612 }
593 FX_BOOL bExit = FALSE;
594 return m_pList->OnCharWithExit(nChar,bExit,nFlag) ? bExit : FALSE;
595 }
596
597 void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, intptr_t wParam, intp tr_t lParam)
598 {
599 switch (msg)
600 {
601 case PNM_LBUTTONDOWN:
602 if (pWnd == m_pButton)
603 {
604 SetPopup(!m_bPopup);
605 return;
606 }
607 break;
608 case PNM_LBUTTONUP:
609 if (m_pEdit && m_pList)
610 {
611 if (pWnd == m_pList)
612 {
613 SetSelectText();
614 SelectAll();
615 m_pEdit->SetFocus();
616 SetPopup(FALSE);
617 return;
618 }
619 }
620 }
621
622 CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);
623 }
624
625 FX_BOOL CPWL_ComboBox::IsPopup() const
626 {
627 return m_bPopup;
628 }
629
630 void CPWL_ComboBox::SetSelectText()
631 {
632 CFX_WideString swText = m_pList->GetText();
633 m_pEdit->SelectAll();
634 m_pEdit->ReplaceSel(m_pList->GetText().c_str());
635 m_pEdit->SelectAll();
636
637 m_nSelectItem = m_pList->GetCurSel();
638 }
639
640 FX_BOOL CPWL_ComboBox::IsModified() const
641 {
642 return m_pEdit->IsModified();
643 }
644
645 void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify)
646 {
647 m_pFillerNotify = pNotify;
648
649 if (m_pEdit)
650 m_pEdit->SetFillerNotify(pNotify);
651
652 if (m_pList)
653 m_pList->SetFillerNotify(pNotify);
654 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698