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

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

Powered by Google App Engine
This is Rietveld 408576698