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

Side by Side Diff: core/src/fpdfdoc/doc_formfield.cpp

Issue 1512763013: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits Created 5 years 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/src/fpdfdoc/doc_form.cpp ('k') | core/src/fpdfdoc/doc_ocg.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 "core/include/fpdfdoc/fpdf_doc.h" 7 #include "core/include/fpdfdoc/fpdf_doc.h"
8 #include "doc_utils.h" 8 #include "doc_utils.h"
9 9
10 FX_BOOL PDF_FormField_IsUnison(CPDF_FormField* pField) { 10 FX_BOOL PDF_FormField_IsUnison(CPDF_FormField* pField) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 } 97 }
98 CFX_WideString CPDF_FormField::GetFullName() { 98 CFX_WideString CPDF_FormField::GetFullName() {
99 return ::GetFullName(m_pDict); 99 return ::GetFullName(m_pDict);
100 } 100 }
101 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { 101 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) {
102 switch (m_Type) { 102 switch (m_Type) {
103 case CPDF_FormField::CheckBox: 103 case CPDF_FormField::CheckBox:
104 case CPDF_FormField::RadioButton: { 104 case CPDF_FormField::RadioButton: {
105 CFX_ByteArray statusArray; 105 CFX_ByteArray statusArray;
106 if (bNotify && m_pForm->m_pFormNotify != NULL) { 106 if (bNotify && m_pForm->m_pFormNotify) {
107 SaveCheckedFieldStatus(this, statusArray); 107 SaveCheckedFieldStatus(this, statusArray);
108 } 108 }
109 int iCount = CountControls(); 109 int iCount = CountControls();
110 if (iCount) { 110 if (iCount) {
111 if (PDF_FormField_IsUnison(this)) { 111 if (PDF_FormField_IsUnison(this)) {
112 for (int i = 0; i < iCount; i++) { 112 for (int i = 0; i < iCount; i++) {
113 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); 113 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE);
114 } 114 }
115 } else { 115 } else {
116 for (int i = 0; i < iCount; i++) { 116 for (int i = 0; i < iCount; i++) {
117 CPDF_FormControl* pControl = GetControl(i); 117 CPDF_FormControl* pControl = GetControl(i);
118 FX_BOOL bChecked = pControl->IsDefaultChecked(); 118 FX_BOOL bChecked = pControl->IsDefaultChecked();
119 CheckControl(i, bChecked, FALSE); 119 CheckControl(i, bChecked, FALSE);
120 } 120 }
121 } 121 }
122 } 122 }
123 if (bNotify && m_pForm->m_pFormNotify != NULL) { 123 if (bNotify && m_pForm->m_pFormNotify) {
124 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); 124 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray);
125 } 125 }
126 } break; 126 } break;
127 case CPDF_FormField::ComboBox: { 127 case CPDF_FormField::ComboBox: {
128 CFX_WideString csValue; 128 CFX_WideString csValue;
129 ClearSelection(); 129 ClearSelection();
130 int iIndex = GetDefaultSelectedItem(); 130 int iIndex = GetDefaultSelectedItem();
131 if (iIndex >= 0) { 131 if (iIndex >= 0) {
132 csValue = GetOptionLabel(iIndex); 132 csValue = GetOptionLabel(iIndex);
133 } 133 }
134 if (bNotify && m_pForm->m_pFormNotify != NULL) { 134 if (bNotify && m_pForm->m_pFormNotify) {
135 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); 135 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
136 if (iRet < 0) { 136 if (iRet < 0) {
137 return FALSE; 137 return FALSE;
138 } 138 }
139 } 139 }
140 SetItemSelection(iIndex, TRUE); 140 SetItemSelection(iIndex, TRUE);
141 if (bNotify && m_pForm->m_pFormNotify != NULL) { 141 if (bNotify && m_pForm->m_pFormNotify) {
142 m_pForm->m_pFormNotify->AfterValueChange(this); 142 m_pForm->m_pFormNotify->AfterValueChange(this);
143 } 143 }
144 } break; 144 } break;
145 case CPDF_FormField::ListBox: { 145 case CPDF_FormField::ListBox: {
146 CFX_WideString csValue; 146 CFX_WideString csValue;
147 ClearSelection(); 147 ClearSelection();
148 int iIndex = GetDefaultSelectedItem(); 148 int iIndex = GetDefaultSelectedItem();
149 if (iIndex >= 0) { 149 if (iIndex >= 0) {
150 csValue = GetOptionLabel(iIndex); 150 csValue = GetOptionLabel(iIndex);
151 } 151 }
152 if (bNotify && m_pForm->m_pFormNotify != NULL) { 152 if (bNotify && m_pForm->m_pFormNotify) {
153 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); 153 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
154 if (iRet < 0) { 154 if (iRet < 0) {
155 return FALSE; 155 return FALSE;
156 } 156 }
157 } 157 }
158 SetItemSelection(iIndex, TRUE); 158 SetItemSelection(iIndex, TRUE);
159 if (bNotify && m_pForm->m_pFormNotify != NULL) { 159 if (bNotify && m_pForm->m_pFormNotify) {
160 m_pForm->m_pFormNotify->AfterSelectionChange(this); 160 m_pForm->m_pFormNotify->AfterSelectionChange(this);
161 } 161 }
162 } break; 162 } break;
163 case CPDF_FormField::Text: 163 case CPDF_FormField::Text:
164 case CPDF_FormField::RichText: 164 case CPDF_FormField::RichText:
165 case CPDF_FormField::File: 165 case CPDF_FormField::File:
166 default: { 166 default: {
167 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); 167 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV");
168 CFX_WideString csDValue; 168 CFX_WideString csDValue;
169 if (pDV != NULL) { 169 if (pDV) {
170 csDValue = pDV->GetUnicodeText(); 170 csDValue = pDV->GetUnicodeText();
171 } 171 }
172 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); 172 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
173 CFX_WideString csValue; 173 CFX_WideString csValue;
174 if (pV != NULL) { 174 if (pV) {
175 csValue = pV->GetUnicodeText(); 175 csValue = pV->GetUnicodeText();
176 } 176 }
177 CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV"); 177 CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV");
178 if (!pRV && (csDValue == csValue)) { 178 if (!pRV && (csDValue == csValue)) {
179 return FALSE; 179 return FALSE;
180 } 180 }
181 if (bNotify && m_pForm->m_pFormNotify != NULL) { 181 if (bNotify && m_pForm->m_pFormNotify) {
182 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csDValue); 182 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csDValue);
183 if (iRet < 0) { 183 if (iRet < 0) {
184 return FALSE; 184 return FALSE;
185 } 185 }
186 } 186 }
187 if (pDV == NULL) { 187 if (pDV == NULL) {
188 m_pDict->RemoveAt("V"); 188 m_pDict->RemoveAt("V");
189 m_pDict->RemoveAt("RV"); 189 m_pDict->RemoveAt("RV");
190 } else { 190 } else {
191 CPDF_Object* pClone = pDV->Clone(); 191 CPDF_Object* pClone = pDV->Clone();
192 if (pClone == NULL) { 192 if (pClone == NULL) {
193 return FALSE; 193 return FALSE;
194 } 194 }
195 m_pDict->SetAt("V", pClone); 195 m_pDict->SetAt("V", pClone);
196 if (pRV) { 196 if (pRV) {
197 CPDF_Object* pCloneR = pDV->Clone(); 197 CPDF_Object* pCloneR = pDV->Clone();
198 m_pDict->SetAt("RV", pCloneR); 198 m_pDict->SetAt("RV", pCloneR);
199 } 199 }
200 } 200 }
201 if (bNotify && m_pForm->m_pFormNotify != NULL) { 201 if (bNotify && m_pForm->m_pFormNotify) {
202 m_pForm->m_pFormNotify->AfterValueChange(this); 202 m_pForm->m_pFormNotify->AfterValueChange(this);
203 } 203 }
204 m_pForm->m_bUpdated = TRUE; 204 m_pForm->m_bUpdated = TRUE;
205 } break; 205 } break;
206 } 206 }
207 return TRUE; 207 return TRUE;
208 } 208 }
209 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) { 209 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) {
210 if (!pControl) { 210 if (!pControl) {
211 return -1; 211 return -1;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 case CheckBox: 324 case CheckBox:
325 case RadioButton: { 325 case RadioButton: {
326 SetCheckValue(value, bDefault, bNotify); 326 SetCheckValue(value, bDefault, bNotify);
327 return TRUE; 327 return TRUE;
328 } 328 }
329 case File: 329 case File:
330 case RichText: 330 case RichText:
331 case Text: 331 case Text:
332 case ComboBox: { 332 case ComboBox: {
333 CFX_WideString csValue = value; 333 CFX_WideString csValue = value;
334 if (bNotify && m_pForm->m_pFormNotify != NULL) { 334 if (bNotify && m_pForm->m_pFormNotify) {
335 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); 335 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
336 if (iRet < 0) { 336 if (iRet < 0) {
337 return FALSE; 337 return FALSE;
338 } 338 }
339 } 339 }
340 int iIndex = FindOptionValue(csValue); 340 int iIndex = FindOptionValue(csValue);
341 if (iIndex < 0) { 341 if (iIndex < 0) {
342 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue); 342 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue);
343 m_pDict->SetAtString(bDefault ? "DV" : "V", bsEncodeText); 343 m_pDict->SetAtString(bDefault ? "DV" : "V", bsEncodeText);
344 if (m_Type == RichText && !bDefault) { 344 if (m_Type == RichText && !bDefault) {
345 m_pDict->SetAtString("RV", bsEncodeText); 345 m_pDict->SetAtString("RV", bsEncodeText);
346 } 346 }
347 m_pDict->RemoveAt("I"); 347 m_pDict->RemoveAt("I");
348 } else { 348 } else {
349 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(csValue)); 349 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(csValue));
350 if (bDefault) { 350 if (bDefault) {
351 } else { 351 } else {
352 ClearSelection(); 352 ClearSelection();
353 SetItemSelection(iIndex, TRUE); 353 SetItemSelection(iIndex, TRUE);
354 } 354 }
355 } 355 }
356 if (bNotify && m_pForm->m_pFormNotify != NULL) { 356 if (bNotify && m_pForm->m_pFormNotify) {
357 m_pForm->m_pFormNotify->AfterValueChange(this); 357 m_pForm->m_pFormNotify->AfterValueChange(this);
358 } 358 }
359 m_pForm->m_bUpdated = TRUE; 359 m_pForm->m_bUpdated = TRUE;
360 } break; 360 } break;
361 case ListBox: { 361 case ListBox: {
362 int iIndex = FindOptionValue(value); 362 int iIndex = FindOptionValue(value);
363 if (iIndex < 0) { 363 if (iIndex < 0) {
364 return FALSE; 364 return FALSE;
365 } 365 }
366 if (bDefault && iIndex == GetDefaultSelectedItem()) { 366 if (bDefault && iIndex == GetDefaultSelectedItem()) {
367 return FALSE; 367 return FALSE;
368 } 368 }
369 if (bNotify && m_pForm->m_pFormNotify != NULL) { 369 if (bNotify && m_pForm->m_pFormNotify) {
370 CFX_WideString csValue = value; 370 CFX_WideString csValue = value;
371 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); 371 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
372 if (iRet < 0) { 372 if (iRet < 0) {
373 return FALSE; 373 return FALSE;
374 } 374 }
375 } 375 }
376 if (bDefault) { 376 if (bDefault) {
377 } else { 377 } else {
378 ClearSelection(); 378 ClearSelection();
379 SetItemSelection(iIndex, TRUE); 379 SetItemSelection(iIndex, TRUE);
380 } 380 }
381 if (bNotify && m_pForm->m_pFormNotify != NULL) { 381 if (bNotify && m_pForm->m_pFormNotify) {
382 m_pForm->m_pFormNotify->AfterSelectionChange(this); 382 m_pForm->m_pFormNotify->AfterSelectionChange(this);
383 } 383 }
384 m_pForm->m_bUpdated = TRUE; 384 m_pForm->m_bUpdated = TRUE;
385 break; 385 break;
386 } 386 }
387 default: 387 default:
388 break; 388 break;
389 } 389 }
390 if (CPDF_InterForm::m_bUpdateAP) { 390 if (CPDF_InterForm::m_bUpdateAP) {
391 UpdateAP(NULL); 391 UpdateAP(NULL);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 } 457 }
458 int nOpts = CountOptions(); 458 int nOpts = CountOptions();
459 for (int i = 0; i < nOpts; i++) { 459 for (int i = 0; i < nOpts; i++) {
460 if (sel_value == GetOptionValue(i)) { 460 if (sel_value == GetOptionValue(i)) {
461 return i; 461 return i;
462 } 462 }
463 } 463 }
464 return -1; 464 return -1;
465 } 465 }
466 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) { 466 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) {
467 if (bNotify && m_pForm->m_pFormNotify != NULL) { 467 if (bNotify && m_pForm->m_pFormNotify) {
468 int iRet = 0; 468 int iRet = 0;
469 CFX_WideString csValue; 469 CFX_WideString csValue;
470 int iIndex = GetSelectedIndex(0); 470 int iIndex = GetSelectedIndex(0);
471 if (iIndex >= 0) { 471 if (iIndex >= 0) {
472 csValue = GetOptionLabel(iIndex); 472 csValue = GetOptionLabel(iIndex);
473 } 473 }
474 if (GetType() == ListBox) { 474 if (GetType() == ListBox) {
475 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); 475 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
476 } 476 }
477 if (GetType() == ComboBox) { 477 if (GetType() == ComboBox) {
478 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); 478 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
479 } 479 }
480 if (iRet < 0) { 480 if (iRet < 0) {
481 return FALSE; 481 return FALSE;
482 } 482 }
483 } 483 }
484 m_pDict->RemoveAt("V"); 484 m_pDict->RemoveAt("V");
485 m_pDict->RemoveAt("I"); 485 m_pDict->RemoveAt("I");
486 if (bNotify && m_pForm->m_pFormNotify != NULL) { 486 if (bNotify && m_pForm->m_pFormNotify) {
487 if (GetType() == ListBox) { 487 if (GetType() == ListBox) {
488 m_pForm->m_pFormNotify->AfterSelectionChange(this); 488 m_pForm->m_pFormNotify->AfterSelectionChange(this);
489 } 489 }
490 if (GetType() == ComboBox) { 490 if (GetType() == ComboBox) {
491 m_pForm->m_pFormNotify->AfterValueChange(this); 491 m_pForm->m_pFormNotify->AfterValueChange(this);
492 } 492 }
493 } 493 }
494 if (CPDF_InterForm::m_bUpdateAP) { 494 if (CPDF_InterForm::m_bUpdateAP) {
495 UpdateAP(NULL); 495 UpdateAP(NULL);
496 } 496 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 return FALSE; 542 return FALSE;
543 } 543 }
544 FX_BOOL CPDF_FormField::SetItemSelection(int index, 544 FX_BOOL CPDF_FormField::SetItemSelection(int index,
545 FX_BOOL bSelected, 545 FX_BOOL bSelected,
546 FX_BOOL bNotify) { 546 FX_BOOL bNotify) {
547 ASSERT(GetType() == ComboBox || GetType() == ListBox); 547 ASSERT(GetType() == ComboBox || GetType() == ListBox);
548 if (index < 0 || index >= CountOptions()) { 548 if (index < 0 || index >= CountOptions()) {
549 return FALSE; 549 return FALSE;
550 } 550 }
551 CFX_WideString opt_value = GetOptionValue(index); 551 CFX_WideString opt_value = GetOptionValue(index);
552 if (bNotify && m_pForm->m_pFormNotify != NULL) { 552 if (bNotify && m_pForm->m_pFormNotify) {
553 int iRet = 0; 553 int iRet = 0;
554 if (GetType() == ListBox) { 554 if (GetType() == ListBox) {
555 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, opt_value); 555 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, opt_value);
556 } 556 }
557 if (GetType() == ComboBox) { 557 if (GetType() == ComboBox) {
558 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, opt_value); 558 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, opt_value);
559 } 559 }
560 if (iRet < 0) { 560 if (iRet < 0) {
561 return FALSE; 561 return FALSE;
562 } 562 }
563 } 563 }
564 if (!bSelected) { 564 if (!bSelected) {
565 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 565 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
566 if (pValue != NULL) { 566 if (pValue) {
567 if (m_Type == ListBox) { 567 if (m_Type == ListBox) {
568 SelectOption(index, FALSE); 568 SelectOption(index, FALSE);
569 if (pValue->IsString()) { 569 if (pValue->IsString()) {
570 if (pValue->GetUnicodeText() == opt_value) { 570 if (pValue->GetUnicodeText() == opt_value) {
571 m_pDict->RemoveAt("V"); 571 m_pDict->RemoveAt("V");
572 } 572 }
573 } else if (pValue->IsArray()) { 573 } else if (pValue->IsArray()) {
574 CPDF_Array* pArray = CPDF_Array::Create(); 574 CPDF_Array* pArray = CPDF_Array::Create();
575 int iCount = CountOptions(); 575 int iCount = CountOptions();
576 for (int i = 0; i < iCount; i++) { 576 for (int i = 0; i < iCount; i++) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 } else if (m_Type == ComboBox) { 620 } else if (m_Type == ComboBox) {
621 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); 621 m_pDict->SetAtString("V", PDF_EncodeText(opt_value));
622 CPDF_Array* pI = CPDF_Array::Create(); 622 CPDF_Array* pI = CPDF_Array::Create();
623 if (pI == NULL) { 623 if (pI == NULL) {
624 return FALSE; 624 return FALSE;
625 } 625 }
626 pI->AddInteger(index); 626 pI->AddInteger(index);
627 m_pDict->SetAt("I", pI); 627 m_pDict->SetAt("I", pI);
628 } 628 }
629 } 629 }
630 if (bNotify && m_pForm->m_pFormNotify != NULL) { 630 if (bNotify && m_pForm->m_pFormNotify) {
631 if (GetType() == ListBox) { 631 if (GetType() == ListBox) {
632 m_pForm->m_pFormNotify->AfterSelectionChange(this); 632 m_pForm->m_pFormNotify->AfterSelectionChange(this);
633 } 633 }
634 if (GetType() == ComboBox) { 634 if (GetType() == ComboBox) {
635 m_pForm->m_pFormNotify->AfterValueChange(this); 635 m_pForm->m_pFormNotify->AfterValueChange(this);
636 } 636 }
637 } 637 }
638 if (CPDF_InterForm::m_bUpdateAP) { 638 if (CPDF_InterForm::m_bUpdateAP) {
639 UpdateAP(NULL); 639 UpdateAP(NULL);
640 } 640 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 FX_BOOL bNotify) { 738 FX_BOOL bNotify) {
739 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 739 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
740 CPDF_FormControl* pControl = GetControl(iControlIndex); 740 CPDF_FormControl* pControl = GetControl(iControlIndex);
741 if (pControl == NULL) { 741 if (pControl == NULL) {
742 return FALSE; 742 return FALSE;
743 } 743 }
744 if (!bChecked && pControl->IsChecked() == bChecked) { 744 if (!bChecked && pControl->IsChecked() == bChecked) {
745 return FALSE; 745 return FALSE;
746 } 746 }
747 CFX_ByteArray statusArray; 747 CFX_ByteArray statusArray;
748 if (bNotify && m_pForm->m_pFormNotify != NULL) { 748 if (bNotify && m_pForm->m_pFormNotify) {
749 SaveCheckedFieldStatus(this, statusArray); 749 SaveCheckedFieldStatus(this, statusArray);
750 } 750 }
751 CFX_WideString csWExport = pControl->GetExportValue(); 751 CFX_WideString csWExport = pControl->GetExportValue();
752 CFX_ByteString csBExport = PDF_EncodeText(csWExport); 752 CFX_ByteString csBExport = PDF_EncodeText(csWExport);
753 int iCount = CountControls(); 753 int iCount = CountControls();
754 FX_BOOL bUnison = PDF_FormField_IsUnison(this); 754 FX_BOOL bUnison = PDF_FormField_IsUnison(this);
755 for (int i = 0; i < iCount; i++) { 755 for (int i = 0; i < iCount; i++) {
756 CPDF_FormControl* pCtrl = GetControl(i); 756 CPDF_FormControl* pCtrl = GetControl(i);
757 if (bUnison) { 757 if (bUnison) {
758 CFX_WideString csEValue = pCtrl->GetExportValue(); 758 CFX_WideString csEValue = pCtrl->GetExportValue();
(...skipping 14 matching lines...) Expand all
773 } 773 }
774 } 774 }
775 } 775 }
776 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); 776 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt");
777 if (!ToArray(pOpt)) { 777 if (!ToArray(pOpt)) {
778 if (bChecked) { 778 if (bChecked) {
779 m_pDict->SetAtName("V", csBExport); 779 m_pDict->SetAtName("V", csBExport);
780 } else { 780 } else {
781 CFX_ByteString csV; 781 CFX_ByteString csV;
782 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); 782 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
783 if (pV != NULL) { 783 if (pV) {
784 csV = pV->GetString(); 784 csV = pV->GetString();
785 } 785 }
786 if (csV == csBExport) { 786 if (csV == csBExport) {
787 m_pDict->SetAtName("V", "Off"); 787 m_pDict->SetAtName("V", "Off");
788 } 788 }
789 } 789 }
790 } else if (bChecked) { 790 } else if (bChecked) {
791 CFX_ByteString csIndex; 791 CFX_ByteString csIndex;
792 csIndex.Format("%d", iControlIndex); 792 csIndex.Format("%d", iControlIndex);
793 m_pDict->SetAtName("V", csIndex); 793 m_pDict->SetAtName("V", csIndex);
794 } 794 }
795 if (bNotify && m_pForm->m_pFormNotify != NULL) { 795 if (bNotify && m_pForm->m_pFormNotify) {
796 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); 796 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray);
797 } 797 }
798 m_pForm->m_bUpdated = TRUE; 798 m_pForm->m_bUpdated = TRUE;
799 return TRUE; 799 return TRUE;
800 } 800 }
801 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) { 801 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) {
802 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 802 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
803 CFX_WideString csExport = L"Off"; 803 CFX_WideString csExport = L"Off";
804 FX_BOOL bChecked; 804 FX_BOOL bChecked;
805 int iCount = CountControls(); 805 int iCount = CountControls();
806 for (int i = 0; i < iCount; i++) { 806 for (int i = 0; i < iCount; i++) {
807 CPDF_FormControl* pControl = GetControl(i); 807 CPDF_FormControl* pControl = GetControl(i);
808 if (bDefault) { 808 if (bDefault) {
809 bChecked = pControl->IsDefaultChecked(); 809 bChecked = pControl->IsDefaultChecked();
810 } else { 810 } else {
811 bChecked = pControl->IsChecked(); 811 bChecked = pControl->IsChecked();
812 } 812 }
813 if (bChecked) { 813 if (bChecked) {
814 csExport = pControl->GetExportValue(); 814 csExport = pControl->GetExportValue();
815 break; 815 break;
816 } 816 }
817 } 817 }
818 return csExport; 818 return csExport;
819 } 819 }
820 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, 820 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value,
821 FX_BOOL bDefault, 821 FX_BOOL bDefault,
822 FX_BOOL bNotify) { 822 FX_BOOL bNotify) {
823 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 823 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
824 CFX_ByteArray statusArray; 824 CFX_ByteArray statusArray;
825 if (bNotify && m_pForm->m_pFormNotify != NULL) { 825 if (bNotify && m_pForm->m_pFormNotify) {
826 SaveCheckedFieldStatus(this, statusArray); 826 SaveCheckedFieldStatus(this, statusArray);
827 } 827 }
828 int iCount = CountControls(); 828 int iCount = CountControls();
829 for (int i = 0; i < iCount; i++) { 829 for (int i = 0; i < iCount; i++) {
830 CPDF_FormControl* pControl = GetControl(i); 830 CPDF_FormControl* pControl = GetControl(i);
831 CFX_WideString csExport = pControl->GetExportValue(); 831 CFX_WideString csExport = pControl->GetExportValue();
832 if (csExport == value) { 832 if (csExport == value) {
833 if (bDefault) { 833 if (bDefault) {
834 } else { 834 } else {
835 CheckControl(GetControlIndex(pControl), TRUE); 835 CheckControl(GetControlIndex(pControl), TRUE);
836 } 836 }
837 break; 837 break;
838 } else { 838 } else {
839 if (bDefault) { 839 if (bDefault) {
840 } else { 840 } else {
841 CheckControl(GetControlIndex(pControl), FALSE); 841 CheckControl(GetControlIndex(pControl), FALSE);
842 } 842 }
843 } 843 }
844 } 844 }
845 if (bNotify && m_pForm->m_pFormNotify != NULL) { 845 if (bNotify && m_pForm->m_pFormNotify) {
846 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); 846 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray);
847 } 847 }
848 m_pForm->m_bUpdated = TRUE; 848 m_pForm->m_bUpdated = TRUE;
849 return TRUE; 849 return TRUE;
850 } 850 }
851 int CPDF_FormField::GetTopVisibleIndex() { 851 int CPDF_FormField::GetTopVisibleIndex() {
852 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); 852 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI");
853 if (pObj == NULL) { 853 if (pObj == NULL) {
854 return 0; 854 return 0;
855 } 855 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 } 912 }
913 m_pDict->SetAt("I", pArray); 913 m_pDict->SetAt("I", pArray);
914 } 914 }
915 FX_BOOL bReturn = FALSE; 915 FX_BOOL bReturn = FALSE;
916 for (int i = 0; i < (int)pArray->GetCount(); i++) { 916 for (int i = 0; i < (int)pArray->GetCount(); i++) {
917 int iFind = pArray->GetInteger(i); 917 int iFind = pArray->GetInteger(i);
918 if (iFind == iOptIndex) { 918 if (iFind == iOptIndex) {
919 if (bSelected) { 919 if (bSelected) {
920 return TRUE; 920 return TRUE;
921 } 921 }
922 if (bNotify && m_pForm->m_pFormNotify != NULL) { 922 if (bNotify && m_pForm->m_pFormNotify) {
923 int iRet = 0; 923 int iRet = 0;
924 CFX_WideString csValue = GetOptionLabel(iOptIndex); 924 CFX_WideString csValue = GetOptionLabel(iOptIndex);
925 if (GetType() == ListBox) { 925 if (GetType() == ListBox) {
926 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); 926 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
927 } 927 }
928 if (GetType() == ComboBox) { 928 if (GetType() == ComboBox) {
929 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); 929 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
930 } 930 }
931 if (iRet < 0) { 931 if (iRet < 0) {
932 return FALSE; 932 return FALSE;
933 } 933 }
934 } 934 }
935 pArray->RemoveAt(i); 935 pArray->RemoveAt(i);
936 bReturn = TRUE; 936 bReturn = TRUE;
937 break; 937 break;
938 } else if (iFind > iOptIndex) { 938 } else if (iFind > iOptIndex) {
939 if (!bSelected) { 939 if (!bSelected) {
940 continue; 940 continue;
941 } 941 }
942 if (bNotify && m_pForm->m_pFormNotify != NULL) { 942 if (bNotify && m_pForm->m_pFormNotify) {
943 int iRet = 0; 943 int iRet = 0;
944 CFX_WideString csValue = GetOptionLabel(iOptIndex); 944 CFX_WideString csValue = GetOptionLabel(iOptIndex);
945 if (GetType() == ListBox) { 945 if (GetType() == ListBox) {
946 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); 946 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
947 } 947 }
948 if (GetType() == ComboBox) { 948 if (GetType() == ComboBox) {
949 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); 949 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
950 } 950 }
951 if (iRet < 0) { 951 if (iRet < 0) {
952 return FALSE; 952 return FALSE;
953 } 953 }
954 } 954 }
955 CPDF_Number* pNum = CPDF_Number::Create(iOptIndex); 955 CPDF_Number* pNum = CPDF_Number::Create(iOptIndex);
956 if (pNum == NULL) { 956 if (pNum == NULL) {
957 return FALSE; 957 return FALSE;
958 } 958 }
959 pArray->InsertAt(i, pNum); 959 pArray->InsertAt(i, pNum);
960 bReturn = TRUE; 960 bReturn = TRUE;
961 break; 961 break;
962 } 962 }
963 } 963 }
964 if (!bReturn) { 964 if (!bReturn) {
965 if (bSelected) { 965 if (bSelected) {
966 pArray->AddInteger(iOptIndex); 966 pArray->AddInteger(iOptIndex);
967 } 967 }
968 if (pArray->GetCount() == 0) { 968 if (pArray->GetCount() == 0) {
969 m_pDict->RemoveAt("I"); 969 m_pDict->RemoveAt("I");
970 } 970 }
971 } 971 }
972 if (bNotify && m_pForm->m_pFormNotify != NULL) { 972 if (bNotify && m_pForm->m_pFormNotify) {
973 if (GetType() == ListBox) { 973 if (GetType() == ListBox) {
974 m_pForm->m_pFormNotify->AfterSelectionChange(this); 974 m_pForm->m_pFormNotify->AfterSelectionChange(this);
975 } 975 }
976 if (GetType() == ComboBox) { 976 if (GetType() == ComboBox) {
977 m_pForm->m_pFormNotify->AfterValueChange(this); 977 m_pForm->m_pFormNotify->AfterValueChange(this);
978 } 978 }
979 } 979 }
980 m_pForm->m_bUpdated = TRUE; 980 m_pForm->m_bUpdated = TRUE;
981 return TRUE; 981 return TRUE;
982 } 982 }
983 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) { 983 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) {
984 if (bNotify && m_pForm->m_pFormNotify != NULL) { 984 if (bNotify && m_pForm->m_pFormNotify) {
985 int iRet = 0; 985 int iRet = 0;
986 CFX_WideString csValue; 986 CFX_WideString csValue;
987 int iIndex = GetSelectedIndex(0); 987 int iIndex = GetSelectedIndex(0);
988 if (iIndex >= 0) { 988 if (iIndex >= 0) {
989 csValue = GetOptionLabel(iIndex); 989 csValue = GetOptionLabel(iIndex);
990 } 990 }
991 if (GetType() == ListBox) { 991 if (GetType() == ListBox) {
992 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); 992 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
993 } 993 }
994 if (GetType() == ComboBox) { 994 if (GetType() == ComboBox) {
995 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); 995 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
996 } 996 }
997 if (iRet < 0) { 997 if (iRet < 0) {
998 return FALSE; 998 return FALSE;
999 } 999 }
1000 } 1000 }
1001 m_pDict->RemoveAt("I"); 1001 m_pDict->RemoveAt("I");
1002 if (bNotify && m_pForm->m_pFormNotify != NULL) { 1002 if (bNotify && m_pForm->m_pFormNotify) {
1003 if (GetType() == ListBox) { 1003 if (GetType() == ListBox) {
1004 m_pForm->m_pFormNotify->AfterSelectionChange(this); 1004 m_pForm->m_pFormNotify->AfterSelectionChange(this);
1005 } 1005 }
1006 if (GetType() == ComboBox) { 1006 if (GetType() == ComboBox) {
1007 m_pForm->m_pFormNotify->AfterValueChange(this); 1007 m_pForm->m_pFormNotify->AfterValueChange(this);
1008 } 1008 }
1009 } 1009 }
1010 m_pForm->m_bUpdated = TRUE; 1010 m_pForm->m_bUpdated = TRUE;
1011 return TRUE; 1011 return TRUE;
1012 } 1012 }
(...skipping 16 matching lines...) Expand all
1029 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")) 1029 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font"))
1030 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict( 1030 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(
1031 font_name); 1031 font_name);
1032 1032
1033 if (pFontDict == NULL) { 1033 if (pFontDict == NULL) {
1034 return; 1034 return;
1035 } 1035 }
1036 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); 1036 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict);
1037 m_FontSize = FX_atof(syntax.GetWord()); 1037 m_FontSize = FX_atof(syntax.GetWord());
1038 } 1038 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_form.cpp ('k') | core/src/fpdfdoc/doc_ocg.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698