1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef _FSDK_BASEFORM_H_ 8 #define _FSDK_BASEFORM_H_ 9 10 #if _FX_OS_ == _FX_ANDROID_ 11 #include "time.h" 12 #else 13 #include <ctime> 14 #endif 15 16 class CPDFSDK_Document; 17 class CPDFSDK_DateTime; 18 struct CPWL_Color; 19 class CFFL_FormFiller; 20 class CPDFSDK_PageView; 21 class CPDFSDK_InterForm; 22 23 24 typedef struct _PDFSDK_FieldAction 25 { 26 _PDFSDK_FieldAction() 27 { 28 bModifier = FALSE; 29 bShift = FALSE; 30 nCommitKey = 0; 31 bKeyDown = FALSE; 32 nSelEnd = nSelStart = 0; 33 bWillCommit = FALSE; 34 bFieldFull = FALSE; 35 bRC = TRUE; 36 } 37 38 FX_BOOL bModifier; //in 39 FX_BOOL bShift; //in 40 int nCommitKey; //in 41 CFX_WideString sChange; //in[out] 42 CFX_WideString sChangeEx; //in 43 FX_BOOL bKeyDown; //in 44 int nSelEnd; //in[out] 45 int nSelStart; //in[out] 46 CFX_WideString sValue; //in[out] 47 FX_BOOL bWillCommit; //in 48 FX_BOOL bFieldFull; //in 49 FX_BOOL bRC; //in[out] 50 }PDFSDK_FieldAction; 51 class CPDFSDK_Widget:public CPDFSDK_Annot 52 { 53 public: 54 CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm); 55 virtual ~CPDFSDK_Widget(); 56 57 virtual CFX_ByteString GetSubType() const; 58 59 virtual CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT); 60 61 int GetFieldType() const; 62 //define layout order to 2. 63 virtual int GetLayoutOrder() {return 2;} 64 /* 65 FIELDFLAG_READONLY 66 FIELDFLAG_REQUIRED 67 FIELDFLAG_NOEXPORT 68 */ 69 70 int GetFieldFlags() const; 71 int GetRotate() const; 72 73 FX_BOOL GetFillColor(FX_COLORREF& color) const; 74 FX_BOOL GetBorderColor(FX_COLORREF& color) const; 75 FX_BOOL GetTextColor(FX_COLORREF& color) const; 76 FX_FLOAT GetFontSize() const; 77 78 int GetSelectedIndex(int nIndex) const; 79 CFX_WideString GetValue() const; 80 CFX_WideString GetDefaultValue() const; 81 CFX_WideString GetOptionLabel(int nIndex) const; 82 int CountOptions() const; 83 FX_BOOL IsOptionSelected(int nIndex) const; 84 int GetTopVisibleIndex() const; 85 FX_BOOL IsChecked() const; 86 /* 87 BF_ALIGN_LEFT 88 BF_ALIGN_MIDDL 89 BF_ALIGN_RIGHT 90 */ 91 int GetAlignment() const; 92 int GetMaxLen() const; 93 CFX_WideString GetAlternateName() const; 94 95 //Set Properties. 96 void SetCheck(FX_BOOL bChecked, FX_BOOL bNotify); 97 void SetValue(const CFX_WideString& sValue, FX_BOOL bNotify); 98 void SetDefaultValue(const CFX_WideString& sValue); 99 void SetOptionSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify); 100 void ClearSelection(FX_BOOL bNotify); 101 void SetTopVisibleIndex(int index); 102 103 void ResetAppearance(FX_LPCWSTR sValue, FX_BOOL bValueChanged); 104 void ResetFieldAppearance(FX_BOOL bValueChanged); 105 void UpdateField(); 106 CFX_WideString OnFormat(int nCommitKey, FX_BOOL& bFormated); 107 108 //Message. 109 FX_BOOL OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, 110 CPDFSDK_PageView* pPageView); 111 112 CPDFSDK_InterForm* GetInterForm() const {return m_pInterForm;} 113 CPDF_FormField* GetFormField() const; 114 CPDF_FormControl* GetFormControl() const; 115 static CPDF_FormControl* GetFormControl(CPDF_InterForm* pInterForm, CPDF_Dictionary* pAnnotDict); 116 117 void DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView); 118 119 void SetAppModified(); 120 void ClearAppModified(); 121 FX_BOOL IsAppModified() const; 122 123 FX_INT32 GetAppearanceAge() const; 124 FX_INT32 GetValueAge() const; 125 126 private: 127 void ResetAppearance_PushButton(); 128 void ResetAppearance_CheckBox(); 129 void ResetAppearance_RadioButton(); 130 void ResetAppearance_ComboBox(FX_LPCWSTR sValue); 131 void ResetAppearance_ListBox(); 132 void ResetAppearance_TextField(FX_LPCWSTR sValue); 133 134 CPDF_Rect GetClientRect() const; 135 CPDF_Rect GetRotatedRect() const; 136 137 CFX_ByteString GetBackgroundAppStream() const; 138 CFX_ByteString GetBorderAppStream() const; 139 CPDF_Matrix GetMatrix() const; 140 141 CPWL_Color GetTextPWLColor() const; 142 CPWL_Color GetBorderPWLColor() const; 143 CPWL_Color GetFillPWLColor() const; 144 145 void AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage); 146 void RemoveAppearance(const CFX_ByteString& sAPType); 147 public: 148 FX_BOOL IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode); 149 void DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device, 150 CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions); 151 public: 152 FX_BOOL HitTest(FX_FLOAT pageX, FX_FLOAT pageY); 153 private: 154 CPDFSDK_InterForm* m_pInterForm; 155 FX_BOOL m_bAppModified; 156 FX_INT32 m_nAppAge; 157 FX_INT32 m_nValueAge; 158 }; 159 160 #define CPDFSDK_WidgetMap CFX_MapPtrTemplate<CPDF_FormControl*, CPDFSDK_Widget*> 161 162 class CPDFSDK_InterForm : public CPDF_FormNotify 163 { 164 public: 165 CPDFSDK_InterForm(CPDFSDK_Document* pDocument); 166 virtual ~CPDFSDK_InterForm(); 167 168 public: 169 virtual void Destroy(); 170 virtual CPDF_InterForm* GetInterForm(); 171 172 CPDFSDK_Document* GetDocument(); 173 FX_BOOL HighlightWidgets(); 174 175 CPDFSDK_Widget* GetSibling(CPDFSDK_Widget* pWidget, FX_BOOL bNext) const; 176 CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const; 177 void GetWidgets(const CFX_WideString& sFieldName, CFX_PtrArray& widgets); 178 void GetWidgets(CPDF_FormField* pField, CFX_PtrArray& widgets); 179 180 void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget); 181 void RemoveMap(CPDF_FormControl* pControl); 182 183 void EnableCalculate(FX_BOOL bEnabled); 184 FX_BOOL IsCalculateEnabled() const; 185 186 #ifdef _WIN32 187 CPDF_Stream* LoadImageFromFile(const CFX_WideString& sFile); 188 #endif 189 190 void OnKeyStrokeCommit(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC); 191 void OnValidate(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC); 192 void OnCalculate(CPDF_FormField* pFormField = NULL); 193 CFX_WideString OnFormat(CPDF_FormField* pFormField, int nCommitKey, FX_BOOL& bFormated); 194 195 void ResetFieldAppearance(CPDF_FormField* pFormField, FX_LPCWSTR sValue, FX_BOOL bValueChanged); 196 void UpdateField(CPDF_FormField* pFormField); 197 198 public: 199 FX_BOOL DoAction_Hide(const CPDF_Action& action); 200 FX_BOOL DoAction_SubmitForm(const CPDF_Action& action); 201 FX_BOOL DoAction_ResetForm(const CPDF_Action& action); 202 FX_BOOL DoAction_ImportData(const CPDF_Action& action); 203 204 void GetFieldFromObjects(const CFX_PtrArray& objects, CFX_PtrArray& fields); 205 FX_BOOL IsValidField(CPDF_Dictionary* pFieldDict); 206 FX_BOOL SubmitFields(const CFX_WideString& csDestination, const CFX_PtrArray& fields, 207 FX_BOOL bIncludeOrExclude, FX_BOOL bUrlEncoded); 208 FX_BOOL SubmitForm(const CFX_WideString& sDestination, FX_BOOL bUrlEncoded); 209 FX_BOOL ImportFormFromFDFFile(const CFX_WideString& csFDFFileName, FX_BOOL bNotify); 210 FX_BOOL ExportFormToFDFFile(const CFX_WideString& sFDFFileName); 211 FX_BOOL ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf); 212 FX_BOOL ExportFieldsToFDFFile(const CFX_WideString& sFDFFileName, const CFX_PtrArray& fields, 213 FX_BOOL bIncludeOrExclude); 214 FX_BOOL ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,FX_BOOL bIncludeOrExclude, CFX_ByteTextBuf& textBuf); 215 FX_BOOL ExportFormToTxtFile(const CFX_WideString& sTxtFileName); 216 FX_BOOL ImportFormFromTxtFile(const CFX_WideString& sTxtFileName); 217 CFX_WideString GetTemporaryFileName(const CFX_WideString& sFileExt); 218 219 private: 220 virtual int BeforeValueChange(const CPDF_FormField* pField, CFX_WideString& csValue); 221 virtual int AfterValueChange(const CPDF_FormField* pField); 222 virtual int BeforeSelectionChange(const CPDF_FormField* pField, CFX_WideString& csValue); 223 virtual int AfterSelectionChange(const CPDF_FormField* pField); 224 virtual int AfterCheckedStatusChange(const CPDF_FormField* pField, const CFX_ByteArray& statusArray); 225 virtual int BeforeFormReset(const CPDF_InterForm* pForm); 226 virtual int AfterFormReset(const CPDF_InterForm* pForm); 227 virtual int BeforeFormImportData(const CPDF_InterForm* pForm); 228 virtual int AfterFormImportData(const CPDF_InterForm* pForm); 229 230 private: 231 FX_BOOL FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile); 232 FX_BOOL FDFToURLEncodedData(FX_LPBYTE& pBuf, FX_STRSIZE& nBufSize); 233 int GetPageIndexByAnnotDict(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict) const; 234 void DoFDFBuffer(CFX_ByteString sBuffer); 235 236 private: 237 CPDFSDK_Document* m_pDocument; 238 CPDF_InterForm* m_pInterForm; 239 CPDFSDK_WidgetMap m_Map; 240 FX_BOOL m_bCalculate; 241 FX_BOOL m_bBusy; 242 243 public: 244 FX_BOOL IsNeedHighLight(int nFieldType); 245 void RemoveAllHighLight(); 246 void SetHighlightAlpha(FX_BYTE alpha) {m_iHighlightAlpha = alpha;} 247 FX_BYTE GetHighlightAlpha() {return m_iHighlightAlpha;} 248 void SetHighlightColor(FX_COLORREF clr, int nFieldType); 249 FX_COLORREF GetHighlightColor(int nFieldType); 250 private: 251 FX_COLORREF m_aHighlightColor[6]; 252 FX_BYTE m_iHighlightAlpha; 253 FX_BOOL m_bNeedHightlight[6]; 254 }; 255 256 #define BAI_STRUCTURE 0 257 #define BAI_ROW 1 258 #define BAI_COLUMN 2 259 260 #define CPDFSDK_Annots CFX_ArrayTemplate<CPDFSDK_Annot*> 261 #define CPDFSDK_SortAnnots CGW_ArrayTemplate<CPDFSDK_Annot*> 262 class CBA_AnnotIterator 263 { 264 public: 265 CBA_AnnotIterator(CPDFSDK_PageView* pPageView, const CFX_ByteString& sType, const CFX_ByteString& sSubType); 266 virtual ~CBA_AnnotIterator(); 267 268 virtual CPDFSDK_Annot* GetFirstAnnot(); 269 virtual CPDFSDK_Annot* GetLastAnnot(); 270 virtual CPDFSDK_Annot* GetNextAnnot(CPDFSDK_Annot* pAnnot); 271 virtual CPDFSDK_Annot* GetPrevAnnot(CPDFSDK_Annot* pAnnot); 272 273 virtual void Release(){delete this;} 274 275 private: 276 void GenerateResults(); 277 static int CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2); 278 static int CompareByTop(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2); 279 280 static CPDF_Rect GetAnnotRect(CPDFSDK_Annot* pAnnot); 281 282 private: 283 CPDFSDK_PageView* m_pPageView; 284 CFX_ByteString m_sType; 285 CFX_ByteString m_sSubType; 286 int m_nTabs; 287 288 CPDFSDK_Annots m_Annots; 289 }; 290 291 #endif //#define _FSDK_BASEFORM_H_ 292 293