KwikPeg Manuals
Home
PegSpreadSheet
Examples
Examples
Index
Index


Members
Styles
Signals
Overview Derived from class PegWindow

The PegSpreadSheet class provides a window for displaying a conventional spreadsheet, a matrix of rows and columns containing text, often alphanumeric data. The PegSpreadSheet class offers a much higher level class than the basic KwikPeg window and control classes. Consequently, there are a large number of member functions which control the spreadsheet appearance and operation.

The PegSpreadSheet class allows the selection of individual cells or entire rows or columns. Multiple rows or multiple columns can also be selected. The spreadsheet may have row headings, column headings and column footers. Headings are referred to as headers.

The PegSpreadSheet class supports automatic horizontal and vertical scrolling if the entire spreadsheet cannot be displayed within its client area. Specific columns may be specified as anchored (fixed) so that they do not move when other portions of the spreadsheet are scrolled. If the spreadsheet window is resized such that the scroll bars are no longer required, they are automatically removed.

The width of a spreadsheet column is automatically adjusted to adapt to the widths of the objects contained in its cells. The justification of text within the cells of a column can be uniquely specified for each column.

Spreadsheet cells may be configured to be selectable individually, in complete rows or in complete columns. When an individual cell is selected by the user, a PSF_CELL_SELECT signal is sent to the spreadsheet's parent window, provided that such notification has been enabled. The message pSource pointer will reference the PegSpreadSheet object and the message Point field will identify the row and column of the selected cell.

When a complete spreadsheet column is selected, the spreadsheet sends a PSF_COL_SELECT signal to its parent window. The message iData and lData members define the first and last (inclusive) selected columns respectively. Both values will match if only one column is selected.

When a complete spreadsheet row is selected, the spreadsheet sends a PSF_ROW_SELECT signal to its parent window. The message iData and lData members define the first and last (inclusive) selected rows respectively. Both values will match if only one row is selected.

Each column of the spreadsheet has its own set of style flags which control the appearance of each cell in the column. Each cell can be drawn with a flat, raised or recessed appearance. The column style flags are modified using the spreadsheet's SetColStyle() member function.

Each row of the spreadsheet has its own set of style flags which control the row attributes of each cell in the row. To avoid conflicts with column style flags, the row style flags do not affect the appearance of the cells in the row. The row style flags are modified using the spreadsheet's SetRowStyle() member function.

The PegSpreadSheet class is only supported if your KwikPeg configuration has the following option enabled:
  Drawing: Enable spreadsheets



 See Also

PegTable



 Styles

The PegSpreadSheet class supports the following style flags:

FF_NONE No frame.
FF_THIN Thin frame.
FF_THICK Thick 3D frame.
FF_RAISED Raised 3D frame.
FF_RECESSED Recessed 3D frame.
SS_CELL_SELECT  Enable selection of cells in a PegSpreadSheet object.
SS_PARTIAL_COL  Draw the rightmost visible column of a PegSpreadSheet object, even if it must be partially clipped.
SS_MULTI_COL_SELECT  Allow simultaneous selection of multiple columns of a PegSpreadSheet object.
SS_MULTI_ROW_SELECT  Allow simultaneous selection of multiple rows of a PegSpreadSheet object.

 
The following column style flags are supported. These styles, when applied to a spreadsheet column, also apply to the content of all cells within the column. The default column style is TJ_CENTER|FF_RECESSED|SCF_CELL_SELECT.

FF_THIN Thin frame.
FF_RAISED Raised 3D frame.
FF_RECESSED Recessed 3D frame.
TJ_RIGHT Right justify text.
TJ_LEFT Left justify text.
TJ_CENTER Center text.
SCF_ALLOW_SELECT  Allows selection of all cells in a column of a PegSpreadSheet object by selecting the column header.
SCF_SELECTED  This style flag is actually a state flag which indicates if the column of a PegSpreadSheet object is currently selected.
SCF_SEPARATOR  This style flag is used to indicate that the column of a PegSpreadSheet object is acting as a column separator. Cell data for the column will not be displayed.
SCF_CELL_SELECT  Allows selection of individual cells within a column of a PegSpreadSheet object. For this flag to have an effect, style flag SS_CELL_SELECT must also be set to enable spreadsheet cell selection.

 
The following row style flags are supported. These styles apply only to the row, not to the cells within the row. The default row style is 0.

SRF_ALLOW_SELECT  Allows selection of all cells in a row of a PegSpreadSheet object by selecting the row header.
SRF_SELECTED  This style flag is actually a state flag which indicates if the row of a PegSpreadSheet object is currently selected.


 Signals

The PegSpreadSheet class generates the following signals:

PSF_COL_SELECT Sent when PegSpreadSheet column(s) are selected.
PSF_COL_DESELECT Sent when a PegSpreadSheet column is deselected.
PSF_ROW_SELECT Sent when PegSpreadSheet row(s) are selected.
PSF_ROW_DESELECT Sent when a PegSpreadSheet row is deselected.
PSF_CELL_SELECT Sent when PegSpreadSheet cell(s) are selected.

Top of page


 Members

Constructors:

PegSpreadSheet(const PegRect &Rect,
  SIGNED iRows, SIGNED iCols,
  WORD wId = 0,
  WORD wStyle =
    FF_RAISED|SS_CELL_SELECT|SS_PARTIAL_COL,
  PegThing *pOwner = NULL)

This constructor creates a PegSpreadSheet object at a specific location within a rectangle specified by parameter Rect. The window frame style and spreadsheet attributes must be defined. The spreadsheet will have iRows rows and iCols columns.

Note:
Spreadsheet rows are numbered from 0 to iRows-1.
Spreadsheet columns are numbered from 0 to iCols-1.

If the spreadsheet object ID specified by wId is non-zero, the spreadsheet will send selection signals when rows, columns or cells are selected.

Parameter Owner identifies the KwikPeg object (window or control) to which the spreadsheet is to send selection signals when spreadsheet cells, rows or columns are selected. If Owner is NULL, the selection signals will be sent to the spreadsheet's parent. When the spreadsheet is added directly to the KwikPeg Presentation Manager's PegPresentationManager window, you can use this ownership feature to force spreadsheet signals to be redirected to an application window for servicing.

 

Public Functions:

SIGNED AddColumn(SIGNED iWidth,
  PEGCHAR *pHeader = NULL)

This function adds a new column to the spreadsheet once the spreadsheet has been created and displayed. The function returns the number of columns in the spreadsheet after the column has been inserted or -1 on error.

The column is added to the right of all existing columns. The iWidth parameter defines the initial width of the new column. Note that the column widths for the initial columns are calculated automatically according to the column cell contents.

The pHeader parameter, if provided, defines a header to be applied to the new column. The column header text is restricted to a single line. If a multiline column header is required, leave the column heading undefined (NULL) and use member function SetHeader() to assign the multiline column header.

SIGNED AddRow(PEGCHAR *pHeader = NULL)

This function adds a new row to the spreadsheet once the spreadsheet has been created and displayed. The function returns the number of rows in the spreadsheet after the row has been inserted or -1 on error.

The row is added below all existing rows. The height of the row will be calculated as cell data is inserted into the cells of the row.

The pHeader parameter, if provided, defines a header to be applied to the new row. A row header is restricted to a single line. The width of the spreadsheet's row heading margin is defined by the widest row heading added before the spreadsheet was first displayed. This margin will not be expanded to accommodate the new row heading. Therefore, if you anticipate adding rows with row headers wider than than those initially defined, you should pad the initial row headers to provide space for the row headers of the dynamically added rows.

BOOL CellSelected(
  const SIGNED iRow, const SIGNED iCol)

This function can be called at any time to determine if the specified spreadsheet cell is currently selected. The function returns TRUE if the indicated cell is selected, else FALSE.

BOOL ColSelected(const SIGNED iCol)

This function can be called at any time to determine if the specified spreadsheet column is currently selected. The function returns TRUE if the indicated column of cells is selected, else FALSE.

SIGNED DeleteColumn(SIGNED iCol)

This function deletes column iCol from the spreadsheet. All data other than that in the deleted column is retained, unaltered. This function returns the number of columns remaining in the spreadsheet after the column has been deleted or -1 on error.

SIGNED DeleteRow(SIGNED iRow)

This function deletes row iRow from the spreadsheet. All data other than that in the deleted row is retained, unaltered. This function returns the number of rows remaining in the spreadsheet after the row has been deleted or -1 on error.

void DrawAllCells(void)

This function draws all visible cells in the spreadsheet.

void void DrawFooters(void)

This function draws all visible footers in the spreadsheet.

void DrawHeaders(void)

This function draws all visible headers in the spreadsheet.

void DrawRowHeaders(void)

This function draws all visible row headers in the spreadsheet.

void ForceColWidth(
  SIGNED iCol, SIGNED iWidth)

This function unconditionally sets the width of column iCol to iWidth pixels. By default, the column width is determined by the widest text string assigned to a cell in the column before the spreadsheet is displayed. You can override the default column width by calling this function immediately prior to displaying the spreadsheet.

PEGCHAR *GetCellData(
  const SIGNED iRow, const SIGNED iCol) const

This function returns a pointer to the text string contained in the indicated spreadsheet cell. The function returns NULL if the indicated cell has no assigned text string or if the cell coordinates are invalid.

PegRect GetCellRect(
  const SIGNED iRow, const SIGNED iCol)

This function returns the PegRect rectangle with coordinates defining the location of the indicated cell. The specified rectangle may NOT be within the client area of the spreadsheet if the spreadsheet has been scrolled. The function returns NULL if the cell coordinates are invalid.

PEGCHAR *GetColHeader(const SIGNED iCol) const

This function returns a pointer to the the column header text string for column iCol. The function returns NULL if the indicated column has no column header or if the column number is invalid.

SIGNED GetCols(void) const { return miCols; }

This inline function returns the number of columns in the spreadsheet.

WORD GetColumnStyle(const SIGNED iCol)

This function returns the column style flags assigned to column iCol. The function returns 0 if the column number is invalid.

SIGNED GetDispCols(void) {return miVisibleCols;}

This inline function returns the number of spreadsheet columns that are actually visible in the spreadsheet client area.

SIGNED GetDispRows(void) {return miVisibleRows;}

This inline function returns the number of spreadsheet rows that are actually visible in the spreadsheet client area.

SIGNED GetOptimumHeight(void)

This function returns the best height (in pixels) for the spreadsheet after all cells have been initialized. This height allows display of the entire spreadsheet without vertical scrolling.

SIGNED GetOptimumWidth(void)

This function returns the best width (in pixels) for the spreadsheet after all cells have been initialized. This width will allow display of the entire spreadsheet without horizontal scrolling.

PEGCHAR *GetRowHeader(const SIGNED iRow) const

This function returns a pointer to the the row header text string for row iRow. The function returns NULL if the indicated row has no column header or if the row number is invalid.

SIGNED GetRows(void) const { return miRows; }

This inline function returns the number of rows in the spreadsheet.

WORD GetRowStyle(const SIGNED iRow)

This function returns the row style flags assigned to row iRow. The function returns 0 if the row number is invalid.

SIGNED GetSelectedColumn(SIGNED iIndex = 0)

This function returns the column number of a selected column, if any. If iIndex is 0, the function returns the first (lowest numbered) selected column. If iIndex is then incremented and the function called again, the function will return the next selected column. If no column is selected, this function returns -1.

Multiple columns can only be selected if the spreadsheet's SS_MULTI_COL_SELECT style flag is set.

SIGNED GetSelectedRow(SIGNED iIndex = 0)

This function returns the row number of a selected row, if any. If iIndex is 0, the function returns the first (lowest numbered) selected row. If iIndex is then incremented and the function called again, the function will return the next selected row. If no row is selected, this function returns -1.

Multiple rows can only be selected if the spreadsheet's SS_MULTI_ROW_SELECT style flag is set.

SIGNED InsertColumn(
  SIGNED iCol, SIGNED iWidth,
  PEGCHAR *pHeader)

This function inserts a new column into the spreadsheet once the spreadsheet has been created and displayed. The function returns the number of columns in the spreadsheet after the column has been inserted or -1 on error.

The column is inserted to the left of column iCol. The iWidth parameter defines the initial width of the new column. Note that the column widths for the initial columns are calculated automatically according to the column cell contents.

The pHeader parameter, if provided, defines a header to be applied to the new column. The column header text is restricted to a single line. If a multiline column header is required, leave the column heading undefined (NULL) and use member function SetHeader() to assign the multiline column header.

SIGNED InsertRow(SIGNED iRow,
  PEGCHAR *pHeader = NULL)

This function inserts a new row into the spreadsheet once the spreadsheet has been created and displayed. The function returns the number of rows in the spreadsheet after the row has been inserted or -1 on error.

The row is inserted above row iRow. The height of the row will be calculated as cell data is inserted into the cells of the row.

The pHeader parameter, if provided, defines a header to be applied to the new row. A row header is restricted to a single line. The width of the spreadsheet's row heading margin is defined by the widest row heading added before the spreadsheet was first displayed. This margin will not be expanded to accommodate the new row heading. Therefore, if you anticipate adding rows with row headers wider than than those initially defined, you should pad the initial row headers to provide space for the row headers of the dynamically added rows.

void RedrawOneCell(
  const SIGNED iRow, const SIGNED iCol)

This function invalidates and draws an individual cell.

void Resize(PegRect Rect)

The PegSpreadSheet class overrides the Resize() function to update the client area spreadsheet scroll bars.

BOOL RowSelected(const SIGNED iRow)

This function can be called at any time to determine if the specified spreadsheet column is currently selected. The function returns TRUE if the indicated row of cells is selected, else FALSE.

void SelectCell(
  SIGNED iRow, SIGNED iCol,
  BOOL bSet = TRUE)

This function changes the selection status of the indicated cell. The cell is marked as selected if parameter bSet is TRUE. Otherwise, the cell is marked as unselected.

void SelectColumn(const SIGNED iCol,
  BOOL bSet = TRUE)

This function marks column iCol as a selected column if parameter bSet is TRUE. All currently selected rows or individually selected cells are first marked as unselected. If multicolumn selection is enabled (style flag SS_MULTI_COL_SELECT is set), other currently selected columns remain selected.

If parameter bSet is FALSE, column iCol is marked as unselected.

In either case, if the spreadsheet's object ID is non-zero and a spreadsheet owner has been assigned, a column selection signal is sent to the owner.

void SelectRow(const SIGNED iRow,
  BOOL bSet = TRUE)

This function marks row iRow as a selected row if parameter bSet is TRUE. All currently selected columns or individually selected cellss are first marked as unselected. If multirow selection is enabled (style flag SS_MULTI_ROW_SELECT is set), other currently selected rows remain selected.

If parameter bSet is FALSE, row iRow is marked as unselected.

In either case, if the spreadsheet's object ID is non-zero and a spreadsheet owner has been assigned, a row selection signal is sent to the owner.

void SetCellData(
  const SIGNED iRow, const SIGNED iCol,
  const PEGCHAR *Text,
  BOOL bRedraw = FALSE)

This function is used to populate the cells of a spreadsheet with text strings. The text string referenced by parameter Text is assigned to the cell at row iRow, column iCol.

If parameter bRedraw is TRUE and the PegSpreadSheet object is visible, the cell will be redrawn immediately to display the updated cell content.

void SetCellFont(PegFont *pFont)

This function specifies the font to be used to display the text strings in all cells in all columns. Calling this function is equivalent to calling SetColumnFont once for each column in the spreadsheet.

void SetColor(const UCHAR index,
  const COLORVAL Color)

The PegSpreadSheet class overrides the SetColor() function to provide additional color indices for spreadsheet use. The following color indices are supported:

PCI_NORMAL Set the client area fill color for normal display.
PCI_SELECTED Set the client area fill color to be used if the object is selected.
PCI_NTEXT Set the text color for normal display.
PCI_STEXT Set the text color to be used if the object is selected.
PCI_SS_COLHEADBACK Set the column header background color.
PCI_SS_COLHEADTEXT Set the column header text color.
PCI_SS_ROWHEADBACK Set the row header background color.
PCI_SS_ROWHEADTEXT Set the row header text color.
PCI_SS_DIVIDER Set the spreadsheet divider color.
PCI_SS_BACKGROUND Set the spreadsheet background color.


void SetColumnFont(const SIGNED iCol,
  PegFont *pFont)

This function specifies the font to be used to display the text strings in all cells of column iCol.

void SetColumnStyle(const SIGNED iCol,
  const WORD wFlags)

This function sets the column style flags for column iCol to wFlags.

The following column style flags are supported:

FF_THIN Thin frame.
FF_RAISED Raised 3D frame.
FF_RECESSED Recessed 3D frame.
TJ_RIGHT Right justify text.
TJ_LEFT Left justify text.
TJ_CENTER Center text.
SCF_ALLOW_SELECT  Allows selection of all cells in a column of a PegSpreadSheet object by selecting the column header.
SCF_SELECTED  This style flag is actually a state flag which indicates if the column of a PegSpreadSheet object is currently selected.
SCF_SEPARATOR  This style flag is used to indicate that the column of a PegSpreadSheet object is acting as a column separator. Cell data for the column will not be displayed.
SCF_CELL_SELECT  Allows selection of individual cells within a column of a PegSpreadSheet object. For this flag to have an effect, style flag SS_CELL_SELECT must also be set to enable spreadsheet cell selection.


void SetFooter(const SIGNED iLine,
  const SIGNED iCol, const PEGCHAR *Text)

This function sets line iLine of the column footer for column iCol to the text string referenced by parameter Text. Column footers are displayed below the bottom cell of the column. Column footers are optional and are only displayed if installed using this function.

The number of footer text lines present across all columns in the spreadsheet will be determined automatically by KwikPeg as footer lines are installed by your application using this function. The width of each column footer is included in the determination of the spreadsheet column width.

The maximum number of text lines allowed in a column header or footer is specified in your KwikPeg configuration by the following parameter:
  Drawing: Heading lines

void SetHeader(const SIGNED iLine,
  const SIGNED iCol, const PEGCHAR *Text)

This function sets line iLine of the column header for column iCol to the text string referenced by parameter Text. Column headers are displayed above the top cell of the column. Column headers are optional and are only displayed if installed using this function.

The number of header text lines present across all columns in the spreadsheet will be determined automatically by KwikPeg as header lines are installed by your application using this function. The width of each column header is included in the determination of the spreadsheet column width.

Column headers must be defined for the spreadsheet to support column selection.

The maximum number of text lines allowed in a column header or footer is specified in your KwikPeg configuration by the following parameter:
  Drawing: Heading lines

void SetHeaderFont(PegFont *pFont)

This function specifies the font to be used to display all row header, column header and column footer text strings. One font applies to all headers and footers.

void SetRowHeader(const SIGNED iRow,
  const PEGCHAR *Text)

This function sets the row header for row iRow to the text string referenced by parameter Text. A row header is restricted to a single line. Row headers are displayed in the left margin of the spreadsheet. Row headers are optional and are only displayed if installed using this function.

Row headers must be defined for the spreadsheet to support row selection.

Row headers are anchored so that they do not scroll horizontally when spreadsheet cells are scrolled horizontally.

void SetRowStyle(const SIGNED iRow,
  const WORD wFlags)

This function sets the row style flags for row iRow to wFlags.

The following row style flags are supported:

SRF_ALLOW_SELECT  Allows selection of all cells in a row of a PegSpreadSheet object by selecting the row header.
SRF_SELECTED  This style flag is actually a state flag which indicates if the row of a PegSpreadSheet object is currently selected.


void SetScrollStartCol(const SIGNED iCol)

This function identifies the columns to be scrolled right and left by the horizontal scroll bar. Columns to the left of column iCol are not scrolled. Column iCol and columns to its right are scrolled. You can use this function to anchor some columns in the display, while allowing other columns to scroll.

void SetSize(
  const SIGNED Rows, const SIGNED Cols)

This function sets the size of the spreadsheet to handle the specified number of rows and columns.

void UnselectAll(void)

This function marks all rows, columns and cells as not selected.

BOOL UnselectCells(void)

This function marks all cells as not selected. Rows and columns, if selected, remain selected. This function returns TRUE if any selected cell was found, else FALSE.

BOOL UnselectColumns(void)

This function marks all columns as not selected. Rows or individual cells, if selected, remain selected. This function returns TRUE if any selected column was found, else FALSE.

BOOL UnselectRows(void)

This function marks all rows as not selected. Columns or individual cells, if selected, remain selected. This function returns TRUE if any selected row was found, else FALSE.

SIGNED UpdateColLayout(void)

This function forces the spreadsheet to recalculate its column visibility parameters and scroll bar settings. This function should be called if the SS_PARTIAL_COL style flag is changed after the spreadsheet becomes visible.

For the benefit of private spreadsheet member functions, this function returns the pixel position of the leftmost edge of the horizontally scrollable region of the spreadsheet.

SIGNED UpdateRowLayout(
  BOOL bForceVertical = FALSE)

This function forces the spreadsheet to recalculate its row visibility parameters and scroll bar settings. This function should be called if any change to the spreadsheet content affecting the number of visible rows is made after the spreadsheet becomes visible. Changes to cell content or header font or the addition of new column header or footer lines can all affect row visibility.

For the benefit of private spreadsheet member functions, this function returns the pixel position of the topmost edge of the visible column region of the spreadsheet.

If parameter bForceVertical is TRUE, a vertical scroll bar will unconditionally be added to the spreadsheet. If bForceVertical is FALSE or omitted, a vertical scroll bar will only be added when needed.

SIGNED UpdateScrollBars(void)

This function forces the spreadsheet to recalculate the size and position of the scrollbars.

void VScrollIntoView(const SIGNED iRow)

This function scrolls the spreadsheet vertically as needed to make row iRow visible within the spreadsheet client area. If the row is near the top (bottom) of the spreadsheet, the spreadsheet will be positioned so that the first (last) row of the spreadsheet is at the top (bottom) of the client area. Otherwise, the spreadsheet will be positioned so that the row of interest is centered vertically in the client area.


Top of page


 Examples

The following example illustrates a PegSpreadSheet object centered in the client area of a PegDecoratedWindow object. The source code for a similar example is provided in the KPGnnn\EXAMPLES\SPREAD installation directory.




Top of page
KwikPeg Manuals
Home
Index
Index

 
Copyright © 2000-2003