1999-10-06 00:58:38 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: griddemo.h
|
|
|
|
// Purpose: Grid control wxWindows sample
|
|
|
|
// Author: Michael Bedward
|
|
|
|
// Modified by:
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Michael Bedward, Julian Smart
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
1999-10-06 00:55:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef griddemo_h
|
|
|
|
#define griddemo_h
|
|
|
|
|
2000-02-09 15:30:27 -05:00
|
|
|
#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
|
|
|
|
#error "This sample requires the new wxGrid class."
|
|
|
|
#endif
|
1999-10-06 00:55:17 -04:00
|
|
|
|
|
|
|
class wxGrid;
|
|
|
|
|
|
|
|
class GridApp : public wxApp
|
|
|
|
{
|
2000-02-11 14:40:56 -05:00
|
|
|
public:
|
1999-10-06 00:55:17 -04:00
|
|
|
bool OnInit();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class GridFrame : public wxFrame
|
|
|
|
{
|
|
|
|
wxGrid *grid;
|
|
|
|
wxTextCtrl *logWin;
|
|
|
|
wxLogTextCtrl *logger;
|
|
|
|
wxString logBuf;
|
|
|
|
|
|
|
|
void SetDefaults();
|
2000-02-03 01:07:07 -05:00
|
|
|
|
1999-10-06 00:55:17 -04:00
|
|
|
void ToggleRowLabels( wxCommandEvent& );
|
|
|
|
void ToggleColLabels( wxCommandEvent& );
|
2000-02-03 01:07:07 -05:00
|
|
|
void ToggleEditing( wxCommandEvent& );
|
2000-02-21 23:06:58 -05:00
|
|
|
void ToggleRowSizing( wxCommandEvent& );
|
|
|
|
void ToggleColSizing( wxCommandEvent& );
|
2000-02-23 02:03:56 -05:00
|
|
|
void ToggleGridSizing( wxCommandEvent& );
|
2000-07-15 15:51:35 -04:00
|
|
|
void ToggleGridLines( wxCommandEvent& );
|
|
|
|
void AutoSizeCols( wxCommandEvent& );
|
2002-09-07 09:46:57 -04:00
|
|
|
void CellOverflow( wxCommandEvent& );
|
|
|
|
void ResizeCell( wxCommandEvent& );
|
1999-10-06 00:55:17 -04:00
|
|
|
void SetLabelColour( wxCommandEvent& );
|
|
|
|
void SetLabelTextColour( wxCommandEvent& );
|
2002-01-21 13:11:15 -05:00
|
|
|
void SetLabelFont(wxCommandEvent &);
|
1999-10-06 00:55:17 -04:00
|
|
|
void SetRowLabelHorizAlignment( wxCommandEvent& );
|
|
|
|
void SetRowLabelVertAlignment( wxCommandEvent& );
|
|
|
|
void SetColLabelHorizAlignment( wxCommandEvent& );
|
|
|
|
void SetColLabelVertAlignment( wxCommandEvent& );
|
|
|
|
void SetGridLineColour( wxCommandEvent& );
|
1999-10-13 07:57:22 -04:00
|
|
|
|
2000-02-11 14:40:56 -05:00
|
|
|
void SetCellFgColour(wxCommandEvent &);
|
|
|
|
void SetCellBgColour(wxCommandEvent &);
|
|
|
|
|
2000-02-09 15:30:27 -05:00
|
|
|
void InsertRow( wxCommandEvent& );
|
|
|
|
void InsertCol( wxCommandEvent& );
|
|
|
|
void DeleteSelectedRows( wxCommandEvent& );
|
|
|
|
void DeleteSelectedCols( wxCommandEvent& );
|
1999-10-06 00:55:17 -04:00
|
|
|
void ClearGrid( wxCommandEvent& );
|
2000-03-04 14:56:39 -05:00
|
|
|
void SelectCells( wxCommandEvent& );
|
|
|
|
void SelectRows( wxCommandEvent& );
|
|
|
|
void SelectCols( wxCommandEvent& );
|
1999-10-06 00:55:17 -04:00
|
|
|
|
2001-01-04 06:05:41 -05:00
|
|
|
void DeselectCell(wxCommandEvent& event);
|
|
|
|
void DeselectCol(wxCommandEvent& event);
|
|
|
|
void DeselectRow(wxCommandEvent& event);
|
|
|
|
void DeselectAll(wxCommandEvent& event);
|
|
|
|
void SelectCell(wxCommandEvent& event);
|
|
|
|
void SelectCol(wxCommandEvent& event);
|
|
|
|
void SelectRow(wxCommandEvent& event);
|
|
|
|
void SelectAll(wxCommandEvent& event);
|
2001-01-08 08:35:16 -05:00
|
|
|
void OnAddToSelectToggle(wxCommandEvent& event);
|
2001-01-04 06:05:41 -05:00
|
|
|
|
1999-10-06 00:55:17 -04:00
|
|
|
void OnLabelLeftClick( wxGridEvent& );
|
|
|
|
void OnCellLeftClick( wxGridEvent& );
|
|
|
|
void OnRowSize( wxGridSizeEvent& );
|
|
|
|
void OnColSize( wxGridSizeEvent& );
|
1999-10-19 03:27:56 -04:00
|
|
|
void OnSelectCell( wxGridEvent& );
|
1999-10-06 00:55:17 -04:00
|
|
|
void OnRangeSelected( wxGridRangeSelectEvent& );
|
|
|
|
void OnCellValueChanged( wxGridEvent& );
|
2000-02-09 15:30:27 -05:00
|
|
|
|
2000-02-17 05:12:48 -05:00
|
|
|
void OnEditorShown(wxGridEvent&);
|
|
|
|
void OnEditorHidden(wxGridEvent&);
|
|
|
|
|
2001-05-09 18:31:17 -04:00
|
|
|
void OnSetHighlightWidth(wxCommandEvent&);
|
|
|
|
void OnSetROHighlightWidth(wxCommandEvent&);
|
|
|
|
|
2000-02-11 14:40:56 -05:00
|
|
|
public:
|
1999-10-06 00:55:17 -04:00
|
|
|
GridFrame();
|
|
|
|
~GridFrame();
|
|
|
|
|
|
|
|
void OnQuit( wxCommandEvent& );
|
2000-02-03 01:07:07 -05:00
|
|
|
void About( wxCommandEvent& );
|
2000-02-13 00:38:03 -05:00
|
|
|
void OnVTable( wxCommandEvent& );
|
2000-02-21 13:34:30 -05:00
|
|
|
void OnBugsTable( wxCommandEvent& );
|
2002-04-12 12:31:38 -04:00
|
|
|
void OnSmallGrid( wxCommandEvent& );
|
1999-10-06 00:55:17 -04:00
|
|
|
|
2000-02-11 14:40:56 -05:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ID_TOGGLEROWLABELS = 100,
|
|
|
|
ID_TOGGLECOLLABELS,
|
|
|
|
ID_TOGGLEEDIT,
|
2000-02-21 23:06:58 -05:00
|
|
|
ID_TOGGLEROWSIZING,
|
|
|
|
ID_TOGGLECOLSIZING,
|
2000-02-23 02:03:56 -05:00
|
|
|
ID_TOGGLEGRIDSIZING,
|
2000-07-15 15:51:35 -04:00
|
|
|
ID_TOGGLEGRIDLINES,
|
|
|
|
ID_AUTOSIZECOLS,
|
2002-09-07 09:46:57 -04:00
|
|
|
ID_CELLOVERFLOW,
|
|
|
|
ID_RESIZECELL,
|
2000-02-11 14:40:56 -05:00
|
|
|
ID_SETLABELCOLOUR,
|
|
|
|
ID_SETLABELTEXTCOLOUR,
|
2002-01-21 13:11:15 -05:00
|
|
|
ID_SETLABEL_FONT,
|
2000-02-11 14:40:56 -05:00
|
|
|
ID_ROWLABELALIGN,
|
|
|
|
ID_ROWLABELHORIZALIGN,
|
|
|
|
ID_ROWLABELVERTALIGN,
|
|
|
|
ID_COLLABELALIGN,
|
|
|
|
ID_COLLABELHORIZALIGN,
|
|
|
|
ID_COLLABELVERTALIGN,
|
|
|
|
ID_GRIDLINECOLOUR,
|
|
|
|
ID_INSERTROW,
|
|
|
|
ID_INSERTCOL,
|
|
|
|
ID_DELETEROW,
|
|
|
|
ID_DELETECOL,
|
|
|
|
ID_CLEARGRID,
|
2001-01-08 08:35:16 -05:00
|
|
|
ID_CHANGESEL,
|
|
|
|
ID_SELCELLS,
|
|
|
|
ID_SELROWS,
|
|
|
|
ID_SELCOLS,
|
2000-02-11 14:40:56 -05:00
|
|
|
ID_SET_CELL_FG_COLOUR,
|
|
|
|
ID_SET_CELL_BG_COLOUR,
|
|
|
|
ID_ABOUT,
|
2000-02-13 00:38:03 -05:00
|
|
|
ID_VTABLE,
|
2000-02-21 13:34:30 -05:00
|
|
|
ID_BUGS_TABLE,
|
2002-04-12 12:31:38 -04:00
|
|
|
ID_SMALL_GRID,
|
2001-01-08 08:35:16 -05:00
|
|
|
ID_SELECT_UNSELECT,
|
2001-01-04 06:05:41 -05:00
|
|
|
ID_SELECT_ALL,
|
|
|
|
ID_SELECT_ROW,
|
|
|
|
ID_SELECT_COL,
|
|
|
|
ID_SELECT_CELL,
|
|
|
|
ID_DESELECT_ALL,
|
|
|
|
ID_DESELECT_ROW,
|
|
|
|
ID_DESELECT_COL,
|
|
|
|
ID_DESELECT_CELL,
|
2000-02-11 14:40:56 -05:00
|
|
|
|
2001-05-09 18:31:17 -04:00
|
|
|
ID_SET_HIGHLIGHT_WIDTH,
|
|
|
|
ID_SET_RO_HIGHLIGHT_WIDTH,
|
|
|
|
|
2000-02-11 14:40:56 -05:00
|
|
|
ID_TESTFUNC
|
|
|
|
};
|
2000-02-09 15:30:27 -05:00
|
|
|
|
2000-02-23 19:20:45 -05:00
|
|
|
wxLog *m_logOld;
|
|
|
|
|
2001-01-08 08:35:16 -05:00
|
|
|
// add the cells to selection when using commands from select menu?
|
|
|
|
bool m_addToSel;
|
|
|
|
|
1999-10-06 00:55:17 -04:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
2000-02-11 14:40:56 -05:00
|
|
|
class MyGridCellRenderer : public wxGridCellStringRenderer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void Draw(wxGrid& grid,
|
2000-02-13 00:38:03 -05:00
|
|
|
wxGridCellAttr& attr,
|
2000-02-11 14:40:56 -05:00
|
|
|
wxDC& dc,
|
|
|
|
const wxRect& rect,
|
|
|
|
int row, int col,
|
|
|
|
bool isSelected);
|
|
|
|
};
|
1999-10-06 00:55:17 -04:00
|
|
|
|
2000-02-21 12:37:07 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// demonstration of virtual table which doesn't store all of its data in
|
|
|
|
// memory
|
|
|
|
// ----------------------------------------------------------------------------
|
2000-02-13 00:38:03 -05:00
|
|
|
|
2000-02-21 12:37:07 -05:00
|
|
|
class BigGridTable : public wxGridTableBase
|
|
|
|
{
|
2000-02-13 00:38:03 -05:00
|
|
|
public:
|
2000-02-21 12:37:07 -05:00
|
|
|
BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
|
|
|
|
|
2000-03-10 07:27:27 -05:00
|
|
|
int GetNumberRows() { return m_sizeGrid; }
|
|
|
|
int GetNumberCols() { return m_sizeGrid; }
|
2000-02-21 12:37:07 -05:00
|
|
|
wxString GetValue( int row, int col )
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
return wxString::Format(wxT("(%d, %d)"), row, col);
|
2000-02-13 00:38:03 -05:00
|
|
|
}
|
|
|
|
|
2000-02-21 12:37:07 -05:00
|
|
|
void SetValue( int , int , const wxString& ) { /* ignore */ }
|
2000-02-13 00:38:03 -05:00
|
|
|
bool IsEmptyCell( int , int ) { return FALSE; }
|
2000-02-21 12:37:07 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
long m_sizeGrid;
|
2000-02-13 00:38:03 -05:00
|
|
|
};
|
|
|
|
|
2000-02-21 12:37:07 -05:00
|
|
|
class BigGridFrame : public wxFrame
|
|
|
|
{
|
2000-02-13 00:38:03 -05:00
|
|
|
public:
|
2000-02-21 12:37:07 -05:00
|
|
|
BigGridFrame(long sizeGrid);
|
2000-02-13 00:38:03 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxGrid* m_grid;
|
|
|
|
BigGridTable* m_table;
|
|
|
|
};
|
|
|
|
|
2000-02-28 14:08:01 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// an example of custom attr provider: this one makes all odd rows appear grey
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MyGridCellAttrProvider : public wxGridCellAttrProvider
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyGridCellAttrProvider();
|
|
|
|
virtual ~MyGridCellAttrProvider();
|
|
|
|
|
2001-05-16 09:20:31 -04:00
|
|
|
virtual wxGridCellAttr *GetAttr(int row, int col,
|
2001-05-27 11:22:28 -04:00
|
|
|
wxGridCellAttr::wxAttrKind kind) const;
|
2000-02-28 14:08:01 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxGridCellAttr *m_attrForOddRows;
|
|
|
|
};
|
|
|
|
|
2000-02-21 13:34:30 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2000-02-22 09:29:41 -05:00
|
|
|
// another, more realistic, grid example: shows typed columns and more
|
2000-02-21 13:34:30 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-02-22 09:29:41 -05:00
|
|
|
class BugsGridTable : public wxGridTableBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BugsGridTable();
|
|
|
|
|
2000-03-10 07:27:27 -05:00
|
|
|
virtual int GetNumberRows();
|
|
|
|
virtual int GetNumberCols();
|
2000-02-22 09:29:41 -05:00
|
|
|
virtual bool IsEmptyCell( int row, int col );
|
|
|
|
virtual wxString GetValue( int row, int col );
|
|
|
|
virtual void SetValue( int row, int col, const wxString& value );
|
|
|
|
|
|
|
|
virtual wxString GetColLabelValue( int col );
|
|
|
|
|
|
|
|
virtual wxString GetTypeName( int row, int col );
|
|
|
|
virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
|
|
|
|
virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
|
|
|
|
|
|
|
|
virtual long GetValueAsLong( int row, int col );
|
|
|
|
virtual bool GetValueAsBool( int row, int col );
|
|
|
|
|
|
|
|
virtual void SetValueAsLong( int row, int col, long value );
|
|
|
|
virtual void SetValueAsBool( int row, int col, bool value );
|
|
|
|
};
|
|
|
|
|
2000-02-21 13:34:30 -05:00
|
|
|
class BugsGridFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BugsGridFrame();
|
|
|
|
};
|
2000-02-13 00:38:03 -05:00
|
|
|
|
2001-05-16 09:20:31 -04:00
|
|
|
|
2000-02-21 12:37:07 -05:00
|
|
|
#endif // griddemo_h
|
1999-10-06 00:55:17 -04:00
|
|
|
|