blob: 58abfff49eed36bc7284fd2585a5e529c6c12ef3 [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
Tom Sepez245c80e2015-04-08 16:19:33 -070016#include "../../core/include/fpdfdoc/fpdf_doc.h"
17#include "../../core/include/fxcrt/fx_basic.h"
18#include "fx_systemhandler.h"
19
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020class CPDFSDK_PageView;
Tom Sepez245c80e2015-04-08 16:19:33 -070021class CPDF_Annot;
22class CPDF_Page;
23class CPDF_Rect;
24class CPDF_Matrix;
25class CPDF_RenderOptions;
26class CFX_RenderDevice;
27
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028#define CFX_IntArray CFX_ArrayTemplate<int>
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070029
Nico Weber9d8ec5a2015-08-04 13:00:21 -070030class CPDFSDK_DateTime {
31 public:
32 CPDFSDK_DateTime();
33 CPDFSDK_DateTime(const CFX_ByteString& dtStr);
34 CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime);
35 CPDFSDK_DateTime(const FX_SYSTEMTIME& st);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070036
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037 CPDFSDK_DateTime& operator=(const CPDFSDK_DateTime& datetime);
38 CPDFSDK_DateTime& operator=(const FX_SYSTEMTIME& st);
39 FX_BOOL operator==(CPDFSDK_DateTime& datetime);
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 operator time_t();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070046
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047 CPDFSDK_DateTime& FromPDFDateTimeString(const CFX_ByteString& dtStr);
48 CFX_ByteString ToCommonDateTimeString();
49 CFX_ByteString ToPDFDateTimeString();
50 void ToSystemTime(FX_SYSTEMTIME& st);
51 CPDFSDK_DateTime ToGMT();
52 CPDFSDK_DateTime& AddDays(short days);
53 CPDFSDK_DateTime& AddSeconds(int seconds);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070054
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 void ResetDateTime();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070056
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 struct FX_DATETIME {
58 int16_t year;
59 uint8_t month;
60 uint8_t day;
61 uint8_t hour;
62 uint8_t minute;
63 uint8_t second;
64 int8_t tzHour;
65 uint8_t tzMinute;
66 } dt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070067};
68
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069class CPDFSDK_Annot {
70 public:
71 CPDFSDK_Annot(CPDFSDK_PageView* pPageView);
72 virtual ~CPDFSDK_Annot(){};
Bo Xufdc00a72014-10-28 23:03:33 -070073
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074 virtual FX_BOOL IsXFAField() { return FALSE; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 virtual FX_FLOAT GetMinWidth() const;
77 virtual FX_FLOAT GetMinHeight() const;
78 // define layout order to 5.
79 virtual int GetLayoutOrder() const { return 5; }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070080
Tom Sepez3343d142015-11-02 09:54:54 -080081 virtual CPDF_Annot* GetPDFAnnot() const { return nullptr; }
82 virtual IXFA_Widget* GetXFAWidget() const { return nullptr; }
Bo Xufdc00a72014-10-28 23:03:33 -070083
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 virtual CFX_ByteString GetType() const { return ""; }
85 virtual CFX_ByteString GetSubType() const { return ""; }
Bo Xufdc00a72014-10-28 23:03:33 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 virtual void SetRect(const CPDF_Rect& rect) {}
88 virtual CPDF_Rect GetRect() const { return CPDF_Rect(); }
Bo Xufdc00a72014-10-28 23:03:33 -070089
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 virtual void Annot_OnDraw(CFX_RenderDevice* pDevice,
91 CPDF_Matrix* pUser2Device,
92 CPDF_RenderOptions* pOptions) {}
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070093
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 CPDF_Page* GetPDFPage();
95 CPDFXFA_Page* GetPDFXFAPage();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070096
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 void SetPage(CPDFSDK_PageView* pPageView) { m_pPageView = pPageView; }
Tom Sepez3343d142015-11-02 09:54:54 -080098 CPDFSDK_PageView* GetPageView() const { return m_pPageView; }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070099
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100 // Tab Order
101 int GetTabOrder();
102 void SetTabOrder(int iTabOrder);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700103
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 // Selection
105 FX_BOOL IsSelected();
106 void SetSelected(FX_BOOL bSelected);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700107
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 protected:
109 CPDF_Annot* m_pAnnot;
110 CPDFSDK_PageView* m_pPageView;
111 FX_BOOL m_bSelected;
112 int m_nTabOrder;
Bo Xufdc00a72014-10-28 23:03:33 -0700113};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115class CPDFSDK_BAAnnot : public CPDFSDK_Annot {
116 public:
117 CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView);
118 virtual ~CPDFSDK_BAAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 public:
121 virtual FX_BOOL IsXFAField();
Bo Xufdc00a72014-10-28 23:03:33 -0700122
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 virtual CFX_ByteString GetType() const;
124 virtual CFX_ByteString GetSubType() const;
Bo Xufdc00a72014-10-28 23:03:33 -0700125
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126 virtual void SetRect(const CPDF_Rect& rect);
127 virtual CPDF_Rect GetRect() const;
Bo Xufdc00a72014-10-28 23:03:33 -0700128
Tom Sepez3343d142015-11-02 09:54:54 -0800129 virtual CPDF_Annot* GetPDFAnnot() const;
Bo Xufdc00a72014-10-28 23:03:33 -0700130
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 virtual void Annot_OnDraw(CFX_RenderDevice* pDevice,
132 CPDF_Matrix* pUser2Device,
133 CPDF_RenderOptions* pOptions);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 public:
136 CPDF_Dictionary* GetAnnotDict() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700137
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138 void SetContents(const CFX_WideString& sContents);
139 CFX_WideString GetContents() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700140
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141 void SetAnnotName(const CFX_WideString& sName);
142 CFX_WideString GetAnnotName() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 void SetModifiedDate(const FX_SYSTEMTIME& st);
145 FX_SYSTEMTIME GetModifiedDate() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700146
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147 void SetFlags(int nFlags);
148 int GetFlags() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700149
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150 void SetAppState(const CFX_ByteString& str);
151 CFX_ByteString GetAppState() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700152
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700153 void SetStructParent(int key);
154 int GetStructParent() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700155
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 // border
157 void SetBorderWidth(int nWidth);
158 int GetBorderWidth() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 // BBS_SOLID
161 // BBS_DASH
162 // BBS_BEVELED
163 // BBS_INSET
164 // BBS_UNDERLINE
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700165
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 void SetBorderStyle(int nStyle);
167 int GetBorderStyle() const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700168
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 void SetBorderDash(const CFX_IntArray& array);
170 void GetBorderDash(CFX_IntArray& array) const;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700171
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 // The background of the annotation's icon when closed
173 // The title bar of the annotation's pop-up window
174 // The border of a link annotation
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700175
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 void SetColor(FX_COLORREF color);
177 void RemoveColor();
178 FX_BOOL GetColor(FX_COLORREF& color) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700179
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180 FX_BOOL IsVisible() const;
181 // action
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700182
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 CPDF_Action GetAction() const;
184 void SetAction(const CPDF_Action& a);
185 void RemoveAction();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700186
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 CPDF_AAction GetAAction() const;
188 void SetAAction(const CPDF_AAction& aa);
189 void RemoveAAction();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700190
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 virtual CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700192
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193 public:
194 virtual FX_BOOL IsAppearanceValid();
195 virtual FX_BOOL IsAppearanceValid(CPDF_Annot::AppearanceMode mode);
196 virtual void DrawAppearance(CFX_RenderDevice* pDevice,
197 const CPDF_Matrix* pUser2Device,
198 CPDF_Annot::AppearanceMode mode,
199 const CPDF_RenderOptions* pOptions);
200 void DrawBorder(CFX_RenderDevice* pDevice,
201 const CPDF_Matrix* pUser2Device,
202 const CPDF_RenderOptions* pOptions);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700203
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204 void ClearCachedAP();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700205
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 void WriteAppearance(const CFX_ByteString& sAPType,
207 const CPDF_Rect& rcBBox,
208 const CPDF_Matrix& matrix,
209 const CFX_ByteString& sContents,
210 const CFX_ByteString& sAPState = "");
211
212 private:
213 FX_BOOL CreateFormFiller();
214
215 protected:
216 CPDF_Annot* m_pAnnot;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700217};
218
Tom Sepez19922bb2015-05-28 13:23:12 -0700219#endif // FPDFSDK_INCLUDE_FSDK_BASEANNOT_H_