Home | History | Annotate | Download | only in theme
      1 // Copyright 2014 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 XFA_FWL_THEME_CFWL_WIDGETTP_H_
      8 #define XFA_FWL_THEME_CFWL_WIDGETTP_H_
      9 
     10 #include <memory>
     11 #include <vector>
     12 
     13 #include "core/fxcrt/fx_coordinates.h"
     14 #include "core/fxcrt/fx_system.h"
     15 #include "core/fxcrt/retain_ptr.h"
     16 #include "xfa/fwl/theme/cfwl_utils.h"
     17 #include "xfa/fxgraphics/cxfa_graphics.h"
     18 
     19 class CFDE_TextOut;
     20 class CFGAS_FontMgr;
     21 class CFGAS_GEFont;
     22 class CFWL_ThemeBackground;
     23 class CFWL_ThemePart;
     24 class CFWL_ThemeText;
     25 class CFWL_Widget;
     26 
     27 #if _FX_PLATFORM_ != _FX_PLATFORM_WINDOWS_
     28 class CFX_FontSourceEnum_File;
     29 #endif
     30 
     31 class CFWL_WidgetTP {
     32  public:
     33   virtual ~CFWL_WidgetTP();
     34 
     35   virtual void Initialize();
     36   virtual void Finalize();
     37 
     38   virtual void DrawBackground(CFWL_ThemeBackground* pParams);
     39   virtual void DrawText(CFWL_ThemeText* pParams);
     40 
     41   const RetainPtr<CFGAS_GEFont>& GetFont() const;
     42 
     43  protected:
     44   struct CColorData {
     45     FX_ARGB clrBorder[4];
     46     FX_ARGB clrStart[4];
     47     FX_ARGB clrEnd[4];
     48     FX_ARGB clrSign[4];
     49   };
     50 
     51   CFWL_WidgetTP();
     52 
     53   void InitializeArrowColorData();
     54   void InitTTO();
     55   void FinalizeTTO();
     56 
     57   void DrawBorder(CXFA_Graphics* pGraphics,
     58                   const CFX_RectF* pRect,
     59                   CFX_Matrix* pMatrix = nullptr);
     60   void FillBackground(CXFA_Graphics* pGraphics,
     61                       const CFX_RectF* pRect,
     62                       CFX_Matrix* pMatrix = nullptr);
     63   void FillSoildRect(CXFA_Graphics* pGraphics,
     64                      FX_ARGB fillColor,
     65                      const CFX_RectF* pRect,
     66                      CFX_Matrix* pMatrix = nullptr);
     67   void DrawAxialShading(CXFA_Graphics* pGraphics,
     68                         float fx1,
     69                         float fy1,
     70                         float fx2,
     71                         float fy2,
     72                         FX_ARGB beginColor,
     73                         FX_ARGB endColor,
     74                         CXFA_GEPath* path,
     75                         int32_t fillMode = FXFILL_WINDING,
     76                         CFX_Matrix* pMatrix = nullptr);
     77   void DrawFocus(CXFA_Graphics* pGraphics,
     78                  const CFX_RectF* pRect,
     79                  CFX_Matrix* pMatrix = nullptr);
     80   void DrawArrow(CXFA_Graphics* pGraphics,
     81                  const CFX_RectF* pRect,
     82                  FWLTHEME_DIRECTION eDict,
     83                  FX_ARGB argSign,
     84                  CFX_Matrix* pMatrix = nullptr);
     85   void DrawBtn(CXFA_Graphics* pGraphics,
     86                const CFX_RectF* pRect,
     87                FWLTHEME_STATE eState,
     88                CFX_Matrix* pMatrix = nullptr);
     89   void DrawArrowBtn(CXFA_Graphics* pGraphics,
     90                     const CFX_RectF* pRect,
     91                     FWLTHEME_DIRECTION eDict,
     92                     FWLTHEME_STATE eState,
     93                     CFX_Matrix* pMatrix = nullptr);
     94 
     95   uint32_t m_dwRefCount;
     96   std::unique_ptr<CFDE_TextOut> m_pTextOut;
     97   RetainPtr<CFGAS_GEFont> m_pFDEFont;
     98   std::unique_ptr<CColorData> m_pColorData;
     99 };
    100 
    101 void FWLTHEME_Release();
    102 
    103 class CFWL_FontData {
    104  public:
    105   CFWL_FontData();
    106   virtual ~CFWL_FontData();
    107 
    108   bool Equal(const WideStringView& wsFontFamily,
    109              uint32_t dwFontStyles,
    110              uint16_t wCodePage);
    111   bool LoadFont(const WideStringView& wsFontFamily,
    112                 uint32_t dwFontStyles,
    113                 uint16_t wCodePage);
    114   RetainPtr<CFGAS_GEFont> GetFont() const;
    115 
    116  protected:
    117   WideString m_wsFamily;
    118   uint32_t m_dwStyles;
    119   uint32_t m_dwCodePage;
    120   std::unique_ptr<CFGAS_FontMgr> m_pFontMgr;
    121   RetainPtr<CFGAS_GEFont> m_pFont;
    122 };
    123 
    124 class CFWL_FontManager {
    125  public:
    126   static CFWL_FontManager* GetInstance();
    127   static void DestroyInstance();
    128 
    129   RetainPtr<CFGAS_GEFont> FindFont(const WideStringView& wsFontFamily,
    130                                    uint32_t dwFontStyles,
    131                                    uint16_t dwCodePage);
    132 
    133  protected:
    134   CFWL_FontManager();
    135   virtual ~CFWL_FontManager();
    136 
    137   static CFWL_FontManager* s_FontManager;
    138   std::vector<std::unique_ptr<CFWL_FontData>> m_FontsArray;
    139 };
    140 
    141 #endif  // XFA_FWL_THEME_CFWL_WIDGETTP_H_
    142