Home |
Class PegSpreadSheet HMI (Human-Machine Interface) Classes |
Class PegSpreadSheetPegSpreadSheet is a matrix for displaying text or alphanumeric values. PegSpreadSheet is a higher level construct than the basic PEG window and control types, and therefore there are a large number of functions available for controlling PegSpreadSheet appearance and operation. PegSpreadSheet allows selection of individual cells, entire rows and columns, or any combination in between. PegSpreadSheet may have any number of column headings, row headings, and column footers. In addition, PegSpreadSheet supports vertical and horizontal scrolling. Specific groups of rows and/or columns may be specified as "fixed", in that they do not move when the table is scrolled. PegSpreadSheet columns automatically size themselves based on the width of the objects contained in each cell. The justification of text within each column can also be individually configured. PegSpreadSheet cells may be configured to be selected individually or in complete rows or columns. Whenever an individual cell is selected by the user, the SpreadSheet will send a PSF_CELL_SELECT signal to the parent window assuming that notification has been enabled. The message pSource pointer will point to the SpreadSheet and the message Point member will contain the row and column of the selected cell, allowing the application to fully determine which cell has been selected. When a spreadsheet column is selected, the spreadsheet will send a PSF_COL_SELECT signal to the parent window. The message iData member will contain the first column number selected, and the message lData member will contain the last column number selected. These will be the same value when only one column is selected. When a spreadsheet row is selected, the spreadsheet will send a PSF_ROW_SELECT signal to the parent window. The message iData member will contain the first row number selected, and the message lData member will contain the last row number selected. Each column of the spreadsheet has its own set of style flags. These flags control the appearance of each column of cells. These flags are modified through the SetColStyle() member function. Likewise, each row of the spreadsheet has unique style flags, which are set with the SetRowStyle() member function. PegSpreadSheet can be drawn with a flat, raised, or recessed appearance to each cell. Optional column headers, row headers, and column footers are drawn if desired. PegSpreadSheet automatically provides horizontal and vertical scrolling capability if the client area is not sufficient to display all cells. If the spreadsheet is resized such that the scroll bars are no longer required, they are automatically removed. class PegSpreadSheet : public PegWindow { public: PegSpreadSheet(const PegRect &Rect, int iRows, int iCols, PEGUINT wId = 0, PEGUINT wStyle = FF_RAISED | SS_CELL_SELECT | SS_PARTIAL_COL, PegThing * pOwner= NULL); virtual void Draw(void); virtual PEGINT Message(const PegMessage &Mesg); void SetCellFont(PegFont * pFont); void SetHeaderFont(PegFont * pFont); void SetColor(const UCHAR index, const COLORVAL Color); void SetCellData(const int iRow, const int iCol, const PEGCHAR * Text, BOOL bRedraw = FALSE); int GetSelectedCellRow() const; int GetSelectedCellCol() const; PEGCHAR * GetCellData(const int iRow, const int iCol) const; PEGCHAR * GetRowHeader(const int iRow) const; PEGCHAR * GetColHeader(const int iCol) const; void SetHeader(const int line, const int iCol, const PEGCHAR * Text); void SetRowHeader(const int iRow, const PEGCHAR * charVal); void SetFooter(const int line, const int iCol, const PEGCHAR * Text); void SetColumnStyle(const int iCol, const PEGUINT wFlags); PEGUINT GetColumnStyle(const int iCol); void SetRowStyle(const int iRow, const PEGUINT wFlags); PEGUINT GetRowStyle(const int iRow); void SetScrollStartCol(const int iCol); void ForceColWidth(int col, int iWidth); int GetOptimumWidth(void); int GetOptimumHeight(void); void Resize(PegRect Rect); int GetRows(void) const; int GetCols(void) const; void SetSize(const int iRows, const int iCols); int AddColumn(int iWidth, PEGCHAR * pHeader = NULL); int InsertColumn(int iColumn, int iWidth, PEGCHAR * pHeader); int DeleteColumn(int iColumn); int AddRow(PEGCHAR * pHeader = NULL); int InsertRow(int iRow, PEGCHAR * pHeader = NULL); int DeleteRow(int iRow); int GetDispRows(void); int GetDispCols(void); int GetSelectedColumn(int iIndex = 0); int GetSelectedRow(int iIndex = 0); void SelectRow(const int iRow, BOOL bSet = TRUE); void SelectColumn(const int iCol, BOOL bSet = TRUE); void SelectCell(int iRow, int iCol, BOOL bSet = TRUE); BOOL RowSelected(const int iRow); BOOL ColSelected(const int iCol); void UnselectAll(void); BOOL UnselectRows(void); BOOL UnselectColumns(void); BOOL UnselectCells(void); PegRect GetCellRect(const int iRow, const int iCol); BOOL RedrawOneCell(const int iRow, const int iCol); int UpdateRowLayout(BOOL bForceVertical = FALSE); int UpdateColLayout(void); void UpdateScrollBars(void); void DrawAllCells(void); void UnselectAllCells(void); void DrawRowHeaders (void); void DrawHeaders (void); void DrawFooters (void); }; Demo program Spread uses this class. Style FlagsSS_PARTIAL_COL, SS_MULTI_COL_SELECT, SS_MULTI_ROW_SELECT, SS_CELL_SELECT. SignalsPSF_COL_SELECT, PSF_ROW_SELECT, PSF_CELL_SELECT, PSF_COL_DESELECT, PSF_ROW_DESELECT. The message Point member has the selected/deselected cell column in x and row in y. ConstructorThe PegSpreadSheet constructor accepts a PegRect defining the spreadsheet position and size. The total number of spreadsheet rows is specified by iRows, and the total number of columns is specified in iCols. The spreadsheet must have a non-zero ID to send signals, and the ID can be specified in wId. wStyle indicates the global spreadsheet style, as each row and column style must be set individually. The pOwner parameter specifies which window, if any, should receive the spreadsheet selection signals. This is required since PegSpreadSheet is often added to PegPresentationManager, rather than to the owner window. Method AddColumnAdds a new column to the right of the spreadsheet after the spreadsheet has been defined and displayed. The iWidth parameter defines the new column width (column widths for the initial columns are calculated automatically based on column data). The pHeader parameter, if used, defines the new column header. Only single-row column headers are supported with this parameter. If your column headers use multiple rows, you should pass NULL to this function and then assign your column headers individually for the new column. Method AddRowAdds a new row at the end of the spreadsheet after the spreadsheet has been defined and displayed. This is not the same as defining the initial spreadsheet rows, normally done before the spreadsheet is displayed, because the new row's header width will not be factored into the left margin width for spreadsheet layout. Therefore, if you anticipate adding rows to a spreadsheet that will have wider row headers than the initially defined rows, you should pad the initial row headers to leave room for the dynamically added row headers. Method ColSelectedDetermines if a spreadsheet column is selected. Method DeleteColumnDeletes a column in the table. All data other than the deleted column is retained. This function returns the number of columns remaining in the table after the delete operation, or -1 on error. Method DeleteRowDeletes a row in the table. All data other than the deleted row is retained. This function returns the number of rows in the table after the delete operation, or -1 on error. Method ForceColWidthOverrides the default width assigned to a spreadsheet column. The default width is determined by finding the widest data string associated with a column of cells. This width is determined from cell data populated before the spreadsheet is displayed. The application may override this default width by calling the ForceColWidth function immediately before displaying the spreadsheet. Method GetCellDataRetrieves the data contained in a table cell. Method GetCellRectReturns the PegRect coordinates defining one cell's position. This rectangle may NOT be within the client area of the spreadsheet if the spreadsheet has been scrolled. Method GetColHeaderReturns the text string used for the indicated column header. Method GetColsReturns the number of columns in the spreadsheet. Method GetColumnStyleReturn the style flags associated with a particular spreadsheet column. Method GetDispColsReturns the number of table columns that are visible in the spreadsheet client area. Method GetDispRowsReturns the number of table rows that are visible in the spreadsheet client area. Method GetOptimumHeightReturns the best height for the spreadsheet after all cells have been initialized. This height will allow display of the entire spreadsheet without scrolling. Method GetOptimumWidthReturns the best width for the table after all cells have been initialized. This width will allow display of the entire table without scrolling. Method GetRowHeaderReturns the characters string used as the row header for the indicated row. Method GetRowsReturns the number of rows in the spreadsheet. Method GetRowsReturns the number of rows in the spreadsheet. Method GetRowStyleReturns the style flags associated with each row in the spreadsheet. Method GetSelectedColumnInquires which column(s), if any, are selected. If the SS_MULTI_COL_SELECT style is not enable, there can only be at most one selected column. If multiple-selection mode is enabled, however, there may be any number of selected columns. In this case, the caller uses the index value to step through the select columns and retrieve all selected column numbers. Method GetSelectedRowinquires which rows(s), if any, are selected. If the SS_MULTI_ROW_SELECT style is not enable, there can only be at most one selected row. If multiple-selection mode is enabled, however, there may be any number of selected rows. In this case, the caller uses the index value to step through the select rows and retrieve all selected row numbers. Method InsertColumnAdds a new column to the spreadsheet, to the left of the column specified by iCol. The initial column width will be iWidth. The column header may be assigned by passing pHeader or by passing NULL and using the normal SetColumnHeader functions after the column has been inserted. The return value is -1 for error or the number of columns in the spreadsheet after insertion. Method InsertRowSimilar to InsertColumn (above), the functions inserts a new row in the spreadsheet immediately above the indicated row. The return value is -1 for error or the number of rows in the spreadsheet after insertion. Method ResizePegSpreadSheet overrides the Resize function to update the client area spreadsheet scrollbars. Method RowSelectedReturns TRUE if the indicated row of cells is selected, else FALSE. Method SelectCellSelects or deselects cells independent of user interaction. Method SelectColumnSelects or deselects spreadsheet columns independent of user interaction. Method SelectRowSelects or deselects spreadsheet rows independent of user interaction. Method SetCellDataPopulates individual spreadsheet cells with program defined data values. If the bRedraw parameter is TRUE and the SpreadSheet is visible, the cell will immediately redraw itself to display the new data. Method SetCellFontSelects the font used to display cell data. There is only one font used to display all cells. Method SetColorPegSpreadSheet overrides the SetColor function to provide additional color indices. These indices include: PCI_NORMALNormal (not selected) cell fill color. PCI_SELECTEDSelected cell fill color. PCI_NTEXTNormal (not selected) cell text color. PCI_STEXTSelected cell text color. PCI_SS_COLHEADBACKColumn header background color. PCI_SS_COLHEADTEXTColumn header text color. PCI_SS_ROWHEADBACKRow header background color. PCI_SS_ROWHEADTEXTRow header text color. PCI_SS_DIVIDERSpreadSheet divider color. PCI_SS_BACKGROUNDSpreadSheet background color. Method SetColumnStyleSetColumnStyle is used to set the style flags associated with a particular spreadsheet column. The default column style is TJ_CENTER | FF_RECESSED | SCF_CELL_SELECT. Method SetFooterSetFooter is used to define the column footers. Columns footers are displayed directly below each column of spreadsheet data. Column footers are optional, and are only displayed if defined. Method SetHeaderSetHeader is used to define the spreadsheet column headers. Columns headers are displayed directly above each column in the spreadsheet. The number of rows of header data is determined automatically by the spreadsheet based on the number of header rows initialized by the calling object. That is, you do not need to explicitly indicate how many rows of column header data are required, you simply initialize the column headers as needed and PegSpreadSheet determines how to display the header information. The width of the column headers are also included when determining the width of each table column. Columns headers are not required, and will not be displayed if not initialized. Column headers must be defined for the spreadsheet to support column selection. Method SetHeaderFontDefines the font used to display column headers. Method SetRowHeaderInitializes the row headers. Rows headers are displayed to the left of each spreadsheet row. Row headers are not required, and will not be displayed if they are not initialized. Row headers must be defined for the spreadsheet to support row selection. Row headers are not scrolled when the spreadsheet performs a horizontal scrolling operation. Method SetRowStyleSets the style flags associated with each row in the spreadsheet. The only row style currently supported is the SRF_ALLOW_SELECT style, which allows the user to select the row header to select all cells in the row. The default row style is 0. Method SetScrollStartColDetermines which columns are scrolled right and left by the horizontal scroll bar. Columns to the left of this value are not scrolled, and columns to the right are. This allow you to "lock" certain columns in the display, while others are scrolled. Method UnselectAllUnselects all rows, columns, and cells. Method UnselectCellsUnselects cells. It returns TRUE if a selected cell was found, else FALSE. Method UnselectColumnsUnselects all columns. It returns TRUE if a selected column was found, else FALSE. Method UnselectRowsThis function unselects all rows. It returns TRUE if a selected row was found, else FALSE. Method UpdateColLayoutForces the spreadsheet to recalculate the visible/non-visible column parameters and scroll bar settings. This function should be called if the SS_PARTIAL_COL style flag is changed after the spreadsheet is visible. Method UpdateRowLayoutForces the spreadsheet to recalculate the visible/non-visible row parameters and scroll bar settings. This function should be called if the number of column header rows, cell or header font, or any other variable that affects the number of visible rows is changed after the spreadsheet is visible. ExamplesThe following is an example of a PegSpreadSheet, centered in the client area of a PegDecoratedWindow: A complete example using PegSpreadSheet (the example used to create the screen shot above) can be found in demo program Spread.
|