blob: 59c9c79b4df6ff1f4b0e682cf9fd2c06307b0ab2 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez19922bb2015-05-28 13:23:12 -07007#ifndef FPDFSDK_INCLUDE_FSDK_BASEANNOT_H_
8#define FPDFSDK_INCLUDE_FSDK_BASEANNOT_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
10#if _FX_OS_ == _FX_ANDROID_
11#include "time.h"
12#else
13#include <ctime>
14#endif
15
Lei Zhanga688a042015-11-09 13:57:49 -080016#include "core/include/fpdfdoc/fpdf_doc.h"
17#include "core/include/fxcrt/fx_basic.h"
Tom Sepez50d12ad2015-11-24 09:50:51 -080018#include "fpdfsdk/include/fsdk_define.h"
19#include "fpdfsdk/include/fx_systemhandler.h"
Tom Sepez245c80e2015-04-08 16:19:33 -070020
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021class CPDFSDK_PageView;
Tom Sepez245c80e2015-04-08 16:19:33 -070022class CPDF_Annot;
23class CPDF_Page;
24class CPDF_Rect;
25class CPDF_Matrix;
26class CPDF_RenderOptions;
27class CFX_RenderDevice;
28
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029#define CFX_IntArray CFX_ArrayTemplate<int>
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031class CPDFSDK_DateTime {
32 public:
33 CPDFSDK_DateTime();
34 CPDFSDK_DateTime(const CFX_ByteString& dtStr);
35 CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime);
36 CPDFSDK_DateTime(const FX_SYSTEMTIME& st);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070037
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038 CPDFSDK_DateTime& operator=(const CPDFSDK_DateTime& datetime);
39 CPDFSDK_DateTime& operator=(const FX_SYSTEMTIME& st);
40 FX_BOOL operator==(CPDFSDK_DateTime& datetime);
41 FX_BOOL operator!=(CPDFSDK_DateTime& datetime);
42 FX_BOOL operator>(CPDFSDK_DateTime& datetime);
43 FX_BOOL operator>=(CPDFSDK_DateTime& datetime);
44 FX_BOOL operator<(CPDFSDK_DateTime& datetime);
45 FX_BOOL operator<=(CPDFSDK_DateTime& datetime);
46 operator time_t();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070047
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048 CPDFSDK_DateTime& FromPDFDateTimeString(const CFX_ByteString& dtStr);
49 CFX_ByteString ToCommonDateTimeString();
50 CFX_ByteString ToPDFDateTimeString();
51 void ToSystemTime(FX_SYSTEMTIME& st);
52 CPDFSDK_DateTime ToGMT();
53 CPDFSDK_DateTime& AddDays(short days);
54 CPDFSDK_DateTime& AddSeconds(int seconds);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070055
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056 void ResetDateTime();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070057
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058 struct FX_DATETIME {
59 int16_t year;
60 uint8_t month;
61 uint8_t day;
62 uint8_t hour;
63 uint8_t minute;
64 uint8_t second;
65 int8_t tzHour;
66 uint8_t tzMinute;
67 } dt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068};
69
Nico Weber9d8ec5a2015-08-04 13:00:21 -070070class CPDFSDK_Annot {
71 public:
Dan Sinclairbfe042a2015-11-04 14:04:13 -050072 explicit CPDFSDK_Annot(CPDFSDK_PageView* pPageView);
73 virtual ~CPDFSDK_Annot() {}
Bo Xufdc00a72014-10-28 23:03:33 -070074
Tom Sepez51da0932015-11-25 16:05:49 -080075#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 virtual FX_BOOL IsXFAField() { return FALSE; }
Tom Sepez40e9ff32015-11-30 12:39:54 -080077#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 virtual FX_FLOAT GetMinWidth() const;
80 virtual FX_FLOAT GetMinHeight() const;
81 // define layout order to 5.
82 virtual int GetLayoutOrder() const { return 5; }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070083
Tom Sepez3343d142015-11-02 09:54:54 -080084 virtual CPDF_Annot* GetPDFAnnot() const { return nullptr; }
Tom Sepez40e9ff32015-11-30 12:39:54 -080085
Tom Sepez51da0932015-11-25 16:05:49 -080086#ifdef PDF_ENABLE_XFA
Tom Sepez3343d142015-11-02 09:54:54 -080087 virtual IXFA_Widget* GetXFAWidget() const { return nullptr; }
Tom Sepez40e9ff32015-11-30 12:39:54 -080088#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -070089
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 virtual CFX_ByteString GetType() const { return ""; }
91 virtual CFX_ByteString GetSubType() const { return ""; }
Bo Xufdc00a72014-10-28 23:03:33 -070092
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 virtual void SetRect(const CPDF_Rect& rect) {}
94 virtual CPDF_Rect GetRect() const { return CPDF_Rect(); }
Bo Xufdc00a72014-10-28 23:03:33 -070095
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096 virtual void Annot_OnDraw(CFX_RenderDevice* pDevice,
97 CPDF_Matrix* pUser2Device,
98 CPDF_RenderOptions* pOptions) {}
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070099
Tom Sepez50d12ad2015-11-24 09:50:51 -0800100 UnderlyingPageType* GetUnderlyingPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 CPDF_Page* GetPDFPage();
Tom Sepez51da0932015-11-25 16:05:49 -0800102#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103 CPDFXFA_Page* GetPDFXFAPage();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800104#endif // PDF_ENABLE_XFA
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700105
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 void SetPage(CPDFSDK_PageView* pPageView) { m_pPageView = pPageView; }
Tom Sepez3343d142015-11-02 09:54:54 -0800107 CPDFSDK_PageView* GetPageView() const { return m_pPageView; }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700108
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109 // Tab Order
110 int GetTabOrder();
111 void SetTabOrder(int iTabOrder);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700112
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 // Selection
114 FX_BOOL IsSelected();
115 void SetSelected(FX_BOOL bSelected);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700116
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 protected:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118 CPDFSDK_PageView* m_pPageView;
119 FX_BOOL m_bSelected;
120 int m_nTabOrder;
Bo Xufdc00a72014-10-28 23:03:33 -0700121};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700122
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123class CPDFSDK_BAAnnot : public CPDFSDK_Annot {
124 public:
125 CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView);
Lei Zhang5fd907b2015-11-19 22:20:59 -0800126 ~CPDFSDK_BAAnnot() override {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700127
Tom Sepez51da0932015-11-25 16:05:49 -0800128#ifdef PDF_ENABLE_XFA
Lei Zhang5fd907b2015-11-19 22:20:59 -0800129 FX_BOOL IsXFAField() override;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800130#endif // PDF_ENABLE_XFA
131
Lei Zhang5fd907b2015-11-19 22:20:59 -0800132 CFX_ByteString GetType() const override;
133 CFX_ByteString GetSubType() const override;
134 void SetRect(const CPDF_Rect& rect) override;
135 CPDF_Rect GetRect() const override;
136 CPDF_Annot* GetPDFAnnot() const override;
137 void Annot_OnDraw(CFX_RenderDevice* pDevice,
138 CPDF_Matrix* pUser2Device,
139 CPDF_RenderOptions* pOptions) override;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700140
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141 CPDF_Dictionary* GetAnnotDict() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700142
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 void SetContents(const CFX_WideString& sContents);
144 CFX_WideString GetContents() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700145
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 void SetAnnotName(const CFX_WideString& sName);
147 CFX_WideString GetAnnotName() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700148
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 void SetModifiedDate(const FX_SYSTEMTIME& st);
150 FX_SYSTEMTIME GetModifiedDate() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700151
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152 void SetFlags(int nFlags);
153 int GetFlags() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700154
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 void SetAppState(const CFX_ByteString& str);
156 CFX_ByteString GetAppState() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700157
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700158 void SetStructParent(int key);
159 int GetStructParent() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700160
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 // border
162 void SetBorderWidth(int nWidth);
163 int GetBorderWidth() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700164
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 // BBS_SOLID
166 // BBS_DASH
167 // BBS_BEVELED
168 // BBS_INSET
169 // BBS_UNDERLINE
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700170
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 void SetBorderStyle(int nStyle);
172 int GetBorderStyle() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700173
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 void SetBorderDash(const CFX_IntArray& array);
175 void GetBorderDash(CFX_IntArray& array) const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700176
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 // The background of the annotation's icon when closed
178 // The title bar of the annotation's pop-up window
179 // The border of a link annotation
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700180
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181 void SetColor(FX_COLORREF color);
182 void RemoveColor();
183 FX_BOOL GetColor(FX_COLORREF& color) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 FX_BOOL IsVisible() const;
186 // action
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700187
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 CPDF_Action GetAction() const;
189 void SetAction(const CPDF_Action& a);
190 void RemoveAction();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700191
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 CPDF_AAction GetAAction() const;
193 void SetAAction(const CPDF_AAction& aa);
194 void RemoveAAction();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700195
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 virtual CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700197
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 virtual FX_BOOL IsAppearanceValid();
199 virtual FX_BOOL IsAppearanceValid(CPDF_Annot::AppearanceMode mode);
200 virtual void DrawAppearance(CFX_RenderDevice* pDevice,
201 const CPDF_Matrix* pUser2Device,
202 CPDF_Annot::AppearanceMode mode,
203 const CPDF_RenderOptions* pOptions);
204 void DrawBorder(CFX_RenderDevice* pDevice,
205 const CPDF_Matrix* pUser2Device,
206 const CPDF_RenderOptions* pOptions);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700207
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 void ClearCachedAP();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 void WriteAppearance(const CFX_ByteString& sAPType,
211 const CPDF_Rect& rcBBox,
212 const CPDF_Matrix& matrix,
213 const CFX_ByteString& sContents,
214 const CFX_ByteString& sAPState = "");
215
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 protected:
217 CPDF_Annot* m_pAnnot;
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500218
219 private:
220 FX_BOOL CreateFormFiller();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700221};
222
Tom Sepez19922bb2015-05-28 13:23:12 -0700223#endif // FPDFSDK_INCLUDE_FSDK_BASEANNOT_H_