X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f7556ff05f5cf0a5be1e494a477fd463db4a9236..1695e2851de295b910fa741ff1d75a20efbc4db1:/samples/grid/griddemo.cpp diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index 31ff32bb5c..86f387a629 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // Name: griddemo.cpp -// Purpose: Grid control wxWindows sample +// Purpose: Grid control wxWidgets sample // Author: Michael Bedward // Modified by: // RCS-ID: $Id$ @@ -16,7 +16,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(__APPLE__) #pragma implementation #pragma interface #endif @@ -34,6 +34,7 @@ #include "wx/colordlg.h" #include "wx/fontdlg.h" +#include "wx/numdlg.h" #include "wx/grid.h" #include "wx/generic/gridctrl.h" @@ -57,9 +58,9 @@ IMPLEMENT_APP( GridApp ) bool GridApp::OnInit() { GridFrame *frame = new GridFrame; - frame->Show( TRUE ); + frame->Show(true); - return TRUE; + return true; } // ---------------------------------------------------------------------------- @@ -73,6 +74,7 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame ) 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 ) @@ -123,6 +125,7 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame ) 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 ) @@ -130,13 +133,10 @@ END_EVENT_TABLE() 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")); @@ -145,18 +145,19 @@ GridFrame::GridFrame() 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; @@ -226,15 +227,19 @@ GridFrame::GridFrame() 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 ), @@ -243,6 +248,7 @@ GridFrame::GridFrame() logger = new wxLogTextCtrl( logWin ); m_logOld = logger->SetActiveTarget( logger ); logger->SetTimestamp( NULL ); +#endif // wxUSE_LOG // this will create a grid and, by default, an associated grid // table for strings @@ -328,7 +334,7 @@ GridFrame::GridFrame() 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); @@ -339,15 +345,16 @@ GridFrame::GridFrame() 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(); @@ -356,20 +363,23 @@ GridFrame::GridFrame() 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 ); } @@ -425,6 +435,11 @@ void GridFrame::ToggleGridSizing( wxCommandEvent& WXUNUSED(ev) ) GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING ) ); } +void GridFrame::ToggleGridDragCell( wxCommandEvent& WXUNUSED(ev) ) +{ + grid->EnableDragCell( + GetMenuBar()->IsChecked( ID_TOGGLEGRIDDRAGCELL ) ); +} void GridFrame::ToggleGridLines( wxCommandEvent& WXUNUSED(ev) ) { @@ -539,7 +554,7 @@ void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) ) break; } - grid->SetRowLabelAlignment( horiz, -1 ); + grid->SetRowLabelAlignment( horiz, vert ); } void GridFrame::SetRowLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) ) @@ -562,7 +577,7 @@ void GridFrame::SetRowLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) ) break; } - grid->SetRowLabelAlignment( -1, vert ); + grid->SetRowLabelAlignment( horiz, vert ); } @@ -586,7 +601,7 @@ void GridFrame::SetColLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) ) break; } - grid->SetColLabelAlignment( horiz, -1 ); + grid->SetColLabelAlignment( horiz, vert ); } @@ -610,7 +625,7 @@ void GridFrame::SetColLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) ) break; } - grid->SetColLabelAlignment( -1, vert ); + grid->SetColLabelAlignment( horiz, vert ); } @@ -709,7 +724,7 @@ void GridFrame::SetCellBgColour( wxCommandEvent& WXUNUSED(ev) ) // which exactly fits the grid. wxRect r(wxPoint(0, 0), grid->GetSize()); grid->SetDefaultCellBackgroundColour(col); - grid->Refresh(TRUE, &r); + grid->Refresh(true, &r); } } @@ -760,7 +775,7 @@ void GridFrame::OnAddToSelectToggle(wxCommandEvent& event) void GridFrame::OnLabelLeftClick( wxGridEvent& ev ) { - logBuf = _T(""); + logBuf = wxEmptyString; if ( ev.GetRow() != -1 ) { logBuf << _T("Left click on row label ") << ev.GetRow(); @@ -786,7 +801,7 @@ void GridFrame::OnLabelLeftClick( wxGridEvent& ev ) 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() ); @@ -800,7 +815,7 @@ void GridFrame::OnCellLeftClick( wxGridEvent& ev ) void GridFrame::OnRowSize( wxGridSizeEvent& ev ) { - logBuf = _T(""); + logBuf = wxEmptyString; logBuf << _T("Resized row ") << ev.GetRowOrCol(); wxLogMessage( wxT("%s"), logBuf.c_str() ); @@ -810,7 +825,7 @@ void GridFrame::OnRowSize( wxGridSizeEvent& ev ) void GridFrame::OnColSize( wxGridSizeEvent& ev ) { - logBuf = _T(""); + logBuf = wxEmptyString; logBuf << _T("Resized col ") << ev.GetRowOrCol(); wxLogMessage( wxT("%s"), logBuf.c_str() ); @@ -820,7 +835,7 @@ void GridFrame::OnColSize( wxGridSizeEvent& ev ) void GridFrame::OnSelectCell( wxGridEvent& ev ) { - logBuf = _T(""); + logBuf = wxEmptyString; if ( ev.Selecting() ) logBuf << _T("Selected "); else @@ -840,7 +855,7 @@ void GridFrame::OnSelectCell( wxGridEvent& ev ) void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) { - logBuf = _T(""); + logBuf = wxEmptyString; if ( ev.Selecting() ) logBuf << _T("Selected "); else @@ -860,7 +875,7 @@ void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) void GridFrame::OnCellValueChanged( wxGridEvent& ev ) { - logBuf = _T(""); + logBuf = wxEmptyString; logBuf << _T("Value changed for cell at") << _T(" row ") << ev.GetRow() << _T(" col ") << ev.GetCol(); @@ -870,6 +885,18 @@ void GridFrame::OnCellValueChanged( 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() ); + + ev.Skip(); +} + void GridFrame::OnEditorShown( wxGridEvent& ev ) { @@ -916,24 +943,24 @@ void GridFrame::About( wxCommandEvent& WXUNUSED(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& ) @@ -961,7 +988,7 @@ void GridFrame::OnVTable(wxCommandEvent& ) if ( s_sizeGrid != -1 ) { BigGridFrame* win = new BigGridFrame(s_sizeGrid); - win->Show(TRUE); + win->Show(true); } } @@ -1033,17 +1060,17 @@ wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col, // ============================================================================ 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 @@ -1101,10 +1128,10 @@ static struct BugsGridData 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] = @@ -1157,9 +1184,9 @@ int BugsGridTable::GetNumberCols() 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 ) @@ -1234,7 +1261,7 @@ bool BugsGridTable::CanGetValueAs( int WXUNUSED(row), int col, const wxString& t { if ( typeName == wxGRID_VALUE_STRING ) { - return TRUE; + return true; } else if ( typeName == wxGRID_VALUE_BOOL ) { @@ -1246,7 +1273,7 @@ bool BugsGridTable::CanGetValueAs( int WXUNUSED(row), int col, const wxString& t } else { - return FALSE; + return false; } } @@ -1286,7 +1313,7 @@ bool BugsGridTable::GetValueAsBool( int row, int col ) { wxFAIL_MSG(_T("unexpected column")); - return FALSE; + return false; } } @@ -1331,13 +1358,13 @@ BugsGridTable::BugsGridTable() // ---------------------------------------------------------------------------- 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,