• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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 
7 #ifndef CORE_FPDFDOC_CPDF_FORMCONTROL_H_
8 #define CORE_FPDFDOC_CPDF_FORMCONTROL_H_
9 
10 #include "core/fpdfdoc/cpdf_aaction.h"
11 #include "core/fpdfdoc/cpdf_action.h"
12 #include "core/fpdfdoc/cpdf_annot.h"
13 #include "core/fpdfdoc/cpdf_annotlist.h"
14 #include "core/fpdfdoc/cpdf_apsettings.h"
15 #include "core/fpdfdoc/cpdf_defaultappearance.h"
16 #include "core/fpdfdoc/cpdf_formfield.h"
17 #include "core/fpdfdoc/cpdf_iconfit.h"
18 #include "core/fxcrt/fx_coordinates.h"
19 #include "core/fxcrt/fx_string.h"
20 #include "core/fxcrt/retain_ptr.h"
21 #include "core/fxge/fx_dib.h"
22 #include "third_party/base/optional.h"
23 
24 class CFX_RenderDevice;
25 class CPDF_Dictionary;
26 class CPDF_Font;
27 class CPDF_FormField;
28 class CPDF_InteractiveForm;
29 class CPDF_OCContext;
30 class CPDF_RenderOptions;
31 class CPDF_Stream;
32 
33 class CPDF_FormControl {
34  public:
35   enum HighlightingMode { None = 0, Invert, Outline, Push, Toggle };
36 
37   CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWidgetDict);
38   ~CPDF_FormControl();
39 
GetType()40   CPDF_FormField::Type GetType() const { return m_pField->GetType(); }
GetInteractiveForm()41   const CPDF_InteractiveForm* GetInteractiveForm() const {
42     return m_pForm.Get();
43   }
GetField()44   CPDF_FormField* GetField() const { return m_pField.Get(); }
GetWidget()45   CPDF_Dictionary* GetWidget() const { return m_pWidgetDict.Get(); }
46   CFX_FloatRect GetRect() const;
47 
48   ByteString GetCheckedAPState() const;
49   WideString GetExportValue() const;
50 
51   bool IsChecked() const;
52   bool IsDefaultChecked() const;
53 
54   HighlightingMode GetHighlightingMode() const;
55   bool HasMKEntry(const ByteString& csEntry) const;
56   int GetRotation() const;
57 
GetBorderColor(int & iColorType)58   FX_ARGB GetBorderColor(int& iColorType) { return GetColor(iColorType, "BC"); }
59 
GetOriginalBorderColor(int index)60   float GetOriginalBorderColor(int index) {
61     return GetOriginalColor(index, "BC");
62   }
63 
GetOriginalBorderColor(int & iColorType,float fc[4])64   void GetOriginalBorderColor(int& iColorType, float fc[4]) {
65     GetOriginalColor(iColorType, fc, "BC");
66   }
67 
GetBackgroundColor(int & iColorType)68   FX_ARGB GetBackgroundColor(int& iColorType) {
69     return GetColor(iColorType, "BG");
70   }
71 
GetOriginalBackgroundColor(int index)72   float GetOriginalBackgroundColor(int index) {
73     return GetOriginalColor(index, "BG");
74   }
75 
GetOriginalBackgroundColor(int & iColorType,float fc[4])76   void GetOriginalBackgroundColor(int& iColorType, float fc[4]) {
77     GetOriginalColor(iColorType, fc, "BG");
78   }
79 
GetNormalCaption()80   WideString GetNormalCaption() const { return GetCaption("CA"); }
GetRolloverCaption()81   WideString GetRolloverCaption() const { return GetCaption("RC"); }
GetDownCaption()82   WideString GetDownCaption() const { return GetCaption("AC"); }
83 
GetNormalIcon()84   CPDF_Stream* GetNormalIcon() { return GetIcon("I"); }
GetRolloverIcon()85   CPDF_Stream* GetRolloverIcon() { return GetIcon("RI"); }
GetDownIcon()86   CPDF_Stream* GetDownIcon() { return GetIcon("IX"); }
87   CPDF_IconFit GetIconFit() const;
88 
89   int GetTextPosition() const;
90   CPDF_Action GetAction() const;
91   CPDF_AAction GetAdditionalAction() const;
92   CPDF_DefaultAppearance GetDefaultAppearance() const;
93 
94   Optional<WideString> GetDefaultControlFontName() const;
95   int GetControlAlignment() const;
96 
97   ByteString GetOnStateName() const;
98   void CheckControl(bool bChecked);
99 
100  private:
101   RetainPtr<CPDF_Font> GetDefaultControlFont() const;
102   FX_ARGB GetColor(int& iColorType, const ByteString& csEntry);
103   float GetOriginalColor(int index, const ByteString& csEntry);
104   void GetOriginalColor(int& iColorType,
105                         float fc[4],
106                         const ByteString& csEntry);
107 
108   WideString GetCaption(const ByteString& csEntry) const;
109   CPDF_Stream* GetIcon(const ByteString& csEntry);
110   CPDF_ApSettings GetMK() const;
111 
112   UnownedPtr<CPDF_FormField> const m_pField;
113   RetainPtr<CPDF_Dictionary> const m_pWidgetDict;
114   UnownedPtr<const CPDF_InteractiveForm> const m_pForm;
115 };
116 
117 #endif  // CORE_FPDFDOC_CPDF_FORMCONTROL_H_
118