]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/grid/griddemo.cpp
updated aui sample to demonstrate/test wxITEM_RADIO support in toolbars
[wxWidgets.git] / samples / grid / griddemo.cpp
index 8ea628b1c59f20eea81a40f9336667b4c6bff6cc..c485fdfe4d15e8706a50474d1d5b0319875552f9 100644 (file)
 #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
 // ----------------------------------------------------------------------------
@@ -133,6 +138,7 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
     EVT_GRID_COL_SIZE( GridFrame::OnColSize )
     EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
     EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
+    EVT_GRID_CELL_CHANGING( GridFrame::OnCellValueChanging )
     EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged )
     EVT_GRID_CELL_BEGIN_DRAG( GridFrame::OnCellBeginDrag )
 
@@ -146,6 +152,8 @@ GridFrame::GridFrame()
                    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"));
@@ -1059,13 +1067,36 @@ void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev )
     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();
 }
@@ -1121,6 +1152,13 @@ void GridFrame::About(  wxCommandEvent& WXUNUSED(ev) )
     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);
 }
 
@@ -1746,7 +1784,8 @@ private:
         int col = m_txtColShowHide->GetCol();
         if ( col != -1 )
         {
-            m_grid->SetColSize(col, event.GetId() == wxID_ADD ? -1 : 0);
+            m_grid->SetColSize(col,
+                               event.GetId() == wxID_ADD ? wxGRID_AUTOSIZE : 0);
 
             UpdateOrderAndVisibility();
         }
@@ -1787,6 +1826,16 @@ private:
         event.Skip();
     }
 
+    void OnGridColSize(wxGridSizeEvent& event)
+    {
+        // we only catch this event to react to the user showing or hiding this
+        // column using the header control menu and not because we're
+        // interested in column resizing
+        UpdateOrderAndVisibility();
+
+        event.Skip();
+    }
+
     void OnIdle(wxIdleEvent& event)
     {
         if ( m_shouldUpdateOrder )
@@ -1798,20 +1847,6 @@ private:
         event.Skip();
     }
 
-    void OnColRightClick(wxHeaderCtrlEvent&)
-    {
-        int col = m_grid->GetGridColHeader()->ShowColumnsMenu("Columns:");
-        if ( col == wxID_NONE )
-            return;
-
-        if ( m_grid->IsColShown(col) )
-            m_grid->HideCol(col);
-        else
-            m_grid->ShowCol(col);
-
-        UpdateOrderAndVisibility();
-    }
-
     void UpdateOrderAndVisibility()
     {
         wxString s;
@@ -1849,7 +1884,7 @@ private:
     // fla for EVT_IDLE handler
     bool m_shouldUpdateOrder;
 
-    DECLARE_NO_COPY_CLASS(TabularGridFrame)
+    wxDECLARE_NO_COPY_CLASS(TabularGridFrame);
     DECLARE_EVENT_TABLE()
 };
 
@@ -1873,6 +1908,7 @@ BEGIN_EVENT_TABLE(TabularGridFrame, wxFrame)
 
     EVT_GRID_COL_SORT(TabularGridFrame::OnGridColSort)
     EVT_GRID_COL_MOVE(TabularGridFrame::OnGridColMove)
+    EVT_GRID_COL_SIZE(TabularGridFrame::OnGridColSize)
 
     EVT_IDLE(TabularGridFrame::OnIdle)
 END_EVENT_TABLE()
@@ -1895,14 +1931,6 @@ TabularGridFrame::TabularGridFrame()
     m_grid->UseNativeColHeader();
     m_grid->HideRowLabels();
 
-    m_grid->GetGridColHeader()->Connect
-        (
-            wxEVT_COMMAND_HEADER_RIGHT_CLICK,
-            wxHeaderCtrlEventHandler(TabularGridFrame::OnColRightClick),
-            NULL,
-            this
-        );
-
     // add it and the other controls to the frame
     wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
     sizerTop->Add(m_grid, wxSizerFlags(1).Expand().Border());
@@ -1979,4 +2007,3 @@ void GridFrame::OnTabularTable(wxCommandEvent&)
 {
     new TabularGridFrame;
 }
-