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 "../include/fsdk_define.h"
8 #include "../include/fsdk_mgr.h"
9 #include "../include/fsdk_baseannot.h"
10 #include "../include/fsdk_baseform.h"
11 #include "../include/formfiller/FFL_FormFiller.h"
12 #include "../include/fsdk_actionhandler.h"
14 #include "../include/javascript/IJavaScript.h"
16 //------------------------------------------------------------------------------------
18 //------------------------------------------------------------------------------------
20 #define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01)
21 #define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
22 #define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
23 #define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
25 CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm) :
26 CPDFSDK_Annot(pAnnot, pPageView),
27 m_pInterForm(pInterForm),
31 ASSERT(m_pInterForm != NULL);
34 CPDFSDK_Widget::~CPDFSDK_Widget()
39 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode)
41 ASSERT(m_pAnnot != NULL);
42 ASSERT(m_pAnnot->m_pAnnotDict != NULL);
44 CPDF_Dictionary* pAP = m_pAnnot->m_pAnnotDict->GetDict("AP");
45 if (pAP == NULL) return FALSE;
47 // Choose the right sub-ap
48 const FX_CHAR* ap_entry = "N";
49 if (mode == CPDF_Annot::Down)
51 else if (mode == CPDF_Annot::Rollover)
53 if (!pAP->KeyExist(ap_entry))
56 // Get the AP stream or subdirectory
57 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
58 if (psub == NULL) return FALSE;
60 int nFieldType = GetFieldType();
63 case FIELDTYPE_PUSHBUTTON:
64 case FIELDTYPE_COMBOBOX:
65 case FIELDTYPE_LISTBOX:
66 case FIELDTYPE_TEXTFIELD:
67 case FIELDTYPE_SIGNATURE:
68 return psub->GetType() == PDFOBJ_STREAM;
69 case FIELDTYPE_CHECKBOX:
70 case FIELDTYPE_RADIOBUTTON:
71 if (psub->GetType() == PDFOBJ_DICTIONARY)
73 CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub;
75 return pSubDict->GetStream(this->GetAppState()) != NULL;
85 int CPDFSDK_Widget::GetFieldType() const
87 CPDF_FormField* pField = GetFormField();
88 ASSERT(pField != NULL);
90 return pField->GetFieldType();
93 int CPDFSDK_Widget::GetFieldFlags() const
95 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
96 ASSERT(pPDFInterForm != NULL);
98 CPDF_FormControl* pFormControl = pPDFInterForm->GetControlByDict(m_pAnnot->m_pAnnotDict);
99 CPDF_FormField* pFormField = pFormControl->GetField();
100 return pFormField->GetFieldFlags();
103 CFX_ByteString CPDFSDK_Widget::GetSubType() const
105 int nType = GetFieldType();
107 if (nType == FIELDTYPE_SIGNATURE)
108 return BFFT_SIGNATURE;
109 return CPDFSDK_Annot::GetSubType();
112 CPDF_FormField* CPDFSDK_Widget::GetFormField() const
114 ASSERT(m_pInterForm != NULL);
116 CPDF_FormControl* pCtrl = GetFormControl();
117 ASSERT(pCtrl != NULL);
119 return pCtrl->GetField();
122 CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const
124 ASSERT(m_pInterForm != NULL);
126 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
127 ASSERT(pPDFInterForm != NULL);
129 return pPDFInterForm->GetControlByDict(GetAnnotDict());
131 static CPDF_Dictionary* BF_GetField(CPDF_Dictionary* pFieldDict, const FX_CHAR* name)
133 if (pFieldDict == NULL) return NULL;
134 // First check the dictionary itself
135 CPDF_Object* pAttr = pFieldDict->GetElementValue(name);
136 if (pAttr) return pFieldDict;
138 // Now we need to search from parents
139 CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent");
140 if (pParent == NULL) return NULL;
142 return BF_GetField(pParent, name);
145 CPDF_FormControl* CPDFSDK_Widget::GetFormControl(CPDF_InterForm* pInterForm, CPDF_Dictionary* pAnnotDict)
147 ASSERT(pInterForm != NULL);
148 ASSERT(pAnnotDict != NULL);
150 CPDF_FormControl* pControl = pInterForm->GetControlByDict(pAnnotDict);
155 int CPDFSDK_Widget::GetRotate() const
157 CPDF_FormControl* pCtrl = this->GetFormControl();
158 ASSERT(pCtrl != NULL);
160 return pCtrl->GetRotation() % 360;
163 FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const
165 CPDF_FormControl* pFormCtrl = GetFormControl();
166 ASSERT(pFormCtrl != NULL);
169 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType));
171 return iColorType != COLORTYPE_TRANSPARENT;
174 FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const
176 CPDF_FormControl* pFormCtrl = GetFormControl();
177 ASSERT(pFormCtrl != NULL);
180 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBorderColor(iColorType));
182 return iColorType != COLORTYPE_TRANSPARENT;
185 FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const
187 CPDF_FormControl* pFormCtrl = GetFormControl();
188 ASSERT(pFormCtrl != NULL);
190 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
194 int iColorType = COLORTYPE_TRANSPARENT;
195 da.GetColor(argb, iColorType);
196 color = FX_ARGBTOCOLORREF(argb);
198 return iColorType != COLORTYPE_TRANSPARENT;
204 FX_FLOAT CPDFSDK_Widget::GetFontSize() const
206 CPDF_FormControl* pFormCtrl = GetFormControl();
207 ASSERT(pFormCtrl != NULL);
209 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
210 CFX_ByteString csFont = "";
211 FX_FLOAT fFontSize = 0.0f;
212 pDa.GetFont(csFont, fFontSize);
217 int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const
219 CPDF_FormField* pFormField = GetFormField();
220 ASSERT(pFormField != NULL);
222 return pFormField->GetSelectedIndex(nIndex);
225 CFX_WideString CPDFSDK_Widget::GetValue() const
227 CPDF_FormField* pFormField = GetFormField();
228 ASSERT(pFormField != NULL);
230 return pFormField->GetValue();
233 CFX_WideString CPDFSDK_Widget::GetDefaultValue() const
235 CPDF_FormField* pFormField = GetFormField();
236 ASSERT(pFormField != NULL);
238 return pFormField->GetDefaultValue();
241 CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const
243 CPDF_FormField* pFormField = GetFormField();
244 ASSERT(pFormField != NULL);
246 return pFormField->GetOptionLabel(nIndex);
249 int CPDFSDK_Widget::CountOptions() const
251 CPDF_FormField* pFormField = GetFormField();
252 ASSERT(pFormField != NULL);
254 return pFormField->CountOptions();
257 FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const
259 CPDF_FormField* pFormField = GetFormField();
260 ASSERT(pFormField != NULL);
262 return pFormField->IsItemSelected(nIndex);
265 int CPDFSDK_Widget::GetTopVisibleIndex() const
267 CPDF_FormField* pFormField = GetFormField();
268 ASSERT(pFormField != NULL);
270 return pFormField->GetTopVisibleIndex();
273 FX_BOOL CPDFSDK_Widget::IsChecked() const
275 CPDF_FormControl* pFormCtrl = GetFormControl();
276 ASSERT(pFormCtrl != NULL);
278 return pFormCtrl->IsChecked();
281 int CPDFSDK_Widget::GetAlignment() const
283 CPDF_FormControl* pFormCtrl = GetFormControl();
284 ASSERT(pFormCtrl != NULL);
286 return pFormCtrl->GetControlAlignment();
289 int CPDFSDK_Widget::GetMaxLen() const
291 CPDF_FormField* pFormField = GetFormField();
292 ASSERT(pFormField != NULL);
294 return pFormField->GetMaxLen();
297 void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify)
299 CPDF_FormControl* pFormCtrl = GetFormControl();
300 ASSERT(pFormCtrl != NULL);
302 CPDF_FormField* pFormField = pFormCtrl->GetField();
303 ASSERT(pFormField != NULL);
305 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, bNotify);
308 void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify)
310 CPDF_FormField* pFormField = GetFormField();
311 ASSERT(pFormField != NULL);
313 pFormField->SetValue(sValue, bNotify);
316 void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue)
319 void CPDFSDK_Widget::SetOptionSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify)
321 CPDF_FormField* pFormField = GetFormField();
322 ASSERT(pFormField != NULL);
324 pFormField->SetItemSelection(index, bSelected, bNotify);
327 void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify)
329 CPDF_FormField* pFormField = GetFormField();
330 ASSERT(pFormField != NULL);
332 pFormField->ClearSelection(bNotify);
335 void CPDFSDK_Widget::SetTopVisibleIndex(int index)
339 void CPDFSDK_Widget::SetAppModified()
341 m_bAppModified = TRUE;
344 void CPDFSDK_Widget::ClearAppModified()
346 m_bAppModified = FALSE;
349 FX_BOOL CPDFSDK_Widget::IsAppModified() const
351 return m_bAppModified;
354 void CPDFSDK_Widget::ResetAppearance(FX_LPCWSTR sValue, FX_BOOL bValueChanged)
359 if (m_nAppAge > 999999)
364 int nFieldType = GetFieldType();
368 case FIELDTYPE_PUSHBUTTON:
369 ResetAppearance_PushButton();
371 case FIELDTYPE_CHECKBOX:
372 ResetAppearance_CheckBox();
374 case FIELDTYPE_RADIOBUTTON:
375 ResetAppearance_RadioButton();
377 case FIELDTYPE_COMBOBOX:
378 ResetAppearance_ComboBox(sValue);
380 case FIELDTYPE_LISTBOX:
381 ResetAppearance_ListBox();
383 case FIELDTYPE_TEXTFIELD:
384 ResetAppearance_TextField(sValue);
388 ASSERT(m_pAnnot != NULL);
389 m_pAnnot->ClearCachedAP();
392 CFX_WideString CPDFSDK_Widget::OnFormat(int nCommitKey, FX_BOOL& bFormated)
394 CPDF_FormField* pFormField = GetFormField();
395 ASSERT(pFormField != NULL);
397 ASSERT(m_pInterForm != NULL);
399 return m_pInterForm->OnFormat(pFormField, nCommitKey, bFormated);
403 void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged)
405 CPDF_FormField* pFormField = GetFormField();
406 ASSERT(pFormField != NULL);
408 ASSERT(m_pInterForm != NULL);
410 m_pInterForm->ResetFieldAppearance(pFormField, NULL, bValueChanged);
413 void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
414 CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)
416 int nFieldType = GetFieldType();
418 if ((nFieldType == FIELDTYPE_CHECKBOX || nFieldType == FIELDTYPE_RADIOBUTTON) &&
419 mode == CPDF_Annot::Normal &&
420 !this->IsWidgetAppearanceValid(CPDF_Annot::Normal))
422 CFX_PathData pathData;
424 CPDF_Rect rcAnnot = this->GetRect();
426 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom,
427 rcAnnot.right, rcAnnot.top);
429 CFX_GraphStateData gsd;
430 gsd.m_LineWidth = 0.0f;
432 pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, FXFILL_ALTERNATE);
436 CPDFSDK_Annot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
440 void CPDFSDK_Widget::UpdateField()
442 CPDF_FormField* pFormField = GetFormField();
443 ASSERT(pFormField != NULL);
445 ASSERT(m_pInterForm != NULL);
446 m_pInterForm->UpdateField(pFormField);
449 void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView)
451 ASSERT(m_pInterForm != NULL);
453 int nFieldType = GetFieldType();
454 if (m_pInterForm->IsNeedHighLight(nFieldType))
457 // if (nFieldType != FIELDTYPE_PUSHBUTTON)
459 CPDF_Rect rc = GetRect();
460 FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
461 FX_BYTE alpha = m_pInterForm->GetHighlightAlpha();
463 CFX_FloatRect rcDevice;
464 ASSERT(m_pInterForm->GetDocument());
465 CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();
468 CFX_AffineMatrix page2device;
469 pPageView->GetCurrentMatrix(page2device);
470 page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), rcDevice.left, rcDevice.bottom);
471 // pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.left, rc.bottom, &rcDevice.left, &rcDevice.bottom);
472 // pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.right, rc.top, &rcDevice.right, &rcDevice.top);
473 page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), rcDevice.right, rcDevice.top);
475 rcDevice.Normalize();
477 FX_ARGB argb = ArgbEncode((int)alpha, color);
478 FX_RECT rcDev((int)rcDevice.left,(int)rcDevice.top,(int)rcDevice.right,(int)rcDevice.bottom);
479 pDevice->FillRect(&rcDev, argb);
484 void CPDFSDK_Widget::ResetAppearance_PushButton()
486 CPDF_FormControl* pControl = GetFormControl();
487 ASSERT(pControl != NULL);
491 CPDF_Rect rcWindow = GetRotatedRect();
493 FX_INT32 nLayout = 0;
495 switch (pControl->GetTextPosition())
501 nLayout = PPBL_ICONTOPLABELBOTTOM;
504 nLayout = PPBL_LABELTOPICONBOTTOM;
507 nLayout = PPBL_ICONLEFTLABELRIGHT;
510 nLayout = PPBL_LABELLEFTICONRIGHT;
512 case TEXTPOS_OVERLAID:
513 nLayout = PPBL_LABELOVERICON;
516 nLayout = PPBL_LABEL;
520 CPWL_Color crBackground, crBorder;
525 pControl->GetOriginalBackgroundColor(iColorType, fc);
527 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
529 pControl->GetOriginalBorderColor(iColorType, fc);
531 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
533 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
534 FX_INT32 nBorderStyle = 0;
535 CPWL_Dash dsBorder(3,0,0);
536 CPWL_Color crLeftTop,crRightBottom;
538 switch (GetBorderStyle())
541 nBorderStyle = PBS_DASH;
542 dsBorder = CPWL_Dash(3, 3, 0);
545 nBorderStyle = PBS_BEVELED;
547 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
548 crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
551 nBorderStyle = PBS_INSET;
553 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
554 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
557 nBorderStyle = PBS_UNDERLINED;
560 nBorderStyle = PBS_SOLID;
564 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);
566 CPWL_Color crText(COLORTYPE_GRAY,0);
568 FX_FLOAT fFontSize = 12.0f;
569 CFX_ByteString csNameTag;
571 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
574 da.GetColor(iColorType, fc);
575 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
579 da.GetFont(csNameTag, fFontSize);
581 CFX_WideString csWCaption;
582 CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
584 if (pControl->HasMKEntry("CA"))
586 csNormalCaption = pControl->GetNormalCaption();
588 if (pControl->HasMKEntry("RC"))
590 csRolloverCaption = pControl->GetRolloverCaption();
592 if (pControl->HasMKEntry("AC"))
594 csDownCaption = pControl->GetDownCaption();
597 CPDF_Stream* pNormalIcon = NULL;
598 CPDF_Stream* pRolloverIcon = NULL;
599 CPDF_Stream* pDownIcon = NULL;
601 if (pControl->HasMKEntry("I"))
603 pNormalIcon = pControl->GetNormalIcon();
605 if (pControl->HasMKEntry("RI"))
607 pRolloverIcon = pControl->GetRolloverIcon();
609 if (pControl->HasMKEntry("IX"))
611 pDownIcon = pControl->GetDownIcon();
616 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict())
618 if (pImageDict->GetString("Name").IsEmpty())
619 pImageDict->SetAtString("Name", "ImgA");
625 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict())
627 if (pImageDict->GetString("Name").IsEmpty())
628 pImageDict->SetAtString("Name", "ImgB");
634 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict())
636 if (pImageDict->GetString("Name").IsEmpty())
637 pImageDict->SetAtString("Name", "ImgC");
641 CPDF_IconFit iconFit = pControl->GetIconFit();
643 // ASSERT(this->m_pBaseForm != NULL);
644 ASSERT(this->m_pInterForm != NULL);
645 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
646 ASSERT(pDoc != NULL);
647 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
649 CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));
652 FontMap.SetAPType("N");
654 CFX_ByteString csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
655 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
656 CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
658 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
660 AddImageToAppearance("N", pNormalIcon);
662 CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
663 if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle)
665 if (csRolloverCaption.IsEmpty() && !pRolloverIcon)
667 csRolloverCaption = csNormalCaption;
668 pRolloverIcon = pNormalIcon;
671 FontMap.SetAPType("R");
673 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
674 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
675 CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, nLayout);
677 WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
679 AddImageToAppearance("R", pRolloverIcon);
681 if (csDownCaption.IsEmpty() && !pDownIcon)
683 csDownCaption = csNormalCaption;
684 pDownIcon = pNormalIcon;
687 switch (nBorderStyle)
691 CPWL_Color crTemp = crLeftTop;
692 crLeftTop = crRightBottom;
693 crRightBottom = crTemp;
697 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
698 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
702 FontMap.SetAPType("D");
704 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, CPWL_Utils::SubstractColor(crBackground,0.25f)) +
705 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) +
706 CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);
708 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);
710 AddImageToAppearance("D", pDownIcon);
714 RemoveAppearance("D");
715 RemoveAppearance("R");
719 void CPDFSDK_Widget::ResetAppearance_CheckBox()
721 CPDF_FormControl* pControl = GetFormControl();
722 ASSERT(pControl != NULL);
726 CPWL_Color crBackground, crBorder, crText;
731 pControl->GetOriginalBackgroundColor(iColorType, fc);
733 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
735 pControl->GetOriginalBorderColor(iColorType, fc);
737 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
739 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
740 FX_INT32 nBorderStyle = 0;
741 CPWL_Dash dsBorder(3,0,0);
742 CPWL_Color crLeftTop,crRightBottom;
744 switch (GetBorderStyle())
747 nBorderStyle = PBS_DASH;
748 dsBorder = CPWL_Dash(3, 3, 0);
751 nBorderStyle = PBS_BEVELED;
753 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
754 crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
757 nBorderStyle = PBS_INSET;
759 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
760 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
763 nBorderStyle = PBS_UNDERLINED;
766 nBorderStyle = PBS_SOLID;
770 CPDF_Rect rcWindow = GetRotatedRect();
771 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);
773 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
776 da.GetColor(iColorType, fc);
777 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
782 CFX_WideString csWCaption = pControl->GetNormalCaption();
783 if (csWCaption.GetLength() > 0)
785 switch (csWCaption[0])
794 nStyle = PCS_DIAMOND;
812 CFX_ByteString csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) +
813 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
815 CFX_ByteString csAP_N_OFF = csAP_N_ON;
817 switch (nBorderStyle)
821 CPWL_Color crTemp = crLeftTop;
822 crLeftTop = crRightBottom;
823 crRightBottom = crTemp;
827 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
828 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
832 CFX_ByteString csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) +
833 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
835 CFX_ByteString csAP_D_OFF = csAP_D_ON;
837 csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);
838 csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);
840 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());
841 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
843 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());
844 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
846 CFX_ByteString csAS = GetAppState();
851 void CPDFSDK_Widget::ResetAppearance_RadioButton()
853 CPDF_FormControl* pControl = GetFormControl();
854 ASSERT(pControl != NULL);
858 CPWL_Color crBackground, crBorder, crText;
863 pControl->GetOriginalBackgroundColor(iColorType, fc);
865 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
867 pControl->GetOriginalBorderColor(iColorType, fc);
869 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
871 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
872 FX_INT32 nBorderStyle = 0;
873 CPWL_Dash dsBorder(3,0,0);
874 CPWL_Color crLeftTop,crRightBottom;
876 switch (GetBorderStyle())
879 nBorderStyle = PBS_DASH;
880 dsBorder = CPWL_Dash(3, 3, 0);
883 nBorderStyle = PBS_BEVELED;
885 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
886 crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
889 nBorderStyle = PBS_INSET;
891 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
892 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
895 nBorderStyle = PBS_UNDERLINED;
898 nBorderStyle = PBS_SOLID;
902 CPDF_Rect rcWindow = GetRotatedRect();
903 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
905 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
908 da.GetColor(iColorType, fc);
909 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
914 CFX_WideString csWCaption = pControl->GetNormalCaption();
915 if (csWCaption.GetLength() > 0)
917 switch (csWCaption[0])
926 nStyle = PCS_DIAMOND;
944 CFX_ByteString csAP_N_ON;
946 CPDF_Rect rcCenter = CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);
948 if (nStyle == PCS_CIRCLE)
950 if (nBorderStyle == PBS_BEVELED)
952 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
953 crRightBottom = CPWL_Utils::SubstractColor(crBackground,0.25f);
955 else if (nBorderStyle == PBS_INSET)
957 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5f);
958 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75f);
961 csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBackground) +
962 CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
966 csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) +
967 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
970 CFX_ByteString csAP_N_OFF = csAP_N_ON;
972 switch (nBorderStyle)
976 CPWL_Color crTemp = crLeftTop;
977 crLeftTop = crRightBottom;
978 crRightBottom = crTemp;
982 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
983 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
987 CFX_ByteString csAP_D_ON;
989 if (nStyle == PCS_CIRCLE)
991 CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground,0.25f);
992 if (nBorderStyle == PBS_BEVELED)
994 crLeftTop = CPWL_Utils::SubstractColor(crBackground,0.25f);
995 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
998 else if (nBorderStyle == PBS_INSET)
1000 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
1001 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
1004 csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBK)
1005 + CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
1009 csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::SubstractColor(crBackground,0.25f)) +
1010 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
1013 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1015 csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);
1016 csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);
1018 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->GetCheckedAPState());
1019 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1021 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->GetCheckedAPState());
1022 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1024 CFX_ByteString csAS = GetAppState();
1029 void CPDFSDK_Widget::ResetAppearance_ComboBox(FX_LPCWSTR sValue)
1031 CPDF_FormControl* pControl = GetFormControl();
1032 ASSERT(pControl != NULL);
1033 CPDF_FormField* pField = pControl->GetField();
1034 ASSERT(pField != NULL);
1036 CFX_ByteTextBuf sBody, sLines;
1038 CPDF_Rect rcClient = GetClientRect();
1039 CPDF_Rect rcButton = rcClient;
1040 rcButton.left = rcButton.right - 13;
1041 rcButton.Normalize();
1043 if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
1045 pEdit->EnableRefresh(FALSE);
1047 ASSERT(this->m_pInterForm != NULL);
1048 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1049 ASSERT(pDoc != NULL);
1050 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1051 CBA_FontMap FontMap(this,pEnv->GetSysHandler());
1053 pEdit->SetFontMap(&FontMap);
1055 CPDF_Rect rcEdit = rcClient;
1056 rcEdit.right = rcButton.left;
1059 pEdit->SetPlateRect(rcEdit);
1060 pEdit->SetAlignmentV(1);
1062 FX_FLOAT fFontSize = this->GetFontSize();
1063 if (IsFloatZero(fFontSize))
1064 pEdit->SetAutoFontSize(TRUE);
1066 pEdit->SetFontSize(fFontSize);
1068 pEdit->Initialize();
1071 pEdit->SetText(sValue);
1074 FX_INT32 nCurSel = pField->GetSelectedIndex(0);
1077 pEdit->SetText((FX_LPCWSTR)pField->GetValue());
1079 pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(nCurSel));
1082 CPDF_Rect rcContent = pEdit->GetContentRect();
1084 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f));
1085 if (sEdit.GetLength() > 0)
1087 sBody << "/Tx BMC\n" << "q\n";
1088 if (rcContent.Width() > rcEdit.Width() ||
1089 rcContent.Height() > rcEdit.Height())
1091 sBody << rcEdit.left << " " << rcEdit.bottom << " "
1092 << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n";
1095 CPWL_Color crText = GetTextPWLColor();
1096 sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";
1099 IFX_Edit::DelEdit(pEdit);
1102 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
1104 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
1106 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1109 void CPDFSDK_Widget::ResetAppearance_ListBox()
1111 CPDF_FormControl* pControl = GetFormControl();
1112 ASSERT(pControl != NULL);
1113 CPDF_FormField* pField = pControl->GetField();
1114 ASSERT(pField != NULL);
1116 CPDF_Rect rcClient = GetClientRect();
1118 CFX_ByteTextBuf sBody, sLines;
1120 if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
1122 pEdit->EnableRefresh(FALSE);
1124 // ASSERT(this->m_pBaseForm != NULL);
1125 ASSERT(this->m_pInterForm != NULL);
1126 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1127 ASSERT(pDoc != NULL);
1128 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1130 CBA_FontMap FontMap(this,pEnv->GetSysHandler());
1132 pEdit->SetFontMap(&FontMap);
1134 pEdit->SetPlateRect(CPDF_Rect(rcClient.left,0.0f,rcClient.right,0.0f));
1136 FX_FLOAT fFontSize = GetFontSize();
1138 if (IsFloatZero(fFontSize))
1139 pEdit->SetFontSize(12.0f);
1141 pEdit->SetFontSize(fFontSize);
1143 pEdit->Initialize();
1145 CFX_ByteTextBuf sList;
1146 FX_FLOAT fy = rcClient.top;
1148 FX_INT32 nTop = pField->GetTopVisibleIndex();
1149 FX_INT32 nCount = pField->CountOptions();
1150 FX_INT32 nSelCount = pField->CountSelectedItems();
1152 for (FX_INT32 i=nTop; i<nCount; i++)
1154 FX_BOOL bSelected = FALSE;
1155 for (FX_INT32 j=0; j<nSelCount; j++)
1157 if (pField->GetSelectedIndex(j) == i)
1164 pEdit->SetText((FX_LPCWSTR)pField->GetOptionLabel(i));
1166 CPDF_Rect rcContent = pEdit->GetContentRect();
1167 FX_FLOAT fItemHeight = rcContent.Height();
1171 CPDF_Rect rcItem = CPDF_Rect(rcClient.left,fy-fItemHeight,rcClient.right,fy);
1172 sList << "q\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB,0,51.0f/255.0f,113.0f/255.0f),TRUE)
1173 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() << " " << rcItem.Height() << " re f\n" << "Q\n";
1175 sList << "BT\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY,1),TRUE) <<
1176 CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";
1180 CPWL_Color crText = GetTextPWLColor();
1181 sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) <<
1182 CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n";
1188 if (sList.GetSize() > 0)
1190 sBody << "/Tx BMC\n" << "q\n" << rcClient.left << " " << rcClient.bottom << " "
1191 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1192 sBody << sList << "Q\nEMC\n";
1195 IFX_Edit::DelEdit(pEdit);
1198 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
1200 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1203 void CPDFSDK_Widget::ResetAppearance_TextField(FX_LPCWSTR sValue)
1205 CPDF_FormControl* pControl = GetFormControl();
1206 ASSERT(pControl != NULL);
1207 CPDF_FormField* pField = pControl->GetField();
1208 ASSERT(pField != NULL);
1210 CFX_ByteTextBuf sBody, sLines;
1212 if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
1214 pEdit->EnableRefresh(FALSE);
1216 // ASSERT(this->m_pBaseForm != NULL);
1217 ASSERT(this->m_pInterForm != NULL);
1218 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1219 ASSERT(pDoc != NULL);
1220 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1222 CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystemHandler(m_pBaseForm->GetEnv()));
1224 pEdit->SetFontMap(&FontMap);
1226 CPDF_Rect rcClient = GetClientRect();
1227 pEdit->SetPlateRect(rcClient);
1228 pEdit->SetAlignmentH(pControl->GetControlAlignment());
1230 FX_DWORD dwFieldFlags = pField->GetFieldFlags();
1231 FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1;
1235 pEdit->SetMultiLine(TRUE);
1236 pEdit->SetAutoReturn(TRUE);
1240 pEdit->SetAlignmentV(1);
1243 FX_WORD subWord = 0;
1244 if ((dwFieldFlags >> 13) & 1)
1247 pEdit->SetPasswordChar(subWord);
1250 int nMaxLen = pField->GetMaxLen();
1251 FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
1252 FX_FLOAT fFontSize = GetFontSize();
1258 pEdit->SetCharArray(nMaxLen);
1260 if (IsFloatZero(fFontSize))
1262 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(FontMap.GetPDFFont(0),rcClient,nMaxLen);
1268 nMaxLen = wcslen((const wchar_t*)sValue);
1269 pEdit->SetLimitChar(nMaxLen);
1273 if (IsFloatZero(fFontSize))
1274 pEdit->SetAutoFontSize(TRUE);
1276 pEdit->SetFontSize(fFontSize);
1278 pEdit->Initialize();
1281 pEdit->SetText(sValue);
1283 pEdit->SetText((FX_LPCWSTR)pField->GetValue());
1285 CPDF_Rect rcContent = pEdit->GetContentRect();
1287 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,0.0f),
1288 NULL,!bCharArray,subWord);
1290 if (sEdit.GetLength() > 0)
1292 sBody << "/Tx BMC\n" << "q\n";
1293 if (rcContent.Width() > rcClient.Width() ||
1294 rcContent.Height() > rcClient.Height())
1296 sBody << rcClient.left << " " << rcClient.bottom << " "
1297 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1299 CPWL_Color crText = GetTextPWLColor();
1300 sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";
1305 switch (GetBorderStyle())
1309 CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);
1310 if (sColor.GetLength() > 0)
1312 sLines << "q\n" << GetBorderWidth() << " w\n"
1313 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE) << " 2 J 0 j\n";
1315 for (FX_INT32 i=1;i<nMaxLen;i++)
1317 sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
1318 << rcClient.bottom << " m\n"
1319 << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
1320 << rcClient.top << " l S\n";
1329 CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE);
1330 if (sColor.GetLength() > 0)
1332 CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
1334 sLines << "q\n" << GetBorderWidth() << " w\n"
1335 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(),FALSE)
1336 << "[" << dsBorder.nDash << " "
1337 << dsBorder.nGap << "] "
1338 << dsBorder.nPhase << " d\n";
1340 for (FX_INT32 i=1;i<nMaxLen;i++)
1342 sLines << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
1343 << rcClient.bottom << " m\n"
1344 << rcClient.left + ((rcClient.right - rcClient.left)/nMaxLen)*i << " "
1345 << rcClient.top << " l S\n";
1355 IFX_Edit::DelEdit(pEdit);
1358 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.GetByteString() + sBody.GetByteString();
1359 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1362 CPDF_Rect CPDFSDK_Widget::GetClientRect() const
1364 CPDF_Rect rcWindow = GetRotatedRect();
1365 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1366 switch (GetBorderStyle())
1370 fBorderWidth *= 2.0f;
1374 return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
1377 CPDF_Rect CPDFSDK_Widget::GetRotatedRect() const
1379 CPDF_Rect rectAnnot = GetRect();
1380 FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
1381 FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
1383 CPDF_FormControl* pControl = GetFormControl();
1384 ASSERT(pControl != NULL);
1386 CPDF_Rect rcPDFWindow;
1387 switch(abs(pControl->GetRotation() % 360))
1392 rcPDFWindow = CPDF_Rect(0, 0, fWidth, fHeight);
1396 rcPDFWindow = CPDF_Rect(0, 0, fHeight, fWidth);
1403 CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const
1405 CPWL_Color crBackground = GetFillPWLColor();
1406 if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
1407 return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
1412 CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const
1414 CPDF_Rect rcWindow = GetRotatedRect();
1415 CPWL_Color crBorder = GetBorderPWLColor();
1416 CPWL_Color crBackground = GetFillPWLColor();
1417 CPWL_Color crLeftTop, crRightBottom;
1419 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1420 FX_INT32 nBorderStyle = 0;
1421 CPWL_Dash dsBorder(3,0,0);
1423 switch (GetBorderStyle())
1426 nBorderStyle = PBS_DASH;
1427 dsBorder = CPWL_Dash(3, 3, 0);
1430 nBorderStyle = PBS_BEVELED;
1432 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1433 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1436 nBorderStyle = PBS_INSET;
1438 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1439 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1442 nBorderStyle = PBS_UNDERLINED;
1445 nBorderStyle = PBS_SOLID;
1449 return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop,
1450 crRightBottom, nBorderStyle, dsBorder);
1453 CPDF_Matrix CPDFSDK_Widget::GetMatrix() const
1456 CPDF_FormControl* pControl = GetFormControl();
1457 ASSERT(pControl != NULL);
1459 CPDF_Rect rcAnnot = GetRect();
1460 FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left;
1461 FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom;
1465 switch (abs(pControl->GetRotation() % 360))
1469 mt = CPDF_Matrix(1, 0, 0, 1, 0, 0);
1472 mt = CPDF_Matrix(0, 1, -1, 0, fWidth, 0);
1475 mt = CPDF_Matrix(-1, 0, 0, -1, fWidth, fHeight);
1478 mt = CPDF_Matrix(0, -1, 1, 0, 0, fHeight);
1485 CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const
1487 CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);
1489 CPDF_FormControl* pFormCtrl = GetFormControl();
1490 ASSERT(pFormCtrl != NULL);
1492 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
1495 FX_INT32 iColorType;
1497 da.GetColor(iColorType, fc);
1498 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1504 CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const
1506 CPWL_Color crBorder;
1508 CPDF_FormControl* pFormCtrl = GetFormControl();
1509 ASSERT(pFormCtrl != NULL);
1511 FX_INT32 iColorType;
1513 pFormCtrl->GetOriginalBorderColor(iColorType, fc);
1515 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1520 CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const
1524 CPDF_FormControl* pFormCtrl = GetFormControl();
1525 ASSERT(pFormCtrl != NULL);
1527 FX_INT32 iColorType;
1529 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
1531 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1536 void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage)
1538 ASSERT(pImage != NULL);
1540 ASSERT(m_pAnnot != NULL);
1541 ASSERT(m_pAnnot->m_pAnnotDict != NULL);
1543 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();//pDocument->GetDocument();
1544 ASSERT(pDoc != NULL);
1546 CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP");
1547 ASSERT(pAPDict != NULL);
1549 CPDF_Stream* pStream = pAPDict->GetStream(sAPType);
1550 ASSERT(pStream != NULL);
1552 CPDF_Dictionary* pStreamDict = pStream->GetDict();
1553 ASSERT(pStreamDict != NULL);
1555 CFX_ByteString sImageAlias = "IMG";
1557 if (CPDF_Dictionary* pImageDict = pImage->GetDict())
1559 sImageAlias = pImageDict->GetString("Name");
1560 if (sImageAlias.IsEmpty())
1561 sImageAlias = "IMG";
1564 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");
1565 if (!pStreamResList)
1567 pStreamResList = FX_NEW CPDF_Dictionary();
1568 pStreamDict->SetAt("Resources", pStreamResList);
1573 CPDF_Dictionary* pXObject = FX_NEW CPDF_Dictionary;
1574 pXObject->SetAtReference(sImageAlias, pDoc, pImage);
1575 pStreamResList->SetAt("XObject", pXObject);
1579 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType)
1581 ASSERT(m_pAnnot != NULL);
1582 ASSERT(m_pAnnot->m_pAnnotDict != NULL);
1584 if (CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP"))
1586 pAPDict->RemoveAt(sAPType);
1590 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView)
1592 CPDF_Action action = GetAAction(type);
1594 if (action && action.GetType() != CPDF_Action::Unknown)
1596 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
1597 ASSERT(pDocument != NULL);
1599 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
1600 ASSERT(pEnv != NULL);
1602 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();/*(CPDFSDK_ActionHandler*)pApp->GetActionHandler();*/
1603 ASSERT(pActionHandler != NULL);
1605 return pActionHandler->DoAction_Field(action, type, pDocument, GetFormField(), data);
1611 CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT)
1615 case CPDF_AAction::CursorEnter:
1616 case CPDF_AAction::CursorExit:
1617 case CPDF_AAction::ButtonDown:
1618 case CPDF_AAction::ButtonUp:
1619 case CPDF_AAction::GetFocus:
1620 case CPDF_AAction::LoseFocus:
1621 case CPDF_AAction::PageOpen:
1622 case CPDF_AAction::PageClose:
1623 case CPDF_AAction::PageVisible:
1624 case CPDF_AAction::PageInvisible:
1625 return CPDFSDK_Annot::GetAAction(eAAT);
1626 case CPDF_AAction::KeyStroke:
1627 case CPDF_AAction::Format:
1628 case CPDF_AAction::Validate:
1629 case CPDF_AAction::Calculate:
1631 CPDF_FormField* pField = this->GetFormField();
1632 ASSERT(pField != NULL);
1634 if (CPDF_AAction aa = pField->GetAdditionalAction())
1635 return aa.GetAction(eAAT);
1637 return CPDFSDK_Annot::GetAAction(eAAT);
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 ASSERT(pWidget != NULL);
1733 CBA_AnnotIterator* pIterator = new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "");
1734 ASSERT(pIterator != NULL);
1736 CPDFSDK_Widget* pRet = NULL;
1739 pRet = (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget);
1741 pRet = (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);
1743 pIterator->Release();
1749 CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const
1751 if(!pControl || !m_pInterForm) return NULL;
1753 CPDFSDK_Widget* pWidget = NULL;
1754 m_Map.Lookup(pControl, pWidget);
1756 if (pWidget) return pWidget;
1758 CPDF_Dictionary* pControlDict = pControl->GetWidget();
1759 ASSERT(pControlDict != NULL);
1761 ASSERT(m_pDocument != NULL);
1762 CPDF_Document* pDocument = m_pDocument->GetDocument();
1764 CPDFSDK_PageView* pPage = NULL;
1766 if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P"))
1768 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
1769 if (nPageIndex >= 0)
1771 pPage = m_pDocument->GetPageView(nPageIndex);
1777 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);
1778 if (nPageIndex >= 0)
1780 pPage = m_pDocument->GetPageView(nPageIndex);
1785 return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
1790 void CPDFSDK_InterForm::GetWidgets(const CFX_WideString& sFieldName, CFX_PtrArray& widgets)
1792 ASSERT(m_pInterForm != NULL);
1794 for (int i=0,sz=m_pInterForm->CountFields(sFieldName); i<sz; i++)
1796 CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName);
1797 ASSERT(pFormField != NULL);
1799 GetWidgets(pFormField, widgets);
1803 void CPDFSDK_InterForm::GetWidgets(CPDF_FormField* pField, CFX_PtrArray& widgets)
1805 ASSERT(pField != NULL);
1807 for (int i=0,isz=pField->CountControls(); i<isz; i++)
1809 CPDF_FormControl* pFormCtrl = pField->GetControl(i);
1810 ASSERT(pFormCtrl != NULL);
1812 CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);
1815 widgets.Add(pWidget);
1819 int CPDFSDK_InterForm::GetPageIndexByAnnotDict(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict) const
1821 ASSERT(pDocument != NULL);
1822 ASSERT(pAnnotDict != NULL);
1824 for (int i=0,sz=pDocument->GetPageCount(); i<sz; i++)
1826 if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i))
1828 if (CPDF_Array* pAnnots = pPageDict->GetArray("Annots"))
1830 for (int j=0,jsz=pAnnots->GetCount(); j<jsz; j++)
1832 CPDF_Object* pDict = pAnnots->GetElementValue(j);
1833 if (pAnnotDict == pDict)
1845 void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget)
1847 m_Map.SetAt(pControl, pWidget);
1850 void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl)
1852 m_Map.RemoveKey(pControl);
1855 void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled)
1857 m_bCalculate = bEnabled;
1860 FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const
1862 return m_bCalculate;
1866 CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile)
1868 ASSERT(m_pDocument != NULL);
1869 CPDF_Document* pDocument = m_pDocument->GetDocument();
1870 ASSERT(pDocument != NULL);
1872 CPDF_Stream* pRetStream = NULL;
1874 if (CFX_DIBitmap* pBmp = CFX_WindowsDIB::LoadFromFile(sFile))
1876 int nWidth = pBmp->GetWidth();
1877 int nHeight = pBmp->GetHeight();
1879 CPDF_Image Image(pDocument);
1880 Image.SetImage(pBmp, FALSE);
1881 CPDF_Stream* pImageStream = Image.GetStream();
1884 if (pImageStream->GetObjNum() == 0)
1885 pDocument->AddIndirectObject(pImageStream);
1887 CPDF_Dictionary* pStreamDict = new CPDF_Dictionary();
1888 pStreamDict->SetAtName("Subtype", "Form");
1889 pStreamDict->SetAtName("Name", "IMG");
1890 CPDF_Array* pMatrix = new CPDF_Array();
1891 pStreamDict->SetAt("Matrix", pMatrix);
1892 pMatrix->AddInteger(1);
1893 pMatrix->AddInteger(0);
1894 pMatrix->AddInteger(0);
1895 pMatrix->AddInteger(1);
1896 pMatrix->AddInteger(-nWidth / 2);
1897 pMatrix->AddInteger(-nHeight / 2);
1898 CPDF_Dictionary* pResource = new CPDF_Dictionary();
1899 pStreamDict->SetAt("Resources", pResource);
1900 CPDF_Dictionary* pXObject = new CPDF_Dictionary();
1901 pResource->SetAt("XObject", pXObject);
1902 pXObject->SetAtReference("Img", pDocument, pImageStream);
1903 CPDF_Array* pProcSet = new CPDF_Array();
1904 pResource->SetAt("ProcSet", pProcSet);
1905 pProcSet->AddName("PDF");
1906 pProcSet->AddName("ImageC");
1907 pStreamDict->SetAtName("Type", "XObject");
1908 CPDF_Array* pBBox = new CPDF_Array();
1909 pStreamDict->SetAt("BBox", pBBox);
1910 pBBox->AddInteger(0);
1911 pBBox->AddInteger(0);
1912 pBBox->AddInteger(nWidth);
1913 pBBox->AddInteger(nHeight);
1914 pStreamDict->SetAtInteger("FormType", 1);
1916 pRetStream = new CPDF_Stream(NULL, 0, NULL);
1917 CFX_ByteString csStream;
1918 csStream.Format("q\n%d 0 0 %d 0 0 cm\n/Img Do\nQ", nWidth, nHeight);
1919 pRetStream->InitStream((FX_BYTE*)(FX_LPCSTR)csStream, csStream.GetLength(), pStreamDict);
1920 pDocument->AddIndirectObject(pRetStream);
1930 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField)
1932 ASSERT(m_pDocument != NULL);
1933 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
1935 if(!pEnv->IsJSInitiated())
1938 if (m_bBusy) return;
1942 if (this->IsCalculateEnabled())
1944 IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
1945 ASSERT(pRuntime != NULL);
1947 pRuntime->SetReaderDocument(m_pDocument);
1949 int nSize = m_pInterForm->CountFieldsInCalculationOrder();
1950 for (int i=0; i<nSize; i++)
1952 if(CPDF_FormField* pField = m_pInterForm->GetFieldInCalculationOrder(i))
1954 // ASSERT(pField != NULL);
1955 int nType = pField->GetFieldType();
1956 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
1958 CPDF_AAction aAction = pField->GetAdditionalAction();
1959 if (aAction && aAction.ActionExist(CPDF_AAction::Calculate))
1961 CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate);
1964 CFX_WideString csJS = action.GetJavaScript();
1965 if (!csJS.IsEmpty())
1967 IFXJS_Context* pContext = pRuntime->NewContext();
1968 ASSERT(pContext != NULL);
1970 CFX_WideString sOldValue = pField->GetValue();
1971 CFX_WideString sValue = sOldValue;
1973 pContext->OnField_Calculate(pFormField, pField, sValue, bRC);
1975 CFX_WideString sInfo;
1976 FX_BOOL bRet = pContext->RunScript(csJS, sInfo);
1977 pRuntime->ReleaseContext(pContext);
1983 if (sValue.Compare(sOldValue) != 0)
1984 pField->SetValue(sValue, TRUE);
2000 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, int nCommitKey, FX_BOOL& bFormated)
2002 ASSERT(m_pDocument != NULL);
2003 ASSERT(pFormField != NULL);
2005 CFX_WideString sValue = pFormField->GetValue();
2006 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2008 if(!pEnv->IsJSInitiated())
2014 IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
2015 ASSERT(pRuntime != NULL);
2017 pRuntime->SetReaderDocument(m_pDocument);
2019 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)
2021 if (pFormField->CountSelectedItems() > 0)
2023 int index = pFormField->GetSelectedIndex(0);
2025 sValue = pFormField->GetOptionLabel(index);
2031 CPDF_AAction aAction = pFormField->GetAdditionalAction();
2032 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format))
2034 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);
2037 CFX_WideString script = action.GetJavaScript();
2038 if (!script.IsEmpty())
2040 CFX_WideString Value = sValue;
2042 IFXJS_Context* pContext = pRuntime->NewContext();
2043 ASSERT(pContext != NULL);
2045 pContext->OnField_Format(nCommitKey, pFormField, Value, TRUE);
2047 CFX_WideString sInfo;
2048 FX_BOOL bRet = pContext->RunScript(script, sInfo);
2049 pRuntime->ReleaseContext(pContext);
2063 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, FX_LPCWSTR sValue, FX_BOOL bValueChanged)
2065 ASSERT(pFormField != NULL);
2067 for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
2069 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
2070 ASSERT(pFormCtrl != NULL);
2072 ASSERT(m_pInterForm != NULL);
2073 if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
2074 pWidget->ResetAppearance(sValue, bValueChanged);
2078 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField)
2080 ASSERT(pFormField != NULL);
2082 for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
2084 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
2085 ASSERT(pFormCtrl != NULL);
2087 if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
2089 CPDFDoc_Environment * pEnv = m_pDocument->GetEnv();
2090 CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller();
2092 CPDF_Page * pPage = pWidget->GetPDFPage();
2093 CPDFSDK_PageView * pPageView = m_pDocument->GetPageView(pPage,FALSE);
2095 FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget);
2097 pEnv->FFI_Invalidate(pPage,rcBBox.left, rcBBox.top, rcBBox.right, rcBBox.bottom);
2102 void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)
2104 ASSERT(pFormField != NULL);
2106 CPDF_AAction aAction = pFormField->GetAdditionalAction();
2107 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::KeyStroke))
2109 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);
2112 ASSERT(m_pDocument != NULL);
2113 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2114 ASSERT(pEnv != NULL);
2116 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
2117 ASSERT(pActionHandler != NULL);
2119 PDFSDK_FieldAction fa;
2120 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
2121 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
2122 fa.sValue = csValue;
2124 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke,
2125 m_pDocument, pFormField, fa);
2131 void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC)
2133 ASSERT(pFormField != NULL);
2135 CPDF_AAction aAction = pFormField->GetAdditionalAction();
2136 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Validate))
2138 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);
2141 ASSERT(m_pDocument != NULL);
2142 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2143 ASSERT(pEnv != NULL);
2145 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
2146 ASSERT(pActionHandler != NULL);
2148 PDFSDK_FieldAction fa;
2149 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
2150 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
2151 fa.sValue = csValue;
2153 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, m_pDocument, pFormField, fa);
2160 /* ----------------------------- action ----------------------------- */
2162 FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action)
2164 ASSERT(action != NULL);
2166 CPDF_ActionFields af = action.GetWidgets();
2167 CFX_PtrArray fieldObjects;
2168 af.GetAllFields(fieldObjects);
2169 CFX_PtrArray widgetArray;
2170 CFX_PtrArray fields;
2171 GetFieldFromObjects(fieldObjects, fields);
2173 FX_BOOL bHide = action.GetHideStatus();
2175 FX_BOOL bChanged = FALSE;
2177 for (int i=0, sz=fields.GetSize(); i<sz; i++)
2179 CPDF_FormField* pField = (CPDF_FormField*)fields[i];
2180 ASSERT(pField != NULL);
2183 for (int j=0,jsz=pField->CountControls(); j<jsz; j++)
2185 CPDF_FormControl* pControl = pField->GetControl(j);
2186 ASSERT(pControl != NULL);
2188 if (CPDFSDK_Widget* pWidget = GetWidget(pControl))
2190 int nFlags = pWidget->GetFlags();
2193 nFlags &= (~ANNOTFLAG_INVISIBLE);
2194 nFlags &= (~ANNOTFLAG_NOVIEW);
2195 nFlags |= (ANNOTFLAG_HIDDEN);
2199 nFlags &= (~ANNOTFLAG_INVISIBLE);
2200 nFlags &= (~ANNOTFLAG_HIDDEN);
2201 nFlags &= (~ANNOTFLAG_NOVIEW);
2203 pWidget->SetFlags(nFlags);
2205 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
2206 ASSERT(pPageView != NULL);
2208 pPageView->UpdateView(pWidget);
2218 FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action)
2220 ASSERT(action != NULL);
2221 ASSERT(m_pInterForm != NULL);
2223 CFX_WideString sDestination = action.GetFilePath();
2224 if (sDestination.IsEmpty()) return FALSE;
2226 CPDF_Dictionary* pActionDict = action;
2227 if (pActionDict->KeyExist("Fields"))
2229 CPDF_ActionFields af = action.GetWidgets();
2230 FX_DWORD dwFlags = action.GetFlags();
2232 CFX_PtrArray fieldObjects;
2233 af.GetAllFields(fieldObjects);
2234 CFX_PtrArray fields;
2235 GetFieldFromObjects(fieldObjects, fields);
2237 if (fields.GetSize() != 0)
2239 FX_BOOL bIncludeOrExclude = !(dwFlags & 0x01);
2240 if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude))
2244 return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE);
2248 if ( m_pInterForm->CheckRequiredFields())
2253 return SubmitForm(sDestination, FALSE);
2258 if ( m_pInterForm->CheckRequiredFields())
2263 return SubmitForm(sDestination, FALSE);
2267 FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination, const CFX_PtrArray& fields,
2268 FX_BOOL bIncludeOrExclude, FX_BOOL bUrlEncoded)
2270 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2271 ASSERT(pEnv != NULL);
2273 CFX_ByteTextBuf textBuf;
2274 ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);
2276 FX_LPBYTE pBuffer = textBuf.GetBuffer();
2277 FX_STRSIZE nBufSize = textBuf.GetLength();
2281 if(!FDFToURLEncodedData(pBuffer, nBufSize))
2285 pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)csDestination);
2287 if (bUrlEncoded && pBuffer)
2296 void CPDFSDK_InterForm::DoFDFBuffer(CFX_ByteString sBuffer)
2298 ASSERT(m_pDocument != NULL);
2300 if (CFDF_Document *pFDFDocument = CFDF_Document::ParseMemory((const unsigned char *)sBuffer.GetBuffer(sBuffer.GetLength()), sBuffer.GetLength()))
2302 CPDF_Dictionary* pRootDic = pFDFDocument->GetRoot();
2305 CPDF_Dictionary * pFDFDict=pRootDic->GetDict("FDF");
2308 CPDF_Dictionary * pJSDict = pFDFDict->GetDict("JavaScript");
2311 CFX_WideString csJS;
2313 CPDF_Object* pJS = pJSDict->GetElementValue("Before");
2316 int iType = pJS->GetType();
2317 if (iType == PDFOBJ_STRING)
2318 csJS = pJSDict->GetUnicodeText("Before");
2319 else if (iType == PDFOBJ_STREAM)
2320 csJS = pJS->GetUnicodeText();
2326 delete pFDFDocument;
2329 sBuffer.ReleaseBuffer();
2332 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile)
2337 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(FX_LPBYTE& pBuf, FX_STRSIZE& nBufSize)
2339 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);
2342 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
2343 if (pMainDict == NULL) return FALSE;
2346 CPDF_Array* pFields = pMainDict->GetArray("Fields");
2347 if (pFields == NULL) return FALSE;
2349 CFX_ByteTextBuf fdfEncodedData;
2351 for (FX_DWORD i = 0; i < pFields->GetCount(); i ++)
2353 CPDF_Dictionary* pField = pFields->GetDict(i);
2354 if (pField == NULL) continue;
2355 CFX_WideString name;
2356 name = pField->GetUnicodeText("T");
2357 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);
2358 CFX_ByteString csBValue = pField->GetString("V");
2359 CFX_WideString csWValue = PDF_DecodeText(csBValue);
2360 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);
2362 fdfEncodedData = fdfEncodedData<<name_b.GetBuffer(name_b.GetLength());
2363 name_b.ReleaseBuffer();
2364 fdfEncodedData = fdfEncodedData<<"=";
2365 fdfEncodedData = fdfEncodedData<<csValue_b.GetBuffer(csValue_b.GetLength());
2366 csValue_b.ReleaseBuffer();
2367 if(i != pFields->GetCount()-1)
2368 fdfEncodedData = fdfEncodedData<<"&";
2371 nBufSize = fdfEncodedData.GetLength();
2372 pBuf = FX_Alloc(FX_BYTE, nBufSize);
2375 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
2381 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFFile(const CFX_WideString& sFDFFileName,
2382 const CFX_PtrArray& fields, FX_BOOL bIncludeOrExclude)
2384 if (sFDFFileName.IsEmpty()) return FALSE;
2385 ASSERT(m_pDocument != NULL);
2386 ASSERT(m_pInterForm != NULL);
2388 CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude);
2389 if (!pFDF) return FALSE;
2390 FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode()); // = FALSE;//
2395 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,FX_BOOL bIncludeOrExclude, CFX_ByteTextBuf& textBuf)
2397 ASSERT(m_pDocument != NULL);
2398 ASSERT(m_pInterForm != NULL);
2400 CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_PtrArray&)fields, bIncludeOrExclude);
2401 if (!pFDF) return FALSE;
2402 FX_BOOL bRet = pFDF->WriteBuf(textBuf); // = FALSE;//
2408 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(const CFX_WideString& sFileExt)
2410 CFX_WideString sFileName;
2414 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, FX_BOOL bUrlEncoded)
2416 if (sDestination.IsEmpty()) return FALSE;
2418 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2419 ASSERT(pEnv != NULL);
2421 if(NULL == m_pDocument) return FALSE;
2422 CFX_WideString wsPDFFilePath = m_pDocument->GetPath();
2424 if(NULL == m_pInterForm) return FALSE;
2425 CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath);
2426 if (NULL == pFDFDoc) return FALSE;
2428 CFX_ByteTextBuf FdfBuffer;
2429 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);
2431 if (!bRet) return FALSE;
2433 FX_LPBYTE pBuffer = FdfBuffer.GetBuffer();
2434 FX_STRSIZE nBufSize = FdfBuffer.GetLength();
2438 if(!FDFToURLEncodedData(pBuffer, nBufSize))
2442 pEnv->JS_docSubmitForm(pBuffer, nBufSize, (FX_LPCWSTR)sDestination);
2444 if (bUrlEncoded && pBuffer)
2453 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFFile(const CFX_WideString& sFDFFileName)
2455 if (sFDFFileName.IsEmpty()) return FALSE;
2457 ASSERT(m_pInterForm != NULL);
2458 ASSERT(m_pDocument != NULL);
2460 CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());
2461 if (!pFDF) return FALSE;
2463 FX_BOOL bRet = pFDF->WriteFile(sFDFFileName.UTF8Encode());
2469 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf)
2472 ASSERT(m_pInterForm != NULL);
2473 ASSERT(m_pDocument != NULL);
2475 CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());
2476 if (!pFDF) return FALSE;
2478 FX_BOOL bRet = pFDF->WriteBuf(textBuf);
2484 FX_BOOL CPDFSDK_InterForm::ExportFormToTxtFile(const CFX_WideString& sTxtFileName)
2486 ASSERT(m_pInterForm != NULL);
2488 CFX_WideString sFieldNames;
2489 CFX_WideString sFieldValues;
2491 int nSize = m_pInterForm->CountFields();
2495 for (int i=0; i<nSize; i++)
2497 CPDF_FormField* pField = m_pInterForm->GetField(i);
2498 ASSERT(pField != NULL);
2502 sFieldNames += L"\t";
2503 sFieldValues += L"\t";
2505 sFieldNames += pField->GetFullName();
2506 sFieldValues += pField->GetValue();
2515 FX_BOOL CPDFSDK_InterForm::ImportFormFromTxtFile(const CFX_WideString& sTxtFileName)
2517 ASSERT(m_pInterForm != NULL);
2522 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action)
2524 ASSERT(action != NULL);
2526 CPDF_Dictionary* pActionDict = action;
2528 if (pActionDict->KeyExist("Fields"))
2530 CPDF_ActionFields af = action.GetWidgets();
2531 FX_DWORD dwFlags = action.GetFlags();
2533 CFX_PtrArray fieldObjects;
2534 af.GetAllFields(fieldObjects);
2535 CFX_PtrArray fields;
2536 GetFieldFromObjects(fieldObjects, fields);
2538 ASSERT(m_pInterForm != NULL);
2540 return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE);
2544 ASSERT(m_pInterForm != NULL);
2545 return m_pInterForm->ResetForm(TRUE);
2549 FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action)
2551 ASSERT(action != NULL);
2553 CFX_WideString sFilePath = action.GetFilePath();
2554 if (sFilePath.IsEmpty())
2557 if (!ImportFormFromFDFFile(sFilePath, TRUE))
2565 FX_BOOL CPDFSDK_InterForm::ImportFormFromFDFFile(const CFX_WideString& csFDFFileName,
2571 void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects, CFX_PtrArray& fields)
2573 ASSERT(m_pInterForm != NULL);
2575 int iCount = objects.GetSize();
2576 for (int i = 0; i < iCount; i ++)
2578 CPDF_Object* pObject = (CPDF_Object*)objects[i];
2579 if (pObject == NULL) continue;
2581 int iType = pObject->GetType();
2582 if (iType == PDFOBJ_STRING)
2584 CFX_WideString csName = pObject->GetUnicodeText();
2585 CPDF_FormField* pField = m_pInterForm->GetField(0, csName);
2589 else if (iType == PDFOBJ_DICTIONARY)
2591 if (m_pInterForm->IsValidFormField(pObject))
2592 fields.Add(pObject);
2597 /* ----------------------------- CPDF_FormNotify ----------------------------- */
2599 int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, CFX_WideString& csValue)
2601 ASSERT(pField != NULL);
2603 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2605 int nType = pFormField->GetFieldType();
2606 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
2609 OnKeyStrokeCommit(pFormField, csValue, bRC);
2612 OnValidate(pFormField, csValue, bRC);
2625 int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField)
2627 ASSERT(pField != NULL);
2629 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2630 int nType = pFormField->GetFieldType();
2632 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
2634 this->OnCalculate(pFormField);
2635 FX_BOOL bFormated = FALSE;
2636 CFX_WideString sValue = this->OnFormat(pFormField, 0, bFormated);
2638 this->ResetFieldAppearance(pFormField, sValue, TRUE);
2640 this->ResetFieldAppearance(pFormField, NULL, TRUE);
2641 this->UpdateField(pFormField);
2647 int CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField, CFX_WideString& csValue)
2649 ASSERT(pField != NULL);
2651 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2653 int nType = pFormField->GetFieldType();
2654 if (nType == FIELDTYPE_LISTBOX)
2657 OnKeyStrokeCommit(pFormField, csValue, bRC);
2660 OnValidate(pFormField, csValue, bRC);
2673 int CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField)
2675 ASSERT(pField != NULL);
2677 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2678 int nType = pFormField->GetFieldType();
2680 if (nType == FIELDTYPE_LISTBOX)
2682 this->OnCalculate(pFormField);
2683 this->ResetFieldAppearance(pFormField, NULL, TRUE);
2684 this->UpdateField(pFormField);
2690 int CPDFSDK_InterForm::AfterCheckedStatusChange(const CPDF_FormField* pField, const CFX_ByteArray& statusArray)
2692 ASSERT(pField != NULL);
2694 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2695 int nType = pFormField->GetFieldType();
2697 if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON)
2699 this->OnCalculate(pFormField);
2700 //this->ResetFieldAppearance(pFormField, NULL);
2701 this->UpdateField(pFormField);
2707 int CPDFSDK_InterForm::BeforeFormReset(const CPDF_InterForm* pForm)
2712 int CPDFSDK_InterForm::AfterFormReset(const CPDF_InterForm* pForm)
2714 this->OnCalculate(NULL);
2719 int CPDFSDK_InterForm::BeforeFormImportData(const CPDF_InterForm* pForm)
2724 int CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm)
2726 this->OnCalculate(NULL);
2731 FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType)
2733 if(nFieldType <1 || nFieldType > 6)
2735 return m_bNeedHightlight[nFieldType-1];
2738 void CPDFSDK_InterForm::RemoveAllHighLight()
2740 memset((void*)m_bNeedHightlight, 0, 6*sizeof(FX_BOOL));
2742 void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType)
2744 if(nFieldType <0 || nFieldType > 6) return;
2749 for(int i=0; i<6; i++)
2751 m_aHighlightColor[i] = clr;
2752 m_bNeedHightlight[i] = TRUE;
2758 m_aHighlightColor[nFieldType-1] = clr;
2759 m_bNeedHightlight[nFieldType-1] = TRUE;
2766 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType)
2768 if(nFieldType <0 || nFieldType >6) return FXSYS_RGB(255,255,255);
2770 return m_aHighlightColor[0];
2772 return m_aHighlightColor[nFieldType-1];
2775 /* ------------------------- CBA_AnnotIterator ------------------------- */
2777 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, const CFX_ByteString& sType, const CFX_ByteString& sSubType)
2778 :m_pPageView(pPageView),
2780 m_sSubType(sSubType),
2781 m_nTabs(BAI_STRUCTURE)
2783 ASSERT(m_pPageView != NULL);
2785 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage();
2786 ASSERT(pPDFPage != NULL);
2787 ASSERT(pPDFPage->m_pFormDict != NULL);
2789 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetString("Tabs");
2795 else if (sTabs == "C")
2797 m_nTabs = BAI_COLUMN;
2801 m_nTabs = BAI_STRUCTURE;
2807 CBA_AnnotIterator::~CBA_AnnotIterator()
2809 m_Annots.RemoveAll();
2812 CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot()
2814 if (m_Annots.GetSize() > 0)
2820 CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot()
2822 if (m_Annots.GetSize() > 0)
2823 return m_Annots[m_Annots.GetSize() - 1];
2828 CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot)
2830 for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)
2832 if (m_Annots[i] == pAnnot)
2835 return m_Annots[i+1];
2844 CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot)
2846 for (int i=0,sz=m_Annots.GetSize(); i<sz; i++)
2848 if (m_Annots[i] == pAnnot)
2851 return m_Annots[i-1];
2853 return m_Annots[sz-1];
2860 int CBA_AnnotIterator::CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
2865 CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
2866 CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
2868 if (rcAnnot1.left < rcAnnot2.left)
2870 if (rcAnnot1.left > rcAnnot2.left)
2876 int CBA_AnnotIterator::CompareByTop(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
2881 CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
2882 CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
2884 if (rcAnnot1.top < rcAnnot2.top)
2886 if (rcAnnot1.top > rcAnnot2.top)
2891 void CBA_AnnotIterator::GenerateResults()
2893 ASSERT(m_pPageView != NULL);
2899 for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
2901 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2902 ASSERT(pAnnot != NULL);
2904 if (pAnnot->GetType() == m_sType
2905 && pAnnot->GetSubType() == m_sSubType)
2906 m_Annots.Add(pAnnot);
2912 CPDFSDK_SortAnnots sa;
2916 for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
2918 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2919 ASSERT(pAnnot != NULL);
2921 if (pAnnot->GetType() == m_sType
2922 && pAnnot->GetSubType() == m_sSubType)
2927 if (sa.GetSize() > 0)
2929 sa.Sort(CBA_AnnotIterator::CompareByLeft);
2932 while (sa.GetSize() > 0)
2934 int nLeftTopIndex = -1;
2937 FX_FLOAT fTop = 0.0f;
2939 for (int i=sa.GetSize()-1; i>=0; i--)
2941 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2942 ASSERT(pAnnot != NULL);
2944 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2946 if (rcAnnot.top > fTop)
2954 if (nLeftTopIndex >= 0)
2956 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
2957 ASSERT(pLeftTopAnnot != NULL);
2959 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
2961 m_Annots.Add(pLeftTopAnnot);
2962 sa.RemoveAt(nLeftTopIndex);
2964 CFX_ArrayTemplate<int> aSelect;
2967 for (int i=0,sz=sa.GetSize(); i<sz; i++)
2969 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2970 ASSERT(pAnnot != NULL);
2972 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2974 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
2976 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
2982 for (int i=0,sz=aSelect.GetSize(); i<sz; i++)
2984 m_Annots.Add(sa[aSelect[i]]);
2989 for (int i=aSelect.GetSize()-1; i>=0; i--)
2991 sa.RemoveAt(aSelect[i]);
2995 aSelect.RemoveAll();
3003 CPDFSDK_SortAnnots sa;
3006 for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
3008 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
3009 ASSERT(pAnnot != NULL);
3011 if (pAnnot->GetType() == m_sType
3012 && pAnnot->GetSubType() == m_sSubType)
3017 if (sa.GetSize() > 0)
3019 sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE);
3022 while (sa.GetSize() > 0)
3024 int nLeftTopIndex = -1;
3027 FX_FLOAT fLeft = -1.0f;
3029 for (int i=sa.GetSize()-1; i>=0; i--)
3031 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
3032 ASSERT(pAnnot != NULL);
3034 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
3039 fLeft = rcAnnot.left;
3041 else if (rcAnnot.left < fLeft)
3044 fLeft = rcAnnot.left;
3049 if (nLeftTopIndex >= 0)
3051 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
3052 ASSERT(pLeftTopAnnot != NULL);
3054 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
3056 m_Annots.Add(pLeftTopAnnot);
3057 sa.RemoveAt(nLeftTopIndex);
3059 CFX_ArrayTemplate<int> aSelect;
3062 for (int i=0,sz=sa.GetSize(); i<sz; i++)
3064 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
3065 ASSERT(pAnnot != NULL);
3067 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
3069 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
3071 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
3077 for (int i=0,sz=aSelect.GetSize(); i<sz; i++)
3079 m_Annots.Add(sa[aSelect[i]]);
3084 for (int i=aSelect.GetSize()-1; i>=0; i--)
3086 sa.RemoveAt(aSelect[i]);
3090 aSelect.RemoveAll();
3099 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot)
3101 ASSERT(pAnnot != NULL);
3103 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
3104 ASSERT(pPDFAnnot != NULL);
3107 pPDFAnnot->GetRect(rcAnnot);