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

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

Issue 1258093002: FX Bool considered harmful, part 3 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdfdoc/doc_formcontrol.cpp ('k') | core/src/fpdfdoc/doc_metadata.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/fpdfdoc/fpdf_doc.h" 7 #include "../../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 bool PDF_FormField_IsUnison(CPDF_FormField *pField)
11 { 11 {
12 FX_BOOL bUnison = FALSE; 12 bool bUnison = false;
13 if (pField->GetType() == CPDF_FormField::CheckBox) { 13 if (pField->GetType() == CPDF_FormField::CheckBox) {
14 bUnison = TRUE; 14 bUnison = true;
15 } else { 15 } else {
16 FX_DWORD dwFlags = pField->GetFieldFlags(); 16 FX_DWORD dwFlags = pField->GetFieldFlags();
17 bUnison = ((dwFlags & 0x2000000) != 0); 17 bUnison = ((dwFlags & 0x2000000) != 0);
18 } 18 }
19 return bUnison; 19 return bUnison;
20 } 20 }
21 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) 21 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict)
22 { 22 {
23 m_pDict = pDict; 23 m_pDict = pDict;
24 m_Type = Unknown; 24 m_Type = Unknown;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 93 }
94 LoadDA(); 94 LoadDA();
95 } else if (type_name == "Sig") { 95 } else if (type_name == "Sig") {
96 m_Type = Sign; 96 m_Type = Sign;
97 } 97 }
98 } 98 }
99 CFX_WideString CPDF_FormField::GetFullName() 99 CFX_WideString CPDF_FormField::GetFullName()
100 { 100 {
101 return ::GetFullName(m_pDict); 101 return ::GetFullName(m_pDict);
102 } 102 }
103 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) 103 bool CPDF_FormField::ResetField(bool bNotify)
104 { 104 {
105 switch (m_Type) { 105 switch (m_Type) {
106 case CPDF_FormField::CheckBox: 106 case CPDF_FormField::CheckBox:
107 case CPDF_FormField::RadioButton: { 107 case CPDF_FormField::RadioButton: {
108 CFX_ByteArray statusArray; 108 CFX_ByteArray statusArray;
109 if (bNotify && m_pForm->m_pFormNotify != NULL) { 109 if (bNotify && m_pForm->m_pFormNotify != NULL) {
110 SaveCheckedFieldStatus(this, statusArray); 110 SaveCheckedFieldStatus(this, statusArray);
111 } 111 }
112 int iCount = CountControls(); 112 int iCount = CountControls();
113 if (iCount) { 113 if (iCount) {
114 if (PDF_FormField_IsUnison(this)) { 114 if (PDF_FormField_IsUnison(this)) {
115 for(int i = 0; i < iCount; i++) { 115 for(int i = 0; i < iCount; i++) {
116 CheckControl(i, GetControl(i)->IsDefaultChecked(), F ALSE); 116 CheckControl(i, GetControl(i)->IsDefaultChecked(), f alse);
117 } 117 }
118 } else { 118 } else {
119 for (int i = 0; i < iCount; i ++) { 119 for (int i = 0; i < iCount; i ++) {
120 CPDF_FormControl* pControl = GetControl(i); 120 CPDF_FormControl* pControl = GetControl(i);
121 FX_BOOL bChecked = pControl->IsDefaultChecked(); 121 bool bChecked = pControl->IsDefaultChecked();
122 CheckControl(i, bChecked, FALSE); 122 CheckControl(i, bChecked, false);
123 } 123 }
124 } 124 }
125 } 125 }
126 if (bNotify && m_pForm->m_pFormNotify != NULL) { 126 if (bNotify && m_pForm->m_pFormNotify != NULL) {
127 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statu sArray); 127 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statu sArray);
128 } 128 }
129 } 129 }
130 break; 130 break;
131 case CPDF_FormField::ComboBox: { 131 case CPDF_FormField::ComboBox: {
132 CFX_WideString csValue; 132 CFX_WideString csValue;
133 ClearSelection(); 133 ClearSelection();
134 int iIndex = GetDefaultSelectedItem(); 134 int iIndex = GetDefaultSelectedItem();
135 if (iIndex >= 0) { 135 if (iIndex >= 0) {
136 csValue = GetOptionLabel(iIndex); 136 csValue = GetOptionLabel(iIndex);
137 } 137 }
138 if (bNotify && m_pForm->m_pFormNotify != NULL) { 138 if (bNotify && m_pForm->m_pFormNotify != NULL) {
139 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, c sValue); 139 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, c sValue);
140 if (iRet < 0) { 140 if (iRet < 0) {
141 return FALSE; 141 return false;
142 } 142 }
143 } 143 }
144 SetItemSelection(iIndex, TRUE); 144 SetItemSelection(iIndex, true);
145 if (bNotify && m_pForm->m_pFormNotify != NULL) { 145 if (bNotify && m_pForm->m_pFormNotify != NULL) {
146 m_pForm->m_pFormNotify->AfterValueChange(this); 146 m_pForm->m_pFormNotify->AfterValueChange(this);
147 } 147 }
148 } 148 }
149 break; 149 break;
150 case CPDF_FormField::ListBox: { 150 case CPDF_FormField::ListBox: {
151 CFX_WideString csValue; 151 CFX_WideString csValue;
152 ClearSelection(); 152 ClearSelection();
153 int iIndex = GetDefaultSelectedItem(); 153 int iIndex = GetDefaultSelectedItem();
154 if (iIndex >= 0) { 154 if (iIndex >= 0) {
155 csValue = GetOptionLabel(iIndex); 155 csValue = GetOptionLabel(iIndex);
156 } 156 }
157 if (bNotify && m_pForm->m_pFormNotify != NULL) { 157 if (bNotify && m_pForm->m_pFormNotify != NULL) {
158 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(thi s, csValue); 158 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(thi s, csValue);
159 if (iRet < 0) { 159 if (iRet < 0) {
160 return FALSE; 160 return false;
161 } 161 }
162 } 162 }
163 SetItemSelection(iIndex, TRUE); 163 SetItemSelection(iIndex, true);
164 if (bNotify && m_pForm->m_pFormNotify != NULL) { 164 if (bNotify && m_pForm->m_pFormNotify != NULL) {
165 m_pForm->m_pFormNotify->AfterSelectionChange(this); 165 m_pForm->m_pFormNotify->AfterSelectionChange(this);
166 } 166 }
167 } 167 }
168 break; 168 break;
169 case CPDF_FormField::Text: 169 case CPDF_FormField::Text:
170 case CPDF_FormField::RichText: 170 case CPDF_FormField::RichText:
171 case CPDF_FormField::File: 171 case CPDF_FormField::File:
172 default: { 172 default: {
173 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); 173 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV");
174 CFX_WideString csDValue; 174 CFX_WideString csDValue;
175 if (pDV != NULL) { 175 if (pDV != NULL) {
176 csDValue = pDV->GetUnicodeText(); 176 csDValue = pDV->GetUnicodeText();
177 } 177 }
178 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); 178 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
179 CFX_WideString csValue; 179 CFX_WideString csValue;
180 if (pV != NULL) { 180 if (pV != NULL) {
181 csValue = pV->GetUnicodeText(); 181 csValue = pV->GetUnicodeText();
182 } 182 }
183 CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV"); 183 CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV");
184 if (!pRV && (csDValue == csValue)) { 184 if (!pRV && (csDValue == csValue)) {
185 return FALSE; 185 return false;
186 } 186 }
187 if (bNotify && m_pForm->m_pFormNotify != NULL) { 187 if (bNotify && m_pForm->m_pFormNotify != NULL) {
188 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, c sDValue); 188 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, c sDValue);
189 if (iRet < 0) { 189 if (iRet < 0) {
190 return FALSE; 190 return false;
191 } 191 }
192 } 192 }
193 if (pDV == NULL) { 193 if (pDV == NULL) {
194 m_pDict->RemoveAt("V"); 194 m_pDict->RemoveAt("V");
195 m_pDict->RemoveAt("RV"); 195 m_pDict->RemoveAt("RV");
196 } else { 196 } else {
197 CPDF_Object* pClone = pDV->Clone(); 197 CPDF_Object* pClone = pDV->Clone();
198 if (pClone == NULL) { 198 if (pClone == NULL) {
199 return FALSE; 199 return false;
200 } 200 }
201 m_pDict->SetAt("V", pClone); 201 m_pDict->SetAt("V", pClone);
202 if(pRV) { 202 if(pRV) {
203 CPDF_Object* pCloneR = pDV->Clone(); 203 CPDF_Object* pCloneR = pDV->Clone();
204 m_pDict->SetAt("RV", pCloneR); 204 m_pDict->SetAt("RV", pCloneR);
205 } 205 }
206 } 206 }
207 if (bNotify && m_pForm->m_pFormNotify != NULL) { 207 if (bNotify && m_pForm->m_pFormNotify != NULL) {
208 m_pForm->m_pFormNotify->AfterValueChange(this); 208 m_pForm->m_pFormNotify->AfterValueChange(this);
209 } 209 }
210 m_pForm->m_bUpdated = TRUE; 210 m_pForm->m_bUpdated = true;
211 } 211 }
212 break; 212 break;
213 } 213 }
214 return TRUE; 214 return true;
215 } 215 }
216 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) 216 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl)
217 { 217 {
218 if (pControl == NULL) { 218 if (pControl == NULL) {
219 return -1; 219 return -1;
220 } 220 }
221 int iCount = m_ControlList.GetSize(); 221 int iCount = m_ControlList.GetSize();
222 for (int i = 0; i < iCount; i ++) { 222 for (int i = 0; i < iCount; i ++) {
223 CPDF_FormControl* pFind = (CPDF_FormControl*)m_ControlList.GetAt(i); 223 CPDF_FormControl* pFind = (CPDF_FormControl*)m_ControlList.GetAt(i);
224 if (pFind == pControl) { 224 if (pFind == pControl) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return pObj->GetString(); 292 return pObj->GetString();
293 } 293 }
294 CFX_WideString CPDF_FormField::GetRichTextString() 294 CFX_WideString CPDF_FormField::GetRichTextString()
295 { 295 {
296 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV"); 296 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV");
297 if (pObj == NULL) { 297 if (pObj == NULL) {
298 return L""; 298 return L"";
299 } 299 }
300 return pObj->GetUnicodeText(); 300 return pObj->GetUnicodeText();
301 } 301 }
302 CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) 302 CFX_WideString CPDF_FormField::GetValue(bool bDefault)
303 { 303 {
304 if (GetType() == CheckBox || GetType() == RadioButton) { 304 if (GetType() == CheckBox || GetType() == RadioButton) {
305 return GetCheckValue(bDefault); 305 return GetCheckValue(bDefault);
306 } 306 }
307 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V"); 307 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V");
308 if (pValue == NULL) { 308 if (pValue == NULL) {
309 if (!bDefault) { 309 if (!bDefault) {
310 if (m_Type == RichText) { 310 if (m_Type == RichText) {
311 pValue = FPDF_GetFieldAttr(m_pDict, "V"); 311 pValue = FPDF_GetFieldAttr(m_pDict, "V");
312 } 312 }
(...skipping 13 matching lines...) Expand all
326 pValue = ((CPDF_Array*)pValue)->GetElementValue(0); 326 pValue = ((CPDF_Array*)pValue)->GetElementValue(0);
327 if (pValue) { 327 if (pValue) {
328 return pValue->GetUnicodeText(); 328 return pValue->GetUnicodeText();
329 } 329 }
330 break; 330 break;
331 } 331 }
332 return CFX_WideString(); 332 return CFX_WideString();
333 } 333 }
334 CFX_WideString CPDF_FormField::GetValue() 334 CFX_WideString CPDF_FormField::GetValue()
335 { 335 {
336 return GetValue(FALSE); 336 return GetValue(false);
337 } 337 }
338 CFX_WideString CPDF_FormField::GetDefaultValue() 338 CFX_WideString CPDF_FormField::GetDefaultValue()
339 { 339 {
340 return GetValue(TRUE); 340 return GetValue(true);
341 } 341 }
342 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bDefault, FX_BOOL bNotify) 342 bool CPDF_FormField::SetValue(const CFX_WideString& value, bool bDefault, bool b Notify)
343 { 343 {
344 switch (m_Type) { 344 switch (m_Type) {
345 case CheckBox: 345 case CheckBox:
346 case RadioButton: { 346 case RadioButton: {
347 SetCheckValue(value, bDefault, bNotify); 347 SetCheckValue(value, bDefault, bNotify);
348 return TRUE; 348 return true;
349 } 349 }
350 case File: 350 case File:
351 case RichText: 351 case RichText:
352 case Text: 352 case Text:
353 case ComboBox: { 353 case ComboBox: {
354 CFX_WideString csValue = value; 354 CFX_WideString csValue = value;
355 if (bNotify && m_pForm->m_pFormNotify != NULL) { 355 if (bNotify && m_pForm->m_pFormNotify != NULL) {
356 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, c sValue); 356 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, c sValue);
357 if (iRet < 0) { 357 if (iRet < 0) {
358 return FALSE; 358 return false;
359 } 359 }
360 } 360 }
361 int iIndex = FindOptionValue(csValue); 361 int iIndex = FindOptionValue(csValue);
362 if (iIndex < 0) { 362 if (iIndex < 0) {
363 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue); 363 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue);
364 m_pDict->SetAtString(bDefault ? "DV" : "V", bsEncodeText); 364 m_pDict->SetAtString(bDefault ? "DV" : "V", bsEncodeText);
365 if (m_Type == RichText && !bDefault) { 365 if (m_Type == RichText && !bDefault) {
366 m_pDict->SetAtString("RV", bsEncodeText); 366 m_pDict->SetAtString("RV", bsEncodeText);
367 } 367 }
368 m_pDict->RemoveAt("I"); 368 m_pDict->RemoveAt("I");
369 } else { 369 } else {
370 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(c sValue)); 370 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(c sValue));
371 if (bDefault) { 371 if (bDefault) {
372 } else { 372 } else {
373 ClearSelection(); 373 ClearSelection();
374 SetItemSelection(iIndex, TRUE); 374 SetItemSelection(iIndex, true);
375 } 375 }
376 } 376 }
377 if (bNotify && m_pForm->m_pFormNotify != NULL) { 377 if (bNotify && m_pForm->m_pFormNotify != NULL) {
378 m_pForm->m_pFormNotify->AfterValueChange(this); 378 m_pForm->m_pFormNotify->AfterValueChange(this);
379 } 379 }
380 m_pForm->m_bUpdated = TRUE; 380 m_pForm->m_bUpdated = true;
381 } 381 }
382 break; 382 break;
383 case ListBox: { 383 case ListBox: {
384 int iIndex = FindOptionValue(value); 384 int iIndex = FindOptionValue(value);
385 if (iIndex < 0) { 385 if (iIndex < 0) {
386 return FALSE; 386 return false;
387 } 387 }
388 if (bDefault && iIndex == GetDefaultSelectedItem()) { 388 if (bDefault && iIndex == GetDefaultSelectedItem()) {
389 return FALSE; 389 return false;
390 } 390 }
391 if (bNotify && m_pForm->m_pFormNotify != NULL) { 391 if (bNotify && m_pForm->m_pFormNotify != NULL) {
392 CFX_WideString csValue = value; 392 CFX_WideString csValue = value;
393 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(thi s, csValue); 393 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(thi s, csValue);
394 if (iRet < 0) { 394 if (iRet < 0) {
395 return FALSE; 395 return false;
396 } 396 }
397 } 397 }
398 if (bDefault) { 398 if (bDefault) {
399 } else { 399 } else {
400 ClearSelection(); 400 ClearSelection();
401 SetItemSelection(iIndex, TRUE); 401 SetItemSelection(iIndex, true);
402 } 402 }
403 if (bNotify && m_pForm->m_pFormNotify != NULL) { 403 if (bNotify && m_pForm->m_pFormNotify != NULL) {
404 m_pForm->m_pFormNotify->AfterSelectionChange(this); 404 m_pForm->m_pFormNotify->AfterSelectionChange(this);
405 } 405 }
406 m_pForm->m_bUpdated = TRUE; 406 m_pForm->m_bUpdated = true;
407 break; 407 break;
408 } 408 }
409 default: 409 default:
410 break; 410 break;
411 } 411 }
412 if (CPDF_InterForm::m_bUpdateAP) { 412 if (CPDF_InterForm::m_bUpdateAP) {
413 UpdateAP(NULL); 413 UpdateAP(NULL);
414 } 414 }
415 return TRUE; 415 return true;
416 } 416 }
417 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bNotify) 417 bool CPDF_FormField::SetValue(const CFX_WideString& value, bool bNotify)
418 { 418 {
419 return SetValue(value, FALSE, bNotify); 419 return SetValue(value, false, bNotify);
420 } 420 }
421 int CPDF_FormField::GetMaxLen() 421 int CPDF_FormField::GetMaxLen()
422 { 422 {
423 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen"); 423 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen");
424 if (pObj == NULL) { 424 if (pObj == NULL) {
425 int iCount = m_ControlList.GetSize(); 425 int iCount = m_ControlList.GetSize();
426 for (int i = 0; i < iCount; i ++) { 426 for (int i = 0; i < iCount; i ++) {
427 CPDF_FormControl* pControl = (CPDF_FormControl*)m_ControlList.GetAt( i); 427 CPDF_FormControl* pControl = (CPDF_FormControl*)m_ControlList.GetAt( i);
428 if (pControl == NULL) { 428 if (pControl == NULL) {
429 continue; 429 continue;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 499 }
500 } 500 }
501 int nOpts = CountOptions(); 501 int nOpts = CountOptions();
502 for (int i = 0; i < nOpts; i ++) { 502 for (int i = 0; i < nOpts; i ++) {
503 if (sel_value == GetOptionValue(i)) { 503 if (sel_value == GetOptionValue(i)) {
504 return i; 504 return i;
505 } 505 }
506 } 506 }
507 return -1; 507 return -1;
508 } 508 }
509 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) 509 bool CPDF_FormField::ClearSelection(bool bNotify)
510 { 510 {
511 if (bNotify && m_pForm->m_pFormNotify != NULL) { 511 if (bNotify && m_pForm->m_pFormNotify != NULL) {
512 int iRet = 0; 512 int iRet = 0;
513 CFX_WideString csValue; 513 CFX_WideString csValue;
514 int iIndex = GetSelectedIndex(0); 514 int iIndex = GetSelectedIndex(0);
515 if (iIndex >= 0) { 515 if (iIndex >= 0) {
516 csValue = GetOptionLabel(iIndex); 516 csValue = GetOptionLabel(iIndex);
517 } 517 }
518 if (GetType() == ListBox) { 518 if (GetType() == ListBox) {
519 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); 519 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
520 } 520 }
521 if (GetType() == ComboBox) { 521 if (GetType() == ComboBox) {
522 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); 522 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
523 } 523 }
524 if (iRet < 0) { 524 if (iRet < 0) {
525 return FALSE; 525 return false;
526 } 526 }
527 } 527 }
528 m_pDict->RemoveAt("V"); 528 m_pDict->RemoveAt("V");
529 m_pDict->RemoveAt("I"); 529 m_pDict->RemoveAt("I");
530 if (bNotify && m_pForm->m_pFormNotify != NULL) { 530 if (bNotify && m_pForm->m_pFormNotify != NULL) {
531 if (GetType() == ListBox) { 531 if (GetType() == ListBox) {
532 m_pForm->m_pFormNotify->AfterSelectionChange(this); 532 m_pForm->m_pFormNotify->AfterSelectionChange(this);
533 } 533 }
534 if (GetType() == ComboBox) { 534 if (GetType() == ComboBox) {
535 m_pForm->m_pFormNotify->AfterValueChange(this); 535 m_pForm->m_pFormNotify->AfterValueChange(this);
536 } 536 }
537 } 537 }
538 if (CPDF_InterForm::m_bUpdateAP) { 538 if (CPDF_InterForm::m_bUpdateAP) {
539 UpdateAP(NULL); 539 UpdateAP(NULL);
540 } 540 }
541 m_pForm->m_bUpdated = TRUE; 541 m_pForm->m_bUpdated = true;
542 return TRUE; 542 return true;
543 } 543 }
544 FX_BOOL CPDF_FormField::IsItemSelected(int index) 544 bool CPDF_FormField::IsItemSelected(int index)
545 { 545 {
546 ASSERT(GetType() == ComboBox || GetType() == ListBox); 546 ASSERT(GetType() == ComboBox || GetType() == ListBox);
547 if (index < 0 || index >= CountOptions()) { 547 if (index < 0 || index >= CountOptions()) {
548 return FALSE; 548 return false;
549 } 549 }
550 if (IsOptionSelected(index)) { 550 if (IsOptionSelected(index)) {
551 return TRUE; 551 return true;
552 } 552 }
553 CFX_WideString opt_value = GetOptionValue(index); 553 CFX_WideString opt_value = GetOptionValue(index);
554 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 554 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
555 if (pValue == NULL) { 555 if (pValue == NULL) {
556 pValue = FPDF_GetFieldAttr(m_pDict, "I"); 556 pValue = FPDF_GetFieldAttr(m_pDict, "I");
557 if (pValue == NULL) { 557 if (pValue == NULL) {
558 return FALSE; 558 return false;
559 } 559 }
560 } 560 }
561 if (pValue->GetType() == PDFOBJ_STRING) { 561 if (pValue->GetType() == PDFOBJ_STRING) {
562 if (pValue->GetUnicodeText() == opt_value) { 562 if (pValue->GetUnicodeText() == opt_value) {
563 return TRUE; 563 return true;
564 } 564 }
565 return FALSE; 565 return false;
566 } 566 }
567 if (pValue->GetType() == PDFOBJ_NUMBER) { 567 if (pValue->GetType() == PDFOBJ_NUMBER) {
568 if (pValue->GetString().IsEmpty()) { 568 if (pValue->GetString().IsEmpty()) {
569 return FALSE; 569 return false;
570 } 570 }
571 if (pValue->GetInteger() == index) { 571 if (pValue->GetInteger() == index) {
572 return TRUE; 572 return true;
573 } 573 }
574 return FALSE; 574 return false;
575 } 575 }
576 if (pValue->GetType() != PDFOBJ_ARRAY) { 576 if (pValue->GetType() != PDFOBJ_ARRAY) {
577 return FALSE; 577 return false;
578 } 578 }
579 CPDF_Array* pArray = (CPDF_Array*)pValue; 579 CPDF_Array* pArray = (CPDF_Array*)pValue;
580 int iPos = -1; 580 int iPos = -1;
581 for (int j = 0; j < CountSelectedOptions(); j ++) { 581 for (int j = 0; j < CountSelectedOptions(); j ++) {
582 if (GetSelectedOptionIndex(j) == index) { 582 if (GetSelectedOptionIndex(j) == index) {
583 iPos = j; 583 iPos = j;
584 break; 584 break;
585 } 585 }
586 } 586 }
587 for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) 587 for (FX_DWORD i = 0; i < pArray->GetCount(); i ++)
588 if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value && (int)i == iPos) { 588 if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value && (int)i == iPos) {
589 return TRUE; 589 return true;
590 } 590 }
591 return FALSE; 591 return false;
592 } 592 }
593 FX_BOOL CPDF_FormField::SetItemSelection(int index, FX_BOOL bSelected, FX_BOOL b Notify) 593 bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify)
594 { 594 {
595 ASSERT(GetType() == ComboBox || GetType() == ListBox); 595 ASSERT(GetType() == ComboBox || GetType() == ListBox);
596 if (index < 0 || index >= CountOptions()) { 596 if (index < 0 || index >= CountOptions()) {
597 return FALSE; 597 return false;
598 } 598 }
599 CFX_WideString opt_value = GetOptionValue(index); 599 CFX_WideString opt_value = GetOptionValue(index);
600 if (bNotify && m_pForm->m_pFormNotify != NULL) { 600 if (bNotify && m_pForm->m_pFormNotify != NULL) {
601 int iRet = 0; 601 int iRet = 0;
602 if (GetType() == ListBox) { 602 if (GetType() == ListBox) {
603 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, opt_value ); 603 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, opt_value );
604 } 604 }
605 if (GetType() == ComboBox) { 605 if (GetType() == ComboBox) {
606 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, opt_value); 606 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, opt_value);
607 } 607 }
608 if (iRet < 0) { 608 if (iRet < 0) {
609 return FALSE; 609 return false;
610 } 610 }
611 } 611 }
612 if (!bSelected) { 612 if (!bSelected) {
613 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 613 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
614 if (pValue != NULL) { 614 if (pValue != NULL) {
615 if (m_Type == ListBox) { 615 if (m_Type == ListBox) {
616 SelectOption(index, FALSE); 616 SelectOption(index, false);
617 if (pValue->GetType() == PDFOBJ_STRING) { 617 if (pValue->GetType() == PDFOBJ_STRING) {
618 if (pValue->GetUnicodeText() == opt_value) { 618 if (pValue->GetUnicodeText() == opt_value) {
619 m_pDict->RemoveAt("V"); 619 m_pDict->RemoveAt("V");
620 } 620 }
621 } else if (pValue->GetType() == PDFOBJ_ARRAY) { 621 } else if (pValue->GetType() == PDFOBJ_ARRAY) {
622 CPDF_Array* pArray = CPDF_Array::Create(); 622 CPDF_Array* pArray = CPDF_Array::Create();
623 if (pArray == NULL) { 623 if (pArray == NULL) {
624 return FALSE; 624 return false;
625 } 625 }
626 int iCount = CountOptions(); 626 int iCount = CountOptions();
627 for (int i = 0; i < iCount; i ++) { 627 for (int i = 0; i < iCount; i ++) {
628 if (i != index) { 628 if (i != index) {
629 if (IsItemSelected(i)) { 629 if (IsItemSelected(i)) {
630 opt_value = GetOptionValue(i); 630 opt_value = GetOptionValue(i);
631 pArray->AddString(PDF_EncodeText(opt_value)); 631 pArray->AddString(PDF_EncodeText(opt_value));
632 } 632 }
633 } 633 }
634 } 634 }
635 if (pArray->GetCount() < 1) { 635 if (pArray->GetCount() < 1) {
636 pArray->Release(); 636 pArray->Release();
637 } else { 637 } else {
638 m_pDict->SetAt("V", pArray); 638 m_pDict->SetAt("V", pArray);
639 } 639 }
640 } 640 }
641 } else if (m_Type == ComboBox) { 641 } else if (m_Type == ComboBox) {
642 m_pDict->RemoveAt("V"); 642 m_pDict->RemoveAt("V");
643 m_pDict->RemoveAt("I"); 643 m_pDict->RemoveAt("I");
644 } 644 }
645 } 645 }
646 } else { 646 } else {
647 if (m_Type == ListBox) { 647 if (m_Type == ListBox) {
648 SelectOption(index, TRUE); 648 SelectOption(index, true);
649 if (!(m_Flags & FORMLIST_MULTISELECT)) { 649 if (!(m_Flags & FORMLIST_MULTISELECT)) {
650 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); 650 m_pDict->SetAtString("V", PDF_EncodeText(opt_value));
651 } else { 651 } else {
652 CPDF_Array* pArray = CPDF_Array::Create(); 652 CPDF_Array* pArray = CPDF_Array::Create();
653 if (pArray == NULL) { 653 if (pArray == NULL) {
654 return FALSE; 654 return false;
655 } 655 }
656 FX_BOOL bSelected; 656 bool bSelected;
657 int iCount = CountOptions(); 657 int iCount = CountOptions();
658 for (int i = 0; i < iCount; i ++) { 658 for (int i = 0; i < iCount; i ++) {
659 if (i != index) { 659 if (i != index) {
660 bSelected = IsItemSelected(i); 660 bSelected = IsItemSelected(i);
661 } else { 661 } else {
662 bSelected = TRUE; 662 bSelected = true;
663 } 663 }
664 if (bSelected) { 664 if (bSelected) {
665 opt_value = GetOptionValue(i); 665 opt_value = GetOptionValue(i);
666 pArray->AddString(PDF_EncodeText(opt_value)); 666 pArray->AddString(PDF_EncodeText(opt_value));
667 } 667 }
668 } 668 }
669 m_pDict->SetAt("V", pArray); 669 m_pDict->SetAt("V", pArray);
670 } 670 }
671 } else if (m_Type == ComboBox) { 671 } else if (m_Type == ComboBox) {
672 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); 672 m_pDict->SetAtString("V", PDF_EncodeText(opt_value));
673 CPDF_Array* pI = CPDF_Array::Create(); 673 CPDF_Array* pI = CPDF_Array::Create();
674 if (pI == NULL) { 674 if (pI == NULL) {
675 return FALSE; 675 return false;
676 } 676 }
677 pI->AddInteger(index); 677 pI->AddInteger(index);
678 m_pDict->SetAt("I", pI); 678 m_pDict->SetAt("I", pI);
679 } 679 }
680 } 680 }
681 if (bNotify && m_pForm->m_pFormNotify != NULL) { 681 if (bNotify && m_pForm->m_pFormNotify != NULL) {
682 if (GetType() == ListBox) { 682 if (GetType() == ListBox) {
683 m_pForm->m_pFormNotify->AfterSelectionChange(this); 683 m_pForm->m_pFormNotify->AfterSelectionChange(this);
684 } 684 }
685 if (GetType() == ComboBox) { 685 if (GetType() == ComboBox) {
686 m_pForm->m_pFormNotify->AfterValueChange(this); 686 m_pForm->m_pFormNotify->AfterValueChange(this);
687 } 687 }
688 } 688 }
689 if (CPDF_InterForm::m_bUpdateAP) { 689 if (CPDF_InterForm::m_bUpdateAP) {
690 UpdateAP(NULL); 690 UpdateAP(NULL);
691 } 691 }
692 m_pForm->m_bUpdated = TRUE; 692 m_pForm->m_bUpdated = true;
693 return TRUE; 693 return true;
694 } 694 }
695 FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) 695 bool CPDF_FormField::IsItemDefaultSelected(int index)
696 { 696 {
697 ASSERT(GetType() == ComboBox || GetType() == ListBox); 697 ASSERT(GetType() == ComboBox || GetType() == ListBox);
698 if (index < 0 || index >= CountOptions()) { 698 if (index < 0 || index >= CountOptions()) {
699 return FALSE; 699 return false;
700 } 700 }
701 int iDVIndex = GetDefaultSelectedItem(); 701 int iDVIndex = GetDefaultSelectedItem();
702 if (iDVIndex < 0) { 702 if (iDVIndex < 0) {
703 return FALSE; 703 return false;
704 } 704 }
705 return (iDVIndex == index); 705 return (iDVIndex == index);
706 } 706 }
707 int CPDF_FormField::GetDefaultSelectedItem() 707 int CPDF_FormField::GetDefaultSelectedItem()
708 { 708 {
709 ASSERT(GetType() == ComboBox || GetType() == ListBox); 709 ASSERT(GetType() == ComboBox || GetType() == ListBox);
710 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV"); 710 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV");
711 if (pValue == NULL) { 711 if (pValue == NULL) {
712 return -1; 712 return -1;
713 } 713 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 } 791 }
792 int iCount = CountOptions(); 792 int iCount = CountOptions();
793 for (; iStartIndex < iCount; iStartIndex ++) { 793 for (; iStartIndex < iCount; iStartIndex ++) {
794 CFX_WideString csValue = GetOptionValue(iStartIndex); 794 CFX_WideString csValue = GetOptionValue(iStartIndex);
795 if (csValue == csOptValue) { 795 if (csValue == csOptValue) {
796 return iStartIndex; 796 return iStartIndex;
797 } 797 }
798 } 798 }
799 return -1; 799 return -1;
800 } 800 }
801 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, FX_BOOL bChecked, FX_BOO L bNotify) 801 bool CPDF_FormField::CheckControl(int iControlIndex, bool bChecked, bool bNotify )
802 { 802 {
803 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 803 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
804 CPDF_FormControl* pControl = GetControl(iControlIndex); 804 CPDF_FormControl* pControl = GetControl(iControlIndex);
805 if (pControl == NULL) { 805 if (pControl == NULL) {
806 return FALSE; 806 return false;
807 } 807 }
808 if (!bChecked && pControl->IsChecked() == bChecked) { 808 if (!bChecked && pControl->IsChecked() == bChecked) {
809 return FALSE; 809 return false;
810 } 810 }
811 CFX_ByteArray statusArray; 811 CFX_ByteArray statusArray;
812 if (bNotify && m_pForm->m_pFormNotify != NULL) { 812 if (bNotify && m_pForm->m_pFormNotify != NULL) {
813 SaveCheckedFieldStatus(this, statusArray); 813 SaveCheckedFieldStatus(this, statusArray);
814 } 814 }
815 CFX_WideString csWExport = pControl->GetExportValue(); 815 CFX_WideString csWExport = pControl->GetExportValue();
816 CFX_ByteString csBExport = PDF_EncodeText(csWExport); 816 CFX_ByteString csBExport = PDF_EncodeText(csWExport);
817 int iCount = CountControls(); 817 int iCount = CountControls();
818 FX_BOOL bUnison = PDF_FormField_IsUnison(this); 818 bool bUnison = PDF_FormField_IsUnison(this);
819 for (int i = 0; i < iCount; i ++) { 819 for (int i = 0; i < iCount; i ++) {
820 CPDF_FormControl* pCtrl = GetControl(i); 820 CPDF_FormControl* pCtrl = GetControl(i);
821 if (bUnison) { 821 if (bUnison) {
822 CFX_WideString csEValue = pCtrl->GetExportValue(); 822 CFX_WideString csEValue = pCtrl->GetExportValue();
823 if (csEValue == csWExport) { 823 if (csEValue == csWExport) {
824 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) { 824 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) {
825 pCtrl->CheckControl(bChecked); 825 pCtrl->CheckControl(bChecked);
826 } else if (bChecked) { 826 } else if (bChecked) {
827 pCtrl->CheckControl(FALSE); 827 pCtrl->CheckControl(false);
828 } 828 }
829 } else if (bChecked) { 829 } else if (bChecked) {
830 pCtrl->CheckControl(FALSE); 830 pCtrl->CheckControl(false);
831 } 831 }
832 } else { 832 } else {
833 if (i == iControlIndex) { 833 if (i == iControlIndex) {
834 pCtrl->CheckControl(bChecked); 834 pCtrl->CheckControl(bChecked);
835 } else if (bChecked) { 835 } else if (bChecked) {
836 pCtrl->CheckControl(FALSE); 836 pCtrl->CheckControl(false);
837 } 837 }
838 } 838 }
839 } 839 }
840 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); 840 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt");
841 if (pOpt == NULL || pOpt->GetType() != PDFOBJ_ARRAY) { 841 if (pOpt == NULL || pOpt->GetType() != PDFOBJ_ARRAY) {
842 if (bChecked) { 842 if (bChecked) {
843 m_pDict->SetAtName("V", csBExport); 843 m_pDict->SetAtName("V", csBExport);
844 } else { 844 } else {
845 CFX_ByteString csV; 845 CFX_ByteString csV;
846 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); 846 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
847 if (pV != NULL) { 847 if (pV != NULL) {
848 csV = pV->GetString(); 848 csV = pV->GetString();
849 } 849 }
850 if (csV == csBExport) { 850 if (csV == csBExport) {
851 m_pDict->SetAtName("V", "Off"); 851 m_pDict->SetAtName("V", "Off");
852 } 852 }
853 } 853 }
854 } else if (bChecked) { 854 } else if (bChecked) {
855 CFX_ByteString csIndex; 855 CFX_ByteString csIndex;
856 csIndex.Format("%d", iControlIndex); 856 csIndex.Format("%d", iControlIndex);
857 m_pDict->SetAtName("V", csIndex); 857 m_pDict->SetAtName("V", csIndex);
858 } 858 }
859 if (bNotify && m_pForm->m_pFormNotify != NULL) { 859 if (bNotify && m_pForm->m_pFormNotify != NULL) {
860 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); 860 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray);
861 } 861 }
862 m_pForm->m_bUpdated = TRUE; 862 m_pForm->m_bUpdated = true;
863 return TRUE; 863 return true;
864 } 864 }
865 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) 865 CFX_WideString CPDF_FormField::GetCheckValue(bool bDefault)
866 { 866 {
867 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 867 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
868 CFX_WideString csExport = L"Off"; 868 CFX_WideString csExport = L"Off";
869 FX_BOOL bChecked; 869 bool bChecked;
870 int iCount = CountControls(); 870 int iCount = CountControls();
871 for (int i = 0; i < iCount; i ++) { 871 for (int i = 0; i < iCount; i ++) {
872 CPDF_FormControl* pControl = GetControl(i); 872 CPDF_FormControl* pControl = GetControl(i);
873 if (bDefault) { 873 if (bDefault) {
874 bChecked = pControl->IsDefaultChecked(); 874 bChecked = pControl->IsDefaultChecked();
875 } else { 875 } else {
876 bChecked = pControl->IsChecked(); 876 bChecked = pControl->IsChecked();
877 } 877 }
878 if (bChecked) { 878 if (bChecked) {
879 csExport = pControl->GetExportValue(); 879 csExport = pControl->GetExportValue();
880 break; 880 break;
881 } 881 }
882 } 882 }
883 return csExport; 883 return csExport;
884 } 884 }
885 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, FX_BOOL bDefa ult, FX_BOOL bNotify) 885 bool CPDF_FormField::SetCheckValue(const CFX_WideString& value, bool bDefault, b ool bNotify)
886 { 886 {
887 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 887 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
888 CFX_ByteArray statusArray; 888 CFX_ByteArray statusArray;
889 if (bNotify && m_pForm->m_pFormNotify != NULL) { 889 if (bNotify && m_pForm->m_pFormNotify != NULL) {
890 SaveCheckedFieldStatus(this, statusArray); 890 SaveCheckedFieldStatus(this, statusArray);
891 } 891 }
892 int iCount = CountControls(); 892 int iCount = CountControls();
893 for (int i = 0; i < iCount; i ++) { 893 for (int i = 0; i < iCount; i ++) {
894 CPDF_FormControl* pControl = GetControl(i); 894 CPDF_FormControl* pControl = GetControl(i);
895 CFX_WideString csExport = pControl->GetExportValue(); 895 CFX_WideString csExport = pControl->GetExportValue();
896 if (csExport == value) { 896 if (csExport == value) {
897 if (bDefault) { 897 if (bDefault) {
898 } else { 898 } else {
899 CheckControl(GetControlIndex(pControl), TRUE); 899 CheckControl(GetControlIndex(pControl), true);
900 } 900 }
901 break; 901 break;
902 } else { 902 } else {
903 if (bDefault) { 903 if (bDefault) {
904 } else { 904 } else {
905 CheckControl(GetControlIndex(pControl), FALSE); 905 CheckControl(GetControlIndex(pControl), false);
906 } 906 }
907 } 907 }
908 } 908 }
909 if (bNotify && m_pForm->m_pFormNotify != NULL) { 909 if (bNotify && m_pForm->m_pFormNotify != NULL) {
910 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); 910 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray);
911 } 911 }
912 m_pForm->m_bUpdated = TRUE; 912 m_pForm->m_bUpdated = true;
913 return TRUE; 913 return true;
914 } 914 }
915 int CPDF_FormField::GetTopVisibleIndex() 915 int CPDF_FormField::GetTopVisibleIndex()
916 { 916 {
917 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); 917 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI");
918 if (pObj == NULL) { 918 if (pObj == NULL) {
919 return 0; 919 return 0;
920 } 920 }
921 return pObj->GetInteger(); 921 return pObj->GetInteger();
922 } 922 }
923 int CPDF_FormField::CountSelectedOptions() 923 int CPDF_FormField::CountSelectedOptions()
(...skipping 17 matching lines...) Expand all
941 CPDF_Array* pArray = pObj->GetArray(); 941 CPDF_Array* pArray = pObj->GetArray();
942 if (pArray == NULL) { 942 if (pArray == NULL) {
943 return -1; 943 return -1;
944 } 944 }
945 int iCount = (int)pArray->GetCount(); 945 int iCount = (int)pArray->GetCount();
946 if (iCount > 0 && index < iCount) { 946 if (iCount > 0 && index < iCount) {
947 return pArray->GetInteger(index); 947 return pArray->GetInteger(index);
948 } 948 }
949 return -1; 949 return -1;
950 } 950 }
951 FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) 951 bool CPDF_FormField::IsOptionSelected(int iOptIndex)
952 { 952 {
953 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); 953 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I");
954 if (pObj == NULL) { 954 if (pObj == NULL) {
955 return FALSE; 955 return false;
956 } 956 }
957 CPDF_Array* pArray = pObj->GetArray(); 957 CPDF_Array* pArray = pObj->GetArray();
958 if (pArray == NULL) { 958 if (pArray == NULL) {
959 return FALSE; 959 return false;
960 } 960 }
961 int iCount = (int)pArray->GetCount(); 961 int iCount = (int)pArray->GetCount();
962 for (int i = 0; i < iCount; i ++) { 962 for (int i = 0; i < iCount; i ++) {
963 if (pArray->GetInteger(i) == iOptIndex) { 963 if (pArray->GetInteger(i) == iOptIndex) {
964 return TRUE; 964 return true;
965 } 965 }
966 } 966 }
967 return FALSE; 967 return false;
968 } 968 }
969 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, FX_BOOL bSelected, FX_BOOL b Notify) 969 bool CPDF_FormField::SelectOption(int iOptIndex, bool bSelected, bool bNotify)
970 { 970 {
971 CPDF_Array* pArray = m_pDict->GetArray("I"); 971 CPDF_Array* pArray = m_pDict->GetArray("I");
972 if (pArray == NULL) { 972 if (pArray == NULL) {
973 if (!bSelected) { 973 if (!bSelected) {
974 return TRUE; 974 return true;
975 } 975 }
976 pArray = CPDF_Array::Create(); 976 pArray = CPDF_Array::Create();
977 if (pArray == NULL) { 977 if (pArray == NULL) {
978 return FALSE; 978 return false;
979 } 979 }
980 m_pDict->SetAt("I", pArray); 980 m_pDict->SetAt("I", pArray);
981 } 981 }
982 FX_BOOL bReturn = FALSE; 982 bool bReturn = false;
983 for (int i = 0; i < (int)pArray->GetCount(); i ++) { 983 for (int i = 0; i < (int)pArray->GetCount(); i ++) {
984 int iFind = pArray->GetInteger(i); 984 int iFind = pArray->GetInteger(i);
985 if (iFind == iOptIndex) { 985 if (iFind == iOptIndex) {
986 if (bSelected) { 986 if (bSelected) {
987 return TRUE; 987 return true;
988 } 988 }
989 if (bNotify && m_pForm->m_pFormNotify != NULL) { 989 if (bNotify && m_pForm->m_pFormNotify != NULL) {
990 int iRet = 0; 990 int iRet = 0;
991 CFX_WideString csValue = GetOptionLabel(iOptIndex); 991 CFX_WideString csValue = GetOptionLabel(iOptIndex);
992 if (GetType() == ListBox) { 992 if (GetType() == ListBox) {
993 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, c sValue); 993 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, c sValue);
994 } 994 }
995 if (GetType() == ComboBox) { 995 if (GetType() == ComboBox) {
996 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csVal ue); 996 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csVal ue);
997 } 997 }
998 if (iRet < 0) { 998 if (iRet < 0) {
999 return FALSE; 999 return false;
1000 } 1000 }
1001 } 1001 }
1002 pArray->RemoveAt(i); 1002 pArray->RemoveAt(i);
1003 bReturn = TRUE; 1003 bReturn = true;
1004 break; 1004 break;
1005 } else if (iFind > iOptIndex) { 1005 } else if (iFind > iOptIndex) {
1006 if (!bSelected) { 1006 if (!bSelected) {
1007 continue; 1007 continue;
1008 } 1008 }
1009 if (bNotify && m_pForm->m_pFormNotify != NULL) { 1009 if (bNotify && m_pForm->m_pFormNotify != NULL) {
1010 int iRet = 0; 1010 int iRet = 0;
1011 CFX_WideString csValue = GetOptionLabel(iOptIndex); 1011 CFX_WideString csValue = GetOptionLabel(iOptIndex);
1012 if (GetType() == ListBox) { 1012 if (GetType() == ListBox) {
1013 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, c sValue); 1013 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, c sValue);
1014 } 1014 }
1015 if (GetType() == ComboBox) { 1015 if (GetType() == ComboBox) {
1016 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csVal ue); 1016 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csVal ue);
1017 } 1017 }
1018 if (iRet < 0) { 1018 if (iRet < 0) {
1019 return FALSE; 1019 return false;
1020 } 1020 }
1021 } 1021 }
1022 CPDF_Number* pNum = CPDF_Number::Create(iOptIndex); 1022 CPDF_Number* pNum = CPDF_Number::Create(iOptIndex);
1023 if (pNum == NULL) { 1023 if (pNum == NULL) {
1024 return FALSE; 1024 return false;
1025 } 1025 }
1026 pArray->InsertAt(i, pNum); 1026 pArray->InsertAt(i, pNum);
1027 bReturn = TRUE; 1027 bReturn = true;
1028 break; 1028 break;
1029 } 1029 }
1030 } 1030 }
1031 if (!bReturn) { 1031 if (!bReturn) {
1032 if (bSelected) { 1032 if (bSelected) {
1033 pArray->AddInteger(iOptIndex); 1033 pArray->AddInteger(iOptIndex);
1034 } 1034 }
1035 if (pArray->GetCount() == 0) { 1035 if (pArray->GetCount() == 0) {
1036 m_pDict->RemoveAt("I"); 1036 m_pDict->RemoveAt("I");
1037 } 1037 }
1038 } 1038 }
1039 if (bNotify && m_pForm->m_pFormNotify != NULL) { 1039 if (bNotify && m_pForm->m_pFormNotify != NULL) {
1040 if (GetType() == ListBox) { 1040 if (GetType() == ListBox) {
1041 m_pForm->m_pFormNotify->AfterSelectionChange(this); 1041 m_pForm->m_pFormNotify->AfterSelectionChange(this);
1042 } 1042 }
1043 if (GetType() == ComboBox) { 1043 if (GetType() == ComboBox) {
1044 m_pForm->m_pFormNotify->AfterValueChange(this); 1044 m_pForm->m_pFormNotify->AfterValueChange(this);
1045 } 1045 }
1046 } 1046 }
1047 m_pForm->m_bUpdated = TRUE; 1047 m_pForm->m_bUpdated = true;
1048 return TRUE; 1048 return true;
1049 } 1049 }
1050 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) 1050 bool CPDF_FormField::ClearSelectedOptions(bool bNotify)
1051 { 1051 {
1052 if (bNotify && m_pForm->m_pFormNotify != NULL) { 1052 if (bNotify && m_pForm->m_pFormNotify != NULL) {
1053 int iRet = 0; 1053 int iRet = 0;
1054 CFX_WideString csValue; 1054 CFX_WideString csValue;
1055 int iIndex = GetSelectedIndex(0); 1055 int iIndex = GetSelectedIndex(0);
1056 if (iIndex >= 0) { 1056 if (iIndex >= 0) {
1057 csValue = GetOptionLabel(iIndex); 1057 csValue = GetOptionLabel(iIndex);
1058 } 1058 }
1059 if (GetType() == ListBox) { 1059 if (GetType() == ListBox) {
1060 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); 1060 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
1061 } 1061 }
1062 if (GetType() == ComboBox) { 1062 if (GetType() == ComboBox) {
1063 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); 1063 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
1064 } 1064 }
1065 if (iRet < 0) { 1065 if (iRet < 0) {
1066 return FALSE; 1066 return false;
1067 } 1067 }
1068 } 1068 }
1069 m_pDict->RemoveAt("I"); 1069 m_pDict->RemoveAt("I");
1070 if (bNotify && m_pForm->m_pFormNotify != NULL) { 1070 if (bNotify && m_pForm->m_pFormNotify != NULL) {
1071 if (GetType() == ListBox) { 1071 if (GetType() == ListBox) {
1072 m_pForm->m_pFormNotify->AfterSelectionChange(this); 1072 m_pForm->m_pFormNotify->AfterSelectionChange(this);
1073 } 1073 }
1074 if (GetType() == ComboBox) { 1074 if (GetType() == ComboBox) {
1075 m_pForm->m_pFormNotify->AfterValueChange(this); 1075 m_pForm->m_pFormNotify->AfterValueChange(this);
1076 } 1076 }
1077 } 1077 }
1078 m_pForm->m_bUpdated = TRUE; 1078 m_pForm->m_bUpdated = true;
1079 return TRUE; 1079 return true;
1080 } 1080 }
1081 void CPDF_FormField::LoadDA() 1081 void CPDF_FormField::LoadDA()
1082 { 1082 {
1083 CFX_ByteString DA; 1083 CFX_ByteString DA;
1084 if (CPDF_Object* pObj_t = FPDF_GetFieldAttr(m_pDict, "DA")) { 1084 if (CPDF_Object* pObj_t = FPDF_GetFieldAttr(m_pDict, "DA")) {
1085 DA = pObj_t->GetString(); 1085 DA = pObj_t->GetString();
1086 } 1086 }
1087 if (DA.IsEmpty() && m_pForm->m_pFormDict) { 1087 if (DA.IsEmpty() && m_pForm->m_pFormDict) {
1088 DA = m_pForm->m_pFormDict->GetString("DA"); 1088 DA = m_pForm->m_pFormDict->GetString("DA");
1089 } 1089 }
1090 if (DA.IsEmpty()) { 1090 if (DA.IsEmpty()) {
1091 return; 1091 return;
1092 } 1092 }
1093 CPDF_SimpleParser syntax(DA); 1093 CPDF_SimpleParser syntax(DA);
1094 syntax.FindTagParam("Tf", 2); 1094 syntax.FindTagParam("Tf", 2);
1095 CFX_ByteString font_name = syntax.GetWord(); 1095 CFX_ByteString font_name = syntax.GetWord();
1096 CPDF_Dictionary* pFontDict = NULL; 1096 CPDF_Dictionary* pFontDict = NULL;
1097 if (m_pForm->m_pFormDict && m_pForm->m_pFormDict->GetDict("DR") && 1097 if (m_pForm->m_pFormDict && m_pForm->m_pFormDict->GetDict("DR") &&
1098 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font") ) 1098 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font") )
1099 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(fo nt_name); 1099 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(fo nt_name);
1100 1100
1101 if (pFontDict == NULL) { 1101 if (pFontDict == NULL) {
1102 return; 1102 return;
1103 } 1103 }
1104 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); 1104 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict);
1105 m_FontSize = FX_atof(syntax.GetWord()); 1105 m_FontSize = FX_atof(syntax.GetWord());
1106 } 1106 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_formcontrol.cpp ('k') | core/src/fpdfdoc/doc_metadata.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698