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