blob: f57e08d526c4117d023471281b1bebdf313ae5d7 [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"
Dan Sinclairaee0db02017-09-21 16:53:58 -040017#include "core/fxcrt/unowned_ptr.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
Ryan Harrison275e2602017-09-18 14:23:18 -040085 WideString GetValue() const;
jaepark611adb82016-08-17 11:34:36 -070086#else
Ryan Harrison275e2602017-09-18 14:23:18 -040087 WideString GetValue(bool bDisplay = true) const;
jaepark611adb82016-08-17 11:34:36 -070088#endif // PDF_ENABLE_XFA
Ryan Harrison275e2602017-09-18 14:23:18 -040089 WideString GetDefaultValue() const;
90 WideString GetOptionLabel(int nIndex) const;
jaepark611adb82016-08-17 11:34:36 -070091 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
Ryan Harrison275e2602017-09-18 14:23:18 -040098 WideString GetName() const;
jaepark611adb82016-08-17 11:34:36 -070099#endif // PDF_ENABLE_XFA
Ryan Harrison275e2602017-09-18 14:23:18 -0400100 WideString GetAlternateName() const;
jaepark611adb82016-08-17 11:34:36 -0700101
102 void SetCheck(bool bChecked, bool bNotify);
Ryan Harrison275e2602017-09-18 14:23:18 -0400103 void SetValue(const WideString& sValue, bool bNotify);
104 void SetDefaultValue(const 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
Ryan Harrison275e2602017-09-18 14:23:18 -0400112 void ResetAppearance(const WideString* sValue, bool bValueChanged);
tsepez4cf55152016-11-02 14:37:54 -0700113 void ResetFieldAppearance(bool bValueChanged);
jaepark611adb82016-08-17 11:34:36 -0700114 void UpdateField();
Ryan Harrison275e2602017-09-18 14:23:18 -0400115 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
Tom Sepez7b1e53c2017-09-15 15:43:11 -0700133 uint32_t GetAppearanceAge() const { return m_nAppearanceAge; }
134 uint32_t GetValueAge() const { return m_nValueAge; }
jaepark611adb82016-08-17 11:34:36 -0700135
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,
Lei Zhang8a449402017-08-17 15:07:47 -0700138 const CFX_Matrix& mtUser2Device,
jaepark611adb82016-08-17 11:34:36 -0700139 CPDF_Annot::AppearanceMode mode,
140 const CPDF_RenderOptions* pOptions) override;
141
Dan Sinclaircb2ea422017-07-19 15:24:49 -0400142 CFX_Matrix GetMatrix() const;
jaepark611adb82016-08-17 11:34:36 -0700143 CFX_FloatRect GetClientRect() const;
144 CFX_FloatRect GetRotatedRect() const;
Dan Sinclair7f55a542017-07-13 14:17:10 -0400145 CFX_Color GetTextPWLColor() const;
146 CFX_Color GetBorderPWLColor() const;
147 CFX_Color GetFillPWLColor() const;
jaepark611adb82016-08-17 11:34:36 -0700148
Dan Sinclaircb2ea422017-07-19 15:24:49 -0400149 private:
Dan Sinclairaee0db02017-09-21 16:53:58 -0400150 UnownedPtr<CPDFSDK_InterForm> const m_pInterForm;
tsepez4cf55152016-11-02 14:37:54 -0700151 bool m_bAppModified;
Tom Sepez7b1e53c2017-09-15 15:43:11 -0700152 uint32_t m_nAppearanceAge;
153 uint32_t m_nValueAge;
jaepark611adb82016-08-17 11:34:36 -0700154
155#ifdef PDF_ENABLE_XFA
Dan Sinclairaee0db02017-09-21 16:53:58 -0400156 mutable UnownedPtr<CXFA_FFWidget> m_hMixXFAWidget;
157 mutable UnownedPtr<CXFA_FFWidgetHandler> m_pWidgetHandler;
jaepark611adb82016-08-17 11:34:36 -0700158#endif // PDF_ENABLE_XFA
159};
160
dsinclair114e46a2016-09-29 17:18:21 -0700161#endif // FPDFSDK_CPDFSDK_WIDGET_H_