blob: ce65383e6b42729c1fa3fd2f25402eef6b735697 [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"
Tom Sepez51da0932015-11-25 16:05:49 -080019#ifndef PDF_ENABLE_XFA
20#include "fx_systemhandler.h"
21#else
Tom Sepez50d12ad2015-11-24 09:50:51 -080022#include "fpdfsdk/include/fx_systemhandler.h"
Tom Sepez51da0932015-11-25 16:05:49 -080023#endif
Tom Sepez245c80e2015-04-08 16:19:33 -070024
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025class CPDFSDK_PageView;
Tom Sepez245c80e2015-04-08 16:19:33 -070026class CPDF_Annot;
27class CPDF_Page;
28class CPDF_Rect;
29class CPDF_Matrix;
30class CPDF_RenderOptions;
31class CFX_RenderDevice;
32
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033#define CFX_IntArray CFX_ArrayTemplate<int>
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035class CPDFSDK_DateTime {
36 public:
37 CPDFSDK_DateTime();
38 CPDFSDK_DateTime(const CFX_ByteString& dtStr);
39 CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime);
40 CPDFSDK_DateTime(const FX_SYSTEMTIME& st);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070041
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042 CPDFSDK_DateTime& operator=(const CPDFSDK_DateTime& datetime);
43 CPDFSDK_DateTime& operator=(const FX_SYSTEMTIME& st);
44 FX_BOOL operator==(CPDFSDK_DateTime& datetime);
45 FX_BOOL operator!=(CPDFSDK_DateTime& datetime);
46 FX_BOOL operator>(CPDFSDK_DateTime& datetime);
47 FX_BOOL operator>=(CPDFSDK_DateTime& datetime);
48 FX_BOOL operator<(CPDFSDK_DateTime& datetime);
49 FX_BOOL operator<=(CPDFSDK_DateTime& datetime);
50 operator time_t();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070051
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052 CPDFSDK_DateTime& FromPDFDateTimeString(const CFX_ByteString& dtStr);
53 CFX_ByteString ToCommonDateTimeString();
54 CFX_ByteString ToPDFDateTimeString();
55 void ToSystemTime(FX_SYSTEMTIME& st);
56 CPDFSDK_DateTime ToGMT();
57 CPDFSDK_DateTime& AddDays(short days);
58 CPDFSDK_DateTime& AddSeconds(int seconds);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070059
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060 void ResetDateTime();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070061
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062 struct FX_DATETIME {
63 int16_t year;
64 uint8_t month;
65 uint8_t day;
66 uint8_t hour;
67 uint8_t minute;
68 uint8_t second;
69 int8_t tzHour;
70 uint8_t tzMinute;
71 } dt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072};
73
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074class CPDFSDK_Annot {
75 public:
Dan Sinclairbfe042a2015-11-04 14:04:13 -050076 explicit CPDFSDK_Annot(CPDFSDK_PageView* pPageView);
77 virtual ~CPDFSDK_Annot() {}
Bo Xufdc00a72014-10-28 23:03:33 -070078
Tom Sepez51da0932015-11-25 16:05:49 -080079#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 virtual FX_BOOL IsXFAField() { return FALSE; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081
Tom Sepez51da0932015-11-25 16:05:49 -080082#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 virtual FX_FLOAT GetMinWidth() const;
84 virtual FX_FLOAT GetMinHeight() const;
85 // define layout order to 5.
86 virtual int GetLayoutOrder() const { return 5; }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070087
Tom Sepez3343d142015-11-02 09:54:54 -080088 virtual CPDF_Annot* GetPDFAnnot() const { return nullptr; }
Tom Sepez51da0932015-11-25 16:05:49 -080089#ifdef PDF_ENABLE_XFA
Tom Sepez3343d142015-11-02 09:54:54 -080090 virtual IXFA_Widget* GetXFAWidget() const { return nullptr; }
Tom Sepez51da0932015-11-25 16:05:49 -080091#endif
Bo Xufdc00a72014-10-28 23:03:33 -070092
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 virtual CFX_ByteString GetType() const { return ""; }
94 virtual CFX_ByteString GetSubType() const { return ""; }
Bo Xufdc00a72014-10-28 23:03:33 -070095
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096 virtual void SetRect(const CPDF_Rect& rect) {}
97 virtual CPDF_Rect GetRect() const { return CPDF_Rect(); }
Bo Xufdc00a72014-10-28 23:03:33 -070098
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 virtual void Annot_OnDraw(CFX_RenderDevice* pDevice,
100 CPDF_Matrix* pUser2Device,
101 CPDF_RenderOptions* pOptions) {}
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700102
Tom Sepez50d12ad2015-11-24 09:50:51 -0800103 UnderlyingPageType* GetUnderlyingPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 CPDF_Page* GetPDFPage();
Tom Sepez51da0932015-11-25 16:05:49 -0800105#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 CPDFXFA_Page* GetPDFXFAPage();
Tom Sepez51da0932015-11-25 16:05:49 -0800107#endif
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700108
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109 void SetPage(CPDFSDK_PageView* pPageView) { m_pPageView = pPageView; }
Tom Sepez3343d142015-11-02 09:54:54 -0800110 CPDFSDK_PageView* GetPageView() const { return m_pPageView; }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700111
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 // Tab Order
113 int GetTabOrder();
114 void SetTabOrder(int iTabOrder);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700115
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 // Selection
117 FX_BOOL IsSelected();
118 void SetSelected(FX_BOOL bSelected);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700119
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 protected:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 CPDFSDK_PageView* m_pPageView;
122 FX_BOOL m_bSelected;
123 int m_nTabOrder;
Bo Xufdc00a72014-10-28 23:03:33 -0700124};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126class CPDFSDK_BAAnnot : public CPDFSDK_Annot {
127 public:
128 CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView);
Lei Zhang5fd907b2015-11-19 22:20:59 -0800129 ~CPDFSDK_BAAnnot() override {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130
Tom Sepez51da0932015-11-25 16:05:49 -0800131#ifdef PDF_ENABLE_XFA
Lei Zhang5fd907b2015-11-19 22:20:59 -0800132 FX_BOOL IsXFAField() override;
Tom Sepez51da0932015-11-25 16:05:49 -0800133#endif
Lei Zhang5fd907b2015-11-19 22:20:59 -0800134 CFX_ByteString GetType() const override;
135 CFX_ByteString GetSubType() const override;
136 void SetRect(const CPDF_Rect& rect) override;
137 CPDF_Rect GetRect() const override;
138 CPDF_Annot* GetPDFAnnot() const override;
139 void Annot_OnDraw(CFX_RenderDevice* pDevice,
140 CPDF_Matrix* pUser2Device,
141 CPDF_RenderOptions* pOptions) override;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700142
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 CPDF_Dictionary* GetAnnotDict() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 void SetContents(const CFX_WideString& sContents);
146 CFX_WideString GetContents() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700147
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 void SetAnnotName(const CFX_WideString& sName);
149 CFX_WideString GetAnnotName() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 void SetModifiedDate(const FX_SYSTEMTIME& st);
152 FX_SYSTEMTIME GetModifiedDate() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700153
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154 void SetFlags(int nFlags);
155 int GetFlags() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700156
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 void SetAppState(const CFX_ByteString& str);
158 CFX_ByteString GetAppState() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 void SetStructParent(int key);
161 int GetStructParent() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700162
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 // border
164 void SetBorderWidth(int nWidth);
165 int GetBorderWidth() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700166
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 // BBS_SOLID
168 // BBS_DASH
169 // BBS_BEVELED
170 // BBS_INSET
171 // BBS_UNDERLINE
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700172
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 void SetBorderStyle(int nStyle);
174 int GetBorderStyle() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700175
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 void SetBorderDash(const CFX_IntArray& array);
177 void GetBorderDash(CFX_IntArray& array) const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700178
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 // The background of the annotation's icon when closed
180 // The title bar of the annotation's pop-up window
181 // The border of a link annotation
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700182
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 void SetColor(FX_COLORREF color);
184 void RemoveColor();
185 FX_BOOL GetColor(FX_COLORREF& color) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700186
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 FX_BOOL IsVisible() const;
188 // action
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700189
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700190 CPDF_Action GetAction() const;
191 void SetAction(const CPDF_Action& a);
192 void RemoveAction();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700193
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194 CPDF_AAction GetAAction() const;
195 void SetAAction(const CPDF_AAction& aa);
196 void RemoveAAction();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700197
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 virtual CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700199
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 virtual FX_BOOL IsAppearanceValid();
201 virtual FX_BOOL IsAppearanceValid(CPDF_Annot::AppearanceMode mode);
202 virtual void DrawAppearance(CFX_RenderDevice* pDevice,
203 const CPDF_Matrix* pUser2Device,
204 CPDF_Annot::AppearanceMode mode,
205 const CPDF_RenderOptions* pOptions);
206 void DrawBorder(CFX_RenderDevice* pDevice,
207 const CPDF_Matrix* pUser2Device,
208 const CPDF_RenderOptions* pOptions);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700209
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 void ClearCachedAP();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 void WriteAppearance(const CFX_ByteString& sAPType,
213 const CPDF_Rect& rcBBox,
214 const CPDF_Matrix& matrix,
215 const CFX_ByteString& sContents,
216 const CFX_ByteString& sAPState = "");
217
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218 protected:
219 CPDF_Annot* m_pAnnot;
Dan Sinclairbfe042a2015-11-04 14:04:13 -0500220
221 private:
222 FX_BOOL CreateFormFiller();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700223};
224
Tom Sepez19922bb2015-05-28 13:23:12 -0700225#endif // FPDFSDK_INCLUDE_FSDK_BASEANNOT_H_