5f56fc70007468f6fd587353e8adf27380d8cee1
[pdfium.git] / fpdfsdk / include / fsdk_baseannot.h
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 _FSDK_BASEANNOT_H_
8 #define _FSDK_BASEANNOT_H_
9
10 #if _FX_OS_ == _FX_ANDROID_
11 #include "time.h"
12 #else
13 #include <ctime>
14 #endif
15
16 class CPDFSDK_PageView;
17 #define CFX_IntArray                            CFX_ArrayTemplate<int>
18
19 class  CPDFSDK_DateTime : public CFX_Object
20 {
21 public:
22         CPDFSDK_DateTime();
23         CPDFSDK_DateTime(const CFX_ByteString& dtStr);
24         CPDFSDK_DateTime(const CPDFSDK_DateTime& datetime);
25         CPDFSDK_DateTime(const FX_SYSTEMTIME& st);
26         
27         
28         CPDFSDK_DateTime&       operator = (const CPDFSDK_DateTime& datetime);
29         CPDFSDK_DateTime&       operator = (const FX_SYSTEMTIME& st);
30         FX_BOOL                         operator == (CPDFSDK_DateTime& datetime);
31         FX_BOOL                         operator != (CPDFSDK_DateTime& datetime);
32         FX_BOOL                         operator > (CPDFSDK_DateTime& datetime);
33         FX_BOOL                         operator >= (CPDFSDK_DateTime& datetime);
34         FX_BOOL                         operator < (CPDFSDK_DateTime& datetime);
35         FX_BOOL                         operator <= (CPDFSDK_DateTime& datetime);       
36                                                 operator time_t();
37         
38         CPDFSDK_DateTime&       FromPDFDateTimeString(const CFX_ByteString& dtStr);
39         CFX_ByteString          ToCommonDateTimeString();
40         CFX_ByteString          ToPDFDateTimeString();
41         void                            ToSystemTime(FX_SYSTEMTIME& st);
42         CPDFSDK_DateTime        ToGMT();
43         CPDFSDK_DateTime&       AddDays(short days);
44         CPDFSDK_DateTime&       AddSeconds(int seconds);
45         
46         void                            ResetDateTime();
47         
48         struct FX_DATETIME
49         {
50                 FX_SHORT        year;
51                 FX_BYTE         month;
52                 FX_BYTE         day;
53                 FX_BYTE         hour;
54                 FX_BYTE         minute;
55                 FX_BYTE         second;
56                 FX_INT8         tzHour;
57                 FX_BYTE         tzMinute;
58         }dt;
59 };
60
61 class CPDFSDK_Annot
62 {
63 public:
64         CPDFSDK_Annot(CPDFSDK_PageView* pPageView);
65     virtual ~CPDFSDK_Annot() {};
66 public:
67         virtual FX_BOOL                         IsXFAField() { return FALSE; }
68
69         virtual FX_FLOAT                        GetMinWidth() const;
70         virtual FX_FLOAT                        GetMinHeight() const;
71         //define layout order to 5.
72         virtual int                                     GetLayoutOrder() const { return 5; }
73
74         virtual CPDF_Annot*                     GetPDFAnnot() { return NULL; }
75         virtual XFA_HWIDGET                     GetXFAWidget() { return NULL; }
76         
77         virtual CFX_ByteString          GetType() const { return ""; }
78         virtual CFX_ByteString          GetSubType() const { return ""; }
79
80         virtual void                            SetRect(const CPDF_Rect& rect) {}
81         virtual CPDF_Rect                       GetRect() const { return CPDF_Rect(); }
82
83         virtual void                            Annot_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions) {}
84
85 public:
86         CPDF_Page*                                      GetPDFPage();
87         CPDFXFA_Page*                           GetPDFXFAPage();
88         
89         void                                            SetPage(CPDFSDK_PageView* pPageView) { m_pPageView = pPageView; }
90         CPDFSDK_PageView*                       GetPageView() { return m_pPageView; }
91         
92         // Tab Order    
93         int                                                     GetTabOrder();
94         void                                            SetTabOrder(int iTabOrder);
95         
96         // Selection
97         FX_BOOL                                         IsSelected();
98         void                                            SetSelected(FX_BOOL bSelected);
99         
100 protected:
101         CPDF_Annot*                     m_pAnnot;
102         CPDFSDK_PageView*       m_pPageView;
103         FX_BOOL                         m_bSelected;
104         int                                     m_nTabOrder;
105         
106 };
107
108 class CPDFSDK_BAAnnot : public CPDFSDK_Annot
109 {
110 public:
111         CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView);
112         virtual ~CPDFSDK_BAAnnot();
113
114 public:
115         virtual FX_BOOL                         IsXFAField();
116
117         virtual CFX_ByteString          GetType() const;
118         virtual CFX_ByteString          GetSubType() const;
119
120         virtual void                            SetRect(const CPDF_Rect& rect);
121         virtual CPDF_Rect                       GetRect() const;
122
123         virtual CPDF_Annot*                     GetPDFAnnot();
124
125         virtual void                            Annot_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions);
126 public:
127         CPDF_Dictionary*                        GetAnnotDict() const;
128         
129         void                                            SetContents(const CFX_WideString& sContents);
130         CFX_WideString                          GetContents() const;
131         
132         void                                            SetAnnotName(const CFX_WideString& sName);
133         CFX_WideString                          GetAnnotName() const;
134         
135         void                                            SetModifiedDate(const FX_SYSTEMTIME& st);
136         FX_SYSTEMTIME                           GetModifiedDate() const;
137
138         void                                            SetFlags(int nFlags);
139         int                                                     GetFlags() const;
140
141         void                                            SetAppState(const CFX_ByteString& str);
142         CFX_ByteString                          GetAppState() const;
143         
144         void                                            SetStructParent(int key);
145         int                                                     GetStructParent() const;
146         
147         //border
148         void                                            SetBorderWidth(int nWidth);
149         int                                                     GetBorderWidth() const;
150         
151         //BBS_SOLID
152         //BBS_DASH
153         //BBS_BEVELED
154         //BBS_INSET
155         //BBS_UNDERLINE
156         
157         void                                            SetBorderStyle(int nStyle);
158         int                                                     GetBorderStyle() const;
159         
160         void                                            SetBorderDash(const CFX_IntArray& array);
161         void                                            GetBorderDash(CFX_IntArray& array) const;
162         
163         //The background of the annotation's icon when closed
164         //The title bar of the annotation's pop-up window
165         //The border of a link annotation
166         
167         void                                            SetColor(FX_COLORREF color);
168         void                                            RemoveColor();
169         FX_BOOL                                         GetColor(FX_COLORREF& color) const;
170         
171         FX_BOOL                                         IsVisible() const;
172         //action
173
174         CPDF_Action                                     GetAction() const;
175         void                                            SetAction(const CPDF_Action& a);
176         void                                            RemoveAction();
177         
178         CPDF_AAction                            GetAAction() const;
179         void                                            SetAAction(const CPDF_AAction& aa);
180         void                                            RemoveAAction();
181         
182         virtual CPDF_Action                     GetAAction(CPDF_AAction::AActionType eAAT);
183         
184 public:
185         virtual FX_BOOL                         IsAppearanceValid();
186         virtual FX_BOOL                         IsAppearanceValid(CPDF_Annot::AppearanceMode mode);
187         virtual void                            DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
188                 CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions);
189         void                                            DrawBorder(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
190                 const CPDF_RenderOptions* pOptions);
191         
192         void                                            ClearCachedAP();
193         
194         virtual void                            ResetAppearance();
195         void                                            WriteAppearance(const CFX_ByteString& sAPType, const CPDF_Rect& rcBBox, 
196                 const CPDF_Matrix& matrix, const CFX_ByteString& sContents,
197                 const CFX_ByteString& sAPState = "");
198
199 private:
200         FX_BOOL CreateFormFiller();
201 protected:
202         CPDF_Annot*                     m_pAnnot;
203 };
204
205
206
207 #endif
208