| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 } | 498 } |
| 499 } | 499 } |
| 500 int nOpts = CountOptions(); | 500 int nOpts = CountOptions(); |
| 501 for (int i = 0; i < nOpts; i ++) { | 501 for (int i = 0; i < nOpts; i ++) { |
| 502 if (sel_value == GetOptionValue(i)) { | 502 if (sel_value == GetOptionValue(i)) { |
| 503 return i; | 503 return i; |
| 504 } | 504 } |
| 505 } | 505 } |
| 506 return -1; | 506 return -1; |
| 507 } | 507 } |
| 508 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) | 508 bool CPDF_FormField::ClearSelection(bool bNotify) |
| 509 { | 509 { |
| 510 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 510 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 511 int iRet = 0; | 511 int iRet = 0; |
| 512 CFX_WideString csValue; | 512 CFX_WideString csValue; |
| 513 int iIndex = GetSelectedIndex(0); | 513 int iIndex = GetSelectedIndex(0); |
| 514 if (iIndex >= 0) { | 514 if (iIndex >= 0) { |
| 515 csValue = GetOptionLabel(iIndex); | 515 csValue = GetOptionLabel(iIndex); |
| 516 } | 516 } |
| 517 if (GetType() == ListBox) { | 517 if (GetType() == ListBox) { |
| 518 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | 518 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); |
| 519 } | 519 } |
| 520 if (GetType() == ComboBox) { | 520 if (GetType() == ComboBox) { |
| 521 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | 521 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); |
| 522 } | 522 } |
| 523 if (iRet < 0) { | 523 if (iRet < 0) { |
| 524 return FALSE; | 524 return false; |
| 525 } | 525 } |
| 526 } | 526 } |
| 527 m_pDict->RemoveAt("V"); | 527 m_pDict->RemoveAt("V"); |
| 528 m_pDict->RemoveAt("I"); | 528 m_pDict->RemoveAt("I"); |
| 529 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 529 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 530 if (GetType() == ListBox) { | 530 if (GetType() == ListBox) { |
| 531 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 531 m_pForm->m_pFormNotify->AfterSelectionChange(this); |
| 532 } | 532 } |
| 533 if (GetType() == ComboBox) { | 533 if (GetType() == ComboBox) { |
| 534 m_pForm->m_pFormNotify->AfterValueChange(this); | 534 m_pForm->m_pFormNotify->AfterValueChange(this); |
| 535 } | 535 } |
| 536 } | 536 } |
| 537 if (CPDF_InterForm::m_bUpdateAP) { | 537 if (CPDF_InterForm::m_bUpdateAP) { |
| 538 UpdateAP(NULL); | 538 UpdateAP(NULL); |
| 539 } | 539 } |
| 540 m_pForm->m_bUpdated = TRUE; | 540 m_pForm->m_bUpdated = true; |
| 541 return TRUE; | 541 return true; |
| 542 } | 542 } |
| 543 FX_BOOL CPDF_FormField::IsItemSelected(int index) | 543 bool CPDF_FormField::IsItemSelected(int index) |
| 544 { | 544 { |
| 545 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 545 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
| 546 if (index < 0 || index >= CountOptions()) { | 546 if (index < 0 || index >= CountOptions()) { |
| 547 return FALSE; | 547 return false; |
| 548 } | 548 } |
| 549 if (IsOptionSelected(index)) { | 549 if (IsOptionSelected(index)) { |
| 550 return TRUE; | 550 return true; |
| 551 } | 551 } |
| 552 CFX_WideString opt_value = GetOptionValue(index); | 552 CFX_WideString opt_value = GetOptionValue(index); |
| 553 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 553 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 554 if (pValue == NULL) { | 554 if (pValue == NULL) { |
| 555 pValue = FPDF_GetFieldAttr(m_pDict, "I"); | 555 pValue = FPDF_GetFieldAttr(m_pDict, "I"); |
| 556 if (pValue == NULL) { | 556 if (pValue == NULL) { |
| 557 return FALSE; | 557 return false; |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 if (pValue->GetType() == PDFOBJ_STRING) { | 560 if (pValue->GetType() == PDFOBJ_STRING) { |
| 561 if (pValue->GetUnicodeText() == opt_value) { | 561 if (pValue->GetUnicodeText() == opt_value) { |
| 562 return TRUE; | 562 return true; |
| 563 } | 563 } |
| 564 return FALSE; | 564 return false; |
| 565 } | 565 } |
| 566 if (pValue->GetType() == PDFOBJ_NUMBER) { | 566 if (pValue->GetType() == PDFOBJ_NUMBER) { |
| 567 if (pValue->GetString().IsEmpty()) { | 567 if (pValue->GetString().IsEmpty()) { |
| 568 return FALSE; | 568 return false; |
| 569 } | 569 } |
| 570 if (pValue->GetInteger() == index) { | 570 if (pValue->GetInteger() == index) { |
| 571 return TRUE; | 571 return true; |
| 572 } | 572 } |
| 573 return FALSE; | 573 return false; |
| 574 } | 574 } |
| 575 if (pValue->GetType() != PDFOBJ_ARRAY) { | 575 if (pValue->GetType() != PDFOBJ_ARRAY) { |
| 576 return FALSE; | 576 return false; |
| 577 } | 577 } |
| 578 CPDF_Array* pArray = (CPDF_Array*)pValue; | 578 CPDF_Array* pArray = (CPDF_Array*)pValue; |
| 579 int iPos = -1; | 579 int iPos = -1; |
| 580 for (int j = 0; j < CountSelectedOptions(); j ++) { | 580 for (int j = 0; j < CountSelectedOptions(); j ++) { |
| 581 if (GetSelectedOptionIndex(j) == index) { | 581 if (GetSelectedOptionIndex(j) == index) { |
| 582 iPos = j; | 582 iPos = j; |
| 583 break; | 583 break; |
| 584 } | 584 } |
| 585 } | 585 } |
| 586 for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) | 586 for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) |
| 587 if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value && (int)i
== iPos) { | 587 if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value && (int)i
== iPos) { |
| 588 return TRUE; | 588 return true; |
| 589 } | 589 } |
| 590 return FALSE; | 590 return false; |
| 591 } | 591 } |
| 592 FX_BOOL CPDF_FormField::SetItemSelection(int index, FX_BOOL bSelected, FX_BOOL b
Notify) | 592 bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) |
| 593 { | 593 { |
| 594 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 594 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
| 595 if (index < 0 || index >= CountOptions()) { | 595 if (index < 0 || index >= CountOptions()) { |
| 596 return FALSE; | 596 return false; |
| 597 } | 597 } |
| 598 CFX_WideString opt_value = GetOptionValue(index); | 598 CFX_WideString opt_value = GetOptionValue(index); |
| 599 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 599 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 600 int iRet = 0; | 600 int iRet = 0; |
| 601 if (GetType() == ListBox) { | 601 if (GetType() == ListBox) { |
| 602 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, opt_value
); | 602 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, opt_value
); |
| 603 } | 603 } |
| 604 if (GetType() == ComboBox) { | 604 if (GetType() == ComboBox) { |
| 605 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, opt_value); | 605 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, opt_value); |
| 606 } | 606 } |
| 607 if (iRet < 0) { | 607 if (iRet < 0) { |
| 608 return FALSE; | 608 return false; |
| 609 } | 609 } |
| 610 } | 610 } |
| 611 if (!bSelected) { | 611 if (!bSelected) { |
| 612 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 612 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 613 if (pValue != NULL) { | 613 if (pValue != NULL) { |
| 614 if (m_Type == ListBox) { | 614 if (m_Type == ListBox) { |
| 615 SelectOption(index, FALSE); | 615 SelectOption(index, false); |
| 616 if (pValue->GetType() == PDFOBJ_STRING) { | 616 if (pValue->GetType() == PDFOBJ_STRING) { |
| 617 if (pValue->GetUnicodeText() == opt_value) { | 617 if (pValue->GetUnicodeText() == opt_value) { |
| 618 m_pDict->RemoveAt("V"); | 618 m_pDict->RemoveAt("V"); |
| 619 } | 619 } |
| 620 } else if (pValue->GetType() == PDFOBJ_ARRAY) { | 620 } else if (pValue->GetType() == PDFOBJ_ARRAY) { |
| 621 CPDF_Array* pArray = CPDF_Array::Create(); | 621 CPDF_Array* pArray = CPDF_Array::Create(); |
| 622 if (pArray == NULL) { | 622 if (pArray == NULL) { |
| 623 return FALSE; | 623 return false; |
| 624 } | 624 } |
| 625 int iCount = CountOptions(); | 625 int iCount = CountOptions(); |
| 626 for (int i = 0; i < iCount; i ++) { | 626 for (int i = 0; i < iCount; i ++) { |
| 627 if (i != index) { | 627 if (i != index) { |
| 628 if (IsItemSelected(i)) { | 628 if (IsItemSelected(i)) { |
| 629 opt_value = GetOptionValue(i); | 629 opt_value = GetOptionValue(i); |
| 630 pArray->AddString(PDF_EncodeText(opt_value)); | 630 pArray->AddString(PDF_EncodeText(opt_value)); |
| 631 } | 631 } |
| 632 } | 632 } |
| 633 } | 633 } |
| 634 if (pArray->GetCount() < 1) { | 634 if (pArray->GetCount() < 1) { |
| 635 pArray->Release(); | 635 pArray->Release(); |
| 636 } else { | 636 } else { |
| 637 m_pDict->SetAt("V", pArray); | 637 m_pDict->SetAt("V", pArray); |
| 638 } | 638 } |
| 639 } | 639 } |
| 640 } else if (m_Type == ComboBox) { | 640 } else if (m_Type == ComboBox) { |
| 641 m_pDict->RemoveAt("V"); | 641 m_pDict->RemoveAt("V"); |
| 642 m_pDict->RemoveAt("I"); | 642 m_pDict->RemoveAt("I"); |
| 643 } | 643 } |
| 644 } | 644 } |
| 645 } else { | 645 } else { |
| 646 if (m_Type == ListBox) { | 646 if (m_Type == ListBox) { |
| 647 SelectOption(index, TRUE); | 647 SelectOption(index, true); |
| 648 if (!(m_Flags & FORMLIST_MULTISELECT)) { | 648 if (!(m_Flags & FORMLIST_MULTISELECT)) { |
| 649 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); | 649 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); |
| 650 } else { | 650 } else { |
| 651 CPDF_Array* pArray = CPDF_Array::Create(); | 651 CPDF_Array* pArray = CPDF_Array::Create(); |
| 652 if (pArray == NULL) { | 652 if (pArray == NULL) { |
| 653 return FALSE; | 653 return false; |
| 654 } | 654 } |
| 655 FX_BOOL bSelected; | 655 bool bSelected; |
| 656 int iCount = CountOptions(); | 656 int iCount = CountOptions(); |
| 657 for (int i = 0; i < iCount; i ++) { | 657 for (int i = 0; i < iCount; i ++) { |
| 658 if (i != index) { | 658 if (i != index) { |
| 659 bSelected = IsItemSelected(i); | 659 bSelected = IsItemSelected(i); |
| 660 } else { | 660 } else { |
| 661 bSelected = TRUE; | 661 bSelected = true; |
| 662 } | 662 } |
| 663 if (bSelected) { | 663 if (bSelected) { |
| 664 opt_value = GetOptionValue(i); | 664 opt_value = GetOptionValue(i); |
| 665 pArray->AddString(PDF_EncodeText(opt_value)); | 665 pArray->AddString(PDF_EncodeText(opt_value)); |
| 666 } | 666 } |
| 667 } | 667 } |
| 668 m_pDict->SetAt("V", pArray); | 668 m_pDict->SetAt("V", pArray); |
| 669 } | 669 } |
| 670 } else if (m_Type == ComboBox) { | 670 } else if (m_Type == ComboBox) { |
| 671 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); | 671 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); |
| 672 CPDF_Array* pI = CPDF_Array::Create(); | 672 CPDF_Array* pI = CPDF_Array::Create(); |
| 673 if (pI == NULL) { | 673 if (pI == NULL) { |
| 674 return FALSE; | 674 return false; |
| 675 } | 675 } |
| 676 pI->AddInteger(index); | 676 pI->AddInteger(index); |
| 677 m_pDict->SetAt("I", pI); | 677 m_pDict->SetAt("I", pI); |
| 678 } | 678 } |
| 679 } | 679 } |
| 680 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 680 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 681 if (GetType() == ListBox) { | 681 if (GetType() == ListBox) { |
| 682 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 682 m_pForm->m_pFormNotify->AfterSelectionChange(this); |
| 683 } | 683 } |
| 684 if (GetType() == ComboBox) { | 684 if (GetType() == ComboBox) { |
| 685 m_pForm->m_pFormNotify->AfterValueChange(this); | 685 m_pForm->m_pFormNotify->AfterValueChange(this); |
| 686 } | 686 } |
| 687 } | 687 } |
| 688 if (CPDF_InterForm::m_bUpdateAP) { | 688 if (CPDF_InterForm::m_bUpdateAP) { |
| 689 UpdateAP(NULL); | 689 UpdateAP(NULL); |
| 690 } | 690 } |
| 691 m_pForm->m_bUpdated = TRUE; | 691 m_pForm->m_bUpdated = true; |
| 692 return TRUE; | 692 return true; |
| 693 } | 693 } |
| 694 FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) | 694 bool CPDF_FormField::IsItemDefaultSelected(int index) |
| 695 { | 695 { |
| 696 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 696 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
| 697 if (index < 0 || index >= CountOptions()) { | 697 if (index < 0 || index >= CountOptions()) { |
| 698 return FALSE; | 698 return false; |
| 699 } | 699 } |
| 700 int iDVIndex = GetDefaultSelectedItem(); | 700 int iDVIndex = GetDefaultSelectedItem(); |
| 701 if (iDVIndex < 0) { | 701 if (iDVIndex < 0) { |
| 702 return FALSE; | 702 return false; |
| 703 } | 703 } |
| 704 return (iDVIndex == index); | 704 return (iDVIndex == index); |
| 705 } | 705 } |
| 706 int CPDF_FormField::GetDefaultSelectedItem() | 706 int CPDF_FormField::GetDefaultSelectedItem() |
| 707 { | 707 { |
| 708 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 708 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
| 709 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV"); | 709 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV"); |
| 710 if (pValue == NULL) { | 710 if (pValue == NULL) { |
| 711 return -1; | 711 return -1; |
| 712 } | 712 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 } | 790 } |
| 791 int iCount = CountOptions(); | 791 int iCount = CountOptions(); |
| 792 for (; iStartIndex < iCount; iStartIndex ++) { | 792 for (; iStartIndex < iCount; iStartIndex ++) { |
| 793 CFX_WideString csValue = GetOptionValue(iStartIndex); | 793 CFX_WideString csValue = GetOptionValue(iStartIndex); |
| 794 if (csValue == csOptValue) { | 794 if (csValue == csOptValue) { |
| 795 return iStartIndex; | 795 return iStartIndex; |
| 796 } | 796 } |
| 797 } | 797 } |
| 798 return -1; | 798 return -1; |
| 799 } | 799 } |
| 800 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, FX_BOOL bChecked, FX_BOO
L bNotify) | 800 bool CPDF_FormField::CheckControl(int iControlIndex, bool bChecked, bool bNotify
) |
| 801 { | 801 { |
| 802 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 802 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
| 803 CPDF_FormControl* pControl = GetControl(iControlIndex); | 803 CPDF_FormControl* pControl = GetControl(iControlIndex); |
| 804 if (pControl == NULL) { | 804 if (pControl == NULL) { |
| 805 return FALSE; | 805 return false; |
| 806 } | 806 } |
| 807 if (!bChecked && pControl->IsChecked() == bChecked) { | 807 if (!bChecked && pControl->IsChecked() == bChecked) { |
| 808 return FALSE; | 808 return false; |
| 809 } | 809 } |
| 810 CFX_ByteArray statusArray; | 810 CFX_ByteArray statusArray; |
| 811 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 811 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 812 SaveCheckedFieldStatus(this, statusArray); | 812 SaveCheckedFieldStatus(this, statusArray); |
| 813 } | 813 } |
| 814 CFX_WideString csWExport = pControl->GetExportValue(); | 814 CFX_WideString csWExport = pControl->GetExportValue(); |
| 815 CFX_ByteString csBExport = PDF_EncodeText(csWExport); | 815 CFX_ByteString csBExport = PDF_EncodeText(csWExport); |
| 816 int iCount = CountControls(); | 816 int iCount = CountControls(); |
| 817 FX_BOOL bUnison = PDF_FormField_IsUnison(this); | 817 bool bUnison = PDF_FormField_IsUnison(this); |
| 818 for (int i = 0; i < iCount; i ++) { | 818 for (int i = 0; i < iCount; i ++) { |
| 819 CPDF_FormControl* pCtrl = GetControl(i); | 819 CPDF_FormControl* pCtrl = GetControl(i); |
| 820 if (bUnison) { | 820 if (bUnison) { |
| 821 CFX_WideString csEValue = pCtrl->GetExportValue(); | 821 CFX_WideString csEValue = pCtrl->GetExportValue(); |
| 822 if (csEValue == csWExport) { | 822 if (csEValue == csWExport) { |
| 823 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) { | 823 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) { |
| 824 pCtrl->CheckControl(bChecked); | 824 pCtrl->CheckControl(bChecked); |
| 825 } else if (bChecked) { | 825 } else if (bChecked) { |
| 826 pCtrl->CheckControl(FALSE); | 826 pCtrl->CheckControl(false); |
| 827 } | 827 } |
| 828 } else if (bChecked) { | 828 } else if (bChecked) { |
| 829 pCtrl->CheckControl(FALSE); | 829 pCtrl->CheckControl(false); |
| 830 } | 830 } |
| 831 } else { | 831 } else { |
| 832 if (i == iControlIndex) { | 832 if (i == iControlIndex) { |
| 833 pCtrl->CheckControl(bChecked); | 833 pCtrl->CheckControl(bChecked); |
| 834 } else if (bChecked) { | 834 } else if (bChecked) { |
| 835 pCtrl->CheckControl(FALSE); | 835 pCtrl->CheckControl(false); |
| 836 } | 836 } |
| 837 } | 837 } |
| 838 } | 838 } |
| 839 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); | 839 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); |
| 840 if (pOpt == NULL || pOpt->GetType() != PDFOBJ_ARRAY) { | 840 if (pOpt == NULL || pOpt->GetType() != PDFOBJ_ARRAY) { |
| 841 if (bChecked) { | 841 if (bChecked) { |
| 842 m_pDict->SetAtName("V", csBExport); | 842 m_pDict->SetAtName("V", csBExport); |
| 843 } else { | 843 } else { |
| 844 CFX_ByteString csV; | 844 CFX_ByteString csV; |
| 845 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); | 845 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); |
| 846 if (pV != NULL) { | 846 if (pV != NULL) { |
| 847 csV = pV->GetString(); | 847 csV = pV->GetString(); |
| 848 } | 848 } |
| 849 if (csV == csBExport) { | 849 if (csV == csBExport) { |
| 850 m_pDict->SetAtName("V", "Off"); | 850 m_pDict->SetAtName("V", "Off"); |
| 851 } | 851 } |
| 852 } | 852 } |
| 853 } else if (bChecked) { | 853 } else if (bChecked) { |
| 854 CFX_ByteString csIndex; | 854 CFX_ByteString csIndex; |
| 855 csIndex.Format("%d", iControlIndex); | 855 csIndex.Format("%d", iControlIndex); |
| 856 m_pDict->SetAtName("V", csIndex); | 856 m_pDict->SetAtName("V", csIndex); |
| 857 } | 857 } |
| 858 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 858 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 859 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); | 859 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); |
| 860 } | 860 } |
| 861 m_pForm->m_bUpdated = TRUE; | 861 m_pForm->m_bUpdated = true; |
| 862 return TRUE; | 862 return true; |
| 863 } | 863 } |
| 864 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) | 864 CFX_WideString CPDF_FormField::GetCheckValue(bool bDefault) |
| 865 { | 865 { |
| 866 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 866 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
| 867 CFX_WideString csExport = L"Off"; | 867 CFX_WideString csExport = L"Off"; |
| 868 FX_BOOL bChecked; | 868 bool bChecked; |
| 869 int iCount = CountControls(); | 869 int iCount = CountControls(); |
| 870 for (int i = 0; i < iCount; i ++) { | 870 for (int i = 0; i < iCount; i ++) { |
| 871 CPDF_FormControl* pControl = GetControl(i); | 871 CPDF_FormControl* pControl = GetControl(i); |
| 872 if (bDefault) { | 872 if (bDefault) { |
| 873 bChecked = pControl->IsDefaultChecked(); | 873 bChecked = pControl->IsDefaultChecked(); |
| 874 } else { | 874 } else { |
| 875 bChecked = pControl->IsChecked(); | 875 bChecked = pControl->IsChecked(); |
| 876 } | 876 } |
| 877 if (bChecked) { | 877 if (bChecked) { |
| 878 csExport = pControl->GetExportValue(); | 878 csExport = pControl->GetExportValue(); |
| 879 break; | 879 break; |
| 880 } | 880 } |
| 881 } | 881 } |
| 882 return csExport; | 882 return csExport; |
| 883 } | 883 } |
| 884 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, FX_BOOL bDefa
ult, FX_BOOL bNotify) | 884 bool CPDF_FormField::SetCheckValue(const CFX_WideString& value, bool bDefault, b
ool bNotify) |
| 885 { | 885 { |
| 886 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 886 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
| 887 CFX_ByteArray statusArray; | 887 CFX_ByteArray statusArray; |
| 888 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 888 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 889 SaveCheckedFieldStatus(this, statusArray); | 889 SaveCheckedFieldStatus(this, statusArray); |
| 890 } | 890 } |
| 891 int iCount = CountControls(); | 891 int iCount = CountControls(); |
| 892 for (int i = 0; i < iCount; i ++) { | 892 for (int i = 0; i < iCount; i ++) { |
| 893 CPDF_FormControl* pControl = GetControl(i); | 893 CPDF_FormControl* pControl = GetControl(i); |
| 894 CFX_WideString csExport = pControl->GetExportValue(); | 894 CFX_WideString csExport = pControl->GetExportValue(); |
| 895 if (csExport == value) { | 895 if (csExport == value) { |
| 896 if (bDefault) { | 896 if (bDefault) { |
| 897 } else { | 897 } else { |
| 898 CheckControl(GetControlIndex(pControl), TRUE); | 898 CheckControl(GetControlIndex(pControl), true); |
| 899 } | 899 } |
| 900 break; | 900 break; |
| 901 } else { | 901 } else { |
| 902 if (bDefault) { | 902 if (bDefault) { |
| 903 } else { | 903 } else { |
| 904 CheckControl(GetControlIndex(pControl), FALSE); | 904 CheckControl(GetControlIndex(pControl), false); |
| 905 } | 905 } |
| 906 } | 906 } |
| 907 } | 907 } |
| 908 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 908 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 909 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); | 909 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); |
| 910 } | 910 } |
| 911 m_pForm->m_bUpdated = TRUE; | 911 m_pForm->m_bUpdated = true; |
| 912 return TRUE; | 912 return true; |
| 913 } | 913 } |
| 914 int CPDF_FormField::GetTopVisibleIndex() | 914 int CPDF_FormField::GetTopVisibleIndex() |
| 915 { | 915 { |
| 916 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); | 916 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); |
| 917 if (pObj == NULL) { | 917 if (pObj == NULL) { |
| 918 return 0; | 918 return 0; |
| 919 } | 919 } |
| 920 return pObj->GetInteger(); | 920 return pObj->GetInteger(); |
| 921 } | 921 } |
| 922 int CPDF_FormField::CountSelectedOptions() | 922 int CPDF_FormField::CountSelectedOptions() |
| (...skipping 17 matching lines...) Expand all Loading... |
| 940 CPDF_Array* pArray = pObj->GetArray(); | 940 CPDF_Array* pArray = pObj->GetArray(); |
| 941 if (pArray == NULL) { | 941 if (pArray == NULL) { |
| 942 return -1; | 942 return -1; |
| 943 } | 943 } |
| 944 int iCount = (int)pArray->GetCount(); | 944 int iCount = (int)pArray->GetCount(); |
| 945 if (iCount > 0 && index < iCount) { | 945 if (iCount > 0 && index < iCount) { |
| 946 return pArray->GetInteger(index); | 946 return pArray->GetInteger(index); |
| 947 } | 947 } |
| 948 return -1; | 948 return -1; |
| 949 } | 949 } |
| 950 FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) | 950 bool CPDF_FormField::IsOptionSelected(int iOptIndex) |
| 951 { | 951 { |
| 952 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); | 952 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); |
| 953 if (pObj == NULL) { | 953 if (pObj == NULL) { |
| 954 return FALSE; | 954 return false; |
| 955 } | 955 } |
| 956 CPDF_Array* pArray = pObj->GetArray(); | 956 CPDF_Array* pArray = pObj->GetArray(); |
| 957 if (pArray == NULL) { | 957 if (pArray == NULL) { |
| 958 return FALSE; | 958 return false; |
| 959 } | 959 } |
| 960 int iCount = (int)pArray->GetCount(); | 960 int iCount = (int)pArray->GetCount(); |
| 961 for (int i = 0; i < iCount; i ++) { | 961 for (int i = 0; i < iCount; i ++) { |
| 962 if (pArray->GetInteger(i) == iOptIndex) { | 962 if (pArray->GetInteger(i) == iOptIndex) { |
| 963 return TRUE; | 963 return true; |
| 964 } | 964 } |
| 965 } | 965 } |
| 966 return FALSE; | 966 return false; |
| 967 } | 967 } |
| 968 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, FX_BOOL bSelected, FX_BOOL b
Notify) | 968 bool CPDF_FormField::SelectOption(int iOptIndex, bool bSelected, bool bNotify) |
| 969 { | 969 { |
| 970 CPDF_Array* pArray = m_pDict->GetArray("I"); | 970 CPDF_Array* pArray = m_pDict->GetArray("I"); |
| 971 if (pArray == NULL) { | 971 if (pArray == NULL) { |
| 972 if (!bSelected) { | 972 if (!bSelected) { |
| 973 return TRUE; | 973 return true; |
| 974 } | 974 } |
| 975 pArray = CPDF_Array::Create(); | 975 pArray = CPDF_Array::Create(); |
| 976 if (pArray == NULL) { | 976 if (pArray == NULL) { |
| 977 return FALSE; | 977 return false; |
| 978 } | 978 } |
| 979 m_pDict->SetAt("I", pArray); | 979 m_pDict->SetAt("I", pArray); |
| 980 } | 980 } |
| 981 FX_BOOL bReturn = FALSE; | 981 bool bReturn = false; |
| 982 for (int i = 0; i < (int)pArray->GetCount(); i ++) { | 982 for (int i = 0; i < (int)pArray->GetCount(); i ++) { |
| 983 int iFind = pArray->GetInteger(i); | 983 int iFind = pArray->GetInteger(i); |
| 984 if (iFind == iOptIndex) { | 984 if (iFind == iOptIndex) { |
| 985 if (bSelected) { | 985 if (bSelected) { |
| 986 return TRUE; | 986 return true; |
| 987 } | 987 } |
| 988 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 988 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 989 int iRet = 0; | 989 int iRet = 0; |
| 990 CFX_WideString csValue = GetOptionLabel(iOptIndex); | 990 CFX_WideString csValue = GetOptionLabel(iOptIndex); |
| 991 if (GetType() == ListBox) { | 991 if (GetType() == ListBox) { |
| 992 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, c
sValue); | 992 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, c
sValue); |
| 993 } | 993 } |
| 994 if (GetType() == ComboBox) { | 994 if (GetType() == ComboBox) { |
| 995 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csVal
ue); | 995 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csVal
ue); |
| 996 } | 996 } |
| 997 if (iRet < 0) { | 997 if (iRet < 0) { |
| 998 return FALSE; | 998 return false; |
| 999 } | 999 } |
| 1000 } | 1000 } |
| 1001 pArray->RemoveAt(i); | 1001 pArray->RemoveAt(i); |
| 1002 bReturn = TRUE; | 1002 bReturn = true; |
| 1003 break; | 1003 break; |
| 1004 } else if (iFind > iOptIndex) { | 1004 } else if (iFind > iOptIndex) { |
| 1005 if (!bSelected) { | 1005 if (!bSelected) { |
| 1006 continue; | 1006 continue; |
| 1007 } | 1007 } |
| 1008 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 1008 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 1009 int iRet = 0; | 1009 int iRet = 0; |
| 1010 CFX_WideString csValue = GetOptionLabel(iOptIndex); | 1010 CFX_WideString csValue = GetOptionLabel(iOptIndex); |
| 1011 if (GetType() == ListBox) { | 1011 if (GetType() == ListBox) { |
| 1012 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, c
sValue); | 1012 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, c
sValue); |
| 1013 } | 1013 } |
| 1014 if (GetType() == ComboBox) { | 1014 if (GetType() == ComboBox) { |
| 1015 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csVal
ue); | 1015 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csVal
ue); |
| 1016 } | 1016 } |
| 1017 if (iRet < 0) { | 1017 if (iRet < 0) { |
| 1018 return FALSE; | 1018 return false; |
| 1019 } | 1019 } |
| 1020 } | 1020 } |
| 1021 CPDF_Number* pNum = CPDF_Number::Create(iOptIndex); | 1021 CPDF_Number* pNum = CPDF_Number::Create(iOptIndex); |
| 1022 if (pNum == NULL) { | 1022 if (pNum == NULL) { |
| 1023 return FALSE; | 1023 return false; |
| 1024 } | 1024 } |
| 1025 pArray->InsertAt(i, pNum); | 1025 pArray->InsertAt(i, pNum); |
| 1026 bReturn = TRUE; | 1026 bReturn = true; |
| 1027 break; | 1027 break; |
| 1028 } | 1028 } |
| 1029 } | 1029 } |
| 1030 if (!bReturn) { | 1030 if (!bReturn) { |
| 1031 if (bSelected) { | 1031 if (bSelected) { |
| 1032 pArray->AddInteger(iOptIndex); | 1032 pArray->AddInteger(iOptIndex); |
| 1033 } | 1033 } |
| 1034 if (pArray->GetCount() == 0) { | 1034 if (pArray->GetCount() == 0) { |
| 1035 m_pDict->RemoveAt("I"); | 1035 m_pDict->RemoveAt("I"); |
| 1036 } | 1036 } |
| 1037 } | 1037 } |
| 1038 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 1038 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 1039 if (GetType() == ListBox) { | 1039 if (GetType() == ListBox) { |
| 1040 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 1040 m_pForm->m_pFormNotify->AfterSelectionChange(this); |
| 1041 } | 1041 } |
| 1042 if (GetType() == ComboBox) { | 1042 if (GetType() == ComboBox) { |
| 1043 m_pForm->m_pFormNotify->AfterValueChange(this); | 1043 m_pForm->m_pFormNotify->AfterValueChange(this); |
| 1044 } | 1044 } |
| 1045 } | 1045 } |
| 1046 m_pForm->m_bUpdated = TRUE; | 1046 m_pForm->m_bUpdated = true; |
| 1047 return TRUE; | 1047 return true; |
| 1048 } | 1048 } |
| 1049 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) | 1049 bool CPDF_FormField::ClearSelectedOptions(bool bNotify) |
| 1050 { | 1050 { |
| 1051 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 1051 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 1052 int iRet = 0; | 1052 int iRet = 0; |
| 1053 CFX_WideString csValue; | 1053 CFX_WideString csValue; |
| 1054 int iIndex = GetSelectedIndex(0); | 1054 int iIndex = GetSelectedIndex(0); |
| 1055 if (iIndex >= 0) { | 1055 if (iIndex >= 0) { |
| 1056 csValue = GetOptionLabel(iIndex); | 1056 csValue = GetOptionLabel(iIndex); |
| 1057 } | 1057 } |
| 1058 if (GetType() == ListBox) { | 1058 if (GetType() == ListBox) { |
| 1059 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | 1059 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); |
| 1060 } | 1060 } |
| 1061 if (GetType() == ComboBox) { | 1061 if (GetType() == ComboBox) { |
| 1062 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | 1062 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); |
| 1063 } | 1063 } |
| 1064 if (iRet < 0) { | 1064 if (iRet < 0) { |
| 1065 return FALSE; | 1065 return false; |
| 1066 } | 1066 } |
| 1067 } | 1067 } |
| 1068 m_pDict->RemoveAt("I"); | 1068 m_pDict->RemoveAt("I"); |
| 1069 if (bNotify && m_pForm->m_pFormNotify != NULL) { | 1069 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 1070 if (GetType() == ListBox) { | 1070 if (GetType() == ListBox) { |
| 1071 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 1071 m_pForm->m_pFormNotify->AfterSelectionChange(this); |
| 1072 } | 1072 } |
| 1073 if (GetType() == ComboBox) { | 1073 if (GetType() == ComboBox) { |
| 1074 m_pForm->m_pFormNotify->AfterValueChange(this); | 1074 m_pForm->m_pFormNotify->AfterValueChange(this); |
| 1075 } | 1075 } |
| 1076 } | 1076 } |
| 1077 m_pForm->m_bUpdated = TRUE; | 1077 m_pForm->m_bUpdated = true; |
| 1078 return TRUE; | 1078 return true; |
| 1079 } | 1079 } |
| 1080 void CPDF_FormField::LoadDA() | 1080 void CPDF_FormField::LoadDA() |
| 1081 { | 1081 { |
| 1082 CFX_ByteString DA; | 1082 CFX_ByteString DA; |
| 1083 if (CPDF_Object* pObj_t = FPDF_GetFieldAttr(m_pDict, "DA")) { | 1083 if (CPDF_Object* pObj_t = FPDF_GetFieldAttr(m_pDict, "DA")) { |
| 1084 DA = pObj_t->GetString(); | 1084 DA = pObj_t->GetString(); |
| 1085 } | 1085 } |
| 1086 if (DA.IsEmpty() && m_pForm->m_pFormDict) { | 1086 if (DA.IsEmpty() && m_pForm->m_pFormDict) { |
| 1087 DA = m_pForm->m_pFormDict->GetString("DA"); | 1087 DA = m_pForm->m_pFormDict->GetString("DA"); |
| 1088 } | 1088 } |
| 1089 if (DA.IsEmpty()) { | 1089 if (DA.IsEmpty()) { |
| 1090 return; | 1090 return; |
| 1091 } | 1091 } |
| 1092 CPDF_SimpleParser syntax(DA); | 1092 CPDF_SimpleParser syntax(DA); |
| 1093 syntax.FindTagParam("Tf", 2); | 1093 syntax.FindTagParam("Tf", 2); |
| 1094 CFX_ByteString font_name = syntax.GetWord(); | 1094 CFX_ByteString font_name = syntax.GetWord(); |
| 1095 CPDF_Dictionary* pFontDict = NULL; | 1095 CPDF_Dictionary* pFontDict = NULL; |
| 1096 if (m_pForm->m_pFormDict && m_pForm->m_pFormDict->GetDict("DR") && | 1096 if (m_pForm->m_pFormDict && m_pForm->m_pFormDict->GetDict("DR") && |
| 1097 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font") ) | 1097 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font") ) |
| 1098 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(fo
nt_name); | 1098 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(fo
nt_name); |
| 1099 | 1099 |
| 1100 if (pFontDict == NULL) { | 1100 if (pFontDict == NULL) { |
| 1101 return; | 1101 return; |
| 1102 } | 1102 } |
| 1103 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); | 1103 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); |
| 1104 m_FontSize = FX_atof(syntax.GetWord()); | 1104 m_FontSize = FX_atof(syntax.GetWord()); |
| 1105 } | 1105 } |
| OLD | NEW |