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

Side by Side Diff: core/fpdfdoc/cpdf_formfield.cpp

Issue 2477443002: Remove FX_BOOL from core (Closed)
Patch Set: Created 4 years, 1 month 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 | « core/fpdfdoc/cpdf_formfield.h ('k') | core/fpdfdoc/cpdf_iconfit.h » ('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 "core/fpdfdoc/cpdf_formfield.h" 7 #include "core/fpdfdoc/cpdf_formfield.h"
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 LoadDA(); 154 LoadDA();
155 } else if (type_name == "Sig") { 155 } else if (type_name == "Sig") {
156 m_Type = Sign; 156 m_Type = Sign;
157 } 157 }
158 } 158 }
159 159
160 CFX_WideString CPDF_FormField::GetFullName() const { 160 CFX_WideString CPDF_FormField::GetFullName() const {
161 return FPDF_GetFullName(m_pDict); 161 return FPDF_GetFullName(m_pDict);
162 } 162 }
163 163
164 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { 164 bool CPDF_FormField::ResetField(bool bNotify) {
165 switch (m_Type) { 165 switch (m_Type) {
166 case CPDF_FormField::CheckBox: 166 case CPDF_FormField::CheckBox:
167 case CPDF_FormField::RadioButton: { 167 case CPDF_FormField::RadioButton: {
168 int iCount = CountControls(); 168 int iCount = CountControls();
169 if (iCount) { 169 if (iCount) {
170 // TODO(weili): Check whether anything special needs to be done for 170 // TODO(weili): Check whether anything special needs to be done for
171 // unison field. Otherwise, merge these branches. 171 // unison field. Otherwise, merge these branches.
172 if (IsUnison(this)) { 172 if (IsUnison(this)) {
173 for (int i = 0; i < iCount; i++) 173 for (int i = 0; i < iCount; i++)
174 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); 174 CheckControl(i, GetControl(i)->IsDefaultChecked(), false);
175 } else { 175 } else {
176 for (int i = 0; i < iCount; i++) 176 for (int i = 0; i < iCount; i++)
177 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); 177 CheckControl(i, GetControl(i)->IsDefaultChecked(), false);
178 } 178 }
179 } 179 }
180 if (bNotify && m_pForm->m_pFormNotify) 180 if (bNotify && m_pForm->m_pFormNotify)
181 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); 181 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this);
182 break; 182 break;
183 } 183 }
184 case CPDF_FormField::ComboBox: 184 case CPDF_FormField::ComboBox:
185 case CPDF_FormField::ListBox: { 185 case CPDF_FormField::ListBox: {
186 CFX_WideString csValue; 186 CFX_WideString csValue;
187 ClearSelection(); 187 ClearSelection();
188 int iIndex = GetDefaultSelectedItem(); 188 int iIndex = GetDefaultSelectedItem();
189 if (iIndex >= 0) 189 if (iIndex >= 0)
190 csValue = GetOptionLabel(iIndex); 190 csValue = GetOptionLabel(iIndex);
191 191
192 if (bNotify && !NotifyListOrComboBoxBeforeChange(csValue)) 192 if (bNotify && !NotifyListOrComboBoxBeforeChange(csValue))
193 return FALSE; 193 return false;
194 194
195 SetItemSelection(iIndex, TRUE); 195 SetItemSelection(iIndex, true);
196 if (bNotify) 196 if (bNotify)
197 NotifyListOrComboBoxAfterChange(); 197 NotifyListOrComboBoxAfterChange();
198 break; 198 break;
199 } 199 }
200 case CPDF_FormField::Text: 200 case CPDF_FormField::Text:
201 case CPDF_FormField::RichText: 201 case CPDF_FormField::RichText:
202 case CPDF_FormField::File: 202 case CPDF_FormField::File:
203 default: { 203 default: {
204 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); 204 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV");
205 CFX_WideString csDValue; 205 CFX_WideString csDValue;
206 if (pDV) 206 if (pDV)
207 csDValue = pDV->GetUnicodeText(); 207 csDValue = pDV->GetUnicodeText();
208 208
209 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); 209 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
210 CFX_WideString csValue; 210 CFX_WideString csValue;
211 if (pV) 211 if (pV)
212 csValue = pV->GetUnicodeText(); 212 csValue = pV->GetUnicodeText();
213 213
214 CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV"); 214 CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV");
215 if (!pRV && (csDValue == csValue)) 215 if (!pRV && (csDValue == csValue))
216 return FALSE; 216 return false;
217 217
218 if (bNotify && !NotifyBeforeValueChange(csDValue)) 218 if (bNotify && !NotifyBeforeValueChange(csDValue))
219 return FALSE; 219 return false;
220 220
221 if (pDV) { 221 if (pDV) {
222 CPDF_Object* pClone = pDV->Clone(); 222 CPDF_Object* pClone = pDV->Clone();
223 if (!pClone) 223 if (!pClone)
224 return FALSE; 224 return false;
225 225
226 m_pDict->SetFor("V", pClone); 226 m_pDict->SetFor("V", pClone);
227 if (pRV) { 227 if (pRV) {
228 CPDF_Object* pCloneR = pDV->Clone(); 228 CPDF_Object* pCloneR = pDV->Clone();
229 m_pDict->SetFor("RV", pCloneR); 229 m_pDict->SetFor("RV", pCloneR);
230 } 230 }
231 } else { 231 } else {
232 m_pDict->RemoveFor("V"); 232 m_pDict->RemoveFor("V");
233 m_pDict->RemoveFor("RV"); 233 m_pDict->RemoveFor("RV");
234 } 234 }
235 if (bNotify) 235 if (bNotify)
236 NotifyAfterValueChange(); 236 NotifyAfterValueChange();
237 break; 237 break;
238 } 238 }
239 } 239 }
240 return TRUE; 240 return true;
241 } 241 }
242 242
243 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const { 243 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const {
244 if (!pControl) 244 if (!pControl)
245 return -1; 245 return -1;
246 246
247 for (int i = 0; i < m_ControlList.GetSize(); i++) { 247 for (int i = 0; i < m_ControlList.GetSize(); i++) {
248 if (m_ControlList.GetAt(i) == pControl) 248 if (m_ControlList.GetAt(i) == pControl)
249 return i; 249 return i;
250 } 250 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 CFX_ByteString CPDF_FormField::GetDefaultStyle() const { 298 CFX_ByteString CPDF_FormField::GetDefaultStyle() const {
299 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DS"); 299 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DS");
300 return pObj ? pObj->GetString() : ""; 300 return pObj ? pObj->GetString() : "";
301 } 301 }
302 302
303 CFX_WideString CPDF_FormField::GetRichTextString() const { 303 CFX_WideString CPDF_FormField::GetRichTextString() const {
304 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV"); 304 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV");
305 return pObj ? pObj->GetUnicodeText() : L""; 305 return pObj ? pObj->GetUnicodeText() : L"";
306 } 306 }
307 307
308 CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) const { 308 CFX_WideString CPDF_FormField::GetValue(bool bDefault) const {
309 if (GetType() == CheckBox || GetType() == RadioButton) 309 if (GetType() == CheckBox || GetType() == RadioButton)
310 return GetCheckValue(bDefault); 310 return GetCheckValue(bDefault);
311 311
312 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V"); 312 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V");
313 if (!pValue) { 313 if (!pValue) {
314 if (!bDefault) { 314 if (!bDefault) {
315 if (m_Type == RichText) 315 if (m_Type == RichText)
316 pValue = FPDF_GetFieldAttr(m_pDict, "V"); 316 pValue = FPDF_GetFieldAttr(m_pDict, "V");
317 if (!pValue && m_Type != Text) 317 if (!pValue && m_Type != Text)
318 pValue = FPDF_GetFieldAttr(m_pDict, "DV"); 318 pValue = FPDF_GetFieldAttr(m_pDict, "DV");
(...skipping 11 matching lines...) Expand all
330 if (pValue) 330 if (pValue)
331 return pValue->GetUnicodeText(); 331 return pValue->GetUnicodeText();
332 break; 332 break;
333 default: 333 default:
334 break; 334 break;
335 } 335 }
336 return CFX_WideString(); 336 return CFX_WideString();
337 } 337 }
338 338
339 CFX_WideString CPDF_FormField::GetValue() const { 339 CFX_WideString CPDF_FormField::GetValue() const {
340 return GetValue(FALSE); 340 return GetValue(false);
341 } 341 }
342 342
343 CFX_WideString CPDF_FormField::GetDefaultValue() const { 343 CFX_WideString CPDF_FormField::GetDefaultValue() const {
344 return GetValue(TRUE); 344 return GetValue(true);
345 } 345 }
346 346
347 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, 347 bool CPDF_FormField::SetValue(const CFX_WideString& value,
348 FX_BOOL bDefault, 348 bool bDefault,
349 FX_BOOL bNotify) { 349 bool bNotify) {
350 switch (m_Type) { 350 switch (m_Type) {
351 case CheckBox: 351 case CheckBox:
352 case RadioButton: { 352 case RadioButton: {
353 SetCheckValue(value, bDefault, bNotify); 353 SetCheckValue(value, bDefault, bNotify);
354 return TRUE; 354 return true;
355 } 355 }
356 case File: 356 case File:
357 case RichText: 357 case RichText:
358 case Text: 358 case Text:
359 case ComboBox: { 359 case ComboBox: {
360 CFX_WideString csValue = value; 360 CFX_WideString csValue = value;
361 if (bNotify && !NotifyBeforeValueChange(csValue)) 361 if (bNotify && !NotifyBeforeValueChange(csValue))
362 return FALSE; 362 return false;
363 363
364 int iIndex = FindOptionValue(csValue); 364 int iIndex = FindOptionValue(csValue);
365 if (iIndex < 0) { 365 if (iIndex < 0) {
366 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue); 366 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue);
367 m_pDict->SetStringFor(bDefault ? "DV" : "V", bsEncodeText); 367 m_pDict->SetStringFor(bDefault ? "DV" : "V", bsEncodeText);
368 if (m_Type == RichText && !bDefault) 368 if (m_Type == RichText && !bDefault)
369 m_pDict->SetStringFor("RV", bsEncodeText); 369 m_pDict->SetStringFor("RV", bsEncodeText);
370 m_pDict->RemoveFor("I"); 370 m_pDict->RemoveFor("I");
371 } else { 371 } else {
372 m_pDict->SetStringFor(bDefault ? "DV" : "V", PDF_EncodeText(csValue)); 372 m_pDict->SetStringFor(bDefault ? "DV" : "V", PDF_EncodeText(csValue));
373 if (!bDefault) { 373 if (!bDefault) {
374 ClearSelection(); 374 ClearSelection();
375 SetItemSelection(iIndex, TRUE); 375 SetItemSelection(iIndex, true);
376 } 376 }
377 } 377 }
378 if (bNotify) 378 if (bNotify)
379 NotifyAfterValueChange(); 379 NotifyAfterValueChange();
380 break; 380 break;
381 } 381 }
382 case ListBox: { 382 case ListBox: {
383 int iIndex = FindOptionValue(value); 383 int iIndex = FindOptionValue(value);
384 if (iIndex < 0) 384 if (iIndex < 0)
385 return FALSE; 385 return false;
386 386
387 if (bDefault && iIndex == GetDefaultSelectedItem()) 387 if (bDefault && iIndex == GetDefaultSelectedItem())
388 return FALSE; 388 return false;
389 389
390 if (bNotify && !NotifyBeforeSelectionChange(value)) 390 if (bNotify && !NotifyBeforeSelectionChange(value))
391 return FALSE; 391 return false;
392 392
393 if (!bDefault) { 393 if (!bDefault) {
394 ClearSelection(); 394 ClearSelection();
395 SetItemSelection(iIndex, TRUE); 395 SetItemSelection(iIndex, true);
396 } 396 }
397 if (bNotify) 397 if (bNotify)
398 NotifyAfterSelectionChange(); 398 NotifyAfterSelectionChange();
399 break; 399 break;
400 } 400 }
401 default: 401 default:
402 break; 402 break;
403 } 403 }
404 return TRUE; 404 return true;
405 } 405 }
406 406
407 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bNotify) { 407 bool CPDF_FormField::SetValue(const CFX_WideString& value, bool bNotify) {
408 return SetValue(value, FALSE, bNotify); 408 return SetValue(value, false, bNotify);
409 } 409 }
410 410
411 int CPDF_FormField::GetMaxLen() const { 411 int CPDF_FormField::GetMaxLen() const {
412 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen")) 412 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen"))
413 return pObj->GetInteger(); 413 return pObj->GetInteger();
414 414
415 for (int i = 0; i < m_ControlList.GetSize(); i++) { 415 for (int i = 0; i < m_ControlList.GetSize(); i++) {
416 CPDF_FormControl* pControl = m_ControlList.GetAt(i); 416 CPDF_FormControl* pControl = m_ControlList.GetAt(i);
417 if (!pControl) 417 if (!pControl)
418 continue; 418 continue;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 if (csOpt == sel_value) 469 if (csOpt == sel_value)
470 return iOptIndex; 470 return iOptIndex;
471 } 471 }
472 for (int i = 0; i < CountOptions(); i++) { 472 for (int i = 0; i < CountOptions(); i++) {
473 if (sel_value == GetOptionValue(i)) 473 if (sel_value == GetOptionValue(i))
474 return i; 474 return i;
475 } 475 }
476 return -1; 476 return -1;
477 } 477 }
478 478
479 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) { 479 bool CPDF_FormField::ClearSelection(bool bNotify) {
480 if (bNotify && m_pForm->m_pFormNotify) { 480 if (bNotify && m_pForm->m_pFormNotify) {
481 CFX_WideString csValue; 481 CFX_WideString csValue;
482 int iIndex = GetSelectedIndex(0); 482 int iIndex = GetSelectedIndex(0);
483 if (iIndex >= 0) 483 if (iIndex >= 0)
484 csValue = GetOptionLabel(iIndex); 484 csValue = GetOptionLabel(iIndex);
485 485
486 if (!NotifyListOrComboBoxBeforeChange(csValue)) 486 if (!NotifyListOrComboBoxBeforeChange(csValue))
487 return FALSE; 487 return false;
488 } 488 }
489 m_pDict->RemoveFor("V"); 489 m_pDict->RemoveFor("V");
490 m_pDict->RemoveFor("I"); 490 m_pDict->RemoveFor("I");
491 if (bNotify) 491 if (bNotify)
492 NotifyListOrComboBoxAfterChange(); 492 NotifyListOrComboBoxAfterChange();
493 return TRUE; 493 return true;
494 } 494 }
495 495
496 FX_BOOL CPDF_FormField::IsItemSelected(int index) const { 496 bool CPDF_FormField::IsItemSelected(int index) const {
497 ASSERT(GetType() == ComboBox || GetType() == ListBox); 497 ASSERT(GetType() == ComboBox || GetType() == ListBox);
498 if (index < 0 || index >= CountOptions()) 498 if (index < 0 || index >= CountOptions())
499 return FALSE; 499 return false;
500 if (IsOptionSelected(index)) 500 if (IsOptionSelected(index))
501 return TRUE; 501 return true;
502 502
503 CFX_WideString opt_value = GetOptionValue(index); 503 CFX_WideString opt_value = GetOptionValue(index);
504 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 504 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
505 if (!pValue) { 505 if (!pValue) {
506 pValue = FPDF_GetFieldAttr(m_pDict, "I"); 506 pValue = FPDF_GetFieldAttr(m_pDict, "I");
507 if (!pValue) 507 if (!pValue)
508 return FALSE; 508 return false;
509 } 509 }
510 510
511 if (pValue->IsString()) 511 if (pValue->IsString())
512 return pValue->GetUnicodeText() == opt_value; 512 return pValue->GetUnicodeText() == opt_value;
513 513
514 if (pValue->IsNumber()) { 514 if (pValue->IsNumber()) {
515 if (pValue->GetString().IsEmpty()) 515 if (pValue->GetString().IsEmpty())
516 return FALSE; 516 return false;
517 return (pValue->GetInteger() == index); 517 return (pValue->GetInteger() == index);
518 } 518 }
519 519
520 CPDF_Array* pArray = pValue->AsArray(); 520 CPDF_Array* pArray = pValue->AsArray();
521 if (!pArray) 521 if (!pArray)
522 return FALSE; 522 return false;
523 523
524 int iPos = -1; 524 int iPos = -1;
525 for (int j = 0; j < CountSelectedOptions(); j++) { 525 for (int j = 0; j < CountSelectedOptions(); j++) {
526 if (GetSelectedOptionIndex(j) == index) { 526 if (GetSelectedOptionIndex(j) == index) {
527 iPos = j; 527 iPos = j;
528 break; 528 break;
529 } 529 }
530 } 530 }
531 for (int i = 0; i < static_cast<int>(pArray->GetCount()); i++) 531 for (int i = 0; i < static_cast<int>(pArray->GetCount()); i++)
532 if (pArray->GetDirectObjectAt(i)->GetUnicodeText() == opt_value && 532 if (pArray->GetDirectObjectAt(i)->GetUnicodeText() == opt_value &&
533 i == iPos) { 533 i == iPos) {
534 return TRUE; 534 return true;
535 } 535 }
536 return FALSE; 536 return false;
537 } 537 }
538 538
539 FX_BOOL CPDF_FormField::SetItemSelection(int index, 539 bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) {
540 FX_BOOL bSelected,
541 FX_BOOL bNotify) {
542 ASSERT(GetType() == ComboBox || GetType() == ListBox); 540 ASSERT(GetType() == ComboBox || GetType() == ListBox);
543 if (index < 0 || index >= CountOptions()) 541 if (index < 0 || index >= CountOptions())
544 return FALSE; 542 return false;
545 543
546 CFX_WideString opt_value = GetOptionValue(index); 544 CFX_WideString opt_value = GetOptionValue(index);
547 if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) 545 if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value))
548 return FALSE; 546 return false;
549 547
550 if (bSelected) { 548 if (bSelected) {
551 if (GetType() == ListBox) { 549 if (GetType() == ListBox) {
552 SelectOption(index, TRUE); 550 SelectOption(index, true);
553 if (!(m_Flags & kFormListMultiSelect)) { 551 if (!(m_Flags & kFormListMultiSelect)) {
554 m_pDict->SetStringFor("V", PDF_EncodeText(opt_value)); 552 m_pDict->SetStringFor("V", PDF_EncodeText(opt_value));
555 } else { 553 } else {
556 CPDF_Array* pArray = new CPDF_Array; 554 CPDF_Array* pArray = new CPDF_Array;
557 for (int i = 0; i < CountOptions(); i++) { 555 for (int i = 0; i < CountOptions(); i++) {
558 if (i == index || IsItemSelected(i)) { 556 if (i == index || IsItemSelected(i)) {
559 opt_value = GetOptionValue(i); 557 opt_value = GetOptionValue(i);
560 pArray->AddString(PDF_EncodeText(opt_value)); 558 pArray->AddString(PDF_EncodeText(opt_value));
561 } 559 }
562 } 560 }
563 m_pDict->SetFor("V", pArray); 561 m_pDict->SetFor("V", pArray);
564 } 562 }
565 } else { 563 } else {
566 m_pDict->SetStringFor("V", PDF_EncodeText(opt_value)); 564 m_pDict->SetStringFor("V", PDF_EncodeText(opt_value));
567 CPDF_Array* pI = new CPDF_Array; 565 CPDF_Array* pI = new CPDF_Array;
568 pI->AddInteger(index); 566 pI->AddInteger(index);
569 m_pDict->SetFor("I", pI); 567 m_pDict->SetFor("I", pI);
570 } 568 }
571 } else { 569 } else {
572 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 570 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
573 if (pValue) { 571 if (pValue) {
574 if (GetType() == ListBox) { 572 if (GetType() == ListBox) {
575 SelectOption(index, FALSE); 573 SelectOption(index, false);
576 if (pValue->IsString()) { 574 if (pValue->IsString()) {
577 if (pValue->GetUnicodeText() == opt_value) 575 if (pValue->GetUnicodeText() == opt_value)
578 m_pDict->RemoveFor("V"); 576 m_pDict->RemoveFor("V");
579 } else if (pValue->IsArray()) { 577 } else if (pValue->IsArray()) {
580 std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( 578 std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray(
581 new CPDF_Array); 579 new CPDF_Array);
582 for (int i = 0; i < CountOptions(); i++) { 580 for (int i = 0; i < CountOptions(); i++) {
583 if (i != index && IsItemSelected(i)) { 581 if (i != index && IsItemSelected(i)) {
584 opt_value = GetOptionValue(i); 582 opt_value = GetOptionValue(i);
585 pArray->AddString(PDF_EncodeText(opt_value)); 583 pArray->AddString(PDF_EncodeText(opt_value));
586 } 584 }
587 } 585 }
588 if (pArray->GetCount() > 0) 586 if (pArray->GetCount() > 0)
589 m_pDict->SetFor("V", pArray.release()); // std::move someday 587 m_pDict->SetFor("V", pArray.release()); // std::move someday
590 } 588 }
591 } else { 589 } else {
592 m_pDict->RemoveFor("V"); 590 m_pDict->RemoveFor("V");
593 m_pDict->RemoveFor("I"); 591 m_pDict->RemoveFor("I");
594 } 592 }
595 } 593 }
596 } 594 }
597 if (bNotify) 595 if (bNotify)
598 NotifyListOrComboBoxAfterChange(); 596 NotifyListOrComboBoxAfterChange();
599 return TRUE; 597 return true;
600 } 598 }
601 599
602 FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) const { 600 bool CPDF_FormField::IsItemDefaultSelected(int index) const {
603 ASSERT(GetType() == ComboBox || GetType() == ListBox); 601 ASSERT(GetType() == ComboBox || GetType() == ListBox);
604 if (index < 0 || index >= CountOptions()) 602 if (index < 0 || index >= CountOptions())
605 return FALSE; 603 return false;
606 int iDVIndex = GetDefaultSelectedItem(); 604 int iDVIndex = GetDefaultSelectedItem();
607 return iDVIndex >= 0 && iDVIndex == index; 605 return iDVIndex >= 0 && iDVIndex == index;
608 } 606 }
609 607
610 int CPDF_FormField::GetDefaultSelectedItem() const { 608 int CPDF_FormField::GetDefaultSelectedItem() const {
611 ASSERT(GetType() == ComboBox || GetType() == ListBox); 609 ASSERT(GetType() == ComboBox || GetType() == ListBox);
612 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV"); 610 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV");
613 if (!pValue) 611 if (!pValue)
614 return -1; 612 return -1;
615 CFX_WideString csDV = pValue->GetUnicodeText(); 613 CFX_WideString csDV = pValue->GetUnicodeText();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 for (int i = 0; i < CountOptions(); i++) { 660 for (int i = 0; i < CountOptions(); i++) {
663 if (GetOptionValue(i) == csOptValue) 661 if (GetOptionValue(i) == csOptValue)
664 return i; 662 return i;
665 } 663 }
666 return -1; 664 return -1;
667 } 665 }
668 666
669 #ifdef PDF_ENABLE_XFA 667 #ifdef PDF_ENABLE_XFA
670 int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, 668 int CPDF_FormField::InsertOption(CFX_WideString csOptLabel,
671 int index, 669 int index,
672 FX_BOOL bNotify) { 670 bool bNotify) {
673 if (csOptLabel.IsEmpty()) 671 if (csOptLabel.IsEmpty())
674 return -1; 672 return -1;
675 673
676 if (bNotify && !NotifyListOrComboBoxBeforeChange(csOptLabel)) 674 if (bNotify && !NotifyListOrComboBoxBeforeChange(csOptLabel))
677 return -1; 675 return -1;
678 676
679 CFX_ByteString csStr = 677 CFX_ByteString csStr =
680 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); 678 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength());
681 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); 679 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt");
682 CPDF_Array* pOpt = ToArray(pValue); 680 CPDF_Array* pOpt = ToArray(pValue);
683 if (!pOpt) { 681 if (!pOpt) {
684 pOpt = new CPDF_Array; 682 pOpt = new CPDF_Array;
685 m_pDict->SetFor("Opt", pOpt); 683 m_pDict->SetFor("Opt", pOpt);
686 } 684 }
687 685
688 int iCount = pdfium::base::checked_cast<int, size_t>(pOpt->GetCount()); 686 int iCount = pdfium::base::checked_cast<int, size_t>(pOpt->GetCount());
689 if (index >= iCount) { 687 if (index >= iCount) {
690 pOpt->AddString(csStr); 688 pOpt->AddString(csStr);
691 index = iCount; 689 index = iCount;
692 } else { 690 } else {
693 CPDF_String* pString = new CPDF_String(csStr, FALSE); 691 CPDF_String* pString = new CPDF_String(csStr, false);
694 pOpt->InsertAt(index, pString); 692 pOpt->InsertAt(index, pString);
695 } 693 }
696 694
697 if (bNotify) 695 if (bNotify)
698 NotifyListOrComboBoxAfterChange(); 696 NotifyListOrComboBoxAfterChange();
699 return index; 697 return index;
700 } 698 }
701 699
702 FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { 700 bool CPDF_FormField::ClearOptions(bool bNotify) {
703 if (bNotify && m_pForm->m_pFormNotify) { 701 if (bNotify && m_pForm->m_pFormNotify) {
704 CFX_WideString csValue; 702 CFX_WideString csValue;
705 int iIndex = GetSelectedIndex(0); 703 int iIndex = GetSelectedIndex(0);
706 if (iIndex >= 0) 704 if (iIndex >= 0)
707 csValue = GetOptionLabel(iIndex); 705 csValue = GetOptionLabel(iIndex);
708 if (!NotifyListOrComboBoxBeforeChange(csValue)) 706 if (!NotifyListOrComboBoxBeforeChange(csValue))
709 return FALSE; 707 return false;
710 } 708 }
711 709
712 m_pDict->RemoveFor("Opt"); 710 m_pDict->RemoveFor("Opt");
713 m_pDict->RemoveFor("V"); 711 m_pDict->RemoveFor("V");
714 m_pDict->RemoveFor("DV"); 712 m_pDict->RemoveFor("DV");
715 m_pDict->RemoveFor("I"); 713 m_pDict->RemoveFor("I");
716 m_pDict->RemoveFor("TI"); 714 m_pDict->RemoveFor("TI");
717 715
718 if (bNotify) 716 if (bNotify)
719 NotifyListOrComboBoxAfterChange(); 717 NotifyListOrComboBoxAfterChange();
720 718
721 return TRUE; 719 return true;
722 } 720 }
723 #endif // PDF_ENABLE_XFA 721 #endif // PDF_ENABLE_XFA
724 722
725 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, 723 bool CPDF_FormField::CheckControl(int iControlIndex,
726 bool bChecked, 724 bool bChecked,
727 bool bNotify) { 725 bool bNotify) {
728 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 726 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
729 CPDF_FormControl* pControl = GetControl(iControlIndex); 727 CPDF_FormControl* pControl = GetControl(iControlIndex);
730 if (!pControl) 728 if (!pControl)
731 return FALSE; 729 return false;
732 if (!bChecked && pControl->IsChecked() == bChecked) 730 if (!bChecked && pControl->IsChecked() == bChecked)
733 return FALSE; 731 return false;
734 732
735 CFX_WideString csWExport = pControl->GetExportValue(); 733 CFX_WideString csWExport = pControl->GetExportValue();
736 CFX_ByteString csBExport = PDF_EncodeText(csWExport); 734 CFX_ByteString csBExport = PDF_EncodeText(csWExport);
737 int iCount = CountControls(); 735 int iCount = CountControls();
738 bool bUnison = IsUnison(this); 736 bool bUnison = IsUnison(this);
739 for (int i = 0; i < iCount; i++) { 737 for (int i = 0; i < iCount; i++) {
740 CPDF_FormControl* pCtrl = GetControl(i); 738 CPDF_FormControl* pCtrl = GetControl(i);
741 if (bUnison) { 739 if (bUnison) {
742 CFX_WideString csEValue = pCtrl->GetExportValue(); 740 CFX_WideString csEValue = pCtrl->GetExportValue();
743 if (csEValue == csWExport) { 741 if (csEValue == csWExport) {
744 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) 742 if (pCtrl->GetOnStateName() == pControl->GetOnStateName())
745 pCtrl->CheckControl(bChecked); 743 pCtrl->CheckControl(bChecked);
746 else if (bChecked) 744 else if (bChecked)
747 pCtrl->CheckControl(FALSE); 745 pCtrl->CheckControl(false);
748 } else if (bChecked) { 746 } else if (bChecked) {
749 pCtrl->CheckControl(FALSE); 747 pCtrl->CheckControl(false);
750 } 748 }
751 } else { 749 } else {
752 if (i == iControlIndex) 750 if (i == iControlIndex)
753 pCtrl->CheckControl(bChecked); 751 pCtrl->CheckControl(bChecked);
754 else if (bChecked) 752 else if (bChecked)
755 pCtrl->CheckControl(FALSE); 753 pCtrl->CheckControl(false);
756 } 754 }
757 } 755 }
758 756
759 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); 757 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt");
760 if (!ToArray(pOpt)) { 758 if (!ToArray(pOpt)) {
761 if (bChecked) { 759 if (bChecked) {
762 m_pDict->SetNameFor("V", csBExport); 760 m_pDict->SetNameFor("V", csBExport);
763 } else { 761 } else {
764 CFX_ByteString csV; 762 CFX_ByteString csV;
765 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); 763 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
766 if (pV) 764 if (pV)
767 csV = pV->GetString(); 765 csV = pV->GetString();
768 if (csV == csBExport) 766 if (csV == csBExport)
769 m_pDict->SetNameFor("V", "Off"); 767 m_pDict->SetNameFor("V", "Off");
770 } 768 }
771 } else if (bChecked) { 769 } else if (bChecked) {
772 CFX_ByteString csIndex; 770 CFX_ByteString csIndex;
773 csIndex.Format("%d", iControlIndex); 771 csIndex.Format("%d", iControlIndex);
774 m_pDict->SetNameFor("V", csIndex); 772 m_pDict->SetNameFor("V", csIndex);
775 } 773 }
776 if (bNotify && m_pForm->m_pFormNotify) 774 if (bNotify && m_pForm->m_pFormNotify)
777 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); 775 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this);
778 return TRUE; 776 return true;
779 } 777 }
780 778
781 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) const { 779 CFX_WideString CPDF_FormField::GetCheckValue(bool bDefault) const {
782 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 780 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
783 CFX_WideString csExport = L"Off"; 781 CFX_WideString csExport = L"Off";
784 int iCount = CountControls(); 782 int iCount = CountControls();
785 for (int i = 0; i < iCount; i++) { 783 for (int i = 0; i < iCount; i++) {
786 CPDF_FormControl* pControl = GetControl(i); 784 CPDF_FormControl* pControl = GetControl(i);
787 FX_BOOL bChecked = 785 bool bChecked =
788 bDefault ? pControl->IsDefaultChecked() : pControl->IsChecked(); 786 bDefault ? pControl->IsDefaultChecked() : pControl->IsChecked();
789 if (bChecked) { 787 if (bChecked) {
790 csExport = pControl->GetExportValue(); 788 csExport = pControl->GetExportValue();
791 break; 789 break;
792 } 790 }
793 } 791 }
794 return csExport; 792 return csExport;
795 } 793 }
796 794
797 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, 795 bool CPDF_FormField::SetCheckValue(const CFX_WideString& value,
798 FX_BOOL bDefault, 796 bool bDefault,
799 FX_BOOL bNotify) { 797 bool bNotify) {
800 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 798 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
801 int iCount = CountControls(); 799 int iCount = CountControls();
802 for (int i = 0; i < iCount; i++) { 800 for (int i = 0; i < iCount; i++) {
803 CPDF_FormControl* pControl = GetControl(i); 801 CPDF_FormControl* pControl = GetControl(i);
804 CFX_WideString csExport = pControl->GetExportValue(); 802 CFX_WideString csExport = pControl->GetExportValue();
805 bool val = csExport == value; 803 bool val = csExport == value;
806 if (!bDefault) 804 if (!bDefault)
807 CheckControl(GetControlIndex(pControl), val); 805 CheckControl(GetControlIndex(pControl), val);
808 if (val) 806 if (val)
809 break; 807 break;
810 } 808 }
811 if (bNotify && m_pForm->m_pFormNotify) 809 if (bNotify && m_pForm->m_pFormNotify)
812 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); 810 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this);
813 return TRUE; 811 return true;
814 } 812 }
815 813
816 int CPDF_FormField::GetTopVisibleIndex() const { 814 int CPDF_FormField::GetTopVisibleIndex() const {
817 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); 815 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI");
818 return pObj ? pObj->GetInteger() : 0; 816 return pObj ? pObj->GetInteger() : 0;
819 } 817 }
820 818
821 int CPDF_FormField::CountSelectedOptions() const { 819 int CPDF_FormField::CountSelectedOptions() const {
822 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); 820 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I"));
823 return pArray ? pArray->GetCount() : 0; 821 return pArray ? pArray->GetCount() : 0;
824 } 822 }
825 823
826 int CPDF_FormField::GetSelectedOptionIndex(int index) const { 824 int CPDF_FormField::GetSelectedOptionIndex(int index) const {
827 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); 825 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I"));
828 if (!pArray) 826 if (!pArray)
829 return -1; 827 return -1;
830 828
831 int iCount = pArray->GetCount(); 829 int iCount = pArray->GetCount();
832 if (iCount < 0 || index >= iCount) 830 if (iCount < 0 || index >= iCount)
833 return -1; 831 return -1;
834 return pArray->GetIntegerAt(index); 832 return pArray->GetIntegerAt(index);
835 } 833 }
836 834
837 FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) const { 835 bool CPDF_FormField::IsOptionSelected(int iOptIndex) const {
838 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); 836 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I"));
839 if (!pArray) 837 if (!pArray)
840 return FALSE; 838 return false;
841 839
842 for (CPDF_Object* pObj : *pArray) { 840 for (CPDF_Object* pObj : *pArray) {
843 if (pObj->GetInteger() == iOptIndex) 841 if (pObj->GetInteger() == iOptIndex)
844 return TRUE; 842 return true;
845 } 843 }
846 return FALSE; 844 return false;
847 } 845 }
848 846
849 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, 847 bool CPDF_FormField::SelectOption(int iOptIndex, bool bSelected, bool bNotify) {
850 FX_BOOL bSelected,
851 FX_BOOL bNotify) {
852 CPDF_Array* pArray = m_pDict->GetArrayFor("I"); 848 CPDF_Array* pArray = m_pDict->GetArrayFor("I");
853 if (!pArray) { 849 if (!pArray) {
854 if (!bSelected) 850 if (!bSelected)
855 return TRUE; 851 return true;
856 852
857 pArray = new CPDF_Array; 853 pArray = new CPDF_Array;
858 m_pDict->SetFor("I", pArray); 854 m_pDict->SetFor("I", pArray);
859 } 855 }
860 856
861 FX_BOOL bReturn = FALSE; 857 bool bReturn = false;
862 for (size_t i = 0; i < pArray->GetCount(); i++) { 858 for (size_t i = 0; i < pArray->GetCount(); i++) {
863 int iFind = pArray->GetIntegerAt(i); 859 int iFind = pArray->GetIntegerAt(i);
864 if (iFind == iOptIndex) { 860 if (iFind == iOptIndex) {
865 if (bSelected) 861 if (bSelected)
866 return TRUE; 862 return true;
867 863
868 if (bNotify && m_pForm->m_pFormNotify) { 864 if (bNotify && m_pForm->m_pFormNotify) {
869 CFX_WideString csValue = GetOptionLabel(iOptIndex); 865 CFX_WideString csValue = GetOptionLabel(iOptIndex);
870 if (!NotifyListOrComboBoxBeforeChange(csValue)) 866 if (!NotifyListOrComboBoxBeforeChange(csValue))
871 return FALSE; 867 return false;
872 } 868 }
873 pArray->RemoveAt(i); 869 pArray->RemoveAt(i);
874 bReturn = TRUE; 870 bReturn = true;
875 break; 871 break;
876 } 872 }
877 873
878 if (iFind > iOptIndex) { 874 if (iFind > iOptIndex) {
879 if (!bSelected) 875 if (!bSelected)
880 continue; 876 continue;
881 877
882 if (bNotify && m_pForm->m_pFormNotify) { 878 if (bNotify && m_pForm->m_pFormNotify) {
883 CFX_WideString csValue = GetOptionLabel(iOptIndex); 879 CFX_WideString csValue = GetOptionLabel(iOptIndex);
884 if (!NotifyListOrComboBoxBeforeChange(csValue)) 880 if (!NotifyListOrComboBoxBeforeChange(csValue))
885 return FALSE; 881 return false;
886 } 882 }
887 pArray->InsertAt(i, new CPDF_Number(iOptIndex)); 883 pArray->InsertAt(i, new CPDF_Number(iOptIndex));
888 bReturn = TRUE; 884 bReturn = true;
889 break; 885 break;
890 } 886 }
891 } 887 }
892 if (!bReturn) { 888 if (!bReturn) {
893 if (bSelected) 889 if (bSelected)
894 pArray->AddInteger(iOptIndex); 890 pArray->AddInteger(iOptIndex);
895 891
896 if (pArray->IsEmpty()) 892 if (pArray->IsEmpty())
897 m_pDict->RemoveFor("I"); 893 m_pDict->RemoveFor("I");
898 } 894 }
899 if (bNotify) 895 if (bNotify)
900 NotifyListOrComboBoxAfterChange(); 896 NotifyListOrComboBoxAfterChange();
901 897
902 return TRUE; 898 return true;
903 } 899 }
904 900
905 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) { 901 bool CPDF_FormField::ClearSelectedOptions(bool bNotify) {
906 if (bNotify && m_pForm->m_pFormNotify) { 902 if (bNotify && m_pForm->m_pFormNotify) {
907 CFX_WideString csValue; 903 CFX_WideString csValue;
908 int iIndex = GetSelectedIndex(0); 904 int iIndex = GetSelectedIndex(0);
909 if (iIndex >= 0) 905 if (iIndex >= 0)
910 csValue = GetOptionLabel(iIndex); 906 csValue = GetOptionLabel(iIndex);
911 907
912 if (!NotifyListOrComboBoxBeforeChange(csValue)) 908 if (!NotifyListOrComboBoxBeforeChange(csValue))
913 return FALSE; 909 return false;
914 } 910 }
915 m_pDict->RemoveFor("I"); 911 m_pDict->RemoveFor("I");
916 if (bNotify) 912 if (bNotify)
917 NotifyListOrComboBoxAfterChange(); 913 NotifyListOrComboBoxAfterChange();
918 914
919 return TRUE; 915 return true;
920 } 916 }
921 917
922 void CPDF_FormField::LoadDA() { 918 void CPDF_FormField::LoadDA() {
923 CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict; 919 CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict;
924 if (!pFormDict) 920 if (!pFormDict)
925 return; 921 return;
926 922
927 CFX_ByteString DA; 923 CFX_ByteString DA;
928 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DA")) 924 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DA"))
929 DA = pObj->GetString(); 925 DA = pObj->GetString();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 case ListBox: 990 case ListBox:
995 NotifyAfterSelectionChange(); 991 NotifyAfterSelectionChange();
996 break; 992 break;
997 case ComboBox: 993 case ComboBox:
998 NotifyAfterValueChange(); 994 NotifyAfterValueChange();
999 break; 995 break;
1000 default: 996 default:
1001 break; 997 break;
1002 } 998 }
1003 } 999 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_formfield.h ('k') | core/fpdfdoc/cpdf_iconfit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698