#include "wx/grid.h"
#include "wx/headerctrl.h"
#include "wx/generic/gridctrl.h"
+#include "wx/generic/grideditors.h"
#include "griddemo.h"
+#ifndef __WXMSW__
+ #include "../sample.xpm"
+#endif
+
// ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
EVT_GRID_COL_SIZE( GridFrame::OnColSize )
EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
- EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged )
+ EVT_GRID_CELL_CHANGING( GridFrame::OnCellValueChanging )
+ EVT_GRID_CELL_CHANGED( GridFrame::OnCellValueChanged )
EVT_GRID_CELL_BEGIN_DRAG( GridFrame::OnCellBeginDrag )
EVT_GRID_EDITOR_SHOWN( GridFrame::OnEditorShown )
wxDefaultPosition,
wxDefaultSize )
{
+ SetIcon(wxICON(sample));
+
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"));
grid->SetCellAlignment(7, 1, wxALIGN_CENTRE, wxALIGN_CENTRE);
grid->SetCellValue(7, 1, _T("Big box!"));
+ // create a separator-like row: it's grey and it's non-resizeable
+ grid->DisableRowResize(10);
+ grid->SetRowSize(10, 30);
+ attr = new wxGridCellAttr;
+ attr->SetBackgroundColour(*wxLIGHT_GREY);
+ grid->SetRowAttr(10, attr);
+ grid->SetCellValue(10, 0, "You can't resize this row interactively -- try it");
+
// this does exactly nothing except testing that SetAttr() handles NULL
// attributes and does reference counting correctly
grid->SetAttr(11, 11, NULL);
void GridFrame::OnRowSize( wxGridSizeEvent& ev )
{
- wxLogMessage(_T("Resized row %d"), ev.GetRowOrCol());
+ const int row = ev.GetRowOrCol();
+
+ wxLogMessage("Resized row %d, new height = %d",
+ row, grid->GetRowSize(row));
ev.Skip();
}
void GridFrame::OnColSize( wxGridSizeEvent& ev )
{
- wxLogMessage(_T("Resized col %d"), ev.GetRowOrCol());
+ const int col = ev.GetRowOrCol();
+
+ wxLogMessage("Resized column %d, new width = %d",
+ col, grid->GetColSize(col));
ev.Skip();
}
ev.Skip();
}
+void GridFrame::OnCellValueChanging( wxGridEvent& ev )
+{
+ int row = ev.GetRow(),
+ col = ev.GetCol();
+
+ wxLogMessage("Value of cell at (%d, %d): about to change "
+ "from \"%s\" to \"%s\"",
+ row, col,
+ grid->GetCellValue(row, col), ev.GetString());
+
+ // test how vetoing works
+ if ( ev.GetString() == "42" )
+ {
+ wxLogMessage("Vetoing the change.");
+ ev.Veto();
+ return;
+ }
+
+ ev.Skip();
+}
+
void GridFrame::OnCellValueChanged( wxGridEvent& ev )
{
int row = ev.GetRow(),
col = ev.GetCol();
- wxLogMessage(_T("Value changed for cell at row %d, col %d: now \"%s\""),
- row, col, grid->GetCellValue(row, col).c_str());
+ wxLogMessage("Value of cell at (%d, %d) changed and is now \"%s\" "
+ "(was \"%s\")",
+ row, col,
+ grid->GetCellValue(row, col), ev.GetString());
ev.Skip();
}
aboutInfo.AddDeveloper(wxT("Julian Smart"));
aboutInfo.AddDeveloper(wxT("Vadim Zeitlin"));
+ // this is just to force the generic version of the about
+ // dialog under wxMSW so that it's easy to test if the grid
+ // repaints correctly when it has lost focus and a dialog
+ // (different from the Windows standard message box -- it doesn't
+ // work with it for some reason) is moved over it.
+ aboutInfo.SetWebSite(wxT("http://www.wxwidgets.org"));
+
wxAboutBox(aboutInfo);
}
// fla for EVT_IDLE handler
bool m_shouldUpdateOrder;
- DECLARE_NO_COPY_CLASS(TabularGridFrame)
+ wxDECLARE_NO_COPY_CLASS(TabularGridFrame);
DECLARE_EVENT_TABLE()
};
{
new TabularGridFrame;
}
-