[Classes] [Prev] [Next] [Methods]

CTable

Methods Index

Heritage
Description
Usage
Enums
Protected Data Members
Public Methods
Constructor, Destructor and Initializer Methods
Overridden CView Methods
Table Methods
Insert/Delete Methods
Selection Methods
Row Methods
Column Methods
Cell Methods
Focus Methods
Event Control Methods
Internal Component Access Methods
Data Connection Methods
Helper Methods for Labels.
Protected Methods
Component Factory Methods
Cancelled Methods

CTable


Heritage

Superclass: CSubview

Subclass: None


Description

CTable combines a table, row labels, column labels, and scrollbars into a complete table view. The DoKey method and an installed mouse handler support user interaction. Most of the CTable methods are delegated to one or more component classes: CTableAttributes, CTableCoordinates (internal), and CTableView.


Usage

// Creating and initializing a table
CTable aTable = new CTable(anEnclosure, aBounds);
aTable->ITable(
CTable::MultipleCell,
TRUE, // H scroll
TRUE, // V scroll
TRUE, // Column labels
TRUE, // Row labels
FALSE, // Thumb tracking
TRUE, // Visible
ALLSTICKY);

// Setting row labels
aTable->SetRow(0, "R01");
aTable->SetRow(1, "R02");
aTable->SetRow(2, "R03");

// Setting column labels
aTable->SetColumn(0, "N Number");
aTable->SetColumn(1, "Make");
aTable->SetColumn(2, "Model");

// Setting some attributes on a diagonal line of cells
for( i = 0; i < 100; i += 1 )
{
CTableAttributes anAttribute;
anAttribute.Foreground(COLOR_GREEN);
anAttribute.Background(COLOR_RED);
anAttribute.ReadOnly(TRUE);
aTable->SetCell(CCell(i, i), anAttribute);
}

// Setting some attributes on every other column
for( i = 0; i < 100; i += 2 )
{
CTableAttributes anAttribute;
anAttribute.Foreground(COLOR_MAGENTA);
anAttribute.Background(COLOR_CYAN);
aTable->SetColumn(i, anAttribute);
}
The next example sets a special data source callback class. This example is a string table source where cells initially contain the coordinates of the cell as a string. The example is based on a CChunkArray to store the string values. Notice the use of multiple inheritance to add the interface of a table source. We also override the BuildChunk factory method of CChunkArray to use our own chunks (CSourceChunk) which take care of deleting the stored CStringRWs.

class CSourceChunk : public CChunk
{
public:
CSourceChunk(const CBounds& theBounds, size_t theCellSize) :
CChunk(theBounds, theCellSize) { }

virtual ~CSourceChunk()
{
for( long i = itsBounds.Width() * itsBounds.Height() - 1;
i >= 0;
i-- )
delete ((CStringRW**)itsData)[i];
}
};

class MyTableSource : private CChunkArray, public CTableSource
{
public:
MyTableSource() : CChunkArray(sizeof(CStringRW*)) { }
virtual ~MyTableSource() { }
virtual void Prime(const CBounds& theCell) { }
virtual CTdiValue* Get(const CCell& theCell)
{
CStringRW* aString;
CChunkArray::Get(theCell, &aString);

if( aString == NULL )
{
static CStringRW aCellString;
char s[64];

sprintf(s, "(%d, %d)", theCell.H(), theCell.V());
aCellString = s;
aString = &aCellString;
}

return aString;
}

virtual BOOLEAN Put(const CCell& theCell, CTdiValue* theData)
{
CStringRW* aString = new CStringRW(*(CStringRW*)theData);
CChunkArray::Set(theCell, &aString);
return TRUE;
}

virtual CChunk* BuildChunk(const CBounds& theChunkBounds) const
{
CChunk* aChunk = new CSourceChunk(theChunkBounds, itsCellSize);
if( itsSourceCallback != NULL )
itsSourceCallback->Populate(aChunk);
return aChunk;
}
}

MyTableSource aSource;
aTable->SetSource(&aSource);

Enums

SelectionPolicy

None No selection allowed
SingleRow Zero or one row may be selected
MandatoryRow After an initial selection, always one
MultipleRow Multiple selected rows allowed
SingleColumn Zero or one row may be selected
MandatoryColumn After an initial selection, always one
MultipleColumn Multiple selected columns allowed
SingleCell Zero or one cell may be selected
MandatoryCell After an initial selection, always one
MultipleCell An arbitrary block of cells may be selected

Selection policy controls the behavior exhibited as the user (or program) selects various cells, rows or columns in the CTable.

EventStyle

EventNone Neither ask permission nor notify after acting
EventPermission Always ask permission before acting
EventNotify Notify after acting
EventBoth Ask permission & notify after acting

Event style controls whether various CTable operations send a TableEventCmd and CTableEvent object up the DoCommand call chain before acting (asking permission), and after acting (notifying). See the enum CTableEvent::Type for more information.


Protected Data Members

SelectionPolicy itsSelectionPolicy; Use selectability
EventStyle itsEventStyle; Control over event (command) use
CFont itsTableFont; For second phase initialization
UNITS itsDefaultRowHeight; Retained from constructor
UNITS itsDefaultColumnWidth; Retained from constructor
long itsChunkRows; Retained from constructor
long itsChunkColumns; Retained from constructor
BOOLEAN itUsesWinScrollBars; Are the scrollbars window attached?
BOOLEAN itIsThumbtracking; Is thumbtracking activated?
NScrollBar* itsHScrollBar;
NScrollBar* itsVScrollBar;
CRowLabels* itsRowLabels; Slave tables for title column
CColumnLabels* itsColumnLabels; Slave tables for title row
CTableView* itsTable;
CMouseHandler* itsTableMouseHandler;


Public Methods

Constructor, Destructor and Initializer Methods

CTable(
CSubview* theEnclosure,
const CRect& theRegion,
const CFont& theTableFont = STDFont,
UNITS theDefaultRowHeight = kNoHeight,
UNITS theDefaultColumnWidth = kNoWidth,
long theChunkRows = 128,
long theChunkColumns = 32);
virtual ~CTable();
BOOLEAN ITable(
SelectionPolicy theSelectionPolicy = MultipleRow,
BOOLEAN hasHorizontalScrollBar = TRUE,
BOOLEAN hasVerticalScrollBar = TRUE,
BOOLEAN hasColumnLabels = TRUE,
BOOLEAN hasRowLabels = TRUE,
BOOLEAN isThumbTracking = FALSE,
BOOLEAN isVisible = TRUE,
GLUETYPE theGlue = NULLSTICKY);

Overridden CView Methods

virtual void VScroll(SCROLL_CONTROL theEventType, 
UNITS thePos);
virtual void HScroll(SCROLL_CONTROL theEventType, 
UNITS thePos);
virtual void DoKey(const CKey& theKey);
virtual void DoCommand(long theCommand, 
void* theData = NULL);

Table Methods

virtual void SetTable(
CTableAttributes& theAttributes,
BOOLEAN thePropagate = FALSE );
virtual const CTableAttributes* GetTableAttributes() const;
virtual void SetCellOrigin(const CCell& theCell);
virtual CCell GetCellOrigin() const;
virtual void SetCellBounds(const CBounds& theBounds);
virtual CBounds GetCellBounds() const;

Note on Cell Bounds

virtual CRect GetLocalInterior() const;
virtual void SetThumbTracking(BOOLEAN isThumbTracking);
virtual void MakeRowVisible(long theRow);
virtual void MakeColumnVisible(long theColumn);
virtual void MakeCellVisible(const CCell& theCell);

Insert/Delete Methods

virtual void InsertColumns(
long theColumn,
long theCount = 1);
virtual void DeleteColumns(
long theColumn,
long theCount = 1);
virtual void InsertRows(
long theRow,
long theCount = 1);
virtual void DeleteRows(
long theRow,
long theCount = 1);

Selection Methods

Note on Selection Methods

virtual void SetSelectionPolicy(
SelectionPolicy theSelectionPolicy);
virtual SelectionPolicy GetSelectionPolicy() const;
virtual void SelectCells(
const CBounds& theBounds,
BOOLEAN isSelected = TRUE);
virtual void SelectRow(
long theRow,
BOOLEAN isSelected = TRUE);
virtual void SelectColumn(
long theColumn, BOOLEAN isSelected = TRUE);
virtual void SelectCell(const CCell& theCell, 
BOOLEAN isSelected = TRUE);
virtual void SetSelectedRegion(
const CRegion& theRegion);
virtual const CRegion& GetSelectedRegion() const;
virtual void DeselectAll();
virtual BOOLEAN IsRowSelected(long theRow) const;
virtual BOOLEAN IsColumnSelected(long theColumn) const;
virtual BOOLEAN IsCellSelected(const CCell& theCell) const;
virtual CRect ToScreen(const CBounds& theCells) const;
virtual CPoint ToScreen(const CCell& theCell) const;
virtual CBounds ToCell(CRect thePoints) const;
virtual CCell ToCell(CPoint thePoint) const;
virtual void SetDefaultRowHeight(UNITS theHeight);
virtual void SetDefaultColumnWidth(UNITS theWidth);
virtual UNITS GetDefaultRowHeight() const;
virtual UNITS GetDefaultColumnWidth() const;

Row Methods

Note: Use TITLE_ROW to access the row of column titles.

virtual void SetRow(long theRow, UNITS theHeight);
virtual void SetRow(
long theRow,
CTableAttributes& theAttributes,
BOOLEAN thePropagate = FALSE);
virtual void SetRow(
long theRow,
const CStringRW& theTitle);
virtual const CTableAttributes* GetRowAttributes(
long theRow ) const;

Column Methods

Note: Use TITLE_COLUMN to access the column of row titles.

virtual void SetColumn(
long theColumn,
UNITS theWidth);
virtual void SetColumn(
long theColumn,
CTableAttributes& theAttributes,
BOOLEAN thePropagate = FALSE);
virtual void SetColumn(
long theColumn,
const CStringRW& theTitle);
virtual const CTableAttributes* GetColumnAttributes(
long theColumn) const;

Cell Methods

virtual void SetCell(
const CCell& theCell,
CTableAttributes& theAttributes);
virtual const CTableAttributes* GetCellAttributes(
const CCell& theCell) const;

Focus Methods

virtual void SetFocus(const CCell* theCell);
virtual const CCell* GetFocus() const;
virtual BOOLEAN ClassCanGetKeyFocus() const;

Event Control Methods

virtual void SetEventStyle(EventStyle theStyle);
virtual EventStyle GetEventStyle() const;

Internal Component Access Methods

CTableView* GetRowLabels();
const CTableView* GetRowLabels() const;
CTableView* GetColumnLabels();
const CTableView* GetColumnLabels() const;
CTableView* GetTableView();
const CTableView* GetTableView() const;

Data Connection Methods

void SetSource(CTableSource* theSource);
CTableSource* GetSource();
const CTableSource* GetSource() const;

Helper Methods for Labels.

Note: These methods must be public since they are returned in factory methods of CTable.

virtual UNITS LabelWidth(const CFont& theFont);
virtual UNITS LabelHeight(const CFont& theFont);

Protected Methods

Component Factory Methods

virtual CMouseHandler* CreateMouseHandler();
virtual CRowLabels* CreateRowLabels(
BOOLEAN hasOtherBar);
virtual CColumnLabels* CreateColumnLabels(
BOOLEAN hasOtherBar);
virtual CTableView* CreateMainTable();
virtual NScrollBar* CreateScrollBar(
const CRect& theRect,
DIRECTION theDirection,
BOOLEAN isVisible

Cancelled Methods

CTable(const CTable& theTable);
CTable& operator=(const CTable& theTable);


[Classes] [Prev] [Next] [Methods]

support@xvt.com


Visit our online help desk for tech support

Copyright © 2009, Providence Software Solutions Inc. All rights reserved.