Sourceforge.net - The VCF's Project Host
   The VCF Website Home   |   Online Discussion Forums   |   Sourceforge.net Project Page   

VCF::TableControl Class Reference

This class if for presenting data in a tabular format. More...

#include <vcf/ApplicationKit/TableControl.h>

Inheritance diagram for VCF::TableControl:

VCF::CustomControl VCF::DelegatedContainer< TableControl > VCF::Control VCF::UIComponent VCF::AbstractView VCF::Component VCF::View VCF::ObjectWithCallbacks VCF::Object List of all members.

Public Types

enum  TableControlEvents {
  TableCellClickedEvent = CUSTOM_EVENT_TYPES + 32131, FixedRowClickedEvent, FixedColumnClickedEvent, SelectingEvent,
  TableSelectionChangingEvent, TableSelectionChangedEvent, TableCellCreatingEvent
}
enum  DrawGridLines { dglNone = 0, dglDrawVerticalLines = 1, dglDrawHorizontalLines = 2, dglDrawBoth = 3 }
enum  AutoSizeOption { asoDefault = 0, asoHeader = 1, asoData = 2, asoBoth }

Public Member Functions

 TableControl (TableModel *model=NULL)
virtual ~TableControl ()
virtual void paint (GraphicsContext *context)
 Paints the control.
void init ()
uint32 getDefaultRowHeight ()
void setDefaultRowHeight (const uint32 &defaultRowHeight)
uint32 getDefaultColumnWidth ()
void setDefaultColumnWidth (const uint32 &defaultColumnWidth)
void setColumnWidth (const uint32 &column, const uint32 &width)
void setRowHeight (const uint32 &row, const uint32 &height)
double getRowHeight (uint32 row)
double getColumnWidth (uint32 col)
TableModelgetTableModel ()
virtual void modelChanged (Model *oldModel, Model *newModel)
void setColumnCount (const uint32 &colCount)
void setRowCount (const uint32 &rowCount)
virtual void mouseDown (MouseEvent *event)
 Called when one (or more) of the mouse buttons are held down.
virtual void mouseMove (MouseEvent *event)
 Called when the mouse moves over the control.
virtual void mouseUp (MouseEvent *event)
 Called when one (or more) of the mouse buttons are released.
virtual void mouseClick (MouseEvent *event)
 Called when one or mouse buttons are held down and immediately released ( a "mouse click" ).
void setAutoResizeColumns (const bool &autoResizeColumns)
bool getAutoResizeColumns ()
virtual void handleEvent (Event *e)
 This gets called by the ControlPeer for any windowing system mouse events, as well as for any windowing system keyboard events and for any windowing system events like size changes, position changes, etc.
DrawGridLines getDrawGridLinesStyle ()
void setDrawGridLinesStyle (DrawGridLines val)
virtual bool canBeginDragDrop (Point *point)
 We'll always return false, so that we can control when to start the drag-drop operation.
bool getAllowColumnResizing ()
void setAllowColumnResizing (bool val)
bool getAllowRowResizing ()
void setAllowRowResizing (bool val)
bool getListMode ()
void setListMode (bool val)
bool getAllowColumnHide ()
void setAllowColumnHide (bool val)
bool getAllowRowHide ()
void setAllowRowHide (bool val)
bool getEnableSelection ()
void setEnableSelection (bool val)
bool getAllowSingleColumnSelection ()
void setAllowSingleColumnSelection (bool val)
bool getAllowSingleRowSelection ()
void setAllowSingleRowSelection (bool val)
bool getAllowFixedColumnSelection ()
void setAllowFixedColumnSelection (bool val)
bool getAllowFixedRowSelection ()
void setAllowFixedRowSelection (bool val)
virtual void keyDown (KeyboardEvent *e)
 called when the user presses the key down
void resizeColumnWidths ()
void resizeRowHeights ()
void resizeColumnRowDimensions ()
bool autoSizeColumn (int column, AutoSizeOption autoSizeStyle=asoDefault, bool resetScroll=true)
 autosize the specified column's width to its text
bool autoSizeRow (int row, bool resetScroll=true)
 autosize the specified row's heigth to its text
ColorgetDefaultTableCellColor ()
void setDefaultTableCellColor (Color *color)
FontgetDefaultTableCellFont ()
void setDefaultTableCellFont (Font *font)
TableCellItemsetSelectedCell (const bool &val, const uint32 &row, const uint32 &column)
void setSelectedRange (const bool &val, const uint32 &startRow, const uint32 &startColumn, const uint32 &endRow, const uint32 &endColumn)
void setFocusedCell (const uint32 &row, const uint32 &column)
TableCellItemgetFocusedCell ()
void clearSelection ()
Enumerator< TableCellItem * > * getSelectedCells ()
CellID getCellIDForItem (TableCellItem *item)
TableCellItemgetItem (const CellID &cell)
TableCellItemgetItem (const uint32 &row, const uint32 &column)
void setItem (const uint32 &row, const uint32 &column, TableCellItem *cell)

Public Attributes

VCF::Delegate TableCellDelegate
TableCellClicked VCF::Delegate TableCellDelegate
TableCellDblClicked VCF::Delegate TableCellDelegate
TableCellDown VCF::Delegate TableCellDelegate
TableCellFinishedEditing VCF::Delegate TableCellDelegate
FixedRowClicked VCF::Delegate TableCellDelegate
FixedColumnClicked VCF::Delegate TableCellDelegate
TableSelecting VCF::Delegate TableCellDelegate
TableSelectionChanging VCF::Delegate EventDelegate
TableSelectionChanged VCF::Delegate TableModelDelegate
 TableCellsSelected
VCF::Delegate CreateTableCellDelegate
 TableCellCreating

Protected Types

enum  MouseState {
  msNone = 0, msPrepareForEdit, msPrepareForDrag, msPrepareToSelect,
  msPrepareColResize, msColResizing, msPrepareRowResize, msRowResizing,
  msSelectAll, msSelectColumn, msSelectRow, msSelectCells
}

Protected Member Functions

Rect getBoundsForCell (const CellID &cell)
Rect getBoundsForItem (TableCellItem *item)
double getFixedColumnWidth ()
double getFixedRowHeight ()
void onTableModelChanged (TableModelEvent *event)
void onTableCellItemSelected (ItemEvent *event)
void onTableModelEmptied (ModelEvent *e)
void onEditingControlKeyPressed (KeyboardEvent *event)
void finishEditing ()
void cancelEditing ()
void onFocusLost (FocusEvent *e)
void onFinishEditing (Event *e)
CellID getCellIDFromPoint (const Point &pt, bool allowFixedCellCheck=true)
CellID setFocusedCell (const CellID &cell)
bool columnResizeAreaHitTest (const Point &pt)
bool rowResizeAreaHitTest (const Point &pt)
bool getCellOrigin (const CellID &cell, Point &pt)
 returns false if the cell is not visible, otherwise pt will be set to the top left coordinates of the item represented by the row/col of cell
CellID getTopLeftNonFixedCell (const bool &recalc=false)
CellRange getVisibleNonFixedCellRange (Rect *rect=NULL, bool forceRecalculation=false)
Point getClickedPoint (const CellID &cell, const Point &pt)
void clearSelectionRange ()
void doSelection (const CellID &cell)
void selectAllCells ()
void selectColumns (CellID currentCell, bool forceRedraw=false, bool selectCells=true)
void selectRows (CellID currentCell, bool forceRedraw=false, bool selectCells=true)
void selectCells (CellID currentCell, bool forceRedraw=false, bool selectCells=true)
void fixedRowClicked (CellID cell)
void fixedColumnClicked (CellID cell)
void recalcScrollBars ()
void onVerticalScrolling (Event *e)
void onHorizontalScrolling (Event *e)
double getTotalRowHeight ()
double getTotalColumnWidth ()
void editCell (const CellID &cell, const Point &pt)
Rect getEditCellRect (const CellID &editCellID)
virtual TableCellItemcreateCell (const uint32 &row, const uint32 &column)
virtual void paintItem (GraphicsContext *ctx, const Rect &itemRect, const CellID &cell, const DrawUIState &state)

Protected Attributes

TableCellItemselectedCellItem_
TableCellItemfocusedCell_
ControlcurrentEditingControl_
TableItemEditorcurrentItemEditor_
bool autoResizeColumns_
bool allowColumnResizing_
bool allowRowResizing_
bool hiddenColumnUnhide_
bool hiddenRowUnhide_
bool listMode_
bool allowColumnHide_
bool allowRowHide_
bool enableSelection_
bool allowSingleColumnSelection_
bool allowSingleRowSelection_
bool allowFixedColumnSelection_
bool allowFixedRowSelection_
bool allowLiveResizing_
int resizeCaptureRange_
Point resizeDragPt_
Point lastMousePoint_
Point leftClickPoint_
CellID clickCell_
CellID selectionStartCell_
CellID currentCell_
CellID topLeftCell_
uint32 dragColumnWidth_
double totalRowHeight_
MouseState mouseState_
DrawGridLines drawGridLinesStyle_
AutoSizeOption autoSizeStyle_
uint32 defaultColumnWidth_
uint32 defaultRowHeight_
std::vector< uint32columnWidths_
std::vector< uint32rowHeights_
Map< uint32, TableCellItem * > selectionMap_
std::map< CellID, TableCellItem * > previouslySelectedCellMap_
ColordefaultCellColor_
FontdefaultCellFont_
std::vector< TableCellItem * > tableItems_

Detailed Description

This class if for presenting data in a tabular format.

You can adjust the number of rows and columns, as well as various formatting features. You can also have custom editors for editing individual cells.

Originally started as a basic table control, I quickly realized what an ordeal this was going to turn into, and I began looking at Chris Maunder's excellent CGridCtrl class. At this point, much of the original code that I wrote has been completely dismantled, and in it's place I have ported over most of the basic design/layout/algorithms from the CGridCtrl.

The original CGridCtrl was written for MFC, and has a number of very Win32-ish designs implicit in it. These have been heavily changed to fit within the VCF way of doing things. For example, the original TableControl made use of a TableModel with TableCellItem's to represent an individual cell. This is still the case and in migrating over to Chris's code, I had to make allowances for this, since his control doesn't separate the model/data from the control itself (though he does use a CGridCell class for the cell items). In addition most of the enumerations and all of the function names have been changed, again to fit in with the VCF's coding standards.


Member Enumeration Documentation

enum VCF::TableControl::AutoSizeOption
 

Enumerator:
asoDefault 
asoHeader 
asoData 
asoBoth 

enum VCF::TableControl::DrawGridLines
 

Enumerator:
dglNone 
dglDrawVerticalLines 
dglDrawHorizontalLines 
dglDrawBoth 

enum VCF::TableControl::MouseState [protected]
 

Enumerator:
msNone 
msPrepareForEdit 
msPrepareForDrag 
msPrepareToSelect 
msPrepareColResize 
msColResizing 
msPrepareRowResize 
msRowResizing 
msSelectAll 
msSelectColumn 
msSelectRow 
msSelectCells 

enum VCF::TableControl::TableControlEvents
 

Enumerator:
TableCellClickedEvent 
FixedRowClickedEvent 
FixedColumnClickedEvent 
SelectingEvent 
TableSelectionChangingEvent 
TableSelectionChangedEvent 
TableCellCreatingEvent 


Constructor & Destructor Documentation

VCF::TableControl::TableControl TableModel model = NULL  ) 
 

virtual VCF::TableControl::~TableControl  )  [virtual]
 


Member Function Documentation

bool VCF::TableControl::autoSizeColumn int  column,
AutoSizeOption  autoSizeStyle = asoDefault,
bool  resetScroll = true
 

autosize the specified column's width to its text

bool VCF::TableControl::autoSizeRow int  row,
bool  resetScroll = true
 

autosize the specified row's heigth to its text

virtual bool VCF::TableControl::canBeginDragDrop Point point  )  [inline, virtual]
 

We'll always return false, so that we can control when to start the drag-drop operation.

Reimplemented from VCF::Control.

void VCF::TableControl::cancelEditing  )  [protected]
 

void VCF::TableControl::clearSelection  ) 
 

void VCF::TableControl::clearSelectionRange  )  [protected]
 

bool VCF::TableControl::columnResizeAreaHitTest const Point pt  )  [protected]
 

virtual TableCellItem* VCF::TableControl::createCell const uint32 row,
const uint32 column
[protected, virtual]
 

void VCF::TableControl::doSelection const CellID cell  )  [protected]
 

void VCF::TableControl::editCell const CellID cell,
const Point pt
[protected]
 

void VCF::TableControl::finishEditing  )  [protected]
 

void VCF::TableControl::fixedColumnClicked CellID  cell  )  [protected]
 

void VCF::TableControl::fixedRowClicked CellID  cell  )  [protected]
 

bool VCF::TableControl::getAllowColumnHide  )  [inline]
 

bool VCF::TableControl::getAllowColumnResizing  )  [inline]
 

bool VCF::TableControl::getAllowFixedColumnSelection  )  [inline]
 

bool VCF::TableControl::getAllowFixedRowSelection  )  [inline]
 

bool VCF::TableControl::getAllowRowHide  )  [inline]
 

bool VCF::TableControl::getAllowRowResizing  )  [inline]
 

bool VCF::TableControl::getAllowSingleColumnSelection  )  [inline]
 

bool VCF::TableControl::getAllowSingleRowSelection  )  [inline]
 

bool VCF::TableControl::getAutoResizeColumns  )  [inline]
 

Rect VCF::TableControl::getBoundsForCell const CellID cell  )  [protected]
 

Rect VCF::TableControl::getBoundsForItem TableCellItem item  )  [protected]
 

CellID VCF::TableControl::getCellIDForItem TableCellItem item  ) 
 

CellID VCF::TableControl::getCellIDFromPoint const Point pt,
bool  allowFixedCellCheck = true
[protected]
 

bool VCF::TableControl::getCellOrigin const CellID cell,
Point pt
[protected]
 

returns false if the cell is not visible, otherwise pt will be set to the top left coordinates of the item represented by the row/col of cell

Point VCF::TableControl::getClickedPoint const CellID cell,
const Point pt
[protected]
 

double VCF::TableControl::getColumnWidth uint32  col  ) 
 

uint32 VCF::TableControl::getDefaultColumnWidth  ) 
 

uint32 VCF::TableControl::getDefaultRowHeight  ) 
 

Color* VCF::TableControl::getDefaultTableCellColor  ) 
 

Font* VCF::TableControl::getDefaultTableCellFont  ) 
 

DrawGridLines VCF::TableControl::getDrawGridLinesStyle  )  [inline]
 

Rect VCF::TableControl::getEditCellRect const CellID editCellID  )  [protected]
 

bool VCF::TableControl::getEnableSelection  )  [inline]
 

double VCF::TableControl::getFixedColumnWidth  )  [protected]
 

double VCF::TableControl::getFixedRowHeight  )  [protected]
 

TableCellItem* VCF::TableControl::getFocusedCell  )  [inline]
 

TableCellItem* VCF::TableControl::getItem const uint32 row,
const uint32 column
[inline]
 

TableCellItem* VCF::TableControl::getItem const CellID cell  ) 
 

bool VCF::TableControl::getListMode  )  [inline]
 

double VCF::TableControl::getRowHeight uint32  row  ) 
 

Enumerator<TableCellItem*>* VCF::TableControl::getSelectedCells  ) 
 

TableModel* VCF::TableControl::getTableModel  ) 
 

CellID VCF::TableControl::getTopLeftNonFixedCell const bool &  recalc = false  )  [protected]
 

double VCF::TableControl::getTotalColumnWidth  )  [protected]
 

double VCF::TableControl::getTotalRowHeight  )  [protected]
 

CellRange VCF::TableControl::getVisibleNonFixedCellRange Rect rect = NULL,
bool  forceRecalculation = false
[protected]
 

virtual void VCF::TableControl::handleEvent Event e  )  [virtual]
 

This gets called by the ControlPeer for any windowing system mouse events, as well as for any windowing system keyboard events and for any windowing system events like size changes, position changes, etc.

Once inside the event the Control determines the type, and behaves accordingly, as well as notifying any appropriate listeners.

Reimplemented from VCF::Control.

void VCF::TableControl::init  ) 
 

Reimplemented from VCF::CustomControl.

virtual void VCF::TableControl::keyDown KeyboardEvent e  )  [virtual]
 

called when the user presses the key down

Reimplemented from VCF::Control.

virtual void VCF::TableControl::modelChanged Model oldModel,
Model newModel
[virtual]
 

Reimplemented from VCF::Control.

virtual void VCF::TableControl::mouseClick MouseEvent event  )  [virtual]
 

Called when one or mouse buttons are held down and immediately released ( a "mouse click" ).

override this to provide specific behaviours when a mouse click occurs

Reimplemented from