• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CFWL_WIDGET_H_
8 #define XFA_FWL_CFWL_WIDGET_H_
9 #include <memory>
10 
11 #include "core/fxcrt/fx_coordinates.h"
12 #include "core/fxcrt/fx_system.h"
13 #include "xfa/fwl/cfwl_event.h"
14 #include "xfa/fwl/cfwl_themepart.h"
15 #include "xfa/fwl/cfwl_widgetmgr.h"
16 #include "xfa/fwl/fwl_widgethit.h"
17 #include "xfa/fwl/ifwl_widgetdelegate.h"
18 #include "xfa/fwl/theme/cfwl_widgettp.h"
19 
20 enum class FWL_Type {
21   Unknown = 0,
22 
23   Barcode,
24   Caret,
25   CheckBox,
26   ComboBox,
27   DateTimePicker,
28   Edit,
29   Form,
30   FormProxy,
31   ListBox,
32   MonthCalendar,
33   PictureBox,
34   PushButton,
35   ScrollBar,
36   SpinButton,
37   ToolTip
38 };
39 
40 class CFWL_App;
41 class CFWL_AppImp;
42 class CFWL_MessageKey;
43 class CFWL_Widget;
44 class CFWL_WidgetMgr;
45 class CFWL_WidgetProperties;
46 class CXFA_FFWidget;
47 class IFWL_ThemeProvider;
48 
49 class CFWL_Widget : public IFWL_WidgetDelegate {
50  public:
51   ~CFWL_Widget() override;
52 
53   virtual FWL_Type GetClassID() const = 0;
54   virtual bool IsInstance(const CFX_WideStringC& wsClass) const;
55   virtual CFX_RectF GetAutosizedWidgetRect();
56   virtual CFX_RectF GetWidgetRect();
57   virtual CFX_RectF GetClientRect();
58   virtual void ModifyStylesEx(uint32_t dwStylesExAdded,
59                               uint32_t dwStylesExRemoved);
60   virtual void SetStates(uint32_t dwStates);
61   virtual void RemoveStates(uint32_t dwStates);
62   virtual void Update() = 0;
63   virtual FWL_WidgetHit HitTest(const CFX_PointF& point);
64   virtual void DrawWidget(CFX_Graphics* pGraphics,
65                           const CFX_Matrix* pMatrix) = 0;
66   virtual void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider);
67 
68   // IFWL_WidgetDelegate.
69   void OnProcessMessage(CFWL_Message* pMessage) override;
70   void OnProcessEvent(CFWL_Event* pEvent) override;
71   void OnDrawWidget(CFX_Graphics* pGraphics,
72                     const CFX_Matrix* pMatrix) override;
73 
74   void InflateWidgetRect(CFX_RectF& rect);
75   void SetWidgetRect(const CFX_RectF& rect);
76 
77   void SetParent(CFWL_Widget* pParent);
78 
GetOwner()79   CFWL_Widget* GetOwner() { return m_pWidgetMgr->GetOwnerWidget(this); }
GetOuter()80   CFWL_Widget* GetOuter() const { return m_pOuter; }
81 
82   uint32_t GetStyles() const;
83   void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved);
84   uint32_t GetStylesEx() const;
85   uint32_t GetStates() const;
86 
LockUpdate()87   void LockUpdate() { m_iLock++; }
UnlockUpdate()88   void UnlockUpdate() {
89     if (IsLocked())
90       m_iLock--;
91   }
92 
93   CFX_PointF TransformTo(CFWL_Widget* pWidget, const CFX_PointF& point);
94   CFX_Matrix GetMatrix();
95   IFWL_ThemeProvider* GetThemeProvider() const;
96 
SetDelegate(IFWL_WidgetDelegate * delegate)97   void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; }
GetDelegate()98   IFWL_WidgetDelegate* GetDelegate() {
99     return m_pDelegate ? m_pDelegate : this;
100   }
GetDelegate()101   const IFWL_WidgetDelegate* GetDelegate() const {
102     return m_pDelegate ? m_pDelegate : this;
103   }
104 
GetOwnerApp()105   const CFWL_App* GetOwnerApp() const { return m_pOwnerApp; }
GetEventKey()106   uint32_t GetEventKey() const { return m_nEventKey; }
SetEventKey(uint32_t key)107   void SetEventKey(uint32_t key) { m_nEventKey = key; }
108 
GetLayoutItem()109   CXFA_FFWidget* GetLayoutItem() const { return m_pLayoutItem; }
SetLayoutItem(CXFA_FFWidget * pItem)110   void SetLayoutItem(CXFA_FFWidget* pItem) { m_pLayoutItem = pItem; }
111 
112   void SetFocus(bool bFocus);
113   void RepaintRect(const CFX_RectF& pRect);
114   void Repaint();
115 
116  protected:
117   CFWL_Widget(const CFWL_App* app,
118               std::unique_ptr<CFWL_WidgetProperties> properties,
119               CFWL_Widget* pOuter);
120 
121   bool IsEnabled() const;
IsLocked()122   bool IsLocked() const { return m_iLock > 0; }
123   bool HasBorder() const;
124   CFX_RectF GetEdgeRect();
125   FX_FLOAT GetBorderSize(bool bCX);
126   CFX_RectF GetRelativeRect();
127   IFWL_ThemeProvider* GetAvailableTheme();
128   CFX_SizeF CalcTextSize(const CFX_WideString& wsText,
129                          IFWL_ThemeProvider* pTheme,
130                          bool bMultiLine);
131   void CalcTextRect(const CFX_WideString& wsText,
132                     IFWL_ThemeProvider* pTheme,
133                     uint32_t dwTTOStyles,
134                     int32_t iTTOAlign,
135                     CFX_RectF& rect);
136   void SetGrab(bool bSet);
137   void GetPopupPos(FX_FLOAT fMinHeight,
138                    FX_FLOAT fMaxHeight,
139                    const CFX_RectF& rtAnchor,
140                    CFX_RectF& rtPopup);
141   void RegisterEventTarget(CFWL_Widget* pEventSource);
142   void UnregisterEventTarget();
143   void DispatchEvent(CFWL_Event* pEvent);
144   void DrawBorder(CFX_Graphics* pGraphics,
145                   CFWL_Part iPartBorder,
146                   IFWL_ThemeProvider* pTheme,
147                   const CFX_Matrix* pMatrix);
148 
149   const CFWL_App* const m_pOwnerApp;
150   CFWL_WidgetMgr* const m_pWidgetMgr;
151   std::unique_ptr<CFWL_WidgetProperties> m_pProperties;
152   CFWL_Widget* m_pOuter;
153   int32_t m_iLock;
154 
155  private:
GetParent()156   CFWL_Widget* GetParent() { return m_pWidgetMgr->GetParentWidget(this); }
157   CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent);
158 
159   bool IsVisible() const;
160   bool IsOverLapper() const;
161   bool IsPopup() const;
162   bool IsChild() const;
163   CFWL_Widget* GetRootOuter();
164   bool GetPopupPosMenu(FX_FLOAT fMinHeight,
165                        FX_FLOAT fMaxHeight,
166                        const CFX_RectF& rtAnchor,
167                        CFX_RectF& rtPopup);
168   bool GetPopupPosComboBox(FX_FLOAT fMinHeight,
169                            FX_FLOAT fMaxHeight,
170                            const CFX_RectF& rtAnchor,
171                            CFX_RectF& rtPopup);
172   bool GetPopupPosGeneral(FX_FLOAT fMinHeight,
173                           FX_FLOAT fMaxHeight,
174                           const CFX_RectF& rtAnchor,
175                           CFX_RectF& rtPopup);
176   void DrawBackground(CFX_Graphics* pGraphics,
177                       CFWL_Part iPartBk,
178                       IFWL_ThemeProvider* pTheme,
179                       const CFX_Matrix* pMatrix);
180   void NotifyDriver();
181   bool IsParent(CFWL_Widget* pParent);
182 
183   CXFA_FFWidget* m_pLayoutItem;
184   uint32_t m_nEventKey;
185   IFWL_WidgetDelegate* m_pDelegate;  // Not owned.
186 };
187 
188 #endif  // XFA_FWL_CFWL_WIDGET_H_
189