/////////////////////////////////////////////////////////////////////////////
// Name: griddemo.cpp
-// Purpose: Grid control wxWindows sample
+// Purpose: Grid control wxWidgets sample
// Author: Michael Bedward
// Modified by:
// RCS-ID: $Id$
#include "wx/colordlg.h"
#include "wx/fontdlg.h"
+#include "wx/numdlg.h"
#include "wx/grid.h"
#include "wx/generic/gridctrl.h"
bool GridApp::OnInit()
{
GridFrame *frame = new GridFrame;
- frame->Show( TRUE );
+ frame->Show(true);
- return TRUE;
+ return true;
}
// ----------------------------------------------------------------------------
EVT_MENU( ID_TOGGLEROWSIZING, GridFrame::ToggleRowSizing )
EVT_MENU( ID_TOGGLECOLSIZING, GridFrame::ToggleColSizing )
EVT_MENU( ID_TOGGLEGRIDSIZING, GridFrame::ToggleGridSizing )
+ EVT_MENU( ID_TOGGLEGRIDDRAGCELL, GridFrame::ToggleGridDragCell )
EVT_MENU( ID_TOGGLEGRIDLINES, GridFrame::ToggleGridLines )
EVT_MENU( ID_AUTOSIZECOLS, GridFrame::AutoSizeCols )
EVT_MENU( ID_CELLOVERFLOW, GridFrame::CellOverflow )
EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged )
+ EVT_GRID_CELL_BEGIN_DRAG( GridFrame::OnCellBeginDrag )
EVT_GRID_EDITOR_SHOWN( GridFrame::OnEditorShown )
EVT_GRID_EDITOR_HIDDEN( GridFrame::OnEditorHidden )
GridFrame::GridFrame()
- : wxFrame( (wxFrame *)NULL, -1, _T("wxWindows grid class demo"),
+ : wxFrame( (wxFrame *)NULL, wxID_ANY, _T("wxWidgets grid class demo"),
wxDefaultPosition,
wxDefaultSize )
{
- int gridW = 600, gridH = 300;
- int logW = gridW, logH = 100;
-
wxMenu *fileMenu = new wxMenu;
fileMenu->Append( ID_VTABLE, _T("&Virtual table test\tCtrl-V"));
fileMenu->Append( ID_BUGS_TABLE, _T("&Bugs table test\tCtrl-B"));
fileMenu->Append( wxID_EXIT, _T("E&xit\tAlt-X") );
wxMenu *viewMenu = new wxMenu;
- viewMenu->Append( ID_TOGGLEROWLABELS, _T("&Row labels"), _T(""), wxITEM_CHECK );
- viewMenu->Append( ID_TOGGLECOLLABELS, _T("&Col labels"), _T(""), wxITEM_CHECK );
- viewMenu->Append( ID_TOGGLEEDIT, _T("&Editable"), _T(""), wxITEM_CHECK );
- viewMenu->Append( ID_TOGGLEROWSIZING, _T("Ro&w drag-resize"), _T(""), wxITEM_CHECK );
- viewMenu->Append( ID_TOGGLECOLSIZING, _T("C&ol drag-resize"), _T(""), wxITEM_CHECK );
- viewMenu->Append( ID_TOGGLEGRIDSIZING, _T("&Grid drag-resize"), _T(""), wxITEM_CHECK );
- viewMenu->Append( ID_TOGGLEGRIDLINES, _T("&Grid Lines"), _T(""), wxITEM_CHECK );
- viewMenu->Append( ID_SET_HIGHLIGHT_WIDTH, _T("&Set Cell Highlight Width..."), _T("") );
- viewMenu->Append( ID_SET_RO_HIGHLIGHT_WIDTH, _T("&Set Cell RO Highlight Width..."), _T("") );
+ viewMenu->Append( ID_TOGGLEROWLABELS, _T("&Row labels"), wxEmptyString, wxITEM_CHECK );
+ viewMenu->Append( ID_TOGGLECOLLABELS, _T("&Col labels"), wxEmptyString, wxITEM_CHECK );
+ viewMenu->Append( ID_TOGGLEEDIT, _T("&Editable"), wxEmptyString, wxITEM_CHECK );
+ viewMenu->Append( ID_TOGGLEROWSIZING, _T("Ro&w drag-resize"), wxEmptyString, wxITEM_CHECK );
+ viewMenu->Append( ID_TOGGLECOLSIZING, _T("C&ol drag-resize"), wxEmptyString, wxITEM_CHECK );
+ viewMenu->Append( ID_TOGGLEGRIDSIZING, _T("&Grid drag-resize"), wxEmptyString, wxITEM_CHECK );
+ viewMenu->Append( ID_TOGGLEGRIDDRAGCELL, _T("&Grid drag-cell"), wxEmptyString, wxITEM_CHECK );
+ viewMenu->Append( ID_TOGGLEGRIDLINES, _T("&Grid Lines"), wxEmptyString, wxITEM_CHECK );
+ viewMenu->Append( ID_SET_HIGHLIGHT_WIDTH, _T("&Set Cell Highlight Width...") );
+ viewMenu->Append( ID_SET_RO_HIGHLIGHT_WIDTH, _T("&Set Cell RO Highlight Width...") );
viewMenu->Append( ID_AUTOSIZECOLS, _T("&Auto-size cols") );
- viewMenu->Append( ID_CELLOVERFLOW, _T("&Overflow cells"), _T(""), wxITEM_CHECK );
- viewMenu->Append( ID_RESIZECELL, _T("&Resize cell (7,1)"), _T(""), wxITEM_CHECK );
+ viewMenu->Append( ID_CELLOVERFLOW, _T("&Overflow cells"), wxEmptyString, wxITEM_CHECK );
+ viewMenu->Append( ID_RESIZECELL, _T("&Resize cell (7,1)"), wxEmptyString, wxITEM_CHECK );
wxMenu *rowLabelMenu = new wxMenu;
SetMenuBar( menuBar );
- m_addToSel = FALSE;
+ m_addToSel = false;
grid = new wxGrid( this,
- -1,
+ wxID_ANY,
wxPoint( 0, 0 ),
wxSize( 400, 300 ) );
+#if wxUSE_LOG
+ int gridW = 600, gridH = 300;
+ int logW = gridW, logH = 100;
+
logWin = new wxTextCtrl( this,
- -1,
+ wxID_ANY,
wxEmptyString,
wxPoint( 0, gridH + 20 ),
wxSize( logW, logH ),
wxTE_MULTILINE );
logger = new wxLogTextCtrl( logWin );
- m_logOld = logger->SetActiveTarget( logger );
- logger->SetTimestamp( NULL );
+ m_logOld = wxLog::SetActiveTarget( logger );
+ wxLog::SetTimestamp( NULL );
+#endif // wxUSE_LOG
// this will create a grid and, by default, an associated grid
// table for strings
grid->SetCellEditor(4, 0, new wxGridCellChoiceEditor(WXSIZEOF(choices), choices));
grid->SetCellSize(4, 0, 1, 2);
grid->SetCellValue(4, 0, choices[0]);
- grid->SetCellOverflow(4, 0, FALSE);
+ grid->SetCellOverflow(4, 0, false);
grid->SetCellSize(7, 1, 3, 4);
grid->SetCellAlignment(7, 1, wxALIGN_CENTRE, wxALIGN_CENTRE);
1,
wxEXPAND );
+#if wxUSE_LOG
topSizer->Add( logWin,
0,
wxEXPAND );
+#endif // wxUSE_LOG
- SetAutoLayout( TRUE );
+ SetAutoLayout(true);
SetSizer( topSizer );
topSizer->Fit( this );
- topSizer->SetSizeHints( this );
Centre();
SetDefaults();
GridFrame::~GridFrame()
{
+#if wxUSE_LOG
delete wxLog::SetActiveTarget(m_logOld);
+#endif // wxUSE_LOG
}
void GridFrame::SetDefaults()
{
- GetMenuBar()->Check( ID_TOGGLEROWLABELS, TRUE );
- GetMenuBar()->Check( ID_TOGGLECOLLABELS, TRUE );
- GetMenuBar()->Check( ID_TOGGLEEDIT, TRUE );
- GetMenuBar()->Check( ID_TOGGLEROWSIZING, TRUE );
- GetMenuBar()->Check( ID_TOGGLECOLSIZING, TRUE );
- GetMenuBar()->Check( ID_TOGGLEGRIDSIZING, TRUE );
- GetMenuBar()->Check( ID_TOGGLEGRIDLINES, TRUE );
- GetMenuBar()->Check( ID_CELLOVERFLOW, TRUE );
+ GetMenuBar()->Check( ID_TOGGLEROWLABELS, true );
+ GetMenuBar()->Check( ID_TOGGLECOLLABELS, true );
+ GetMenuBar()->Check( ID_TOGGLEEDIT, true );
+ GetMenuBar()->Check( ID_TOGGLEROWSIZING, true );
+ GetMenuBar()->Check( ID_TOGGLECOLSIZING, true );
+ GetMenuBar()->Check( ID_TOGGLEGRIDSIZING, true );
+ GetMenuBar()->Check( ID_TOGGLEGRIDDRAGCELL, false );
+ GetMenuBar()->Check( ID_TOGGLEGRIDLINES, true );
+ GetMenuBar()->Check( ID_CELLOVERFLOW, true );
}
GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING ) );
}
+void GridFrame::ToggleGridDragCell( wxCommandEvent& WXUNUSED(ev) )
+{
+ grid->EnableDragCell(
+ GetMenuBar()->IsChecked( ID_TOGGLEGRIDDRAGCELL ) );
+}
void GridFrame::ToggleGridLines( wxCommandEvent& WXUNUSED(ev) )
{
break;
}
- grid->SetRowLabelAlignment( horiz, -1 );
+ grid->SetRowLabelAlignment( horiz, vert );
}
void GridFrame::SetRowLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) )
break;
}
- grid->SetRowLabelAlignment( -1, vert );
+ grid->SetRowLabelAlignment( horiz, vert );
}
break;
}
- grid->SetColLabelAlignment( horiz, -1 );
+ grid->SetColLabelAlignment( horiz, vert );
}
break;
}
- grid->SetColLabelAlignment( -1, vert );
+ grid->SetColLabelAlignment( horiz, vert );
}
{
// Check the new Refresh function by passing it a rectangle
// which exactly fits the grid.
- wxRect r(wxPoint(0, 0), grid->GetSize());
+ wxPoint pt(0, 0);
+ wxRect r(pt, grid->GetSize());
grid->SetDefaultCellBackgroundColour(col);
- grid->Refresh(TRUE, &r);
+ grid->Refresh(true, &r);
}
}
void GridFrame::OnLabelLeftClick( wxGridEvent& ev )
{
- logBuf = _T("");
+ logBuf = wxEmptyString;
if ( ev.GetRow() != -1 )
{
logBuf << _T("Left click on row label ") << ev.GetRow();
void GridFrame::OnCellLeftClick( wxGridEvent& ev )
{
- logBuf = _T("");
+ logBuf = wxEmptyString;
logBuf << _T("Left click at row ") << ev.GetRow()
<< _T(" col ") << ev.GetCol();
wxLogMessage( wxT("%s"), logBuf.c_str() );
void GridFrame::OnRowSize( wxGridSizeEvent& ev )
{
- logBuf = _T("");
+ logBuf = wxEmptyString;
logBuf << _T("Resized row ") << ev.GetRowOrCol();
wxLogMessage( wxT("%s"), logBuf.c_str() );
void GridFrame::OnColSize( wxGridSizeEvent& ev )
{
- logBuf = _T("");
+ logBuf = wxEmptyString;
logBuf << _T("Resized col ") << ev.GetRowOrCol();
wxLogMessage( wxT("%s"), logBuf.c_str() );
void GridFrame::OnSelectCell( wxGridEvent& ev )
{
- logBuf = _T("");
+ logBuf = wxEmptyString;
if ( ev.Selecting() )
logBuf << _T("Selected ");
else
void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev )
{
- logBuf = _T("");
+ logBuf = wxEmptyString;
if ( ev.Selecting() )
logBuf << _T("Selected ");
else
void GridFrame::OnCellValueChanged( wxGridEvent& ev )
{
- logBuf = _T("");
+ logBuf = wxEmptyString;
logBuf << _T("Value changed for cell at")
<< _T(" row ") << ev.GetRow()
<< _T(" col ") << ev.GetCol();
ev.Skip();
}
+void GridFrame::OnCellBeginDrag( wxGridEvent& ev )
+{
+ logBuf = _T("");
+ logBuf << _T("Got request to drag cell at")
+ << _T(" row ") << ev.GetRow()
+ << _T(" col ") << ev.GetCol();
+
+ wxLogMessage( wxT("%s"), logBuf.c_str() );
+
+ ev.Skip();
+}
+
void GridFrame::OnEditorShown( wxGridEvent& ev )
{
void GridFrame::OnQuit( wxCommandEvent& WXUNUSED(ev) )
{
- Close( TRUE );
+ Close( true );
}
void GridFrame::OnBugsTable(wxCommandEvent& )
{
BugsGridFrame *frame = new BugsGridFrame;
- frame->Show(TRUE);
+ frame->Show(true);
}
void GridFrame::OnSmallGrid(wxCommandEvent& )
{
- wxFrame* frame = new wxFrame(NULL, -1, _T("A Small Grid"),
+ wxFrame* frame = new wxFrame(NULL, wxID_ANY, _T("A Small Grid"),
wxDefaultPosition, wxSize(640, 480));
- wxPanel* panel = new wxPanel(frame, -1);
- wxGrid* grid = new wxGrid(panel, -1, wxPoint(10,10), wxSize(400,400),
+ wxPanel* panel = new wxPanel(frame, wxID_ANY);
+ wxGrid* grid = new wxGrid(panel, wxID_ANY, wxPoint(10,10), wxSize(400,400),
wxWANTS_CHARS | wxSIMPLE_BORDER);
grid->CreateGrid(3,3);
- frame->Show(TRUE);
+ frame->Show(true);
}
void GridFrame::OnVTable(wxCommandEvent& )
if ( s_sizeGrid != -1 )
{
BigGridFrame* win = new BigGridFrame(s_sizeGrid);
- win->Show(TRUE);
+ win->Show(true);
}
}
// ============================================================================
BigGridFrame::BigGridFrame(long sizeGrid)
- : wxFrame(NULL, -1, _T("Plugin Virtual Table"),
+ : wxFrame(NULL, wxID_ANY, _T("Plugin Virtual Table"),
wxDefaultPosition, wxSize(500, 450))
{
- m_grid = new wxGrid(this, -1, wxDefaultPosition, wxDefaultSize);
+ m_grid = new wxGrid(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
m_table = new BigGridTable(sizeGrid);
// VZ: I don't understand why this slows down the display that much,
// must profile it...
//m_table->SetAttrProvider(new MyGridCellAttrProvider);
- m_grid->SetTable(m_table, TRUE);
+ m_grid->SetTable(m_table, true);
#if defined __WXMOTIF__
// MB: the grid isn't getting a sensible default size under wxMotif
bool opened;
} gs_dataBugsGrid [] =
{
- { 18, _T("foo doesn't work"), Sev_Major, 1, _T("wxMSW"), TRUE },
- { 27, _T("bar crashes"), Sev_Critical, 1, _T("all"), FALSE },
- { 45, _T("printing is slow"), Sev_Minor, 3, _T("wxMSW"), TRUE },
- { 68, _T("Rectangle() fails"), Sev_Normal, 1, _T("wxMSW"), FALSE },
+ { 18, _T("foo doesn't work"), Sev_Major, 1, _T("wxMSW"), true },
+ { 27, _T("bar crashes"), Sev_Critical, 1, _T("all"), false },
+ { 45, _T("printing is slow"), Sev_Minor, 3, _T("wxMSW"), true },
+ { 68, _T("Rectangle() fails"), Sev_Normal, 1, _T("wxMSW"), false },
};
static const wxChar *headers[Col_Max] =
return Col_Max;
}
-bool BugsGridTable::IsEmptyCell( int row, int col )
+bool BugsGridTable::IsEmptyCell( int WXUNUSED(row), int WXUNUSED(col) )
{
- return FALSE;
+ return false;
}
wxString BugsGridTable::GetValue( int row, int col )
{
if ( typeName == wxGRID_VALUE_STRING )
{
- return TRUE;
+ return true;
}
else if ( typeName == wxGRID_VALUE_BOOL )
{
}
else
{
- return FALSE;
+ return false;
}
}
{
wxFAIL_MSG(_T("unexpected column"));
- return FALSE;
+ return false;
}
}
return headers[col];
}
-BugsGridTable::BugsGridTable()
-{
-}
-
// ----------------------------------------------------------------------------
// BugsGridFrame
// ----------------------------------------------------------------------------
BugsGridFrame::BugsGridFrame()
- : wxFrame(NULL, -1, _T("Bugs table"),
+ : wxFrame(NULL, wxID_ANY, _T("Bugs table"),
wxDefaultPosition, wxSize(500, 300))
{
- wxGrid *grid = new wxGrid(this, -1, wxDefaultPosition);
+ wxGrid *grid = new wxGrid(this, wxID_ANY, wxDefaultPosition);
wxGridTableBase *table = new BugsGridTable();
table->SetAttrProvider(new MyGridCellAttrProvider);
- grid->SetTable(table, TRUE);
+ grid->SetTable(table, true);
wxGridCellAttr *attrRO = new wxGridCellAttr,
*attrRangeEditor = new wxGridCellAttr,