• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 XFA_FXFA_FXFA_H_
8 #define XFA_FXFA_FXFA_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/cfx_timer.h"
13 #include "core/fxcrt/fx_coordinates.h"
14 #include "core/fxcrt/retain_ptr.h"
15 #include "core/fxge/fx_dib.h"
16 #include "xfa/fxfa/fxfa_basic.h"
17 
18 class CXFA_FFDoc;
19 class CXFA_FFPageView;
20 class CXFA_FFWidget;
21 class CXFA_Submit;
22 class IFX_SeekableReadStream;
23 class IJS_Runtime;
24 
25 // Note, values must match fpdf_formfill.h JSPLATFORM_ALERT_BUTTON_* flags.
26 enum class AlertButton {
27   kDefault = 0,
28   kOK = 0,
29   kOKCancel = 1,
30   kYesNo = 2,
31   kYesNoCancel = 3,
32 };
33 
34 // Note, values must match fpdf_formfill.h JSPLATFORM_ALERT_ICON_* flags.
35 enum class AlertIcon {
36   kDefault = 0,
37   kError = 0,
38   kWarning = 1,
39   kQuestion = 2,
40   kStatus = 3,
41   kAsterisk = 4,
42 };
43 
44 // Note, values must match fpdf_formfill.h JSPLATFORM_ALERT_RETURN_* flags.
45 enum class AlertReturn {
46   kOK = 1,
47   kCancel = 2,
48   kNo = 3,
49   kYes = 4,
50 };
51 
52 // Note, values must match fpdf_formfill.h FORMTYPE_* flags.
53 enum class FormType {
54   kNone = 0,
55   kAcroForm = 1,
56   kXFAFull = 2,
57   kXFAForeground = 3,
58 };
59 
60 #define XFA_PRINTOPT_ShowDialog 0x00000001
61 #define XFA_PRINTOPT_CanCancel 0x00000002
62 #define XFA_PRINTOPT_ShrinkPage 0x00000004
63 #define XFA_PRINTOPT_AsImage 0x00000008
64 #define XFA_PRINTOPT_ReverseOrder 0x00000010
65 #define XFA_PRINTOPT_PrintAnnot 0x00000020
66 
67 #define XFA_PAGEVIEWEVENT_PostAdded 1
68 #define XFA_PAGEVIEWEVENT_PostRemoved 3
69 #define XFA_PAGEVIEWEVENT_StopLayout 4
70 
71 enum class XFA_EventError {
72   kError = -1,
73   kNotExist = 0,
74   kSuccess = 1,
75   kDisabled = 2,
76 };
77 
78 enum XFA_WidgetStatus {
79   XFA_WidgetStatus_None = 0,
80 
81   XFA_WidgetStatus_Access = 1 << 0,
82   XFA_WidgetStatus_ButtonDown = 1 << 1,
83   XFA_WidgetStatus_Disabled = 1 << 2,
84   XFA_WidgetStatus_Focused = 1 << 3,
85   XFA_WidgetStatus_Printable = 1 << 4,
86   XFA_WidgetStatus_RectCached = 1 << 5,
87   XFA_WidgetStatus_TextEditValueChanged = 1 << 6,
88   XFA_WidgetStatus_Viewable = 1 << 7,
89   XFA_WidgetStatus_Visible = 1 << 8
90 };
91 
92 // Probably should be called IXFA_AppDelegate.
93 class IXFA_AppProvider {
94  public:
95   virtual ~IXFA_AppProvider() = default;
96 
97   /**
98    * Returns the language of the running host application. Such as zh_CN
99    */
100   virtual WideString GetLanguage() = 0;
101 
102   /**
103    * Returns the platform of the machine running the script. Such as WIN
104    */
105   virtual WideString GetPlatform() = 0;
106 
107   /**
108    * Get application name, such as Phantom.
109    */
110   virtual WideString GetAppName() = 0;
111 
112   /**
113    * Get application message box title.
114    */
115   virtual WideString GetAppTitle() const = 0;
116 
117   /**
118    * Causes the system to play a sound.
119    * @param[in] dwType The system code for the appropriate sound.0 (Error)1
120    * (Warning)2 (Question)3 (Status)4 (Default)
121    */
122   virtual void Beep(uint32_t dwType) = 0;
123 
124   /**
125    * Displays a message box.
126    * @param[in] wsMessage    - Message string to display in box.
127    * @param[in] wsTitle      - Title string for box.
128    * @param[in] dwIconType   - Icon type, refer to XFA_MBICON.
129    * @param[in] dwButtonType - Button type, refer to XFA_MESSAGEBUTTON.
130    * @return A valid integer representing the value of the button pressed by the
131    * user, refer to XFA_ID.
132    */
133   virtual int32_t MsgBox(const WideString& wsMessage,
134                          const WideString& wsTitle,
135                          uint32_t dwIconType,
136                          uint32_t dwButtonType) = 0;
137 
138   /**
139    * Get a response from the user.
140    * @param[in] wsQuestion      - Message string to display in box.
141    * @param[in] wsTitle         - Title string for box.
142    * @param[in] wsDefaultAnswer - Initial contents for answer.
143    * @param[in] bMask           - Mask the user input with asterisks when true,
144    * @return A string containing the user's response.
145    */
146   virtual WideString Response(const WideString& wsQuestion,
147                               const WideString& wsTitle,
148                               const WideString& wsDefaultAnswer,
149                               bool bMask) = 0;
150 
151   /**
152    * Download something from somewhere.
153    * @param[in] wsURL - http, ftp, such as
154    * "http://www.w3.org/TR/REC-xml-names/".
155    */
156   virtual RetainPtr<IFX_SeekableReadStream> DownloadURL(
157       const WideString& wsURL) = 0;
158 
159   /**
160    * POST data to the given url.
161    * @param[in] wsURL         the URL being uploaded.
162    * @param[in] wsData        the data being uploaded.
163    * @param[in] wsContentType the content type of data including text/html,
164    * text/xml, text/plain, multipart/form-data,
165    *                          application/x-www-form-urlencoded,
166    * application/octet-stream, any valid MIME type.
167    * @param[in] wsEncode      the encode of data including UTF-8, UTF-16,
168    * ISO8859-1, any recognized [IANA]character encoding
169    * @param[in] wsHeader      any additional HTTP headers to be included in the
170    * post.
171    * @param[out] wsResponse   decoded response from server.
172    * @return true Server permitted the post request, false otherwise.
173    */
174   virtual bool PostRequestURL(const WideString& wsURL,
175                               const WideString& wsData,
176                               const WideString& wsContentType,
177                               const WideString& wsEncode,
178                               const WideString& wsHeader,
179                               WideString& wsResponse) = 0;
180 
181   /**
182    * PUT data to the given url.
183    * @param[in] wsURL         the URL being uploaded.
184    * @param[in] wsData            the data being uploaded.
185    * @param[in] wsEncode      the encode of data including UTF-8, UTF-16,
186    * ISO8859-1, any recognized [IANA]character encoding
187    * @return true Server permitted the post request, false otherwise.
188    */
189   virtual bool PutRequestURL(const WideString& wsURL,
190                              const WideString& wsData,
191                              const WideString& wsEncode) = 0;
192 
193   virtual TimerHandlerIface* GetTimerHandler() const = 0;
194 };
195 
196 class IXFA_DocEnvironment {
197  public:
198   virtual ~IXFA_DocEnvironment() = default;
199 
200   virtual void SetChangeMark(CXFA_FFDoc* hDoc) = 0;
201   virtual void InvalidateRect(CXFA_FFPageView* pPageView,
202                               const CFX_RectF& rt) = 0;
203   // Show or hide caret.
204   virtual void DisplayCaret(CXFA_FFWidget* hWidget,
205                             bool bVisible,
206                             const CFX_RectF* pRtAnchor) = 0;
207 
208   virtual bool GetPopupPos(CXFA_FFWidget* hWidget,
209                            float fMinPopup,
210                            float fMaxPopup,
211                            const CFX_RectF& rtAnchor,
212                            CFX_RectF* pPopupRect) = 0;
213   virtual bool PopupMenu(CXFA_FFWidget* hWidget, const CFX_PointF& ptPopup) = 0;
214 
215   // Specify dwFlags XFA_PAGEVIEWEVENT_Added, XFA_PAGEVIEWEVENT_Removing
216   virtual void PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) = 0;
217 
218   virtual void WidgetPostAdd(CXFA_FFWidget* hWidget) = 0;
219   virtual void WidgetPreRemove(CXFA_FFWidget* hWidget) = 0;
220   virtual int32_t CountPages(CXFA_FFDoc* hDoc) = 0;
221   virtual int32_t GetCurrentPage(CXFA_FFDoc* hDoc) = 0;
222   virtual void SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) = 0;
223   virtual bool IsCalculationsEnabled(CXFA_FFDoc* hDoc) = 0;
224   virtual void SetCalculationsEnabled(CXFA_FFDoc* hDoc, bool bEnabled) = 0;
225   virtual void GetTitle(CXFA_FFDoc* hDoc, WideString& wsTitle) = 0;
226   virtual void SetTitle(CXFA_FFDoc* hDoc, const WideString& wsTitle) = 0;
227   virtual void ExportData(CXFA_FFDoc* hDoc,
228                           const WideString& wsFilePath,
229                           bool bXDP) = 0;
230   virtual void GotoURL(CXFA_FFDoc* hDoc, const WideString& bsURL) = 0;
231   virtual bool IsValidationsEnabled(CXFA_FFDoc* hDoc) = 0;
232   virtual void SetValidationsEnabled(CXFA_FFDoc* hDoc, bool bEnabled) = 0;
233   virtual void SetFocusWidget(CXFA_FFDoc* hDoc, CXFA_FFWidget* hWidget) = 0;
234   virtual void Print(CXFA_FFDoc* hDoc,
235                      int32_t nStartPage,
236                      int32_t nEndPage,
237                      uint32_t dwOptions) = 0;
238   virtual FX_ARGB GetHighlightColor(CXFA_FFDoc* hDoc) = 0;
239   virtual IJS_Runtime* GetIJSRuntime(CXFA_FFDoc* hDoc) const = 0;
240   virtual RetainPtr<IFX_SeekableReadStream> OpenLinkedFile(
241       CXFA_FFDoc* hDoc,
242       const WideString& wsLink) = 0;
243 
244 #ifdef PDF_XFA_ELEMENT_SUBMIT_ENABLED
245   virtual bool Submit(CXFA_FFDoc* hDoc, CXFA_Submit* submit) = 0;
246 #endif  // PDF_XFA_ELEMENT_SUBMIT_ENABLED
247 };
248 
249 class IXFA_WidgetIterator {
250  public:
251   virtual ~IXFA_WidgetIterator() = default;
252 
253   virtual void Reset() = 0;
254   virtual CXFA_FFWidget* MoveToFirst() = 0;
255   virtual CXFA_FFWidget* MoveToLast() = 0;
256   virtual CXFA_FFWidget* MoveToNext() = 0;
257   virtual CXFA_FFWidget* MoveToPrevious() = 0;
258   virtual CXFA_FFWidget* GetCurrentWidget() = 0;
259   virtual bool SetCurrentWidget(CXFA_FFWidget* hWidget) = 0;
260 };
261 
262 #endif  // XFA_FXFA_FXFA_H_
263