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