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

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

Issue 1799773002: Move fpdfsdk/src up to fpdfsdk/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/fsdk_baseannot.cpp ('k') | fpdfsdk/src/fsdk_baseform_embeddertest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "fpdfsdk/include/fsdk_baseform.h"
8
9 #include <algorithm>
10 #include <memory>
11 #include <vector>
12
13 #include "core/include/fpdfapi/cfdf_document.h"
14 #include "core/include/fpdfapi/cpdf_array.h"
15 #include "core/include/fpdfapi/cpdf_document.h"
16 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h"
17 #include "fpdfsdk/include/fsdk_actionhandler.h"
18 #include "fpdfsdk/include/fsdk_baseannot.h"
19 #include "fpdfsdk/include/fsdk_define.h"
20 #include "fpdfsdk/include/fsdk_mgr.h"
21 #include "fpdfsdk/include/javascript/IJavaScript.h"
22 #include "fpdfsdk/include/pdfwindow/PWL_Utils.h"
23
24 #ifdef PDF_ENABLE_XFA
25 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h"
26 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h"
27 #endif // PDF_ENABLE_XFA
28
29 #define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01)
30 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
31 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
32 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
33
34 CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
35 CPDFSDK_PageView* pPageView,
36 CPDFSDK_InterForm* pInterForm)
37 : CPDFSDK_BAAnnot(pAnnot, pPageView),
38 m_pInterForm(pInterForm),
39 m_nAppAge(0),
40 m_nValueAge(0)
41 #ifdef PDF_ENABLE_XFA
42 ,
43 m_hMixXFAWidget(NULL),
44 m_pWidgetHandler(NULL)
45 #endif // PDF_ENABLE_XFA
46 {
47 }
48
49 CPDFSDK_Widget::~CPDFSDK_Widget() {}
50
51 #ifdef PDF_ENABLE_XFA
52 IXFA_Widget* CPDFSDK_Widget::GetMixXFAWidget() const {
53 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
54 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
55 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
56 if (!m_hMixXFAWidget) {
57 if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
58 CFX_WideString sName;
59 if (GetFieldType() == FIELDTYPE_RADIOBUTTON) {
60 sName = GetAnnotName();
61 if (sName.IsEmpty())
62 sName = GetName();
63 } else {
64 sName = GetName();
65 }
66
67 if (!sName.IsEmpty())
68 m_hMixXFAWidget = pDocView->GetWidgetByName(sName);
69 }
70 }
71 return m_hMixXFAWidget;
72 }
73
74 return NULL;
75 }
76
77 IXFA_Widget* CPDFSDK_Widget::GetGroupMixXFAWidget() {
78 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
79 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
80 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
81 if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
82 CFX_WideString sName = GetName();
83 if (!sName.IsEmpty())
84 return pDocView->GetWidgetByName(sName);
85 }
86 }
87
88 return nullptr;
89 }
90
91 IXFA_WidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const {
92 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
93 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
94 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
95 if (!m_pWidgetHandler) {
96 if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
97 m_pWidgetHandler = pDocView->GetWidgetHandler();
98 }
99 }
100 return m_pWidgetHandler;
101 }
102
103 return NULL;
104 }
105
106 static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) {
107 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
108
109 switch (eXFAAAT) {
110 case PDFSDK_XFA_Click:
111 eEventType = XFA_EVENT_Click;
112 break;
113 case PDFSDK_XFA_Full:
114 eEventType = XFA_EVENT_Full;
115 break;
116 case PDFSDK_XFA_PreOpen:
117 eEventType = XFA_EVENT_PreOpen;
118 break;
119 case PDFSDK_XFA_PostOpen:
120 eEventType = XFA_EVENT_PostOpen;
121 break;
122 }
123
124 return eEventType;
125 }
126
127 static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
128 FX_BOOL bWillCommit) {
129 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
130
131 switch (eAAT) {
132 case CPDF_AAction::CursorEnter:
133 eEventType = XFA_EVENT_MouseEnter;
134 break;
135 case CPDF_AAction::CursorExit:
136 eEventType = XFA_EVENT_MouseExit;
137 break;
138 case CPDF_AAction::ButtonDown:
139 eEventType = XFA_EVENT_MouseDown;
140 break;
141 case CPDF_AAction::ButtonUp:
142 eEventType = XFA_EVENT_MouseUp;
143 break;
144 case CPDF_AAction::GetFocus:
145 eEventType = XFA_EVENT_Enter;
146 break;
147 case CPDF_AAction::LoseFocus:
148 eEventType = XFA_EVENT_Exit;
149 break;
150 case CPDF_AAction::PageOpen:
151 break;
152 case CPDF_AAction::PageClose:
153 break;
154 case CPDF_AAction::PageVisible:
155 break;
156 case CPDF_AAction::PageInvisible:
157 break;
158 case CPDF_AAction::KeyStroke:
159 if (!bWillCommit) {
160 eEventType = XFA_EVENT_Change;
161 }
162 break;
163 case CPDF_AAction::Validate:
164 eEventType = XFA_EVENT_Validate;
165 break;
166 case CPDF_AAction::OpenPage:
167 case CPDF_AAction::ClosePage:
168 case CPDF_AAction::Format:
169 case CPDF_AAction::Calculate:
170 case CPDF_AAction::CloseDocument:
171 case CPDF_AAction::SaveDocument:
172 case CPDF_AAction::DocumentSaved:
173 case CPDF_AAction::PrintDocument:
174 case CPDF_AAction::DocumentPrinted:
175 break;
176 }
177
178 return eEventType;
179 }
180
181 FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) {
182 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
183 if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
184 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
185
186 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
187 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
188 if (IXFA_Widget* hGroupWidget = GetGroupMixXFAWidget()) {
189 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hGroupWidget);
190 if (pXFAWidgetHandler->HasEvent(pAcc, eEventType))
191 return TRUE;
192 }
193 }
194
195 {
196 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
197 return pXFAWidgetHandler->HasEvent(pAcc, eEventType);
198 }
199 }
200 }
201
202 return FALSE;
203 }
204
205 FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
206 PDFSDK_FieldAction& data,
207 CPDFSDK_PageView* pPageView) {
208 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
209 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
210 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
211 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
212
213 if (eEventType != XFA_EVENT_Unknown) {
214 if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
215 CXFA_EventParam param;
216 param.m_eType = eEventType;
217 param.m_wsChange = data.sChange;
218 param.m_iCommitKey = data.nCommitKey;
219 param.m_bShift = data.bShift;
220 param.m_iSelStart = data.nSelStart;
221 param.m_iSelEnd = data.nSelEnd;
222 param.m_wsFullText = data.sValue;
223 param.m_bKeyDown = data.bKeyDown;
224 param.m_bModifier = data.bModifier;
225 param.m_wsNewText = data.sValue;
226 if (data.nSelEnd > data.nSelStart)
227 param.m_wsNewText.Delete(data.nSelStart,
228 data.nSelEnd - data.nSelStart);
229 for (int i = 0; i < data.sChange.GetLength(); i++)
230 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
231 param.m_wsPrevText = data.sValue;
232
233 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
234 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
235 if (IXFA_Widget* hGroupWidget = GetGroupMixXFAWidget()) {
236 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hGroupWidget);
237 param.m_pTarget = pAcc;
238 pXFAWidgetHandler->ProcessEvent(pAcc, &param);
239 }
240
241 {
242 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
243 param.m_pTarget = pAcc;
244 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
245 return nRet == XFA_EVENTERROR_Sucess;
246 }
247 } else {
248 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
249 param.m_pTarget = pAcc;
250 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
251 return nRet == XFA_EVENTERROR_Sucess;
252 }
253
254 if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
255 pDocView->UpdateDocView();
256 }
257 }
258 }
259 }
260
261 return FALSE;
262 }
263
264 void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) {
265 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
266 if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
267 CPDF_FormField* pFormField = GetFormField();
268 if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
269 switch (GetFieldType()) {
270 case FIELDTYPE_CHECKBOX:
271 case FIELDTYPE_RADIOBUTTON: {
272 CPDF_FormControl* pFormCtrl = GetFormControl();
273 XFA_CHECKSTATE eCheckState =
274 pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
275 pWidgetAcc->SetCheckState(eCheckState);
276 } break;
277 case FIELDTYPE_TEXTFIELD:
278 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
279 break;
280 case FIELDTYPE_LISTBOX: {
281 pWidgetAcc->ClearAllSelections();
282
283 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz;
284 i++) {
285 int nIndex = pFormField->GetSelectedIndex(i);
286 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
287 pWidgetAcc->SetItemState(nIndex, TRUE, FALSE);
288 }
289 } break;
290 case FIELDTYPE_COMBOBOX: {
291 pWidgetAcc->ClearAllSelections();
292
293 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz;
294 i++) {
295 int nIndex = pFormField->GetSelectedIndex(i);
296 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
297 pWidgetAcc->SetItemState(nIndex, TRUE, FALSE);
298 }
299 }
300
301 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
302 break;
303 }
304
305 if (bSynchronizeElse)
306 pWidgetAcc->ProcessValueChanged();
307 }
308 }
309 }
310 }
311
312 void CPDFSDK_Widget::SynchronizeXFAValue() {
313 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
314 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
315 IXFA_DocView* pXFADocView = pDoc->GetXFADocView();
316 if (!pXFADocView)
317 return;
318
319 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
320 if (GetXFAWidgetHandler()) {
321 CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(),
322 GetFormControl());
323 }
324 }
325 }
326
327 void CPDFSDK_Widget::SynchronizeXFAItems() {
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 }
339
340 void CPDFSDK_Widget::SynchronizeXFAValue(IXFA_DocView* pXFADocView,
341 IXFA_Widget* hWidget,
342 CPDF_FormField* pFormField,
343 CPDF_FormControl* pFormControl) {
344 ASSERT(hWidget);
345
346 if (IXFA_WidgetHandler* pXFAWidgetHandler = pXFADocView->GetWidgetHandler()) {
347 ASSERT(pFormControl);
348
349 switch (pFormField->GetFieldType()) {
350 case FIELDTYPE_CHECKBOX: {
351 if (CXFA_WidgetAcc* pWidgetAcc =
352 pXFAWidgetHandler->GetDataAcc(hWidget)) {
353 FX_BOOL bChecked = pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
354
355 pFormField->CheckControl(pFormField->GetControlIndex(pFormControl),
356 bChecked, TRUE);
357 }
358 } break;
359 case FIELDTYPE_RADIOBUTTON: {
360 if (CXFA_WidgetAcc* pWidgetAcc =
361 pXFAWidgetHandler->GetDataAcc(hWidget)) {
362 FX_BOOL bChecked = pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
363
364 pFormField->CheckControl(pFormField->GetControlIndex(pFormControl),
365 bChecked, TRUE);
366 }
367 } break;
368 case FIELDTYPE_TEXTFIELD: {
369 if (CXFA_WidgetAcc* pWidgetAcc =
370 pXFAWidgetHandler->GetDataAcc(hWidget)) {
371 CFX_WideString sValue;
372 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
373 pFormField->SetValue(sValue, TRUE);
374 }
375 } break;
376 case FIELDTYPE_LISTBOX: {
377 pFormField->ClearSelection(FALSE);
378
379 if (CXFA_WidgetAcc* pWidgetAcc =
380 pXFAWidgetHandler->GetDataAcc(hWidget)) {
381 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
382 int nIndex = pWidgetAcc->GetSelectedItem(i);
383
384 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
385 pFormField->SetItemSelection(nIndex, TRUE, TRUE);
386 }
387 }
388 }
389 } break;
390 case FIELDTYPE_COMBOBOX: {
391 pFormField->ClearSelection(FALSE);
392
393 if (CXFA_WidgetAcc* pWidgetAcc =
394 pXFAWidgetHandler->GetDataAcc(hWidget)) {
395 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
396 int nIndex = pWidgetAcc->GetSelectedItem(i);
397
398 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
399 pFormField->SetItemSelection(nIndex, TRUE, TRUE);
400 }
401 }
402
403 CFX_WideString sValue;
404 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
405 pFormField->SetValue(sValue, TRUE);
406 }
407 } break;
408 }
409 }
410 }
411
412 void CPDFSDK_Widget::SynchronizeXFAItems(IXFA_DocView* pXFADocView,
413 IXFA_Widget* hWidget,
414 CPDF_FormField* pFormField,
415 CPDF_FormControl* pFormControl) {
416 ASSERT(hWidget);
417
418 if (IXFA_WidgetHandler* pXFAWidgetHandler = pXFADocView->GetWidgetHandler()) {
419 switch (pFormField->GetFieldType()) {
420 case FIELDTYPE_LISTBOX: {
421 pFormField->ClearSelection(FALSE);
422 pFormField->ClearOptions(TRUE);
423
424 if (CXFA_WidgetAcc* pWidgetAcc =
425 pXFAWidgetHandler->GetDataAcc(hWidget)) {
426 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz;
427 i++) {
428 CFX_WideString swText;
429 pWidgetAcc->GetChoiceListItem(swText, i);
430
431 pFormField->InsertOption(swText, i, TRUE);
432 }
433 }
434 } break;
435 case FIELDTYPE_COMBOBOX: {
436 pFormField->ClearSelection(FALSE);
437 pFormField->ClearOptions(FALSE);
438
439 if (CXFA_WidgetAcc* pWidgetAcc =
440 pXFAWidgetHandler->GetDataAcc(hWidget)) {
441 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz;
442 i++) {
443 CFX_WideString swText;
444 pWidgetAcc->GetChoiceListItem(swText, i);
445
446 pFormField->InsertOption(swText, i, FALSE);
447 }
448 }
449
450 pFormField->SetValue(L"", TRUE);
451 } break;
452 }
453 }
454 }
455 #endif // PDF_ENABLE_XFA
456
457 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
458 CPDF_Annot::AppearanceMode mode) {
459 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictBy("AP");
460 if (!pAP)
461 return FALSE;
462
463 // Choose the right sub-ap
464 const FX_CHAR* ap_entry = "N";
465 if (mode == CPDF_Annot::Down)
466 ap_entry = "D";
467 else if (mode == CPDF_Annot::Rollover)
468 ap_entry = "R";
469 if (!pAP->KeyExist(ap_entry))
470 ap_entry = "N";
471
472 // Get the AP stream or subdirectory
473 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
474 if (!psub)
475 return FALSE;
476
477 int nFieldType = GetFieldType();
478 switch (nFieldType) {
479 case FIELDTYPE_PUSHBUTTON:
480 case FIELDTYPE_COMBOBOX:
481 case FIELDTYPE_LISTBOX:
482 case FIELDTYPE_TEXTFIELD:
483 case FIELDTYPE_SIGNATURE:
484 return psub->IsStream();
485 case FIELDTYPE_CHECKBOX:
486 case FIELDTYPE_RADIOBUTTON:
487 if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) {
488 return pSubDict->GetStreamBy(GetAppState()) != NULL;
489 }
490 return FALSE;
491 }
492 return TRUE;
493 }
494
495 int CPDFSDK_Widget::GetFieldType() const {
496 return GetFormField()->GetFieldType();
497 }
498
499 FX_BOOL CPDFSDK_Widget::IsAppearanceValid() {
500 #ifdef PDF_ENABLE_XFA
501 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
502 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
503 int nDocType = pDoc->GetDocType();
504 if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA)
505 return TRUE;
506 #endif // PDF_ENABLE_XFA
507 return CPDFSDK_BAAnnot::IsAppearanceValid();
508 }
509
510 int CPDFSDK_Widget::GetFieldFlags() const {
511 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
512 CPDF_FormControl* pFormControl =
513 pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict());
514 CPDF_FormField* pFormField = pFormControl->GetField();
515 return pFormField->GetFieldFlags();
516 }
517
518 CFX_ByteString CPDFSDK_Widget::GetSubType() const {
519 int nType = GetFieldType();
520
521 if (nType == FIELDTYPE_SIGNATURE)
522 return BFFT_SIGNATURE;
523 return CPDFSDK_Annot::GetSubType();
524 }
525
526 CPDF_FormField* CPDFSDK_Widget::GetFormField() const {
527 return GetFormControl()->GetField();
528 }
529
530 CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const {
531 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
532 return pPDFInterForm->GetControlByDict(GetAnnotDict());
533 }
534
535 CPDF_FormControl* CPDFSDK_Widget::GetFormControl(
536 CPDF_InterForm* pInterForm,
537 const CPDF_Dictionary* pAnnotDict) {
538 ASSERT(pAnnotDict);
539 return pInterForm->GetControlByDict(pAnnotDict);
540 }
541
542 int CPDFSDK_Widget::GetRotate() const {
543 CPDF_FormControl* pCtrl = GetFormControl();
544 return pCtrl->GetRotation() % 360;
545 }
546
547 #ifdef PDF_ENABLE_XFA
548 CFX_WideString CPDFSDK_Widget::GetName() const {
549 CPDF_FormField* pFormField = GetFormField();
550 return pFormField->GetFullName();
551 }
552 #endif // PDF_ENABLE_XFA
553
554 FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
555 CPDF_FormControl* pFormCtrl = GetFormControl();
556 int iColorType = 0;
557 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType));
558
559 return iColorType != COLORTYPE_TRANSPARENT;
560 }
561
562 FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const {
563 CPDF_FormControl* pFormCtrl = GetFormControl();
564 int iColorType = 0;
565 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBorderColor(iColorType));
566
567 return iColorType != COLORTYPE_TRANSPARENT;
568 }
569
570 FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const {
571 CPDF_FormControl* pFormCtrl = GetFormControl();
572 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
573 if (da.HasColor()) {
574 FX_ARGB argb;
575 int iColorType = COLORTYPE_TRANSPARENT;
576 da.GetColor(argb, iColorType);
577 color = FX_ARGBTOCOLORREF(argb);
578
579 return iColorType != COLORTYPE_TRANSPARENT;
580 }
581
582 return FALSE;
583 }
584
585 FX_FLOAT CPDFSDK_Widget::GetFontSize() const {
586 CPDF_FormControl* pFormCtrl = GetFormControl();
587 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
588 CFX_ByteString csFont = "";
589 FX_FLOAT fFontSize = 0.0f;
590 pDa.GetFont(csFont, fFontSize);
591
592 return fFontSize;
593 }
594
595 int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
596 #ifdef PDF_ENABLE_XFA
597 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
598 if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
599 if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
600 if (nIndex < pWidgetAcc->CountSelectedItems())
601 return pWidgetAcc->GetSelectedItem(nIndex);
602 }
603 }
604 }
605 #endif // PDF_ENABLE_XFA
606 CPDF_FormField* pFormField = GetFormField();
607 return pFormField->GetSelectedIndex(nIndex);
608 }
609
610 #ifdef PDF_ENABLE_XFA
611 CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const {
612 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
613 if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
614 if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
615 CFX_WideString sValue;
616 pWidgetAcc->GetValue(sValue, bDisplay ? XFA_VALUEPICTURE_Display
617 : XFA_VALUEPICTURE_Edit);
618 return sValue;
619 }
620 }
621 }
622 #else
623 CFX_WideString CPDFSDK_Widget::GetValue() const {
624 #endif // PDF_ENABLE_XFA
625 CPDF_FormField* pFormField = GetFormField();
626 return pFormField->GetValue();
627 }
628
629 CFX_WideString CPDFSDK_Widget::GetDefaultValue() const {
630 CPDF_FormField* pFormField = GetFormField();
631 return pFormField->GetDefaultValue();
632 }
633
634 CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
635 CPDF_FormField* pFormField = GetFormField();
636 return pFormField->GetOptionLabel(nIndex);
637 }
638
639 int CPDFSDK_Widget::CountOptions() const {
640 CPDF_FormField* pFormField = GetFormField();
641 return pFormField->CountOptions();
642 }
643
644 FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
645 #ifdef PDF_ENABLE_XFA
646 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
647 if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
648 if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) {
649 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
650 return pWidgetAcc->GetItemState(nIndex);
651
652 return FALSE;
653 }
654 }
655 }
656 #endif // PDF_ENABLE_XFA
657 CPDF_FormField* pFormField = GetFormField();
658 return pFormField->IsItemSelected(nIndex);
659 }
660
661 int CPDFSDK_Widget::GetTopVisibleIndex() const {
662 CPDF_FormField* pFormField = GetFormField();
663 return pFormField->GetTopVisibleIndex();
664 }
665
666 bool CPDFSDK_Widget::IsChecked() const {
667 #ifdef PDF_ENABLE_XFA
668 if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
669 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
670 if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
671 return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
672 }
673 }
674 #endif // PDF_ENABLE_XFA
675 CPDF_FormControl* pFormCtrl = GetFormControl();
676 return pFormCtrl->IsChecked();
677 }
678
679 int CPDFSDK_Widget::GetAlignment() const {
680 CPDF_FormControl* pFormCtrl = GetFormControl();
681 return pFormCtrl->GetControlAlignment();
682 }
683
684 int CPDFSDK_Widget::GetMaxLen() const {
685 CPDF_FormField* pFormField = GetFormField();
686 return pFormField->GetMaxLen();
687 }
688
689 void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) {
690 CPDF_FormControl* pFormCtrl = GetFormControl();
691 CPDF_FormField* pFormField = pFormCtrl->GetField();
692 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
693 bNotify);
694 #ifdef PDF_ENABLE_XFA
695 if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
696 ResetAppearance(TRUE);
697 if (!bNotify)
698 Synchronize(TRUE);
699 #endif // PDF_ENABLE_XFA
700 }
701
702 void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) {
703 CPDF_FormField* pFormField = GetFormField();
704 pFormField->SetValue(sValue, bNotify);
705 #ifdef PDF_ENABLE_XFA
706 if (!bNotify)
707 Synchronize(TRUE);
708 #endif // PDF_ENABLE_XFA
709 }
710
711 void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {}
712 void CPDFSDK_Widget::SetOptionSelection(int index,
713 FX_BOOL bSelected,
714 FX_BOOL bNotify) {
715 CPDF_FormField* pFormField = GetFormField();
716 pFormField->SetItemSelection(index, bSelected, bNotify);
717 #ifdef PDF_ENABLE_XFA
718 if (!bNotify)
719 Synchronize(TRUE);
720 #endif // PDF_ENABLE_XFA
721 }
722
723 void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) {
724 CPDF_FormField* pFormField = GetFormField();
725 pFormField->ClearSelection(bNotify);
726 #ifdef PDF_ENABLE_XFA
727 if (!bNotify)
728 Synchronize(TRUE);
729 #endif // PDF_ENABLE_XFA
730 }
731
732 void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
733
734 void CPDFSDK_Widget::SetAppModified() {
735 m_bAppModified = TRUE;
736 }
737
738 void CPDFSDK_Widget::ClearAppModified() {
739 m_bAppModified = FALSE;
740 }
741
742 FX_BOOL CPDFSDK_Widget::IsAppModified() const {
743 return m_bAppModified;
744 }
745
746 #ifdef PDF_ENABLE_XFA
747 void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) {
748 switch (GetFieldType()) {
749 case FIELDTYPE_TEXTFIELD:
750 case FIELDTYPE_COMBOBOX: {
751 FX_BOOL bFormated = FALSE;
752 CFX_WideString sValue = OnFormat(bFormated);
753 ResetAppearance(bFormated ? sValue : nullptr, TRUE);
754 } break;
755 default:
756 ResetAppearance(nullptr, FALSE);
757 break;
758 }
759 }
760 #endif // PDF_ENABLE_XFA
761
762 void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue,
763 FX_BOOL bValueChanged) {
764 SetAppModified();
765
766 m_nAppAge++;
767 if (m_nAppAge > 999999)
768 m_nAppAge = 0;
769 if (bValueChanged)
770 m_nValueAge++;
771
772 int nFieldType = GetFieldType();
773
774 switch (nFieldType) {
775 case FIELDTYPE_PUSHBUTTON:
776 ResetAppearance_PushButton();
777 break;
778 case FIELDTYPE_CHECKBOX:
779 ResetAppearance_CheckBox();
780 break;
781 case FIELDTYPE_RADIOBUTTON:
782 ResetAppearance_RadioButton();
783 break;
784 case FIELDTYPE_COMBOBOX:
785 ResetAppearance_ComboBox(sValue);
786 break;
787 case FIELDTYPE_LISTBOX:
788 ResetAppearance_ListBox();
789 break;
790 case FIELDTYPE_TEXTFIELD:
791 ResetAppearance_TextField(sValue);
792 break;
793 }
794
795 m_pAnnot->ClearCachedAP();
796 }
797
798 CFX_WideString CPDFSDK_Widget::OnFormat(FX_BOOL& bFormated) {
799 CPDF_FormField* pFormField = GetFormField();
800 ASSERT(pFormField);
801 return m_pInterForm->OnFormat(pFormField, bFormated);
802 }
803
804 void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged) {
805 CPDF_FormField* pFormField = GetFormField();
806 ASSERT(pFormField);
807 m_pInterForm->ResetFieldAppearance(pFormField, NULL, bValueChanged);
808 }
809
810 void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice,
811 const CFX_Matrix* pUser2Device,
812 CPDF_Annot::AppearanceMode mode,
813 const CPDF_RenderOptions* pOptions) {
814 int nFieldType = GetFieldType();
815
816 if ((nFieldType == FIELDTYPE_CHECKBOX ||
817 nFieldType == FIELDTYPE_RADIOBUTTON) &&
818 mode == CPDF_Annot::Normal &&
819 !IsWidgetAppearanceValid(CPDF_Annot::Normal)) {
820 CFX_PathData pathData;
821
822 CFX_FloatRect rcAnnot = GetRect();
823
824 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right,
825 rcAnnot.top);
826
827 CFX_GraphStateData gsd;
828 gsd.m_LineWidth = 0.0f;
829
830 pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA,
831 FXFILL_ALTERNATE);
832 } else {
833 CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
834 }
835 }
836
837 void CPDFSDK_Widget::UpdateField() {
838 CPDF_FormField* pFormField = GetFormField();
839 ASSERT(pFormField);
840 m_pInterForm->UpdateField(pFormField);
841 }
842
843 void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
844 CPDFSDK_PageView* pPageView) {
845 int nFieldType = GetFieldType();
846 if (m_pInterForm->IsNeedHighLight(nFieldType)) {
847 CFX_FloatRect rc = GetRect();
848 FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
849 uint8_t alpha = m_pInterForm->GetHighlightAlpha();
850
851 CFX_FloatRect rcDevice;
852 ASSERT(m_pInterForm->GetDocument());
853 CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();
854 if (!pEnv)
855 return;
856 CFX_Matrix page2device;
857 pPageView->GetCurrentMatrix(page2device);
858 page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom),
859 rcDevice.left, rcDevice.bottom);
860 page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top),
861 rcDevice.right, rcDevice.top);
862
863 rcDevice.Normalize();
864
865 FX_ARGB argb = ArgbEncode((int)alpha, color);
866 FX_RECT rcDev((int)rcDevice.left, (int)rcDevice.top, (int)rcDevice.right,
867 (int)rcDevice.bottom);
868 pDevice->FillRect(&rcDev, argb);
869 }
870 }
871
872 void CPDFSDK_Widget::ResetAppearance_PushButton() {
873 CPDF_FormControl* pControl = GetFormControl();
874 CFX_FloatRect rcWindow = GetRotatedRect();
875 int32_t nLayout = 0;
876 switch (pControl->GetTextPosition()) {
877 case TEXTPOS_ICON:
878 nLayout = PPBL_ICON;
879 break;
880 case TEXTPOS_BELOW:
881 nLayout = PPBL_ICONTOPLABELBOTTOM;
882 break;
883 case TEXTPOS_ABOVE:
884 nLayout = PPBL_LABELTOPICONBOTTOM;
885 break;
886 case TEXTPOS_RIGHT:
887 nLayout = PPBL_ICONLEFTLABELRIGHT;
888 break;
889 case TEXTPOS_LEFT:
890 nLayout = PPBL_LABELLEFTICONRIGHT;
891 break;
892 case TEXTPOS_OVERLAID:
893 nLayout = PPBL_LABELOVERICON;
894 break;
895 default:
896 nLayout = PPBL_LABEL;
897 break;
898 }
899
900 CPWL_Color crBackground, crBorder;
901
902 int iColorType;
903 FX_FLOAT fc[4];
904
905 pControl->GetOriginalBackgroundColor(iColorType, fc);
906 if (iColorType > 0)
907 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
908
909 pControl->GetOriginalBorderColor(iColorType, fc);
910 if (iColorType > 0)
911 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
912
913 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
914 int32_t nBorderStyle = 0;
915 CPWL_Dash dsBorder(3, 0, 0);
916 CPWL_Color crLeftTop, crRightBottom;
917
918 switch (GetBorderStyle()) {
919 case BBS_DASH:
920 nBorderStyle = PBS_DASH;
921 dsBorder = CPWL_Dash(3, 3, 0);
922 break;
923 case BBS_BEVELED:
924 nBorderStyle = PBS_BEVELED;
925 fBorderWidth *= 2;
926 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
927 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
928 break;
929 case BBS_INSET:
930 nBorderStyle = PBS_INSET;
931 fBorderWidth *= 2;
932 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
933 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
934 break;
935 case BBS_UNDERLINE:
936 nBorderStyle = PBS_UNDERLINED;
937 break;
938 default:
939 nBorderStyle = PBS_SOLID;
940 break;
941 }
942
943 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
944
945 CPWL_Color crText(COLORTYPE_GRAY, 0);
946
947 FX_FLOAT fFontSize = 12.0f;
948 CFX_ByteString csNameTag;
949
950 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
951 if (da.HasColor()) {
952 da.GetColor(iColorType, fc);
953 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
954 }
955
956 if (da.HasFont())
957 da.GetFont(csNameTag, fFontSize);
958
959 CFX_WideString csWCaption;
960 CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
961
962 if (pControl->HasMKEntry("CA")) {
963 csNormalCaption = pControl->GetNormalCaption();
964 }
965 if (pControl->HasMKEntry("RC")) {
966 csRolloverCaption = pControl->GetRolloverCaption();
967 }
968 if (pControl->HasMKEntry("AC")) {
969 csDownCaption = pControl->GetDownCaption();
970 }
971
972 CPDF_Stream* pNormalIcon = NULL;
973 CPDF_Stream* pRolloverIcon = NULL;
974 CPDF_Stream* pDownIcon = NULL;
975
976 if (pControl->HasMKEntry("I")) {
977 pNormalIcon = pControl->GetNormalIcon();
978 }
979 if (pControl->HasMKEntry("RI")) {
980 pRolloverIcon = pControl->GetRolloverIcon();
981 }
982 if (pControl->HasMKEntry("IX")) {
983 pDownIcon = pControl->GetDownIcon();
984 }
985
986 if (pNormalIcon) {
987 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) {
988 if (pImageDict->GetStringBy("Name").IsEmpty())
989 pImageDict->SetAtString("Name", "ImgA");
990 }
991 }
992
993 if (pRolloverIcon) {
994 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) {
995 if (pImageDict->GetStringBy("Name").IsEmpty())
996 pImageDict->SetAtString("Name", "ImgB");
997 }
998 }
999
1000 if (pDownIcon) {
1001 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) {
1002 if (pImageDict->GetStringBy("Name").IsEmpty())
1003 pImageDict->SetAtString("Name", "ImgC");
1004 }
1005 }
1006
1007 CPDF_IconFit iconFit = pControl->GetIconFit();
1008
1009 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1010 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1011
1012 CBA_FontMap font_map(this, pEnv->GetSysHandler());
1013 font_map.SetAPType("N");
1014
1015 CFX_ByteString csAP =
1016 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1017 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1018 crLeftTop, crRightBottom, nBorderStyle,
1019 dsBorder) +
1020 CPWL_Utils::GetPushButtonAppStream(
1021 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
1022 pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
1023
1024 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
1025 if (pNormalIcon)
1026 AddImageToAppearance("N", pNormalIcon);
1027
1028 CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
1029 if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) {
1030 if (csRolloverCaption.IsEmpty() && !pRolloverIcon) {
1031 csRolloverCaption = csNormalCaption;
1032 pRolloverIcon = pNormalIcon;
1033 }
1034
1035 font_map.SetAPType("R");
1036
1037 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1038 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1039 crLeftTop, crRightBottom,
1040 nBorderStyle, dsBorder) +
1041 CPWL_Utils::GetPushButtonAppStream(
1042 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
1043 pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize,
1044 nLayout);
1045
1046 WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
1047 if (pRolloverIcon)
1048 AddImageToAppearance("R", pRolloverIcon);
1049
1050 if (csDownCaption.IsEmpty() && !pDownIcon) {
1051 csDownCaption = csNormalCaption;
1052 pDownIcon = pNormalIcon;
1053 }
1054
1055 switch (nBorderStyle) {
1056 case PBS_BEVELED: {
1057 CPWL_Color crTemp = crLeftTop;
1058 crLeftTop = crRightBottom;
1059 crRightBottom = crTemp;
1060 } break;
1061 case PBS_INSET:
1062 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1063 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1064 break;
1065 }
1066
1067 font_map.SetAPType("D");
1068
1069 csAP = CPWL_Utils::GetRectFillAppStream(
1070 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1071 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1072 crLeftTop, crRightBottom,
1073 nBorderStyle, dsBorder) +
1074 CPWL_Utils::GetPushButtonAppStream(
1075 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
1076 pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);
1077
1078 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);
1079 if (pDownIcon)
1080 AddImageToAppearance("D", pDownIcon);
1081 } else {
1082 RemoveAppearance("D");
1083 RemoveAppearance("R");
1084 }
1085 }
1086
1087 void CPDFSDK_Widget::ResetAppearance_CheckBox() {
1088 CPDF_FormControl* pControl = GetFormControl();
1089 CPWL_Color crBackground, crBorder, crText;
1090 int iColorType;
1091 FX_FLOAT fc[4];
1092
1093 pControl->GetOriginalBackgroundColor(iColorType, fc);
1094 if (iColorType > 0)
1095 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1096
1097 pControl->GetOriginalBorderColor(iColorType, fc);
1098 if (iColorType > 0)
1099 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1100
1101 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1102 int32_t nBorderStyle = 0;
1103 CPWL_Dash dsBorder(3, 0, 0);
1104 CPWL_Color crLeftTop, crRightBottom;
1105
1106 switch (GetBorderStyle()) {
1107 case BBS_DASH:
1108 nBorderStyle = PBS_DASH;
1109 dsBorder = CPWL_Dash(3, 3, 0);
1110 break;
1111 case BBS_BEVELED:
1112 nBorderStyle = PBS_BEVELED;
1113 fBorderWidth *= 2;
1114 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1115 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1116 break;
1117 case BBS_INSET:
1118 nBorderStyle = PBS_INSET;
1119 fBorderWidth *= 2;
1120 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1121 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1122 break;
1123 case BBS_UNDERLINE:
1124 nBorderStyle = PBS_UNDERLINED;
1125 break;
1126 default:
1127 nBorderStyle = PBS_SOLID;
1128 break;
1129 }
1130
1131 CFX_FloatRect rcWindow = GetRotatedRect();
1132 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
1133
1134 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1135 if (da.HasColor()) {
1136 da.GetColor(iColorType, fc);
1137 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1138 }
1139
1140 int32_t nStyle = 0;
1141
1142 CFX_WideString csWCaption = pControl->GetNormalCaption();
1143 if (csWCaption.GetLength() > 0) {
1144 switch (csWCaption[0]) {
1145 case L'l':
1146 nStyle = PCS_CIRCLE;
1147 break;
1148 case L'8':
1149 nStyle = PCS_CROSS;
1150 break;
1151 case L'u':
1152 nStyle = PCS_DIAMOND;
1153 break;
1154 case L'n':
1155 nStyle = PCS_SQUARE;
1156 break;
1157 case L'H':
1158 nStyle = PCS_STAR;
1159 break;
1160 default: // L'4'
1161 nStyle = PCS_CHECK;
1162 break;
1163 }
1164 } else {
1165 nStyle = PCS_CHECK;
1166 }
1167
1168 CFX_ByteString csAP_N_ON =
1169 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1170 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1171 crLeftTop, crRightBottom, nBorderStyle,
1172 dsBorder);
1173
1174 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1175
1176 switch (nBorderStyle) {
1177 case PBS_BEVELED: {
1178 CPWL_Color crTemp = crLeftTop;
1179 crLeftTop = crRightBottom;
1180 crRightBottom = crTemp;
1181 } break;
1182 case PBS_INSET:
1183 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1184 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1185 break;
1186 }
1187
1188 CFX_ByteString csAP_D_ON =
1189 CPWL_Utils::GetRectFillAppStream(
1190 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1191 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1192 crLeftTop, crRightBottom, nBorderStyle,
1193 dsBorder);
1194
1195 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1196
1197 csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1198 csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1199
1200 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1201 pControl->GetCheckedAPState());
1202 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1203
1204 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1205 pControl->GetCheckedAPState());
1206 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1207
1208 CFX_ByteString csAS = GetAppState();
1209 if (csAS.IsEmpty())
1210 SetAppState("Off");
1211 }
1212
1213 void CPDFSDK_Widget::ResetAppearance_RadioButton() {
1214 CPDF_FormControl* pControl = GetFormControl();
1215 CPWL_Color crBackground, crBorder, crText;
1216 int iColorType;
1217 FX_FLOAT fc[4];
1218
1219 pControl->GetOriginalBackgroundColor(iColorType, fc);
1220 if (iColorType > 0)
1221 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1222
1223 pControl->GetOriginalBorderColor(iColorType, fc);
1224 if (iColorType > 0)
1225 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1226
1227 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1228 int32_t nBorderStyle = 0;
1229 CPWL_Dash dsBorder(3, 0, 0);
1230 CPWL_Color crLeftTop, crRightBottom;
1231
1232 switch (GetBorderStyle()) {
1233 case BBS_DASH:
1234 nBorderStyle = PBS_DASH;
1235 dsBorder = CPWL_Dash(3, 3, 0);
1236 break;
1237 case BBS_BEVELED:
1238 nBorderStyle = PBS_BEVELED;
1239 fBorderWidth *= 2;
1240 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1241 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1242 break;
1243 case BBS_INSET:
1244 nBorderStyle = PBS_INSET;
1245 fBorderWidth *= 2;
1246 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1247 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1248 break;
1249 case BBS_UNDERLINE:
1250 nBorderStyle = PBS_UNDERLINED;
1251 break;
1252 default:
1253 nBorderStyle = PBS_SOLID;
1254 break;
1255 }
1256
1257 CFX_FloatRect rcWindow = GetRotatedRect();
1258 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
1259
1260 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1261 if (da.HasColor()) {
1262 da.GetColor(iColorType, fc);
1263 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1264 }
1265
1266 int32_t nStyle = 0;
1267
1268 CFX_WideString csWCaption = pControl->GetNormalCaption();
1269 if (csWCaption.GetLength() > 0) {
1270 switch (csWCaption[0]) {
1271 default: // L'l':
1272 nStyle = PCS_CIRCLE;
1273 break;
1274 case L'8':
1275 nStyle = PCS_CROSS;
1276 break;
1277 case L'u':
1278 nStyle = PCS_DIAMOND;
1279 break;
1280 case L'n':
1281 nStyle = PCS_SQUARE;
1282 break;
1283 case L'H':
1284 nStyle = PCS_STAR;
1285 break;
1286 case L'4':
1287 nStyle = PCS_CHECK;
1288 break;
1289 }
1290 } else {
1291 nStyle = PCS_CIRCLE;
1292 }
1293
1294 CFX_ByteString csAP_N_ON;
1295
1296 CFX_FloatRect rcCenter =
1297 CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);
1298
1299 if (nStyle == PCS_CIRCLE) {
1300 if (nBorderStyle == PBS_BEVELED) {
1301 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1302 crRightBottom = CPWL_Utils::SubstractColor(crBackground, 0.25f);
1303 } else if (nBorderStyle == PBS_INSET) {
1304 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f);
1305 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f);
1306 }
1307
1308 csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) +
1309 CPWL_Utils::GetCircleBorderAppStream(
1310 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1311 nBorderStyle, dsBorder);
1312 } else {
1313 csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1314 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1315 crLeftTop, crRightBottom,
1316 nBorderStyle, dsBorder);
1317 }
1318
1319 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1320
1321 switch (nBorderStyle) {
1322 case PBS_BEVELED: {
1323 CPWL_Color crTemp = crLeftTop;
1324 crLeftTop = crRightBottom;
1325 crRightBottom = crTemp;
1326 } break;
1327 case PBS_INSET:
1328 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1329 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1330 break;
1331 }
1332
1333 CFX_ByteString csAP_D_ON;
1334
1335 if (nStyle == PCS_CIRCLE) {
1336 CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground, 0.25f);
1337 if (nBorderStyle == PBS_BEVELED) {
1338 crLeftTop = CPWL_Utils::SubstractColor(crBackground, 0.25f);
1339 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1340 crBK = crBackground;
1341 } else if (nBorderStyle == PBS_INSET) {
1342 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1343 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1344 }
1345
1346 csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) +
1347 CPWL_Utils::GetCircleBorderAppStream(
1348 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1349 nBorderStyle, dsBorder);
1350 } else {
1351 csAP_D_ON = CPWL_Utils::GetRectFillAppStream(
1352 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1353 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1354 crLeftTop, crRightBottom,
1355 nBorderStyle, dsBorder);
1356 }
1357
1358 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1359
1360 csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1361 csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1362
1363 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1364 pControl->GetCheckedAPState());
1365 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1366
1367 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1368 pControl->GetCheckedAPState());
1369 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1370
1371 CFX_ByteString csAS = GetAppState();
1372 if (csAS.IsEmpty())
1373 SetAppState("Off");
1374 }
1375
1376 void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) {
1377 CPDF_FormControl* pControl = GetFormControl();
1378 CPDF_FormField* pField = pControl->GetField();
1379 CFX_ByteTextBuf sBody, sLines;
1380
1381 CFX_FloatRect rcClient = GetClientRect();
1382 CFX_FloatRect rcButton = rcClient;
1383 rcButton.left = rcButton.right - 13;
1384 rcButton.Normalize();
1385
1386 if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) {
1387 pEdit->EnableRefresh(FALSE);
1388
1389 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1390 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1391 CBA_FontMap font_map(this, pEnv->GetSysHandler());
1392 pEdit->SetFontMap(&font_map);
1393
1394 CFX_FloatRect rcEdit = rcClient;
1395 rcEdit.right = rcButton.left;
1396 rcEdit.Normalize();
1397
1398 pEdit->SetPlateRect(rcEdit);
1399 pEdit->SetAlignmentV(1);
1400
1401 FX_FLOAT fFontSize = GetFontSize();
1402 if (IsFloatZero(fFontSize))
1403 pEdit->SetAutoFontSize(TRUE);
1404 else
1405 pEdit->SetFontSize(fFontSize);
1406
1407 pEdit->Initialize();
1408
1409 if (sValue) {
1410 pEdit->SetText(sValue);
1411 } else {
1412 int32_t nCurSel = pField->GetSelectedIndex(0);
1413
1414 if (nCurSel < 0)
1415 pEdit->SetText(pField->GetValue().c_str());
1416 else
1417 pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str());
1418 }
1419
1420 CFX_FloatRect rcContent = pEdit->GetContentRect();
1421
1422 CFX_ByteString sEdit =
1423 CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f));
1424 if (sEdit.GetLength() > 0) {
1425 sBody << "/Tx BMC\n"
1426 << "q\n";
1427 if (rcContent.Width() > rcEdit.Width() ||
1428 rcContent.Height() > rcEdit.Height()) {
1429 sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width()
1430 << " " << rcEdit.Height() << " re\nW\nn\n";
1431 }
1432
1433 CPWL_Color crText = GetTextPWLColor();
1434 sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit
1435 << "ET\n"
1436 << "Q\nEMC\n";
1437 }
1438
1439 IFX_Edit::DelEdit(pEdit);
1440 }
1441
1442 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
1443
1444 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
1445 sLines.GetByteString() + sBody.GetByteString();
1446
1447 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1448 }
1449
1450 void CPDFSDK_Widget::ResetAppearance_ListBox() {
1451 CPDF_FormControl* pControl = GetFormControl();
1452 CPDF_FormField* pField = pControl->GetField();
1453 CFX_FloatRect rcClient = GetClientRect();
1454 CFX_ByteTextBuf sBody, sLines;
1455
1456 if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) {
1457 pEdit->EnableRefresh(FALSE);
1458
1459 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1460 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1461
1462 CBA_FontMap font_map(this, pEnv->GetSysHandler());
1463 pEdit->SetFontMap(&font_map);
1464
1465 pEdit->SetPlateRect(
1466 CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f));
1467
1468 FX_FLOAT fFontSize = GetFontSize();
1469
1470 if (IsFloatZero(fFontSize))
1471 pEdit->SetFontSize(12.0f);
1472 else
1473 pEdit->SetFontSize(fFontSize);
1474
1475 pEdit->Initialize();
1476
1477 CFX_ByteTextBuf sList;
1478 FX_FLOAT fy = rcClient.top;
1479
1480 int32_t nTop = pField->GetTopVisibleIndex();
1481 int32_t nCount = pField->CountOptions();
1482 int32_t nSelCount = pField->CountSelectedItems();
1483
1484 for (int32_t i = nTop; i < nCount; i++) {
1485 FX_BOOL bSelected = FALSE;
1486 for (int32_t j = 0; j < nSelCount; j++) {
1487 if (pField->GetSelectedIndex(j) == i) {
1488 bSelected = TRUE;
1489 break;
1490 }
1491 }
1492
1493 pEdit->SetText(pField->GetOptionLabel(i).c_str());
1494
1495 CFX_FloatRect rcContent = pEdit->GetContentRect();
1496 FX_FLOAT fItemHeight = rcContent.Height();
1497
1498 if (bSelected) {
1499 CFX_FloatRect rcItem =
1500 CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy);
1501 sList << "q\n" << CPWL_Utils::GetColorAppStream(
1502 CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f,
1503 113.0f / 255.0f),
1504 TRUE)
1505 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width()
1506 << " " << rcItem.Height() << " re f\n"
1507 << "Q\n";
1508
1509 sList << "BT\n" << CPWL_Utils::GetColorAppStream(
1510 CPWL_Color(COLORTYPE_GRAY, 1), TRUE)
1511 << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy))
1512 << "ET\n";
1513 } else {
1514 CPWL_Color crText = GetTextPWLColor();
1515 sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText, TRUE)
1516 << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy))
1517 << "ET\n";
1518 }
1519
1520 fy -= fItemHeight;
1521 }
1522
1523 if (sList.GetSize() > 0) {
1524 sBody << "/Tx BMC\n"
1525 << "q\n" << rcClient.left << " " << rcClient.bottom << " "
1526 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1527 sBody << sList << "Q\nEMC\n";
1528 }
1529
1530 IFX_Edit::DelEdit(pEdit);
1531 }
1532
1533 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
1534 sLines.GetByteString() + sBody.GetByteString();
1535
1536 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1537 }
1538
1539 void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) {
1540 CPDF_FormControl* pControl = GetFormControl();
1541 CPDF_FormField* pField = pControl->GetField();
1542 CFX_ByteTextBuf sBody, sLines;
1543
1544 if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) {
1545 pEdit->EnableRefresh(FALSE);
1546
1547 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1548 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1549
1550 CBA_FontMap font_map(this, pEnv->GetSysHandler());
1551 pEdit->SetFontMap(&font_map);
1552
1553 CFX_FloatRect rcClient = GetClientRect();
1554 pEdit->SetPlateRect(rcClient);
1555 pEdit->SetAlignmentH(pControl->GetControlAlignment());
1556
1557 FX_DWORD dwFieldFlags = pField->GetFieldFlags();
1558 FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1;
1559
1560 if (bMultiLine) {
1561 pEdit->SetMultiLine(TRUE);
1562 pEdit->SetAutoReturn(TRUE);
1563 } else {
1564 pEdit->SetAlignmentV(1);
1565 }
1566
1567 FX_WORD subWord = 0;
1568 if ((dwFieldFlags >> 13) & 1) {
1569 subWord = '*';
1570 pEdit->SetPasswordChar(subWord);
1571 }
1572
1573 int nMaxLen = pField->GetMaxLen();
1574 FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
1575 FX_FLOAT fFontSize = GetFontSize();
1576
1577 #ifdef PDF_ENABLE_XFA
1578 CFX_WideString sValueTmp;
1579 if (!sValue && GetMixXFAWidget()) {
1580 sValueTmp = GetValue(TRUE);
1581 sValue = sValueTmp;
1582 }
1583 #endif // PDF_ENABLE_XFA
1584
1585 if (nMaxLen > 0) {
1586 if (bCharArray) {
1587 pEdit->SetCharArray(nMaxLen);
1588
1589 if (IsFloatZero(fFontSize)) {
1590 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(
1591 font_map.GetPDFFont(0), rcClient, nMaxLen);
1592 }
1593 } else {
1594 if (sValue)
1595 nMaxLen = wcslen((const wchar_t*)sValue);
1596 pEdit->SetLimitChar(nMaxLen);
1597 }
1598 }
1599
1600 if (IsFloatZero(fFontSize))
1601 pEdit->SetAutoFontSize(TRUE);
1602 else
1603 pEdit->SetFontSize(fFontSize);
1604
1605 pEdit->Initialize();
1606
1607 if (sValue)
1608 pEdit->SetText(sValue);
1609 else
1610 pEdit->SetText(pField->GetValue().c_str());
1611
1612 CFX_FloatRect rcContent = pEdit->GetContentRect();
1613
1614 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(
1615 pEdit, CFX_FloatPoint(0.0f, 0.0f), NULL, !bCharArray, subWord);
1616
1617 if (sEdit.GetLength() > 0) {
1618 sBody << "/Tx BMC\n"
1619 << "q\n";
1620 if (rcContent.Width() > rcClient.Width() ||
1621 rcContent.Height() > rcClient.Height()) {
1622 sBody << rcClient.left << " " << rcClient.bottom << " "
1623 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1624 }
1625 CPWL_Color crText = GetTextPWLColor();
1626 sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit
1627 << "ET\n"
1628 << "Q\nEMC\n";
1629 }
1630
1631 if (bCharArray) {
1632 switch (GetBorderStyle()) {
1633 case BBS_SOLID: {
1634 CFX_ByteString sColor =
1635 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE);
1636 if (sColor.GetLength() > 0) {
1637 sLines << "q\n" << GetBorderWidth() << " w\n"
1638 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE)
1639 << " 2 J 0 j\n";
1640
1641 for (int32_t i = 1; i < nMaxLen; i++) {
1642 sLines << rcClient.left +
1643 ((rcClient.right - rcClient.left) / nMaxLen) * i
1644 << " " << rcClient.bottom << " m\n"
1645 << rcClient.left +
1646 ((rcClient.right - rcClient.left) / nMaxLen) * i
1647 << " " << rcClient.top << " l S\n";
1648 }
1649
1650 sLines << "Q\n";
1651 }
1652 } break;
1653 case BBS_DASH: {
1654 CFX_ByteString sColor =
1655 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE);
1656 if (sColor.GetLength() > 0) {
1657 CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
1658
1659 sLines << "q\n" << GetBorderWidth() << " w\n"
1660 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE)
1661 << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] "
1662 << dsBorder.nPhase << " d\n";
1663
1664 for (int32_t i = 1; i < nMaxLen; i++) {
1665 sLines << rcClient.left +
1666 ((rcClient.right - rcClient.left) / nMaxLen) * i
1667 << " " << rcClient.bottom << " m\n"
1668 << rcClient.left +
1669 ((rcClient.right - rcClient.left) / nMaxLen) * i
1670 << " " << rcClient.top << " l S\n";
1671 }
1672
1673 sLines << "Q\n";
1674 }
1675 } break;
1676 }
1677 }
1678
1679 IFX_Edit::DelEdit(pEdit);
1680 }
1681
1682 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
1683 sLines.GetByteString() + sBody.GetByteString();
1684 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1685 }
1686
1687 CFX_FloatRect CPDFSDK_Widget::GetClientRect() const {
1688 CFX_FloatRect rcWindow = GetRotatedRect();
1689 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1690 switch (GetBorderStyle()) {
1691 case BBS_BEVELED:
1692 case BBS_INSET:
1693 fBorderWidth *= 2.0f;
1694 break;
1695 }
1696
1697 return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
1698 }
1699
1700 CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
1701 CFX_FloatRect rectAnnot = GetRect();
1702 FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
1703 FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
1704
1705 CPDF_FormControl* pControl = GetFormControl();
1706 CFX_FloatRect rcPDFWindow;
1707 switch (abs(pControl->GetRotation() % 360)) {
1708 case 0:
1709 case 180:
1710 default:
1711 rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight);
1712 break;
1713 case 90:
1714 case 270:
1715 rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth);
1716 break;
1717 }
1718
1719 return rcPDFWindow;
1720 }
1721
1722 CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const {
1723 CPWL_Color crBackground = GetFillPWLColor();
1724 if (crBackground.nColorType != COLORTYPE_TRANSPARENT) {
1725 return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
1726 }
1727 return "";
1728 }
1729
1730 CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const {
1731 CFX_FloatRect rcWindow = GetRotatedRect();
1732 CPWL_Color crBorder = GetBorderPWLColor();
1733 CPWL_Color crBackground = GetFillPWLColor();
1734 CPWL_Color crLeftTop, crRightBottom;
1735
1736 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1737 int32_t nBorderStyle = 0;
1738 CPWL_Dash dsBorder(3, 0, 0);
1739
1740 switch (GetBorderStyle()) {
1741 case BBS_DASH:
1742 nBorderStyle = PBS_DASH;
1743 dsBorder = CPWL_Dash(3, 3, 0);
1744 break;
1745 case BBS_BEVELED:
1746 nBorderStyle = PBS_BEVELED;
1747 fBorderWidth *= 2;
1748 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1749 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1750 break;
1751 case BBS_INSET:
1752 nBorderStyle = PBS_INSET;
1753 fBorderWidth *= 2;
1754 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1755 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1756 break;
1757 case BBS_UNDERLINE:
1758 nBorderStyle = PBS_UNDERLINED;
1759 break;
1760 default:
1761 nBorderStyle = PBS_SOLID;
1762 break;
1763 }
1764
1765 return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1766 crLeftTop, crRightBottom, nBorderStyle,
1767 dsBorder);
1768 }
1769
1770 CFX_Matrix CPDFSDK_Widget::GetMatrix() const {
1771 CFX_Matrix mt;
1772 CPDF_FormControl* pControl = GetFormControl();
1773 CFX_FloatRect rcAnnot = GetRect();
1774 FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left;
1775 FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom;
1776
1777 switch (abs(pControl->GetRotation() % 360)) {
1778 case 0:
1779 default:
1780 mt = CFX_Matrix(1, 0, 0, 1, 0, 0);
1781 break;
1782 case 90:
1783 mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0);
1784 break;
1785 case 180:
1786 mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight);
1787 break;
1788 case 270:
1789 mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight);
1790 break;
1791 }
1792
1793 return mt;
1794 }
1795
1796 CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const {
1797 CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);
1798
1799 CPDF_FormControl* pFormCtrl = GetFormControl();
1800 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
1801 if (da.HasColor()) {
1802 int32_t iColorType;
1803 FX_FLOAT fc[4];
1804 da.GetColor(iColorType, fc);
1805 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1806 }
1807
1808 return crText;
1809 }
1810
1811 CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const {
1812 CPWL_Color crBorder;
1813
1814 CPDF_FormControl* pFormCtrl = GetFormControl();
1815 int32_t iColorType;
1816 FX_FLOAT fc[4];
1817 pFormCtrl->GetOriginalBorderColor(iColorType, fc);
1818 if (iColorType > 0)
1819 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1820
1821 return crBorder;
1822 }
1823
1824 CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const {
1825 CPWL_Color crFill;
1826
1827 CPDF_FormControl* pFormCtrl = GetFormControl();
1828 int32_t iColorType;
1829 FX_FLOAT fc[4];
1830 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
1831 if (iColorType > 0)
1832 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1833
1834 return crFill;
1835 }
1836
1837 void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
1838 CPDF_Stream* pImage) {
1839 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
1840 ASSERT(pDoc);
1841
1842 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP");
1843 CPDF_Stream* pStream = pAPDict->GetStreamBy(sAPType);
1844 CPDF_Dictionary* pStreamDict = pStream->GetDict();
1845 CFX_ByteString sImageAlias = "IMG";
1846
1847 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) {
1848 sImageAlias = pImageDict->GetStringBy("Name");
1849 if (sImageAlias.IsEmpty())
1850 sImageAlias = "IMG";
1851 }
1852
1853 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources");
1854 if (!pStreamResList) {
1855 pStreamResList = new CPDF_Dictionary();
1856 pStreamDict->SetAt("Resources", pStreamResList);
1857 }
1858
1859 if (pStreamResList) {
1860 CPDF_Dictionary* pXObject = new CPDF_Dictionary;
1861 pXObject->SetAtReference(sImageAlias, pDoc, pImage);
1862 pStreamResList->SetAt("XObject", pXObject);
1863 }
1864 }
1865
1866 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) {
1867 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP")) {
1868 pAPDict->RemoveAt(sAPType);
1869 }
1870 }
1871
1872 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
1873 PDFSDK_FieldAction& data,
1874 CPDFSDK_PageView* pPageView) {
1875 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
1876 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
1877
1878 #ifdef PDF_ENABLE_XFA
1879 CPDFXFA_Document* pDoc = pDocument->GetXFADocument();
1880 if (IXFA_Widget* hWidget = GetMixXFAWidget()) {
1881 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
1882
1883 if (eEventType != XFA_EVENT_Unknown) {
1884 if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
1885 CXFA_EventParam param;
1886 param.m_eType = eEventType;
1887 param.m_wsChange = data.sChange;
1888 param.m_iCommitKey = data.nCommitKey;
1889 param.m_bShift = data.bShift;
1890 param.m_iSelStart = data.nSelStart;
1891 param.m_iSelEnd = data.nSelEnd;
1892 param.m_wsFullText = data.sValue;
1893 param.m_bKeyDown = data.bKeyDown;
1894 param.m_bModifier = data.bModifier;
1895 param.m_wsNewText = data.sValue;
1896 if (data.nSelEnd > data.nSelStart)
1897 param.m_wsNewText.Delete(data.nSelStart,
1898 data.nSelEnd - data.nSelStart);
1899 for (int i = data.sChange.GetLength() - 1; i >= 0; i--)
1900 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
1901 param.m_wsPrevText = data.sValue;
1902
1903 CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
1904 param.m_pTarget = pAcc;
1905 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
1906
1907 if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) {
1908 pDocView->UpdateDocView();
1909 }
1910
1911 if (nRet == XFA_EVENTERROR_Sucess)
1912 return TRUE;
1913 }
1914 }
1915 }
1916 #endif // PDF_ENABLE_XFA
1917
1918 CPDF_Action action = GetAAction(type);
1919 if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) {
1920 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
1921 return pActionHandler->DoAction_Field(action, type, pDocument,
1922 GetFormField(), data);
1923 }
1924 return FALSE;
1925 }
1926
1927 CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) {
1928 switch (eAAT) {
1929 case CPDF_AAction::CursorEnter:
1930 case CPDF_AAction::CursorExit:
1931 case CPDF_AAction::ButtonDown:
1932 case CPDF_AAction::ButtonUp:
1933 case CPDF_AAction::GetFocus:
1934 case CPDF_AAction::LoseFocus:
1935 case CPDF_AAction::PageOpen:
1936 case CPDF_AAction::PageClose:
1937 case CPDF_AAction::PageVisible:
1938 case CPDF_AAction::PageInvisible:
1939 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1940
1941 case CPDF_AAction::KeyStroke:
1942 case CPDF_AAction::Format:
1943 case CPDF_AAction::Validate:
1944 case CPDF_AAction::Calculate: {
1945 CPDF_FormField* pField = GetFormField();
1946 if (pField->GetAdditionalAction().GetDict())
1947 return pField->GetAdditionalAction().GetAction(eAAT);
1948 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1949 }
1950 default:
1951 break;
1952 }
1953
1954 return CPDF_Action();
1955 }
1956
1957 CFX_WideString CPDFSDK_Widget::GetAlternateName() const {
1958 CPDF_FormField* pFormField = GetFormField();
1959 return pFormField->GetAlternateName();
1960 }
1961
1962 int32_t CPDFSDK_Widget::GetAppearanceAge() const {
1963 return m_nAppAge;
1964 }
1965
1966 int32_t CPDFSDK_Widget::GetValueAge() const {
1967 return m_nValueAge;
1968 }
1969
1970 FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) {
1971 CPDF_Annot* pAnnot = GetPDFAnnot();
1972 CFX_FloatRect annotRect;
1973 pAnnot->GetRect(annotRect);
1974 if (annotRect.Contains(pageX, pageY)) {
1975 if (!IsVisible())
1976 return FALSE;
1977
1978 int nFieldFlags = GetFieldFlags();
1979 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
1980 return FALSE;
1981
1982 return TRUE;
1983 }
1984 return FALSE;
1985 }
1986
1987 #ifdef PDF_ENABLE_XFA
1988 CPDFSDK_XFAWidget::CPDFSDK_XFAWidget(IXFA_Widget* pAnnot,
1989 CPDFSDK_PageView* pPageView,
1990 CPDFSDK_InterForm* pInterForm)
1991 : CPDFSDK_Annot(pPageView), m_pInterForm(pInterForm), m_hXFAWidget(pAnnot) {
1992 }
1993
1994 FX_BOOL CPDFSDK_XFAWidget::IsXFAField() {
1995 return TRUE;
1996 }
1997
1998 CFX_ByteString CPDFSDK_XFAWidget::GetType() const {
1999 return FSDK_XFAWIDGET_TYPENAME;
2000 }
2001
2002 CFX_FloatRect CPDFSDK_XFAWidget::GetRect() const {
2003 CPDFSDK_PageView* pPageView = GetPageView();
2004 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
2005 CPDFXFA_Document* pDoc = pDocument->GetXFADocument();
2006 IXFA_DocView* pDocView = pDoc->GetXFADocView();
2007 IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
2008
2009 CFX_RectF rcBBox;
2010 pWidgetHandler->GetRect(GetXFAWidget(), rcBBox);
2011
2012 return CFX_FloatRect(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
2013 rcBBox.top + rcBBox.height);
2014 }
2015 #endif // PDF_ENABLE_XFA
2016
2017 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)
2018 : m_pDocument(pDocument),
2019 m_pInterForm(NULL),
2020 #ifdef PDF_ENABLE_XFA
2021 m_bXfaCalculate(TRUE),
2022 m_bXfaValidationsEnabled(TRUE),
2023 #endif // PDF_ENABLE_XFA
2024 m_bCalculate(TRUE),
2025 m_bBusy(FALSE) {
2026 m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE);
2027 m_pInterForm->SetFormNotify(this);
2028
2029 for (int i = 0; i < kNumFieldTypes; ++i)
2030 m_bNeedHightlight[i] = FALSE;
2031 m_iHighlightAlpha = 0;
2032 }
2033
2034 CPDFSDK_InterForm::~CPDFSDK_InterForm() {
2035 delete m_pInterForm;
2036 m_pInterForm = nullptr;
2037 m_Map.clear();
2038 #ifdef PDF_ENABLE_XFA
2039 m_XFAMap.RemoveAll();
2040 #endif // PDF_ENABLE_XFA
2041 }
2042
2043 FX_BOOL CPDFSDK_InterForm::HighlightWidgets() {
2044 return FALSE;
2045 }
2046
2047 CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget,
2048 FX_BOOL bNext) const {
2049 std::unique_ptr<CBA_AnnotIterator> pIterator(
2050 new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", ""));
2051
2052 if (bNext) {
2053 return (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget);
2054 }
2055 return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);
2056 }
2057
2058 CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const {
2059 if (!pControl || !m_pInterForm)
2060 return nullptr;
2061
2062 CPDFSDK_Widget* pWidget = nullptr;
2063 const auto it = m_Map.find(pControl);
2064 if (it != m_Map.end())
2065 pWidget = it->second;
2066
2067 if (pWidget)
2068 return pWidget;
2069
2070 CPDF_Dictionary* pControlDict = pControl->GetWidget();
2071 CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
2072 CPDFSDK_PageView* pPage = nullptr;
2073
2074 if (CPDF_Dictionary* pPageDict = pControlDict->GetDictBy("P")) {
2075 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
2076 if (nPageIndex >= 0) {
2077 pPage = m_pDocument->GetPageView(nPageIndex);
2078 }
2079 }
2080
2081 if (!pPage) {
2082 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);
2083 if (nPageIndex >= 0) {
2084 pPage = m_pDocument->GetPageView(nPageIndex);
2085 }
2086 }
2087
2088 if (!pPage)
2089 return nullptr;
2090 return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
2091 }
2092
2093 void CPDFSDK_InterForm::GetWidgets(
2094 const CFX_WideString& sFieldName,
2095 std::vector<CPDFSDK_Widget*>* widgets) const {
2096 for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; ++i) {
2097 CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName);
2098 ASSERT(pFormField);
2099 GetWidgets(pFormField, widgets);
2100 }
2101 }
2102
2103 void CPDFSDK_InterForm::GetWidgets(
2104 CPDF_FormField* pField,
2105 std::vector<CPDFSDK_Widget*>* widgets) const {
2106 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) {
2107 CPDF_FormControl* pFormCtrl = pField->GetControl(i);
2108 ASSERT(pFormCtrl);
2109 CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);
2110 if (pWidget)
2111 widgets->push_back(pWidget);
2112 }
2113 }
2114
2115 int CPDFSDK_InterForm::GetPageIndexByAnnotDict(
2116 CPDF_Document* pDocument,
2117 CPDF_Dictionary* pAnnotDict) const {
2118 ASSERT(pAnnotDict);
2119
2120 for (int i = 0, sz = pDocument->GetPageCount(); i < sz; i++) {
2121 if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i)) {
2122 if (CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots")) {
2123 for (int j = 0, jsz = pAnnots->GetCount(); j < jsz; j++) {
2124 CPDF_Object* pDict = pAnnots->GetElementValue(j);
2125 if (pAnnotDict == pDict) {
2126 return i;
2127 }
2128 }
2129 }
2130 }
2131 }
2132
2133 return -1;
2134 }
2135
2136 void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl,
2137 CPDFSDK_Widget* pWidget) {
2138 m_Map[pControl] = pWidget;
2139 }
2140
2141 void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl) {
2142 m_Map.erase(pControl);
2143 }
2144
2145 void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled) {
2146 m_bCalculate = bEnabled;
2147 }
2148
2149 FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const {
2150 return m_bCalculate;
2151 }
2152
2153 #ifdef PDF_ENABLE_XFA
2154 void CPDFSDK_InterForm::AddXFAMap(IXFA_Widget* hWidget,
2155 CPDFSDK_XFAWidget* pWidget) {
2156 m_XFAMap.SetAt(hWidget, pWidget);
2157 }
2158
2159 void CPDFSDK_InterForm::RemoveXFAMap(IXFA_Widget* hWidget) {
2160 m_XFAMap.RemoveKey(hWidget);
2161 }
2162
2163 CPDFSDK_XFAWidget* CPDFSDK_InterForm::GetXFAWidget(IXFA_Widget* hWidget) {
2164 CPDFSDK_XFAWidget* pWidget = NULL;
2165 m_XFAMap.Lookup(hWidget, pWidget);
2166
2167 return pWidget;
2168 }
2169
2170 void CPDFSDK_InterForm::XfaEnableCalculate(FX_BOOL bEnabled) {
2171 m_bXfaCalculate = bEnabled;
2172 }
2173 FX_BOOL CPDFSDK_InterForm::IsXfaCalculateEnabled() const {
2174 return m_bXfaCalculate;
2175 }
2176
2177 FX_BOOL CPDFSDK_InterForm::IsXfaValidationsEnabled() {
2178 return m_bXfaValidationsEnabled;
2179 }
2180 void CPDFSDK_InterForm::XfaSetValidationsEnabled(FX_BOOL bEnabled) {
2181 m_bXfaValidationsEnabled = bEnabled;
2182 }
2183 #endif // PDF_ENABLE_XFA
2184
2185 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
2186 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2187 ASSERT(pEnv);
2188 if (!pEnv->IsJSInitiated())
2189 return;
2190
2191 if (m_bBusy)
2192 return;
2193
2194 m_bBusy = TRUE;
2195
2196 if (IsCalculateEnabled()) {
2197 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
2198 pRuntime->SetReaderDocument(m_pDocument);
2199
2200 int nSize = m_pInterForm->CountFieldsInCalculationOrder();
2201 for (int i = 0; i < nSize; i++) {
2202 if (CPDF_FormField* pField =
2203 m_pInterForm->GetFieldInCalculationOrder(i)) {
2204 int nType = pField->GetFieldType();
2205 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
2206 CPDF_AAction aAction = pField->GetAdditionalAction();
2207 if (aAction.GetDict() &&
2208 aAction.ActionExist(CPDF_AAction::Calculate)) {
2209 CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate);
2210 if (action.GetDict()) {
2211 CFX_WideString csJS = action.GetJavaScript();
2212 if (!csJS.IsEmpty()) {
2213 IJS_Context* pContext = pRuntime->NewContext();
2214 CFX_WideString sOldValue = pField->GetValue();
2215 CFX_WideString sValue = sOldValue;
2216 FX_BOOL bRC = TRUE;
2217 pContext->OnField_Calculate(pFormField, pField, sValue, bRC);
2218
2219 CFX_WideString sInfo;
2220 FX_BOOL bRet = pContext->RunScript(csJS, &sInfo);
2221 pRuntime->ReleaseContext(pContext);
2222
2223 if (bRet) {
2224 if (bRC) {
2225 if (sValue.Compare(sOldValue) != 0)
2226 pField->SetValue(sValue, TRUE);
2227 }
2228 }
2229 }
2230 }
2231 }
2232 }
2233 }
2234 }
2235 }
2236
2237 m_bBusy = FALSE;
2238 }
2239
2240 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField,
2241 FX_BOOL& bFormated) {
2242 CFX_WideString sValue = pFormField->GetValue();
2243 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2244 ASSERT(pEnv);
2245 if (!pEnv->IsJSInitiated()) {
2246 bFormated = FALSE;
2247 return sValue;
2248 }
2249
2250 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
2251 pRuntime->SetReaderDocument(m_pDocument);
2252
2253 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX) {
2254 if (pFormField->CountSelectedItems() > 0) {
2255 int index = pFormField->GetSelectedIndex(0);
2256 if (index >= 0)
2257 sValue = pFormField->GetOptionLabel(index);
2258 }
2259 }
2260
2261 bFormated = FALSE;
2262
2263 CPDF_AAction aAction = pFormField->GetAdditionalAction();
2264 if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) {
2265 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);
2266 if (action.GetDict()) {
2267 CFX_WideString script = action.GetJavaScript();
2268 if (!script.IsEmpty()) {
2269 CFX_WideString Value = sValue;
2270
2271 IJS_Context* pContext = pRuntime->NewContext();
2272 pContext->OnField_Format(pFormField, Value, TRUE);
2273
2274 CFX_WideString sInfo;
2275 FX_BOOL bRet = pContext->RunScript(script, &sInfo);
2276 pRuntime->ReleaseContext(pContext);
2277
2278 if (bRet) {
2279 sValue = Value;
2280 bFormated = TRUE;
2281 }
2282 }
2283 }
2284 }
2285
2286 return sValue;
2287 }
2288
2289 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField,
2290 const FX_WCHAR* sValue,
2291 FX_BOOL bValueChanged) {
2292 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2293 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
2294 ASSERT(pFormCtrl);
2295 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
2296 pWidget->ResetAppearance(sValue, bValueChanged);
2297 }
2298 }
2299
2300 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) {
2301 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2302 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
2303 ASSERT(pFormCtrl);
2304
2305 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) {
2306 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2307 CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller();
2308 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage();
2309 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, FALSE);
2310 FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget);
2311
2312 pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right,
2313 rcBBox.bottom);
2314 }
2315 }
2316 }
2317
2318 FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField,
2319 const CFX_WideString& csValue) {
2320 CPDF_AAction aAction = pFormField->GetAdditionalAction();
2321 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::KeyStroke))
2322 return TRUE;
2323
2324 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);
2325 if (!action.GetDict())
2326 return TRUE;
2327
2328 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2329 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
2330 PDFSDK_FieldAction fa;
2331 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
2332 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
2333 fa.sValue = csValue;
2334 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke,
2335 m_pDocument, pFormField, fa);
2336 return fa.bRC;
2337 }
2338
2339 FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField,
2340 const CFX_WideString& csValue) {
2341 CPDF_AAction aAction = pFormField->GetAdditionalAction();
2342 if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate))
2343 return TRUE;
2344
2345 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);
2346 if (!action.GetDict())
2347 return TRUE;
2348
2349 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2350 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
2351 PDFSDK_FieldAction fa;
2352 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
2353 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
2354 fa.sValue = csValue;
2355 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate,
2356 m_pDocument, pFormField, fa);
2357 return fa.bRC;
2358 }
2359
2360 FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) {
2361 ASSERT(action.GetDict());
2362
2363 CPDF_ActionFields af(&action);
2364 std::vector<CPDF_Object*> fieldObjects = af.GetAllFields();
2365 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects);
2366
2367 FX_BOOL bHide = action.GetHideStatus();
2368 FX_BOOL bChanged = FALSE;
2369
2370 for (CPDF_FormField* pField : fields) {
2371 for (int i = 0, sz = pField->CountControls(); i < sz; ++i) {
2372 CPDF_FormControl* pControl = pField->GetControl(i);
2373 ASSERT(pControl);
2374
2375 if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) {
2376 FX_DWORD nFlags = pWidget->GetFlags();
2377 nFlags &= ~ANNOTFLAG_INVISIBLE;
2378 nFlags &= ~ANNOTFLAG_NOVIEW;
2379 if (bHide)
2380 nFlags |= ANNOTFLAG_HIDDEN;
2381 else
2382 nFlags &= ~ANNOTFLAG_HIDDEN;
2383 pWidget->SetFlags(nFlags);
2384 pWidget->GetPageView()->UpdateView(pWidget);
2385 bChanged = TRUE;
2386 }
2387 }
2388 }
2389
2390 return bChanged;
2391 }
2392
2393 FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) {
2394 CFX_WideString sDestination = action.GetFilePath();
2395 if (sDestination.IsEmpty())
2396 return FALSE;
2397
2398 CPDF_Dictionary* pActionDict = action.GetDict();
2399 if (pActionDict->KeyExist("Fields")) {
2400 CPDF_ActionFields af(&action);
2401 FX_DWORD dwFlags = action.GetFlags();
2402 std::vector<CPDF_Object*> fieldObjects = af.GetAllFields();
2403 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects);
2404 if (!fields.empty()) {
2405 bool bIncludeOrExclude = !(dwFlags & 0x01);
2406 if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude))
2407 return FALSE;
2408
2409 return SubmitFields(sDestination, fields, bIncludeOrExclude, false);
2410 }
2411 }
2412 if (m_pInterForm->CheckRequiredFields(nullptr, true))
2413 return FALSE;
2414
2415 return SubmitForm(sDestination, FALSE);
2416 }
2417
2418 FX_BOOL CPDFSDK_InterForm::SubmitFields(
2419 const CFX_WideString& csDestination,
2420 const std::vector<CPDF_FormField*>& fields,
2421 bool bIncludeOrExclude,
2422 bool bUrlEncoded) {
2423 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2424
2425 CFX_ByteTextBuf textBuf;
2426 ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);
2427
2428 uint8_t* pBuffer = textBuf.GetBuffer();
2429 FX_STRSIZE nBufSize = textBuf.GetLength();
2430
2431 if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize))
2432 return FALSE;
2433
2434 pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str());
2435 return TRUE;
2436 }
2437
2438 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile,
2439 CFX_WideString csTxtFile) {
2440 return TRUE;
2441 }
2442
2443 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf,
2444 FX_STRSIZE& nBufSize) {
2445 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);
2446 if (pFDF) {
2447 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF");
2448 if (!pMainDict)
2449 return FALSE;
2450
2451 // Get fields
2452 CPDF_Array* pFields = pMainDict->GetArrayBy("Fields");
2453 if (!pFields)
2454 return FALSE;
2455
2456 CFX_ByteTextBuf fdfEncodedData;
2457 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) {
2458 CPDF_Dictionary* pField = pFields->GetDictAt(i);
2459 if (!pField)
2460 continue;
2461 CFX_WideString name;
2462 name = pField->GetUnicodeTextBy("T");
2463 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);
2464 CFX_ByteString csBValue = pField->GetStringBy("V");
2465 CFX_WideString csWValue = PDF_DecodeText(csBValue);
2466 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);
2467
2468 fdfEncodedData << name_b.GetBuffer(name_b.GetLength());
2469 name_b.ReleaseBuffer();
2470 fdfEncodedData << "=";
2471 fdfEncodedData << csValue_b.GetBuffer(csValue_b.GetLength());
2472 csValue_b.ReleaseBuffer();
2473 if (i != pFields->GetCount() - 1)
2474 fdfEncodedData << "&";
2475 }
2476
2477 nBufSize = fdfEncodedData.GetLength();
2478 pBuf = FX_Alloc(uint8_t, nBufSize);
2479 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
2480 }
2481 return TRUE;
2482 }
2483
2484 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(
2485 const std::vector<CPDF_FormField*>& fields,
2486 bool bIncludeOrExclude,
2487 CFX_ByteTextBuf& textBuf) {
2488 std::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF(
2489 m_pDocument->GetPath(), fields, bIncludeOrExclude));
2490 return pFDF ? pFDF->WriteBuf(textBuf) : FALSE;
2491 }
2492
2493 #ifdef PDF_ENABLE_XFA
2494 void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField,
2495 FX_BOOL bSynchronizeElse) {
2496 int x = 0;
2497 if (m_FieldSynchronizeMap.Lookup(pFormField, x))
2498 return;
2499
2500 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2501 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
2502 ASSERT(pFormCtrl);
2503 ASSERT(m_pInterForm);
2504 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) {
2505 pWidget->Synchronize(bSynchronizeElse);
2506 }
2507 }
2508 }
2509 #endif // PDF_ENABLE_XFA
2510
2511 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(
2512 const CFX_WideString& sFileExt) {
2513 CFX_WideString sFileName;
2514 return L"";
2515 }
2516
2517 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination,
2518 FX_BOOL bUrlEncoded) {
2519 if (sDestination.IsEmpty())
2520 return FALSE;
2521
2522 if (!m_pDocument || !m_pInterForm)
2523 return FALSE;
2524
2525 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2526 CFX_WideString wsPDFFilePath = m_pDocument->GetPath();
2527 CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath);
2528 if (!pFDFDoc)
2529 return FALSE;
2530
2531 CFX_ByteTextBuf FdfBuffer;
2532 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);
2533 delete pFDFDoc;
2534 if (!bRet)
2535 return FALSE;
2536
2537 uint8_t* pBuffer = FdfBuffer.GetBuffer();
2538 FX_STRSIZE nBufSize = FdfBuffer.GetLength();
2539
2540 if (bUrlEncoded) {
2541 if (!FDFToURLEncodedData(pBuffer, nBufSize))
2542 return FALSE;
2543 }
2544
2545 pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str());
2546
2547 if (bUrlEncoded) {
2548 FX_Free(pBuffer);
2549 pBuffer = NULL;
2550 }
2551
2552 return TRUE;
2553 }
2554
2555 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) {
2556 CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());
2557 if (!pFDF)
2558 return FALSE;
2559
2560 FX_BOOL bRet = pFDF->WriteBuf(textBuf);
2561 delete pFDF;
2562
2563 return bRet;
2564 }
2565
2566 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) {
2567 ASSERT(action.GetDict());
2568
2569 CPDF_Dictionary* pActionDict = action.GetDict();
2570 if (!pActionDict->KeyExist("Fields"))
2571 return m_pInterForm->ResetForm(true);
2572
2573 CPDF_ActionFields af(&action);
2574 FX_DWORD dwFlags = action.GetFlags();
2575
2576 std::vector<CPDF_Object*> fieldObjects = af.GetAllFields();
2577 std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects);
2578 return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true);
2579 }
2580
2581 FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) {
2582 return FALSE;
2583 }
2584
2585 std::vector<CPDF_FormField*> CPDFSDK_InterForm::GetFieldFromObjects(
2586 const std::vector<CPDF_Object*>& objects) const {
2587 std::vector<CPDF_FormField*> fields;
2588 for (CPDF_Object* pObject : objects) {
2589 if (pObject && pObject->IsString()) {
2590 CFX_WideString csName = pObject->GetUnicodeText();
2591 CPDF_FormField* pField = m_pInterForm->GetField(0, csName);
2592 if (pField)
2593 fields.push_back(pField);
2594 }
2595 }
2596 return fields;
2597 }
2598
2599 int CPDFSDK_InterForm::BeforeValueChange(CPDF_FormField* pField,
2600 const CFX_WideString& csValue) {
2601 int nType = pField->GetFieldType();
2602 if (nType != FIELDTYPE_COMBOBOX && nType != FIELDTYPE_TEXTFIELD)
2603 return 0;
2604
2605 if (!OnKeyStrokeCommit(pField, csValue))
2606 return -1;
2607
2608 if (!OnValidate(pField, csValue))
2609 return -1;
2610
2611 return 1;
2612 }
2613
2614 void CPDFSDK_InterForm::AfterValueChange(CPDF_FormField* pField) {
2615 #ifdef PDF_ENABLE_XFA
2616 SynchronizeField(pField, FALSE);
2617 #endif // PDF_ENABLE_XFA
2618 int nType = pField->GetFieldType();
2619 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
2620 OnCalculate(pField);
2621 FX_BOOL bFormated = FALSE;
2622 CFX_WideString sValue = OnFormat(pField, bFormated);
2623 ResetFieldAppearance(pField, bFormated ? sValue.c_str() : nullptr, TRUE);
2624 UpdateField(pField);
2625 }
2626 }
2627
2628 int CPDFSDK_InterForm::BeforeSelectionChange(CPDF_FormField* pField,
2629 const CFX_WideString& csValue) {
2630 if (pField->GetFieldType() != FIELDTYPE_LISTBOX)
2631 return 0;
2632
2633 if (!OnKeyStrokeCommit(pField, csValue))
2634 return -1;
2635
2636 if (!OnValidate(pField, csValue))
2637 return -1;
2638
2639 return 1;
2640 }
2641
2642 void CPDFSDK_InterForm::AfterSelectionChange(CPDF_FormField* pField) {
2643 if (pField->GetFieldType() == FIELDTYPE_LISTBOX) {
2644 OnCalculate(pField);
2645 ResetFieldAppearance(pField, NULL, TRUE);
2646 UpdateField(pField);
2647 }
2648 }
2649
2650 void CPDFSDK_InterForm::AfterCheckedStatusChange(CPDF_FormField* pField) {
2651 int nType = pField->GetFieldType();
2652 if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON) {
2653 OnCalculate(pField);
2654 UpdateField(pField);
2655 }
2656 }
2657
2658 int CPDFSDK_InterForm::BeforeFormReset(CPDF_InterForm* pForm) {
2659 return 0;
2660 }
2661
2662 void CPDFSDK_InterForm::AfterFormReset(CPDF_InterForm* pForm) {
2663 OnCalculate(nullptr);
2664 }
2665
2666 int CPDFSDK_InterForm::BeforeFormImportData(CPDF_InterForm* pForm) {
2667 return 0;
2668 }
2669
2670 void CPDFSDK_InterForm::AfterFormImportData(CPDF_InterForm* pForm) {
2671 OnCalculate(nullptr);
2672 }
2673
2674 FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType) {
2675 if (nFieldType < 1 || nFieldType > kNumFieldTypes)
2676 return FALSE;
2677 return m_bNeedHightlight[nFieldType - 1];
2678 }
2679
2680 void CPDFSDK_InterForm::RemoveAllHighLight() {
2681 for (int i = 0; i < kNumFieldTypes; ++i)
2682 m_bNeedHightlight[i] = FALSE;
2683 }
2684
2685 void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType) {
2686 if (nFieldType < 0 || nFieldType > kNumFieldTypes)
2687 return;
2688 switch (nFieldType) {
2689 case 0: {
2690 for (int i = 0; i < kNumFieldTypes; ++i) {
2691 m_aHighlightColor[i] = clr;
2692 m_bNeedHightlight[i] = TRUE;
2693 }
2694 break;
2695 }
2696 default: {
2697 m_aHighlightColor[nFieldType - 1] = clr;
2698 m_bNeedHightlight[nFieldType - 1] = TRUE;
2699 break;
2700 }
2701 }
2702 }
2703
2704 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) {
2705 if (nFieldType < 0 || nFieldType > kNumFieldTypes)
2706 return FXSYS_RGB(255, 255, 255);
2707 if (nFieldType == 0)
2708 return m_aHighlightColor[0];
2709 return m_aHighlightColor[nFieldType - 1];
2710 }
2711
2712 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView,
2713 const CFX_ByteString& sType,
2714 const CFX_ByteString& sSubType)
2715 : m_eTabOrder(STRUCTURE),
2716 m_pPageView(pPageView),
2717 m_sType(sType),
2718 m_sSubType(sSubType) {
2719 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage();
2720 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetStringBy("Tabs");
2721 if (sTabs == "R")
2722 m_eTabOrder = ROW;
2723 else if (sTabs == "C")
2724 m_eTabOrder = COLUMN;
2725
2726 GenerateResults();
2727 }
2728
2729 CBA_AnnotIterator::~CBA_AnnotIterator() {
2730 }
2731
2732 CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot() {
2733 return m_Annots.empty() ? nullptr : m_Annots.front();
2734 }
2735
2736 CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot() {
2737 return m_Annots.empty() ? nullptr : m_Annots.back();
2738 }
2739
2740 CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot) {
2741 auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot);
2742 if (iter == m_Annots.end())
2743 return nullptr;
2744 ++iter;
2745 if (iter == m_Annots.end())
2746 iter = m_Annots.begin();
2747 return *iter;
2748 }
2749
2750 CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot) {
2751 auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot);
2752 if (iter == m_Annots.end())
2753 return nullptr;
2754 if (iter == m_Annots.begin())
2755 iter = m_Annots.end();
2756 return *(--iter);
2757 }
2758
2759 // static
2760 bool CBA_AnnotIterator::CompareByLeftAscending(const CPDFSDK_Annot* p1,
2761 const CPDFSDK_Annot* p2) {
2762 return GetAnnotRect(p1).left < GetAnnotRect(p2).left;
2763 }
2764
2765 // static
2766 bool CBA_AnnotIterator::CompareByTopDescending(const CPDFSDK_Annot* p1,
2767 const CPDFSDK_Annot* p2) {
2768 return GetAnnotRect(p1).top > GetAnnotRect(p2).top;
2769 }
2770
2771 void CBA_AnnotIterator::GenerateResults() {
2772 switch (m_eTabOrder) {
2773 case STRUCTURE: {
2774 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
2775 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2776 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType)
2777 m_Annots.push_back(pAnnot);
2778 }
2779 } break;
2780 case ROW: {
2781 std::vector<CPDFSDK_Annot*> sa;
2782 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
2783 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2784 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType)
2785 sa.push_back(pAnnot);
2786 }
2787
2788 std::sort(sa.begin(), sa.end(), CompareByLeftAscending);
2789 while (!sa.empty()) {
2790 int nLeftTopIndex = -1;
2791 FX_FLOAT fTop = 0.0f;
2792 for (int i = sa.size() - 1; i >= 0; i--) {
2793 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
2794 if (rcAnnot.top > fTop) {
2795 nLeftTopIndex = i;
2796 fTop = rcAnnot.top;
2797 }
2798 }
2799 if (nLeftTopIndex >= 0) {
2800 CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex];
2801 CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
2802 m_Annots.push_back(pLeftTopAnnot);
2803 sa.erase(sa.begin() + nLeftTopIndex);
2804
2805 std::vector<int> aSelect;
2806 for (int i = 0; i < sa.size(); ++i) {
2807 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
2808 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
2809 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
2810 aSelect.push_back(i);
2811 }
2812 for (int i = 0; i < aSelect.size(); ++i)
2813 m_Annots.push_back(sa[aSelect[i]]);
2814
2815 for (int i = aSelect.size() - 1; i >= 0; --i)
2816 sa.erase(sa.begin() + aSelect[i]);
2817 }
2818 }
2819 } break;
2820 case COLUMN: {
2821 std::vector<CPDFSDK_Annot*> sa;
2822 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
2823 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2824 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType)
2825 sa.push_back(pAnnot);
2826 }
2827
2828 std::sort(sa.begin(), sa.end(), CompareByTopDescending);
2829 while (!sa.empty()) {
2830 int nLeftTopIndex = -1;
2831 FX_FLOAT fLeft = -1.0f;
2832 for (int i = sa.size() - 1; i >= 0; --i) {
2833 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
2834 if (fLeft < 0) {
2835 nLeftTopIndex = 0;
2836 fLeft = rcAnnot.left;
2837 } else if (rcAnnot.left < fLeft) {
2838 nLeftTopIndex = i;
2839 fLeft = rcAnnot.left;
2840 }
2841 }
2842
2843 if (nLeftTopIndex >= 0) {
2844 CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex];
2845 CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
2846 m_Annots.push_back(pLeftTopAnnot);
2847 sa.erase(sa.begin() + nLeftTopIndex);
2848
2849 std::vector<int> aSelect;
2850 for (int i = 0; i < sa.size(); ++i) {
2851 CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
2852 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
2853 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
2854 aSelect.push_back(i);
2855 }
2856 for (int i = 0; i < aSelect.size(); ++i)
2857 m_Annots.push_back(sa[aSelect[i]]);
2858
2859 for (int i = aSelect.size() - 1; i >= 0; --i)
2860 sa.erase(sa.begin() + aSelect[i]);
2861 }
2862 }
2863 break;
2864 }
2865 }
2866 }
2867
2868 CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) {
2869 CFX_FloatRect rcAnnot;
2870 pAnnot->GetPDFAnnot()->GetRect(rcAnnot);
2871 return rcAnnot;
2872 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fsdk_baseannot.cpp ('k') | fpdfsdk/src/fsdk_baseform_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698