Home | History | Annotate | Download | only in fpdfdoc
      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 #define COLORTYPE_TRANSPARENT 0
     32 #define COLORTYPE_GRAY 1
     33 #define COLORTYPE_RGB 2
     34 #define COLORTYPE_CMYK 3
     35 
     36 class CFX_RenderDevice;
     37 class CPDF_Dictionary;
     38 class CPDF_Font;
     39 class CPDF_FormField;
     40 class CPDF_InterForm;
     41 class CPDF_OCContext;
     42 class CPDF_RenderOptions;
     43 class CPDF_Stream;
     44 
     45 class CPDF_FormControl {
     46  public:
     47   enum HighlightingMode { None = 0, Invert, Outline, Push, Toggle };
     48 
     49   CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWidgetDict);
     50 
     51   CPDF_FormField::Type GetType() const { return m_pField->GetType(); }
     52   CPDF_InterForm* GetInterForm() const { return m_pForm; }
     53   CPDF_FormField* GetField() const { return m_pField; }
     54   CPDF_Dictionary* GetWidget() const { return m_pWidgetDict; }
     55   CFX_FloatRect GetRect() const { return m_pWidgetDict->GetRectFor("Rect"); }
     56 
     57   void DrawControl(CFX_RenderDevice* pDevice,
     58                    CFX_Matrix* pMatrix,
     59                    CPDF_Page* pPage,
     60                    CPDF_Annot::AppearanceMode mode,
     61                    const CPDF_RenderOptions* pOptions = nullptr);
     62 
     63   CFX_ByteString GetCheckedAPState();
     64   CFX_WideString GetExportValue() const;
     65 
     66   bool IsChecked() const;
     67   bool IsDefaultChecked() const;
     68 
     69   HighlightingMode GetHighlightingMode();
     70   bool HasMKEntry(const CFX_ByteString& csEntry) const;
     71   int GetRotation();
     72 
     73   FX_ARGB GetBorderColor(int& iColorType) { return GetColor(iColorType, "BC"); }
     74 
     75   FX_FLOAT GetOriginalBorderColor(int index) {
     76     return GetOriginalColor(index, "BC");
     77   }
     78 
     79   void GetOriginalBorderColor(int& iColorType, FX_FLOAT fc[4]) {
     80     GetOriginalColor(iColorType, fc, "BC");
     81   }
     82 
     83   FX_ARGB GetBackgroundColor(int& iColorType) {
     84     return GetColor(iColorType, "BG");
     85   }
     86 
     87   FX_FLOAT GetOriginalBackgroundColor(int index) {
     88     return GetOriginalColor(index, "BG");
     89   }
     90 
     91   void GetOriginalBackgroundColor(int& iColorType, FX_FLOAT fc[4]) {
     92     GetOriginalColor(iColorType, fc, "BG");
     93   }
     94 
     95   CFX_WideString GetNormalCaption() { return GetCaption("CA"); }
     96   CFX_WideString GetRolloverCaption() { return GetCaption("RC"); }
     97   CFX_WideString GetDownCaption() { return GetCaption("AC"); }
     98 
     99   CPDF_Stream* GetNormalIcon() { return GetIcon("I"); }
    100   CPDF_Stream* GetRolloverIcon() { return GetIcon("RI"); }
    101   CPDF_Stream* GetDownIcon() { return GetIcon("IX"); }
    102   CPDF_IconFit GetIconFit();
    103 
    104   int GetTextPosition();
    105   CPDF_Action GetAction();
    106   CPDF_AAction GetAdditionalAction();
    107   CPDF_DefaultAppearance GetDefaultAppearance();
    108 
    109   CPDF_Font* GetDefaultControlFont();
    110   int GetControlAlignment();
    111 
    112  private:
    113   friend class CPDF_InterForm;
    114   friend class CPDF_FormField;
    115 
    116   CFX_ByteString GetOnStateName() const;
    117   void SetOnStateName(const CFX_ByteString& csOn);
    118   void CheckControl(bool bChecked);
    119   FX_ARGB GetColor(int& iColorType, const CFX_ByteString& csEntry);
    120   FX_FLOAT GetOriginalColor(int index, const CFX_ByteString& csEntry);
    121   void GetOriginalColor(int& iColorType,
    122                         FX_FLOAT fc[4],
    123                         const CFX_ByteString& csEntry);
    124 
    125   CFX_WideString GetCaption(const CFX_ByteString& csEntry);
    126   CPDF_Stream* GetIcon(const CFX_ByteString& csEntry);
    127   CPDF_ApSettings GetMK() const;
    128 
    129   CPDF_FormField* const m_pField;
    130   CPDF_Dictionary* const m_pWidgetDict;
    131   CPDF_InterForm* const m_pForm;
    132 };
    133 
    134 #endif  // CORE_FPDFDOC_CPDF_FORMCONTROL_H_
    135