blob: 1ab988a6603c168277aa170701827bc875ad2d17 [file] [log] [blame]
jaepark611adb82016-08-17 11:34:36 -07001// Copyright 2016 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
dsinclair114e46a2016-09-29 17:18:21 -07007#ifndef FPDFSDK_CPDFSDK_WIDGET_H_
8#define FPDFSDK_CPDFSDK_WIDGET_H_
jaepark611adb82016-08-17 11:34:36 -07009
10#include <set>
11
dsinclair1727aee2016-09-29 13:12:56 -070012#include "core/fpdfdoc/cpdf_aaction.h"
13#include "core/fpdfdoc/cpdf_action.h"
14#include "core/fpdfdoc/cpdf_annot.h"
dsinclaira52ab742016-09-29 13:59:29 -070015#include "core/fxcrt/fx_coordinates.h"
16#include "core/fxcrt/fx_string.h"
dsinclair114e46a2016-09-29 17:18:21 -070017#include "fpdfsdk/cpdfsdk_baannot.h"
18#include "fpdfsdk/pdfsdk_fieldaction.h"
jaepark611adb82016-08-17 11:34:36 -070019#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
20
21class CFX_RenderDevice;
22class CPDF_Annot;
23class CPDF_Dictionary;
24class CPDF_FormControl;
25class CPDF_FormField;
26class CPDF_RenderOptions;
27class CPDF_Stream;
28class CPDFSDK_InterForm;
29class CPDFSDK_PageView;
30
31#ifdef PDF_ENABLE_XFA
32class CXFA_FFWidget;
33class CXFA_FFWidgetHandler;
34#endif // PDF_ENABLE_XFA
35
36class CPDFSDK_Widget : public CPDFSDK_BAAnnot {
37 public:
jaepark611adb82016-08-17 11:34:36 -070038#ifdef PDF_ENABLE_XFA
39 CXFA_FFWidget* GetMixXFAWidget() const;
40 CXFA_FFWidget* GetGroupMixXFAWidget();
41 CXFA_FFWidgetHandler* GetXFAWidgetHandler() const;
42
43 FX_BOOL HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT);
44 FX_BOOL OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
45 PDFSDK_FieldAction& data,
46 CPDFSDK_PageView* pPageView);
47
48 void Synchronize(FX_BOOL bSynchronizeElse);
49 void SynchronizeXFAValue();
50 void SynchronizeXFAItems();
51
52 static void SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
53 CXFA_FFWidget* hWidget,
54 CPDF_FormField* pFormField,
55 CPDF_FormControl* pFormControl);
56 static void SynchronizeXFAItems(CXFA_FFDocView* pXFADocView,
57 CXFA_FFWidget* hWidget,
58 CPDF_FormField* pFormField,
59 CPDF_FormControl* pFormControl);
60#endif // PDF_ENABLE_XFA
61
62 CPDFSDK_Widget(CPDF_Annot* pAnnot,
63 CPDFSDK_PageView* pPageView,
64 CPDFSDK_InterForm* pInterForm);
65 ~CPDFSDK_Widget() override;
66
jaepark9ed91372016-08-26 16:16:10 -070067 bool IsSignatureWidget() const override;
jaepark611adb82016-08-17 11:34:36 -070068 CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT) override;
69 FX_BOOL IsAppearanceValid() override;
70
71 int GetLayoutOrder() const override;
72
73 int GetFieldType() const;
74 int GetFieldFlags() const;
75 int GetRotate() const;
76
77 FX_BOOL GetFillColor(FX_COLORREF& color) const;
78 FX_BOOL GetBorderColor(FX_COLORREF& color) const;
79 FX_BOOL GetTextColor(FX_COLORREF& color) const;
80 FX_FLOAT GetFontSize() const;
81
82 int GetSelectedIndex(int nIndex) const;
83#ifndef PDF_ENABLE_XFA
84 CFX_WideString GetValue() const;
85#else
86 CFX_WideString GetValue(FX_BOOL bDisplay = TRUE) const;
87#endif // PDF_ENABLE_XFA
88 CFX_WideString GetDefaultValue() const;
89 CFX_WideString GetOptionLabel(int nIndex) const;
90 int CountOptions() const;
91 FX_BOOL IsOptionSelected(int nIndex) const;
92 int GetTopVisibleIndex() const;
93 bool IsChecked() const;
94 int GetAlignment() const;
95 int GetMaxLen() const;
96#ifdef PDF_ENABLE_XFA
97 CFX_WideString GetName() const;
98#endif // PDF_ENABLE_XFA
99 CFX_WideString GetAlternateName() const;
100
101 void SetCheck(bool bChecked, bool bNotify);
102 void SetValue(const CFX_WideString& sValue, FX_BOOL bNotify);
103 void SetDefaultValue(const CFX_WideString& sValue);
104 void SetOptionSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify);
105 void ClearSelection(FX_BOOL bNotify);
106 void SetTopVisibleIndex(int index);
107
108#ifdef PDF_ENABLE_XFA
109 void ResetAppearance(FX_BOOL bValueChanged);
110#endif // PDF_ENABLE_XFA
tsepeza31da742016-09-08 11:28:14 -0700111 void ResetAppearance(const CFX_WideString* sValue, FX_BOOL bValueChanged);
jaepark611adb82016-08-17 11:34:36 -0700112 void ResetFieldAppearance(FX_BOOL bValueChanged);
113 void UpdateField();
tsepez8c2a8cd2016-09-07 15:29:11 -0700114 CFX_WideString OnFormat(FX_BOOL& bFormatted);
jaepark611adb82016-08-17 11:34:36 -0700115
116 FX_BOOL OnAAction(CPDF_AAction::AActionType type,
117 PDFSDK_FieldAction& data,
118 CPDFSDK_PageView* pPageView);
119
120 CPDFSDK_InterForm* GetInterForm() const { return m_pInterForm; }
121 CPDF_FormField* GetFormField() const;
122 CPDF_FormControl* GetFormControl() const;
123 static CPDF_FormControl* GetFormControl(CPDF_InterForm* pInterForm,
124 const CPDF_Dictionary* pAnnotDict);
125
126 void DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView);
127
128 void SetAppModified();
129 void ClearAppModified();
130 FX_BOOL IsAppModified() const;
131
132 int32_t GetAppearanceAge() const;
133 int32_t GetValueAge() const;
134
135 FX_BOOL IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode);
136 void DrawAppearance(CFX_RenderDevice* pDevice,
137 const CFX_Matrix* pUser2Device,
138 CPDF_Annot::AppearanceMode mode,
139 const CPDF_RenderOptions* pOptions) override;
140
141 FX_BOOL HitTest(FX_FLOAT pageX, FX_FLOAT pageY);
142
143 private:
144 void ResetAppearance_PushButton();
145 void ResetAppearance_CheckBox();
146 void ResetAppearance_RadioButton();
tsepeza31da742016-09-08 11:28:14 -0700147 void ResetAppearance_ComboBox(const CFX_WideString* sValue);
jaepark611adb82016-08-17 11:34:36 -0700148 void ResetAppearance_ListBox();
tsepeza31da742016-09-08 11:28:14 -0700149 void ResetAppearance_TextField(const CFX_WideString* sValue);
jaepark611adb82016-08-17 11:34:36 -0700150
151 CFX_FloatRect GetClientRect() const;
152 CFX_FloatRect GetRotatedRect() const;
153
154 CFX_ByteString GetBackgroundAppStream() const;
155 CFX_ByteString GetBorderAppStream() const;
156 CFX_Matrix GetMatrix() const;
157
158 CPWL_Color GetTextPWLColor() const;
159 CPWL_Color GetBorderPWLColor() const;
160 CPWL_Color GetFillPWLColor() const;
161
162 void AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage);
163 void RemoveAppearance(const CFX_ByteString& sAPType);
164
165 CPDFSDK_InterForm* const m_pInterForm;
166 FX_BOOL m_bAppModified;
167 int32_t m_nAppAge;
168 int32_t m_nValueAge;
jaepark611adb82016-08-17 11:34:36 -0700169
170#ifdef PDF_ENABLE_XFA
171 mutable CXFA_FFWidget* m_hMixXFAWidget;
172 mutable CXFA_FFWidgetHandler* m_pWidgetHandler;
173#endif // PDF_ENABLE_XFA
174};
175
dsinclair114e46a2016-09-29 17:18:21 -0700176#endif // FPDFSDK_CPDFSDK_WIDGET_H_