]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/grid/griddemo.cpp
don't use deprecated toolbar API
[wxWidgets.git] / samples / grid / griddemo.cpp
index 4ad34e9774fd33fd3725efa33319163f196b2f2e..2cd20c56d4f05b8391fadfce7de52e38ce93efd5 100644 (file)
@@ -100,6 +100,7 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
     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)
@@ -146,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_TABULAR_GRID, _T("&Tabular Grid test\tCtrl-T"));
     fileMenu->AppendSeparator();
     fileMenu->Append( wxID_EXIT, _T("E&xit\tAlt-X") );
 
@@ -334,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(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->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[] =
     {
@@ -358,6 +365,12 @@ GridFrame::GridFrame()
     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,
@@ -369,10 +382,7 @@ GridFrame::GridFrame()
                    wxEXPAND );
 #endif // wxUSE_LOG
 
-    SetAutoLayout(true);
-    SetSizer( topSizer );
-
-    topSizer->Fit( this );
+    SetSizerAndFit( topSizer );
 
     Centre();
     SetDefaults();
@@ -961,8 +971,8 @@ void GridFrame::OnShowSelection(wxCommandEvent& WXUNUSED(event))
                     single = _T("column");
                 }
 
-                const wxArrayInt sels(rows ? grid->GetSelectedRows()
-                                           : grid->GetSelectedCols());
+                const wxArrayInt sels((const wxArrayInt)(rows ? grid->GetSelectedRows()
+                                           : grid->GetSelectedCols()));
                 size_t count = sels.size();
                 wxLogMessage(_T("%lu %s selected:"),
                              (unsigned long)count, plural);
@@ -1117,6 +1127,65 @@ void GridFrame::OnSmallGrid(wxCommandEvent& )
     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;
@@ -1167,48 +1236,6 @@ void MyGridCellRenderer::Draw(wxGrid& grid,
     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
 // ============================================================================