blob: 8f031cf45f44827b80cffe42433278ad5219d3ee [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"
Tom Sepezd0409af2017-05-25 15:53:57 -070015#include "core/fxcrt/cfx_unowned_ptr.h"
dsinclaira52ab742016-09-29 13:59:29 -070016#include "core/fxcrt/fx_coordinates.h"
17#include "core/fxcrt/fx_string.h"
Dan Sinclair7f55a542017-07-13 14:17:10 -040018#include "core/fxge/cfx_color.h"
dsinclair114e46a2016-09-29 17:18:21 -070019#include "fpdfsdk/cpdfsdk_baannot.h"
20#include "fpdfsdk/pdfsdk_fieldaction.h"
jaepark611adb82016-08-17 11:34:36 -070021
22class CFX_RenderDevice;
23class CPDF_Annot;
24class CPDF_Dictionary;
25class CPDF_FormControl;
26class CPDF_FormField;
27class CPDF_RenderOptions;
28class CPDF_Stream;
29class CPDFSDK_InterForm;
30class CPDFSDK_PageView;
31
32#ifdef PDF_ENABLE_XFA
33class CXFA_FFWidget;
34class CXFA_FFWidgetHandler;
35#endif // PDF_ENABLE_XFA
36
37class CPDFSDK_Widget : public CPDFSDK_BAAnnot {
38 public:
jaepark611adb82016-08-17 11:34:36 -070039#ifdef PDF_ENABLE_XFA
40 CXFA_FFWidget* GetMixXFAWidget() const;
41 CXFA_FFWidget* GetGroupMixXFAWidget();
42 CXFA_FFWidgetHandler* GetXFAWidgetHandler() const;
43
tsepez4cf55152016-11-02 14:37:54 -070044 bool HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT);
45 bool OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
46 PDFSDK_FieldAction& data,
47 CPDFSDK_PageView* pPageView);
jaepark611adb82016-08-17 11:34:36 -070048
tsepez4cf55152016-11-02 14:37:54 -070049 void Synchronize(bool bSynchronizeElse);
jaepark611adb82016-08-17 11:34:36 -070050 void SynchronizeXFAValue();
51 void SynchronizeXFAItems();
52
53 static void SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
54 CXFA_FFWidget* hWidget,
55 CPDF_FormField* pFormField,
56 CPDF_FormControl* pFormControl);
57 static void SynchronizeXFAItems(CXFA_FFDocView* pXFADocView,
58 CXFA_FFWidget* hWidget,
59 CPDF_FormField* pFormField,
60 CPDF_FormControl* pFormControl);
61#endif // PDF_ENABLE_XFA
62
63 CPDFSDK_Widget(CPDF_Annot* pAnnot,
64 CPDFSDK_PageView* pPageView,
65 CPDFSDK_InterForm* pInterForm);
66 ~CPDFSDK_Widget() override;
67
jaepark9ed91372016-08-26 16:16:10 -070068 bool IsSignatureWidget() const override;
jaepark611adb82016-08-17 11:34:36 -070069 CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT) override;
tsepez4cf55152016-11-02 14:37:54 -070070 bool IsAppearanceValid() override;
jaepark611adb82016-08-17 11:34:36 -070071
72 int GetLayoutOrder() const override;
73
74 int GetFieldType() const;
75 int GetFieldFlags() const;
76 int GetRotate() const;
77
tsepez4cf55152016-11-02 14:37:54 -070078 bool GetFillColor(FX_COLORREF& color) const;
79 bool GetBorderColor(FX_COLORREF& color) const;
80 bool GetTextColor(FX_COLORREF& color) const;
Dan Sinclair05df0752017-03-14 14:43:42 -040081 float GetFontSize() const;
jaepark611adb82016-08-17 11:34:36 -070082
83 int GetSelectedIndex(int nIndex) const;
84#ifndef PDF_ENABLE_XFA
85 CFX_WideString GetValue() const;
86#else
tsepez4cf55152016-11-02 14:37:54 -070087 CFX_WideString GetValue(bool bDisplay = true) const;
jaepark611adb82016-08-17 11:34:36 -070088#endif // PDF_ENABLE_XFA
89 CFX_WideString GetDefaultValue() const;
90 CFX_WideString GetOptionLabel(int nIndex) const;
91 int CountOptions() const;
tsepez4cf55152016-11-02 14:37:54 -070092 bool IsOptionSelected(int nIndex) const;
jaepark611adb82016-08-17 11:34:36 -070093 int GetTopVisibleIndex() const;
94 bool IsChecked() const;
95 int GetAlignment() const;
96 int GetMaxLen() const;
97#ifdef PDF_ENABLE_XFA
98 CFX_WideString GetName() const;
99#endif // PDF_ENABLE_XFA
100 CFX_WideString GetAlternateName() const;
101
102 void SetCheck(bool bChecked, bool bNotify);
tsepez4cf55152016-11-02 14:37:54 -0700103 void SetValue(const CFX_WideString& sValue, bool bNotify);
jaepark611adb82016-08-17 11:34:36 -0700104 void SetDefaultValue(const CFX_WideString& sValue);
tsepez4cf55152016-11-02 14:37:54 -0700105 void SetOptionSelection(int index, bool bSelected, bool bNotify);
106 void ClearSelection(bool bNotify);
jaepark611adb82016-08-17 11:34:36 -0700107 void SetTopVisibleIndex(int index);
108
109#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700110 void ResetAppearance(bool bValueChanged);
jaepark611adb82016-08-17 11:34:36 -0700111#endif // PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700112 void ResetAppearance(const CFX_WideString* sValue, bool bValueChanged);
113 void ResetFieldAppearance(bool bValueChanged);
jaepark611adb82016-08-17 11:34:36 -0700114 void UpdateField();
tsepez4cf55152016-11-02 14:37:54 -0700115 CFX_WideString OnFormat(bool& bFormatted);
jaepark611adb82016-08-17 11:34:36 -0700116
tsepez4cf55152016-11-02 14:37:54 -0700117 bool OnAAction(CPDF_AAction::AActionType type,
118 PDFSDK_FieldAction& data,
119 CPDFSDK_PageView* pPageView);
jaepark611adb82016-08-17 11:34:36 -0700120
Tom Sepez797ca5c2017-05-25 12:03:18 -0700121 CPDFSDK_InterForm* GetInterForm() const { return m_pInterForm.Get(); }
jaepark611adb82016-08-17 11:34:36 -0700122 CPDF_FormField* GetFormField() const;
123 CPDF_FormControl* GetFormControl() const;
124 static CPDF_FormControl* GetFormControl(CPDF_InterForm* pInterForm,
125 const CPDF_Dictionary* pAnnotDict);
126
127 void DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView);
128
129 void SetAppModified();
130 void ClearAppModified();
tsepez4cf55152016-11-02 14:37:54 -0700131 bool IsAppModified() const;
jaepark611adb82016-08-17 11:34:36 -0700132
133 int32_t GetAppearanceAge() const;
134 int32_t GetValueAge() const;
135
tsepez4cf55152016-11-02 14:37:54 -0700136 bool IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode);
jaepark611adb82016-08-17 11:34:36 -0700137 void DrawAppearance(CFX_RenderDevice* pDevice,
138 const CFX_Matrix* pUser2Device,
139 CPDF_Annot::AppearanceMode mode,
140 const CPDF_RenderOptions* pOptions) override;
141
jaepark611adb82016-08-17 11:34:36 -0700142 private:
143 void ResetAppearance_PushButton();
144 void ResetAppearance_CheckBox();
145 void ResetAppearance_RadioButton();
tsepeza31da742016-09-08 11:28:14 -0700146 void ResetAppearance_ComboBox(const CFX_WideString* sValue);
jaepark611adb82016-08-17 11:34:36 -0700147 void ResetAppearance_ListBox();
tsepeza31da742016-09-08 11:28:14 -0700148 void ResetAppearance_TextField(const CFX_WideString* sValue);
jaepark611adb82016-08-17 11:34:36 -0700149
150 CFX_FloatRect GetClientRect() const;
151 CFX_FloatRect GetRotatedRect() const;
152
153 CFX_ByteString GetBackgroundAppStream() const;
154 CFX_ByteString GetBorderAppStream() const;
155 CFX_Matrix GetMatrix() const;
156
Dan Sinclair7f55a542017-07-13 14:17:10 -0400157 CFX_Color GetTextPWLColor() const;
158 CFX_Color GetBorderPWLColor() const;
159 CFX_Color GetFillPWLColor() const;
jaepark611adb82016-08-17 11:34:36 -0700160
161 void AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage);
162 void RemoveAppearance(const CFX_ByteString& sAPType);
163
Tom Sepez797ca5c2017-05-25 12:03:18 -0700164 CFX_UnownedPtr<CPDFSDK_InterForm> const m_pInterForm;
tsepez4cf55152016-11-02 14:37:54 -0700165 bool m_bAppModified;
jaepark611adb82016-08-17 11:34:36 -0700166 int32_t m_nAppAge;
167 int32_t m_nValueAge;
jaepark611adb82016-08-17 11:34:36 -0700168
169#ifdef PDF_ENABLE_XFA
Tom Sepezd0409af2017-05-25 15:53:57 -0700170 mutable CFX_UnownedPtr<CXFA_FFWidget> m_hMixXFAWidget;
171 mutable CFX_UnownedPtr<CXFA_FFWidgetHandler> m_pWidgetHandler;
jaepark611adb82016-08-17 11:34:36 -0700172#endif // PDF_ENABLE_XFA
173};
174
dsinclair114e46a2016-09-29 17:18:21 -0700175#endif // FPDFSDK_CPDFSDK_WIDGET_H_