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

Side by Side Diff: fpdfsdk/src/formfiller/FFL_ListBox.cpp

Issue 453133004: clang-format all code (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 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/formfiller/FormFiller.h" 7 #include "../../include/formfiller/FormFiller.h"
8 #include "../../include/formfiller/FFL_FormFiller.h" 8 #include "../../include/formfiller/FFL_FormFiller.h"
9 #include "../../include/formfiller/FFL_ListBox.h" 9 #include "../../include/formfiller/FFL_ListBox.h"
10 //#include "../../include/formfiller/FFL_Module.h" 10 //#include "../../include/formfiller/FFL_Module.h"
11 #include "../../include/formfiller/FFL_IFormFiller.h" 11 #include "../../include/formfiller/FFL_IFormFiller.h"
12 //#include "../../include/formfiller/FFL_Undo.h" 12 //#include "../../include/formfiller/FFL_Undo.h"
13 #include "../../include/formfiller/FFL_CBA_Fontmap.h" 13 #include "../../include/formfiller/FFL_CBA_Fontmap.h"
14 14
15 15 #define FFL_DEFAULTLISTBOXFONTSIZE 12.0f
16 #define FFL_DEFAULTLISTBOXFONTSIZE 12.0f 16
17 17 /* ------------------------------- CFFL_ListBox -------------------------------
18 18 */
19 /* ------------------------------- CFFL_ListBox ------------------------------- */ 19
20 20 CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget)
21 CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) : 21 : CFFL_FormFiller(pApp, pWidget), m_pFontMap(NULL) {
22 CFFL_FormFiller(pApp, pWidget), 22 }
23 m_pFontMap(NULL) 23
24 { 24 CFFL_ListBox::~CFFL_ListBox() {
25 } 25 if (m_pFontMap) {
26 26 delete m_pFontMap;
27 CFFL_ListBox::~CFFL_ListBox() 27 m_pFontMap = NULL;
28 { 28 }
29 if (m_pFontMap) 29 }
30 { 30
31 delete m_pFontMap; 31 PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() {
32 m_pFontMap = NULL; 32 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
33 } 33
34 } 34 ASSERT(m_pWidget != NULL);
35 35 FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags();
36 PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() 36
37 { 37 if (dwFieldFlag & FIELDFLAG_MULTISELECT) {
38 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); 38 cp.dwFlags |= PLBS_MULTIPLESEL;
39 39 }
40 ASSERT(m_pWidget != NULL); 40
41 FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags(); 41 if (dwFieldFlag & FIELDFLAG_COMMITONSELCHANGE) {
42 42 // cp.dwFlags |= PLBS_COMMITSELECTEDVALUE;
43 if (dwFieldFlag & FIELDFLAG_MULTISELECT) 43 }
44 { 44
45 cp.dwFlags |= PLBS_MULTIPLESEL; 45 cp.dwFlags |= PWS_VSCROLL;
46 } 46
47 47 if (cp.dwFlags & PWS_AUTOFONTSIZE)
48 if (dwFieldFlag & FIELDFLAG_COMMITONSELCHANGE) 48 cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE;
49 { 49
50 //cp.dwFlags |= PLBS_COMMITSELECTEDVALUE; 50 if (!m_pFontMap) {
51 } 51 ASSERT(this->m_pApp != NULL);
52 52 m_pFontMap = new CBA_FontMap(
53 cp.dwFlags |= PWS_VSCROLL; 53 m_pWidget,
54 54 m_pApp->GetSysHandler()); //, ISystemHandle::GetSystemHandler(m_pApp));
55 if (cp.dwFlags & PWS_AUTOFONTSIZE) 55 m_pFontMap->Initial();
56 cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE; 56 }
57 57 cp.pFontMap = m_pFontMap;
58 if (!m_pFontMap) 58
59 { 59 return cp;
60 ASSERT(this->m_pApp != NULL); 60 }
61 m_pFontMap = new CBA_FontMap(m_pWidget,m_pApp->GetSysHandler()); //, ISystemHandle::GetSystemHandler(m_pApp)); 61
62 m_pFontMap->Initial(); 62 CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp,
63 } 63 CPDFSDK_PageView* pPageView) {
64 cp.pFontMap = m_pFontMap; 64 CPWL_ListBox* pWnd = new CPWL_ListBox();
65 65 pWnd->AttachFFLData(this);
66 return cp; 66 pWnd->Create(cp);
67 } 67
68 68 ASSERT(m_pApp != NULL);
69 CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView * pPageView) 69 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
70 { 70 pWnd->SetFillerNotify(pIFormFiller);
71 CPWL_ListBox* pWnd = new CPWL_ListBox(); 71
72 pWnd->AttachFFLData(this); 72 ASSERT(m_pWidget != NULL);
73 pWnd->Create(cp); 73
74 74 for (FX_INT32 i = 0, sz = m_pWidget->CountOptions(); i < sz; i++)
75 ASSERT(m_pApp != NULL); 75 pWnd->AddString(m_pWidget->GetOptionLabel(i));
76 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); 76
77 pWnd->SetFillerNotify(pIFormFiller); 77 if (pWnd->HasFlag(PLBS_MULTIPLESEL)) {
78 78 m_OriginSelections.RemoveAll();
79 ASSERT(m_pWidget != NULL); 79
80 80 FX_BOOL bSetCaret = FALSE;
81 for (FX_INT32 i=0,sz=m_pWidget->CountOptions(); i<sz; i++) 81 for (FX_INT32 i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) {
82 pWnd->AddString(m_pWidget->GetOptionLabel(i)); 82 if (m_pWidget->IsOptionSelected(i)) {
83 83 if (!bSetCaret) {
84 if (pWnd->HasFlag(PLBS_MULTIPLESEL)) 84 pWnd->SetCaret(i);
85 { 85 bSetCaret = TRUE;
86 m_OriginSelections.RemoveAll(); 86 }
87 87 pWnd->Select(i);
88 FX_BOOL bSetCaret = FALSE; 88 m_OriginSelections.SetAt(i, NULL);
89 for (FX_INT32 i=0,sz=m_pWidget->CountOptions(); i<sz; i++) 89 }
90 { 90 }
91 if (m_pWidget->IsOptionSelected(i)) 91 } else {
92 { 92 for (int i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) {
93 if (!bSetCaret) 93 if (m_pWidget->IsOptionSelected(i)) {
94 { 94 pWnd->Select(i);
95 pWnd->SetCaret(i); 95 break;
96 bSetCaret = TRUE; 96 }
97 } 97 }
98 pWnd->Select(i); 98 }
99 m_OriginSelections.SetAt(i, NULL); 99
100 } 100 pWnd->SetTopVisibleIndex(m_pWidget->GetTopVisibleIndex());
101 } 101
102 } 102 return pWnd;
103 else 103 }
104 { 104
105 for (int i=0,sz=m_pWidget->CountOptions(); i<sz; i++) 105 FX_BOOL CFFL_ListBox::OnChar(CPDFSDK_Annot* pAnnot,
106 { 106 FX_UINT nChar,
107 if (m_pWidget->IsOptionSelected(i)) 107 FX_UINT nFlags) {
108 { 108 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
109 pWnd->Select(i); 109 }
110 break; 110
111 } 111 FX_BOOL CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView) {
112 } 112 ASSERT(m_pWidget != NULL);
113 } 113
114 114 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) {
115 pWnd->SetTopVisibleIndex(m_pWidget->GetTopVisibleIndex()); 115 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) {
116 116 int nSelCount = 0;
117 return pWnd; 117 for (FX_INT32 i = 0, sz = pListBox->GetCount(); i < sz; i++) {
118 } 118 if (pListBox->IsItemSelected(i)) {
119 119 void* p = NULL;
120 120 if (!m_OriginSelections.Lookup(i, p))
121 FX_BOOL CFFL_ListBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlag s) 121 return TRUE;
122 { 122
123 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); 123 nSelCount++;
124 } 124 }
125 125 }
126 FX_BOOL CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView) 126
127 { 127 return nSelCount != m_OriginSelections.GetCount();
128 ASSERT(m_pWidget != NULL); 128 } else {
129 129 return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0);
130 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALS E)) 130 }
131 { 131 }
132 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) 132
133 { 133 return FALSE;
134 int nSelCount = 0; 134 }
135 for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++) 135
136 { 136 void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView) {
137 if (pListBox->IsItemSelected(i)) 137 ASSERT(m_pWidget != NULL);
138 { 138
139 void* p = NULL; 139 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) {
140 if (!m_OriginSelections.Lookup(i, p)) 140 CFX_IntArray aOldSelect, aNewSelect;
141 return TRUE; 141
142 142 {
143 nSelCount++; 143 for (int i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) {
144 } 144 if (m_pWidget->IsOptionSelected(i)) {
145 } 145 aOldSelect.Add(i);
146 146 }
147 return nSelCount != m_OriginSelections.GetCount(); 147 }
148 } 148 }
149 else 149
150 { 150 FX_INT32 nNewTopIndex = pListBox->GetTopVisibleIndex();
151 return pListBox->GetCurSel() != m_pWidget->GetSelectedIn dex(0); 151
152 } 152 m_pWidget->ClearSelection(FALSE);
153 } 153
154 154 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) {
155 return FALSE; 155 for (FX_INT32 i = 0, sz = pListBox->GetCount(); i < sz; i++) {
156 } 156 if (pListBox->IsItemSelected(i)) {
157 157 m_pWidget->SetOptionSelection(i, TRUE, FALSE);
158 void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView) 158 aNewSelect.Add(i);
159 { 159 }
160 ASSERT(m_pWidget != NULL); 160 }
161 161 } else {
162 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALS E)) 162 m_pWidget->SetOptionSelection(pListBox->GetCurSel(), TRUE, FALSE);
163 { 163 aNewSelect.Add(pListBox->GetCurSel());
164 CFX_IntArray aOldSelect, aNewSelect; 164 }
165 165
166 { 166 m_pWidget->SetTopVisibleIndex(nNewTopIndex);
167 for (int i=0,sz=m_pWidget->CountOptions(); i<sz; i++) 167 m_pWidget->ResetFieldAppearance(TRUE);
168 { 168 m_pWidget->UpdateField();
169 if (m_pWidget->IsOptionSelected(i)) 169 SetChangeMark();
170 { 170 }
171 aOldSelect.Add(i); 171 }
172 } 172
173 } 173 void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView,
174 } 174 CPDF_AAction::AActionType type,
175 175 PDFSDK_FieldAction& fa) {
176 176 switch (type) {
177 FX_INT32 nNewTopIndex = pListBox->GetTopVisibleIndex(); 177 case CPDF_AAction::Validate:
178 178 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) {
179 m_pWidget->ClearSelection(FALSE); 179 fa.sValue = L"";
180 180 } else {
181 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) 181 if (CPWL_ListBox* pListBox =
182 { 182 (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) {
183 for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++) 183 ASSERT(m_pWidget != NULL);
184 { 184 FX_INT32 nCurSel = pListBox->GetCurSel();
185 if (pListBox->IsItemSelected(i)) 185 if (nCurSel >= 0)
186 { 186 fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
187 m_pWidget->SetOptionSelection(i, TRUE, F ALSE); 187 }
188 aNewSelect.Add(i); 188 }
189 } 189 break;
190 } 190 case CPDF_AAction::LoseFocus:
191 } 191 case CPDF_AAction::GetFocus:
192 else 192 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) {
193 { 193 fa.sValue = L"";
194 m_pWidget->SetOptionSelection(pListBox->GetCurSel(), TRU E, FALSE); 194 } else {
195 aNewSelect.Add(pListBox->GetCurSel()); 195 ASSERT(m_pWidget != NULL);
196 } 196 FX_INT32 nCurSel = m_pWidget->GetSelectedIndex(0);
197 197 if (nCurSel >= 0)
198 m_pWidget->SetTopVisibleIndex(nNewTopIndex); 198 fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
199 m_pWidget->ResetFieldAppearance(TRUE); 199 }
200 m_pWidget->UpdateField(); 200 break;
201 SetChangeMark(); 201 default:
202 } 202 break;
203 } 203 }
204 204 }
205 void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AAct ionType type, 205
206 PDFSDK_FieldAction& fa) 206 void CFFL_ListBox::SetActionData(CPDFSDK_PageView* pPageView,
207 { 207 CPDF_AAction::AActionType type,
208 switch (type) 208 const PDFSDK_FieldAction& fa) {
209 { 209 }
210 case CPDF_AAction::Validate: 210
211 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) 211 void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView) {
212 { 212 ASSERT(pPageView != NULL);
213 fa.sValue = L""; 213
214 } 214 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) {
215 else 215 for (FX_INT32 i = 0, sz = pListBox->GetCount(); i < sz; i++) {
216 { 216 if (pListBox->IsItemSelected(i)) {
217 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow (pPageView, FALSE)) 217 m_State.Add(i);
218 { 218 }
219 ASSERT(m_pWidget != NULL); 219 }
220 FX_INT32 nCurSel = pListBox->GetCurSel(); 220 }
221 if (nCurSel >= 0) 221 }
222 fa.sValue = m_pWidget->GetOptionLabel(nC urSel); 222
223 } 223 void CFFL_ListBox::RestoreState(CPDFSDK_PageView* pPageView) {
224 } 224 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) {
225 break; 225 for (int i = 0, sz = m_State.GetSize(); i < sz; i++)
226 case CPDF_AAction::LoseFocus: 226 pListBox->Select(m_State[i]);
227 case CPDF_AAction::GetFocus: 227 }
228 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) 228 }
229 { 229
230 fa.sValue = L""; 230 CPWL_Wnd* CFFL_ListBox::ResetPDFWindow(CPDFSDK_PageView* pPageView,
231 } 231 FX_BOOL bRestoreValue) {
232 else 232 if (bRestoreValue)
233 { 233 SaveState(pPageView);
234 ASSERT(m_pWidget != NULL); 234
235 FX_INT32 nCurSel = m_pWidget->GetSelectedIndex(0); 235 DestroyPDFWindow(pPageView);
236 if (nCurSel >= 0) 236
237 fa.sValue = m_pWidget->GetOptionLabel(nCurSel); 237 CPWL_Wnd* pRet = NULL;
238 } 238
239 break; 239 if (bRestoreValue) {
240 default: 240 RestoreState(pPageView);
241 break; 241 pRet = this->GetPDFWindow(pPageView, FALSE);
242 } 242 } else
243 } 243 pRet = this->GetPDFWindow(pPageView, TRUE);
244 244
245 245 m_pWidget->UpdateField();
246 void CFFL_ListBox::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AAct ionType type, 246
247 const PDFSDK_Fie ldAction& fa) 247 return pRet;
248 { 248 }
249 } 249
250 250 void CFFL_ListBox::OnKeyStroke(FX_BOOL bKeyDown, FX_DWORD nFlag) {
251 void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView) 251 ASSERT(m_pWidget != NULL);
252 { 252
253 ASSERT(pPageView != NULL); 253 int nFlags = m_pWidget->GetFieldFlags();
254 254
255 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALS E)) 255 if (nFlags & FIELDFLAG_COMMITONSELCHANGE) {
256 { 256 if (m_bValid) {
257 for (FX_INT32 i=0,sz=pListBox->GetCount(); i<sz; i++) 257 CPDFSDK_PageView* pPageView = this->GetCurPageView();
258 { 258 ASSERT(pPageView != NULL);
259 if (pListBox->IsItemSelected(i)) 259
260 { 260 if (CommitData(pPageView, nFlag)) {
261 m_State.Add(i); 261 DestroyPDFWindow(pPageView);
262 } 262 m_bValid = FALSE;
263 } 263 }
264 } 264 }
265 } 265 }
266 266 }
267 void CFFL_ListBox::RestoreState(CPDFSDK_PageView* pPageView)
268 {
269 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALS E))
270 {
271 for (int i=0,sz=m_State.GetSize(); i<sz; i++)
272 pListBox->Select(m_State[i]);
273 }
274 }
275
276 CPWL_Wnd* CFFL_ListBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRes toreValue)
277 {
278 if (bRestoreValue)
279 SaveState(pPageView);
280
281 DestroyPDFWindow(pPageView);
282
283 CPWL_Wnd* pRet = NULL;
284
285 if (bRestoreValue)
286 {
287 RestoreState(pPageView);
288 pRet = this->GetPDFWindow(pPageView, FALSE);
289 }
290 else
291 pRet = this->GetPDFWindow(pPageView, TRUE);
292
293 m_pWidget->UpdateField();
294
295 return pRet;
296 }
297
298 void CFFL_ListBox::OnKeyStroke(FX_BOOL bKeyDown, FX_DWORD nFlag)
299 {
300 ASSERT(m_pWidget != NULL);
301
302 int nFlags = m_pWidget->GetFieldFlags();
303
304 if (nFlags & FIELDFLAG_COMMITONSELCHANGE)
305 {
306 if (m_bValid)
307 {
308 CPDFSDK_PageView* pPageView = this->GetCurPageView();
309 ASSERT(pPageView != NULL);
310
311 if (CommitData(pPageView, nFlag))
312 {
313 DestroyPDFWindow(pPageView);
314 m_bValid = FALSE;
315 }
316 }
317 }
318 }
319
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698