Initial commit.
[pdfium.git] / fpdfsdk / include / javascript / Document.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 _DOCUMENT_H_\r
8 #define _DOCUMENT_H_\r
9 \r
10 \r
11 \r
12 class PrintParamsObj : public CJS_EmbedObj\r
13 {\r
14 public:\r
15         PrintParamsObj(CJS_Object* pJSObject);\r
16         virtual ~PrintParamsObj(){}\r
17         \r
18 public:\r
19         FX_BOOL bUI;\r
20         int nStart;\r
21         int nEnd;\r
22         FX_BOOL bSilent;\r
23         FX_BOOL bShrinkToFit;\r
24         FX_BOOL bPrintAsImage;\r
25         FX_BOOL bReverse;\r
26         FX_BOOL bAnnotations;\r
27 };\r
28 \r
29 class CJS_PrintParamsObj : public CJS_Object\r
30 {\r
31 public:\r
32         CJS_PrintParamsObj(JSFXObject pObject) : CJS_Object(pObject) {}\r
33         virtual ~CJS_PrintParamsObj(){}\r
34         \r
35         DECLARE_JS_CLASS(CJS_PrintParamsObj);\r
36 };\r
37 \r
38 \r
39 class Icon;\r
40 class Field;\r
41 \r
42 struct IconElement\r
43 {\r
44         IconElement() : IconName(L""), IconStream(NULL), NextIcon(NULL){}\r
45         virtual ~IconElement()\r
46         {\r
47         }\r
48         CFX_WideString  IconName;\r
49         IconElement*    NextIcon;\r
50         Icon*                   IconStream;\r
51 };\r
52 \r
53 class IconTree\r
54 {\r
55 public:\r
56         IconTree():m_pHead(NULL), m_pEnd(NULL), m_iLength(0)\r
57         {\r
58 \r
59         }\r
60 \r
61         virtual ~IconTree()\r
62         {\r
63         }\r
64 \r
65 public:\r
66         void                    InsertIconElement(IconElement* pNewIcon);\r
67         void                    DeleteIconElement(CFX_WideString swIconName);\r
68         void                    DeleteIconTree();\r
69         int                             GetLength();\r
70         IconElement*    operator[](int iIndex);\r
71 \r
72 private:\r
73         IconElement*    m_pHead;\r
74         IconElement*    m_pEnd;\r
75         int                             m_iLength;\r
76 };\r
77 \r
78 struct CJS_DelayData;\r
79 struct CJS_DelayAnnot;\r
80 struct CJS_AnnotObj;\r
81 \r
82 class Document : public CJS_EmbedObj\r
83 {\r
84 public:\r
85         Document(CJS_Object* pJSObject);\r
86         virtual ~Document();\r
87 \r
88 public:\r
89         FX_BOOL ADBE(OBJ_PROP_PARAMS);\r
90         FX_BOOL author(OBJ_PROP_PARAMS);\r
91         FX_BOOL baseURL(OBJ_PROP_PARAMS);\r
92         FX_BOOL bookmarkRoot(OBJ_PROP_PARAMS);\r
93         FX_BOOL calculate(OBJ_PROP_PARAMS);\r
94         FX_BOOL Collab(OBJ_PROP_PARAMS);\r
95         FX_BOOL creationDate(OBJ_PROP_PARAMS);\r
96         FX_BOOL creator(OBJ_PROP_PARAMS);\r
97         FX_BOOL delay(OBJ_PROP_PARAMS);\r
98         FX_BOOL dirty(OBJ_PROP_PARAMS);\r
99         FX_BOOL documentFileName(OBJ_PROP_PARAMS);\r
100         FX_BOOL external(OBJ_PROP_PARAMS);\r
101         FX_BOOL filesize(OBJ_PROP_PARAMS);\r
102         FX_BOOL icons(OBJ_PROP_PARAMS);\r
103         FX_BOOL info(OBJ_PROP_PARAMS);\r
104         FX_BOOL keywords(OBJ_PROP_PARAMS);\r
105         FX_BOOL layout(OBJ_PROP_PARAMS);\r
106         FX_BOOL media(OBJ_PROP_PARAMS);\r
107         FX_BOOL modDate(OBJ_PROP_PARAMS);\r
108         FX_BOOL mouseX(OBJ_PROP_PARAMS);\r
109         FX_BOOL mouseY(OBJ_PROP_PARAMS);\r
110         FX_BOOL numFields(OBJ_PROP_PARAMS);\r
111         FX_BOOL numPages(OBJ_PROP_PARAMS);\r
112         FX_BOOL pageNum(OBJ_PROP_PARAMS);\r
113         FX_BOOL pageWindowRect(OBJ_PROP_PARAMS);\r
114         FX_BOOL path(OBJ_PROP_PARAMS);\r
115         FX_BOOL producer(OBJ_PROP_PARAMS);\r
116         FX_BOOL subject(OBJ_PROP_PARAMS);\r
117         FX_BOOL title(OBJ_PROP_PARAMS);\r
118         FX_BOOL zoom(OBJ_PROP_PARAMS);\r
119         FX_BOOL zoomType(OBJ_PROP_PARAMS);\r
120 \r
121         FX_BOOL addAnnot(OBJ_METHOD_PARAMS);\r
122         FX_BOOL addField(OBJ_METHOD_PARAMS);\r
123         FX_BOOL addLink(OBJ_METHOD_PARAMS);\r
124         FX_BOOL addIcon(OBJ_METHOD_PARAMS);\r
125         FX_BOOL calculateNow(OBJ_METHOD_PARAMS);\r
126         FX_BOOL closeDoc(OBJ_METHOD_PARAMS);\r
127         FX_BOOL createDataObject(OBJ_METHOD_PARAMS);\r
128         FX_BOOL deletePages(OBJ_METHOD_PARAMS);\r
129         FX_BOOL exportAsText(OBJ_METHOD_PARAMS);\r
130         FX_BOOL exportAsFDF(OBJ_METHOD_PARAMS);\r
131         FX_BOOL exportAsXFDF(OBJ_METHOD_PARAMS);\r
132         FX_BOOL extractPages(OBJ_METHOD_PARAMS);\r
133         FX_BOOL getAnnot(OBJ_METHOD_PARAMS);\r
134         FX_BOOL getAnnots(OBJ_METHOD_PARAMS);\r
135         FX_BOOL getAnnot3D(OBJ_METHOD_PARAMS);\r
136         FX_BOOL getAnnots3D(OBJ_METHOD_PARAMS);\r
137         FX_BOOL getField(OBJ_METHOD_PARAMS);\r
138         FX_BOOL getIcon(OBJ_METHOD_PARAMS);\r
139         FX_BOOL getLinks(OBJ_METHOD_PARAMS);\r
140         FX_BOOL getNthFieldName(OBJ_METHOD_PARAMS);\r
141         FX_BOOL getOCGs(OBJ_METHOD_PARAMS);\r
142         FX_BOOL getPageBox(OBJ_METHOD_PARAMS);\r
143         FX_BOOL getPageNthWord(OBJ_METHOD_PARAMS);\r
144         FX_BOOL getPageNthWordQuads(OBJ_METHOD_PARAMS);\r
145         FX_BOOL getPageNumWords(OBJ_METHOD_PARAMS);\r
146         FX_BOOL getPrintParams(OBJ_METHOD_PARAMS);\r
147         FX_BOOL getURL(OBJ_METHOD_PARAMS);\r
148         FX_BOOL importAnFDF(OBJ_METHOD_PARAMS);\r
149         FX_BOOL importAnXFDF(OBJ_METHOD_PARAMS);\r
150         FX_BOOL importTextData(OBJ_METHOD_PARAMS);\r
151         FX_BOOL insertPages(OBJ_METHOD_PARAMS);\r
152         FX_BOOL mailForm(OBJ_METHOD_PARAMS);\r
153         FX_BOOL print(OBJ_METHOD_PARAMS);\r
154         FX_BOOL removeField(OBJ_METHOD_PARAMS);\r
155         FX_BOOL replacePages(OBJ_METHOD_PARAMS);\r
156         FX_BOOL resetForm(OBJ_METHOD_PARAMS);\r
157         FX_BOOL saveAs(OBJ_METHOD_PARAMS);\r
158         FX_BOOL submitForm(OBJ_METHOD_PARAMS);\r
159         FX_BOOL mailDoc(OBJ_METHOD_PARAMS);\r
160         FX_BOOL removeIcon(OBJ_METHOD_PARAMS);\r
161         \r
162 public:\r
163         void AttachDoc(CPDFSDK_Document* pDoc);\r
164         CPDFSDK_Document* GetReaderDoc();\r
165 \r
166         static FX_BOOL                          ExtractFileName(CPDFSDK_Document* pDoc, CFX_ByteString& strFileName);\r
167         static FX_BOOL                          ExtractFolderName(CPDFSDK_Document* pDoc, CFX_ByteString& strFolderName);\r
168 \r
169 public:\r
170         void                                            AddDelayData(CJS_DelayData* pData);\r
171         void                                            DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex);\r
172 \r
173         void                                            AddDelayAnnotData(CJS_AnnotObj *pData);\r
174         void                                            DoAnnotDelay();\r
175         void                                            SetIsolate(v8::Isolate* isolate) {m_isolate = isolate;}\r
176 \r
177 private:\r
178         CFX_WideString                          ReversalStr(CFX_WideString cbFrom);\r
179         CFX_WideString                          CutString(CFX_WideString cbFrom);\r
180         bool                                            IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect);\r
181         int                                                     CountWords(CPDF_TextObject* pTextObj);\r
182         CFX_WideString                          GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex);\r
183 \r
184         FX_BOOL                                         ParserParams(JSObject *pObj,CJS_AnnotObj& annotobj);\r
185 \r
186 private:\r
187         v8::Isolate*                                    m_isolate;\r
188         IconTree*                                       m_pIconTree;\r
189         CPDFSDK_Document*                       m_pDocument;\r
190         CFX_WideString                          m_cwBaseURL;\r
191 \r
192         FX_BOOL                                                         m_bDelay;\r
193         CFX_ArrayTemplate<CJS_DelayData*>       m_DelayData;\r
194         CFX_ArrayTemplate<CJS_AnnotObj*>        m_DelayAnnotData;\r
195 };\r
196 \r
197 class CJS_Document : public CJS_Object\r
198 {\r
199 public:\r
200         CJS_Document(JSFXObject pObject) : CJS_Object(pObject) {};\r
201         virtual ~CJS_Document(){};\r
202 \r
203         virtual FX_BOOL InitInstance(IFXJS_Context* cc);        \r
204 \r
205         DECLARE_JS_CLASS(CJS_Document);\r
206 \r
207         JS_STATIC_PROP(ADBE, Document);\r
208         JS_STATIC_PROP(author, Document);\r
209         JS_STATIC_PROP(baseURL, Document);\r
210         JS_STATIC_PROP(bookmarkRoot, Document);\r
211         JS_STATIC_PROP(calculate, Document);\r
212         JS_STATIC_PROP(Collab, Document);\r
213         JS_STATIC_PROP(creationDate, Document);\r
214         JS_STATIC_PROP(creator, Document);\r
215         JS_STATIC_PROP(delay, Document);\r
216         JS_STATIC_PROP(dirty, Document);\r
217         JS_STATIC_PROP(documentFileName, Document);\r
218         JS_STATIC_PROP(external, Document);\r
219         JS_STATIC_PROP(filesize, Document);\r
220         JS_STATIC_PROP(icons, Document);\r
221         JS_STATIC_PROP(info, Document);\r
222         JS_STATIC_PROP(keywords, Document);\r
223         JS_STATIC_PROP(layout, Document);\r
224         JS_STATIC_PROP(media, Document);\r
225         JS_STATIC_PROP(modDate, Document);\r
226         JS_STATIC_PROP(mouseX, Document);\r
227         JS_STATIC_PROP(mouseY, Document);\r
228         JS_STATIC_PROP(numFields, Document);\r
229         JS_STATIC_PROP(numPages, Document);\r
230         JS_STATIC_PROP(pageNum, Document);\r
231         JS_STATIC_PROP(pageWindowRect, Document);\r
232         JS_STATIC_PROP(path, Document);\r
233         JS_STATIC_PROP(producer, Document);\r
234         JS_STATIC_PROP(subject, Document);\r
235         JS_STATIC_PROP(title, Document);\r
236         JS_STATIC_PROP(zoom, Document);\r
237         JS_STATIC_PROP(zoomType, Document);\r
238 \r
239         JS_STATIC_METHOD(addAnnot,Document);\r
240         JS_STATIC_METHOD(addField, Document);\r
241         JS_STATIC_METHOD(addLink, Document);\r
242         JS_STATIC_METHOD(addIcon, Document);\r
243         JS_STATIC_METHOD(calculateNow, Document);\r
244         JS_STATIC_METHOD(closeDoc, Document);\r
245         JS_STATIC_METHOD(createDataObject, Document);\r
246         JS_STATIC_METHOD(deletePages, Document);\r
247         JS_STATIC_METHOD(exportAsText, Document);\r
248         JS_STATIC_METHOD(exportAsFDF, Document);\r
249         JS_STATIC_METHOD(exportAsXFDF, Document);\r
250         JS_STATIC_METHOD(extractPages, Document);\r
251         JS_STATIC_METHOD(getAnnot, Document);\r
252         JS_STATIC_METHOD(getAnnots, Document);\r
253         JS_STATIC_METHOD(getAnnot3D, Document);\r
254         JS_STATIC_METHOD(getAnnots3D, Document);\r
255         JS_STATIC_METHOD(getField, Document);\r
256         JS_STATIC_METHOD(getIcon, Document);\r
257         JS_STATIC_METHOD(getLinks, Document);\r
258         JS_STATIC_METHOD(getNthFieldName, Document);\r
259         JS_STATIC_METHOD(getOCGs, Document);\r
260         JS_STATIC_METHOD(getPageBox, Document);\r
261         JS_STATIC_METHOD(getPageNthWord, Document);\r
262         JS_STATIC_METHOD(getPageNthWordQuads, Document);\r
263         JS_STATIC_METHOD(getPageNumWords, Document);\r
264         JS_STATIC_METHOD(getPrintParams, Document);\r
265         JS_STATIC_METHOD(getURL, Document);\r
266         JS_STATIC_METHOD(importAnFDF, Document);\r
267         JS_STATIC_METHOD(importAnXFDF, Document);\r
268         JS_STATIC_METHOD(importTextData, Document);\r
269         JS_STATIC_METHOD(insertPages, Document);\r
270         JS_STATIC_METHOD(mailForm, Document);\r
271         JS_STATIC_METHOD(print, Document);\r
272         JS_STATIC_METHOD(removeField, Document);\r
273         JS_STATIC_METHOD(replacePages, Document);\r
274         JS_STATIC_METHOD(removeIcon, Document);\r
275         JS_STATIC_METHOD(resetForm, Document);\r
276         JS_STATIC_METHOD(saveAs, Document);\r
277         JS_STATIC_METHOD(submitForm, Document);\r
278         JS_STATIC_METHOD(mailDoc, Document);\r
279 };\r
280 \r
281 #endif//_DOCUMENT_H_\r
282 \r