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 "core/fpdfapi/fpdf_parser/include/cfdf_document.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" |
8 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" |
13 #include "core/fpdfdoc/cpvt_generateap.h" | 13 #include "core/fpdfdoc/cpvt_generateap.h" |
14 #include "core/fpdfdoc/doc_utils.h" | 14 #include "core/fpdfdoc/doc_utils.h" |
15 #include "core/fpdfdoc/include/fpdf_doc.h" | 15 #include "core/fpdfdoc/include/fpdf_doc.h" |
16 | 16 |
17 FX_BOOL PDF_FormField_IsUnison(CPDF_FormField* pField) { | 17 namespace { |
18 FX_BOOL bUnison = FALSE; | 18 |
19 if (pField->GetType() == CPDF_FormField::CheckBox) { | 19 bool PDF_FormField_IsUnison(CPDF_FormField* pField) { |
20 bUnison = TRUE; | 20 if (pField->GetType() == CPDF_FormField::CheckBox) |
21 } else { | 21 return true; |
22 uint32_t dwFlags = pField->GetFieldFlags(); | 22 |
23 bUnison = ((dwFlags & 0x2000000) != 0); | 23 return (pField->GetFieldFlags() & 0x2000000) != 0; |
24 } | |
25 return bUnison; | |
26 } | 24 } |
27 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) { | 25 |
28 m_pDict = pDict; | 26 } // namespace |
29 m_Type = Unknown; | 27 |
30 m_pForm = pForm; | 28 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) |
31 m_pFont = NULL; | 29 : m_Type(Unknown), |
32 m_FontSize = 0; | 30 m_pForm(pForm), |
| 31 m_pDict(pDict), |
| 32 m_FontSize(0), |
| 33 m_pFont(nullptr) { |
33 SyncFieldFlags(); | 34 SyncFieldFlags(); |
34 } | 35 } |
| 36 |
35 CPDF_FormField::~CPDF_FormField() {} | 37 CPDF_FormField::~CPDF_FormField() {} |
| 38 |
36 void CPDF_FormField::SyncFieldFlags() { | 39 void CPDF_FormField::SyncFieldFlags() { |
37 CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") | 40 CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") |
38 ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() | 41 ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() |
39 : CFX_ByteString(); | 42 : CFX_ByteString(); |
40 uint32_t flags = FPDF_GetFieldAttr(m_pDict, "Ff") | 43 uint32_t flags = FPDF_GetFieldAttr(m_pDict, "Ff") |
41 ? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() | 44 ? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() |
42 : 0; | 45 : 0; |
43 m_Flags = 0; | 46 m_Flags = 0; |
44 if (flags & 1) { | 47 if (flags & 1) { |
45 m_Flags |= FORMFIELD_READONLY; | 48 m_Flags |= FORMFIELD_READONLY; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 101 } |
99 } | 102 } |
100 LoadDA(); | 103 LoadDA(); |
101 } else if (type_name == "Sig") { | 104 } else if (type_name == "Sig") { |
102 m_Type = Sign; | 105 m_Type = Sign; |
103 } | 106 } |
104 } | 107 } |
105 CFX_WideString CPDF_FormField::GetFullName() { | 108 CFX_WideString CPDF_FormField::GetFullName() { |
106 return ::GetFullName(m_pDict); | 109 return ::GetFullName(m_pDict); |
107 } | 110 } |
| 111 |
108 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { | 112 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { |
109 switch (m_Type) { | 113 switch (m_Type) { |
110 case CPDF_FormField::CheckBox: | 114 case CPDF_FormField::CheckBox: |
111 case CPDF_FormField::RadioButton: { | 115 case CPDF_FormField::RadioButton: { |
112 int iCount = CountControls(); | 116 int iCount = CountControls(); |
113 if (iCount) { | 117 if (iCount) { |
114 // TODO(weili): Check whether anything special needs to be done for | 118 // TODO(weili): Check whether anything special needs to be done for |
115 // unison field. Otherwise, merge these branches. | 119 // unison field. Otherwise, merge these branches. |
116 if (PDF_FormField_IsUnison(this)) { | 120 if (PDF_FormField_IsUnison(this)) { |
117 for (int i = 0; i < iCount; i++) { | 121 for (int i = 0; i < iCount; i++) { |
118 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); | 122 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); |
119 } | 123 } |
120 } else { | 124 } else { |
121 for (int i = 0; i < iCount; i++) { | 125 for (int i = 0; i < iCount; i++) { |
122 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); | 126 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); |
123 } | 127 } |
124 } | 128 } |
125 } | 129 } |
126 if (bNotify && m_pForm->m_pFormNotify) { | 130 if (bNotify && m_pForm->m_pFormNotify) { |
127 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); | 131 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
128 } | 132 } |
129 } break; | 133 } break; |
130 case CPDF_FormField::ComboBox: { | 134 case CPDF_FormField::ComboBox: |
131 CFX_WideString csValue; | |
132 ClearSelection(); | |
133 int iIndex = GetDefaultSelectedItem(); | |
134 if (iIndex >= 0) { | |
135 csValue = GetOptionLabel(iIndex); | |
136 } | |
137 if (bNotify && m_pForm->m_pFormNotify) { | |
138 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
139 if (iRet < 0) { | |
140 return FALSE; | |
141 } | |
142 } | |
143 SetItemSelection(iIndex, TRUE); | |
144 if (bNotify && m_pForm->m_pFormNotify) { | |
145 m_pForm->m_pFormNotify->AfterValueChange(this); | |
146 } | |
147 } break; | |
148 case CPDF_FormField::ListBox: { | 135 case CPDF_FormField::ListBox: { |
149 CFX_WideString csValue; | 136 CFX_WideString csValue; |
150 ClearSelection(); | 137 ClearSelection(); |
151 int iIndex = GetDefaultSelectedItem(); | 138 int iIndex = GetDefaultSelectedItem(); |
152 if (iIndex >= 0) { | 139 if (iIndex >= 0) |
153 csValue = GetOptionLabel(iIndex); | 140 csValue = GetOptionLabel(iIndex); |
154 } | 141 |
155 if (bNotify && m_pForm->m_pFormNotify) { | 142 if (bNotify && !NotifyListOrComboBoxBeforeChange(csValue)) |
156 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | 143 return FALSE; |
157 if (iRet < 0) { | 144 |
158 return FALSE; | |
159 } | |
160 } | |
161 SetItemSelection(iIndex, TRUE); | 145 SetItemSelection(iIndex, TRUE); |
162 if (bNotify && m_pForm->m_pFormNotify) { | 146 if (bNotify) |
163 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 147 NotifyListOrComboBoxAfterChange(); |
164 } | |
165 } break; | 148 } break; |
166 case CPDF_FormField::Text: | 149 case CPDF_FormField::Text: |
167 case CPDF_FormField::RichText: | 150 case CPDF_FormField::RichText: |
168 case CPDF_FormField::File: | 151 case CPDF_FormField::File: |
169 default: { | 152 default: { |
170 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); | 153 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); |
171 CFX_WideString csDValue; | 154 CFX_WideString csDValue; |
172 if (pDV) { | 155 if (pDV) |
173 csDValue = pDV->GetUnicodeText(); | 156 csDValue = pDV->GetUnicodeText(); |
174 } | 157 |
175 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); | 158 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); |
176 CFX_WideString csValue; | 159 CFX_WideString csValue; |
177 if (pV) { | 160 if (pV) |
178 csValue = pV->GetUnicodeText(); | 161 csValue = pV->GetUnicodeText(); |
179 } | 162 |
180 CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV"); | 163 CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV"); |
181 if (!pRV && (csDValue == csValue)) { | 164 if (!pRV && (csDValue == csValue)) |
182 return FALSE; | 165 return FALSE; |
183 } | 166 |
184 if (bNotify && m_pForm->m_pFormNotify) { | 167 if (bNotify && !NotifyBeforeValueChange(csDValue)) |
185 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csDValue); | 168 return FALSE; |
186 if (iRet < 0) { | 169 |
187 return FALSE; | |
188 } | |
189 } | |
190 if (pDV) { | 170 if (pDV) { |
191 CPDF_Object* pClone = pDV->Clone(); | 171 CPDF_Object* pClone = pDV->Clone(); |
192 if (!pClone) { | 172 if (!pClone) |
193 return FALSE; | 173 return FALSE; |
194 } | 174 |
195 m_pDict->SetAt("V", pClone); | 175 m_pDict->SetAt("V", pClone); |
196 if (pRV) { | 176 if (pRV) { |
197 CPDF_Object* pCloneR = pDV->Clone(); | 177 CPDF_Object* pCloneR = pDV->Clone(); |
198 m_pDict->SetAt("RV", pCloneR); | 178 m_pDict->SetAt("RV", pCloneR); |
199 } | 179 } |
200 } else { | 180 } else { |
201 m_pDict->RemoveAt("V"); | 181 m_pDict->RemoveAt("V"); |
202 m_pDict->RemoveAt("RV"); | 182 m_pDict->RemoveAt("RV"); |
203 } | 183 } |
204 if (bNotify && m_pForm->m_pFormNotify) { | 184 if (bNotify) |
205 m_pForm->m_pFormNotify->AfterValueChange(this); | 185 NotifyAfterValueChange(); |
206 } | |
207 m_pForm->m_bUpdated = TRUE; | |
208 } break; | 186 } break; |
209 } | 187 } |
210 return TRUE; | 188 return TRUE; |
211 } | 189 } |
| 190 |
212 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) { | 191 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) { |
213 if (!pControl) { | 192 if (!pControl) |
214 return -1; | 193 return -1; |
215 } | 194 |
216 for (int i = 0; i < m_ControlList.GetSize(); i++) { | 195 for (int i = 0; i < m_ControlList.GetSize(); i++) { |
217 if (m_ControlList.GetAt(i) == pControl) | 196 if (m_ControlList.GetAt(i) == pControl) |
218 return i; | 197 return i; |
219 } | 198 } |
220 return -1; | 199 return -1; |
221 } | 200 } |
222 int CPDF_FormField::GetFieldType() { | 201 int CPDF_FormField::GetFieldType() { |
223 switch (m_Type) { | 202 switch (m_Type) { |
224 case PushButton: | 203 case PushButton: |
225 return FIELDTYPE_PUSHBUTTON; | 204 return FIELDTYPE_PUSHBUTTON; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 return pObj->GetString(); | 256 return pObj->GetString(); |
278 } | 257 } |
279 CFX_WideString CPDF_FormField::GetRichTextString() { | 258 CFX_WideString CPDF_FormField::GetRichTextString() { |
280 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV"); | 259 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV"); |
281 if (!pObj) { | 260 if (!pObj) { |
282 return L""; | 261 return L""; |
283 } | 262 } |
284 return pObj->GetUnicodeText(); | 263 return pObj->GetUnicodeText(); |
285 } | 264 } |
286 CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) { | 265 CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) { |
287 if (GetType() == CheckBox || GetType() == RadioButton) { | 266 if (GetType() == CheckBox || GetType() == RadioButton) |
288 return GetCheckValue(bDefault); | 267 return GetCheckValue(bDefault); |
289 } | 268 |
290 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V"); | 269 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V"); |
291 if (!pValue) { | 270 if (!pValue) { |
292 if (!bDefault) { | 271 if (!bDefault) { |
293 if (m_Type == RichText) { | 272 if (m_Type == RichText) { |
294 pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 273 pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
295 } | 274 } |
296 if (!pValue && m_Type != Text) { | 275 if (!pValue && m_Type != Text) { |
297 pValue = FPDF_GetFieldAttr(m_pDict, "DV"); | 276 pValue = FPDF_GetFieldAttr(m_pDict, "DV"); |
298 } | 277 } |
299 } | 278 } |
300 if (!pValue) { | 279 if (!pValue) |
301 return CFX_WideString(); | 280 return CFX_WideString(); |
302 } | |
303 } | 281 } |
304 switch (pValue->GetType()) { | 282 switch (pValue->GetType()) { |
305 case CPDF_Object::STRING: | 283 case CPDF_Object::STRING: |
306 case CPDF_Object::STREAM: | 284 case CPDF_Object::STREAM: |
307 return pValue->GetUnicodeText(); | 285 return pValue->GetUnicodeText(); |
308 case CPDF_Object::ARRAY: | 286 case CPDF_Object::ARRAY: |
309 pValue = pValue->AsArray()->GetDirectObjectAt(0); | 287 pValue = pValue->AsArray()->GetDirectObjectAt(0); |
310 if (pValue) | 288 if (pValue) |
311 return pValue->GetUnicodeText(); | 289 return pValue->GetUnicodeText(); |
312 break; | 290 break; |
313 default: | 291 default: |
314 break; | 292 break; |
315 } | 293 } |
316 return CFX_WideString(); | 294 return CFX_WideString(); |
317 } | 295 } |
| 296 |
318 CFX_WideString CPDF_FormField::GetValue() { | 297 CFX_WideString CPDF_FormField::GetValue() { |
319 return GetValue(FALSE); | 298 return GetValue(FALSE); |
320 } | 299 } |
| 300 |
321 CFX_WideString CPDF_FormField::GetDefaultValue() { | 301 CFX_WideString CPDF_FormField::GetDefaultValue() { |
322 return GetValue(TRUE); | 302 return GetValue(TRUE); |
323 } | 303 } |
| 304 |
324 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, | 305 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, |
325 FX_BOOL bDefault, | 306 FX_BOOL bDefault, |
326 FX_BOOL bNotify) { | 307 FX_BOOL bNotify) { |
327 switch (m_Type) { | 308 switch (m_Type) { |
328 case CheckBox: | 309 case CheckBox: |
329 case RadioButton: { | 310 case RadioButton: { |
330 SetCheckValue(value, bDefault, bNotify); | 311 SetCheckValue(value, bDefault, bNotify); |
331 return TRUE; | 312 return TRUE; |
332 } | 313 } |
333 case File: | 314 case File: |
334 case RichText: | 315 case RichText: |
335 case Text: | 316 case Text: |
336 case ComboBox: { | 317 case ComboBox: { |
337 CFX_WideString csValue = value; | 318 CFX_WideString csValue = value; |
338 if (bNotify && m_pForm->m_pFormNotify) { | 319 if (bNotify && !NotifyBeforeValueChange(csValue)) |
339 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | 320 return FALSE; |
340 if (iRet < 0) { | 321 |
341 return FALSE; | |
342 } | |
343 } | |
344 int iIndex = FindOptionValue(csValue); | 322 int iIndex = FindOptionValue(csValue); |
345 if (iIndex < 0) { | 323 if (iIndex < 0) { |
346 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue); | 324 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue); |
347 m_pDict->SetAtString(bDefault ? "DV" : "V", bsEncodeText); | 325 m_pDict->SetAtString(bDefault ? "DV" : "V", bsEncodeText); |
348 if (m_Type == RichText && !bDefault) { | 326 if (m_Type == RichText && !bDefault) |
349 m_pDict->SetAtString("RV", bsEncodeText); | 327 m_pDict->SetAtString("RV", bsEncodeText); |
350 } | |
351 m_pDict->RemoveAt("I"); | 328 m_pDict->RemoveAt("I"); |
352 } else { | 329 } else { |
353 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(csValue)); | 330 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(csValue)); |
354 if (bDefault) { | 331 if (!bDefault) { |
355 } else { | |
356 ClearSelection(); | 332 ClearSelection(); |
357 SetItemSelection(iIndex, TRUE); | 333 SetItemSelection(iIndex, TRUE); |
358 } | 334 } |
359 } | 335 } |
360 if (bNotify && m_pForm->m_pFormNotify) { | 336 if (bNotify) |
361 m_pForm->m_pFormNotify->AfterValueChange(this); | 337 NotifyAfterValueChange(); |
362 } | |
363 m_pForm->m_bUpdated = TRUE; | |
364 } break; | 338 } break; |
365 case ListBox: { | 339 case ListBox: { |
366 int iIndex = FindOptionValue(value); | 340 int iIndex = FindOptionValue(value); |
367 if (iIndex < 0) { | 341 if (iIndex < 0) |
368 return FALSE; | 342 return FALSE; |
369 } | 343 |
370 if (bDefault && iIndex == GetDefaultSelectedItem()) { | 344 if (bDefault && iIndex == GetDefaultSelectedItem()) |
371 return FALSE; | 345 return FALSE; |
372 } | 346 |
373 if (bNotify && m_pForm->m_pFormNotify) { | 347 if (bNotify && !NotifyBeforeSelectionChange(value)) |
374 CFX_WideString csValue = value; | 348 return FALSE; |
375 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | 349 |
376 if (iRet < 0) { | 350 if (!bDefault) { |
377 return FALSE; | |
378 } | |
379 } | |
380 if (bDefault) { | |
381 } else { | |
382 ClearSelection(); | 351 ClearSelection(); |
383 SetItemSelection(iIndex, TRUE); | 352 SetItemSelection(iIndex, TRUE); |
384 } | 353 } |
385 if (bNotify && m_pForm->m_pFormNotify) { | 354 if (bNotify) |
386 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 355 NotifyAfterSelectionChange(); |
387 } | |
388 m_pForm->m_bUpdated = TRUE; | |
389 break; | 356 break; |
390 } | 357 } |
391 default: | 358 default: |
392 break; | 359 break; |
393 } | 360 } |
394 if (CPDF_InterForm::m_bUpdateAP) { | |
395 UpdateAP(NULL); | |
396 } | |
397 return TRUE; | 361 return TRUE; |
398 } | 362 } |
| 363 |
399 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bNotify) { | 364 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bNotify) { |
400 return SetValue(value, FALSE, bNotify); | 365 return SetValue(value, FALSE, bNotify); |
401 } | 366 } |
| 367 |
402 int CPDF_FormField::GetMaxLen() { | 368 int CPDF_FormField::GetMaxLen() { |
403 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen")) | 369 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen")) |
404 return pObj->GetInteger(); | 370 return pObj->GetInteger(); |
405 | 371 |
406 for (int i = 0; i < m_ControlList.GetSize(); i++) { | 372 for (int i = 0; i < m_ControlList.GetSize(); i++) { |
407 CPDF_FormControl* pControl = m_ControlList.GetAt(i); | 373 CPDF_FormControl* pControl = m_ControlList.GetAt(i); |
408 if (!pControl) | 374 if (!pControl) |
409 continue; | 375 continue; |
410 | 376 |
411 CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict; | 377 CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 if (csOpt == sel_value) { | 426 if (csOpt == sel_value) { |
461 return iOptIndex; | 427 return iOptIndex; |
462 } | 428 } |
463 } | 429 } |
464 for (int i = 0; i < CountOptions(); i++) { | 430 for (int i = 0; i < CountOptions(); i++) { |
465 if (sel_value == GetOptionValue(i)) | 431 if (sel_value == GetOptionValue(i)) |
466 return i; | 432 return i; |
467 } | 433 } |
468 return -1; | 434 return -1; |
469 } | 435 } |
| 436 |
470 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) { | 437 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) { |
471 if (bNotify && m_pForm->m_pFormNotify) { | 438 if (bNotify && m_pForm->m_pFormNotify) { |
472 int iRet = 0; | |
473 CFX_WideString csValue; | 439 CFX_WideString csValue; |
474 int iIndex = GetSelectedIndex(0); | 440 int iIndex = GetSelectedIndex(0); |
475 if (iIndex >= 0) { | 441 if (iIndex >= 0) |
476 csValue = GetOptionLabel(iIndex); | 442 csValue = GetOptionLabel(iIndex); |
477 } | 443 |
478 if (GetType() == ListBox) { | 444 if (!NotifyListOrComboBoxBeforeChange(csValue)) |
479 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | |
480 } | |
481 if (GetType() == ComboBox) { | |
482 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
483 } | |
484 if (iRet < 0) { | |
485 return FALSE; | 445 return FALSE; |
486 } | |
487 } | 446 } |
488 m_pDict->RemoveAt("V"); | 447 m_pDict->RemoveAt("V"); |
489 m_pDict->RemoveAt("I"); | 448 m_pDict->RemoveAt("I"); |
490 if (bNotify && m_pForm->m_pFormNotify) { | 449 if (bNotify) |
491 if (GetType() == ListBox) { | 450 NotifyListOrComboBoxAfterChange(); |
492 m_pForm->m_pFormNotify->AfterSelectionChange(this); | |
493 } | |
494 if (GetType() == ComboBox) { | |
495 m_pForm->m_pFormNotify->AfterValueChange(this); | |
496 } | |
497 } | |
498 if (CPDF_InterForm::m_bUpdateAP) { | |
499 UpdateAP(NULL); | |
500 } | |
501 m_pForm->m_bUpdated = TRUE; | |
502 return TRUE; | 451 return TRUE; |
503 } | 452 } |
504 | 453 |
505 FX_BOOL CPDF_FormField::IsItemSelected(int index) { | 454 FX_BOOL CPDF_FormField::IsItemSelected(int index) { |
506 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 455 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
507 if (index < 0 || index >= CountOptions()) { | 456 if (index < 0 || index >= CountOptions()) { |
508 return FALSE; | 457 return FALSE; |
509 } | 458 } |
510 if (IsOptionSelected(index)) { | 459 if (IsOptionSelected(index)) { |
511 return TRUE; | 460 return TRUE; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 i == iPos) { | 493 i == iPos) { |
545 return TRUE; | 494 return TRUE; |
546 } | 495 } |
547 return FALSE; | 496 return FALSE; |
548 } | 497 } |
549 | 498 |
550 FX_BOOL CPDF_FormField::SetItemSelection(int index, | 499 FX_BOOL CPDF_FormField::SetItemSelection(int index, |
551 FX_BOOL bSelected, | 500 FX_BOOL bSelected, |
552 FX_BOOL bNotify) { | 501 FX_BOOL bNotify) { |
553 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 502 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
554 if (index < 0 || index >= CountOptions()) { | 503 if (index < 0 || index >= CountOptions()) |
555 return FALSE; | 504 return FALSE; |
556 } | 505 |
557 CFX_WideString opt_value = GetOptionValue(index); | 506 CFX_WideString opt_value = GetOptionValue(index); |
558 if (bNotify && m_pForm->m_pFormNotify) { | 507 if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) |
559 int iRet = 0; | 508 return FALSE; |
| 509 |
| 510 if (bSelected) { |
560 if (GetType() == ListBox) { | 511 if (GetType() == ListBox) { |
561 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, opt_value); | 512 SelectOption(index, TRUE); |
| 513 if (!(m_Flags & FORMLIST_MULTISELECT)) { |
| 514 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); |
| 515 } else { |
| 516 CPDF_Array* pArray = new CPDF_Array; |
| 517 for (int i = 0; i < CountOptions(); i++) { |
| 518 if (i == index || IsItemSelected(i)) { |
| 519 opt_value = GetOptionValue(i); |
| 520 pArray->AddString(PDF_EncodeText(opt_value)); |
| 521 } |
| 522 } |
| 523 m_pDict->SetAt("V", pArray); |
| 524 } |
| 525 } else { |
| 526 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); |
| 527 CPDF_Array* pI = new CPDF_Array; |
| 528 pI->AddInteger(index); |
| 529 m_pDict->SetAt("I", pI); |
562 } | 530 } |
563 if (GetType() == ComboBox) { | 531 } else { |
564 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, opt_value); | |
565 } | |
566 if (iRet < 0) { | |
567 return FALSE; | |
568 } | |
569 } | |
570 if (!bSelected) { | |
571 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 532 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
572 if (pValue) { | 533 if (pValue) { |
573 if (m_Type == ListBox) { | 534 if (GetType() == ListBox) { |
574 SelectOption(index, FALSE); | 535 SelectOption(index, FALSE); |
575 if (pValue->IsString()) { | 536 if (pValue->IsString()) { |
576 if (pValue->GetUnicodeText() == opt_value) { | 537 if (pValue->GetUnicodeText() == opt_value) |
577 m_pDict->RemoveAt("V"); | 538 m_pDict->RemoveAt("V"); |
578 } | |
579 } else if (pValue->IsArray()) { | 539 } else if (pValue->IsArray()) { |
580 CPDF_Array* pArray = new CPDF_Array; | 540 CPDF_Array* pArray = new CPDF_Array; |
581 for (int i = 0; i < CountOptions(); i++) { | 541 for (int i = 0; i < CountOptions(); i++) { |
582 if (i != index && IsItemSelected(i)) { | 542 if (i != index && IsItemSelected(i)) { |
583 opt_value = GetOptionValue(i); | 543 opt_value = GetOptionValue(i); |
584 pArray->AddString(PDF_EncodeText(opt_value)); | 544 pArray->AddString(PDF_EncodeText(opt_value)); |
585 } | 545 } |
586 } | 546 } |
587 if (pArray->GetCount() < 1) | 547 if (pArray->GetCount() < 1) |
588 pArray->Release(); | 548 pArray->Release(); |
589 else | 549 else |
590 m_pDict->SetAt("V", pArray); | 550 m_pDict->SetAt("V", pArray); |
591 } | 551 } |
592 } else if (m_Type == ComboBox) { | 552 } else { |
593 m_pDict->RemoveAt("V"); | 553 m_pDict->RemoveAt("V"); |
594 m_pDict->RemoveAt("I"); | 554 m_pDict->RemoveAt("I"); |
595 } | 555 } |
596 } | 556 } |
597 } else { | |
598 if (m_Type == ListBox) { | |
599 SelectOption(index, TRUE); | |
600 if (!(m_Flags & FORMLIST_MULTISELECT)) { | |
601 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); | |
602 } else { | |
603 CPDF_Array* pArray = new CPDF_Array; | |
604 for (int i = 0; i < CountOptions(); i++) { | |
605 if (i == index || IsItemSelected(i)) { | |
606 opt_value = GetOptionValue(i); | |
607 pArray->AddString(PDF_EncodeText(opt_value)); | |
608 } | |
609 } | |
610 m_pDict->SetAt("V", pArray); | |
611 } | |
612 } else if (m_Type == ComboBox) { | |
613 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); | |
614 CPDF_Array* pI = new CPDF_Array; | |
615 pI->AddInteger(index); | |
616 m_pDict->SetAt("I", pI); | |
617 } | |
618 } | 557 } |
619 if (bNotify && m_pForm->m_pFormNotify) { | 558 if (bNotify) |
620 if (GetType() == ListBox) { | 559 NotifyListOrComboBoxAfterChange(); |
621 m_pForm->m_pFormNotify->AfterSelectionChange(this); | |
622 } | |
623 if (GetType() == ComboBox) { | |
624 m_pForm->m_pFormNotify->AfterValueChange(this); | |
625 } | |
626 } | |
627 if (CPDF_InterForm::m_bUpdateAP) { | |
628 UpdateAP(NULL); | |
629 } | |
630 m_pForm->m_bUpdated = TRUE; | |
631 return TRUE; | 560 return TRUE; |
632 } | 561 } |
633 | 562 |
634 FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) { | 563 FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) { |
635 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 564 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
636 if (index < 0 || index >= CountOptions()) | 565 if (index < 0 || index >= CountOptions()) |
637 return FALSE; | 566 return FALSE; |
638 int iDVIndex = GetDefaultSelectedItem(); | 567 int iDVIndex = GetDefaultSelectedItem(); |
639 return iDVIndex >= 0 && iDVIndex == index; | 568 return iDVIndex >= 0 && iDVIndex == index; |
640 } | 569 } |
641 | 570 |
642 int CPDF_FormField::GetDefaultSelectedItem() { | 571 int CPDF_FormField::GetDefaultSelectedItem() { |
643 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 572 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
644 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV"); | 573 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV"); |
645 if (!pValue) | 574 if (!pValue) |
646 return -1; | 575 return -1; |
647 CFX_WideString csDV = pValue->GetUnicodeText(); | 576 CFX_WideString csDV = pValue->GetUnicodeText(); |
648 if (csDV.IsEmpty()) | 577 if (csDV.IsEmpty()) |
649 return -1; | 578 return -1; |
650 for (int i = 0; i < CountOptions(); i++) { | 579 for (int i = 0; i < CountOptions(); i++) { |
651 if (csDV == GetOptionValue(i)) | 580 if (csDV == GetOptionValue(i)) |
652 return i; | 581 return i; |
653 } | 582 } |
654 return -1; | 583 return -1; |
655 } | 584 } |
656 | 585 |
657 void CPDF_FormField::UpdateAP(CPDF_FormControl* pControl) { | |
658 if (m_Type == PushButton || m_Type == RadioButton || m_Type == CheckBox) | |
659 return; | |
660 if (!m_pForm->m_bGenerateAP) | |
661 return; | |
662 for (int i = 0; i < CountControls(); i++) { | |
663 CPDF_FormControl* pControl = GetControl(i); | |
664 FPDF_GenerateAP(m_pForm->m_pDocument, pControl->m_pWidgetDict); | |
665 } | |
666 } | |
667 | |
668 int CPDF_FormField::CountOptions() { | 586 int CPDF_FormField::CountOptions() { |
669 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); | 587 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); |
670 return pArray ? pArray->GetCount() : 0; | 588 return pArray ? pArray->GetCount() : 0; |
671 } | 589 } |
672 | 590 |
673 CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) { | 591 CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) { |
674 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); | 592 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); |
675 if (!pArray) | 593 if (!pArray) |
676 return CFX_WideString(); | 594 return CFX_WideString(); |
677 | 595 |
(...skipping 29 matching lines...) Expand all Loading... |
707 return -1; | 625 return -1; |
708 } | 626 } |
709 | 627 |
710 #ifdef PDF_ENABLE_XFA | 628 #ifdef PDF_ENABLE_XFA |
711 int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, | 629 int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, |
712 int index, | 630 int index, |
713 FX_BOOL bNotify) { | 631 FX_BOOL bNotify) { |
714 if (csOptLabel.IsEmpty()) | 632 if (csOptLabel.IsEmpty()) |
715 return -1; | 633 return -1; |
716 | 634 |
717 if (bNotify && m_pForm->m_pFormNotify) { | 635 if (bNotify && !NotifyListOrComboBoxBeforeChange(csOptLabel)) |
718 int iRet = 0; | 636 return -1; |
719 if (GetType() == ListBox) | |
720 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csOptLabel); | |
721 if (GetType() == ComboBox) | |
722 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csOptLabel); | |
723 if (iRet < 0) | |
724 return -1; | |
725 } | |
726 | 637 |
727 CFX_ByteString csStr = | 638 CFX_ByteString csStr = |
728 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); | 639 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); |
729 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); | 640 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); |
730 CPDF_Array* pOpt = ToArray(pValue); | 641 CPDF_Array* pOpt = ToArray(pValue); |
731 if (!pOpt) { | 642 if (!pOpt) { |
732 pOpt = new CPDF_Array; | 643 pOpt = new CPDF_Array; |
733 m_pDict->SetAt("Opt", pOpt); | 644 m_pDict->SetAt("Opt", pOpt); |
734 } | 645 } |
735 | 646 |
736 int iCount = (int)pOpt->GetCount(); | 647 int iCount = (int)pOpt->GetCount(); |
737 if (index < 0 || index >= iCount) { | 648 if (index < 0 || index >= iCount) { |
738 pOpt->AddString(csStr); | 649 pOpt->AddString(csStr); |
739 index = iCount; | 650 index = iCount; |
740 } else { | 651 } else { |
741 CPDF_String* pString = new CPDF_String(csStr, FALSE); | 652 CPDF_String* pString = new CPDF_String(csStr, FALSE); |
742 pOpt->InsertAt(index, pString); | 653 pOpt->InsertAt(index, pString); |
743 } | 654 } |
744 | 655 |
745 if (bNotify && m_pForm->m_pFormNotify) { | 656 if (bNotify) |
746 if (GetType() == ListBox) | 657 NotifyListOrComboBoxAfterChange(); |
747 m_pForm->m_pFormNotify->AfterSelectionChange(this); | |
748 if (GetType() == ComboBox) | |
749 m_pForm->m_pFormNotify->AfterValueChange(this); | |
750 } | |
751 m_pForm->m_bUpdated = TRUE; | |
752 return index; | 658 return index; |
753 } | 659 } |
| 660 |
754 FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { | 661 FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { |
755 if (bNotify && m_pForm->m_pFormNotify) { | 662 if (bNotify && m_pForm->m_pFormNotify) { |
756 int iRet = 0; | |
757 CFX_WideString csValue; | 663 CFX_WideString csValue; |
758 int iIndex = GetSelectedIndex(0); | 664 int iIndex = GetSelectedIndex(0); |
759 if (iIndex >= 0) | 665 if (iIndex >= 0) |
760 csValue = GetOptionLabel(iIndex); | 666 csValue = GetOptionLabel(iIndex); |
761 if (GetType() == ListBox) | 667 if (!NotifyListOrComboBoxBeforeChange(csValue)) |
762 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | |
763 if (GetType() == ComboBox) | |
764 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
765 if (iRet < 0) | |
766 return FALSE; | 668 return FALSE; |
767 } | 669 } |
768 | 670 |
769 m_pDict->RemoveAt("Opt"); | 671 m_pDict->RemoveAt("Opt"); |
770 m_pDict->RemoveAt("V"); | 672 m_pDict->RemoveAt("V"); |
771 m_pDict->RemoveAt("DV"); | 673 m_pDict->RemoveAt("DV"); |
772 m_pDict->RemoveAt("I"); | 674 m_pDict->RemoveAt("I"); |
773 m_pDict->RemoveAt("TI"); | 675 m_pDict->RemoveAt("TI"); |
774 | 676 |
775 if (bNotify && m_pForm->m_pFormNotify) { | 677 if (bNotify) |
776 if (GetType() == ListBox) | 678 NotifyListOrComboBoxAfterChange(); |
777 m_pForm->m_pFormNotify->AfterSelectionChange(this); | |
778 if (GetType() == ComboBox) | |
779 m_pForm->m_pFormNotify->AfterValueChange(this); | |
780 } | |
781 | 679 |
782 m_pForm->m_bUpdated = TRUE; | |
783 return TRUE; | 680 return TRUE; |
784 } | 681 } |
785 #endif // PDF_ENABLE_XFA | 682 #endif // PDF_ENABLE_XFA |
| 683 |
786 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, | 684 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, |
787 bool bChecked, | 685 bool bChecked, |
788 bool bNotify) { | 686 bool bNotify) { |
789 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 687 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
790 CPDF_FormControl* pControl = GetControl(iControlIndex); | 688 CPDF_FormControl* pControl = GetControl(iControlIndex); |
791 if (!pControl) { | 689 if (!pControl) { |
792 return FALSE; | 690 return FALSE; |
793 } | 691 } |
794 if (!bChecked && pControl->IsChecked() == bChecked) { | 692 if (!bChecked && pControl->IsChecked() == bChecked) { |
795 return FALSE; | 693 return FALSE; |
796 } | 694 } |
797 CFX_WideString csWExport = pControl->GetExportValue(); | 695 CFX_WideString csWExport = pControl->GetExportValue(); |
798 CFX_ByteString csBExport = PDF_EncodeText(csWExport); | 696 CFX_ByteString csBExport = PDF_EncodeText(csWExport); |
799 int iCount = CountControls(); | 697 int iCount = CountControls(); |
800 FX_BOOL bUnison = PDF_FormField_IsUnison(this); | 698 bool bUnison = PDF_FormField_IsUnison(this); |
801 for (int i = 0; i < iCount; i++) { | 699 for (int i = 0; i < iCount; i++) { |
802 CPDF_FormControl* pCtrl = GetControl(i); | 700 CPDF_FormControl* pCtrl = GetControl(i); |
803 if (bUnison) { | 701 if (bUnison) { |
804 CFX_WideString csEValue = pCtrl->GetExportValue(); | 702 CFX_WideString csEValue = pCtrl->GetExportValue(); |
805 if (csEValue == csWExport) { | 703 if (csEValue == csWExport) { |
806 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) { | 704 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) { |
807 pCtrl->CheckControl(bChecked); | 705 pCtrl->CheckControl(bChecked); |
808 } else if (bChecked) { | 706 } else if (bChecked) { |
809 pCtrl->CheckControl(FALSE); | 707 pCtrl->CheckControl(FALSE); |
810 } | 708 } |
(...skipping 20 matching lines...) Expand all Loading... |
831 } | 729 } |
832 if (csV == csBExport) { | 730 if (csV == csBExport) { |
833 m_pDict->SetAtName("V", "Off"); | 731 m_pDict->SetAtName("V", "Off"); |
834 } | 732 } |
835 } | 733 } |
836 } else if (bChecked) { | 734 } else if (bChecked) { |
837 CFX_ByteString csIndex; | 735 CFX_ByteString csIndex; |
838 csIndex.Format("%d", iControlIndex); | 736 csIndex.Format("%d", iControlIndex); |
839 m_pDict->SetAtName("V", csIndex); | 737 m_pDict->SetAtName("V", csIndex); |
840 } | 738 } |
841 if (bNotify && m_pForm->m_pFormNotify) { | 739 if (bNotify && m_pForm->m_pFormNotify) |
842 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); | 740 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
843 } | |
844 m_pForm->m_bUpdated = TRUE; | |
845 return TRUE; | 741 return TRUE; |
846 } | 742 } |
| 743 |
847 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) { | 744 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) { |
848 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 745 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
849 CFX_WideString csExport = L"Off"; | 746 CFX_WideString csExport = L"Off"; |
850 FX_BOOL bChecked; | |
851 int iCount = CountControls(); | 747 int iCount = CountControls(); |
852 for (int i = 0; i < iCount; i++) { | 748 for (int i = 0; i < iCount; i++) { |
853 CPDF_FormControl* pControl = GetControl(i); | 749 CPDF_FormControl* pControl = GetControl(i); |
854 if (bDefault) { | 750 FX_BOOL bChecked = |
855 bChecked = pControl->IsDefaultChecked(); | 751 bDefault ? pControl->IsDefaultChecked() : pControl->IsChecked(); |
856 } else { | |
857 bChecked = pControl->IsChecked(); | |
858 } | |
859 if (bChecked) { | 752 if (bChecked) { |
860 csExport = pControl->GetExportValue(); | 753 csExport = pControl->GetExportValue(); |
861 break; | 754 break; |
862 } | 755 } |
863 } | 756 } |
864 return csExport; | 757 return csExport; |
865 } | 758 } |
| 759 |
866 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, | 760 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, |
867 FX_BOOL bDefault, | 761 FX_BOOL bDefault, |
868 FX_BOOL bNotify) { | 762 FX_BOOL bNotify) { |
869 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 763 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
870 int iCount = CountControls(); | 764 int iCount = CountControls(); |
871 for (int i = 0; i < iCount; i++) { | 765 for (int i = 0; i < iCount; i++) { |
872 CPDF_FormControl* pControl = GetControl(i); | 766 CPDF_FormControl* pControl = GetControl(i); |
873 CFX_WideString csExport = pControl->GetExportValue(); | 767 CFX_WideString csExport = pControl->GetExportValue(); |
874 if (csExport == value) { | 768 bool val = csExport == value; |
875 if (bDefault) { | 769 if (!bDefault) |
876 } else { | 770 CheckControl(GetControlIndex(pControl), val); |
877 CheckControl(GetControlIndex(pControl), TRUE); | 771 if (val) |
878 } | |
879 break; | 772 break; |
880 } else { | |
881 if (bDefault) { | |
882 } else { | |
883 CheckControl(GetControlIndex(pControl), FALSE); | |
884 } | |
885 } | |
886 } | 773 } |
887 if (bNotify && m_pForm->m_pFormNotify) { | 774 if (bNotify && m_pForm->m_pFormNotify) |
888 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); | 775 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
889 } | |
890 m_pForm->m_bUpdated = TRUE; | |
891 return TRUE; | 776 return TRUE; |
892 } | 777 } |
893 | 778 |
894 int CPDF_FormField::GetTopVisibleIndex() { | 779 int CPDF_FormField::GetTopVisibleIndex() { |
895 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); | 780 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); |
896 return pObj ? pObj->GetInteger() : 0; | 781 return pObj ? pObj->GetInteger() : 0; |
897 } | 782 } |
898 | 783 |
899 int CPDF_FormField::CountSelectedOptions() { | 784 int CPDF_FormField::CountSelectedOptions() { |
900 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); | 785 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); |
(...skipping 21 matching lines...) Expand all Loading... |
922 return TRUE; | 807 return TRUE; |
923 } | 808 } |
924 return FALSE; | 809 return FALSE; |
925 } | 810 } |
926 | 811 |
927 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, | 812 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, |
928 FX_BOOL bSelected, | 813 FX_BOOL bSelected, |
929 FX_BOOL bNotify) { | 814 FX_BOOL bNotify) { |
930 CPDF_Array* pArray = m_pDict->GetArrayBy("I"); | 815 CPDF_Array* pArray = m_pDict->GetArrayBy("I"); |
931 if (!pArray) { | 816 if (!pArray) { |
932 if (!bSelected) { | 817 if (!bSelected) |
933 return TRUE; | 818 return TRUE; |
934 } | 819 |
935 pArray = new CPDF_Array; | 820 pArray = new CPDF_Array; |
936 m_pDict->SetAt("I", pArray); | 821 m_pDict->SetAt("I", pArray); |
937 } | 822 } |
| 823 |
938 FX_BOOL bReturn = FALSE; | 824 FX_BOOL bReturn = FALSE; |
939 for (size_t i = 0; i < pArray->GetCount(); i++) { | 825 for (size_t i = 0; i < pArray->GetCount(); i++) { |
940 int iFind = pArray->GetIntegerAt(i); | 826 int iFind = pArray->GetIntegerAt(i); |
941 if (iFind == iOptIndex) { | 827 if (iFind == iOptIndex) { |
942 if (bSelected) { | 828 if (bSelected) |
943 return TRUE; | 829 return TRUE; |
944 } | 830 |
945 if (bNotify && m_pForm->m_pFormNotify) { | 831 if (bNotify && m_pForm->m_pFormNotify) { |
946 int iRet = 0; | |
947 CFX_WideString csValue = GetOptionLabel(iOptIndex); | 832 CFX_WideString csValue = GetOptionLabel(iOptIndex); |
948 if (GetType() == ListBox) { | 833 if (!NotifyListOrComboBoxBeforeChange(csValue)) |
949 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | |
950 } | |
951 if (GetType() == ComboBox) { | |
952 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
953 } | |
954 if (iRet < 0) { | |
955 return FALSE; | 834 return FALSE; |
956 } | |
957 } | 835 } |
958 pArray->RemoveAt(i); | 836 pArray->RemoveAt(i); |
959 bReturn = TRUE; | 837 bReturn = TRUE; |
960 break; | 838 break; |
961 } else if (iFind > iOptIndex) { | 839 } |
962 if (!bSelected) { | 840 |
| 841 if (iFind > iOptIndex) { |
| 842 if (!bSelected) |
963 continue; | 843 continue; |
| 844 |
| 845 if (bNotify && m_pForm->m_pFormNotify) { |
| 846 CFX_WideString csValue = GetOptionLabel(iOptIndex); |
| 847 if (!NotifyListOrComboBoxBeforeChange(csValue)) |
| 848 return FALSE; |
964 } | 849 } |
965 if (bNotify && m_pForm->m_pFormNotify) { | 850 pArray->InsertAt(i, new CPDF_Number(iOptIndex)); |
966 int iRet = 0; | |
967 CFX_WideString csValue = GetOptionLabel(iOptIndex); | |
968 if (GetType() == ListBox) { | |
969 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | |
970 } | |
971 if (GetType() == ComboBox) { | |
972 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
973 } | |
974 if (iRet < 0) { | |
975 return FALSE; | |
976 } | |
977 } | |
978 CPDF_Number* pNum = new CPDF_Number(iOptIndex); | |
979 pArray->InsertAt(i, pNum); | |
980 bReturn = TRUE; | 851 bReturn = TRUE; |
981 break; | 852 break; |
982 } | 853 } |
983 } | 854 } |
984 if (!bReturn) { | 855 if (!bReturn) { |
985 if (bSelected) { | 856 if (bSelected) |
986 pArray->AddInteger(iOptIndex); | 857 pArray->AddInteger(iOptIndex); |
987 } | 858 |
988 if (pArray->GetCount() == 0) { | 859 if (pArray->GetCount() == 0) |
989 m_pDict->RemoveAt("I"); | 860 m_pDict->RemoveAt("I"); |
990 } | |
991 } | 861 } |
992 if (bNotify && m_pForm->m_pFormNotify) { | 862 if (bNotify) |
993 if (GetType() == ListBox) { | 863 NotifyListOrComboBoxAfterChange(); |
994 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 864 |
995 } | |
996 if (GetType() == ComboBox) { | |
997 m_pForm->m_pFormNotify->AfterValueChange(this); | |
998 } | |
999 } | |
1000 m_pForm->m_bUpdated = TRUE; | |
1001 return TRUE; | 865 return TRUE; |
1002 } | 866 } |
| 867 |
1003 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) { | 868 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) { |
1004 if (bNotify && m_pForm->m_pFormNotify) { | 869 if (bNotify && m_pForm->m_pFormNotify) { |
1005 int iRet = 0; | |
1006 CFX_WideString csValue; | 870 CFX_WideString csValue; |
1007 int iIndex = GetSelectedIndex(0); | 871 int iIndex = GetSelectedIndex(0); |
1008 if (iIndex >= 0) { | 872 if (iIndex >= 0) |
1009 csValue = GetOptionLabel(iIndex); | 873 csValue = GetOptionLabel(iIndex); |
1010 } | 874 |
1011 if (GetType() == ListBox) { | 875 if (!NotifyListOrComboBoxBeforeChange(csValue)) |
1012 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | |
1013 } | |
1014 if (GetType() == ComboBox) { | |
1015 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
1016 } | |
1017 if (iRet < 0) { | |
1018 return FALSE; | 876 return FALSE; |
1019 } | |
1020 } | 877 } |
1021 m_pDict->RemoveAt("I"); | 878 m_pDict->RemoveAt("I"); |
1022 if (bNotify && m_pForm->m_pFormNotify) { | 879 if (bNotify) |
1023 if (GetType() == ListBox) { | 880 NotifyListOrComboBoxAfterChange(); |
1024 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 881 |
1025 } | |
1026 if (GetType() == ComboBox) { | |
1027 m_pForm->m_pFormNotify->AfterValueChange(this); | |
1028 } | |
1029 } | |
1030 m_pForm->m_bUpdated = TRUE; | |
1031 return TRUE; | 882 return TRUE; |
1032 } | 883 } |
| 884 |
1033 void CPDF_FormField::LoadDA() { | 885 void CPDF_FormField::LoadDA() { |
| 886 CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict; |
| 887 if (!pFormDict) |
| 888 return; |
| 889 |
1034 CFX_ByteString DA; | 890 CFX_ByteString DA; |
1035 if (CPDF_Object* pObj_t = FPDF_GetFieldAttr(m_pDict, "DA")) { | 891 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DA")) |
1036 DA = pObj_t->GetString(); | 892 DA = pObj->GetString(); |
1037 } | 893 |
1038 if (DA.IsEmpty() && m_pForm->m_pFormDict) { | 894 if (DA.IsEmpty()) |
1039 DA = m_pForm->m_pFormDict->GetStringBy("DA"); | 895 DA = pFormDict->GetStringBy("DA"); |
1040 } | 896 |
1041 if (DA.IsEmpty()) { | 897 if (DA.IsEmpty()) |
1042 return; | 898 return; |
1043 } | 899 |
| 900 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); |
| 901 if (!pDR) |
| 902 return; |
| 903 |
| 904 CPDF_Dictionary* pFont = pDR->GetDictBy("Font"); |
| 905 if (!pFont) |
| 906 return; |
| 907 |
1044 CPDF_SimpleParser syntax(DA.AsStringC()); | 908 CPDF_SimpleParser syntax(DA.AsStringC()); |
1045 syntax.FindTagParamFromStart("Tf", 2); | 909 syntax.FindTagParamFromStart("Tf", 2); |
1046 CFX_ByteString font_name(syntax.GetWord()); | 910 CFX_ByteString font_name(syntax.GetWord()); |
1047 CPDF_Dictionary* pFontDict = NULL; | 911 CPDF_Dictionary* pFontDict = pFont->GetDictBy(font_name); |
1048 if (m_pForm->m_pFormDict && m_pForm->m_pFormDict->GetDictBy("DR") && | 912 if (!pFontDict) |
1049 m_pForm->m_pFormDict->GetDictBy("DR")->GetDictBy("Font")) { | |
1050 pFontDict = m_pForm->m_pFormDict->GetDictBy("DR") | |
1051 ->GetDictBy("Font") | |
1052 ->GetDictBy(font_name); | |
1053 } | |
1054 if (!pFontDict) { | |
1055 return; | 913 return; |
1056 } | 914 |
1057 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); | 915 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); |
1058 m_FontSize = FX_atof(syntax.GetWord()); | 916 m_FontSize = FX_atof(syntax.GetWord()); |
1059 } | 917 } |
| 918 |
| 919 bool CPDF_FormField::NotifyBeforeSelectionChange(const CFX_WideString& value) { |
| 920 if (!m_pForm->m_pFormNotify) |
| 921 return true; |
| 922 return m_pForm->m_pFormNotify->BeforeSelectionChange(this, value) >= 0; |
| 923 } |
| 924 |
| 925 void CPDF_FormField::NotifyAfterSelectionChange() { |
| 926 if (!m_pForm->m_pFormNotify) |
| 927 return; |
| 928 m_pForm->m_pFormNotify->AfterSelectionChange(this); |
| 929 } |
| 930 |
| 931 bool CPDF_FormField::NotifyBeforeValueChange(const CFX_WideString& value) { |
| 932 if (!m_pForm->m_pFormNotify) |
| 933 return true; |
| 934 return m_pForm->m_pFormNotify->BeforeValueChange(this, value) >= 0; |
| 935 } |
| 936 |
| 937 void CPDF_FormField::NotifyAfterValueChange() { |
| 938 if (!m_pForm->m_pFormNotify) |
| 939 return; |
| 940 m_pForm->m_pFormNotify->AfterValueChange(this); |
| 941 } |
| 942 |
| 943 bool CPDF_FormField::NotifyListOrComboBoxBeforeChange( |
| 944 const CFX_WideString& value) { |
| 945 switch (GetType()) { |
| 946 case ListBox: |
| 947 return NotifyBeforeSelectionChange(value); |
| 948 case ComboBox: |
| 949 return NotifyBeforeValueChange(value); |
| 950 default: |
| 951 return true; |
| 952 } |
| 953 } |
| 954 |
| 955 void CPDF_FormField::NotifyListOrComboBoxAfterChange() { |
| 956 switch (GetType()) { |
| 957 case ListBox: |
| 958 NotifyAfterSelectionChange(); |
| 959 break; |
| 960 case ComboBox: |
| 961 NotifyAfterValueChange(); |
| 962 break; |
| 963 default: |
| 964 break; |
| 965 } |
| 966 } |
OLD | NEW |