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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #include "../../third_party/base/nonstd_unique_ptr.h"
8 #include "../include/fsdk_define.h"
9 #include "../include/fsdk_mgr.h"
10 #include "../include/fsdk_baseannot.h"
11 #include "../include/fsdk_baseform.h"
12 #include "../include/formfiller/FFL_FormFiller.h"
13 #include "../include/fsdk_actionhandler.h"
15 #include "../include/javascript/IJavaScript.h"
17 //------------------------------------------------------------------------------------
19 //------------------------------------------------------------------------------------
21 #define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01)
22 #define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
23 #define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
24 #define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
26 CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm) :
27 CPDFSDK_Annot(pAnnot, pPageView),
28 m_pInterForm(pInterForm),
32 ASSERT(m_pInterForm != NULL);
35 CPDFSDK_Widget::~CPDFSDK_Widget()
40 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode)
42 ASSERT(m_pAnnot != NULL);
43 ASSERT(m_pAnnot->m_pAnnotDict != NULL);
45 CPDF_Dictionary* pAP = m_pAnnot->m_pAnnotDict->GetDict("AP");
46 if (pAP == NULL) return FALSE;
48 // Choose the right sub-ap
49 const FX_CHAR* ap_entry = "N";
50 if (mode == CPDF_Annot::Down)
52 else if (mode == CPDF_Annot::Rollover)
54 if (!pAP->KeyExist(ap_entry))
57 // Get the AP stream or subdirectory
58 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
59 if (psub == NULL) return FALSE;
61 int nFieldType = GetFieldType();
64 case FIELDTYPE_PUSHBUTTON:
65 case FIELDTYPE_COMBOBOX:
66 case FIELDTYPE_LISTBOX:
67 case FIELDTYPE_TEXTFIELD:
68 case FIELDTYPE_SIGNATURE:
69 return psub->GetType() == PDFOBJ_STREAM;
70 case FIELDTYPE_CHECKBOX:
71 case FIELDTYPE_RADIOBUTTON:
72 if (psub->GetType() == PDFOBJ_DICTIONARY)
74 CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub;
76 return pSubDict->GetStream(this->GetAppState()) != NULL;
86 int CPDFSDK_Widget::GetFieldType() const
88 CPDF_FormField* pField = GetFormField();
89 ASSERT(pField != NULL);
91 return pField->GetFieldType();
94 int CPDFSDK_Widget::GetFieldFlags() const
96 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
97 ASSERT(pPDFInterForm != NULL);
99 CPDF_FormControl* pFormControl = pPDFInterForm->GetControlByDict(m_pAnnot->m_pAnnotDict);
100 CPDF_FormField* pFormField = pFormControl->GetField();
101 return pFormField->GetFieldFlags();
104 CFX_ByteString CPDFSDK_Widget::GetSubType() const
106 int nType = GetFieldType();
108 if (nType == FIELDTYPE_SIGNATURE)
109 return BFFT_SIGNATURE;
110 return CPDFSDK_Annot::GetSubType();
113 CPDF_FormField* CPDFSDK_Widget::GetFormField() const
115 ASSERT(m_pInterForm != NULL);
117 CPDF_FormControl* pCtrl = GetFormControl();
118 ASSERT(pCtrl != NULL);
120 return pCtrl->GetField();
123 CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const
125 ASSERT(m_pInterForm != NULL);
127 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
128 ASSERT(pPDFInterForm != NULL);
130 return pPDFInterForm->GetControlByDict(GetAnnotDict());
132 static CPDF_Dictionary* BF_GetField(CPDF_Dictionary* pFieldDict, const FX_CHAR* name)
134 if (pFieldDict == NULL) return NULL;
135 // First check the dictionary itself
136 CPDF_Object* pAttr = pFieldDict->GetElementValue(name);
137 if (pAttr) return pFieldDict;
139 // Now we need to search from parents
140 CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent");
141 if (pParent == NULL) return NULL;
143 return BF_GetField(pParent, name);
146 CPDF_FormControl* CPDFSDK_Widget::GetFormControl(CPDF_InterForm* pInterForm, CPDF_Dictionary* pAnnotDict)
148 ASSERT(pInterForm != NULL);
149 ASSERT(pAnnotDict != NULL);
151 CPDF_FormControl* pControl = pInterForm->GetControlByDict(pAnnotDict);
156 int CPDFSDK_Widget::GetRotate() const
158 CPDF_FormControl* pCtrl = this->GetFormControl();
159 ASSERT(pCtrl != NULL);
161 return pCtrl->GetRotation() % 360;
164 FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const
166 CPDF_FormControl* pFormCtrl = GetFormControl();
167 ASSERT(pFormCtrl != NULL);
170 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType));
172 return iColorType != COLORTYPE_TRANSPARENT;
175 FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const
177 CPDF_FormControl* pFormCtrl = GetFormControl();
178 ASSERT(pFormCtrl != NULL);
181 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBorderColor(iColorType));
183 return iColorType != COLORTYPE_TRANSPARENT;
186 FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const
188 CPDF_FormControl* pFormCtrl = GetFormControl();
189 ASSERT(pFormCtrl != NULL);
191 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
195 int iColorType = COLORTYPE_TRANSPARENT;
196 da.GetColor(argb, iColorType);
197 color = FX_ARGBTOCOLORREF(argb);
199 return iColorType != COLORTYPE_TRANSPARENT;
205 FX_FLOAT CPDFSDK_Widget::GetFontSize() const
207 CPDF_FormControl* pFormCtrl = GetFormControl();
208 ASSERT(pFormCtrl != NULL);
210 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
211 CFX_ByteString csFont = "";
212 FX_FLOAT fFontSize = 0.0f;
213 pDa.GetFont(csFont, fFontSize);
218 int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const
220 CPDF_FormField* pFormField = GetFormField();
221 ASSERT(pFormField != NULL);
223 return pFormField->GetSelectedIndex(nIndex);
226 CFX_WideString CPDFSDK_Widget::GetValue() const
228 CPDF_FormField* pFormField = GetFormField();
229 ASSERT(pFormField != NULL);
231 return pFormField->GetValue();
234 CFX_WideString CPDFSDK_Widget::GetDefaultValue() const
236 CPDF_FormField* pFormField = GetFormField();
237 ASSERT(pFormField != NULL);
239 return pFormField->GetDefaultValue();
242 CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const
244 CPDF_FormField* pFormField = GetFormField();
245 ASSERT(pFormField != NULL);
247 return pFormField->GetOptionLabel(nIndex);
250 int CPDFSDK_Widget::CountOptions() const
252 CPDF_FormField* pFormField = GetFormField();
253 ASSERT(pFormField != NULL);
255 return pFormField->CountOptions();
258 FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const
260 CPDF_FormField* pFormField = GetFormField();
261 ASSERT(pFormField != NULL);
263 return pFormField->IsItemSelected(nIndex);
266 int CPDFSDK_Widget::GetTopVisibleIndex() const
268 CPDF_FormField* pFormField = GetFormField();
269 ASSERT(pFormField != NULL);
271 return pFormField->GetTopVisibleIndex();
274 FX_BOOL CPDFSDK_Widget::IsChecked() const
276 CPDF_FormControl* pFormCtrl = GetFormControl();
277 ASSERT(pFormCtrl != NULL);
279 return pFormCtrl->IsChecked();
282 int CPDFSDK_Widget::GetAlignment() const
284 CPDF_FormControl* pFormCtrl = GetFormControl();
285 ASSERT(pFormCtrl != NULL);
287 return pFormCtrl->GetControlAlignment();
290 int CPDFSDK_Widget::GetMaxLen() const
292 CPDF_FormField* pFormField = GetFormField();
293 ASSERT(pFormField != NULL);
295 return pFormField->GetMaxLen();
298 void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify)
300 CPDF_FormControl* pFormCtrl = GetFormControl();
301 ASSERT(pFormCtrl != NULL);
303 CPDF_FormField* pFormField = pFormCtrl->GetField();
304 ASSERT(pFormField != NULL);
306 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, bNotify);
309 void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify)
311 CPDF_FormField* pFormField = GetFormField();
312 ASSERT(pFormField != NULL);
314 pFormField->SetValue(sValue, bNotify);
317 void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue)
320 void CPDFSDK_Widget::SetOptionSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify)
322 CPDF_FormField* pFormField = GetFormField();
323 ASSERT(pFormField != NULL);
325 pFormField->SetItemSelection(index, bSelected, bNotify);
328 void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify)
330 CPDF_FormField* pFormField = GetFormField();
331 ASSERT(pFormField != NULL);
333 pFormField->ClearSelection(bNotify);
336 void CPDFSDK_Widget::SetTopVisibleIndex(int index)
340 void CPDFSDK_Widget::SetAppModified()
342 m_bAppModified = TRUE;
345 void CPDFSDK_Widget::ClearAppModified()
347 m_bAppModified = FALSE;
350 FX_BOOL CPDFSDK_Widget::IsAppModified() const
352 return m_bAppModified;
355 void CPDFSDK_Widget::ResetAppearance(FX_LPCWSTR sValue, FX_BOOL bValueChanged)
360 if (m_nAppAge > 999999)
365 int nFieldType = GetFieldType();
369 case FIELDTYPE_PUSHBUTTON:
370 ResetAppearance_PushButton();
372 case FIELDTYPE_CHECKBOX:
373 ResetAppearance_CheckBox();
375 case FIELDTYPE_RADIOBUTTON:
376 ResetAppearance_RadioButton();
378 case FIELDTYPE_COMBOBOX:
379 ResetAppearance_ComboBox(sValue);
381 case FIELDTYPE_LISTBOX:
382 ResetAppearance_ListBox();
384 case FIELDTYPE_TEXTFIELD:
385 ResetAppearance_TextField(sValue);
389 ASSERT(m_pAnnot != NULL);
390 m_pAnnot->ClearCachedAP();
393 CFX_WideString CPDFSDK_Widget::OnFormat(int nCommitKey, FX_BOOL& bFormated)
395 CPDF_FormField* pFormField = GetFormField();
396 ASSERT(pFormField != NULL);
398 ASSERT(m_pInterForm != NULL);
400 return m_pInterForm->OnFormat(pFormField, nCommitKey, bFormated);
404 void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged)
406 CPDF_FormField* pFormField = GetFormField();
407 ASSERT(pFormField != NULL);
409 ASSERT(m_pInterForm != NULL);
411 m_pInterForm->ResetFieldAppearance(pFormField, NULL, bValueChanged);
414 void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
415 CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)
417 int nFieldType = GetFieldType();
419 if ((nFieldType == FIELDTYPE_CHECKBOX || nFieldType == FIELDTYPE_RADIOBUTTON) &&
420 mode == CPDF_Annot::Normal &&
421 !this->IsWidgetAppearanceValid(CPDF_Annot::Normal))
423 CFX_PathData pathData;
425 CPDF_Rect rcAnnot = this->GetRect();
427 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom,
428 rcAnnot.right, rcAnnot.top);
430 CFX_GraphStateData gsd;
431 gsd.m_LineWidth = 0.0f;
433 pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, FXFILL_ALTERNATE);
437 CPDFSDK_Annot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
441 void CPDFSDK_Widget::UpdateField()
443 CPDF_FormField* pFormField = GetFormField();
444 ASSERT(pFormField != NULL);
446 ASSERT(m_pInterForm != NULL);
447 m_pInterForm->UpdateField(pFormField);
450 void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView)
452 ASSERT(m_pInterForm != NULL);
454 int nFieldType = GetFieldType();
455 if (m_pInterForm->IsNeedHighLight(nFieldType))
458 // if (nFieldType != FIELDTYPE_PUSHBUTTON)
460 CPDF_Rect rc = GetRect();
461 FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
462 FX_BYTE alpha = m_pInterForm->GetHighlightAlpha();
464 CFX_FloatRect rcDevice;
465 ASSERT(m_pInterForm->GetDocument());
466 CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();
469 CFX_AffineMatrix page2device;
470 pPageView->GetCurrentMatrix(page2device);
471 page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), rcDevice.left, rcDevice.bottom);
472 // pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.left, rc.bottom, &rcDevice.left, &rcDevice.bottom);
473 // pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.right, rc.top, &rcDevice.right, &rcDevice.top);
474 page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), rcDevice.right, rcDevice.top);
476 rcDevice.Normalize();
478 FX_ARGB argb = ArgbEncode((int)alpha, color);
479 FX_RECT rcDev((int)rcDevice.left,(int)rcDevice.top,(int)rcDevice.right,(int)rcDevice.bottom);
480 pDevice->FillRect(&rcDev, argb);
485 void CPDFSDK_Widget::ResetAppearance_PushButton()
487 CPDF_FormControl* pControl = GetFormControl();
488 ASSERT(pControl != NULL);
492 CPDF_Rect rcWindow = GetRotatedRect();
494 FX_INT32 nLayout = 0;
496 switch (pControl->GetTextPosition())
502 nLayout = PPBL_ICONTOPLABELBOTTOM;
505 nLayout = PPBL_LABELTOPICONBOTTOM;
508 nLayout = PPBL_ICONLEFTLABELRIGHT;
511 nLayout = PPBL_LABELLEFTICONRIGHT;
513 case TEXTPOS_OVERLAID:
514 nLayout = PPBL_LABELOVERICON;
517 nLayout = PPBL_LABEL;
521 CPWL_Color crBackground, crBorder;
526 pControl->GetOriginalBackgroundColor(iColorType, fc);
528 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
530 pControl->GetOriginalBorderColor(iColorType, fc);
532 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
534 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
535 FX_INT32 nBorderStyle = 0;
536 CPWL_Dash dsBorder(3,0,0);
537 CPWL_Color crLeftTop,crRightBottom;
539 switch (GetBorderStyle())
542 nBorderStyle = PBS_DASH;
543 dsBorder = CPWL_Dash(3, 3, 0);
546 nBorderStyle = PBS_BEVELED;
548 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
549 crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
552 nBorderStyle = PBS_INSET;
554 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
555 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
558 nBorderStyle = PBS_UNDERLINED;
561 nBorderStyle = PBS_SOLID;
565 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);
567 CPWL_Color crText(COLORTYPE_GRAY,0);
569 FX_FLOAT fFontSize = 12.0f;
570 CFX_ByteString csNameTag;
572 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
575 da.GetColor(iColorType, fc);
576 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
580 da.GetFont(csNameTag, fFontSize);
582 CFX_WideString csWCaption;
583 CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
585 if (pControl->HasMKEntry("CA"))
587 csNormalCaption = pControl->GetNormalCaption();
589 if (pControl->HasMKEntry("RC"))
591 csRolloverCaption = pControl->GetRolloverCaption();
593 if (pControl->HasMKEntry("AC"))
595 csDownCaption = pControl->GetDownCaption();
598 CPDF_Stream* pNormalIcon = NULL;
599 CPDF_Stream* pRolloverIcon = NULL;
600 CPDF_Stream* pDownIcon = NULL;
602 if (pControl->HasMKEntry("I"))
604 pNormalIcon = pControl->GetNormalIcon();
606 if (pControl->HasMKEntry("RI"))
608 pRolloverIcon = pControl->GetRolloverIcon();
610 if (pControl->HasMKEntry("IX"))
612 pDownIcon = pControl->GetDownIcon();
617 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict())
619 if (pImageDict->GetString("Name").IsEmpty())
620 pImageDict->SetAtString("Name", "ImgA");
626 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict())
628 if (pImageDict->GetString("Name").IsEmpty())
629 pImageDict->SetAtString("Name", "ImgB");
635 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict())
637 if (pImageDict->GetString("Name").IsEmpty())
638 pImageDict->SetAtString("Name", "ImgC");
642 CPDF_IconFit iconFit = pControl->GetIconFit();
644 // ASSERT(this->m_pBaseForm != NULL);
645 ASSERT(this->m_pInterForm != NULL);
646 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
647 ASSERT(pDoc != NULL);
648 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
650 CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));
653 FontMap.SetAPType("N");
655 CFX_ByteString csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
656 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
657 CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
659 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
661 AddImageToAppearance("N", pNormalIcon);
663 CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
664 if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle)
666 if (csRolloverCaption.IsEmpty() && !pRolloverIcon)
668 csRolloverCaption = csNormalCaption;
669 pRolloverIcon = pNormalIcon;
672 FontMap.SetAPType("R");
674 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
675 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
676 CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, nLayout);
678 WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
680 AddImageToAppearance("R", pRolloverIcon);
682 if (csDownCaption.IsEmpty() && !pDownIcon)
684 csDownCaption = csNormalCaption;
685 pDownIcon = pNormalIcon;
688 switch (nBorderStyle)
692 CPWL_Color crTemp = crLeftTop;
693 crLeftTop = crRightBottom;
694 crRightBottom = crTemp;
698 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
699 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
703 FontMap.SetAPType("D");
705 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, CPWL_Utils::SubstractColor(crBackground,0.25f)) +
706 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
707 CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);
709 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);
711 AddImageToAppearance("D", pDownIcon);
715 RemoveAppearance("D");
716 RemoveAppearance("R");
720 void CPDFSDK_Widget::ResetAppearance_CheckBox()
722 CPDF_FormControl* pControl = GetFormControl();
723 ASSERT(pControl != NULL);
727 CPWL_Color crBackground, crBorder, crText;
732 pControl->GetOriginalBackgroundColor(iColorType, fc);
734 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
736 pControl->GetOriginalBorderColor(iColorType, fc);
738 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
740 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
741 FX_INT32 nBorderStyle = 0;
742 CPWL_Dash dsBorder(3,0,0);
743 CPWL_Color crLeftTop,crRightBottom;
745 switch (GetBorderStyle())
748 nBorderStyle = PBS_DASH;
749 dsBorder = CPWL_Dash(3, 3, 0);
752 nBorderStyle = PBS_BEVELED;
754 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
755 crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
758 nBorderStyle = PBS_INSET;
760 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
761 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
764 nBorderStyle = PBS_UNDERLINED;
767 nBorderStyle = PBS_SOLID;
771 CPDF_Rect rcWindow = GetRotatedRect();
772 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);
774 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
777 da.GetColor(iColorType, fc);
778 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
783 CFX_WideString csWCaption = pControl->GetNormalCaption();
784 if (csWCaption.GetLength() > 0)
786 switch (csWCaption[0])
795 nStyle = PCS_DIAMOND;
813 CFX_ByteString csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) +
814 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
816 CFX_ByteString csAP_N_OFF = csAP_N_ON;
818 switch (nBorderStyle)
822 CPWL_Color crTemp = crLeftTop;
823 crLeftTop = crRightBottom;
824 crRightBottom = crTemp;
828 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
829 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
833 CFX_ByteString csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) +
834 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
836 CFX_ByteString csAP_D_OFF = csAP_D_ON;
838 csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);
839 csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);
841 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());
842 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
844 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());
845 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
847 CFX_ByteString csAS = GetAppState();
852 void CPDFSDK_Widget::ResetAppearance_RadioButton()
854 CPDF_FormControl* pControl = GetFormControl();
855 ASSERT(pControl != NULL);
859 CPWL_Color crBackground, crBorder, crText;
864 pControl->GetOriginalBackgroundColor(iColorType, fc);
866 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
868 pControl->GetOriginalBorderColor(iColorType, fc);
870 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
872 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
873 FX_INT32 nBorderStyle = 0;
874 CPWL_Dash dsBorder(3,0,0);
875 CPWL_Color crLeftTop,crRightBottom;
877 switch (GetBorderStyle())
880 nBorderStyle = PBS_DASH;
881 dsBorder = CPWL_Dash(3, 3, 0);
884 nBorderStyle = PBS_BEVELED;
886 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
887 crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
890 nBorderStyle = PBS_INSET;
892 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
893 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
896 nBorderStyle = PBS_UNDERLINED;
899 nBorderStyle = PBS_SOLID;
903 CPDF_Rect rcWindow = GetRotatedRect();
904 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
906 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
909 da.GetColor(iColorType, fc);
910 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
915 CFX_WideString csWCaption = pControl->GetNormalCaption();
916 if (csWCaption.GetLength() > 0)
918 switch (csWCaption[0])
927 nStyle = PCS_DIAMOND;
945 CFX_ByteString csAP_N_ON;
947 CPDF_Rect rcCenter = CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);
949 if (nStyle == PCS_CIRCLE)
951 if (nBorderStyle == PBS_BEVELED)
953 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
954 crRightBottom = CPWL_Utils::SubstractColor(crBackground,0.25f);
956 else if (nBorderStyle == PBS_INSET)
958 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5f);
959 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75f);
962 csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBackground) +
963 CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
967 csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) +
968 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
971 CFX_ByteString csAP_N_OFF = csAP_N_ON;
973 switch (nBorderStyle)
977 CPWL_Color crTemp = crLeftTop;
978 crLeftTop = crRightBottom;
979 crRightBottom = crTemp;
983 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
984 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
988 CFX_ByteString csAP_D_ON;
990 if (nStyle == PCS_CIRCLE)
992 CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground,0.25f);
993 if (nBorderStyle == PBS_BEVELED)
995 crLeftTop = CPWL_Utils::SubstractColor(crBackground,0.25f);
996 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
999 else if (nBorderStyle == PBS_INSET)
1001 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
1002 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
1005 csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBK)
1006 + CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
1010 csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) +
1011 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
1014 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1016 csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);
1017 csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);
1019 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());
1020 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1022 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());
1023 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1025 CFX_ByteString csAS = GetAppState();
1030 void CPDFSDK_Widget::ResetAppearance_ComboBox(FX_LPCWSTR sValue)
1032 CPDF_FormControl* pControl = GetFormControl();
1033 ASSERT(pControl != NULL);
1034 CPDF_FormField* pField = pControl->GetField();
1035 ASSERT(pField != NULL);
1037 CFX_ByteTextBuf sBody, sLines;
1039 CPDF_Rect rcClient = GetClientRect();
1040 CPDF_Rect rcButton = rcClient;
1041 rcButton.left = rcButton.right - 13;
1042 rcButton.Normalize();
1044 if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
1046 pEdit->EnableRefresh(FALSE);
1048 ASSERT(this->m_pInterForm != NULL);
1049 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1050 ASSERT(pDoc != NULL);
1051 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1052 CBA_FontMap FontMap(this,pEnv->GetSysHandler());
1054 pEdit->SetFontMap(&FontMap);
1056 CPDF_Rect rcEdit = rcClient;
1057 rcEdit.right = rcButton.left;
1060 pEdit->SetPlateRect(rcEdit);
1061 pEdit->SetAlignmentV(1);
1063 FX_FLOAT fFontSize = this->GetFontSize();
1064 if (IsFloatZero(fFontSize))
1065 pEdit->SetAutoFontSize(TRUE);
1067 pEdit->SetFontSize(fFontSize);
1069 pEdit->Initialize();
1072 pEdit->SetText(sValue);
1075 FX_INT32 nCurSel = pField->GetSelectedIndex(0);
1078 pEdit->SetText(pField->GetValue().c_str());
1080 pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str());
1083 CPDF_Rect rcContent = pEdit->GetContentRect();
1085 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f));
1086 if (sEdit.GetLength() > 0)
1088 sBody << "/Tx BMC\n" << "q\n";
1089 if (rcContent.Width() > rcEdit.Width() ||
1090 rcContent.Height() > rcEdit.Height())
1092 sBody << rcEdit.left << " " << rcEdit.bottom << " "
1093 << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n";
1096 CPWL_Color crText = GetTextPWLColor();
1097 sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";
1100 IFX_Edit::DelEdit(pEdit);
1103 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
1105 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
1107 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1110 void CPDFSDK_Widget::ResetAppearance_ListBox()
1112 CPDF_FormControl* pControl = GetFormControl();
1113 ASSERT(pControl != NULL);
1114 CPDF_FormField* pField = pControl->GetField();
1115 ASSERT(pField != NULL);
1117 CPDF_Rect rcClient = GetClientRect();
1119 CFX_ByteTextBuf sBody, sLines;
1121 if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
1123 pEdit->EnableRefresh(FALSE);
1125 // ASSERT(this->m_pBaseForm != NULL);
1126 ASSERT(this->m_pInterForm != NULL);
1127 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1128 ASSERT(pDoc != NULL);
1129 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1131 CBA_FontMap FontMap(this,pEnv->GetSysHandler());
1133 pEdit->SetFontMap(&FontMap);
1135 pEdit->SetPlateRect(CPDF_Rect(rcClient.left,0.0f,rcClient.right,0.0f));
1137 FX_FLOAT fFontSize = GetFontSize();
1139 if (IsFloatZero(fFontSize))
1140 pEdit->SetFontSize(12.0f);
1142 pEdit->SetFontSize(fFontSize);
1144 pEdit->Initialize();
1146 CFX_ByteTextBuf sList;
1147 FX_FLOAT fy = rcClient.top;
1149 FX_INT32 nTop = pField->GetTopVisibleIndex();
1150 FX_INT32 nCount = pField->CountOptions();
1151 FX_INT32 nSelCount = pField->CountSelectedItems();
1153 for (FX_INT32 i=nTop; i<nCount; i++)
1155 FX_BOOL bSelected = FALSE;
1156 for (FX_INT32 j=0; j<nSelCount; j++)
1158 if (pField->GetSelectedIndex(j) == i)
1165 pEdit->SetText(pField->GetOptionLabel(i).c_str());
1167 CPDF_Rect rcContent = pEdit->GetContentRect();
1168 FX_FLOAT fItemHeight = rcContent.Height();
1172 CPDF_Rect rcItem = CPDF_Rect(rcClient.left,fy-fItemHeight,rcClient.right,fy);
1173 sList << "q\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB,0,51.0f/255.0f,113.0f/255.0f),TRUE)
1174 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() << " " << rcItem.Height() << " re f\n" << "Q\n";
1176 sList << "BT\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY,1),TRUE) <<
1177 CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";
1181 CPWL_Color crText = GetTextPWLColor();
1182 sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) <<
1183 CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";
1189 if (sList.GetSize() > 0)
1191 sBody << "/Tx BMC\n" << "q\n" << rcClient.left << " " << rcClient.bottom << " "
1192 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1193 sBody << sList << "Q\nEMC\n";
1196 IFX_Edit::DelEdit(pEdit);
1199 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
1201 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1204 void CPDFSDK_Widget::ResetAppearance_TextField(FX_LPCWSTR sValue)
1206 CPDF_FormControl* pControl = GetFormControl();
1207 ASSERT(pControl != NULL);
1208 CPDF_FormField* pField = pControl->GetField();
1209 ASSERT(pField != NULL);
1211 CFX_ByteTextBuf sBody, sLines;
1213 if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
1215 pEdit->EnableRefresh(FALSE);
1217 // ASSERT(this->m_pBaseForm != NULL);
1218 ASSERT(this->m_pInterForm != NULL);
1219 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1220 ASSERT(pDoc != NULL);
1221 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1223 CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));
1225 pEdit->SetFontMap(&FontMap);
1227 CPDF_Rect rcClient = GetClientRect();
1228 pEdit->SetPlateRect(rcClient);
1229 pEdit->SetAlignmentH(pControl->GetControlAlignment());
1231 FX_DWORD dwFieldFlags = pField->GetFieldFlags();
1232 FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1;
1236 pEdit->SetMultiLine(TRUE);
1237 pEdit->SetAutoReturn(TRUE);
1241 pEdit->SetAlignmentV(1);
1244 FX_WORD subWord = 0;
1245 if ((dwFieldFlags >> 13) & 1)
1248 pEdit->SetPasswordChar(subWord);
1251 int nMaxLen = pField->GetMaxLen();
1252 FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
1253 FX_FLOAT fFontSize = GetFontSize();
1259 pEdit->SetCharArray(nMaxLen);
1261 if (IsFloatZero(fFontSize))
1263 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(FontMap.GetPDFFont(0),rcClient,nMaxLen);
1269 nMaxLen = wcslen((const wchar_t*)sValue);
1270 pEdit->SetLimitChar(nMaxLen);
1274 if (IsFloatZero(fFontSize))
1275 pEdit->SetAutoFontSize(TRUE);
1277 pEdit->SetFontSize(fFontSize);
1279 pEdit->Initialize();
1282 pEdit->SetText(sValue);
1284 pEdit->SetText(pField->GetValue().c_str());
1286 CPDF_Rect rcContent = pEdit->GetContentRect();
1288 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f),
1289 NULL,!bCharArray,subWord);
1291 if (sEdit.GetLength() > 0)
1293 sBody << "/Tx BMC\n" << "q\n";
1294 if (rcContent.Width() > rcClient.Width() ||
1295 rcContent.Height() > rcClient.Height())
1297 sBody << rcClient.left << " " << rcClient.bottom << " "
1298 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1300 CPWL_Color crText = GetTextPWLColor();
1301 sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";
1306 switch (GetBorderStyle())
1310 CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);
1311 if (sColor.GetLength() > 0)
1313 sLines << "q\n" << GetBorderWidth() << " w\n"
1314 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE) << " 2 J 0 j\n";
1316 for (FX_INT32 i=1;i<nMaxLen;i++)
1318 sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
1319 << rcClient.bottom << " m\n"
1320 << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
1321 << rcClient.top << " l S\n";
1330 CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);
1331 if (sColor.GetLength() > 0)
1333 CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
1335 sLines << "q\n" << GetBorderWidth() << " w\n"
1336 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE)
1337 << "[" << dsBorder.nDash << " "
1338 << dsBorder.nGap << "] "
1339 << dsBorder.nPhase << " d\n";
1341 for (FX_INT32 i=1;i<nMaxLen;i++)
1343 sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
1344 << rcClient.bottom << " m\n"
1345 << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
1346 << rcClient.top << " l S\n";
1356 IFX_Edit::DelEdit(pEdit);
1359 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
1360 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1363 CPDF_Rect CPDFSDK_Widget::GetClientRect() const
1365 CPDF_Rect rcWindow = GetRotatedRect();
1366 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1367 switch (GetBorderStyle())
1371 fBorderWidth *= 2.0f;
1375 return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
1378 CPDF_Rect CPDFSDK_Widget::GetRotatedRect() const
1380 CPDF_Rect rectAnnot = GetRect();
1381 FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
1382 FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
1384 CPDF_FormControl* pControl = GetFormControl();
1385 ASSERT(pControl != NULL);
1387 CPDF_Rect rcPDFWindow;
1388 switch(abs(pControl->GetRotation() % 360))
1393 rcPDFWindow = CPDF_Rect(0, 0, fWidth, fHeight);
1397 rcPDFWindow = CPDF_Rect(0, 0, fHeight, fWidth);
1404 CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const
1406 CPWL_Color crBackground = GetFillPWLColor();
1407 if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
1408 return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
1413 CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const
1415 CPDF_Rect rcWindow = GetRotatedRect();
1416 CPWL_Color crBorder = GetBorderPWLColor();
1417 CPWL_Color crBackground = GetFillPWLColor();
1418 CPWL_Color crLeftTop, crRightBottom;
1420 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1421 FX_INT32 nBorderStyle = 0;
1422 CPWL_Dash dsBorder(3,0,0);
1424 switch (GetBorderStyle())
1427 nBorderStyle = PBS_DASH;
1428 dsBorder = CPWL_Dash(3, 3, 0);
1431 nBorderStyle = PBS_BEVELED;
1433 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1434 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1437 nBorderStyle = PBS_INSET;
1439 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1440 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1443 nBorderStyle = PBS_UNDERLINED;
1446 nBorderStyle = PBS_SOLID;
1450 return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop,
1451 crRightBottom, nBorderStyle, dsBorder);
1454 CPDF_Matrix CPDFSDK_Widget::GetMatrix() const
1457 CPDF_FormControl* pControl = GetFormControl();
1458 ASSERT(pControl != NULL);
1460 CPDF_Rect rcAnnot = GetRect();
1461 FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left;
1462 FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom;
1466 switch (abs(pControl->GetRotation() % 360))
1470 mt = CPDF_Matrix(1, 0, 0, 1, 0, 0);
1473 mt = CPDF_Matrix(0, 1, -1, 0, fWidth, 0);
1476 mt = CPDF_Matrix(-1, 0, 0, -1, fWidth, fHeight);
1479 mt = CPDF_Matrix(0, -1, 1, 0, 0, fHeight);
1486 CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const
1488 CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);
1490 CPDF_FormControl* pFormCtrl = GetFormControl();
1491 ASSERT(pFormCtrl != NULL);
1493 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
1496 FX_INT32 iColorType;
1498 da.GetColor(iColorType, fc);
1499 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1505 CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const
1507 CPWL_Color crBorder;
1509 CPDF_FormControl* pFormCtrl = GetFormControl();
1510 ASSERT(pFormCtrl != NULL);
1512 FX_INT32 iColorType;
1514 pFormCtrl->GetOriginalBorderColor(iColorType, fc);
1516 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1521 CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const
1525 CPDF_FormControl* pFormCtrl = GetFormControl();
1526 ASSERT(pFormCtrl != NULL);
1528 FX_INT32 iColorType;
1530 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
1532 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1537 void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage)
1539 ASSERT(pImage != NULL);
1541 ASSERT(m_pAnnot != NULL);
1542 ASSERT(m_pAnnot->m_pAnnotDict != NULL);
1544 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();//pDocument->GetDocument();
1545 ASSERT(pDoc != NULL);
1547 CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP");
1548 ASSERT(pAPDict != NULL);
1550 CPDF_Stream* pStream = pAPDict->GetStream(sAPType);
1551 ASSERT(pStream != NULL);
1553 CPDF_Dictionary* pStreamDict = pStream->GetDict();
1554 ASSERT(pStreamDict != NULL);
1556 CFX_ByteString sImageAlias = "IMG";
1558 if (CPDF_Dictionary* pImageDict = pImage->GetDict())
1560 sImageAlias = pImageDict->GetString("Name");
1561 if (sImageAlias.IsEmpty())
1562 sImageAlias = "IMG";
1565 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");
1566 if (!pStreamResList)
1568 pStreamResList = new CPDF_Dictionary();
1569 pStreamDict->SetAt("Resources", pStreamResList);
1574 CPDF_Dictionary* pXObject = new CPDF_Dictionary;
1575 pXObject->SetAtReference(sImageAlias, pDoc, pImage);
1576 pStreamResList->SetAt("XObject", pXObject);
1580 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType)
1582 ASSERT(m_pAnnot != NULL);
1583 ASSERT(m_pAnnot->m_pAnnotDict != NULL);
1585 if (CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP"))
1587 pAPDict->RemoveAt(sAPType);
1591 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView)
1593 CPDF_Action action = GetAAction(type);
1595 if (action && action.GetType() != CPDF_Action::Unknown)
1597 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
1598 ASSERT(pDocument != NULL);
1600 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
1601 ASSERT(pEnv != NULL);
1603 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();/*(CPDFSDK_ActionHandler*)pApp->GetActionHandler();*/
1604 ASSERT(pActionHandler != NULL);
1606 return pActionHandler->DoAction_Field(action, type, pDocument, GetFormField(), data);
1612 CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT)
1616 case CPDF_AAction::CursorEnter:
1617 case CPDF_AAction::CursorExit:
1618 case CPDF_AAction::ButtonDown:
1619 case CPDF_AAction::ButtonUp:
1620 case CPDF_AAction::GetFocus:
1621 case CPDF_AAction::LoseFocus:
1622 case CPDF_AAction::PageOpen:
1623 case CPDF_AAction::PageClose:
1624 case CPDF_AAction::PageVisible:
1625 case CPDF_AAction::PageInvisible:
1626 return CPDFSDK_Annot::GetAAction(eAAT);
1628 case CPDF_AAction::KeyStroke:
1629 case CPDF_AAction::Format:
1630 case CPDF_AAction::Validate:
1631 case CPDF_AAction::Calculate:
1633 CPDF_FormField* pField = this->GetFormField();
1634 if (CPDF_AAction aa = pField->GetAdditionalAction())
1635 return aa.GetAction(eAAT);
1637 return CPDFSDK_Annot::GetAAction(eAAT);
1643 return CPDF_Action();
1647 CFX_WideString CPDFSDK_Widget::GetAlternateName() const
1649 CPDF_FormField* pFormField = GetFormField();
1650 ASSERT(pFormField != NULL);
1652 return pFormField->GetAlternateName();
1655 FX_INT32 CPDFSDK_Widget::GetAppearanceAge() const
1660 FX_INT32 CPDFSDK_Widget::GetValueAge() const
1666 FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY)
1668 CPDF_Annot* pAnnot = GetPDFAnnot();
1669 CFX_FloatRect annotRect;
1670 pAnnot->GetRect(annotRect);
1671 if(annotRect.Contains(pageX, pageY))
1673 if (!IsVisible()) return FALSE;
1675 int nFieldFlags = GetFieldFlags();
1676 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
1684 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)
1685 :m_pDocument(pDocument),
1690 ASSERT(m_pDocument != NULL);
1691 m_pInterForm = new CPDF_InterForm(m_pDocument->GetDocument(), FALSE);
1692 ASSERT(m_pInterForm != NULL);
1693 m_pInterForm->SetFormNotify(this);
1695 for(int i=0; i<6; i++)
1696 m_bNeedHightlight[i] = FALSE;
1697 m_iHighlightAlpha = 0;
1700 CPDFSDK_InterForm::~CPDFSDK_InterForm()
1702 ASSERT(m_pInterForm != NULL);
1703 delete m_pInterForm;
1704 m_pInterForm = NULL;
1709 void CPDFSDK_InterForm::Destroy()
1714 CPDF_InterForm* CPDFSDK_InterForm::GetInterForm()
1716 return m_pInterForm;
1719 CPDFSDK_Document* CPDFSDK_InterForm::GetDocument()
1724 FX_BOOL CPDFSDK_InterForm::HighlightWidgets()
1729 CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, FX_BOOL bNext) const
1731 nonstd::unique_ptr<CBA_AnnotIterator> pIterator(
1732 new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", ""));
1735 return (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget);
1737 return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);
1740 CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const
1742 if(!pControl || !m_pInterForm) return NULL;
1744 CPDFSDK_Widget* pWidget = NULL;
1745 m_Map.Lookup(pControl, pWidget);
1747 if (pWidget) return pWidget;
1749 CPDF_Dictionary* pControlDict = pControl->GetWidget();
1750 ASSERT(pControlDict != NULL);
1752 ASSERT(m_pDocument != NULL);
1753 CPDF_Document* pDocument = m_pDocument->GetDocument();
1755 CPDFSDK_PageView* pPage = NULL;
1757 if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P"))
1759 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
1760 if (nPageIndex >= 0)
1762 pPage = m_pDocument->GetPageView(nPageIndex);
1768 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);
1769 if (nPageIndex >= 0)
1771 pPage = m_pDocument->GetPageView(nPageIndex);
1776 return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
1781 void CPDFSDK_InterForm::GetWidgets(const CFX_WideString& sFieldName, CFX_PtrArray& widgets)
1783 ASSERT(m_pInterForm != NULL);
1785 for (int i=0,sz=m_pInterForm->CountFields(sFieldName); i<sz; i++)
1787 CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName);
1788 ASSERT(pFormField != NULL);
1790 GetWidgets(pFormField, widgets);
1794 void CPDFSDK_InterForm::GetWidgets(CPDF_FormField* pField, CFX_PtrArray& widgets)
1796 ASSERT(pField != NULL);
1798 for (int i=0,isz=pField->CountControls(); i<isz; i++)
1800 CPDF_FormControl* pFormCtrl = pField->GetControl(i);
1801 ASSERT(pFormCtrl != NULL);
1803 CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);
1806 widgets.Add(pWidget);
1810 int CPDFSDK_InterForm::GetPageIndexByAnnotDict(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict) const
1812 ASSERT(pDocument != NULL);
1813 ASSERT(pAnnotDict != NULL);
1815 for (int i=0,sz=pDocument->GetPageCount(); i<sz; i++)
1817 if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i))
1819 if (CPDF_Array* pAnnots = pPageDict->GetArray("Annots"))
1821 for (int j=0,jsz=pAnnots->GetCount(); j<jsz; j++)
1823 CPDF_Object* pDict = pAnnots->GetElementValue(j);
1824 if (pAnnotDict == pDict)
1836 void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget)
1838 m_Map.SetAt(pControl, pWidget);
1841 void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl)
1843 m_Map.RemoveKey(pControl);
1846 void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled)
1848 m_bCalculate = bEnabled;
1851 FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const
1853 return m_bCalculate;
1857 CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile)
1859 ASSERT(m_pDocument != NULL);
1860 CPDF_Document* pDocument = m_pDocument->GetDocument();
1861 ASSERT(pDocument != NULL);
1863 CPDF_Stream* pRetStream = NULL;
1865 if (CFX_DIBitmap* pBmp = CFX_WindowsDIB::LoadFromFile(sFile))
1867 int nWidth = pBmp->GetWidth();
1868 int nHeight = pBmp->GetHeight();
1870 CPDF_Image Image(pDocument);
1871 Image.SetImage(pBmp, FALSE);
1872 CPDF_Stream* pImageStream = Image.GetStream();
1875 if (pImageStream->GetObjNum() == 0)
1876 pDocument->AddIndirectObject(pImageStream);
1878 CPDF_Dictionary* pStreamDict = new CPDF_Dictionary();
1879 pStreamDict->SetAtName("Subtype", "Form");
1880 pStreamDict->SetAtName("Name", "IMG");
1881 CPDF_Array* pMatrix = new CPDF_Array();
1882 pStreamDict->SetAt("Matrix", pMatrix);
1883 pMatrix->AddInteger(1);
1884 pMatrix->AddInteger(0);
1885 pMatrix->AddInteger(0);
1886 pMatrix->AddInteger(1);
1887 pMatrix->AddInteger(-nWidth / 2);
1888 pMatrix->AddInteger(-nHeight / 2);
1889 CPDF_Dictionary* pResource = new CPDF_Dictionary();
1890 pStreamDict->SetAt("Resources", pResource);
1891 CPDF_Dictionary* pXObject = new CPDF_Dictionary();
1892 pResource->SetAt("XObject", pXObject);
1893 pXObject->SetAtReference("Img", pDocument, pImageStream);
1894 CPDF_Array* pProcSet = new CPDF_Array();
1895 pResource->SetAt("ProcSet", pProcSet);
1896 pProcSet->AddName("PDF");
1897 pProcSet->AddName("ImageC");
1898 pStreamDict->SetAtName("Type", "XObject");
1899 CPDF_Array* pBBox = new CPDF_Array();
1900 pStreamDict->SetAt("BBox", pBBox);
1901 pBBox->AddInteger(0);
1902 pBBox->AddInteger(0);
1903 pBBox->AddInteger(nWidth);
1904 pBBox->AddInteger(nHeight);
1905 pStreamDict->SetAtInteger("FormType", 1);
1907 pRetStream = new CPDF_Stream(NULL, 0, NULL);
1908 CFX_ByteString csStream;
1909 csStream.Format("q\n%d 0 0 %d 0 0 cm\n/Img Do\nQ", nWidth, nHeight);
1910 pRetStream->InitStream((FX_BYTE*)csStream.c_str(), csStream.GetLength(), pStreamDict);
1911 pDocument->AddIndirectObject(pRetStream);
1921 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField)
1923 ASSERT(m_pDocument != NULL);
1924 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
1926 if(!pEnv->IsJSInitiated())
1929 if (m_bBusy) return;
1933 if (this->IsCalculateEnabled())
1935 IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
1936 ASSERT(pRuntime != NULL);
1938 pRuntime->SetReaderDocument(m_pDocument);
1940 int nSize = m_pInterForm->CountFieldsInCalculationOrder();
1941 for (int i=0; i<nSize; i++)
1943 if(CPDF_FormField* pField = m_pInterForm->GetFieldInCalculationOrder(i))
1945 // ASSERT(pField != NULL);
1946 int nType = pField->GetFieldType();
1947 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
1949 CPDF_AAction aAction = pField->GetAdditionalAction();
1950 if (aAction && aAction.ActionExist(CPDF_AAction::Calculate))
1952 CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate);
1955 CFX_WideString csJS = action.GetJavaScript();
1956 if (!csJS.IsEmpty())
1958 IFXJS_Context* pContext = pRuntime->NewContext();
1959 ASSERT(pContext != NULL);
1961 CFX_WideString sOldValue = pField->GetValue();
1962 CFX_WideString sValue = sOldValue;
1964 pContext->OnField_Calculate(pFormField, pField, sValue, bRC);
1966 CFX_WideString sInfo;
1967 FX_BOOL bRet = pContext->RunScript(csJS, sInfo);
1968 pRuntime->ReleaseContext(pContext);
1974 if (sValue.Compare(sOldValue) != 0)
1975 pField->SetValue(sValue, TRUE);
1991 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, int nCommitKey, FX_BOOL& bFormated)
1993 ASSERT(m_pDocument != NULL);
1994 ASSERT(pFormField != NULL);
1996 CFX_WideString sValue = pFormField->GetValue();
1997 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
1999 if(!pEnv->IsJSInitiated())
2005 IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
2006 ASSERT(pRuntime != NULL);
2008 pRuntime->SetReaderDocument(m_pDocument);
2010 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)
2012 if (pFormField->CountSelectedItems() > 0)
2014 int index = pFormField->GetSelectedIndex(0);
2016 sValue = pFormField->GetOptionLabel(index);
2022 CPDF_AAction aAction = pFormField->GetAdditionalAction();
2023 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format))
2025 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);
2028 CFX_WideString script = action.GetJavaScript();
2029 if (!script.IsEmpty())
2031 CFX_WideString Value = sValue;
2033 IFXJS_Context* pContext = pRuntime->NewContext();
2034 ASSERT(pContext != NULL);
2036 pContext->OnField_Format(nCommitKey, pFormField, Value, TRUE);
2038 CFX_WideString sInfo;
2039 FX_BOOL bRet = pContext->RunScript(script, sInfo);
2040 pRuntime->ReleaseContext(pContext);
2054 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, FX_LPCWSTR sValue, FX_BOOL bValueChanged)
2056 ASSERT(pFormField != NULL);
2058 for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
2060 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
2061 ASSERT(pFormCtrl != NULL);
2063 ASSERT(m_pInterForm != NULL);
2064 if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
2065 pWidget->ResetAppearance(sValue, bValueChanged);
2069 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField)
2071 ASSERT(pFormField != NULL);
2073 for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
2075 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
2076 ASSERT(pFormCtrl != NULL);
2078 if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
2080 CPDFDoc_Environment * pEnv = m_pDocument->GetEnv();
2081 CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller();
2083 CPDF_Page * pPage = pWidget->GetPDFPage();
2084 CPDFSDK_PageView * pPageView = m_pDocument->GetPageView(pPage,FALSE);
2086 FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget);
2088 pEnv->FFI_Invalidate(pPage,rcBBox.left, rcBBox.top, rcBBox.right, rcBBox.bottom);
2093 void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)
2095 ASSERT(pFormField != NULL);
2097 CPDF_AAction aAction = pFormField->GetAdditionalAction();
2098 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::KeyStroke))
2100 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);
2103 ASSERT(m_pDocument != NULL);
2104 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2105 ASSERT(pEnv != NULL);
2107 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
2108 ASSERT(pActionHandler != NULL);
2110 PDFSDK_FieldAction fa;
2111 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
2112 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
2113 fa.sValue = csValue;
2115 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke,
2116 m_pDocument, pFormField, fa);
2122 void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)
2124 ASSERT(pFormField != NULL);
2126 CPDF_AAction aAction = pFormField->GetAdditionalAction();
2127 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Validate))
2129 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);
2132 ASSERT(m_pDocument != NULL);
2133 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2134 ASSERT(pEnv != NULL);
2136 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
2137 ASSERT(pActionHandler != NULL);
2139 PDFSDK_FieldAction fa;
2140 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
2141 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
2142 fa.sValue = csValue;
2144 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, m_pDocument, pFormField, fa);
2151 /* ----------------------------- action ----------------------------- */
2153 FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action)
2157 CPDF_ActionFields af = action.GetWidgets();
2158 CFX_PtrArray fieldObjects;
2159 af.GetAllFields(fieldObjects);
2160 CFX_PtrArray widgetArray;
2161 CFX_PtrArray fields;
2162 GetFieldFromObjects(fieldObjects, fields);
2164 FX_BOOL bHide = action.GetHideStatus();
2166 FX_BOOL bChanged = FALSE;
2168 for (int i=0, sz=fields.GetSize(); i<sz; i++)
2170 CPDF_FormField* pField = (CPDF_FormField*)fields[i];
2171 ASSERT(pField != NULL);
2174 for (int j=0,jsz=pField->CountControls(); j<jsz; j++)
2176 CPDF_FormControl* pControl = pField->GetControl(j);
2177 ASSERT(pControl != NULL);
2179 if (CPDFSDK_Widget* pWidget = GetWidget(pControl))
2181 int nFlags = pWidget->GetFlags();
2184 nFlags &= (~ANNOTFLAG_INVISIBLE);
2185 nFlags &= (~ANNOTFLAG_NOVIEW);
2186 nFlags |= (ANNOTFLAG_HIDDEN);
2190 nFlags &= (~ANNOTFLAG_INVISIBLE);
2191 nFlags &= (~ANNOTFLAG_HIDDEN);
2192 nFlags &= (~ANNOTFLAG_NOVIEW);
2194 pWidget->SetFlags(nFlags);
2196 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
2197 ASSERT(pPageView != NULL);
2199 pPageView->UpdateView(pWidget);
2209 FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action)
2212 ASSERT(m_pInterForm != NULL);
2214 CFX_WideString sDestination = action.GetFilePath();
2215 if (sDestination.IsEmpty()) return FALSE;
2217 CPDF_Dictionary* pActionDict = action.GetDict();
2218 if (pActionDict->KeyExist("Fields"))
2220 CPDF_ActionFields af = action.GetWidgets();
2221 FX_DWORD dwFlags = action.GetFlags();
2223 CFX_PtrArray fieldObjects;
2224 af.GetAllFields(fieldObjects);
2225 CFX_PtrArray fields;
2226 GetFieldFromObjects(fieldObjects, fields);
2228 if (fields.GetSize() != 0)
2230 FX_BOOL bIncludeOrExclude = !(dwFlags & 0x01);
2231 if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude))
2235 return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE);
2239 if ( m_pInterForm->CheckRequiredFields())
2244 return SubmitForm(sDestination, FALSE);
2249 if ( m_pInterForm->CheckRequiredFields())
2254 return SubmitForm(sDestination, FALSE);
2258 FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination, const CFX_PtrArray& fields,
2259 FX_BOOL bIncludeOrExclude, FX_BOOL bUrlEncoded)
2261 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2262 ASSERT(pEnv != NULL);
2264 CFX_ByteTextBuf textBuf;
2265 ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);
2267 FX_LPBYTE pBuffer = textBuf.GetBuffer();
2268 FX_STRSIZE nBufSize = textBuf.GetLength();
2272 if(!FDFToURLEncodedData(pBuffer, nBufSize))
2276 pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str());
2281 void CPDFSDK_InterForm::DoFDFBuffer(CFX_ByteString sBuffer)
2283 ASSERT(m_pDocument != NULL);
2285 if (CFDF_Document *pFDFDocument = CFDF_Document::ParseMemory((const unsigned char *)sBuffer.GetBuffer(sBuffer.GetLength()), sBuffer.GetLength()))
2287 CPDF_Dictionary* pRootDic = pFDFDocument->GetRoot();
2290 CPDF_Dictionary * pFDFDict=pRootDic->GetDict("FDF");
2293 CPDF_Dictionary * pJSDict = pFDFDict->GetDict("JavaScript");
2296 CFX_WideString csJS;
2298 CPDF_Object* pJS = pJSDict->GetElementValue("Before");
2301 int iType = pJS->GetType();
2302 if (iType == PDFOBJ_STRING)
2303 csJS = pJSDict->GetUnicodeText("Before");
2304 else if (iType == PDFOBJ_STREAM)
2305 csJS = pJS->GetUnicodeText();
2311 delete pFDFDocument;
2314 sBuffer.ReleaseBuffer();
2317 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile)
2322 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(FX_LPBYTE& pBuf, FX_STRSIZE& nBufSize)
2324 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);
2327 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
2328 if (pMainDict == NULL) return FALSE;
2331 CPDF_Array* pFields = pMainDict->GetArray("Fields");
2332 if (pFields == NULL) return FALSE;
2334 CFX_ByteTextBuf fdfEncodedData;
2336 for (FX_DWORD i = 0; i < pFields->GetCount(); i ++)
2338 CPDF_Dictionary* pField = pFields->GetDict(i);
2339 if (pField == NULL) continue;
2340 CFX_WideString name;
2341 name = pField->GetUnicodeText("T");
2342 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);
2343 CFX_ByteString csBValue = pField->GetString("V");
2344 CFX_WideString csWValue = PDF_DecodeText(csBValue);
2345 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);
2347 fdfEncodedData = fdfEncodedData<<name_b.GetBuffer(name_b.GetLength());
2348 name_b.ReleaseBuffer();
2349 fdfEncodedData = fdfEncodedData<<"=";
2350 fdfEncodedData = fdfEncodedData<<csValue_b.GetBuffer(csValue_b.GetLength());
2351 csValue_b.ReleaseBuffer();
2352 if(i != pFields->GetCount()-1)
2353 fdfEncodedData = fdfEncodedData<<"&";
2356 nBufSize = fdfEncodedData.GetLength();
2357 pBuf = FX_Alloc(FX_BYTE, nBufSize);
2360 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
2366 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,FX_BOOL bIncludeOrExclude, CFX_ByteTextBuf& textBuf)
2368 ASSERT(m_pDocument != NULL);
2369 ASSERT(m_pInterForm != NULL);
2371 CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude);
2372 if (!pFDF) return FALSE;
2373 FX_BOOL bRet = pFDF->WriteBuf(textBuf); // = FALSE;//
2379 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(const CFX_WideString& sFileExt)
2381 CFX_WideString sFileName;
2385 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, FX_BOOL bUrlEncoded)
2387 if (sDestination.IsEmpty()) return FALSE;
2389 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2390 ASSERT(pEnv != NULL);
2392 if(NULL == m_pDocument) return FALSE;
2393 CFX_WideString wsPDFFilePath = m_pDocument->GetPath();
2395 if(NULL == m_pInterForm) return FALSE;
2396 CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath);
2397 if (NULL == pFDFDoc) return FALSE;
2399 CFX_ByteTextBuf FdfBuffer;
2400 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);
2402 if (!bRet) return FALSE;
2404 FX_LPBYTE pBuffer = FdfBuffer.GetBuffer();
2405 FX_STRSIZE nBufSize = FdfBuffer.GetLength();
2409 if(!FDFToURLEncodedData(pBuffer, nBufSize))
2413 pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str());
2415 if (bUrlEncoded && pBuffer)
2424 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf)
2427 ASSERT(m_pInterForm != NULL);
2428 ASSERT(m_pDocument != NULL);
2430 CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());
2431 if (!pFDF) return FALSE;
2433 FX_BOOL bRet = pFDF->WriteBuf(textBuf);
2440 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action)
2444 CPDF_Dictionary* pActionDict = action.GetDict();
2445 if (pActionDict->KeyExist("Fields"))
2447 CPDF_ActionFields af = action.GetWidgets();
2448 FX_DWORD dwFlags = action.GetFlags();
2450 CFX_PtrArray fieldObjects;
2451 af.GetAllFields(fieldObjects);
2452 CFX_PtrArray fields;
2453 GetFieldFromObjects(fieldObjects, fields);
2454 return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE);
2457 return m_pInterForm->ResetForm(TRUE);
2460 FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action)
2465 void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects, CFX_PtrArray& fields)
2467 ASSERT(m_pInterForm != NULL);
2469 int iCount = objects.GetSize();
2470 for (int i = 0; i < iCount; i ++)
2472 CPDF_Object* pObject = (CPDF_Object*)objects[i];
2473 if (pObject == NULL) continue;
2475 int iType = pObject->GetType();
2476 if (iType == PDFOBJ_STRING)
2478 CFX_WideString csName = pObject->GetUnicodeText();
2479 CPDF_FormField* pField = m_pInterForm->GetField(0, csName);
2483 else if (iType == PDFOBJ_DICTIONARY)
2485 if (m_pInterForm->IsValidFormField(pObject))
2486 fields.Add(pObject);
2491 /* ----------------------------- CPDF_FormNotify ----------------------------- */
2493 int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, CFX_WideString& csValue)
2495 ASSERT(pField != NULL);
2497 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2499 int nType = pFormField->GetFieldType();
2500 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
2503 OnKeyStrokeCommit(pFormField, csValue, bRC);
2506 OnValidate(pFormField, csValue, bRC);
2519 int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField)
2521 ASSERT(pField != NULL);
2523 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2524 int nType = pFormField->GetFieldType();
2526 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
2528 this->OnCalculate(pFormField);
2529 FX_BOOL bFormated = FALSE;
2530 CFX_WideString sValue = this->OnFormat(pFormField, 0, bFormated);
2532 this->ResetFieldAppearance(pFormField, sValue, TRUE);
2534 this->ResetFieldAppearance(pFormField, NULL, TRUE);
2535 this->UpdateField(pFormField);
2541 int CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField, CFX_WideString& csValue)
2543 ASSERT(pField != NULL);
2545 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2547 int nType = pFormField->GetFieldType();
2548 if (nType == FIELDTYPE_LISTBOX)
2551 OnKeyStrokeCommit(pFormField, csValue, bRC);
2554 OnValidate(pFormField, csValue, bRC);
2567 int CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField)
2569 ASSERT(pField != NULL);
2571 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2572 int nType = pFormField->GetFieldType();
2574 if (nType == FIELDTYPE_LISTBOX)
2576 this->OnCalculate(pFormField);
2577 this->ResetFieldAppearance(pFormField, NULL, TRUE);
2578 this->UpdateField(pFormField);
2584 int CPDFSDK_InterForm::AfterCheckedStatusChange(const CPDF_FormField* pField, const CFX_ByteArray& statusArray)
2586 ASSERT(pField != NULL);
2588 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2589 int nType = pFormField->GetFieldType();
2591 if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON)
2593 this->OnCalculate(pFormField);
2594 //this->ResetFieldAppearance(pFormField, NULL);
2595 this->UpdateField(pFormField);
2601 int CPDFSDK_InterForm::BeforeFormReset(const CPDF_InterForm* pForm)
2606 int CPDFSDK_InterForm::AfterFormReset(const CPDF_InterForm* pForm)
2608 this->OnCalculate(NULL);
2613 int CPDFSDK_InterForm::BeforeFormImportData(const CPDF_InterForm* pForm)
2618 int CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm)
2620 this->OnCalculate(NULL);
2625 FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType)
2627 if(nFieldType <1 || nFieldType > 6)
2629 return m_bNeedHightlight[nFieldType-1];
2632 void CPDFSDK_InterForm::RemoveAllHighLight()
2634 memset((void*)m_bNeedHightlight, 0, 6*sizeof(FX_BOOL));
2636 void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType)
2638 if(nFieldType <0 || nFieldType > 6) return;
2643 for(int i=0; i<6; i++)
2645 m_aHighlightColor[i] = clr;
2646 m_bNeedHightlight[i] = TRUE;
2652 m_aHighlightColor[nFieldType-1] = clr;
2653 m_bNeedHightlight[nFieldType-1] = TRUE;
2660 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType)
2662 if(nFieldType <0 || nFieldType >6) return FXSYS_RGB(255,255,255);
2664 return m_aHighlightColor[0];
2666 return m_aHighlightColor[nFieldType-1];
2669 /* ------------------------- CBA_AnnotIterator ------------------------- */
2671 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, const CFX_ByteString& sType, const CFX_ByteString& sSubType)
2672 :m_pPageView(pPageView),
2674 m_sSubType(sSubType),
2675 m_nTabs(BAI_STRUCTURE)
2677 ASSERT(m_pPageView != NULL);
2679 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage();
2680 ASSERT(pPDFPage != NULL);
2681 ASSERT(pPDFPage->m_pFormDict != NULL);
2683 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetString("Tabs");
2689 else if (sTabs == "C")
2691 m_nTabs = BAI_COLUMN;
2695 m_nTabs = BAI_STRUCTURE;
2701 CBA_AnnotIterator::~CBA_AnnotIterator()
2703 m_Annots.RemoveAll();
2706 CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot()
2708 if (m_Annots.GetSize() > 0)
2714 CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot()
2716 if (m_Annots.GetSize() > 0)
2717 return m_Annots[m_Annots.GetSize() - 1];
2722 CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot)
2724 for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)
2726 if (m_Annots[i] == pAnnot)
2729 return m_Annots[i+1];
2738 CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot)
2740 for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)
2742 if (m_Annots[i] == pAnnot)
2745 return m_Annots[i-1];
2747 return m_Annots[sz-1];
2754 int CBA_AnnotIterator::CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
2759 CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
2760 CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
2762 if (rcAnnot1.left < rcAnnot2.left)
2764 if (rcAnnot1.left > rcAnnot2.left)
2770 int CBA_AnnotIterator::CompareByTop(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
2775 CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
2776 CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
2778 if (rcAnnot1.top < rcAnnot2.top)
2780 if (rcAnnot1.top > rcAnnot2.top)
2785 void CBA_AnnotIterator::GenerateResults()
2787 ASSERT(m_pPageView != NULL);
2793 for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
2795 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2796 ASSERT(pAnnot != NULL);
2798 if (pAnnot->GetType() == m_sType
2799 && pAnnot->GetSubType() == m_sSubType)
2800 m_Annots.Add(pAnnot);
2806 CPDFSDK_SortAnnots sa;
2810 for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
2812 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2813 ASSERT(pAnnot != NULL);
2815 if (pAnnot->GetType() == m_sType
2816 && pAnnot->GetSubType() == m_sSubType)
2821 if (sa.GetSize() > 0)
2823 sa.Sort(CBA_AnnotIterator::CompareByLeft);
2826 while (sa.GetSize() > 0)
2828 int nLeftTopIndex = -1;
2831 FX_FLOAT fTop = 0.0f;
2833 for (int i=sa.GetSize()-1; i>=0; i--)
2835 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2836 ASSERT(pAnnot != NULL);
2838 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2840 if (rcAnnot.top > fTop)
2848 if (nLeftTopIndex >= 0)
2850 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
2851 ASSERT(pLeftTopAnnot != NULL);
2853 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
2855 m_Annots.Add(pLeftTopAnnot);
2856 sa.RemoveAt(nLeftTopIndex);
2858 CFX_ArrayTemplate<int> aSelect;
2861 for (int i=0,sz=sa.GetSize(); i<sz; i++)
2863 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2864 ASSERT(pAnnot != NULL);
2866 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2868 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
2870 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
2876 for (int i=0,sz=aSelect.GetSize(); i<sz; i++)
2878 m_Annots.Add(sa[aSelect[i]]);
2883 for (int i=aSelect.GetSize()-1; i>=0; i--)
2885 sa.RemoveAt(aSelect[i]);
2889 aSelect.RemoveAll();
2897 CPDFSDK_SortAnnots sa;
2900 for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
2902 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2903 ASSERT(pAnnot != NULL);
2905 if (pAnnot->GetType() == m_sType
2906 && pAnnot->GetSubType() == m_sSubType)
2911 if (sa.GetSize() > 0)
2913 sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE);
2916 while (sa.GetSize() > 0)
2918 int nLeftTopIndex = -1;
2921 FX_FLOAT fLeft = -1.0f;
2923 for (int i=sa.GetSize()-1; i>=0; i--)
2925 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2926 ASSERT(pAnnot != NULL);
2928 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2933 fLeft = rcAnnot.left;
2935 else if (rcAnnot.left < fLeft)
2938 fLeft = rcAnnot.left;
2943 if (nLeftTopIndex >= 0)
2945 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
2946 ASSERT(pLeftTopAnnot != NULL);
2948 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
2950 m_Annots.Add(pLeftTopAnnot);
2951 sa.RemoveAt(nLeftTopIndex);
2953 CFX_ArrayTemplate<int> aSelect;
2956 for (int i=0,sz=sa.GetSize(); i<sz; i++)
2958 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2959 ASSERT(pAnnot != NULL);
2961 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2963 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
2965 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
2971 for (int i=0,sz=aSelect.GetSize(); i<sz; i++)
2973 m_Annots.Add(sa[aSelect[i]]);
2978 for (int i=aSelect.GetSize()-1; i>=0; i--)
2980 sa.RemoveAt(aSelect[i]);
2984 aSelect.RemoveAll();
2993 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot)
2995 ASSERT(pAnnot != NULL);
2997 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
2998 ASSERT(pPDFAnnot != NULL);
3001 pPDFAnnot->GetRect(rcAnnot);