| OLD | NEW |
| (Empty) |
| 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 FPDFSDK_INCLUDE_FSDK_BASEFORM_H_ | |
| 8 #define FPDFSDK_INCLUDE_FSDK_BASEFORM_H_ | |
| 9 | |
| 10 #include <map> | |
| 11 #include <set> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "core/fpdfdoc/include/ipdf_formnotify.h" | |
| 15 #include "core/fxcrt/include/fx_basic.h" | |
| 16 #include "core/fxge/include/fx_dib.h" | |
| 17 #include "fpdfsdk/include/cpdfsdk_annot.h" | |
| 18 #include "fpdfsdk/include/cpdfsdk_baannot.h" | |
| 19 | |
| 20 #if _FX_OS_ == _FX_ANDROID_ | |
| 21 #include "time.h" | |
| 22 #else | |
| 23 #include <ctime> | |
| 24 #endif | |
| 25 | |
| 26 class CPDFSDK_Annot; | |
| 27 class CPDFSDK_Document; | |
| 28 class CPDFSDK_InterForm; | |
| 29 class CPDFSDK_PageView; | |
| 30 class CPDF_Action; | |
| 31 class CPDF_FormControl; | |
| 32 class CPDF_FormField; | |
| 33 class CPDF_InterForm; | |
| 34 struct CPWL_Color; | |
| 35 | |
| 36 #ifdef PDF_ENABLE_XFA | |
| 37 class CXFA_FFWidgetHandler; | |
| 38 | |
| 39 typedef enum _PDFSDK_XFAAActionType { | |
| 40 PDFSDK_XFA_Click = 0, | |
| 41 PDFSDK_XFA_Full, | |
| 42 PDFSDK_XFA_PreOpen, | |
| 43 PDFSDK_XFA_PostOpen | |
| 44 } PDFSDK_XFAAActionType; | |
| 45 #endif // PDF_ENABLE_XFA | |
| 46 | |
| 47 struct PDFSDK_FieldAction { | |
| 48 PDFSDK_FieldAction(); | |
| 49 PDFSDK_FieldAction(const PDFSDK_FieldAction& other) = delete; | |
| 50 | |
| 51 FX_BOOL bModifier; // in | |
| 52 FX_BOOL bShift; // in | |
| 53 int nCommitKey; // in | |
| 54 CFX_WideString sChange; // in[out] | |
| 55 CFX_WideString sChangeEx; // in | |
| 56 FX_BOOL bKeyDown; // in | |
| 57 int nSelEnd; // in[out] | |
| 58 int nSelStart; // in[out] | |
| 59 CFX_WideString sValue; // in[out] | |
| 60 FX_BOOL bWillCommit; // in | |
| 61 FX_BOOL bFieldFull; // in | |
| 62 FX_BOOL bRC; // in[out] | |
| 63 }; | |
| 64 | |
| 65 class CPDFSDK_Widget : public CPDFSDK_BAAnnot { | |
| 66 public: | |
| 67 class Observer { | |
| 68 public: | |
| 69 explicit Observer(CPDFSDK_Widget** pWatchedPtr); | |
| 70 ~Observer(); | |
| 71 | |
| 72 void OnWidgetDestroyed(); | |
| 73 | |
| 74 private: | |
| 75 CPDFSDK_Widget** m_pWatchedPtr; | |
| 76 }; | |
| 77 | |
| 78 #ifdef PDF_ENABLE_XFA | |
| 79 CXFA_FFWidget* GetMixXFAWidget() const; | |
| 80 CXFA_FFWidget* GetGroupMixXFAWidget(); | |
| 81 CXFA_FFWidgetHandler* GetXFAWidgetHandler() const; | |
| 82 | |
| 83 FX_BOOL HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT); | |
| 84 FX_BOOL OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, | |
| 85 PDFSDK_FieldAction& data, | |
| 86 CPDFSDK_PageView* pPageView); | |
| 87 | |
| 88 void Synchronize(FX_BOOL bSynchronizeElse); | |
| 89 void SynchronizeXFAValue(); | |
| 90 void SynchronizeXFAItems(); | |
| 91 | |
| 92 static void SynchronizeXFAValue(CXFA_FFDocView* pXFADocView, | |
| 93 CXFA_FFWidget* hWidget, | |
| 94 CPDF_FormField* pFormField, | |
| 95 CPDF_FormControl* pFormControl); | |
| 96 static void SynchronizeXFAItems(CXFA_FFDocView* pXFADocView, | |
| 97 CXFA_FFWidget* hWidget, | |
| 98 CPDF_FormField* pFormField, | |
| 99 CPDF_FormControl* pFormControl); | |
| 100 #endif // PDF_ENABLE_XFA | |
| 101 | |
| 102 CPDFSDK_Widget(CPDF_Annot* pAnnot, | |
| 103 CPDFSDK_PageView* pPageView, | |
| 104 CPDFSDK_InterForm* pInterForm); | |
| 105 ~CPDFSDK_Widget() override; | |
| 106 | |
| 107 void AddObserver(Observer* observer); | |
| 108 void RemoveObserver(Observer* observer); | |
| 109 | |
| 110 // CPDFSDK_Annot | |
| 111 CFX_ByteString GetSubType() const override; | |
| 112 CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT) override; | |
| 113 FX_BOOL IsAppearanceValid() override; | |
| 114 | |
| 115 int GetLayoutOrder() const override; | |
| 116 | |
| 117 int GetFieldType() const; | |
| 118 | |
| 119 // Possible values from PDF 32000-1:2008, table 221. | |
| 120 // FIELDFLAG_READONLY | |
| 121 // FIELDFLAG_REQUIRED | |
| 122 // FIELDFLAG_NOEXPORT | |
| 123 int GetFieldFlags() const; | |
| 124 int GetRotate() const; | |
| 125 | |
| 126 FX_BOOL GetFillColor(FX_COLORREF& color) const; | |
| 127 FX_BOOL GetBorderColor(FX_COLORREF& color) const; | |
| 128 FX_BOOL GetTextColor(FX_COLORREF& color) const; | |
| 129 FX_FLOAT GetFontSize() const; | |
| 130 | |
| 131 int GetSelectedIndex(int nIndex) const; | |
| 132 #ifndef PDF_ENABLE_XFA | |
| 133 CFX_WideString GetValue() const; | |
| 134 #else | |
| 135 CFX_WideString GetValue(FX_BOOL bDisplay = TRUE) const; | |
| 136 #endif // PDF_ENABLE_XFA | |
| 137 CFX_WideString GetDefaultValue() const; | |
| 138 CFX_WideString GetOptionLabel(int nIndex) const; | |
| 139 int CountOptions() const; | |
| 140 FX_BOOL IsOptionSelected(int nIndex) const; | |
| 141 int GetTopVisibleIndex() const; | |
| 142 bool IsChecked() const; | |
| 143 /* | |
| 144 BF_ALIGN_LEFT | |
| 145 BF_ALIGN_MIDDL | |
| 146 BF_ALIGN_RIGHT | |
| 147 */ | |
| 148 int GetAlignment() const; | |
| 149 int GetMaxLen() const; | |
| 150 #ifdef PDF_ENABLE_XFA | |
| 151 CFX_WideString GetName() const; | |
| 152 #endif // PDF_ENABLE_XFA | |
| 153 CFX_WideString GetAlternateName() const; | |
| 154 | |
| 155 // Set Properties. | |
| 156 void SetCheck(bool bChecked, bool bNotify); | |
| 157 void SetValue(const CFX_WideString& sValue, FX_BOOL bNotify); | |
| 158 void SetDefaultValue(const CFX_WideString& sValue); | |
| 159 void SetOptionSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify); | |
| 160 void ClearSelection(FX_BOOL bNotify); | |
| 161 void SetTopVisibleIndex(int index); | |
| 162 | |
| 163 #ifdef PDF_ENABLE_XFA | |
| 164 void ResetAppearance(FX_BOOL bValueChanged); | |
| 165 #endif // PDF_ENABLE_XFA | |
| 166 void ResetAppearance(const FX_WCHAR* sValue, FX_BOOL bValueChanged); | |
| 167 void ResetFieldAppearance(FX_BOOL bValueChanged); | |
| 168 void UpdateField(); | |
| 169 CFX_WideString OnFormat(FX_BOOL& bFormated); | |
| 170 | |
| 171 // Message. | |
| 172 FX_BOOL OnAAction(CPDF_AAction::AActionType type, | |
| 173 PDFSDK_FieldAction& data, | |
| 174 CPDFSDK_PageView* pPageView); | |
| 175 | |
| 176 CPDFSDK_InterForm* GetInterForm() const { return m_pInterForm; } | |
| 177 CPDF_FormField* GetFormField() const; | |
| 178 CPDF_FormControl* GetFormControl() const; | |
| 179 static CPDF_FormControl* GetFormControl(CPDF_InterForm* pInterForm, | |
| 180 const CPDF_Dictionary* pAnnotDict); | |
| 181 | |
| 182 void DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView); | |
| 183 | |
| 184 void SetAppModified(); | |
| 185 void ClearAppModified(); | |
| 186 FX_BOOL IsAppModified() const; | |
| 187 | |
| 188 int32_t GetAppearanceAge() const; | |
| 189 int32_t GetValueAge() const; | |
| 190 | |
| 191 FX_BOOL IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode); | |
| 192 void DrawAppearance(CFX_RenderDevice* pDevice, | |
| 193 const CFX_Matrix* pUser2Device, | |
| 194 CPDF_Annot::AppearanceMode mode, | |
| 195 const CPDF_RenderOptions* pOptions) override; | |
| 196 | |
| 197 FX_BOOL HitTest(FX_FLOAT pageX, FX_FLOAT pageY); | |
| 198 | |
| 199 private: | |
| 200 void ResetAppearance_PushButton(); | |
| 201 void ResetAppearance_CheckBox(); | |
| 202 void ResetAppearance_RadioButton(); | |
| 203 void ResetAppearance_ComboBox(const FX_WCHAR* sValue); | |
| 204 void ResetAppearance_ListBox(); | |
| 205 void ResetAppearance_TextField(const FX_WCHAR* sValue); | |
| 206 | |
| 207 CFX_FloatRect GetClientRect() const; | |
| 208 CFX_FloatRect GetRotatedRect() const; | |
| 209 | |
| 210 CFX_ByteString GetBackgroundAppStream() const; | |
| 211 CFX_ByteString GetBorderAppStream() const; | |
| 212 CFX_Matrix GetMatrix() const; | |
| 213 | |
| 214 CPWL_Color GetTextPWLColor() const; | |
| 215 CPWL_Color GetBorderPWLColor() const; | |
| 216 CPWL_Color GetFillPWLColor() const; | |
| 217 | |
| 218 void AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage); | |
| 219 void RemoveAppearance(const CFX_ByteString& sAPType); | |
| 220 | |
| 221 CPDFSDK_InterForm* const m_pInterForm; | |
| 222 FX_BOOL m_bAppModified; | |
| 223 int32_t m_nAppAge; | |
| 224 int32_t m_nValueAge; | |
| 225 std::set<Observer*> m_Observers; | |
| 226 | |
| 227 #ifdef PDF_ENABLE_XFA | |
| 228 mutable CXFA_FFWidget* m_hMixXFAWidget; | |
| 229 mutable CXFA_FFWidgetHandler* m_pWidgetHandler; | |
| 230 #endif // PDF_ENABLE_XFA | |
| 231 }; | |
| 232 | |
| 233 #ifdef PDF_ENABLE_XFA | |
| 234 class CPDFSDK_XFAWidget : public CPDFSDK_Annot { | |
| 235 public: | |
| 236 CPDFSDK_XFAWidget(CXFA_FFWidget* pAnnot, | |
| 237 CPDFSDK_PageView* pPageView, | |
| 238 CPDFSDK_InterForm* pInterForm); | |
| 239 ~CPDFSDK_XFAWidget() override {} | |
| 240 | |
| 241 FX_BOOL IsXFAField() override; | |
| 242 CXFA_FFWidget* GetXFAWidget() const override; | |
| 243 CFX_ByteString GetType() const override; | |
| 244 CFX_ByteString GetSubType() const override; | |
| 245 CFX_FloatRect GetRect() const override; | |
| 246 | |
| 247 CPDFSDK_InterForm* GetInterForm() { return m_pInterForm; } | |
| 248 | |
| 249 private: | |
| 250 CPDFSDK_InterForm* m_pInterForm; | |
| 251 CXFA_FFWidget* m_hXFAWidget; | |
| 252 }; | |
| 253 #endif // PDF_ENABLE_XFA | |
| 254 | |
| 255 class CPDFSDK_InterForm : public IPDF_FormNotify { | |
| 256 public: | |
| 257 explicit CPDFSDK_InterForm(CPDFSDK_Document* pDocument); | |
| 258 ~CPDFSDK_InterForm() override; | |
| 259 | |
| 260 CPDF_InterForm* GetInterForm() const { return m_pInterForm.get(); } | |
| 261 CPDFSDK_Document* GetDocument() const { return m_pDocument; } | |
| 262 | |
| 263 FX_BOOL HighlightWidgets(); | |
| 264 | |
| 265 CPDFSDK_Widget* GetSibling(CPDFSDK_Widget* pWidget, FX_BOOL bNext) const; | |
| 266 CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl, | |
| 267 bool createIfNeeded) const; | |
| 268 void GetWidgets(const CFX_WideString& sFieldName, | |
| 269 std::vector<CPDFSDK_Widget*>* widgets) const; | |
| 270 void GetWidgets(CPDF_FormField* pField, | |
| 271 std::vector<CPDFSDK_Widget*>* widgets) const; | |
| 272 | |
| 273 void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget); | |
| 274 void RemoveMap(CPDF_FormControl* pControl); | |
| 275 | |
| 276 void EnableCalculate(FX_BOOL bEnabled); | |
| 277 FX_BOOL IsCalculateEnabled() const; | |
| 278 | |
| 279 #ifdef PDF_ENABLE_XFA | |
| 280 void AddXFAMap(CXFA_FFWidget* hWidget, CPDFSDK_XFAWidget* pWidget); | |
| 281 void RemoveXFAMap(CXFA_FFWidget* hWidget); | |
| 282 CPDFSDK_XFAWidget* GetXFAWidget(CXFA_FFWidget* hWidget); | |
| 283 void XfaEnableCalculate(FX_BOOL bEnabled); | |
| 284 FX_BOOL IsXfaCalculateEnabled() const; | |
| 285 FX_BOOL IsXfaValidationsEnabled(); | |
| 286 void XfaSetValidationsEnabled(FX_BOOL bEnabled); | |
| 287 #endif // PDF_ENABLE_XFA | |
| 288 | |
| 289 FX_BOOL OnKeyStrokeCommit(CPDF_FormField* pFormField, | |
| 290 const CFX_WideString& csValue); | |
| 291 FX_BOOL OnValidate(CPDF_FormField* pFormField, const CFX_WideString& csValue); | |
| 292 void OnCalculate(CPDF_FormField* pFormField = nullptr); | |
| 293 CFX_WideString OnFormat(CPDF_FormField* pFormField, FX_BOOL& bFormated); | |
| 294 | |
| 295 void ResetFieldAppearance(CPDF_FormField* pFormField, | |
| 296 const FX_WCHAR* sValue, | |
| 297 FX_BOOL bValueChanged); | |
| 298 void UpdateField(CPDF_FormField* pFormField); | |
| 299 | |
| 300 FX_BOOL DoAction_Hide(const CPDF_Action& action); | |
| 301 FX_BOOL DoAction_SubmitForm(const CPDF_Action& action); | |
| 302 FX_BOOL DoAction_ResetForm(const CPDF_Action& action); | |
| 303 FX_BOOL DoAction_ImportData(const CPDF_Action& action); | |
| 304 | |
| 305 std::vector<CPDF_FormField*> GetFieldFromObjects( | |
| 306 const std::vector<CPDF_Object*>& objects) const; | |
| 307 FX_BOOL IsValidField(CPDF_Dictionary* pFieldDict); | |
| 308 FX_BOOL SubmitFields(const CFX_WideString& csDestination, | |
| 309 const std::vector<CPDF_FormField*>& fields, | |
| 310 bool bIncludeOrExclude, | |
| 311 bool bUrlEncoded); | |
| 312 FX_BOOL SubmitForm(const CFX_WideString& sDestination, FX_BOOL bUrlEncoded); | |
| 313 FX_BOOL ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf); | |
| 314 FX_BOOL ExportFieldsToFDFTextBuf(const std::vector<CPDF_FormField*>& fields, | |
| 315 bool bIncludeOrExclude, | |
| 316 CFX_ByteTextBuf& textBuf); | |
| 317 CFX_WideString GetTemporaryFileName(const CFX_WideString& sFileExt); | |
| 318 | |
| 319 #ifdef PDF_ENABLE_XFA | |
| 320 void SynchronizeField(CPDF_FormField* pFormField, FX_BOOL bSynchronizeElse); | |
| 321 #endif // PDF_ENABLE_XFA | |
| 322 | |
| 323 private: | |
| 324 // IPDF_FormNotify: | |
| 325 int BeforeValueChange(CPDF_FormField* pField, | |
| 326 const CFX_WideString& csValue) override; | |
| 327 void AfterValueChange(CPDF_FormField* pField) override; | |
| 328 int BeforeSelectionChange(CPDF_FormField* pField, | |
| 329 const CFX_WideString& csValue) override; | |
| 330 void AfterSelectionChange(CPDF_FormField* pField) override; | |
| 331 void AfterCheckedStatusChange(CPDF_FormField* pField) override; | |
| 332 int BeforeFormReset(CPDF_InterForm* pForm) override; | |
| 333 void AfterFormReset(CPDF_InterForm* pForm) override; | |
| 334 int BeforeFormImportData(CPDF_InterForm* pForm) override; | |
| 335 void AfterFormImportData(CPDF_InterForm* pForm) override; | |
| 336 | |
| 337 FX_BOOL FDFToURLEncodedData(CFX_WideString csFDFFile, | |
| 338 CFX_WideString csTxtFile); | |
| 339 FX_BOOL FDFToURLEncodedData(uint8_t*& pBuf, FX_STRSIZE& nBufSize); | |
| 340 int GetPageIndexByAnnotDict(CPDF_Document* pDocument, | |
| 341 CPDF_Dictionary* pAnnotDict) const; | |
| 342 | |
| 343 using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>; | |
| 344 | |
| 345 CPDFSDK_Document* m_pDocument; | |
| 346 std::unique_ptr<CPDF_InterForm> m_pInterForm; | |
| 347 CPDFSDK_WidgetMap m_Map; | |
| 348 #ifdef PDF_ENABLE_XFA | |
| 349 std::map<CXFA_FFWidget*, CPDFSDK_XFAWidget*> m_XFAMap; | |
| 350 FX_BOOL m_bXfaCalculate; | |
| 351 FX_BOOL m_bXfaValidationsEnabled; | |
| 352 #endif // PDF_ENABLE_XFA | |
| 353 FX_BOOL m_bCalculate; | |
| 354 FX_BOOL m_bBusy; | |
| 355 | |
| 356 public: | |
| 357 FX_BOOL IsNeedHighLight(int nFieldType); | |
| 358 void RemoveAllHighLight(); | |
| 359 void SetHighlightAlpha(uint8_t alpha) { m_iHighlightAlpha = alpha; } | |
| 360 uint8_t GetHighlightAlpha() { return m_iHighlightAlpha; } | |
| 361 void SetHighlightColor(FX_COLORREF clr, int nFieldType); | |
| 362 FX_COLORREF GetHighlightColor(int nFieldType); | |
| 363 | |
| 364 private: | |
| 365 #ifndef PDF_ENABLE_XFA | |
| 366 static const int kNumFieldTypes = 6; | |
| 367 #else // PDF_ENABLE_XFA | |
| 368 static const int kNumFieldTypes = 7; | |
| 369 #endif // PDF_ENABLE_XFA | |
| 370 | |
| 371 FX_COLORREF m_aHighlightColor[kNumFieldTypes]; | |
| 372 uint8_t m_iHighlightAlpha; | |
| 373 FX_BOOL m_bNeedHightlight[kNumFieldTypes]; | |
| 374 }; | |
| 375 | |
| 376 class CBA_AnnotIterator { | |
| 377 public: | |
| 378 enum TabOrder { STRUCTURE = 0, ROW, COLUMN }; | |
| 379 | |
| 380 CBA_AnnotIterator(CPDFSDK_PageView* pPageView, | |
| 381 const CFX_ByteString& sType, | |
| 382 const CFX_ByteString& sSubType); | |
| 383 ~CBA_AnnotIterator(); | |
| 384 | |
| 385 CPDFSDK_Annot* GetFirstAnnot(); | |
| 386 CPDFSDK_Annot* GetLastAnnot(); | |
| 387 CPDFSDK_Annot* GetNextAnnot(CPDFSDK_Annot* pAnnot); | |
| 388 CPDFSDK_Annot* GetPrevAnnot(CPDFSDK_Annot* pAnnot); | |
| 389 | |
| 390 private: | |
| 391 void GenerateResults(); | |
| 392 static CFX_FloatRect GetAnnotRect(const CPDFSDK_Annot* pAnnot); | |
| 393 | |
| 394 // Function signature compatible with std::sort(). | |
| 395 static bool CompareByLeftAscending(const CPDFSDK_Annot* p1, | |
| 396 const CPDFSDK_Annot* p2); | |
| 397 static bool CompareByTopDescending(const CPDFSDK_Annot* p1, | |
| 398 const CPDFSDK_Annot* p2); | |
| 399 | |
| 400 TabOrder m_eTabOrder; | |
| 401 CPDFSDK_PageView* m_pPageView; | |
| 402 CFX_ByteString m_sType; | |
| 403 CFX_ByteString m_sSubType; | |
| 404 std::vector<CPDFSDK_Annot*> m_Annots; | |
| 405 }; | |
| 406 | |
| 407 #endif // FPDFSDK_INCLUDE_FSDK_BASEFORM_H_ | |
| OLD | NEW |