Initial commit.
[pdfium.git] / fpdfsdk / include / javascript / Field.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 _FIELD_H_\r
8 #define _FIELD_H_\r
9 \r
10 class Document;\r
11 \r
12 enum FIELD_PROP\r
13 {\r
14         FP_ALIGNMENT,\r
15         FP_BORDERSTYLE,\r
16         FP_BUTTONALIGNX,\r
17         FP_BUTTONALIGNY,\r
18         FP_BUTTONFITBOUNDS,\r
19         FP_BUTTONPOSITION,\r
20         FP_BUTTONSCALEHOW,\r
21         FP_BUTTONSCALEWHEN,\r
22         FP_CALCORDERINDEX,\r
23         FP_CHARLIMIT,\r
24         FP_COMB,\r
25         FP_COMMITONSELCHANGE,\r
26         FP_CURRENTVALUEINDICES,\r
27         FP_DEFAULTVALUE,\r
28         FP_DONOTSCROLL,\r
29         FP_DISPLAY,\r
30         FP_FILLCOLOR,\r
31         FP_HIDDEN,\r
32         FP_HIGHLIGHT,\r
33         FP_LINEWIDTH,\r
34         FP_MULTILINE,\r
35         FP_MULTIPLESELECTION,\r
36         FP_PASSWORD,\r
37         FP_RECT,\r
38         FP_RICHTEXT,\r
39         FP_RICHVALUE,\r
40         FP_ROTATION,\r
41         FP_STROKECOLOR,\r
42         FP_STYLE,\r
43         FP_TEXTCOLOR,\r
44         FP_TEXTFONT,\r
45         FP_TEXTSIZE,\r
46         FP_USERNAME,\r
47         FP_VALUE\r
48 };\r
49 \r
50 class CJS_WideStringArray\r
51 {\r
52 public:\r
53         CJS_WideStringArray(){}\r
54         virtual ~CJS_WideStringArray()\r
55         {\r
56                 for (int i=0,sz=m_Data.GetSize(); i<sz; i++)\r
57                         delete m_Data.GetAt(i);\r
58                 m_Data.RemoveAll();\r
59         }\r
60 \r
61         void Add(const CFX_WideString& string)\r
62         {\r
63                 m_Data.Add(new CFX_WideString(string));\r
64         }\r
65 \r
66         int GetSize() const\r
67         {\r
68                 return m_Data.GetSize();\r
69         }\r
70 \r
71         CFX_WideString GetAt(int i) const\r
72         {\r
73                 return *m_Data.GetAt(i);\r
74         }\r
75 \r
76 private:\r
77         CFX_ArrayTemplate<CFX_WideString*>      m_Data;\r
78 };\r
79 \r
80 struct CJS_DelayData\r
81 {\r
82         CFX_WideString                  sFieldName;\r
83         int                                             nControlIndex;\r
84         enum FIELD_PROP                 eProp;\r
85         FX_INT32                                num;\r
86         bool                                    b;\r
87         CFX_ByteString                  string;\r
88         CFX_WideString                  widestring;\r
89         CPDF_Rect                               rect;\r
90         CPWL_Color                              color;\r
91         CFX_DWordArray                  wordarray;\r
92         CJS_WideStringArray             widestringarray;\r
93 };\r
94 \r
95 class Field : public CJS_EmbedObj\r
96 {\r
97 public:\r
98         Field(CJS_Object* pJSObject);   \r
99         virtual ~Field(void);\r
100 \r
101     FX_BOOL alignment(OBJ_PROP_PARAMS);\r
102     FX_BOOL borderStyle(OBJ_PROP_PARAMS);\r
103         FX_BOOL buttonAlignX(OBJ_PROP_PARAMS);\r
104         FX_BOOL buttonAlignY(OBJ_PROP_PARAMS);\r
105         FX_BOOL buttonFitBounds(OBJ_PROP_PARAMS);\r
106         FX_BOOL buttonPosition(OBJ_PROP_PARAMS);\r
107         FX_BOOL buttonScaleHow(OBJ_PROP_PARAMS);\r
108     FX_BOOL buttonScaleWhen(OBJ_PROP_PARAMS);\r
109         FX_BOOL calcOrderIndex(OBJ_PROP_PARAMS);\r
110         FX_BOOL charLimit(OBJ_PROP_PARAMS);\r
111         FX_BOOL comb(OBJ_PROP_PARAMS);\r
112         FX_BOOL commitOnSelChange(OBJ_PROP_PARAMS);\r
113         FX_BOOL currentValueIndices(OBJ_PROP_PARAMS);\r
114     FX_BOOL defaultStyle(OBJ_PROP_PARAMS);\r
115         FX_BOOL defaultValue(OBJ_PROP_PARAMS);\r
116         FX_BOOL doNotScroll(OBJ_PROP_PARAMS);\r
117         FX_BOOL doNotSpellCheck(OBJ_PROP_PARAMS);\r
118         FX_BOOL delay(OBJ_PROP_PARAMS);\r
119         FX_BOOL display(OBJ_PROP_PARAMS);\r
120     FX_BOOL doc(OBJ_PROP_PARAMS);\r
121         FX_BOOL editable(OBJ_PROP_PARAMS);\r
122         FX_BOOL exportValues(OBJ_PROP_PARAMS);\r
123         FX_BOOL fileSelect(OBJ_PROP_PARAMS);\r
124         FX_BOOL fillColor(OBJ_PROP_PARAMS);\r
125         FX_BOOL hidden(OBJ_PROP_PARAMS);\r
126     FX_BOOL highlight(OBJ_PROP_PARAMS);\r
127         FX_BOOL lineWidth(OBJ_PROP_PARAMS);\r
128         FX_BOOL multiline(OBJ_PROP_PARAMS);\r
129         FX_BOOL multipleSelection(OBJ_PROP_PARAMS);\r
130         FX_BOOL name(OBJ_PROP_PARAMS);\r
131         FX_BOOL numItems(OBJ_PROP_PARAMS);\r
132     FX_BOOL page(OBJ_PROP_PARAMS);\r
133         FX_BOOL password(OBJ_PROP_PARAMS);\r
134         FX_BOOL print(OBJ_PROP_PARAMS);\r
135         FX_BOOL radiosInUnison(OBJ_PROP_PARAMS);\r
136         FX_BOOL readonly(OBJ_PROP_PARAMS);\r
137         FX_BOOL rect(OBJ_PROP_PARAMS);\r
138     FX_BOOL required(OBJ_PROP_PARAMS);\r
139         FX_BOOL richText(OBJ_PROP_PARAMS);\r
140         FX_BOOL richValue(OBJ_PROP_PARAMS);\r
141         FX_BOOL rotation(OBJ_PROP_PARAMS);\r
142         FX_BOOL strokeColor(OBJ_PROP_PARAMS);\r
143         FX_BOOL style(OBJ_PROP_PARAMS);\r
144         FX_BOOL submitName(OBJ_PROP_PARAMS);\r
145         FX_BOOL textColor(OBJ_PROP_PARAMS);\r
146         FX_BOOL textFont(OBJ_PROP_PARAMS);\r
147         FX_BOOL textSize(OBJ_PROP_PARAMS);\r
148         FX_BOOL type(OBJ_PROP_PARAMS);\r
149         FX_BOOL userName(OBJ_PROP_PARAMS);\r
150         FX_BOOL value(OBJ_PROP_PARAMS);\r
151         FX_BOOL valueAsString(OBJ_PROP_PARAMS);\r
152         FX_BOOL source(OBJ_PROP_PARAMS);\r
153 \r
154         FX_BOOL browseForFileToSubmit(OBJ_METHOD_PARAMS);\r
155         FX_BOOL buttonGetCaption(OBJ_METHOD_PARAMS);\r
156         FX_BOOL buttonGetIcon(OBJ_METHOD_PARAMS);\r
157         FX_BOOL buttonImportIcon(OBJ_METHOD_PARAMS);\r
158         FX_BOOL buttonSetCaption(OBJ_METHOD_PARAMS);\r
159         FX_BOOL buttonSetIcon(OBJ_METHOD_PARAMS);\r
160         FX_BOOL checkThisBox(OBJ_METHOD_PARAMS);\r
161         FX_BOOL clearItems(OBJ_METHOD_PARAMS);\r
162         FX_BOOL defaultIsChecked(OBJ_METHOD_PARAMS);\r
163         FX_BOOL deleteItemAt(OBJ_METHOD_PARAMS);\r
164         FX_BOOL getArray(OBJ_METHOD_PARAMS);\r
165         FX_BOOL getItemAt(OBJ_METHOD_PARAMS);\r
166         FX_BOOL getLock(OBJ_METHOD_PARAMS);\r
167         FX_BOOL insertItemAt(OBJ_METHOD_PARAMS);\r
168         FX_BOOL isBoxChecked(OBJ_METHOD_PARAMS);\r
169         FX_BOOL isDefaultChecked(OBJ_METHOD_PARAMS);\r
170         FX_BOOL setAction(OBJ_METHOD_PARAMS);\r
171         FX_BOOL setFocus(OBJ_METHOD_PARAMS);\r
172         FX_BOOL setItems(OBJ_METHOD_PARAMS);\r
173         FX_BOOL setLock(OBJ_METHOD_PARAMS);\r
174         FX_BOOL signatureGetModifications(OBJ_METHOD_PARAMS);\r
175         FX_BOOL signatureGetSeedValue(OBJ_METHOD_PARAMS);\r
176         FX_BOOL signatureInfo(OBJ_METHOD_PARAMS);\r
177         FX_BOOL signatureSetSeedValue(OBJ_METHOD_PARAMS);\r
178         FX_BOOL signatureSign(OBJ_METHOD_PARAMS);\r
179         FX_BOOL signatureValidate(OBJ_METHOD_PARAMS);\r
180 \r
181 public:\r
182         static void SetAlignment(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string);\r
183     static void SetBorderStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string);\r
184         static void SetButtonAlignX(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number);\r
185         static void SetButtonAlignY(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number);\r
186         static void SetButtonFitBounds(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b);\r
187         static void SetButtonPosition(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number);\r
188         static void SetButtonScaleHow(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number);\r
189     static void SetButtonScaleWhen(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number);\r
190         static void SetCalcOrderIndex(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number);\r
191         static void SetCharLimit(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number);\r
192         static void SetComb(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b);\r
193         static void SetCommitOnSelChange(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b);\r
194         static void SetCurrentValueIndices(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_DWordArray& array);\r
195     static void SetDefaultStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex);\r
196         static void SetDefaultValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_WideString& string);\r
197         static void SetDoNotScroll(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b);\r
198         static void SetDisplay(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number);\r
199         static void SetFillColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color);\r
200         static void SetHidden(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b);\r
201     static void SetHighlight(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string);\r
202         static void SetLineWidth(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number);\r
203         static void SetMultiline(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b);\r
204         static void SetMultipleSelection(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b);\r
205         static void SetPassword(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b);\r
206         static void SetRect(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPDF_Rect& rect);\r
207         static void SetRichText(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b);\r
208         static void SetRichValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex);\r
209         static void SetRotation(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number);\r
210         static void SetStrokeColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color);\r
211         static void SetStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string);\r
212         static void SetTextColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color);\r
213         static void SetTextFont(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string);\r
214         static void SetTextSize(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number);\r
215         static void SetUserName(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_WideString& string);\r
216         static void SetValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CJS_WideStringArray& strArray);\r
217 \r
218 public:\r
219         static void                                                     AddField(CPDFSDK_Document* pDocument, int nPageIndex, int nFieldType, \r
220                                                                                         const CFX_WideString& sName, const CPDF_Rect& rcCoords);\r
221 public:\r
222         static void                                                     UpdateFormField(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, \r
223                                                                                         FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh);\r
224         static void                                                     UpdateFormControl(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl, \r
225                                                                                         FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh);\r
226 \r
227         static CPDFSDK_Widget*                                  GetWidget(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl);\r
228         static void                                                     GetFormFields(CPDFSDK_Document* pDocument, const CFX_WideString& csFieldName, CFX_PtrArray& FieldsArray);\r
229 \r
230         static void                                                     DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData);\r
231 \r
232 public:\r
233         FX_BOOL                                                         AttachField(Document* pDocument, const CFX_WideString& csFieldName);\r
234         void                                                            SetDelay(FX_BOOL bDelay);\r
235         void                                                            SetIsolate(v8::Isolate* isolate) {m_isolate = isolate;}\r
236 protected:\r
237         void                                                            ParseFieldName(const std::wstring &strFieldNameParsed,std::wstring &strFieldName,int & iControlNo);\r
238         void                                                            GetFormFields(const CFX_WideString& csFieldName, CFX_PtrArray& FieldsArray);\r
239         CPDF_FormControl*                                       GetSmartFieldControl(CPDF_FormField* pFormField);\r
240         FX_BOOL                                                         ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel);\r
241 \r
242         void                                                            AddDelay_Int(enum FIELD_PROP prop, FX_INT32 n);\r
243         void                                                            AddDelay_Bool(enum FIELD_PROP prop,bool b);\r
244         void                                                            AddDelay_String(enum FIELD_PROP prop, const CFX_ByteString& string);\r
245         void                                                            AddDelay_WideString(enum FIELD_PROP prop, const CFX_WideString& string);\r
246         void                                                            AddDelay_Rect(enum FIELD_PROP prop, const CPDF_Rect& rect);\r
247         void                                                            AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color);\r
248         void                                                            AddDelay_WordArray(enum FIELD_PROP prop, const CFX_DWordArray& array);\r
249         void                                                            AddDelay_WideStringArray(enum FIELD_PROP prop, const CJS_WideStringArray& array);\r
250 \r
251         void                                                            DoDelay();\r
252 public:\r
253         Document*                                                       m_pJSDoc;\r
254         CPDFSDK_Document*                                       m_pDocument;\r
255         CFX_WideString                                          m_FieldName;\r
256         int                                                                     m_nFormControlIndex;\r
257         FX_BOOL                                                         m_bCanSet;\r
258 \r
259         FX_BOOL                                                         m_bDelay;\r
260         v8::Isolate*                                                    m_isolate;\r
261 };\r
262 \r
263 class CJS_Field : public CJS_Object\r
264 {\r
265 public:\r
266         CJS_Field(JSFXObject pObject) : CJS_Object(pObject) {};\r
267         virtual ~CJS_Field(void){};\r
268 \r
269         virtual FX_BOOL InitInstance(IFXJS_Context* cc);\r
270 \r
271         DECLARE_JS_CLASS(CJS_Field);\r
272 \r
273     JS_STATIC_PROP(alignment, Field);\r
274     JS_STATIC_PROP(borderStyle, Field);\r
275         JS_STATIC_PROP(buttonAlignX, Field);\r
276         JS_STATIC_PROP(buttonAlignY, Field);\r
277         JS_STATIC_PROP(buttonFitBounds, Field);\r
278         JS_STATIC_PROP(buttonPosition, Field);\r
279         JS_STATIC_PROP(buttonScaleHow, Field);\r
280     JS_STATIC_PROP(buttonScaleWhen, Field);\r
281         JS_STATIC_PROP(calcOrderIndex, Field);\r
282         JS_STATIC_PROP(charLimit, Field);\r
283         JS_STATIC_PROP(comb, Field);\r
284         JS_STATIC_PROP(commitOnSelChange, Field);\r
285         JS_STATIC_PROP(currentValueIndices, Field);\r
286     JS_STATIC_PROP(defaultStyle, Field);\r
287         JS_STATIC_PROP(defaultValue, Field);\r
288         JS_STATIC_PROP(doNotScroll, Field);\r
289         JS_STATIC_PROP(doNotSpellCheck, Field);\r
290         JS_STATIC_PROP(delay, Field);\r
291         JS_STATIC_PROP(display, Field);\r
292     JS_STATIC_PROP(doc, Field);\r
293         JS_STATIC_PROP(editable, Field);\r
294         JS_STATIC_PROP(exportValues, Field);\r
295         JS_STATIC_PROP(fileSelect, Field);\r
296         JS_STATIC_PROP(fillColor, Field);\r
297         JS_STATIC_PROP(hidden, Field);\r
298     JS_STATIC_PROP(highlight, Field);\r
299         JS_STATIC_PROP(lineWidth, Field);\r
300         JS_STATIC_PROP(multiline, Field);\r
301         JS_STATIC_PROP(multipleSelection, Field);\r
302         JS_STATIC_PROP(name, Field);\r
303         JS_STATIC_PROP(numItems, Field);\r
304     JS_STATIC_PROP(page, Field);\r
305         JS_STATIC_PROP(password, Field);\r
306         JS_STATIC_PROP(print, Field);\r
307         JS_STATIC_PROP(radiosInUnison, Field);\r
308         JS_STATIC_PROP(readonly, Field);\r
309         JS_STATIC_PROP(rect, Field);\r
310     JS_STATIC_PROP(required, Field);\r
311         JS_STATIC_PROP(richText, Field);\r
312         JS_STATIC_PROP(richValue, Field);\r
313         JS_STATIC_PROP(rotation, Field);\r
314         JS_STATIC_PROP(strokeColor, Field);\r
315         JS_STATIC_PROP(style, Field);\r
316         JS_STATIC_PROP(submitName, Field);\r
317         JS_STATIC_PROP(textColor, Field);\r
318         JS_STATIC_PROP(textFont, Field);\r
319         JS_STATIC_PROP(textSize, Field);\r
320         JS_STATIC_PROP(type, Field);\r
321         JS_STATIC_PROP(userName, Field);\r
322         JS_STATIC_PROP(value, Field);\r
323         JS_STATIC_PROP(valueAsString, Field);\r
324         JS_STATIC_PROP(source, Field);\r
325 \r
326         JS_STATIC_METHOD(browseForFileToSubmit, Field);\r
327         JS_STATIC_METHOD(buttonGetCaption, Field);\r
328         JS_STATIC_METHOD(buttonGetIcon, Field);\r
329         JS_STATIC_METHOD(buttonImportIcon, Field);\r
330         JS_STATIC_METHOD(buttonSetCaption, Field);\r
331         JS_STATIC_METHOD(buttonSetIcon, Field);\r
332         JS_STATIC_METHOD(checkThisBox, Field);\r
333         JS_STATIC_METHOD(clearItems, Field);\r
334         JS_STATIC_METHOD(defaultIsChecked, Field);\r
335         JS_STATIC_METHOD(deleteItemAt, Field);\r
336         JS_STATIC_METHOD(getArray, Field);\r
337         JS_STATIC_METHOD(getItemAt, Field);\r
338         JS_STATIC_METHOD(getLock, Field);\r
339         JS_STATIC_METHOD(insertItemAt, Field);\r
340         JS_STATIC_METHOD(isBoxChecked, Field);\r
341         JS_STATIC_METHOD(isDefaultChecked, Field);\r
342         JS_STATIC_METHOD(setAction, Field);\r
343         JS_STATIC_METHOD(setFocus, Field);\r
344         JS_STATIC_METHOD(setItems, Field);\r
345         JS_STATIC_METHOD(setLock, Field);\r
346         JS_STATIC_METHOD(signatureGetModifications, Field);\r
347         JS_STATIC_METHOD(signatureGetSeedValue, Field);\r
348         JS_STATIC_METHOD(signatureInfo, Field);\r
349         JS_STATIC_METHOD(signatureSetSeedValue, Field);\r
350         JS_STATIC_METHOD(signatureSign, Field);\r
351         JS_STATIC_METHOD(signatureValidate, Field);\r
352 };\r
353 \r
354 #endif //_FIELD_H_\r
355 \r