]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/grid/griddemo.cpp
don't use deprecated toolbar API
[wxWidgets.git] / samples / grid / griddemo.cpp
index af1a576dae0af3269cd903c78676d3f2f44bb9cd..2cd20c56d4f05b8391fadfce7de52e38ce93efd5 100644 (file)
@@ -2,7 +2,7 @@
 // Name:        griddemo.cpp
 // Purpose:     Grid control wxWidgets sample
 // Author:      Michael Bedward
 // Name:        griddemo.cpp
 // Purpose:     Grid control wxWidgets sample
 // Author:      Michael Bedward
-// Modified by:
+// Modified by: Santiago Palacios
 // RCS-ID:      $Id$
 // Copyright:   (c) Michael Bedward, Julian Smart, Vadim Zeitlin
 // Licence:     wxWindows license
 // RCS-ID:      $Id$
 // Copyright:   (c) Michael Bedward, Julian Smart, Vadim Zeitlin
 // Licence:     wxWindows license
 // headers
 // ----------------------------------------------------------------------------
 
 // headers
 // ----------------------------------------------------------------------------
 
-#if defined(__GNUG__) && !defined(__APPLE__)
-    #pragma implementation
-    #pragma interface
-#endif
-
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 
@@ -73,6 +68,7 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
     EVT_MENU( ID_TOGGLEEDIT, GridFrame::ToggleEditing )
     EVT_MENU( ID_TOGGLEROWSIZING, GridFrame::ToggleRowSizing )
     EVT_MENU( ID_TOGGLECOLSIZING, GridFrame::ToggleColSizing )
     EVT_MENU( ID_TOGGLEEDIT, GridFrame::ToggleEditing )
     EVT_MENU( ID_TOGGLEROWSIZING, GridFrame::ToggleRowSizing )
     EVT_MENU( ID_TOGGLECOLSIZING, GridFrame::ToggleColSizing )
+    EVT_MENU( ID_TOGGLECOLMOVING, GridFrame::ToggleColMoving )
     EVT_MENU( ID_TOGGLEGRIDSIZING, GridFrame::ToggleGridSizing )
     EVT_MENU( ID_TOGGLEGRIDDRAGCELL, GridFrame::ToggleGridDragCell )
     EVT_MENU( ID_TOGGLEGRIDLINES, GridFrame::ToggleGridLines )
     EVT_MENU( ID_TOGGLEGRIDSIZING, GridFrame::ToggleGridSizing )
     EVT_MENU( ID_TOGGLEGRIDDRAGCELL, GridFrame::ToggleGridDragCell )
     EVT_MENU( ID_TOGGLEGRIDLINES, GridFrame::ToggleGridLines )
@@ -99,11 +95,12 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
     EVT_MENU( ID_SET_CELL_FG_COLOUR, GridFrame::SetCellFgColour )
     EVT_MENU( ID_SET_CELL_BG_COLOUR, GridFrame::SetCellBgColour )
 
     EVT_MENU( ID_SET_CELL_FG_COLOUR, GridFrame::SetCellFgColour )
     EVT_MENU( ID_SET_CELL_BG_COLOUR, GridFrame::SetCellBgColour )
 
-    EVT_MENU( ID_ABOUT, GridFrame::About )
+    EVT_MENU( wxID_ABOUT, GridFrame::About )
     EVT_MENU( wxID_EXIT, GridFrame::OnQuit )
     EVT_MENU( ID_VTABLE, GridFrame::OnVTable)
     EVT_MENU( ID_BUGS_TABLE, GridFrame::OnBugsTable)
     EVT_MENU( ID_SMALL_GRID, GridFrame::OnSmallGrid)
     EVT_MENU( wxID_EXIT, GridFrame::OnQuit )
     EVT_MENU( ID_VTABLE, GridFrame::OnVTable)
     EVT_MENU( ID_BUGS_TABLE, GridFrame::OnBugsTable)
     EVT_MENU( ID_SMALL_GRID, GridFrame::OnSmallGrid)
+    EVT_MENU( ID_TABULAR_GRID, GridFrame::OnTabularGrid)
 
     EVT_MENU( ID_DESELECT_CELL, GridFrame::DeselectCell)
     EVT_MENU( ID_DESELECT_COL, GridFrame::DeselectCol)
 
     EVT_MENU( ID_DESELECT_CELL, GridFrame::DeselectCell)
     EVT_MENU( ID_DESELECT_COL, GridFrame::DeselectCol)
@@ -114,6 +111,15 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
     EVT_MENU( ID_SELECT_ROW, GridFrame::SelectRow)
     EVT_MENU( ID_SELECT_ALL, GridFrame::SelectAll)
     EVT_MENU( ID_SELECT_UNSELECT, GridFrame::OnAddToSelectToggle)
     EVT_MENU( ID_SELECT_ROW, GridFrame::SelectRow)
     EVT_MENU( ID_SELECT_ALL, GridFrame::SelectAll)
     EVT_MENU( ID_SELECT_UNSELECT, GridFrame::OnAddToSelectToggle)
+    EVT_MENU( ID_SHOW_SELECTION, GridFrame::OnShowSelection)
+
+    EVT_MENU( ID_SIZE_ROW, GridFrame::AutoSizeRow )
+    EVT_MENU( ID_SIZE_COL, GridFrame::AutoSizeCol )
+    EVT_MENU( ID_SIZE_ROW_LABEL, GridFrame::AutoSizeRowLabel )
+    EVT_MENU( ID_SIZE_COL_LABEL, GridFrame::AutoSizeColLabel )
+    EVT_MENU( ID_SIZE_LABELS_COL, GridFrame::AutoSizeLabelsCol )
+    EVT_MENU( ID_SIZE_LABELS_ROW, GridFrame::AutoSizeLabelsRow )
+    EVT_MENU( ID_SIZE_GRID, GridFrame::AutoSizeTable )
 
     EVT_MENU( ID_SET_HIGHLIGHT_WIDTH, GridFrame::OnSetHighlightWidth)
     EVT_MENU( ID_SET_RO_HIGHLIGHT_WIDTH, GridFrame::OnSetROHighlightWidth)
 
     EVT_MENU( ID_SET_HIGHLIGHT_WIDTH, GridFrame::OnSetHighlightWidth)
     EVT_MENU( ID_SET_RO_HIGHLIGHT_WIDTH, GridFrame::OnSetROHighlightWidth)
@@ -141,6 +147,7 @@ GridFrame::GridFrame()
     fileMenu->Append( ID_VTABLE, _T("&Virtual table test\tCtrl-V"));
     fileMenu->Append( ID_BUGS_TABLE, _T("&Bugs table test\tCtrl-B"));
     fileMenu->Append( ID_SMALL_GRID, _T("&Small Grid test\tCtrl-S"));
     fileMenu->Append( ID_VTABLE, _T("&Virtual table test\tCtrl-V"));
     fileMenu->Append( ID_BUGS_TABLE, _T("&Bugs table test\tCtrl-B"));
     fileMenu->Append( ID_SMALL_GRID, _T("&Small Grid test\tCtrl-S"));
+    fileMenu->Append( ID_TABULAR_GRID, _T("&Tabular Grid test\tCtrl-T"));
     fileMenu->AppendSeparator();
     fileMenu->Append( wxID_EXIT, _T("E&xit\tAlt-X") );
 
     fileMenu->AppendSeparator();
     fileMenu->Append( wxID_EXIT, _T("E&xit\tAlt-X") );
 
@@ -150,6 +157,7 @@ GridFrame::GridFrame()
     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_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_TOGGLECOLMOVING, _T("Col drag-&move"), 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_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 );
@@ -196,10 +204,14 @@ GridFrame::GridFrame()
     selectMenu->Append( ID_SELECT_UNSELECT, _T("Add new cells to the selection"),
                         _T("When off, old selection is deselected before ")
                         _T("selecting the new cells"), wxITEM_CHECK );
     selectMenu->Append( ID_SELECT_UNSELECT, _T("Add new cells to the selection"),
                         _T("When off, old selection is deselected before ")
                         _T("selecting the new cells"), wxITEM_CHECK );
+    selectMenu->Append( ID_SHOW_SELECTION,
+                        _T("&Show current selection\tCtrl-Alt-S"));
+    selectMenu->AppendSeparator();
     selectMenu->Append( ID_SELECT_ALL, _T("Select all"));
     selectMenu->Append( ID_SELECT_ROW, _T("Select row 2"));
     selectMenu->Append( ID_SELECT_COL, _T("Select col 2"));
     selectMenu->Append( ID_SELECT_CELL, _T("Select cell (3, 1)"));
     selectMenu->Append( ID_SELECT_ALL, _T("Select all"));
     selectMenu->Append( ID_SELECT_ROW, _T("Select row 2"));
     selectMenu->Append( ID_SELECT_COL, _T("Select col 2"));
     selectMenu->Append( ID_SELECT_CELL, _T("Select cell (3, 1)"));
+    selectMenu->AppendSeparator();
     selectMenu->Append( ID_DESELECT_ALL, _T("Deselect all"));
     selectMenu->Append( ID_DESELECT_ROW, _T("Deselect row 2"));
     selectMenu->Append( ID_DESELECT_COL, _T("Deselect col 2"));
     selectMenu->Append( ID_DESELECT_ALL, _T("Deselect all"));
     selectMenu->Append( ID_DESELECT_ROW, _T("Deselect row 2"));
     selectMenu->Append( ID_DESELECT_COL, _T("Deselect col 2"));
@@ -213,9 +225,17 @@ GridFrame::GridFrame()
     selectionMenu->Append( ID_SELROWS, _T("Select &Rows") );
     selectionMenu->Append( ID_SELCOLS, _T("Select C&ols") );
 
     selectionMenu->Append( ID_SELROWS, _T("Select &Rows") );
     selectionMenu->Append( ID_SELCOLS, _T("Select C&ols") );
 
+    wxMenu *autosizeMenu = new wxMenu;
+    autosizeMenu->Append( ID_SIZE_ROW, _T("Selected &row data") );
+    autosizeMenu->Append( ID_SIZE_COL, _T("Selected &column data") );
+    autosizeMenu->Append( ID_SIZE_ROW_LABEL, _T("Selected row la&bel") );
+    autosizeMenu->Append( ID_SIZE_COL_LABEL, _T("Selected column &label") );
+    autosizeMenu->Append( ID_SIZE_LABELS_COL, _T("Column la&bels") );
+    autosizeMenu->Append( ID_SIZE_LABELS_ROW, _T("Row label&s") );
+    autosizeMenu->Append( ID_SIZE_GRID, _T("Entire &grid") );
 
     wxMenu *helpMenu = new wxMenu;
 
     wxMenu *helpMenu = new wxMenu;
-    helpMenu->Append( ID_ABOUT, _T("&About wxGrid demo") );
+    helpMenu->Append( wxID_ABOUT, _T("&About wxGrid demo") );
 
     wxMenuBar *menuBar = new wxMenuBar;
     menuBar->Append( fileMenu, _T("&File") );
 
     wxMenuBar *menuBar = new wxMenuBar;
     menuBar->Append( fileMenu, _T("&File") );
@@ -223,6 +243,7 @@ GridFrame::GridFrame()
     menuBar->Append( colMenu,  _T("&Colours") );
     menuBar->Append( editMenu, _T("&Edit") );
     menuBar->Append( selectMenu, _T("&Select") );
     menuBar->Append( colMenu,  _T("&Colours") );
     menuBar->Append( editMenu, _T("&Edit") );
     menuBar->Append( selectMenu, _T("&Select") );
+    menuBar->Append( autosizeMenu, _T("&Autosize") );
     menuBar->Append( helpMenu, _T("&Help") );
 
     SetMenuBar( menuBar );
     menuBar->Append( helpMenu, _T("&Help") );
 
     SetMenuBar( menuBar );
@@ -247,7 +268,7 @@ GridFrame::GridFrame()
 
     logger = new wxLogTextCtrl( logWin );
     m_logOld = wxLog::SetActiveTarget( logger );
 
     logger = new wxLogTextCtrl( logWin );
     m_logOld = wxLog::SetActiveTarget( logger );
-    wxLog::SetTimestamp( NULL );
+    wxLog::DisableTimestamp();
 #endif // wxUSE_LOG
 
     // this will create a grid and, by default, an associated grid
 #endif // wxUSE_LOG
 
     // this will create a grid and, by default, an associated grid
@@ -295,7 +316,6 @@ GridFrame::GridFrame()
     grid->SetCellAlignment(4, 4, wxALIGN_CENTRE, wxALIGN_CENTRE);
     grid->SetCellRenderer(4, 4, new MyGridCellRenderer);
 
     grid->SetCellAlignment(4, 4, wxALIGN_CENTRE, wxALIGN_CENTRE);
     grid->SetCellRenderer(4, 4, new MyGridCellRenderer);
 
-    grid->SetCellValue(3, 0, _T("0"));
     grid->SetCellRenderer(3, 0, new wxGridCellBoolRenderer);
     grid->SetCellEditor(3, 0, new wxGridCellBoolEditor);
 
     grid->SetCellRenderer(3, 0, new wxGridCellBoolRenderer);
     grid->SetCellEditor(3, 0, new wxGridCellBoolEditor);
 
@@ -316,14 +336,19 @@ GridFrame::GridFrame()
     grid->SetCellValue(5, 5, _T("Bg from row attr Text col from col attr and this text is so long that it covers over many many empty cells but is broken by one that isn't"));
 
     grid->SetColFormatFloat(6);
     grid->SetCellValue(5, 5, _T("Bg from row attr Text col from col attr and this text is so long that it covers over many many empty cells but is broken by one that isn't"));
 
     grid->SetColFormatFloat(6);
-    grid->SetCellValue(0, 6, _T("3.1415"));
-    grid->SetCellValue(1, 6, _T("1415"));
-    grid->SetCellValue(2, 6, _T("12345.67890"));
+    grid->SetCellValue(0, 6, wxString::Format(wxT("%g"), 3.1415));
+    grid->SetCellValue(1, 6, wxString::Format(wxT("%g"), 1415.0));
+    grid->SetCellValue(2, 6, wxString::Format(wxT("%g"), 12345.67890));
 
     grid->SetColFormatFloat(7, 6, 2);
 
     grid->SetColFormatFloat(7, 6, 2);
-    grid->SetCellValue(0, 7, _T("3.1415"));
-    grid->SetCellValue(1, 7, _T("1415"));
-    grid->SetCellValue(2, 7, _T("12345.67890"));
+    grid->SetCellValue(0, 7, wxString::Format(wxT("%g"), 3.1415));
+    grid->SetCellValue(1, 7, wxString::Format(wxT("%g"), 1415.0));
+    grid->SetCellValue(2, 7, wxString::Format(wxT("%g"), 12345.67890));
+
+    grid->SetColFormatNumber(8);
+    grid->SetCellValue(0, 8, "17");
+    grid->SetCellValue(1, 8, "0");
+    grid->SetCellValue(2, 8, "-666");
 
     const wxString choices[] =
     {
 
     const wxString choices[] =
     {
@@ -340,6 +365,12 @@ GridFrame::GridFrame()
     grid->SetCellAlignment(7, 1, wxALIGN_CENTRE, wxALIGN_CENTRE);
     grid->SetCellValue(7, 1, _T("Big box!"));
 
     grid->SetCellAlignment(7, 1, wxALIGN_CENTRE, wxALIGN_CENTRE);
     grid->SetCellValue(7, 1, _T("Big box!"));
 
+    // this does exactly nothing except testing that SetAttr() handles NULL
+    // attributes and does reference counting correctly
+    grid->SetAttr(11, 11, NULL);
+    grid->SetAttr(11, 11, new wxGridCellAttr);
+    grid->SetAttr(11, 11, NULL);
+
     wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
     topSizer->Add( grid,
                    1,
     wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
     topSizer->Add( grid,
                    1,
@@ -351,10 +382,7 @@ GridFrame::GridFrame()
                    wxEXPAND );
 #endif // wxUSE_LOG
 
                    wxEXPAND );
 #endif // wxUSE_LOG
 
-    SetAutoLayout(true);
-    SetSizer( topSizer );
-
-    topSizer->Fit( this );
+    SetSizerAndFit( topSizer );
 
     Centre();
     SetDefaults();
 
     Centre();
     SetDefaults();
@@ -376,6 +404,7 @@ void GridFrame::SetDefaults()
     GetMenuBar()->Check( ID_TOGGLEEDIT, true );
     GetMenuBar()->Check( ID_TOGGLEROWSIZING, true );
     GetMenuBar()->Check( ID_TOGGLECOLSIZING, true );
     GetMenuBar()->Check( ID_TOGGLEEDIT, true );
     GetMenuBar()->Check( ID_TOGGLEROWSIZING, true );
     GetMenuBar()->Check( ID_TOGGLECOLSIZING, true );
+    GetMenuBar()->Check( ID_TOGGLECOLMOVING, false );
     GetMenuBar()->Check( ID_TOGGLEGRIDSIZING, true );
     GetMenuBar()->Check( ID_TOGGLEGRIDDRAGCELL, false );
     GetMenuBar()->Check( ID_TOGGLEGRIDLINES, true );
     GetMenuBar()->Check( ID_TOGGLEGRIDSIZING, true );
     GetMenuBar()->Check( ID_TOGGLEGRIDDRAGCELL, false );
     GetMenuBar()->Check( ID_TOGGLEGRIDLINES, true );
@@ -429,6 +458,12 @@ void GridFrame::ToggleColSizing( wxCommandEvent& WXUNUSED(ev) )
         GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING ) );
 }
 
         GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING ) );
 }
 
+void GridFrame::ToggleColMoving( wxCommandEvent& WXUNUSED(ev) )
+{
+    grid->EnableDragColMove(
+        GetMenuBar()->IsChecked( ID_TOGGLECOLMOVING ) );
+}
+
 void GridFrame::ToggleGridSizing( wxCommandEvent& WXUNUSED(ev) )
 {
     grid->EnableDragGridSize(
 void GridFrame::ToggleGridSizing( wxCommandEvent& WXUNUSED(ev) )
 {
     grid->EnableDragGridSize(
@@ -659,28 +694,86 @@ void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) )
 {
     if ( grid->IsSelection() )
     {
 {
     if ( grid->IsSelection() )
     {
-        grid->BeginBatch();
+        wxGridUpdateLocker locker(grid);
         for ( int n = 0; n < grid->GetNumberRows(); )
         for ( int n = 0; n < grid->GetNumberRows(); )
+        {
             if ( grid->IsInSelection( n , 0 ) )
                 grid->DeleteRows( n, 1 );
             if ( grid->IsInSelection( n , 0 ) )
                 grid->DeleteRows( n, 1 );
-        else
-            n++;
-        grid->EndBatch();
+            else
+                n++;
+        }
     }
 }
 
 
     }
 }
 
 
+void GridFrame::AutoSizeRow(wxCommandEvent& WXUNUSED(event))
+{
+    wxGridUpdateLocker locker(grid);
+    const wxArrayInt sels  = grid->GetSelectedRows();
+    for ( size_t n = 0, count = sels.size(); n < count; n++ )
+    {
+        grid->AutoSizeRow( sels[n], false );
+    }
+}
+
+void GridFrame::AutoSizeCol(wxCommandEvent& WXUNUSED(event))
+{
+    wxGridUpdateLocker locker(grid);
+    const wxArrayInt sels  = grid->GetSelectedCols();
+    for ( size_t n = 0, count = sels.size(); n < count; n++ )
+    {
+        grid->AutoSizeColumn( sels[n], false );
+    }
+}
+
+void GridFrame::AutoSizeRowLabel(wxCommandEvent& WXUNUSED(event))
+{
+    wxGridUpdateLocker locker(grid);
+    const wxArrayInt sels  = grid->GetSelectedRows();
+    for ( size_t n = 0, count = sels.size(); n < count; n++ )
+    {
+        grid->AutoSizeRowLabelSize( sels[n] );
+    }
+}
+
+void GridFrame::AutoSizeColLabel(wxCommandEvent& WXUNUSED(event))
+{
+    wxGridUpdateLocker locker(grid);
+    const wxArrayInt sels  = grid->GetSelectedCols();
+    for ( size_t n = 0, count = sels.size(); n < count; n++ )
+    {
+        grid->AutoSizeColLabelSize( sels[n] );
+    }
+}
+
+void GridFrame::AutoSizeLabelsCol(wxCommandEvent& WXUNUSED(event))
+{
+    grid->SetColLabelSize( wxGRID_AUTOSIZE );
+}
+
+void GridFrame::AutoSizeLabelsRow(wxCommandEvent& WXUNUSED(event))
+{
+    grid->SetRowLabelSize( wxGRID_AUTOSIZE );
+}
+
+void GridFrame::AutoSizeTable(wxCommandEvent& WXUNUSED(event))
+{
+    grid->AutoSize();
+}
+
+
 void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) )
 {
     if ( grid->IsSelection() )
     {
 void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) )
 {
     if ( grid->IsSelection() )
     {
-        grid->BeginBatch();
+        wxGridUpdateLocker locker(grid);
         for ( int n = 0; n < grid->GetNumberCols(); )
         for ( int n = 0; n < grid->GetNumberCols(); )
+        {
             if ( grid->IsInSelection( 0 , n ) )
                 grid->DeleteCols( n, 1 );
             if ( grid->IsInSelection( 0 , n ) )
                 grid->DeleteCols( n, 1 );
-        else
-            n++;
-        grid->EndBatch();
+            else
+                n++;
+        }
     }
 }
 
     }
 }
 
@@ -776,7 +869,7 @@ void GridFrame::OnAddToSelectToggle(wxCommandEvent& event)
 
 void GridFrame::OnLabelLeftClick( wxGridEvent& ev )
 {
 
 void GridFrame::OnLabelLeftClick( wxGridEvent& ev )
 {
-    logBuf = wxEmptyString;
+    wxString logBuf;
     if ( ev.GetRow() != -1 )
     {
         logBuf << _T("Left click on row label ") << ev.GetRow();
     if ( ev.GetRow() != -1 )
     {
         logBuf << _T("Left click on row label ") << ev.GetRow();
@@ -790,8 +883,10 @@ void GridFrame::OnLabelLeftClick( wxGridEvent& ev )
         logBuf << _T("Left click on corner label");
     }
 
         logBuf << _T("Left click on corner label");
     }
 
-    if ( ev.ShiftDown() ) logBuf << _T(" (shift down)");
-    if ( ev.ControlDown() ) logBuf << _T(" (control down)");
+    if ( ev.ShiftDown() )
+        logBuf << _T(" (shift down)");
+    if ( ev.ControlDown() )
+        logBuf << _T(" (control down)");
     wxLogMessage( wxT("%s"), logBuf.c_str() );
 
     // you must call event skip if you want default grid processing
     wxLogMessage( wxT("%s"), logBuf.c_str() );
 
     // you must call event skip if you want default grid processing
@@ -802,10 +897,7 @@ void GridFrame::OnLabelLeftClick( wxGridEvent& ev )
 
 void GridFrame::OnCellLeftClick( wxGridEvent& ev )
 {
 
 void GridFrame::OnCellLeftClick( wxGridEvent& ev )
 {
-    logBuf = wxEmptyString;
-    logBuf << _T("Left click at row ") << ev.GetRow()
-           << _T(" col ") << ev.GetCol();
-    wxLogMessage( wxT("%s"), logBuf.c_str() );
+    wxLogMessage(_T("Left click at row %d, col %d"), ev.GetRow(), ev.GetCol());
 
     // you must call event skip if you want default grid processing
     // (cell highlighting etc.)
 
     // you must call event skip if you want default grid processing
     // (cell highlighting etc.)
@@ -816,9 +908,7 @@ void GridFrame::OnCellLeftClick( wxGridEvent& ev )
 
 void GridFrame::OnRowSize( wxGridSizeEvent& ev )
 {
 
 void GridFrame::OnRowSize( wxGridSizeEvent& ev )
 {
-    logBuf = wxEmptyString;
-    logBuf << _T("Resized row ") << ev.GetRowOrCol();
-    wxLogMessage( wxT("%s"), logBuf.c_str() );
+    wxLogMessage(_T("Resized row %d"), ev.GetRowOrCol());
 
     ev.Skip();
 }
 
     ev.Skip();
 }
@@ -826,17 +916,91 @@ void GridFrame::OnRowSize( wxGridSizeEvent& ev )
 
 void GridFrame::OnColSize( wxGridSizeEvent& ev )
 {
 
 void GridFrame::OnColSize( wxGridSizeEvent& ev )
 {
-    logBuf = wxEmptyString;
-    logBuf << _T("Resized col ") << ev.GetRowOrCol();
-    wxLogMessage( wxT("%s"), logBuf.c_str() );
+    wxLogMessage(_T("Resized col %d"), ev.GetRowOrCol());
 
     ev.Skip();
 }
 
 
 
     ev.Skip();
 }
 
 
+void GridFrame::OnShowSelection(wxCommandEvent& WXUNUSED(event))
+{
+    // max number of elements to dump -- otherwise it can take too much time
+    static const size_t countMax = 100;
+
+    bool rows = false;
+
+    switch ( grid->GetSelectionMode() )
+    {
+        case wxGrid::wxGridSelectCells:
+            {
+                const wxGridCellCoordsArray cells(grid->GetSelectedCells());
+                size_t count = cells.size();
+                wxLogMessage(_T("%lu cells selected:"), (unsigned long)count);
+                if ( count > countMax )
+                {
+                    wxLogMessage(_T("[too many selected cells, ")
+                                 _T("showing only the first %lu]"),
+                                 (unsigned long)countMax);
+                    count = countMax;
+                }
+
+                for ( size_t n = 0; n < count; n++ )
+                {
+                    const wxGridCellCoords& c = cells[n];
+                    wxLogMessage(_T("  selected cell %lu: (%d, %d)"),
+                                 (unsigned long)n, c.GetCol(), c.GetRow());
+                }
+            }
+            break;
+
+        case wxGrid::wxGridSelectRows:
+            rows = true;
+            // fall through
+
+        case wxGrid::wxGridSelectColumns:
+            {
+                const wxChar *plural, *single;
+                if ( rows )
+                {
+                    plural = _T("rows");
+                    single = _T("row");
+                }
+                else // columns
+                {
+                    plural = _T("columns");
+                    single = _T("column");
+                }
+
+                const wxArrayInt sels((const wxArrayInt)(rows ? grid->GetSelectedRows()
+                                           : grid->GetSelectedCols()));
+                size_t count = sels.size();
+                wxLogMessage(_T("%lu %s selected:"),
+                             (unsigned long)count, plural);
+                if ( count > countMax )
+                {
+                    wxLogMessage(_T("[too many selected %s, ")
+                                 _T("showing only the first %lu]"),
+                                 plural, (unsigned long)countMax);
+                    count = countMax;
+                }
+
+                for ( size_t n = 0; n < count; n++ )
+                {
+                    wxLogMessage(_T("  selected %s %lu: %d"),
+                                 single, (unsigned long)n, sels[n]);
+                }
+            }
+            break;
+
+        default:
+            wxFAIL_MSG( _T("unknown wxGrid selection mode") );
+            break;
+    }
+}
+
 void GridFrame::OnSelectCell( wxGridEvent& ev )
 {
 void GridFrame::OnSelectCell( wxGridEvent& ev )
 {
-    logBuf = wxEmptyString;
+    wxString logBuf;
     if ( ev.Selecting() )
         logBuf << _T("Selected ");
     else
     if ( ev.Selecting() )
         logBuf << _T("Selected ");
     else
@@ -847,6 +1011,11 @@ void GridFrame::OnSelectCell( wxGridEvent& ev )
            << _T(", ShiftDown: ")<< (ev.ShiftDown() ? 'T':'F')
            << _T(", AltDown: ")<< (ev.AltDown() ? 'T':'F')
            << _T(", MetaDown: ")<< (ev.MetaDown() ? 'T':'F') << _T(" )");
            << _T(", ShiftDown: ")<< (ev.ShiftDown() ? 'T':'F')
            << _T(", AltDown: ")<< (ev.AltDown() ? 'T':'F')
            << _T(", MetaDown: ")<< (ev.MetaDown() ? 'T':'F') << _T(" )");
+
+    //Indicate whether this column was moved
+    if ( ((wxGrid *)ev.GetEventObject())->GetColPos( ev.GetCol() ) != ev.GetCol() )
+        logBuf << _T(" *** Column moved, current position: ") << ((wxGrid *)ev.GetEventObject())->GetColPos( ev.GetCol() );
+
     wxLogMessage( wxT("%s"), logBuf.c_str() );
 
     // you must call Skip() if you want the default processing
     wxLogMessage( wxT("%s"), logBuf.c_str() );
 
     // you must call Skip() if you want the default processing
@@ -856,7 +1025,7 @@ void GridFrame::OnSelectCell( wxGridEvent& ev )
 
 void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev )
 {
 
 void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev )
 {
-    logBuf = wxEmptyString;
+    wxString logBuf;
     if ( ev.Selecting() )
         logBuf << _T("Selected ");
     else
     if ( ev.Selecting() )
         logBuf << _T("Selected ");
     else
@@ -876,24 +1045,19 @@ void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev )
 
 void GridFrame::OnCellValueChanged( wxGridEvent& ev )
 {
 
 void GridFrame::OnCellValueChanged( wxGridEvent& ev )
 {
-    logBuf = wxEmptyString;
-    logBuf  << _T("Value changed for cell at")
-            << _T(" row ") << ev.GetRow()
-            << _T(" col ") << ev.GetCol();
+    int row = ev.GetRow(),
+        col = ev.GetCol();
 
 
-    wxLogMessage( wxT("%s"), logBuf.c_str() );
+    wxLogMessage(_T("Value changed for cell at row %d, col %d: now \"%s\""),
+                 row, col, grid->GetCellValue(row, col).c_str());
 
     ev.Skip();
 }
 
 void GridFrame::OnCellBeginDrag( wxGridEvent& ev )
 {
 
     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() );
+    wxLogMessage(_T("Got request to drag cell at row %d, col %d"),
+                 ev.GetRow(), ev.GetCol());
 
     ev.Skip();
 }
 
     ev.Skip();
 }
@@ -935,7 +1099,7 @@ void GridFrame::OnEditorHidden( wxGridEvent& ev )
 void GridFrame::About(  wxCommandEvent& WXUNUSED(ev) )
 {
     (void)wxMessageBox( _T("\n\nwxGrid demo \n\n")
 void GridFrame::About(  wxCommandEvent& WXUNUSED(ev) )
 {
     (void)wxMessageBox( _T("\n\nwxGrid demo \n\n")
-                        _T("Michael Bedward, Julian Small, Vadim Zeitlin"),
+                        _T("Michael Bedward, Julian Smart, Vadim Zeitlin"),
                         _T("About"),
                         wxOK );
 }
                         _T("About"),
                         wxOK );
 }
@@ -963,6 +1127,65 @@ void GridFrame::OnSmallGrid(wxCommandEvent& )
     frame->Show(true);
 }
 
     frame->Show(true);
 }
 
+// ----------------------------------------------------------------------------
+// MyGridCellAttrProvider
+// ----------------------------------------------------------------------------
+
+MyGridCellAttrProvider::MyGridCellAttrProvider()
+{
+    m_attrForOddRows = new wxGridCellAttr;
+    m_attrForOddRows->SetBackgroundColour(*wxLIGHT_GREY);
+}
+
+MyGridCellAttrProvider::~MyGridCellAttrProvider()
+{
+    m_attrForOddRows->DecRef();
+}
+
+wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col,
+                           wxGridCellAttr::wxAttrKind  kind /* = wxGridCellAttr::Any */) const
+{
+    wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind);
+
+    if ( row % 2 )
+    {
+        if ( !attr )
+        {
+            attr = m_attrForOddRows;
+            attr->IncRef();
+        }
+        else
+        {
+            if ( !attr->HasBackgroundColour() )
+            {
+                wxGridCellAttr *attrNew = attr->Clone();
+                attr->DecRef();
+                attr = attrNew;
+                attr->SetBackgroundColour(*wxLIGHT_GREY);
+            }
+        }
+    }
+
+    return attr;
+}
+
+// ----------------------------------------------------------------------------
+
+void GridFrame::OnTabularGrid(wxCommandEvent& )
+{
+    wxFrame* frame = new wxFrame(NULL, wxID_ANY, _T("A small tabular Grid"),
+                                 wxDefaultPosition, wxSize(640, 480));
+    wxGrid* grid = new wxGrid(frame, wxID_ANY, wxPoint(10,10), wxSize(40,40),
+                              wxWANTS_CHARS | wxBORDER_SUNKEN);
+    grid->SetRowLabelSize( 0 );
+    grid->DisableDragRowSize();
+    grid->SetUseNativeColLabels();
+    grid->CreateGrid(10,10);
+    grid->SetSelectionMode( wxGrid::wxGridSelectRows );
+
+    frame->Show(true);
+}
+
 void GridFrame::OnVTable(wxCommandEvent& )
 {
     static long s_sizeGrid = 10000;
 void GridFrame::OnVTable(wxCommandEvent& )
 {
     static long s_sizeGrid = 10000;
@@ -1013,48 +1236,6 @@ void MyGridCellRenderer::Draw(wxGrid& grid,
     dc.DrawEllipse(rect);
 }
 
     dc.DrawEllipse(rect);
 }
 
-// ----------------------------------------------------------------------------
-// MyGridCellAttrProvider
-// ----------------------------------------------------------------------------
-
-MyGridCellAttrProvider::MyGridCellAttrProvider()
-{
-    m_attrForOddRows = new wxGridCellAttr;
-    m_attrForOddRows->SetBackgroundColour(*wxLIGHT_GREY);
-}
-
-MyGridCellAttrProvider::~MyGridCellAttrProvider()
-{
-    m_attrForOddRows->DecRef();
-}
-
-wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col,
-                           wxGridCellAttr::wxAttrKind  kind /* = wxGridCellAttr::Any */) const
-{
-    wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind);
-
-    if ( row % 2 )
-    {
-        if ( !attr )
-        {
-            attr = m_attrForOddRows;
-            attr->IncRef();
-        }
-        else
-        {
-            if ( !attr->HasBackgroundColour() )
-            {
-                wxGridCellAttr *attrNew = attr->Clone();
-                attr->DecRef();
-                attr = attrNew;
-                attr->SetBackgroundColour(*wxLIGHT_GREY);
-            }
-        }
-    }
-
-    return attr;
-}
-
 // ============================================================================
 // BigGridFrame and BigGridTable:  Sample of a non-standard table
 // ============================================================================
 // ============================================================================
 // BigGridFrame and BigGridTable:  Sample of a non-standard table
 // ============================================================================
@@ -1360,8 +1541,7 @@ wxString BugsGridTable::GetColLabelValue( int col )
 // ----------------------------------------------------------------------------
 
 BugsGridFrame::BugsGridFrame()
 // ----------------------------------------------------------------------------
 
 BugsGridFrame::BugsGridFrame()
-             : wxFrame(NULL, wxID_ANY, _T("Bugs table"),
-                       wxDefaultPosition, wxSize(500, 300))
+             : wxFrame(NULL, wxID_ANY, _T("Bugs table"))
 {
     wxGrid *grid = new wxGrid(this, wxID_ANY, wxDefaultPosition);
     wxGridTableBase *table = new BugsGridTable();
 {
     wxGrid *grid = new wxGrid(this, wxID_ANY, wxDefaultPosition);
     wxGridTableBase *table = new BugsGridTable();
@@ -1381,8 +1561,6 @@ BugsGridFrame::BugsGridFrame()
     grid->SetColAttr(Col_Priority, attrRangeEditor);
     grid->SetColAttr(Col_Severity, attrCombo);
 
     grid->SetColAttr(Col_Priority, attrRangeEditor);
     grid->SetColAttr(Col_Severity, attrCombo);
 
-    grid->SetMargins(0, 0);
-
     grid->Fit();
     SetClientSize(grid->GetSize());
 }
     grid->Fit();
     SetClientSize(grid->GetSize());
 }