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/include/fx_coordinates.h"
14 #include "core/fxcrt/include/fx_system.h"
15 #include "xfa/fwl/core/fwl_error.h"
16 #include "xfa/fxgraphics/include/cfx_graphics.h"
17 #include "xfa/fwl/theme/cfwl_utils.h"
18 
19 enum class CFWL_WidgetCapacity {
20   None = 0,
21 
22   Today,
23   Sun,
24   Mon,
25   Tue,
26   Wed,
27   Thu,
28   Fri,
29   Sat,
30 
31   January,
32   February,
33   March,
34   April,
35   May,
36   June,
37   July,
38   August,
39   September,
40   October,
41   November,
42   December,
43 
44   BigIcon,
45   ComboFormHandler,
46   CXBorder,
47   CYBorder,
48   CYCaption,
49   CYNarrowCaption,
50   DatesCellHeight,
51   DatesCellWidth,
52   EdgeFlat,
53   EdgeRaised,
54   EdgeSunken,
55   Font,
56   FontSize,
57   HeaderBtnHeight,
58   HeaderBtnHMargin,
59   HeaderBtnVMargin,
60   HeaderBtnWidth,
61   HeaderHeight,
62   HeaderTextHeight,
63   HeaderTextHMargin,
64   HeaderTextVMargin,
65   HeaderTextWidth,
66   HeaderWidth,
67   Height,
68   HSepHeight,
69   HSepWidth,
70   LineHeight,
71   Margin,
72   ScrollBarWidth,
73   SepDOffset,
74   SepX,
75   SepY,
76   Size,
77   SmallIcon,
78   SpaceAboveBelow,
79   TextColor,
80   TextSelColor,
81   TodayFlagWidth,
82   TodayHeight,
83   TodayWidth,
84   UIMargin,
85   VSepHeight,
86   VSepWidth,
87   WeekHeight,
88   WeekNumHeight,
89   WeekNumWidth,
90   WeekWidth,
91   Width
92 };
93 
94 class CFDE_TextOut;
95 class CFGAS_GEFont;
96 class CFWL_ArrowData;
97 class CFWL_ThemeBackground;
98 class CFWL_ThemePart;
99 class CFWL_ThemeText;
100 class IFGAS_FontMgr;
101 class IFWL_Widget;
102 
103 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
104 class CFX_FontSourceEnum_File;
105 #endif
106 
107 class CFWL_WidgetTP {
108  public:
109   virtual ~CFWL_WidgetTP();
110 
111   virtual FWL_Error Initialize();
112   virtual FWL_Error Finalize();
113 
114   virtual bool IsValidWidget(IFWL_Widget* pWidget);
115   virtual uint32_t GetThemeID(IFWL_Widget* pWidget);
116   virtual uint32_t SetThemeID(IFWL_Widget* pWidget,
117                               uint32_t dwThemeID,
118                               FX_BOOL bChildren = TRUE);
119   virtual FWL_Error GetThemeMatrix(IFWL_Widget* pWidget, CFX_Matrix& matrix);
120   virtual FWL_Error SetThemeMatrix(IFWL_Widget* pWidget,
121                                    const CFX_Matrix& matrix);
122   virtual FX_BOOL DrawBackground(CFWL_ThemeBackground* pParams);
123   virtual FX_BOOL DrawText(CFWL_ThemeText* pParams);
124   virtual void* GetCapacity(CFWL_ThemePart* pThemePart,
125                             CFWL_WidgetCapacity dwCapacity);
126   virtual FX_BOOL IsCustomizedLayout(IFWL_Widget* pWidget);
127   virtual FWL_Error GetPartRect(CFWL_ThemePart* pThemePart, CFX_RectF& rtPart);
128   virtual FX_BOOL IsInPart(CFWL_ThemePart* pThemePart,
129                            FX_FLOAT fx,
130                            FX_FLOAT fy);
131   virtual FX_BOOL CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect);
132 
133   FWL_Error SetFont(IFWL_Widget* pWidget,
134                     const FX_WCHAR* strFont,
135                     FX_FLOAT fFontSize,
136                     FX_ARGB rgbFont);
137   FWL_Error SetFont(IFWL_Widget* pWidget,
138                     CFGAS_GEFont* pFont,
139                     FX_FLOAT fFontSize,
140                     FX_ARGB rgbFont);
141   CFGAS_GEFont* GetFont(IFWL_Widget* pWidget);
142 
143  protected:
144   CFWL_WidgetTP();
145   FWL_Error InitTTO();
146   FWL_Error FinalizeTTO();
147   void DrawEdge(CFX_Graphics* pGraphics,
148                 uint32_t dwStyles,
149                 const CFX_RectF* pRect,
150                 CFX_Matrix* pMatrix = nullptr);
151   void Draw3DRect(CFX_Graphics* pGraphics,
152                   FWLTHEME_EDGE eType,
153                   FX_FLOAT fWidth,
154                   const CFX_RectF* pRect,
155                   FX_ARGB cr1,
156                   FX_ARGB cr2,
157                   FX_ARGB cr3,
158                   FX_ARGB cr4,
159                   CFX_Matrix* pMatrix = nullptr);
160   void Draw3DCircle(CFX_Graphics* pGraphics,
161                     FWLTHEME_EDGE eType,
162                     FX_FLOAT fWidth,
163                     const CFX_RectF* pRect,
164                     FX_ARGB cr1,
165                     FX_ARGB cr2,
166                     FX_ARGB cr3,
167                     FX_ARGB cr4,
168                     CFX_Matrix* pMatrix = nullptr);
169   void DrawBorder(CFX_Graphics* pGraphics,
170                   const CFX_RectF* pRect,
171                   CFX_Matrix* pMatrix = nullptr);
172   void FillBackground(CFX_Graphics* pGraphics,
173                       const CFX_RectF* pRect,
174                       CFX_Matrix* pMatrix = nullptr);
175   void FillSoildRect(CFX_Graphics* pGraphics,
176                      FX_ARGB fillColor,
177                      const CFX_RectF* pRect,
178                      CFX_Matrix* pMatrix = nullptr);
179   void DrawAxialShading(CFX_Graphics* pGraphics,
180                         FX_FLOAT fx1,
181                         FX_FLOAT fy1,
182                         FX_FLOAT fx2,
183                         FX_FLOAT fy2,
184                         FX_ARGB beginColor,
185                         FX_ARGB endColor,
186                         CFX_Path* path,
187                         int32_t fillMode = FXFILL_WINDING,
188                         CFX_Matrix* pMatrix = nullptr);
189   void DrawAnnulusRect(CFX_Graphics* pGraphics,
190                        FX_ARGB fillColor,
191                        const CFX_RectF* pRect,
192                        FX_FLOAT fRingWidth = 1,
193                        CFX_Matrix* pMatrix = nullptr);
194   void DrawAnnulusCircle(CFX_Graphics* pGraphics,
195                          FX_ARGB fillColor,
196                          const CFX_RectF* pRect,
197                          FX_FLOAT fWidth = 1,
198                          CFX_Matrix* pMatrix = nullptr);
199   void DrawFocus(CFX_Graphics* pGraphics,
200                  const CFX_RectF* pRect,
201                  CFX_Matrix* pMatrix = nullptr);
202   void DrawArrow(CFX_Graphics* pGraphics,
203                  const CFX_RectF* pRect,
204                  FWLTHEME_DIRECTION eDict,
205                  FX_ARGB argbFill,
206                  FX_BOOL bPressed,
207                  CFX_Matrix* pMatrix = nullptr);
208   void DrawArrow(CFX_Graphics* pGraphics,
209                  const CFX_RectF* pRect,
210                  FWLTHEME_DIRECTION eDict,
211                  FX_ARGB argSign,
212                  CFX_Matrix* pMatrix = nullptr);
213   void DrawBtn(CFX_Graphics* pGraphics,
214                const CFX_RectF* pRect,
215                FWLTHEME_STATE eState,
216                CFX_Matrix* pMatrix = nullptr);
217   void DrawArrowBtn(CFX_Graphics* pGraphics,
218                     const CFX_RectF* pRect,
219                     FWLTHEME_DIRECTION eDict,
220                     FWLTHEME_STATE eState,
221                     CFX_Matrix* pMatrix = nullptr);
222   uint32_t m_dwRefCount;
223   std::unique_ptr<CFDE_TextOut> m_pTextOut;
224   CFGAS_GEFont* m_pFDEFont;
225   FX_FLOAT m_fValue;
226   uint32_t m_dwValue;
227   CFX_RectF m_rtMargin;
228   uint32_t m_dwThemeID;
229   CFX_Matrix _ctm;
230 };
231 FX_BOOL FWLTHEME_Init();
232 void FWLTHEME_Release();
233 uint32_t FWL_GetThemeLayout(uint32_t dwThemeID);
234 uint32_t FWL_GetThemeColor(uint32_t dwThemeID);
235 
236 class CFWL_ArrowData {
237  public:
238   static CFWL_ArrowData* GetInstance();
239   static FX_BOOL IsInstance();
240   static void DestroyInstance();
241   virtual ~CFWL_ArrowData();
242   void SetColorData(uint32_t dwID);
243 
244   class CColorData {
245    public:
246     FX_ARGB clrBorder[4];
247     FX_ARGB clrStart[4];
248     FX_ARGB clrEnd[4];
249     FX_ARGB clrSign[4];
250   } * m_pColorData;
251 
252  protected:
253   CFWL_ArrowData();
254   static CFWL_ArrowData* m_pInstance;
255 };
256 
257 class CFWL_FontData {
258  public:
259   CFWL_FontData();
260   virtual ~CFWL_FontData();
261   FX_BOOL Equal(const CFX_WideStringC& wsFontFamily,
262                 uint32_t dwFontStyles,
263                 uint16_t wCodePage);
264   FX_BOOL LoadFont(const CFX_WideStringC& wsFontFamily,
265                    uint32_t dwFontStyles,
266                    uint16_t wCodePage);
GetFont()267   CFGAS_GEFont* GetFont() const { return m_pFont; }
268 
269  protected:
270   CFX_WideString m_wsFamily;
271   uint32_t m_dwStyles;
272   uint32_t m_dwCodePage;
273   CFGAS_GEFont* m_pFont;
274   IFGAS_FontMgr* m_pFontMgr;
275 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
276   CFX_FontSourceEnum_File* m_pFontSource;
277 #endif
278 };
279 
280 class CFWL_FontManager {
281  public:
282   static CFWL_FontManager* GetInstance();
283   static void DestroyInstance();
284 
285   CFGAS_GEFont* FindFont(const CFX_WideStringC& wsFontFamily,
286                          uint32_t dwFontStyles,
287                          uint16_t dwCodePage);
288 
289  protected:
290   CFWL_FontManager();
291   virtual ~CFWL_FontManager();
292 
293   static CFWL_FontManager* s_FontManager;
294   std::vector<std::unique_ptr<CFWL_FontData>> m_FontsArray;
295 };
296 
297 #endif  // XFA_FWL_THEME_CFWL_WIDGETTP_H_
298