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& );
|
1999-10-06 00:55:17 -04:00
|
|
|
void SetLabelColour( wxCommandEvent& );
|
|
|
|
void SetLabelTextColour( wxCommandEvent& );
|
|
|
|
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
|
|
|
|
|
|
|
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&);
|
|
|
|
|
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& );
|
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-02-11 14:40:56 -05:00
|
|
|
ID_SETLABELCOLOUR,
|
|
|
|
ID_SETLABELTEXTCOLOUR,
|
|
|
|
ID_ROWLABELALIGN,
|
|
|
|
ID_ROWLABELHORIZALIGN,
|
|
|
|
ID_ROWLABELVERTALIGN,
|
|
|
|
ID_COLLABELALIGN,
|
|
|
|
ID_COLLABELHORIZALIGN,
|
|
|
|
ID_COLLABELVERTALIGN,
|
|
|
|
ID_GRIDLINECOLOUR,
|
|
|
|
ID_INSERTROW,
|
|
|
|
ID_INSERTCOL,
|
|
|
|
ID_DELETEROW,
|
|
|
|
ID_DELETECOL,
|
|
|
|
ID_CLEARGRID,
|
2000-03-04 14:56:39 -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,
|
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;
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
long GetNumberRows() { return m_sizeGrid; }
|
|
|
|
long GetNumberCols() { return m_sizeGrid; }
|
|
|
|
wxString GetValue( int row, int col )
|
|
|
|
{
|
|
|
|
return wxString::Format("(%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();
|
|
|
|
|
|
|
|
virtual wxGridCellAttr *GetAttr(int row, int col) const;
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
virtual long GetNumberRows();
|
|
|
|
virtual long GetNumberCols();
|
|
|
|
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
|
|
|
|
2000-02-21 12:37:07 -05:00
|
|
|
#endif // griddemo_h
|
1999-10-06 00:55:17 -04:00
|
|
|
|