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