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/fpdfdoc/ipdf_formnotify.h" 19 #include "core/fxcrt/fx_coordinates.h" 20 #include "core/fxcrt/fx_string.h" 21 #include "core/fxge/fx_dib.h" 22 23 #define TEXTPOS_CAPTION 0 24 #define TEXTPOS_ICON 1 25 #define TEXTPOS_BELOW 2 26 #define TEXTPOS_ABOVE 3 27 #define TEXTPOS_RIGHT 4 28 #define TEXTPOS_LEFT 5 29 #define TEXTPOS_OVERLAID 6 30 31 class CFX_RenderDevice; 32 class CPDF_Dictionary; 33 class CPDF_Font; 34 class CPDF_FormField; 35 class CPDF_InterForm; 36 class CPDF_OCContext; 37 class CPDF_RenderOptions; 38 class CPDF_Stream; 39 40 class CPDF_FormControl { 41 public: 42 enum HighlightingMode { None = 0, Invert, Outline, Push, Toggle }; 43 44 CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWidgetDict); 45 ~CPDF_FormControl(); 46 GetType()47 CPDF_FormField::Type GetType() const { return m_pField->GetType(); } GetInterForm()48 const CPDF_InterForm* GetInterForm() const { return m_pForm.Get(); } GetField()49 CPDF_FormField* GetField() const { return m_pField; } GetWidget()50 CPDF_Dictionary* GetWidget() const { return m_pWidgetDict.Get(); } GetRect()51 CFX_FloatRect GetRect() const { return m_pWidgetDict->GetRectFor("Rect"); } 52 53 void DrawControl(CFX_RenderDevice* pDevice, 54 CFX_Matrix* pMatrix, 55 CPDF_Page* pPage, 56 CPDF_Annot::AppearanceMode mode, 57 const CPDF_RenderOptions* pOptions = nullptr); 58 59 ByteString GetCheckedAPState(); 60 WideString GetExportValue() const; 61 62 bool IsChecked() const; 63 bool IsDefaultChecked() const; 64 65 HighlightingMode GetHighlightingMode(); 66 bool HasMKEntry(const ByteString& csEntry) const; 67 int GetRotation(); 68 GetBorderColor(int & iColorType)69 FX_ARGB GetBorderColor(int& iColorType) { return GetColor(iColorType, "BC"); } 70 GetOriginalBorderColor(int index)71 float GetOriginalBorderColor(int index) { 72 return GetOriginalColor(index, "BC"); 73 } 74 GetOriginalBorderColor(int & iColorType,float fc[4])75 void GetOriginalBorderColor(int& iColorType, float fc[4]) { 76 GetOriginalColor(iColorType, fc, "BC"); 77 } 78 GetBackgroundColor(int & iColorType)79 FX_ARGB GetBackgroundColor(int& iColorType) { 80 return GetColor(iColorType, "BG"); 81 } 82 GetOriginalBackgroundColor(int index)83 float GetOriginalBackgroundColor(int index) { 84 return GetOriginalColor(index, "BG"); 85 } 86 GetOriginalBackgroundColor(int & iColorType,float fc[4])87 void GetOriginalBackgroundColor(int& iColorType, float fc[4]) { 88 GetOriginalColor(iColorType, fc, "BG"); 89 } 90 GetNormalCaption()91 WideString GetNormalCaption() { return GetCaption("CA"); } GetRolloverCaption()92 WideString GetRolloverCaption() { return GetCaption("RC"); } GetDownCaption()93 WideString GetDownCaption() { return GetCaption("AC"); } 94 GetNormalIcon()95 CPDF_Stream* GetNormalIcon() { return GetIcon("I"); } GetRolloverIcon()96 CPDF_Stream* GetRolloverIcon() { return GetIcon("RI"); } GetDownIcon()97 CPDF_Stream* GetDownIcon() { return GetIcon("IX"); } 98 CPDF_IconFit GetIconFit(); 99 100 int GetTextPosition(); 101 CPDF_Action GetAction(); 102 CPDF_AAction GetAdditionalAction(); 103 CPDF_DefaultAppearance GetDefaultAppearance(); 104 105 CPDF_Font* GetDefaultControlFont(); 106 int GetControlAlignment(); 107 108 ByteString GetOnStateName() const; 109 void CheckControl(bool bChecked); 110 111 private: 112 void SetOnStateName(const ByteString& csOn); 113 FX_ARGB GetColor(int& iColorType, const ByteString& csEntry); 114 float GetOriginalColor(int index, const ByteString& csEntry); 115 void GetOriginalColor(int& iColorType, 116 float fc[4], 117 const ByteString& csEntry); 118 119 WideString GetCaption(const ByteString& csEntry); 120 CPDF_Stream* GetIcon(const ByteString& csEntry); 121 CPDF_ApSettings GetMK() const; 122 123 CPDF_FormField* const m_pField; 124 UnownedPtr<CPDF_Dictionary> const m_pWidgetDict; 125 UnownedPtr<const CPDF_InterForm> const m_pForm; 126 }; 127 128 #endif // CORE_FPDFDOC_CPDF_FORMCONTROL_H_ 129