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_BASEANNOT_H_
8 #define FPDFSDK_INCLUDE_FSDK_BASEANNOT_H_
9 
10 #if _FX_OS_ == _FX_ANDROID_
11 #include "time.h"
12 #else
13 #include <ctime>
14 #endif
15 
16 #include "core/include/fpdfdoc/fpdf_doc.h"
17 #include "core/include/fxcrt/fx_basic.h"
18 #include "fpdfsdk/include/fsdk_define.h"
19 #include "fpdfsdk/include/fx_systemhandler.h"
20 
21 class CPDFSDK_PageView;
22 class CPDF_Annot;
23 class CPDF_Page;
24 class CFX_Matrix;
25 class CPDF_RenderOptions;
26 class CFX_RenderDevice;
27 
28 #define CFX_IntArray CFX_ArrayTemplate<int>
29 
30 class 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);
36 
37   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();
46 
47   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);
54 
55   void ResetDateTime();
56 
57   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;
67 };
68 
69 class CPDFSDK_Annot {
70  public:
71   explicit CPDFSDK_Annot(CPDFSDK_PageView* pPageView);
~CPDFSDK_Annot()72   virtual ~CPDFSDK_Annot() {}
73 
74 #ifdef PDF_ENABLE_XFA
IsXFAField()75   virtual FX_BOOL IsXFAField() { return FALSE; }
76 #endif  // PDF_ENABLE_XFA
77 
78   virtual FX_FLOAT GetMinWidth() const;
79   virtual FX_FLOAT GetMinHeight() const;
80   // define layout order to 5.
GetLayoutOrder()81   virtual int GetLayoutOrder() const { return 5; }
82 
GetPDFAnnot()83   virtual CPDF_Annot* GetPDFAnnot() const { return nullptr; }
84 
85 #ifdef PDF_ENABLE_XFA
GetXFAWidget()86   virtual IXFA_Widget* GetXFAWidget() const { return nullptr; }
87 #endif  // PDF_ENABLE_XFA
88 
GetType()89   virtual CFX_ByteString GetType() const { return ""; }
GetSubType()90   virtual CFX_ByteString GetSubType() const { return ""; }
91 
SetRect(const CPDF_Rect & rect)92   virtual void SetRect(const CPDF_Rect& rect) {}
GetRect()93   virtual CPDF_Rect GetRect() const { return CPDF_Rect(); }
94 
Annot_OnDraw(CFX_RenderDevice * pDevice,CFX_Matrix * pUser2Device,CPDF_RenderOptions * pOptions)95   virtual void Annot_OnDraw(CFX_RenderDevice* pDevice,
96                             CFX_Matrix* pUser2Device,
97                             CPDF_RenderOptions* pOptions) {}
98 
99   UnderlyingPageType* GetUnderlyingPage();
100   CPDF_Page* GetPDFPage();
101 #ifdef PDF_ENABLE_XFA
102   CPDFXFA_Page* GetPDFXFAPage();
103 #endif  // PDF_ENABLE_XFA
104 
SetPage(CPDFSDK_PageView * pPageView)105   void SetPage(CPDFSDK_PageView* pPageView) { m_pPageView = pPageView; }
GetPageView()106   CPDFSDK_PageView* GetPageView() const { return m_pPageView; }
107 
108   // Tab Order
109   int GetTabOrder();
110   void SetTabOrder(int iTabOrder);
111 
112   // Selection
113   FX_BOOL IsSelected();
114   void SetSelected(FX_BOOL bSelected);
115 
116  protected:
117   CPDFSDK_PageView* m_pPageView;
118   FX_BOOL m_bSelected;
119   int m_nTabOrder;
120 };
121 
122 class CPDFSDK_BAAnnot : public CPDFSDK_Annot {
123  public:
124   CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView);
~CPDFSDK_BAAnnot()125   ~CPDFSDK_BAAnnot() override {}
126 
127 #ifdef PDF_ENABLE_XFA
128   FX_BOOL IsXFAField() override;
129 #endif  // PDF_ENABLE_XFA
130 
131   CFX_ByteString GetType() const override;
132   CFX_ByteString GetSubType() const override;
133   void SetRect(const CPDF_Rect& rect) override;
134   CPDF_Rect GetRect() const override;
135   CPDF_Annot* GetPDFAnnot() const override;
136   void Annot_OnDraw(CFX_RenderDevice* pDevice,
137                     CFX_Matrix* pUser2Device,
138                     CPDF_RenderOptions* pOptions) override;
139 
140   CPDF_Dictionary* GetAnnotDict() const;
141 
142   void SetContents(const CFX_WideString& sContents);
143   CFX_WideString GetContents() const;
144 
145   void SetAnnotName(const CFX_WideString& sName);
146   CFX_WideString GetAnnotName() const;
147 
148   void SetModifiedDate(const FX_SYSTEMTIME& st);
149   FX_SYSTEMTIME GetModifiedDate() const;
150 
151   void SetFlags(int nFlags);
152   int GetFlags() const;
153 
154   void SetAppState(const CFX_ByteString& str);
155   CFX_ByteString GetAppState() const;
156 
157   void SetStructParent(int key);
158   int GetStructParent() const;
159 
160   // border
161   void SetBorderWidth(int nWidth);
162   int GetBorderWidth() const;
163 
164   // BBS_SOLID
165   // BBS_DASH
166   // BBS_BEVELED
167   // BBS_INSET
168   // BBS_UNDERLINE
169 
170   void SetBorderStyle(int nStyle);
171   int GetBorderStyle() const;
172 
173   void SetBorderDash(const CFX_IntArray& array);
174   void GetBorderDash(CFX_IntArray& array) const;
175 
176   // The background of the annotation's icon when closed
177   // The title bar of the annotation's pop-up window
178   // The border of a link annotation
179 
180   void SetColor(FX_COLORREF color);
181   void RemoveColor();
182   FX_BOOL GetColor(FX_COLORREF& color) const;
183 
184   FX_BOOL IsVisible() const;
185   // action
186 
187   CPDF_Action GetAction() const;
188   void SetAction(const CPDF_Action& a);
189   void RemoveAction();
190 
191   CPDF_AAction GetAAction() const;
192   void SetAAction(const CPDF_AAction& aa);
193   void RemoveAAction();
194 
195   virtual CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT);
196 
197   virtual FX_BOOL IsAppearanceValid();
198   virtual FX_BOOL IsAppearanceValid(CPDF_Annot::AppearanceMode mode);
199   virtual void DrawAppearance(CFX_RenderDevice* pDevice,
200                               const CFX_Matrix* pUser2Device,
201                               CPDF_Annot::AppearanceMode mode,
202                               const CPDF_RenderOptions* pOptions);
203   void DrawBorder(CFX_RenderDevice* pDevice,
204                   const CFX_Matrix* pUser2Device,
205                   const CPDF_RenderOptions* pOptions);
206 
207   void ClearCachedAP();
208 
209   void WriteAppearance(const CFX_ByteString& sAPType,
210                        const CPDF_Rect& rcBBox,
211                        const CFX_Matrix& matrix,
212                        const CFX_ByteString& sContents,
213                        const CFX_ByteString& sAPState = "");
214 
215  protected:
216   CPDF_Annot* m_pAnnot;
217 
218  private:
219   FX_BOOL CreateFormFiller();
220 };
221 
222 #endif  // FPDFSDK_INCLUDE_FSDK_BASEANNOT_H_
223