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

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

Issue 1258093002: FX Bool considered harmful, part 3 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 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
« no previous file with comments | « fpdfsdk/src/formfiller/FFL_CheckBox.cpp ('k') | fpdfsdk/src/formfiller/FFL_FormFiller.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_IFormFiller.h" 9 #include "../../include/formfiller/FFL_IFormFiller.h"
10 #include "../../include/formfiller/FFL_CBA_Fontmap.h" 10 #include "../../include/formfiller/FFL_CBA_Fontmap.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 { 71 {
72 pWnd->AddString(m_pWidget->GetOptionLabel(i).c_str()); 72 pWnd->AddString(m_pWidget->GetOptionLabel(i).c_str());
73 } 73 }
74 74
75 pWnd->SetSelect(nCurSel); 75 pWnd->SetSelect(nCurSel);
76 pWnd->SetText(swText.c_str()); 76 pWnd->SetText(swText.c_str());
77 return pWnd; 77 return pWnd;
78 } 78 }
79 79
80 80
81 FX_BOOL CFFL_ComboBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFla gs) 81 bool CFFL_ComboBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
82 { 82 {
83 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); 83 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
84 } 84 }
85 85
86 FX_BOOL CFFL_ComboBox::IsDataChanged(CPDFSDK_PageView* pPageView) 86 bool CFFL_ComboBox::IsDataChanged(CPDFSDK_PageView* pPageView)
87 { 87 {
88 CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE); 88 CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, false);
89 if (!pWnd) 89 if (!pWnd)
90 return FALSE; 90 return false;
91 91
92 int32_t nCurSel = pWnd->GetSelect(); 92 int32_t nCurSel = pWnd->GetSelect();
93 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)) 93 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT))
94 return nCurSel != m_pWidget->GetSelectedIndex(0); 94 return nCurSel != m_pWidget->GetSelectedIndex(0);
95 95
96 if (nCurSel >= 0) 96 if (nCurSel >= 0)
97 return nCurSel != m_pWidget->GetSelectedIndex(0); 97 return nCurSel != m_pWidget->GetSelectedIndex(0);
98 98
99 return pWnd->GetText() != m_pWidget->GetValue(); 99 return pWnd->GetText() != m_pWidget->GetValue();
100 } 100 }
101 101
102 void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) 102 void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView)
103 { 103 {
104 ASSERT(m_pWidget != NULL); 104 ASSERT(m_pWidget != NULL);
105 105
106 if (CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE)) 106 if (CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, false))
107 { 107 {
108 CFX_WideString swText = pWnd->GetText(); 108 CFX_WideString swText = pWnd->GetText();
109 int32_t nCurSel = pWnd->GetSelect(); 109 int32_t nCurSel = pWnd->GetSelect();
110 110
111 //mantis:0004157 111 //mantis:0004157
112 FX_BOOL bSetValue = TRUE; 112 bool bSetValue = true;
113 113
114 if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT) 114 if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)
115 { 115 {
116 if (nCurSel >= 0) 116 if (nCurSel >= 0)
117 { 117 {
118 if (swText != m_pWidget->GetOptionLabel(nCurSel)) 118 if (swText != m_pWidget->GetOptionLabel(nCurSel))
119 bSetValue = TRUE; 119 bSetValue = true;
120 else 120 else
121 bSetValue = FALSE; 121 bSetValue = false;
122 } 122 }
123 else 123 else
124 bSetValue = TRUE; 124 bSetValue = true;
125 } 125 }
126 else 126 else
127 bSetValue = FALSE; 127 bSetValue = false;
128 128
129 CFX_WideString sOldValue; 129 CFX_WideString sOldValue;
130 130
131 131
132 if (bSetValue) 132 if (bSetValue)
133 { 133 {
134 sOldValue = m_pWidget->GetValue(); 134 sOldValue = m_pWidget->GetValue();
135 m_pWidget->SetValue(swText, FALSE); 135 m_pWidget->SetValue(swText, false);
136 } 136 }
137 else 137 else
138 { 138 {
139 m_pWidget->GetSelectedIndex(0); 139 m_pWidget->GetSelectedIndex(0);
140 m_pWidget->SetOptionSelection(nCurSel, TRUE, FALSE); 140 m_pWidget->SetOptionSelection(nCurSel, true, false);
141 } 141 }
142 142
143 m_pWidget->ResetFieldAppearance(TRUE); 143 m_pWidget->ResetFieldAppearance(true);
144 m_pWidget->UpdateField(); 144 m_pWidget->UpdateField();
145 SetChangeMark(); 145 SetChangeMark();
146 146
147 m_pWidget->GetPDFPage(); 147 m_pWidget->GetPDFPage();
148 148
149 149
150 } 150 }
151 } 151 }
152 152
153 void CFFL_ComboBox::GetActionData( CPDFSDK_PageView* pPageView, CPDF_AAction::A ActionType type, PDFSDK_FieldAction& fa) 153 void CFFL_ComboBox::GetActionData( CPDFSDK_PageView* pPageView, CPDF_AAction::A ActionType type, PDFSDK_FieldAction& fa)
154 { 154 {
155 switch (type) 155 switch (type)
156 { 156 {
157 case CPDF_AAction::KeyStroke: 157 case CPDF_AAction::KeyStroke:
158 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, F ALSE)) 158 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, f alse))
159 { 159 {
160 if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox) 160 if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
161 { 161 {
162 fa.bFieldFull = pEdit->IsTextFull(); 162 fa.bFieldFull = pEdit->IsTextFull();
163 int nSelStart = 0; 163 int nSelStart = 0;
164 int nSelEnd = 0; 164 int nSelEnd = 0;
165 pEdit->GetSel(nSelStart, nSelEnd); 165 pEdit->GetSel(nSelStart, nSelEnd);
166 fa.nSelEnd = nSelEnd; 166 fa.nSelEnd = nSelEnd;
167 fa.nSelStart = nSelStart; 167 fa.nSelStart = nSelStart;
168 fa.sValue = pEdit->GetText(); 168 fa.sValue = pEdit->GetText();
169 fa.sChangeEx = GetSelectExportText(); 169 fa.sChangeEx = GetSelectExportText();
170 170
171 if (fa.bFieldFull) 171 if (fa.bFieldFull)
172 { 172 {
173 fa.sChange = L""; 173 fa.sChange = L"";
174 fa.sChangeEx = L""; 174 fa.sChangeEx = L"";
175 } 175 }
176 } 176 }
177 } 177 }
178 break; 178 break;
179 case CPDF_AAction::Validate: 179 case CPDF_AAction::Validate:
180 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, F ALSE)) 180 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, f alse))
181 { 181 {
182 if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox) 182 if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
183 { 183 {
184 fa.sValue = pEdit->GetText(); 184 fa.sValue = pEdit->GetText();
185 } 185 }
186 } 186 }
187 break; 187 break;
188 case CPDF_AAction::LoseFocus: 188 case CPDF_AAction::LoseFocus:
189 case CPDF_AAction::GetFocus: 189 case CPDF_AAction::GetFocus:
190 ASSERT(m_pWidget != NULL); 190 ASSERT(m_pWidget != NULL);
191 fa.sValue = m_pWidget->GetValue(); 191 fa.sValue = m_pWidget->GetValue();
192 break; 192 break;
193 default: 193 default:
194 break; 194 break;
195 } 195 }
196 } 196 }
197 197
198 198
199 199
200 void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AAc tionType type, 200 void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AAc tionType type,
201 const PDFSDK_FieldAction& fa) 201 const PDFSDK_FieldAction& fa)
202 { 202 {
203 switch (type) 203 switch (type)
204 { 204 {
205 case CPDF_AAction::KeyStroke: 205 case CPDF_AAction::KeyStroke:
206 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, F ALSE)) 206 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, f alse))
207 { 207 {
208 if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox) 208 if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
209 { 209 {
210 pEdit->SetSel(fa.nSelStart, fa.nSelEnd); 210 pEdit->SetSel(fa.nSelStart, fa.nSelEnd);
211 pEdit->ReplaceSel(fa.sChange.c_str()); 211 pEdit->ReplaceSel(fa.sChange.c_str());
212 } 212 }
213 } 213 }
214 break; 214 break;
215 default: 215 default:
216 break; 216 break;
217 } 217 }
218 } 218 }
219 219
220 FX_BOOL CFFL_ComboBox::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld, 220 bool CFFL_ComboBox::IsActionDataChanged(CPDF_AAction::AActionType type, const PD FSDK_FieldAction& faOld,
221 const PDFSDK_FieldAction& faNew) 221 const PDFSDK_FieldAction& faNew)
222 { 222 {
223 switch (type) 223 switch (type)
224 { 224 {
225 case CPDF_AAction::KeyStroke: 225 case CPDF_AAction::KeyStroke:
226 return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || faOld.nS elStart != faNew.nSelStart || 226 return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || faOld.nS elStart != faNew.nSelStart ||
227 faOld.sChange != faNew.sChange; 227 faOld.sChange != faNew.sChange;
228 default: 228 default:
229 break; 229 break;
230 } 230 }
231 231
232 return FALSE; 232 return false;
233 } 233 }
234 234
235 void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView) 235 void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView)
236 { 236 {
237 ASSERT(pPageView != NULL); 237 ASSERT(pPageView != NULL);
238 238
239 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE )) 239 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, false ))
240 { 240 {
241 m_State.nIndex = pComboBox->GetSelect(); 241 m_State.nIndex = pComboBox->GetSelect();
242 242
243 if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox) 243 if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
244 { 244 {
245 pEdit->GetSel(m_State.nStart, m_State.nEnd); 245 pEdit->GetSel(m_State.nStart, m_State.nEnd);
246 m_State.sValue = pEdit->GetText(); 246 m_State.sValue = pEdit->GetText();
247 } 247 }
248 } 248 }
249 } 249 }
250 250
251 void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView) 251 void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView)
252 { 252 {
253 ASSERT(pPageView != NULL); 253 ASSERT(pPageView != NULL);
254 254
255 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, TRUE) ) 255 if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, true) )
256 { 256 {
257 if (m_State.nIndex >= 0) 257 if (m_State.nIndex >= 0)
258 pComboBox->SetSelect(m_State.nIndex); 258 pComboBox->SetSelect(m_State.nIndex);
259 else 259 else
260 { 260 {
261 if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox) 261 if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
262 { 262 {
263 pEdit->SetText(m_State.sValue.c_str()); 263 pEdit->SetText(m_State.sValue.c_str());
264 pEdit->SetSel(m_State.nStart, m_State.nEnd); 264 pEdit->SetSel(m_State.nStart, m_State.nEnd);
265 } 265 }
266 } 266 }
267 } 267 }
268 } 268 }
269 269
270 CPWL_Wnd* CFFL_ComboBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRe storeValue) 270 CPWL_Wnd* CFFL_ComboBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, bool bResto reValue)
271 { 271 {
272 if (bRestoreValue) 272 if (bRestoreValue)
273 SaveState(pPageView); 273 SaveState(pPageView);
274 274
275 DestroyPDFWindow(pPageView); 275 DestroyPDFWindow(pPageView);
276 276
277 CPWL_Wnd* pRet = NULL; 277 CPWL_Wnd* pRet = NULL;
278 278
279 if (bRestoreValue) 279 if (bRestoreValue)
280 { 280 {
281 RestoreState(pPageView); 281 RestoreState(pPageView);
282 pRet = GetPDFWindow(pPageView, FALSE); 282 pRet = GetPDFWindow(pPageView, false);
283 } 283 }
284 else 284 else
285 pRet = GetPDFWindow(pPageView, TRUE); 285 pRet = GetPDFWindow(pPageView, true);
286 286
287 m_pWidget->UpdateField(); 287 m_pWidget->UpdateField();
288 288
289 return pRet; 289 return pRet;
290 } 290 }
291 291
292 void CFFL_ComboBox::OnKeyStroke(FX_BOOL bKeyDown, FX_UINT nFlag) 292 void CFFL_ComboBox::OnKeyStroke(bool bKeyDown, FX_UINT nFlag)
293 { 293 {
294 ASSERT(m_pWidget != NULL); 294 ASSERT(m_pWidget != NULL);
295 295
296 int nFlags = m_pWidget->GetFieldFlags(); 296 int nFlags = m_pWidget->GetFieldFlags();
297 297
298 if (nFlags & FIELDFLAG_COMMITONSELCHANGE) 298 if (nFlags & FIELDFLAG_COMMITONSELCHANGE)
299 { 299 {
300 if (m_bValid) 300 if (m_bValid)
301 { 301 {
302 CPDFSDK_PageView* pPageView = GetCurPageView(); 302 CPDFSDK_PageView* pPageView = GetCurPageView();
303 ASSERT(pPageView != NULL); 303 ASSERT(pPageView != NULL);
304 304
305 if (CommitData(pPageView, nFlag)) 305 if (CommitData(pPageView, nFlag))
306 { 306 {
307 DestroyPDFWindow(pPageView); 307 DestroyPDFWindow(pPageView);
308 m_bValid = FALSE; 308 m_bValid = false;
309 } 309 }
310 } 310 }
311 } 311 }
312 } 312 }
313 313
314 void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) 314 void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd)
315 { 315 {
316 ASSERT(m_pApp != NULL); 316 ASSERT(m_pApp != NULL);
317 317
318 ASSERT(pWnd != NULL); 318 ASSERT(pWnd != NULL);
319 319
320 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) 320 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT)
321 { 321 {
322 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; 322 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd;
323 pEdit->SetCharSet(134); 323 pEdit->SetCharSet(134);
324 pEdit->SetCodePage(936); 324 pEdit->SetCodePage(936);
325 325
326 pEdit->SetReadyToInput(); 326 pEdit->SetReadyToInput();
327 CFX_WideString wsText = pEdit->GetText(); 327 CFX_WideString wsText = pEdit->GetText();
328 int nCharacters = wsText.GetLength(); 328 int nCharacters = wsText.GetLength();
329 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); 329 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode();
330 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); 330 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str();
331 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, nCh aracters, TRUE); 331 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, nCh aracters, true);
332 332
333 pEdit->SetEditNotify(this); 333 pEdit->SetEditNotify(this);
334 } 334 }
335 } 335 }
336 336
337 void CFFL_ComboBox::OnKillFocus(CPWL_Wnd* pWnd) 337 void CFFL_ComboBox::OnKillFocus(CPWL_Wnd* pWnd)
338 { 338 {
339 ASSERT(m_pApp != NULL); 339 ASSERT(m_pApp != NULL);
340 } 340 }
341 341
342 FX_BOOL CFFL_ComboBox::CanCopy(CPDFSDK_Document* pDocument) 342 bool CFFL_ComboBox::CanCopy(CPDFSDK_Document* pDocument)
343 { 343 {
344 ASSERT(pDocument != NULL); 344 ASSERT(pDocument != NULL);
345 345
346 return FALSE; 346 return false;
347 } 347 }
348 348
349 FX_BOOL CFFL_ComboBox::CanCut(CPDFSDK_Document* pDocument) 349 bool CFFL_ComboBox::CanCut(CPDFSDK_Document* pDocument)
350 { 350 {
351 ASSERT(pDocument != NULL); 351 ASSERT(pDocument != NULL);
352 352
353 return FALSE; 353 return false;
354 } 354 }
355 355
356 FX_BOOL CFFL_ComboBox::CanPaste(CPDFSDK_Document* pDocument) 356 bool CFFL_ComboBox::CanPaste(CPDFSDK_Document* pDocument)
357 { 357 {
358 ASSERT(pDocument != NULL); 358 ASSERT(pDocument != NULL);
359 359
360 return FALSE; 360 return false;
361 } 361 }
362 362
363 void CFFL_ComboBox::OnAddUndo(CPWL_Edit* pEdit) 363 void CFFL_ComboBox::OnAddUndo(CPWL_Edit* pEdit)
364 { 364 {
365 ASSERT(pEdit != NULL); 365 ASSERT(pEdit != NULL);
366 } 366 }
367 367
368 CFX_WideString CFFL_ComboBox::GetSelectExportText() 368 CFX_WideString CFFL_ComboBox::GetSelectExportText()
369 { 369 {
370 CFX_WideString swRet; 370 CFX_WideString swRet;
371 371
372 int nExport = -1; 372 int nExport = -1;
373 CPDFSDK_PageView *pPageView = GetCurPageView(); 373 CPDFSDK_PageView *pPageView = GetCurPageView();
374 if (CPWL_ComboBox * pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALS E)) 374 if (CPWL_ComboBox * pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, fals e))
375 { 375 {
376 nExport = pComboBox->GetSelect(); 376 nExport = pComboBox->GetSelect();
377 } 377 }
378 378
379 if (nExport >= 0) 379 if (nExport >= 0)
380 { 380 {
381 if (CPDF_FormField * pFormField = m_pWidget->GetFormField()) 381 if (CPDF_FormField * pFormField = m_pWidget->GetFormField())
382 { 382 {
383 swRet = pFormField->GetOptionValue(nExport); 383 swRet = pFormField->GetOptionValue(nExport);
384 if (swRet.IsEmpty()) 384 if (swRet.IsEmpty())
385 swRet = pFormField->GetOptionLabel(nExport); 385 swRet = pFormField->GetOptionLabel(nExport);
386 } 386 }
387 } 387 }
388 388
389 return swRet; 389 return swRet;
390 } 390 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/formfiller/FFL_CheckBox.cpp ('k') | fpdfsdk/src/formfiller/FFL_FormFiller.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698