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_GRID_IMP_H 8 #define _FWL_GRID_IMP_H 9 class CFWL_Content; 10 class IFWL_Widget; 11 class CFWL_GridLength; 12 class CFWL_GridColRow; 13 class CFWL_GridWidgetInfo; 14 class CFWL_GridImp; 15 class CFWL_GridLength { 16 public: CFWL_GridLength()17 CFWL_GridLength() : fLength(0), eUnit(FWL_GRIDUNIT_Fixed) {} CFWL_GridLength(FX_FLOAT fValue,FWL_GRIDUNIT e)18 CFWL_GridLength(FX_FLOAT fValue, FWL_GRIDUNIT e) 19 : fLength(fValue), eUnit(e) {} 20 FX_FLOAT fLength; 21 FWL_GRIDUNIT eUnit; 22 }; 23 class CFWL_GridColRow { 24 public: CFWL_GridColRow()25 CFWL_GridColRow() 26 : m_Size(1, FWL_GRIDUNIT_Scaled), 27 m_MinSize(0, FWL_GRIDUNIT_Fixed), 28 m_MaxSize(0, FWL_GRIDUNIT_Infinity), 29 m_fActualSize(0), 30 m_fActualPos(0) {} 31 CFWL_GridLength m_Size; 32 CFWL_GridLength m_MinSize; 33 CFWL_GridLength m_MaxSize; 34 FX_FLOAT m_fActualSize; 35 FX_FLOAT m_fActualPos; 36 }; 37 class CFWL_GridWidgetInfo { 38 public: CFWL_GridWidgetInfo()39 CFWL_GridWidgetInfo() 40 : m_iColumn(0), 41 m_iColumnSpan(1), 42 m_iRow(0), 43 m_iRowSpan(1), 44 m_dwMarginFlag(0), 45 m_fActualWidth(0), 46 m_fActualHeight(0) { 47 m_Size[FWL_GRIDSIZE_Width].eUnit = FWL_GRIDUNIT_Auto; 48 m_Size[FWL_GRIDSIZE_Width].fLength = 0; 49 m_Size[FWL_GRIDSIZE_Height].eUnit = FWL_GRIDUNIT_Auto; 50 m_Size[FWL_GRIDSIZE_Height].fLength = 0; 51 m_Size[FWL_GRIDSIZE_MinWidth].eUnit = FWL_GRIDUNIT_Fixed; 52 m_Size[FWL_GRIDSIZE_MinWidth].fLength = 0; 53 m_Size[FWL_GRIDSIZE_MaxWidth].eUnit = FWL_GRIDUNIT_Infinity; 54 m_Size[FWL_GRIDSIZE_MaxWidth].fLength = 0; 55 m_Size[FWL_GRIDSIZE_MinHeight].eUnit = FWL_GRIDUNIT_Fixed; 56 m_Size[FWL_GRIDSIZE_MinHeight].fLength = 0; 57 m_Size[FWL_GRIDSIZE_MaxHeight].eUnit = FWL_GRIDUNIT_Infinity; 58 m_Size[FWL_GRIDSIZE_MaxHeight].fLength = 0; 59 m_Margin[0] = m_Margin[1] = m_Margin[2] = m_Margin[3] = 0; 60 } 61 int32_t m_iColumn; 62 int32_t m_iColumnSpan; 63 int32_t m_iRow; 64 int32_t m_iRowSpan; 65 CFWL_GridLength m_Size[6]; 66 FX_DWORD m_dwMarginFlag; 67 FX_FLOAT m_Margin[4]; 68 FX_FLOAT m_fActualWidth; 69 FX_FLOAT m_fActualHeight; 70 }; 71 class CFWL_GridImp : public CFWL_ContentImp { 72 public: 73 CFWL_GridImp(const CFWL_WidgetImpProperties& properties, IFWL_Widget* pOuter); 74 virtual ~CFWL_GridImp(); 75 virtual FWL_ERR GetClassName(CFX_WideString& wsClass) const; 76 virtual FX_DWORD GetClassID() const; 77 virtual FWL_ERR Initialize(); 78 virtual FWL_ERR Finalize(); 79 virtual FWL_ERR GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE); 80 virtual FWL_ERR SetWidgetRect(const CFX_RectF& rect); 81 virtual FWL_ERR Update(); 82 virtual FWL_ERR DrawWidget(CFX_Graphics* pGraphics, 83 const CFX_Matrix* pMatrix = NULL); 84 85 virtual FWL_ERR InsertWidget(IFWL_Widget* pChild, int32_t nIndex = -1); 86 virtual FWL_ERR RemoveWidget(IFWL_Widget* pWidget); 87 virtual FWL_HGRIDCOLROW InsertColRow(FX_BOOL bColumn, int32_t nIndex = -1); 88 virtual int32_t CountColRows(FX_BOOL bColumn); 89 virtual FWL_HGRIDCOLROW GetColRow(FX_BOOL bColumn, int32_t nIndex); 90 virtual int32_t GetIndex(FWL_HGRIDCOLROW hColRow); 91 virtual FX_FLOAT GetSize(FWL_HGRIDCOLROW hColRow, FWL_GRIDUNIT& eUnit); 92 virtual FWL_ERR SetSize(FWL_HGRIDCOLROW hColRow, 93 FX_FLOAT fSize, 94 FWL_GRIDUNIT eUnit); 95 FX_FLOAT GetMinSize(FWL_HGRIDCOLROW hColRow, FWL_GRIDUNIT& eUnit); 96 FWL_ERR SetMinSize(FWL_HGRIDCOLROW hColRow, 97 FX_FLOAT fSize, 98 FWL_GRIDUNIT eUnit); 99 FX_FLOAT GetMaxSize(FWL_HGRIDCOLROW hColRow, FWL_GRIDUNIT& eUnit); 100 FWL_ERR SetMaxSize(FWL_HGRIDCOLROW hColRow, 101 FX_FLOAT fSize, 102 FWL_GRIDUNIT eUnit); 103 virtual FX_BOOL DeleteColRow(FWL_HGRIDCOLROW hColRow); 104 virtual FX_BOOL IsColumn(FWL_HGRIDCOLROW hColRow); 105 virtual int32_t GetWidgetPos(IFWL_Widget* pWidget, FX_BOOL bColumn); 106 virtual FWL_ERR SetWidgetPos(IFWL_Widget* pWidget, 107 int32_t iPos, 108 FX_BOOL bColumn); 109 virtual int32_t GetWidgetSpan(IFWL_Widget* pWidget, FX_BOOL bColumn); 110 virtual FWL_ERR SetWidgetSpan(IFWL_Widget* pWidget, 111 int32_t iSpan, 112 FX_BOOL bColumn); 113 virtual FX_FLOAT GetWidgetSize(IFWL_Widget* pWidget, 114 FWL_GRIDSIZE eSize, 115 FWL_GRIDUNIT& eUnit); 116 virtual FWL_ERR SetWidgetSize(IFWL_Widget* pWidget, 117 FWL_GRIDSIZE eSize, 118 FX_FLOAT fSize, 119 FWL_GRIDUNIT eUit); 120 virtual FX_BOOL GetWidgetMargin(IFWL_Widget* pWidget, 121 FWL_GRIDMARGIN eMargin, 122 FX_FLOAT& fMargin); 123 virtual FWL_ERR SetWidgetMargin(IFWL_Widget* pWidget, 124 FWL_GRIDMARGIN eMargin, 125 FX_FLOAT fMargin); 126 virtual FWL_ERR RemoveWidgetMargin(IFWL_Widget* pWidget, 127 FWL_GRIDMARGIN eMargin); 128 virtual FX_FLOAT GetGridSize(FWL_GRIDSIZE eSize, FWL_GRIDUNIT& eUnit); 129 virtual FWL_ERR SetGridSize(FWL_GRIDSIZE eSize, 130 FX_FLOAT fSize, 131 FWL_GRIDUNIT eUit); 132 133 protected: 134 CFWL_GridWidgetInfo* GetWidgetInfo(IFWL_Widget* pWidget); 135 void ProcFixedColRow(CFWL_GridColRow* pColRow, 136 int32_t nIndex, 137 FX_FLOAT fColRowSize, 138 FX_BOOL bColumn); 139 void ProcAutoColRow(CFWL_GridColRow* pColRow, 140 int32_t nIndex, 141 FX_BOOL bColumn); 142 void ProcScaledColRow(CFWL_GridColRow* pColRow, 143 int32_t nIndex, 144 FX_FLOAT fColRowSize, 145 FX_BOOL bColumn); 146 void CalcWidgetWidth(IFWL_Widget* pWidget, 147 CFWL_GridWidgetInfo* pInfo, 148 FX_FLOAT fColunmWidth); 149 void CalcWidgetHeigt(IFWL_Widget* pWidget, 150 CFWL_GridWidgetInfo* pInfo, 151 FX_FLOAT fRowHeigt); 152 FX_FLOAT CalcAutoColumnWidgetWidth(IFWL_Widget* pWidget, 153 CFWL_GridWidgetInfo* pInfo); 154 FX_FLOAT CalcAutoColumnWidgetHeight(IFWL_Widget* pWidget, 155 CFWL_GridWidgetInfo* pInfo); 156 FX_FLOAT ProcessColumns(FX_FLOAT fWidth); 157 FX_FLOAT ProcessRows(FX_FLOAT fHeight); 158 FX_FLOAT ProcessUnCertainColumns(); 159 FX_FLOAT ProcessUnCertainRows(); 160 FX_BOOL SetColRowActualSize(CFWL_GridColRow* pColRow, 161 FX_FLOAT fSize, 162 FX_BOOL bSetBeyond = FALSE); 163 FX_FLOAT SetWidgetActualWidth(CFWL_GridWidgetInfo* pInfo, FX_FLOAT fWidth); 164 FX_FLOAT SetWidgetActualHeight(CFWL_GridWidgetInfo* pInfo, FX_FLOAT fHeight); 165 void SetAllWidgetsRect(); 166 FX_BOOL IsGrid(IFWL_Widget* pWidget); 167 void SetSpanAutoColRowSize(const CFX_PtrArray& spanAutos, 168 FX_FLOAT fTotalSize); 169 void SetSpanScaledColRowSize(const CFX_PtrArray& spanScaleds, 170 FX_FLOAT fTotalSize, 171 FX_FLOAT fTotalScaledNum); 172 void SetScaledColRowsSize(const CFX_PtrArray& spanScaleds, 173 FX_FLOAT fTotalSize, 174 FX_FLOAT fTotalScaledNum); 175 CFX_PtrArray m_Rows; 176 CFX_PtrArray m_Columns; 177 CFX_PtrArray m_Widgets; 178 CFX_MapPtrToPtr m_mapWidgetInfo; 179 CFWL_GridLength m_Size[6]; 180 friend class CFWL_GridImpDelegate; 181 }; 182 class CFWL_GridImpDelegate : public CFWL_WidgetImpDelegate { 183 public: 184 CFWL_GridImpDelegate(CFWL_GridImp* pOwner); 185 int32_t OnProcessMessage(CFWL_Message* pMessage) override; 186 FWL_ERR OnDrawWidget(CFX_Graphics* pGraphics, 187 const CFX_Matrix* pMatrix = NULL) override; 188 189 protected: 190 CFWL_GridImp* m_pOwner; 191 }; 192 #endif 193