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

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

Issue 1529553003: Merge to XFA: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: 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
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 FX_BOOL bNotify) { 817 FX_BOOL bNotify) {
818 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 818 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
819 CPDF_FormControl* pControl = GetControl(iControlIndex); 819 CPDF_FormControl* pControl = GetControl(iControlIndex);
820 if (pControl == NULL) { 820 if (pControl == NULL) {
821 return FALSE; 821 return FALSE;
822 } 822 }
823 if (!bChecked && pControl->IsChecked() == bChecked) { 823 if (!bChecked && pControl->IsChecked() == bChecked) {
824 return FALSE; 824 return FALSE;
825 } 825 }
826 CFX_ByteArray statusArray; 826 CFX_ByteArray statusArray;
827 if (bNotify && m_pForm->m_pFormNotify != NULL) { 827 if (bNotify && m_pForm->m_pFormNotify) {
828 SaveCheckedFieldStatus(this, statusArray); 828 SaveCheckedFieldStatus(this, statusArray);
829 } 829 }
830 CFX_WideString csWExport = pControl->GetExportValue(); 830 CFX_WideString csWExport = pControl->GetExportValue();
831 CFX_ByteString csBExport = PDF_EncodeText(csWExport); 831 CFX_ByteString csBExport = PDF_EncodeText(csWExport);
832 int iCount = CountControls(); 832 int iCount = CountControls();
833 FX_BOOL bUnison = PDF_FormField_IsUnison(this); 833 FX_BOOL bUnison = PDF_FormField_IsUnison(this);
834 for (int i = 0; i < iCount; i++) { 834 for (int i = 0; i < iCount; i++) {
835 CPDF_FormControl* pCtrl = GetControl(i); 835 CPDF_FormControl* pCtrl = GetControl(i);
836 if (bUnison) { 836 if (bUnison) {
837 CFX_WideString csEValue = pCtrl->GetExportValue(); 837 CFX_WideString csEValue = pCtrl->GetExportValue();
(...skipping 14 matching lines...) Expand all
852 } 852 }
853 } 853 }
854 } 854 }
855 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); 855 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt");
856 if (!ToArray(pOpt)) { 856 if (!ToArray(pOpt)) {
857 if (bChecked) { 857 if (bChecked) {
858 m_pDict->SetAtName("V", csBExport); 858 m_pDict->SetAtName("V", csBExport);
859 } else { 859 } else {
860 CFX_ByteString csV; 860 CFX_ByteString csV;
861 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); 861 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
862 if (pV != NULL) { 862 if (pV) {
863 csV = pV->GetString(); 863 csV = pV->GetString();
864 } 864 }
865 if (csV == csBExport) { 865 if (csV == csBExport) {
866 m_pDict->SetAtName("V", "Off"); 866 m_pDict->SetAtName("V", "Off");
867 } 867 }
868 } 868 }
869 } else if (bChecked) { 869 } else if (bChecked) {
870 CFX_ByteString csIndex; 870 CFX_ByteString csIndex;
871 csIndex.Format("%d", iControlIndex); 871 csIndex.Format("%d", iControlIndex);
872 m_pDict->SetAtName("V", csIndex); 872 m_pDict->SetAtName("V", csIndex);
873 } 873 }
874 if (bNotify && m_pForm->m_pFormNotify != NULL) { 874 if (bNotify && m_pForm->m_pFormNotify) {
875 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); 875 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray);
876 } 876 }
877 m_pForm->m_bUpdated = TRUE; 877 m_pForm->m_bUpdated = TRUE;
878 return TRUE; 878 return TRUE;
879 } 879 }
880 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) { 880 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) {
881 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 881 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
882 CFX_WideString csExport = L"Off"; 882 CFX_WideString csExport = L"Off";
883 FX_BOOL bChecked; 883 FX_BOOL bChecked;
884 int iCount = CountControls(); 884 int iCount = CountControls();
885 for (int i = 0; i < iCount; i++) { 885 for (int i = 0; i < iCount; i++) {
886 CPDF_FormControl* pControl = GetControl(i); 886 CPDF_FormControl* pControl = GetControl(i);
887 if (bDefault) { 887 if (bDefault) {
888 bChecked = pControl->IsDefaultChecked(); 888 bChecked = pControl->IsDefaultChecked();
889 } else { 889 } else {
890 bChecked = pControl->IsChecked(); 890 bChecked = pControl->IsChecked();
891 } 891 }
892 if (bChecked) { 892 if (bChecked) {
893 csExport = pControl->GetExportValue(); 893 csExport = pControl->GetExportValue();
894 break; 894 break;
895 } 895 }
896 } 896 }
897 return csExport; 897 return csExport;
898 } 898 }
899 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, 899 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value,
900 FX_BOOL bDefault, 900 FX_BOOL bDefault,
901 FX_BOOL bNotify) { 901 FX_BOOL bNotify) {
902 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 902 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
903 CFX_ByteArray statusArray; 903 CFX_ByteArray statusArray;
904 if (bNotify && m_pForm->m_pFormNotify != NULL) { 904 if (bNotify && m_pForm->m_pFormNotify) {
905 SaveCheckedFieldStatus(this, statusArray); 905 SaveCheckedFieldStatus(this, statusArray);
906 } 906 }
907 int iCount = CountControls(); 907 int iCount = CountControls();
908 for (int i = 0; i < iCount; i++) { 908 for (int i = 0; i < iCount; i++) {
909 CPDF_FormControl* pControl = GetControl(i); 909 CPDF_FormControl* pControl = GetControl(i);
910 CFX_WideString csExport = pControl->GetExportValue(); 910 CFX_WideString csExport = pControl->GetExportValue();
911 if (csExport == value) { 911 if (csExport == value) {
912 if (bDefault) { 912 if (bDefault) {
913 } else { 913 } else {
914 CheckControl(GetControlIndex(pControl), TRUE); 914 CheckControl(GetControlIndex(pControl), TRUE);
915 } 915 }
916 break; 916 break;
917 } else { 917 } else {
918 if (bDefault) { 918 if (bDefault) {
919 } else { 919 } else {
920 CheckControl(GetControlIndex(pControl), FALSE); 920 CheckControl(GetControlIndex(pControl), FALSE);
921 } 921 }
922 } 922 }
923 } 923 }
924 if (bNotify && m_pForm->m_pFormNotify != NULL) { 924 if (bNotify && m_pForm->m_pFormNotify) {
925 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); 925 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray);
926 } 926 }
927 m_pForm->m_bUpdated = TRUE; 927 m_pForm->m_bUpdated = TRUE;
928 return TRUE; 928 return TRUE;
929 } 929 }
930 int CPDF_FormField::GetTopVisibleIndex() { 930 int CPDF_FormField::GetTopVisibleIndex() {
931 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); 931 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI");
932 if (pObj == NULL) { 932 if (pObj == NULL) {
933 return 0; 933 return 0;
934 } 934 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 } 991 }
992 m_pDict->SetAt("I", pArray); 992 m_pDict->SetAt("I", pArray);
993 } 993 }
994 FX_BOOL bReturn = FALSE; 994 FX_BOOL bReturn = FALSE;
995 for (int i = 0; i < (int)pArray->GetCount(); i++) { 995 for (int i = 0; i < (int)pArray->GetCount(); i++) {
996 int iFind = pArray->GetInteger(i); 996 int iFind = pArray->GetInteger(i);
997 if (iFind == iOptIndex) { 997 if (iFind == iOptIndex) {
998 if (bSelected) { 998 if (bSelected) {
999 return TRUE; 999 return TRUE;
1000 } 1000 }
1001 if (bNotify && m_pForm->m_pFormNotify != NULL) { 1001 if (bNotify && m_pForm->m_pFormNotify) {
1002 int iRet = 0; 1002 int iRet = 0;
1003 CFX_WideString csValue = GetOptionLabel(iOptIndex); 1003 CFX_WideString csValue = GetOptionLabel(iOptIndex);
1004 if (GetType() == ListBox) { 1004 if (GetType() == ListBox) {
1005 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); 1005 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
1006 } 1006 }
1007 if (GetType() == ComboBox) { 1007 if (GetType() == ComboBox) {
1008 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); 1008 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
1009 } 1009 }
1010 if (iRet < 0) { 1010 if (iRet < 0) {
1011 return FALSE; 1011 return FALSE;
1012 } 1012 }
1013 } 1013 }
1014 pArray->RemoveAt(i); 1014 pArray->RemoveAt(i);
1015 bReturn = TRUE; 1015 bReturn = TRUE;
1016 break; 1016 break;
1017 } else if (iFind > iOptIndex) { 1017 } else if (iFind > iOptIndex) {
1018 if (!bSelected) { 1018 if (!bSelected) {
1019 continue; 1019 continue;
1020 } 1020 }
1021 if (bNotify && m_pForm->m_pFormNotify != NULL) { 1021 if (bNotify && m_pForm->m_pFormNotify) {
1022 int iRet = 0; 1022 int iRet = 0;
1023 CFX_WideString csValue = GetOptionLabel(iOptIndex); 1023 CFX_WideString csValue = GetOptionLabel(iOptIndex);
1024 if (GetType() == ListBox) { 1024 if (GetType() == ListBox) {
1025 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); 1025 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
1026 } 1026 }
1027 if (GetType() == ComboBox) { 1027 if (GetType() == ComboBox) {
1028 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); 1028 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
1029 } 1029 }
1030 if (iRet < 0) { 1030 if (iRet < 0) {
1031 return FALSE; 1031 return FALSE;
1032 } 1032 }
1033 } 1033 }
1034 CPDF_Number* pNum = CPDF_Number::Create(iOptIndex); 1034 CPDF_Number* pNum = CPDF_Number::Create(iOptIndex);
1035 if (pNum == NULL) { 1035 if (pNum == NULL) {
1036 return FALSE; 1036 return FALSE;
1037 } 1037 }
1038 pArray->InsertAt(i, pNum); 1038 pArray->InsertAt(i, pNum);
1039 bReturn = TRUE; 1039 bReturn = TRUE;
1040 break; 1040 break;
1041 } 1041 }
1042 } 1042 }
1043 if (!bReturn) { 1043 if (!bReturn) {
1044 if (bSelected) { 1044 if (bSelected) {
1045 pArray->AddInteger(iOptIndex); 1045 pArray->AddInteger(iOptIndex);
1046 } 1046 }
1047 if (pArray->GetCount() == 0) { 1047 if (pArray->GetCount() == 0) {
1048 m_pDict->RemoveAt("I"); 1048 m_pDict->RemoveAt("I");
1049 } 1049 }
1050 } 1050 }
1051 if (bNotify && m_pForm->m_pFormNotify != NULL) { 1051 if (bNotify && m_pForm->m_pFormNotify) {
1052 if (GetType() == ListBox) { 1052 if (GetType() == ListBox) {
1053 m_pForm->m_pFormNotify->AfterSelectionChange(this); 1053 m_pForm->m_pFormNotify->AfterSelectionChange(this);
1054 } 1054 }
1055 if (GetType() == ComboBox) { 1055 if (GetType() == ComboBox) {
1056 m_pForm->m_pFormNotify->AfterValueChange(this); 1056 m_pForm->m_pFormNotify->AfterValueChange(this);
1057 } 1057 }
1058 } 1058 }
1059 m_pForm->m_bUpdated = TRUE; 1059 m_pForm->m_bUpdated = TRUE;
1060 return TRUE; 1060 return TRUE;
1061 } 1061 }
1062 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) { 1062 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) {
1063 if (bNotify && m_pForm->m_pFormNotify != NULL) { 1063 if (bNotify && m_pForm->m_pFormNotify) {
1064 int iRet = 0; 1064 int iRet = 0;
1065 CFX_WideString csValue; 1065 CFX_WideString csValue;
1066 int iIndex = GetSelectedIndex(0); 1066 int iIndex = GetSelectedIndex(0);
1067 if (iIndex >= 0) { 1067 if (iIndex >= 0) {
1068 csValue = GetOptionLabel(iIndex); 1068 csValue = GetOptionLabel(iIndex);
1069 } 1069 }
1070 if (GetType() == ListBox) { 1070 if (GetType() == ListBox) {
1071 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); 1071 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
1072 } 1072 }
1073 if (GetType() == ComboBox) { 1073 if (GetType() == ComboBox) {
1074 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); 1074 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
1075 } 1075 }
1076 if (iRet < 0) { 1076 if (iRet < 0) {
1077 return FALSE; 1077 return FALSE;
1078 } 1078 }
1079 } 1079 }
1080 m_pDict->RemoveAt("I"); 1080 m_pDict->RemoveAt("I");
1081 if (bNotify && m_pForm->m_pFormNotify != NULL) { 1081 if (bNotify && m_pForm->m_pFormNotify) {
1082 if (GetType() == ListBox) { 1082 if (GetType() == ListBox) {
1083 m_pForm->m_pFormNotify->AfterSelectionChange(this); 1083 m_pForm->m_pFormNotify->AfterSelectionChange(this);
1084 } 1084 }
1085 if (GetType() == ComboBox) { 1085 if (GetType() == ComboBox) {
1086 m_pForm->m_pFormNotify->AfterValueChange(this); 1086 m_pForm->m_pFormNotify->AfterValueChange(this);
1087 } 1087 }
1088 } 1088 }
1089 m_pForm->m_bUpdated = TRUE; 1089 m_pForm->m_bUpdated = TRUE;
1090 return TRUE; 1090 return TRUE;
1091 } 1091 }
(...skipping 16 matching lines...) Expand all
1108 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")) 1108 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font"))
1109 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict( 1109 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(
1110 font_name); 1110 font_name);
1111 1111
1112 if (pFontDict == NULL) { 1112 if (pFontDict == NULL) {
1113 return; 1113 return;
1114 } 1114 }
1115 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); 1115 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict);
1116 m_FontSize = FX_atof(syntax.GetWord()); 1116 m_FontSize = FX_atof(syntax.GetWord());
1117 } 1117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698