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_FORM_IMP_H 8 #define _FWL_FORM_IMP_H 9 class CFWL_NoteLoop; 10 class CFWL_PanelImp; 11 class CFWL_WidgetImpProperties; 12 class CFWL_WidgetImpDelegate; 13 class CFWL_MsgMouse; 14 class IFWL_Widget; 15 class IFWL_ThemeProvider; 16 class CFWL_SysBtn; 17 class CFWL_FormImp; 18 class CFWL_FormImpDelegate; 19 #define FWL_SYSBUTTONSTATE_Hover 0x0001 20 #define FWL_SYSBUTTONSTATE_Pressed 0x0002 21 #define FWL_SYSBUTTONSTATE_Disabled 0x0010 22 class CFWL_SysBtn { 23 public: 24 CFWL_SysBtn() { 25 m_rtBtn.Set(0, 0, 0, 0); 26 m_dwState = 0; 27 } 28 29 FX_BOOL IsHover() { return m_dwState & FWL_SYSBUTTONSTATE_Hover; } 30 FX_BOOL IsPressed() { return m_dwState & FWL_SYSBUTTONSTATE_Pressed; } 31 FX_BOOL IsDisabled() { return m_dwState & FWL_SYSBUTTONSTATE_Disabled; } 32 void SetNormal() { m_dwState &= 0xFFF0; } 33 void SetPressed() { 34 SetNormal(); 35 m_dwState |= FWL_SYSBUTTONSTATE_Pressed; 36 } 37 void SetHover() { 38 SetNormal(); 39 m_dwState |= FWL_SYSBUTTONSTATE_Hover; 40 } 41 void SetDisabled(FX_BOOL bDisabled) { 42 bDisabled ? m_dwState |= FWL_SYSBUTTONSTATE_Disabled 43 : m_dwState &= ~FWL_SYSBUTTONSTATE_Disabled; 44 } 45 int32_t GetPartState() { 46 return (IsDisabled() ? FWL_PARTSTATE_FRM_Disabled : (m_dwState + 1)); 47 } 48 49 CFX_RectF m_rtBtn; 50 FX_DWORD m_dwState; 51 }; 52 enum FORM_RESIZETYPE { 53 FORM_RESIZETYPE_None = 0, 54 FORM_RESIZETYPE_Cap, 55 FORM_RESIZETYPE_Left, 56 FORM_RESIZETYPE_Top, 57 FORM_RESIZETYPE_Right, 58 FORM_RESIZETYPE_Bottom, 59 FORM_RESIZETYPE_LeftTop, 60 FORM_RESIZETYPE_LeftBottom, 61 FORM_RESIZETYPE_RightTop, 62 FORM_RESIZETYPE_RightBottom 63 }; 64 typedef struct RestoreResizeInfo { 65 CFX_PointF m_ptStart; 66 CFX_SizeF m_szStart; 67 } RestoreInfo; 68 class CFWL_FormImp : public CFWL_PanelImp { 69 public: 70 CFWL_FormImp(const CFWL_WidgetImpProperties& properties, IFWL_Widget* pOuter); 71 virtual ~CFWL_FormImp(); 72 virtual FWL_ERR GetClassName(CFX_WideString& wsClass) const; 73 virtual FX_DWORD GetClassID() const; 74 virtual FX_BOOL IsInstance(const CFX_WideStringC& wsClass) const; 75 virtual FWL_ERR Initialize(); 76 virtual FWL_ERR Finalize(); 77 78 virtual FWL_ERR GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE); 79 virtual FWL_ERR GetClientRect(CFX_RectF& rect); 80 virtual FWL_ERR Update(); 81 virtual FX_DWORD HitTest(FX_FLOAT fx, FX_FLOAT fy); 82 virtual FWL_ERR DrawWidget(CFX_Graphics* pGraphics, 83 const CFX_Matrix* pMatrix = NULL); 84 virtual FWL_FORMSIZE GetFormSize(); 85 virtual FWL_ERR SetFormSize(FWL_FORMSIZE eFormSize); 86 virtual IFWL_Widget* DoModal(); 87 virtual IFWL_Widget* DoModal(FX_DWORD& dwCommandID); 88 virtual FWL_ERR EndDoModal(); 89 virtual FWL_ERR SetBorderRegion(CFX_Path* pPath); 90 virtual void DrawBackground(CFX_Graphics* pGraphics, 91 IFWL_ThemeProvider* pTheme); 92 CFWL_WidgetImp* GetSubFocus(); 93 void SetSubFocus(CFWL_WidgetImp* pWidget); 94 CFX_MapAccelerators& GetAccelerator(); 95 void SetAccelerator(CFX_MapAccelerators* pAccelerators); 96 97 protected: 98 void ShowChildWidget(IFWL_Widget* pParent); 99 void RemoveSysButtons(); 100 void CalcContentRect(CFX_RectF& rtContent); 101 CFWL_SysBtn* GetSysBtnAtPoint(FX_FLOAT fx, FX_FLOAT fy); 102 CFWL_SysBtn* GetSysBtnByState(FX_DWORD dwState); 103 CFWL_SysBtn* GetSysBtnByIndex(int32_t nIndex); 104 int32_t GetSysBtnIndex(CFWL_SysBtn* pBtn); 105 FX_FLOAT GetCaptionHeight(); 106 void DrawCaptionText(CFX_Graphics* pGs, 107 IFWL_ThemeProvider* pTheme, 108 const CFX_Matrix* pMatrix = NULL); 109 void DrawIconImage(CFX_Graphics* pGs, 110 IFWL_ThemeProvider* pTheme, 111 const CFX_Matrix* pMatrix = NULL); 112 void GetEdgeRect(CFX_RectF& rtEdge); 113 void SetWorkAreaRect(); 114 void SetCursor(FX_FLOAT fx, FX_FLOAT fy); 115 void Layout(); 116 void ReSetSysBtn(); 117 void RegisterForm(); 118 void UnRegisterForm(); 119 FX_BOOL IsDoModal(); 120 void SetThemeData(); 121 FX_BOOL HasIcon(); 122 void UpdateIcon(); 123 void UpdateCaption(); 124 void DoWidthLimit(FX_FLOAT& fLeft, 125 FX_FLOAT& fWidth, 126 FX_FLOAT fCurX, 127 FX_FLOAT fSpace, 128 FX_FLOAT fLimitMin, 129 FX_FLOAT fLimitMax, 130 FX_BOOL bLeft); 131 void DoHeightLimit(FX_FLOAT& fTop, 132 FX_FLOAT& fHeight, 133 FX_FLOAT fCurY, 134 FX_FLOAT fSpace, 135 FX_FLOAT fLimitMin, 136 FX_FLOAT fLimitMax, 137 FX_BOOL bTop); 138 CFX_MapAccelerators m_mapAccelerators; 139 CFX_RectF m_rtRestore; 140 CFX_RectF m_rtCaptionText; 141 CFX_RectF m_rtRelative; 142 CFX_RectF m_rtCaption; 143 CFX_RectF m_rtIcon; 144 CFWL_SysBtn* m_pCloseBox; 145 CFWL_SysBtn* m_pMinBox; 146 CFWL_SysBtn* m_pMaxBox; 147 CFWL_SysBtn* m_pCaptionBox; 148 CFWL_NoteLoop* m_pNoteLoop; 149 CFWL_WidgetImp* m_pSubFocus; 150 RestoreInfo m_InfoStart; 151 FX_FLOAT m_fCXBorder; 152 FX_FLOAT m_fCYBorder; 153 int32_t m_iCaptureBtn; 154 int32_t m_iSysBox; 155 int32_t m_eResizeType; 156 FX_BOOL m_bLButtonDown; 157 FX_BOOL m_bMaximized; 158 FX_BOOL m_bSetMaximize; 159 FX_BOOL m_bCustomizeLayout; 160 FWL_FORMSIZE m_eFormSize; 161 FX_BOOL m_bDoModalFlag; 162 FX_FLOAT m_fSmallIconSz; 163 FX_FLOAT m_fBigIconSz; 164 CFX_DIBitmap* m_pBigIcon; 165 CFX_DIBitmap* m_pSmallIcon; 166 FX_BOOL m_bMouseIn; 167 friend class CFWL_FormImpDelegate; 168 }; 169 class CFWL_FormImpDelegate : public CFWL_WidgetImpDelegate { 170 public: 171 CFWL_FormImpDelegate(CFWL_FormImp* pOwner); 172 int32_t OnProcessMessage(CFWL_Message* pMessage) override; 173 FWL_ERR OnProcessEvent(CFWL_Event* pEvent) override; 174 FWL_ERR OnDrawWidget(CFX_Graphics* pGraphics, 175 const CFX_Matrix* pMatrix = NULL) override; 176 177 protected: 178 void OnLButtonDown(CFWL_MsgMouse* pMsg); 179 void OnLButtonUp(CFWL_MsgMouse* pMsg); 180 void OnMouseMove(CFWL_MsgMouse* pMsg); 181 void OnMouseHover(CFWL_MsgMouse* pMsg); 182 void OnMouseLeave(CFWL_MsgMouse* pMsg); 183 void OnLButtonDblClk(CFWL_MsgMouse* pMsg); 184 void OnWindowMove(CFWL_MsgWindowMove* pMsg); 185 void OnClose(CFWL_MsgClose* pMsg); 186 CFWL_FormImp* m_pOwner; 187 }; 188 #endif 189