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

Side by Side Diff: fpdfsdk/src/fsdk_baseform.cpp

Issue 1399273003: fpdfsdk/ differences with XFA (for didactic purposes only). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Regenerate after taking juns patch Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/fsdk_baseannot.cpp ('k') | fpdfsdk/src/fsdk_mgr.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #ifdef PDF_ENABLE_XFA
8 #include "../include/fpdfxfa/fpdfxfa_doc.h"
9 #include "../include/fpdfxfa/fpdfxfa_util.h"
10 #endif
7 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" 11 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h"
8 #include "fpdfsdk/include/fsdk_actionhandler.h" 12 #include "fpdfsdk/include/fsdk_actionhandler.h"
9 #include "fpdfsdk/include/fsdk_baseannot.h" 13 #include "fpdfsdk/include/fsdk_baseannot.h"
10 #include "fpdfsdk/include/fsdk_baseform.h" 14 #include "fpdfsdk/include/fsdk_baseform.h"
11 #include "fpdfsdk/include/fsdk_define.h" 15 #include "fpdfsdk/include/fsdk_define.h"
12 #include "fpdfsdk/include/fsdk_mgr.h" 16 #include "fpdfsdk/include/fsdk_mgr.h"
13 #include "fpdfsdk/include/javascript/IJavaScript.h" 17 #include "fpdfsdk/include/javascript/IJavaScript.h"
14 #include "third_party/base/nonstd_unique_ptr.h" 18 #include "third_party/base/nonstd_unique_ptr.h"
15 19
16 #define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01) 20 #define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01)
17 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) 21 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
18 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) 22 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
19 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) 23 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
20 24
21 CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, 25 CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
22 CPDFSDK_PageView* pPageView, 26 CPDFSDK_PageView* pPageView,
23 CPDFSDK_InterForm* pInterForm) 27 CPDFSDK_InterForm* pInterForm)
24 : CPDFSDK_BAAnnot(pAnnot, pPageView), 28 : CPDFSDK_BAAnnot(pAnnot, pPageView),
25 m_pInterForm(pInterForm), 29 m_pInterForm(pInterForm),
26 m_nAppAge(0), 30 m_nAppAge(0),
31 #ifndef PDF_ENABLE_XFA
27 m_nValueAge(0) { 32 m_nValueAge(0) {
33 #else
34 m_nValueAge(0),
35 m_hMixXFAWidget(NULL),
36 m_pWidgetHandler(NULL) {
37 #endif
28 ASSERT(m_pInterForm != NULL); 38 ASSERT(m_pInterForm != NULL);
29 } 39 }
30 40
31 CPDFSDK_Widget::~CPDFSDK_Widget() {} 41 CPDFSDK_Widget::~CPDFSDK_Widget() {}
32 42
43 #ifdef PDF_ENABLE_XFA
44 IXFA_Widget* CPDFSDK_Widget::GetMixXFAWidget() const {
45 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
46 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
47 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
48 if (!m_hMixXFAWidget) {
49 if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
50 CFX_WideString sName;
51 if (this->GetFieldType() == FIELDTYPE_RADIOBUTTON) {
52 sName = this->GetAnnotName();
53 if (sName.IsEmpty())
54 sName = GetName();
55 } else
56 sName = GetName();
57
58 if (!sName.IsEmpty())
59 m_hMixXFAWidget = pDocView->GetWidgetByName(sName);
60 }
61 }
62 return m_hMixXFAWidget;
63 }
64
65 return NULL;
66 }
67
68 IXFA_Widget* CPDFSDK_Widget::GetGroupMixXFAWidget() {
69 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
70 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
71 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
72 if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
73 CFX_WideString sName = GetName();
74 if (!sName.IsEmpty())
75 return pDocView->GetWidgetByName(sName);
76 }
77 }
78
79 return nullptr;
80 }
81
82 IXFA_WidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const {
83 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
84 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
85 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
86 if (!m_pWidgetHandler) {
87 if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
88 m_pWidgetHandler = pDocView->GetWidgetHandler();
89 }
90 }
91 return m_pWidgetHandler;
92 }
93
94 return NULL;
95 }
96
97 static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) {
98 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
99
100 switch (eXFAAAT) {
101 case PDFSDK_XFA_Click:
102 eEventType = XFA_EVENT_Click;
103 break;
104 case PDFSDK_XFA_Full:
105 eEventType = XFA_EVENT_Full;
106 break;
107 case PDFSDK_XFA_PreOpen:
108 eEventType = XFA_EVENT_PreOpen;
109 break;
110 case PDFSDK_XFA_PostOpen:
111 eEventType = XFA_EVENT_PostOpen;
112 break;
113 }
114
115 return eEventType;
116 }
117
118 static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
119 FX_BOOL bWillCommit) {
120 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
121
122 switch (eAAT) {
123 case CPDF_AAction::CursorEnter:
124 eEventType = XFA_EVENT_MouseEnter;
125 break;
126 case CPDF_AAction::CursorExit:
127 eEventType = XFA_EVENT_MouseExit;
128 break;
129 case CPDF_AAction::ButtonDown:
130 eEventType = XFA_EVENT_MouseDown;
131 break;
132 case CPDF_AAction::ButtonUp:
133 eEventType = XFA_EVENT_MouseUp;
134 break;
135 case CPDF_AAction::GetFocus:
136 eEventType = XFA_EVENT_Enter;
137 break;
138 case CPDF_AAction::LoseFocus:
139 eEventType = XFA_EVENT_Exit;
140 break;
141 case CPDF_AAction::PageOpen:
142 break;
143 case CPDF_AAction::PageClose:
144 break;
145 case CPDF_AAction::PageVisible:
146 break;
147 case CPDF_AAction::PageInvisible:
148 break;
149 case CPDF_AAction::KeyStroke:
150 if (!bWillCommit) {
151 eEventType = XFA_EVENT_Change;
152 }
153 break;
154 case CPDF_AAction::Validate:
155 eEventType = XFA_EVENT_Validate;
156 break;
157 case CPDF_AAction::OpenPage:
158 case CPDF_AAction::ClosePage:
159 case CPDF_AAction::Format:
160 case CPDF_AAction::Calculate:
161 case CPDF_AAction::CloseDocument:
162 case CPDF_AAction::SaveDocument:
163 case CPDF_AAction::DocumentSaved:
164 case CPDF_AAction::PrintDocument:
165 case CPDF_AAction::DocumentPrinted:
166 break;
167 }
168
169 return eEventType;
170 }
171
172 FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) {
173 if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
174 if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
175 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
176
177 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
178 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
179 if (IXFA_Widget* hGroupWidget = GetGroupMixXFAWidget()) {
180 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hGroupWidget);
181 if (pXFAWidgetHandler->HasEvent(pAcc, eEventType))
182 return TRUE;
183 }
184 }
185
186 {
187 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
188 return pXFAWidgetHandler->HasEvent(pAcc, eEventType);
189 }
190 }
191 }
192
193 return FALSE;
194 }
195
196 FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
197 PDFSDK_FieldAction& data,
198 CPDFSDK_PageView* pPageView) {
199 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
200 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
201 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
202 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
203
204 if (eEventType != XFA_EVENT_Unknown) {
205 if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
206 CXFA_EventParam param;
207 param.m_eType = eEventType;
208 param.m_wsChange = data.sChange;
209 param.m_iCommitKey = data.nCommitKey;
210 param.m_bShift = data.bShift;
211 param.m_iSelStart = data.nSelStart;
212 param.m_iSelEnd = data.nSelEnd;
213 param.m_wsFullText = data.sValue;
214 param.m_bKeyDown = data.bKeyDown;
215 param.m_bModifier = data.bModifier;
216 param.m_wsNewText = data.sValue;
217 if (data.nSelEnd > data.nSelStart)
218 param.m_wsNewText.Delete(data.nSelStart,
219 data.nSelEnd - data.nSelStart);
220 for (int i = 0; i < data.sChange.GetLength(); i++)
221 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
222 param.m_wsPrevText = data.sValue;
223
224 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
225 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
226 if (IXFA_Widget* hGroupWidget = GetGroupMixXFAWidget()) {
227 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hGroupWidget);
228 param.m_pTarget = pAcc;
229 pXFAWidgetHandler->ProcessEvent(pAcc, &param);
230 }
231
232 {
233 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
234 param.m_pTarget = pAcc;
235 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
236 return nRet == XFA_EVENTERROR_Sucess;
237 }
238 } else {
239 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
240 param.m_pTarget = pAcc;
241 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
242 return nRet == XFA_EVENTERROR_Sucess;
243 }
244
245 if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
246 pDocView->UpdateDocView();
247 }
248 }
249 }
250 }
251
252 return FALSE;
253 }
254
255 void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) {
256 #ifdef PDF_ENABLE_XFA
257 if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
258 if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
259 CPDF_FormField* pFormField = GetFormField();
260 ASSERT(pFormField != NULL);
261
262 if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
263 switch (GetFieldType()) {
264 case FIELDTYPE_CHECKBOX:
265 case FIELDTYPE_RADIOBUTTON: {
266 CPDF_FormControl* pFormCtrl = GetFormControl();
267 ASSERT(pFormCtrl != NULL);
268
269 XFA_CHECKSTATE eCheckState =
270 pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
271 pWidgetAcc->SetCheckState(eCheckState);
272 } break;
273 case FIELDTYPE_TEXTFIELD:
274 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
275 break;
276 case FIELDTYPE_LISTBOX: {
277 pWidgetAcc->ClearAllSelections();
278
279 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz;
280 i++) {
281 int nIndex = pFormField->GetSelectedIndex(i);
282 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
283 pWidgetAcc->SetItemState(nIndex, TRUE, FALSE);
284 }
285 } break;
286 case FIELDTYPE_COMBOBOX: {
287 pWidgetAcc->ClearAllSelections();
288
289 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz;
290 i++) {
291 int nIndex = pFormField->GetSelectedIndex(i);
292 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
293 pWidgetAcc->SetItemState(nIndex, TRUE, FALSE);
294 }
295 }
296
297 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
298 break;
299 }
300
301 if (bSynchronizeElse)
302 pWidgetAcc->ProcessValueChanged();
303 }
304 }
305 }
306 #endif // PDF_ENABLE_XFA
307 }
308
309 void CPDFSDK_Widget::SynchronizeXFAValue() {
310 #ifdef PDF_ENABLE_XFA
311 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
312 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
313 IXFA_DocView* pXFADocView = pDoc->GetXFADocView();
314 if (!pXFADocView)
315 return;
316
317 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
318 if (GetXFAWidgetHandler()) {
319 CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(),
320 GetFormControl());
321 }
322 }
323 #endif // PDF_ENABLE_XFA
324 }
325
326 void CPDFSDK_Widget::SynchronizeXFAItems() {
327 #ifdef PDF_ENABLE_XFA
328 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
329 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
330 IXFA_DocView* pXFADocView = pDoc->GetXFADocView();
331 if (!pXFADocView)
332 return;
333
334 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
335 if (GetXFAWidgetHandler())
336 SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr);
337 }
338 #endif // PDF_ENABLE_XFA
339 }
340
341 void CPDFSDK_Widget::SynchronizeXFAValue(IXFA_DocView* pXFADocView,
342 IXFA_Widget* hWidget,
343 CPDF_FormField* pFormField,
344 CPDF_FormControl* pFormControl) {
345 #ifdef PDF_ENABLE_XFA
346 ASSERT(pXFADocView != NULL);
347 ASSERT(hWidget != NULL);
348
349 if (IXFA_WidgetHandler* pXFAWidgetHandler = pXFADocView->GetWidgetHandler()) {
350 ASSERT(pFormField != NULL);
351 ASSERT(pFormControl != NULL);
352
353 switch (pFormField->GetFieldType()) {
354 case FIELDTYPE_CHECKBOX: {
355 if (CXFA_WidgetAcc* pWidgetAcc =
356 pXFAWidgetHandler->GetDataAcc(hWidget)) {
357 FX_BOOL bChecked = pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
358
359 pFormField->CheckControl(pFormField->GetControlIndex(pFormControl),
360 bChecked, TRUE);
361 }
362 } break;
363 case FIELDTYPE_RADIOBUTTON: {
364 if (CXFA_WidgetAcc* pWidgetAcc =
365 pXFAWidgetHandler->GetDataAcc(hWidget)) {
366 FX_BOOL bChecked = pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
367
368 pFormField->CheckControl(pFormField->GetControlIndex(pFormControl),
369 bChecked, TRUE);
370 }
371 } break;
372 case FIELDTYPE_TEXTFIELD: {
373 if (CXFA_WidgetAcc* pWidgetAcc =
374 pXFAWidgetHandler->GetDataAcc(hWidget)) {
375 CFX_WideString sValue;
376 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
377 pFormField->SetValue(sValue, TRUE);
378 }
379 } break;
380 case FIELDTYPE_LISTBOX: {
381 pFormField->ClearSelection(FALSE);
382
383 if (CXFA_WidgetAcc* pWidgetAcc =
384 pXFAWidgetHandler->GetDataAcc(hWidget)) {
385 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
386 int nIndex = pWidgetAcc->GetSelectedItem(i);
387
388 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
389 pFormField->SetItemSelection(nIndex, TRUE, TRUE);
390 }
391 }
392 }
393 } break;
394 case FIELDTYPE_COMBOBOX: {
395 pFormField->ClearSelection(FALSE);
396
397 if (CXFA_WidgetAcc* pWidgetAcc =
398 pXFAWidgetHandler->GetDataAcc(hWidget)) {
399 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
400 int nIndex = pWidgetAcc->GetSelectedItem(i);
401
402 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
403 pFormField->SetItemSelection(nIndex, TRUE, TRUE);
404 }
405 }
406
407 CFX_WideString sValue;
408 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
409 pFormField->SetValue(sValue, TRUE);
410 }
411 } break;
412 }
413 }
414 #endif // PDF_ENABLE_XFA
415 }
416
417 void CPDFSDK_Widget::SynchronizeXFAItems(IXFA_DocView* pXFADocView,
418 IXFA_Widget* hWidget,
419 CPDF_FormField* pFormField,
420 CPDF_FormControl* pFormControl) {
421 #ifdef PDF_ENABLE_XFA
422 ASSERT(pXFADocView != NULL);
423 ASSERT(hWidget != NULL);
424
425 if (IXFA_WidgetHandler* pXFAWidgetHandler = pXFADocView->GetWidgetHandler()) {
426 ASSERT(pFormField != NULL);
427
428 switch (pFormField->GetFieldType()) {
429 case FIELDTYPE_LISTBOX: {
430 pFormField->ClearSelection(FALSE);
431 pFormField->ClearOptions(TRUE);
432
433 if (CXFA_WidgetAcc* pWidgetAcc =
434 pXFAWidgetHandler->GetDataAcc(hWidget)) {
435 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz;
436 i++) {
437 CFX_WideString swText;
438 pWidgetAcc->GetChoiceListItem(swText, i);
439
440 pFormField->InsertOption(swText, i, TRUE);
441 }
442 }
443 } break;
444 case FIELDTYPE_COMBOBOX: {
445 pFormField->ClearSelection(FALSE);
446 pFormField->ClearOptions(FALSE);
447
448 if (CXFA_WidgetAcc* pWidgetAcc =
449 pXFAWidgetHandler->GetDataAcc(hWidget)) {
450 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz;
451 i++) {
452 CFX_WideString swText;
453 pWidgetAcc->GetChoiceListItem(swText, i);
454
455 pFormField->InsertOption(swText, i, FALSE);
456 }
457 }
458
459 pFormField->SetValue(L"", TRUE);
460 } break;
461 }
462 }
463 #endif // PDF_ENABLE_XFA
464 }
465
466 #endif
33 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid( 467 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
34 CPDF_Annot::AppearanceMode mode) { 468 CPDF_Annot::AppearanceMode mode) {
35 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP"); 469 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
36 if (!pAP) 470 if (!pAP)
37 return FALSE; 471 return FALSE;
38 472
39 // Choose the right sub-ap 473 // Choose the right sub-ap
40 const FX_CHAR* ap_entry = "N"; 474 const FX_CHAR* ap_entry = "N";
41 if (mode == CPDF_Annot::Down) 475 if (mode == CPDF_Annot::Down)
42 ap_entry = "D"; 476 ap_entry = "D";
(...skipping 26 matching lines...) Expand all
69 } 503 }
70 504
71 int CPDFSDK_Widget::GetFieldType() const { 505 int CPDFSDK_Widget::GetFieldType() const {
72 CPDF_FormField* pField = GetFormField(); 506 CPDF_FormField* pField = GetFormField();
73 ASSERT(pField != NULL); 507 ASSERT(pField != NULL);
74 508
75 return pField->GetFieldType(); 509 return pField->GetFieldType();
76 } 510 }
77 511
78 FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { 512 FX_BOOL CPDFSDK_Widget::IsAppearanceValid() {
513 #ifdef PDF_ENABLE_XFA
514 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
515 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
516 int nDocType = pDoc->GetDocType();
517 if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA)
518 return TRUE;
519
520 #endif
79 return CPDFSDK_BAAnnot::IsAppearanceValid(); 521 return CPDFSDK_BAAnnot::IsAppearanceValid();
80 } 522 }
81 523
82 int CPDFSDK_Widget::GetFieldFlags() const { 524 int CPDFSDK_Widget::GetFieldFlags() const {
83 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); 525 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
84 ASSERT(pPDFInterForm != NULL); 526 ASSERT(pPDFInterForm != NULL);
85 527
86 CPDF_FormControl* pFormControl = 528 CPDF_FormControl* pFormControl =
87 pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict()); 529 pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict());
88 CPDF_FormField* pFormField = pFormControl->GetField(); 530 CPDF_FormField* pFormField = pFormControl->GetField();
(...skipping 22 matching lines...) Expand all
111 const CPDF_Dictionary* pAnnotDict) { 553 const CPDF_Dictionary* pAnnotDict) {
112 ASSERT(pAnnotDict != NULL); 554 ASSERT(pAnnotDict != NULL);
113 return pInterForm->GetControlByDict(pAnnotDict); 555 return pInterForm->GetControlByDict(pAnnotDict);
114 } 556 }
115 557
116 int CPDFSDK_Widget::GetRotate() const { 558 int CPDFSDK_Widget::GetRotate() const {
117 CPDF_FormControl* pCtrl = GetFormControl(); 559 CPDF_FormControl* pCtrl = GetFormControl();
118 return pCtrl->GetRotation() % 360; 560 return pCtrl->GetRotation() % 360;
119 } 561 }
120 562
563 #ifdef PDF_ENABLE_XFA
564 CFX_WideString CPDFSDK_Widget::GetName() const {
565 CPDF_FormField* pFormField = GetFormField();
566 return pFormField->GetFullName();
567 }
568
569 #endif
121 FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const { 570 FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
122 CPDF_FormControl* pFormCtrl = GetFormControl(); 571 CPDF_FormControl* pFormCtrl = GetFormControl();
123 ASSERT(pFormCtrl != NULL); 572 ASSERT(pFormCtrl != NULL);
124 573
125 int iColorType = 0; 574 int iColorType = 0;
126 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType)); 575 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType));
127 576
128 return iColorType != COLORTYPE_TRANSPARENT; 577 return iColorType != COLORTYPE_TRANSPARENT;
129 } 578 }
130 579
(...skipping 30 matching lines...) Expand all
161 610
162 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance(); 611 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
163 CFX_ByteString csFont = ""; 612 CFX_ByteString csFont = "";
164 FX_FLOAT fFontSize = 0.0f; 613 FX_FLOAT fFontSize = 0.0f;
165 pDa.GetFont(csFont, fFontSize); 614 pDa.GetFont(csFont, fFontSize);
166 615
167 return fFontSize; 616 return fFontSize;
168 } 617 }
169 618
170 int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const { 619 int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
620 #ifdef PDF_ENABLE_XFA
621 #ifdef PDF_ENABLE_XFA
622 if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
623 if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
624 if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
625 if (nIndex < pWidgetAcc->CountSelectedItems())
626 return pWidgetAcc->GetSelectedItem(nIndex);
627 }
628 }
629 }
630 #endif // PDF_ENABLE_XFA
631
632 #endif
171 CPDF_FormField* pFormField = GetFormField(); 633 CPDF_FormField* pFormField = GetFormField();
172 return pFormField->GetSelectedIndex(nIndex); 634 return pFormField->GetSelectedIndex(nIndex);
173 } 635 }
174 636
637 #ifndef PDF_ENABLE_XFA
175 CFX_WideString CPDFSDK_Widget::GetValue() const { 638 CFX_WideString CPDFSDK_Widget::GetValue() const {
639 #else
640 CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const {
641 #ifdef PDF_ENABLE_XFA
642 if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
643 if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
644 if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
645 CFX_WideString sValue;
646 pWidgetAcc->GetValue(sValue, bDisplay ? XFA_VALUEPICTURE_Display
647 : XFA_VALUEPICTURE_Edit);
648 return sValue;
649 }
650 }
651 }
652 #endif // PDF_ENABLE_XFA
653
654 #endif
176 CPDF_FormField* pFormField = GetFormField(); 655 CPDF_FormField* pFormField = GetFormField();
177 return pFormField->GetValue(); 656 return pFormField->GetValue();
178 } 657 }
179 658
180 CFX_WideString CPDFSDK_Widget::GetDefaultValue() const { 659 CFX_WideString CPDFSDK_Widget::GetDefaultValue() const {
181 CPDF_FormField* pFormField = GetFormField(); 660 CPDF_FormField* pFormField = GetFormField();
182 ASSERT(pFormField != NULL); 661 ASSERT(pFormField != NULL);
183 662
184 return pFormField->GetDefaultValue(); 663 return pFormField->GetDefaultValue();
185 } 664 }
186 665
187 CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const { 666 CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
188 CPDF_FormField* pFormField = GetFormField(); 667 CPDF_FormField* pFormField = GetFormField();
189 ASSERT(pFormField != NULL); 668 ASSERT(pFormField != NULL);
190 669
191 return pFormField->GetOptionLabel(nIndex); 670 return pFormField->GetOptionLabel(nIndex);
192 } 671 }
193 672
194 int CPDFSDK_Widget::CountOptions() const { 673 int CPDFSDK_Widget::CountOptions() const {
195 CPDF_FormField* pFormField = GetFormField(); 674 CPDF_FormField* pFormField = GetFormField();
196 ASSERT(pFormField != NULL); 675 ASSERT(pFormField != NULL);
197 676
198 return pFormField->CountOptions(); 677 return pFormField->CountOptions();
199 } 678 }
200 679
201 FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const { 680 FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
681 #ifdef PDF_ENABLE_XFA
682 #ifdef PDF_ENABLE_XFA
683 if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
684 if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
685 if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
686 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
687 return pWidgetAcc->GetItemState(nIndex);
688
689 return FALSE;
690 }
691 }
692 }
693 #endif // PDF_ENABLE_XFA
694
695 #endif
202 CPDF_FormField* pFormField = GetFormField(); 696 CPDF_FormField* pFormField = GetFormField();
203 return pFormField->IsItemSelected(nIndex); 697 return pFormField->IsItemSelected(nIndex);
204 } 698 }
205 699
206 int CPDFSDK_Widget::GetTopVisibleIndex() const { 700 int CPDFSDK_Widget::GetTopVisibleIndex() const {
207 CPDF_FormField* pFormField = GetFormField(); 701 CPDF_FormField* pFormField = GetFormField();
208 return pFormField->GetTopVisibleIndex(); 702 return pFormField->GetTopVisibleIndex();
209 } 703 }
210 704
211 FX_BOOL CPDFSDK_Widget::IsChecked() const { 705 FX_BOOL CPDFSDK_Widget::IsChecked() const {
706 #ifdef PDF_ENABLE_XFA
707 #ifdef PDF_ENABLE_XFA
708 if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler()) {
709 if (IXFA_Widget* hWidget = this->GetMixXFAWidget()) {
710 if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
711 FX_BOOL bChecked = pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
712 return bChecked;
713 }
714 }
715 }
716 #endif // PDF_ENABLE_XFA
717
718 #endif
212 CPDF_FormControl* pFormCtrl = GetFormControl(); 719 CPDF_FormControl* pFormCtrl = GetFormControl();
213 return pFormCtrl->IsChecked(); 720 return pFormCtrl->IsChecked();
214 } 721 }
215 722
216 int CPDFSDK_Widget::GetAlignment() const { 723 int CPDFSDK_Widget::GetAlignment() const {
217 CPDF_FormControl* pFormCtrl = GetFormControl(); 724 CPDF_FormControl* pFormCtrl = GetFormControl();
218 ASSERT(pFormCtrl != NULL); 725 ASSERT(pFormCtrl != NULL);
219 726
220 return pFormCtrl->GetControlAlignment(); 727 return pFormCtrl->GetControlAlignment();
221 } 728 }
222 729
223 int CPDFSDK_Widget::GetMaxLen() const { 730 int CPDFSDK_Widget::GetMaxLen() const {
224 CPDF_FormField* pFormField = GetFormField(); 731 CPDF_FormField* pFormField = GetFormField();
225 ASSERT(pFormField != NULL); 732 ASSERT(pFormField != NULL);
226 733
227 return pFormField->GetMaxLen(); 734 return pFormField->GetMaxLen();
228 } 735 }
229 736
230 void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify) { 737 void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify) {
231 CPDF_FormControl* pFormCtrl = GetFormControl(); 738 CPDF_FormControl* pFormCtrl = GetFormControl();
232 ASSERT(pFormCtrl != NULL); 739 ASSERT(pFormCtrl != NULL);
233 740
234 CPDF_FormField* pFormField = pFormCtrl->GetField(); 741 CPDF_FormField* pFormField = pFormCtrl->GetField();
235 ASSERT(pFormField != NULL); 742 ASSERT(pFormField != NULL);
236 743
237 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, 744 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
238 bNotify); 745 bNotify);
746 #ifdef PDF_ENABLE_XFA
747 if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
748 ResetAppearance(TRUE);
749 if (!bNotify)
750 Synchronize(TRUE);
751 #endif
239 } 752 }
240 753
241 void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) { 754 void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) {
242 CPDF_FormField* pFormField = GetFormField(); 755 CPDF_FormField* pFormField = GetFormField();
243 ASSERT(pFormField != NULL); 756 ASSERT(pFormField != NULL);
244 757
245 pFormField->SetValue(sValue, bNotify); 758 pFormField->SetValue(sValue, bNotify);
759 #ifdef PDF_ENABLE_XFA
760
761 if (!bNotify)
762 Synchronize(TRUE);
763 #endif
246 } 764 }
247 765
248 void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {} 766 void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {}
249 void CPDFSDK_Widget::SetOptionSelection(int index, 767 void CPDFSDK_Widget::SetOptionSelection(int index,
250 FX_BOOL bSelected, 768 FX_BOOL bSelected,
251 FX_BOOL bNotify) { 769 FX_BOOL bNotify) {
252 CPDF_FormField* pFormField = GetFormField(); 770 CPDF_FormField* pFormField = GetFormField();
253 ASSERT(pFormField != NULL); 771 ASSERT(pFormField != NULL);
254 772
255 pFormField->SetItemSelection(index, bSelected, bNotify); 773 pFormField->SetItemSelection(index, bSelected, bNotify);
774 #ifdef PDF_ENABLE_XFA
775
776 if (!bNotify)
777 Synchronize(TRUE);
778 #endif
256 } 779 }
257 780
258 void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) { 781 void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) {
259 CPDF_FormField* pFormField = GetFormField(); 782 CPDF_FormField* pFormField = GetFormField();
260 ASSERT(pFormField != NULL); 783 ASSERT(pFormField != NULL);
261 784
262 pFormField->ClearSelection(bNotify); 785 pFormField->ClearSelection(bNotify);
786 #ifdef PDF_ENABLE_XFA
787
788 if (!bNotify)
789 Synchronize(TRUE);
790 #endif
263 } 791 }
264 792
265 void CPDFSDK_Widget::SetTopVisibleIndex(int index) {} 793 void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
266 794
267 void CPDFSDK_Widget::SetAppModified() { 795 void CPDFSDK_Widget::SetAppModified() {
268 m_bAppModified = TRUE; 796 m_bAppModified = TRUE;
269 } 797 }
270 798
271 void CPDFSDK_Widget::ClearAppModified() { 799 void CPDFSDK_Widget::ClearAppModified() {
272 m_bAppModified = FALSE; 800 m_bAppModified = FALSE;
273 } 801 }
274 802
275 FX_BOOL CPDFSDK_Widget::IsAppModified() const { 803 FX_BOOL CPDFSDK_Widget::IsAppModified() const {
276 return m_bAppModified; 804 return m_bAppModified;
277 } 805 }
278 806
807 #ifdef PDF_ENABLE_XFA
808 void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) {
809 switch (GetFieldType()) {
810 case FIELDTYPE_TEXTFIELD:
811 case FIELDTYPE_COMBOBOX: {
812 FX_BOOL bFormated = FALSE;
813 CFX_WideString sValue = this->OnFormat(bFormated);
814 if (bFormated)
815 this->ResetAppearance(sValue, TRUE);
816 else
817 this->ResetAppearance(NULL, TRUE);
818 } break;
819 default:
820 this->ResetAppearance(NULL, FALSE);
821 break;
822 }
823 }
824
825 #endif
279 void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue, 826 void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue,
280 FX_BOOL bValueChanged) { 827 FX_BOOL bValueChanged) {
281 SetAppModified(); 828 SetAppModified();
282 829
283 m_nAppAge++; 830 m_nAppAge++;
284 if (m_nAppAge > 999999) 831 if (m_nAppAge > 999999)
285 m_nAppAge = 0; 832 m_nAppAge = 0;
286 if (bValueChanged) 833 if (bValueChanged)
287 m_nValueAge++; 834 m_nValueAge++;
288 835
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 FX_WORD subWord = 0; 1667 FX_WORD subWord = 0;
1121 if ((dwFieldFlags >> 13) & 1) { 1668 if ((dwFieldFlags >> 13) & 1) {
1122 subWord = '*'; 1669 subWord = '*';
1123 pEdit->SetPasswordChar(subWord); 1670 pEdit->SetPasswordChar(subWord);
1124 } 1671 }
1125 1672
1126 int nMaxLen = pField->GetMaxLen(); 1673 int nMaxLen = pField->GetMaxLen();
1127 FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; 1674 FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
1128 FX_FLOAT fFontSize = GetFontSize(); 1675 FX_FLOAT fFontSize = GetFontSize();
1129 1676
1677 #ifdef PDF_ENABLE_XFA
1678 CFX_WideString sValueTmp;
1679 if (!sValue && (NULL != this->GetMixXFAWidget())) {
1680 sValueTmp = GetValue(TRUE);
1681 sValue = sValueTmp;
1682 }
1683
1684 #endif
1130 if (nMaxLen > 0) { 1685 if (nMaxLen > 0) {
1131 if (bCharArray) { 1686 if (bCharArray) {
1132 pEdit->SetCharArray(nMaxLen); 1687 pEdit->SetCharArray(nMaxLen);
1133 1688
1134 if (IsFloatZero(fFontSize)) { 1689 if (IsFloatZero(fFontSize)) {
1135 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(FontMap.GetPDFFont(0), 1690 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(FontMap.GetPDFFont(0),
1136 rcClient, nMaxLen); 1691 rcClient, nMaxLen);
1137 } 1692 }
1138 } else { 1693 } else {
1139 if (sValue) 1694 if (sValue)
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP")) { 1983 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP")) {
1429 pAPDict->RemoveAt(sAPType); 1984 pAPDict->RemoveAt(sAPType);
1430 } 1985 }
1431 } 1986 }
1432 1987
1433 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, 1988 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
1434 PDFSDK_FieldAction& data, 1989 PDFSDK_FieldAction& data,
1435 CPDFSDK_PageView* pPageView) { 1990 CPDFSDK_PageView* pPageView) {
1436 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); 1991 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
1437 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 1992 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
1993 #ifdef PDF_ENABLE_XFA
1994
1995 CPDFXFA_Document* pDoc = pDocument->GetXFADocument();
1996 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
1997 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
1998
1999 if (eEventType != XFA_EVENT_Unknown) {
2000 if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
2001 CXFA_EventParam param;
2002 param.m_eType = eEventType;
2003 param.m_wsChange = data.sChange;
2004 param.m_iCommitKey = data.nCommitKey;
2005 param.m_bShift = data.bShift;
2006 param.m_iSelStart = data.nSelStart;
2007 param.m_iSelEnd = data.nSelEnd;
2008 param.m_wsFullText = data.sValue;
2009 param.m_bKeyDown = data.bKeyDown;
2010 param.m_bModifier = data.bModifier;
2011 param.m_wsNewText = data.sValue;
2012 if (data.nSelEnd > data.nSelStart)
2013 param.m_wsNewText.Delete(data.nSelStart,
2014 data.nSelEnd - data.nSelStart);
2015 for (int i = data.sChange.GetLength() - 1; i >= 0; i--)
2016 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
2017 param.m_wsPrevText = data.sValue;
2018
2019 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
2020 param.m_pTarget = pAcc;
2021 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
2022
2023 if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
2024 pDocView->UpdateDocView();
2025 }
2026
2027 if (nRet == XFA_EVENTERROR_Sucess)
2028 return TRUE;
2029 }
2030 }
2031 }
2032
2033 #endif
1438 CPDF_Action action = GetAAction(type); 2034 CPDF_Action action = GetAAction(type);
1439 2035
1440 if (action && action.GetType() != CPDF_Action::Unknown) { 2036 if (action && action.GetType() != CPDF_Action::Unknown) {
1441 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); 2037 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
1442 return pActionHandler->DoAction_Field(action, type, pDocument, 2038 return pActionHandler->DoAction_Field(action, type, pDocument,
1443 GetFormField(), data); 2039 GetFormField(), data);
1444 } 2040 }
1445 return FALSE; 2041 return FALSE;
1446 } 2042 }
1447 2043
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 2096
1501 int nFieldFlags = GetFieldFlags(); 2097 int nFieldFlags = GetFieldFlags();
1502 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) 2098 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
1503 return FALSE; 2099 return FALSE;
1504 2100
1505 return TRUE; 2101 return TRUE;
1506 } 2102 }
1507 return FALSE; 2103 return FALSE;
1508 } 2104 }
1509 2105
2106 #ifdef PDF_ENABLE_XFA
2107 CPDFSDK_XFAWidget::CPDFSDK_XFAWidget(IXFA_Widget* pAnnot,
2108 CPDFSDK_PageView* pPageView,
2109 CPDFSDK_InterForm* pInterForm)
2110 : CPDFSDK_Annot(pPageView), m_pInterForm(pInterForm), m_hXFAWidget(pAnnot) {
2111 }
2112
2113 FX_BOOL CPDFSDK_XFAWidget::IsXFAField() {
2114 return TRUE;
2115 }
2116
2117 CFX_ByteString CPDFSDK_XFAWidget::GetType() const {
2118 return FSDK_XFAWIDGET_TYPENAME;
2119 }
2120
2121 CFX_FloatRect CPDFSDK_XFAWidget::GetRect() const {
2122 CPDFSDK_PageView* pPageView = GetPageView();
2123 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
2124 CPDFXFA_Document* pDoc = pDocument->GetXFADocument();
2125 IXFA_DocView* pDocView = pDoc->GetXFADocView();
2126 IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
2127
2128 CFX_RectF rcBBox;
2129 pWidgetHandler->GetRect(GetXFAWidget(), rcBBox);
2130
2131 return CFX_FloatRect(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
2132 rcBBox.top + rcBBox.height);
2133 }
2134
2135 #endif
1510 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument) 2136 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)
1511 : m_pDocument(pDocument), 2137 : m_pDocument(pDocument),
1512 m_pInterForm(NULL), 2138 m_pInterForm(NULL),
1513 m_bCalculate(TRUE), 2139 m_bCalculate(TRUE),
2140 #ifdef PDF_ENABLE_XFA
2141 m_bXfaCalculate(TRUE),
2142 m_bXfaValidationsEnabled(TRUE),
2143 #endif
1514 m_bBusy(FALSE) { 2144 m_bBusy(FALSE) {
1515 m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE); 2145 m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE);
1516 m_pInterForm->SetFormNotify(this); 2146 m_pInterForm->SetFormNotify(this);
1517 2147
1518 for (int i = 0; i < kNumFieldTypes; ++i) 2148 for (int i = 0; i < kNumFieldTypes; ++i)
1519 m_bNeedHightlight[i] = FALSE; 2149 m_bNeedHightlight[i] = FALSE;
1520 m_iHighlightAlpha = 0; 2150 m_iHighlightAlpha = 0;
1521 } 2151 }
1522 2152
1523 CPDFSDK_InterForm::~CPDFSDK_InterForm() { 2153 CPDFSDK_InterForm::~CPDFSDK_InterForm() {
1524 delete m_pInterForm; 2154 delete m_pInterForm;
1525 m_pInterForm = nullptr; 2155 m_pInterForm = nullptr;
1526 m_Map.clear(); 2156 m_Map.clear();
2157 #ifdef PDF_ENABLE_XFA
2158 m_XFAMap.RemoveAll();
2159 #endif
1527 } 2160 }
1528 2161
1529 FX_BOOL CPDFSDK_InterForm::HighlightWidgets() { 2162 FX_BOOL CPDFSDK_InterForm::HighlightWidgets() {
1530 return FALSE; 2163 return FALSE;
1531 } 2164 }
1532 2165
1533 CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, 2166 CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget,
1534 FX_BOOL bNext) const { 2167 FX_BOOL bNext) const {
1535 nonstd::unique_ptr<CBA_AnnotIterator> pIterator( 2168 nonstd::unique_ptr<CBA_AnnotIterator> pIterator(
1536 new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "")); 2169 new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", ""));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 2255
1623 void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, 2256 void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl,
1624 CPDFSDK_Widget* pWidget) { 2257 CPDFSDK_Widget* pWidget) {
1625 m_Map[pControl] = pWidget; 2258 m_Map[pControl] = pWidget;
1626 } 2259 }
1627 2260
1628 void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl) { 2261 void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl) {
1629 m_Map.erase(pControl); 2262 m_Map.erase(pControl);
1630 } 2263 }
1631 2264
2265 #ifdef PDF_ENABLE_XFA
2266 void CPDFSDK_InterForm::AddXFAMap(IXFA_Widget* hWidget,
2267 CPDFSDK_XFAWidget* pWidget) {
2268 m_XFAMap.SetAt(hWidget, pWidget);
2269 }
2270
2271 void CPDFSDK_InterForm::RemoveXFAMap(IXFA_Widget* hWidget) {
2272 m_XFAMap.RemoveKey(hWidget);
2273 }
2274
2275 CPDFSDK_XFAWidget* CPDFSDK_InterForm::GetXFAWidget(IXFA_Widget* hWidget) {
2276 CPDFSDK_XFAWidget* pWidget = NULL;
2277 m_XFAMap.Lookup(hWidget, pWidget);
2278
2279 return pWidget;
2280 }
2281
2282 #endif
1632 void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled) { 2283 void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled) {
1633 m_bCalculate = bEnabled; 2284 m_bCalculate = bEnabled;
1634 } 2285 }
1635 2286
1636 FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const { 2287 FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const {
1637 return m_bCalculate; 2288 return m_bCalculate;
1638 } 2289 }
1639 2290
2291 #ifdef PDF_ENABLE_XFA
2292 void CPDFSDK_InterForm::XfaEnableCalculate(FX_BOOL bEnabled) {
2293 m_bXfaCalculate = bEnabled;
2294 }
2295 FX_BOOL CPDFSDK_InterForm::IsXfaCalculateEnabled() const {
2296 return m_bXfaCalculate;
2297 }
2298
2299 FX_BOOL CPDFSDK_InterForm::IsXfaValidationsEnabled() {
2300 return m_bXfaValidationsEnabled;
2301 }
2302 void CPDFSDK_InterForm::XfaSetValidationsEnabled(FX_BOOL bEnabled) {
2303 m_bXfaValidationsEnabled = bEnabled;
2304 }
2305
2306 #endif
1640 #ifdef _WIN32 2307 #ifdef _WIN32
1641 CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile) { 2308 CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile) {
1642 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); 2309 CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
1643 CPDF_Stream* pRetStream = NULL; 2310 CPDF_Stream* pRetStream = NULL;
1644 2311
1645 if (CFX_DIBitmap* pBmp = CFX_WindowsDIB::LoadFromFile(sFile.c_str())) { 2312 if (CFX_DIBitmap* pBmp = CFX_WindowsDIB::LoadFromFile(sFile.c_str())) {
1646 int nWidth = pBmp->GetWidth(); 2313 int nWidth = pBmp->GetWidth();
1647 int nHeight = pBmp->GetHeight(); 2314 int nHeight = pBmp->GetHeight();
1648 2315
1649 CPDF_Image Image(pDocument); 2316 CPDF_Image Image(pDocument);
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 2699
2033 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( 2700 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(
2034 const std::vector<CPDF_FormField*>& fields, 2701 const std::vector<CPDF_FormField*>& fields,
2035 FX_BOOL bIncludeOrExclude, 2702 FX_BOOL bIncludeOrExclude,
2036 CFX_ByteTextBuf& textBuf) { 2703 CFX_ByteTextBuf& textBuf) {
2037 nonstd::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF( 2704 nonstd::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF(
2038 m_pDocument->GetPath(), fields, bIncludeOrExclude)); 2705 m_pDocument->GetPath(), fields, bIncludeOrExclude));
2039 return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; 2706 return pFDF ? pFDF->WriteBuf(textBuf) : FALSE;
2040 } 2707 }
2041 2708
2709 #ifdef PDF_ENABLE_XFA
2710 void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField,
2711 FX_BOOL bSynchronizeElse) {
2712 ASSERT(pFormField != NULL);
2713
2714 int x = 0;
2715 if (m_FieldSynchronizeMap.Lookup(pFormField, x))
2716 return;
2717
2718 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2719 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
2720 ASSERT(pFormCtrl != NULL);
2721
2722 ASSERT(m_pInterForm != NULL);
2723 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) {
2724 pWidget->Synchronize(bSynchronizeElse);
2725 }
2726 }
2727 }
2728
2729 #endif
2042 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( 2730 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(
2043 const CFX_WideString& sFileExt) { 2731 const CFX_WideString& sFileExt) {
2044 CFX_WideString sFileName; 2732 CFX_WideString sFileName;
2045 return L""; 2733 return L"";
2046 } 2734 }
2047 2735
2048 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, 2736 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination,
2049 FX_BOOL bUrlEncoded) { 2737 FX_BOOL bUrlEncoded) {
2050 if (sDestination.IsEmpty()) 2738 if (sDestination.IsEmpty())
2051 return FALSE; 2739 return FALSE;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2148 OnValidate(pFormField, csValue, bRC); 2836 OnValidate(pFormField, csValue, bRC);
2149 return bRC ? 1 : -1; 2837 return bRC ? 1 : -1;
2150 } 2838 }
2151 return -1; 2839 return -1;
2152 } 2840 }
2153 return 0; 2841 return 0;
2154 } 2842 }
2155 2843
2156 int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField) { 2844 int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField) {
2157 CPDF_FormField* pFormField = (CPDF_FormField*)pField; 2845 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2846 #ifdef PDF_ENABLE_XFA
2847 SynchronizeField(pFormField, FALSE);
2848
2849 #endif
2158 int nType = pFormField->GetFieldType(); 2850 int nType = pFormField->GetFieldType();
2159 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { 2851 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
2160 OnCalculate(pFormField); 2852 OnCalculate(pFormField);
2161 FX_BOOL bFormated = FALSE; 2853 FX_BOOL bFormated = FALSE;
2162 CFX_WideString sValue = OnFormat(pFormField, bFormated); 2854 CFX_WideString sValue = OnFormat(pFormField, bFormated);
2163 if (bFormated) 2855 if (bFormated)
2164 ResetFieldAppearance(pFormField, sValue.c_str(), TRUE); 2856 ResetFieldAppearance(pFormField, sValue.c_str(), TRUE);
2165 else 2857 else
2166 ResetFieldAppearance(pFormField, NULL, TRUE); 2858 ResetFieldAppearance(pFormField, NULL, TRUE);
2167 UpdateField(pFormField); 2859 UpdateField(pFormField);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
2488 break; 3180 break;
2489 } 3181 }
2490 } 3182 }
2491 } 3183 }
2492 3184
2493 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) { 3185 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) {
2494 CPDF_Rect rcAnnot; 3186 CPDF_Rect rcAnnot;
2495 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); 3187 pAnnot->GetPDFAnnot()->GetRect(rcAnnot);
2496 return rcAnnot; 3188 return rcAnnot;
2497 } 3189 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fsdk_baseannot.cpp ('k') | fpdfsdk/src/fsdk_mgr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698