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::Component VCF::AbstractView VCF::ObjectWithEvents VCF::View VCF::Object List of all members.

Public Types

enum  {
  TableCellClickedEvent = CUSTOM_EVENT_TYPES + 32131, FixedRowClickedEvent, FixedColumnClickedEvent, SelectingEvent,
  TableSelectionChangingEvent, TableSelectionChangedEvent
}
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 ()
 This is going to be removed from the bext release.
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 ()
void setTableModel (TableModel *model)
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)

Public Attributes

VCF::Delegate TableCellClicked
VCF::Delegate TableCellDblClicked
VCF::Delegate TableCellDown
VCF::Delegate TableCellFinishedEditing
VCF::Delegate FixedRowClicked
VCF::Delegate FixedColumnClicked
VCF::Delegate TableSelecting
VCF::Delegate TableSelectionChanging
VCF::Delegate TableSelectionChanged

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)
TableCellItemgetItem (const CellID &cell)
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)

Protected Attributes

TableCellItemselectedCellItem_
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_
std::map< CellID, TableCellItem * > previouslySelectedCellMap_
ColordefaultCellColor_
FontdefaultCellFont_

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

anonymous enum
 

Enumerator:
TableCellClickedEvent 
FixedRowClickedEvent 
FixedColumnClickedEvent 
SelectingEvent 
TableSelectionChangingEvent 
TableSelectionChangedEvent 

Reimplemented from VCF::Control.

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 


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::clearSelectionRange  )  [protected]
 

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

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::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::getItem const CellID cell  )  [protected]
 

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

double VCF::TableControl::getRowHeight uint32  row  ) 
 

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  ) 
 

This is going to be removed from the bext release.

Deprecated:

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::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 VCF::Control.

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

Called when one (or more) of the mouse buttons are held down.

override this to provide specific behaviours when the mouse buttons are held down

Reimplemented from VCF::Control.

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

Called when the mouse moves over the control.

override this to provide specific behaviours when the mouse moves over the control.

Reimplemented from VCF::Control.

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

Called when one (or more) of the mouse buttons are released.

override this to provide specific behaviours when the mouse buttons are released.

Reimplemented from VCF::Control.

void VCF::TableControl::onEditingControlKeyPressed KeyboardEvent event  )  [protected]
 

void VCF::TableControl::onFinishEditing Event e  )  [protected]
 

void VCF::TableControl::onFocusLost FocusEvent e  )  [protected]
 

void VCF::TableControl::onHorizontalScrolling Event e  )  [protected]
 

void VCF::TableControl::onTableCellItemSelected ItemEvent event  )  [protected]
 

void VCF::TableControl::onTableModelChanged TableModelEvent event  )  [protected]
 

void VCF::TableControl::onTableModelEmptied ModelEvent e  )  [protected]
 

void VCF::TableControl::onVerticalScrolling Event e  )  [protected]
 

virtual void VCF::TableControl::paint GraphicsContext context  )  [virtual]
 

Paints the control.

Called by the underlying windowing system whenever the control needs to be painted. Note that in some cases the GraphicsContext passed in to this method may not be the same pointer as the GraphicsContext that the control holds itself. During the paint() method you should only use the context value for all your drawing and not the one returned in getContext(). The value returned by getContext() should be used for drawing that takes place outside of the paint() method.

If the control allows paint notification, then the framework will fire an event to the BeforeControlPainted delegate prior to calling the control's paint() method. After the paint() method has returned, if the control allows paint notification, the framework will fire an event to the AfterControlPainted delegate. This allows outside observers to take part in the paint cycle, but beware that this does come at a bit of a cost, so use this feature sparingly.

Note: This should NEVER be called by programmers using the VCF, it will be called for you during the course of your applications native event loop, and is only here for providing custom drawing routines for controls. In other words: you implement it, you never call it yourself.

See also:
getAllowPaintNotification

Reimplemented from VCF::CustomControl.