Home |
Class PegTable HMI (Human-Machine Interface) Classes |
Class PegTablePegTable is a container object for displaying a matrix of PegThing derived objects. The number of table rows and columns must be passed to the PegTable constructor. The row heights and columns widths are determined dynamically as objects are added to the table. PegTable will display a cell grid if the table gridline width is non-zero. The default gridline width is PEG_FRAME_WIDTH. This can be modified by calling the member function SetGridWidth(). Each cell can add padding space around each child object if desired. The default padding amount is zero pixels. This can be modified by calling the table member function SetCellPadding(). Cell padding applies to all cells in the table. Child objects are added to the table using the table SetCellClient() member function. Any PegThing derived class may become a table cell client. As objects are added to the table, they can be set to span multiple rows and/or columns. This allows much flexibility in the final appearance of the table. When objects that span multiple rows or columns are added to the table and the bForceFit parameter to the SetCellClient() function is TRUE, the spanned rows and/or columns may be expanded to insure that the object is fully displayed in the indicated table cells. When constructing child objects to display in the table, it is not necessary for the application software to calculate each child object's position. This is determined by the table window. It IS necessary, however, to properly set the overall size of each child object before adding that object to the table. The table determines the row heights and columns widths by examining the size of each child object in conjunction with the rowspan and columnspan attributes of each child. After the table has been fully initialized, the Layout() member function should be called before the table is displayed. The Layout function calculates the correct overall table size, and positions each child object to fit correctly within the desired table cells. The Layout() function re-sizes row heights and column widths if required to accommodate all 'bForceFit' children. The layout algorithm works by checking the following rules in the following order:
The general order of constructing a PegTable is:
Each table column has a fixed width. Initially each column has a default width of zero. The true width of each column can either be set manually by calling the SetColWidth() function, or can be determined automatically by the table. When adding objects to the table, the table will automatically re-size columns (and rows) to match the size of the child object if the bForceFit parameter is set to TRUE on a call to SetCellClient(). In all cases, the column width for each column is set to the maximum width of either all children for that column or the manually assigned column width value. Each table row also has a fixed height, which can be set using the SetRowHeight() function or can be determined automatically by the table. PegTable will automatically size itself to display all children when the Layout() function is called. For displaying very large tables, PegTable may be added to the client area of a parent window which has scrolling enabled This will allow the table to be panned up down and left right. Notifications sent from table cell clients are passed unchanged to the table parent. This allows any window containing a PegTable to receive events from the table cell client objects as if the objects were direct children of the parent window. struct TableCellInfo { TableCellInfo(void); PegThing * pChild; TableCellInfo * pNext; PEGINT iRow; PEGINT iCol; PEGINT iRowSpan; PEGINT iColSpan; PEGUINT wStyle; // 0x0001 bit is for ForceFit, upper byte for justification }; class PegTable : public PegWindow { public: PegTable(int iLeft, int iTop, int iRows, int iCols); virtual void Draw(void); virtual void DrawGrid(void); virtual void DrawChildren(void); virtual void SetCellPadding(PEGINT iPad); void SetGridWidth(int iWidth = PEG_FRAME_WIDTH); virtual void SetColWidth(int iCol, int iWidth, BOOL bForce = FALSE); virtual void SetRowHeight(int iRow, int iHeight, BOOL bForce = FALSE); virtual void SetCellClient(int iRow, int iCol, PegThing * Child, int iRowSpan = 1, int iColSpan = 1, PEGUINT wStyle = TCF_HCENTER | TCF_VCENTER); virtual void Reconfigure(int iRows, int iCols, int iGridWidth, int iCellPad); PegThing * GetCellClient(int iRow, int iCol); virtual void Layout(void); int GetRows(void); int GetColumns(void); int GetGridWidth(void); int GetCellPadding(void); BOOL GetRowCol(PegThing * pChild, PEGINT * pRow, PEGINT * pCol); PegThing * RemoveCellClient(int iRow, int iCol); protected: BOOL CellSpansRow(int iRow, int iCol); BOOL CellSpansCol(int iRow, int iCol); int * mpCellHeights; int * mpCellWidths; TableCellInfo * mpCellInfo; int miCellPad; int miGridWidth; int miRows; int miCols; }; Demo program Table uses this class. Style FlagsTS_SOLID_FILL, TS_DRAW_GRID, TS_PARTIAL_COL, TS_PARTIAL_ROW, TS_DRAW_HORZ_GRID, TS_DRAW_VERT_GRID. PegTable also supports the following styles with regard to the cell clients. These flags are only applicable when calling the SetCellClient() method: TCF_FORCEFIT, TCF_HCENTER, TCF_HLEFT, TCF_HRIGHT, TCF_VCENTER, TCF_VTOP, TCF_VBOTTOM. ConstructorThe PegTable constructor requires the top-left table corner position, and the number of table rows and columns. Method DrawPegTable overrides the draw function and breaks the procedure into two stages. First the table itself draws the table gridlines. Then the table mClip variable is set to the "client area" of each cell, and individual cell clients are drawn. Method DrawGridDraws the table gridlines. Method DrawChildrenModifies the base class function of the same name to prevent child objects from drawing outside the cell area allocated to each cell client. Method GetCellClientReturns a pointer to the object displayed at the indicated cell position. Method GetCellPaddingThis function returns the cell padding of the table. Method GetColumnsReturns the number of columns in the table. Method GetGridWidthThis function returns the table's grid width. Method GetRowColReturns the row and column position of the child object indicated by pChild. If pChild is found in the table, pRow and pCol are written by this function to contain the row and column of the indicated child object. If the object spans multiple rows or columns, the returned row and column value will be the first, or upper left, cell position. This function returns TRUE if the object pChild is found in the table, else FALSE. Method GetRowsReturns the number of rows in the table. Method LayoutLayout should be called whenever the list of table child objects is modified. This is normally done after the table is fully initialized but before the table is displayed. Note that child objects can be modified after the table has been displayed. The layout function should be called after any modifications are made to a visible table. Note that table row heights and column widths are never decreased, but may be increased if new child objects are added which are larger than the objects previously contained in a given cell or group of cells. Method ReconfigureThis function recalculates row/column widths based on current entries. This should be called after changing the cell clients. Method RemoveCellClientRemoves the child object at the indicated cell position, and returns a pointer to that object. The object is not destroyed. Method SetCellClientSetCellClient is used to populate the children displayed in each table cell. The child objects can be any type of PegThing derived objects, which includes all buttons, strings, prompts, textboxes, etc.. The default row and column span for an object is 1, indicating that the object occupies one table cell. If the ColSpan or RowSpan values are set to a value larger than 1, this object will occupy multiple table cells. The default wStyle flag will center the object vertically and horizontally within the bounding cell. To enable force fitting the cell on the table, specify the TCF_FORCEFIT style. It is important to note that the justification styles operate only on the placement of the object within its bounding cell or cells. The style flags do not operate on the object itself. For example, a PegPrompt object has a series of styles that allow for left, center and right justification of its text. These text justification style flags are completely independant of the cell style flags. Therefore, it would be acceptable to right justify the text within the PegPrompt object while specifying that the PegPrompt object be positioned horizontally to the left within the cell. Method SetCellPaddingSetCellPadding is used to modify the default cell padding value, which is zero. The padding amount is in pixels. Method SetColWidthSets the column width for any number of columns in the table. The column width can not be decreased, but can only be set to a value larger than the current value. The initial width of all table columns is zero pixels. Method SetGridWidthSets the grid line width for the grid drawn by the table. Setting the gridline width to zero disables the table grid, however all other positioning works as normal. Method SetRowHeightSets the row height for each table row. The row height cannot be decreased, but can only be set to a value larger than the current value. The initial height of all table rows is zero. ExampleThe following is a PegTable populated with different types of cell client objects.
|