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 _FWL_WIDGETTP_H
8 #define _FWL_WIDGETTP_H
9 class IFWL_ThemeProvider;
10 class IFWL_Widget;
11 class IFDE_TextOut;
12 class IFX_Font;
13 class IFX_FontMgr;
14 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
15 class IFX_FontSourceEnum;
16 #endif
17 class CFWL_WidgetTP;
18 class CFWL_ArrowData;
19 class CFWL_WidgetTP {
20  public:
21   virtual FX_BOOL IsValidWidget(IFWL_Widget* pWidget);
22   virtual FX_DWORD GetThemeID(IFWL_Widget* pWidget);
23   virtual FX_DWORD SetThemeID(IFWL_Widget* pWidget,
24                               FX_DWORD dwThemeID,
25                               FX_BOOL bChildren = TRUE);
26   virtual FWL_ERR GetThemeMatrix(IFWL_Widget* pWidget, CFX_Matrix& matrix);
27   virtual FWL_ERR SetThemeMatrix(IFWL_Widget* pWidget,
28                                  const CFX_Matrix& matrix);
29   virtual FX_BOOL DrawBackground(CFWL_ThemeBackground* pParams);
30   virtual FX_BOOL DrawText(CFWL_ThemeText* pParams);
31   virtual void* GetCapacity(CFWL_ThemePart* pThemePart, FX_DWORD dwCapacity);
32   virtual FX_BOOL IsCustomizedLayout(IFWL_Widget* pWidget);
33   virtual FWL_ERR GetPartRect(CFWL_ThemePart* pThemePart, CFX_RectF& rtPart);
34   virtual FX_BOOL IsInPart(CFWL_ThemePart* pThemePart,
35                            FX_FLOAT fx,
36                            FX_FLOAT fy);
37   virtual FX_BOOL CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect);
38   virtual FWL_ERR Initialize();
39   virtual FWL_ERR Finalize();
40   virtual ~CFWL_WidgetTP();
41   FWL_ERR SetFont(IFWL_Widget* pWidget,
42                   const FX_WCHAR* strFont,
43                   FX_FLOAT fFontSize,
44                   FX_ARGB rgbFont);
45   FWL_ERR SetFont(IFWL_Widget* pWidget,
46                   IFX_Font* pFont,
47                   FX_FLOAT fFontSize,
48                   FX_ARGB rgbFont);
49   IFX_Font* GetFont(IFWL_Widget* pWidget);
50 
51  protected:
52   CFWL_WidgetTP();
53   FX_ERR InitTTO();
54   FX_ERR FinalizeTTO();
55   void DrawEdge(CFX_Graphics* pGraphics,
56                 FX_DWORD dwStyles,
57                 const CFX_RectF* pRect,
58                 CFX_Matrix* pMatrix = NULL);
59   void Draw3DRect(CFX_Graphics* pGraphics,
60                   FWLTHEME_EDGE eType,
61                   FX_FLOAT fWidth,
62                   const CFX_RectF* pRect,
63                   FX_ARGB cr1,
64                   FX_ARGB cr2,
65                   FX_ARGB cr3,
66                   FX_ARGB cr4,
67                   CFX_Matrix* pMatrix = NULL);
68   void Draw3DCircle(CFX_Graphics* pGraphics,
69                     FWLTHEME_EDGE eType,
70                     FX_FLOAT fWidth,
71                     const CFX_RectF* pRect,
72                     FX_ARGB cr1,
73                     FX_ARGB cr2,
74                     FX_ARGB cr3,
75                     FX_ARGB cr4,
76                     CFX_Matrix* pMatrix = NULL);
77   void DrawBorder(CFX_Graphics* pGraphics,
78                   const CFX_RectF* pRect,
79                   CFX_Matrix* pMatrix = NULL);
80   void FillBackground(CFX_Graphics* pGraphics,
81                       const CFX_RectF* pRect,
82                       CFX_Matrix* pMatrix = NULL);
83   void FillSoildRect(CFX_Graphics* pGraphics,
84                      FX_ARGB fillColor,
85                      const CFX_RectF* pRect,
86                      CFX_Matrix* pMatrix = NULL);
87   void DrawAxialShading(CFX_Graphics* pGraphics,
88                         FX_FLOAT fx1,
89                         FX_FLOAT fy1,
90                         FX_FLOAT fx2,
91                         FX_FLOAT fy2,
92                         FX_ARGB beginColor,
93                         FX_ARGB endColor,
94                         CFX_Path* path,
95                         int32_t fillMode = FXFILL_WINDING,
96                         CFX_Matrix* pMatrix = NULL);
97   void DrawAnnulusRect(CFX_Graphics* pGraphics,
98                        FX_ARGB fillColor,
99                        const CFX_RectF* pRect,
100                        FX_FLOAT fRingWidth = 1,
101                        CFX_Matrix* pMatrix = NULL);
102   void DrawAnnulusCircle(CFX_Graphics* pGraphics,
103                          FX_ARGB fillColor,
104                          const CFX_RectF* pRect,
105                          FX_FLOAT fWidth = 1,
106                          CFX_Matrix* pMatrix = NULL);
107   void DrawFocus(CFX_Graphics* pGraphics,
108                  const CFX_RectF* pRect,
109                  CFX_Matrix* pMatrix = NULL);
110   void DrawArrow(CFX_Graphics* pGraphics,
111                  const CFX_RectF* pRect,
112                  FWLTHEME_DIRECTION eDict,
113                  FX_ARGB argbFill,
114                  FX_BOOL bPressed,
115                  CFX_Matrix* pMatrix = NULL);
116   void DrawArrow(CFX_Graphics* pGraphics,
117                  const CFX_RectF* pRect,
118                  FWLTHEME_DIRECTION eDict,
119                  FX_ARGB argSign,
120                  CFX_Matrix* pMatrix = NULL);
121   void DrawBtn(CFX_Graphics* pGraphics,
122                const CFX_RectF* pRect,
123                FWLTHEME_STATE eState,
124                CFX_Matrix* pMatrix = NULL);
125   void DrawArrowBtn(CFX_Graphics* pGraphics,
126                     const CFX_RectF* pRect,
127                     FWLTHEME_DIRECTION eDict,
128                     FWLTHEME_STATE eState,
129                     CFX_Matrix* pMatrix = NULL);
130   FWLCOLOR BlendColor(FWLCOLOR srcColor, FWLCOLOR renderColor, uint8_t scale);
131   FX_DWORD m_dwRefCount;
132   IFDE_TextOut* m_pTextOut;
133   IFX_Font* m_pFDEFont;
134   FX_FLOAT m_fValue;
135   FX_DWORD m_dwValue;
136   CFX_RectF m_rtMargin;
137   FX_DWORD m_dwThemeID;
138   CFX_Matrix _ctm;
139 };
140 FX_BOOL FWLTHEME_Init();
141 void FWLTHEME_Release();
142 FX_DWORD FWL_GetThemeLayout(FX_DWORD dwThemeID);
143 FX_DWORD FWL_GetThemeColor(FX_DWORD dwThemeID);
144 FX_DWORD FWL_MakeThemeID(FX_DWORD dwLayout, FX_DWORD dwColor);
145 class CFWL_ArrowData {
146  public:
147   static CFWL_ArrowData* GetInstance();
148   static FX_BOOL IsInstance();
149   static void DestroyInstance();
150   virtual ~CFWL_ArrowData();
151   void SetColorData(FX_DWORD dwID);
152 
153   class CColorData {
154    public:
155     FX_ARGB clrBorder[4];
156     FX_ARGB clrStart[4];
157     FX_ARGB clrEnd[4];
158     FX_ARGB clrSign[4];
159   } * m_pColorData;
160 
161  protected:
162   CFWL_ArrowData();
163   static CFWL_ArrowData* m_pInstance;
164 };
165 class CFWL_FontData {
166  public:
167   CFWL_FontData();
168   virtual ~CFWL_FontData();
169   FX_BOOL Equal(const CFX_WideStringC& wsFontFamily,
170                 FX_DWORD dwFontStyles,
171                 FX_WORD wCodePage);
172   FX_BOOL LoadFont(const CFX_WideStringC& wsFontFamily,
173                    FX_DWORD dwFontStyles,
174                    FX_WORD wCodePage);
GetFont()175   IFX_Font* GetFont() const { return m_pFont; }
176 
177  protected:
178   CFX_WideString m_wsFamily;
179   FX_DWORD m_dwStyles;
180   FX_DWORD m_dwCodePage;
181   IFX_Font* m_pFont;
182   IFX_FontMgr* m_pFontMgr;
183 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
184   IFX_FontSourceEnum* m_pFontSource;
185 #endif
186 };
187 class CFWL_FontManager {
188  public:
189   CFWL_FontManager();
190   virtual ~CFWL_FontManager();
191   IFX_Font* FindFont(const CFX_WideStringC& wsFontFamily,
192                      FX_DWORD dwFontStyles,
193                      FX_WORD dwCodePage);
194 
195  protected:
196   CFX_PtrArray m_arrFonts;
197 };
198 CFWL_FontManager* FWL_GetFontManager();
199 #endif
200