X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/af870ed80f7cbfe49a0900c35310dedf82b06f63..da98e15760bfcad41a5579e64955caadc2e535f3:/samples/grid/griddemo.cpp diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index ff9f0c0841..74be937a4e 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -4,7 +4,7 @@ // Author: Michael Bedward // Modified by: // RCS-ID: $Id$ -// Copyright: (c) Michael Bedward, Julian Smart +// Copyright: (c) Michael Bedward, Julian Smart, Vadim Zeitlin // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// @@ -74,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 ) @@ -98,7 +99,7 @@ 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_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) @@ -124,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 ) @@ -135,9 +137,6 @@ GridFrame::GridFrame() 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")); @@ -146,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; @@ -215,7 +215,7 @@ GridFrame::GridFrame() 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") ); @@ -234,6 +234,10 @@ GridFrame::GridFrame() wxPoint( 0, 0 ), wxSize( 400, 300 ) ); +#if wxUSE_LOG + int gridW = 600, gridH = 300; + int logW = gridW, logH = 100; + logWin = new wxTextCtrl( this, wxID_ANY, wxEmptyString, @@ -242,8 +246,9 @@ GridFrame::GridFrame() wxTE_MULTILINE ); logger = new wxLogTextCtrl( logWin ); - m_logOld = logger->SetActiveTarget( logger ); - logger->SetTimestamp( NULL ); + m_logOld = wxLog::SetActiveTarget( logger ); + wxLog::SetTimestamp( NULL ); +#endif // wxUSE_LOG // this will create a grid and, by default, an associated grid // table for strings @@ -340,15 +345,16 @@ GridFrame::GridFrame() 1, wxEXPAND ); +#if wxUSE_LOG topSizer->Add( logWin, 0, wxEXPAND ); +#endif // wxUSE_LOG SetAutoLayout(true); SetSizer( topSizer ); topSizer->Fit( this ); - topSizer->SetSizeHints( this ); Centre(); SetDefaults(); @@ -357,7 +363,9 @@ GridFrame::GridFrame() GridFrame::~GridFrame() { +#if wxUSE_LOG delete wxLog::SetActiveTarget(m_logOld); +#endif // wxUSE_LOG } @@ -369,6 +377,7 @@ void GridFrame::SetDefaults() 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 ); } @@ -426,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) ) { @@ -647,10 +661,12 @@ void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) ) { grid->BeginBatch(); for ( int n = 0; n < grid->GetNumberRows(); ) + { if ( grid->IsInSelection( n , 0 ) ) grid->DeleteRows( n, 1 ); - else - n++; + else + n++; + } grid->EndBatch(); } } @@ -662,10 +678,12 @@ void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) ) { grid->BeginBatch(); for ( int n = 0; n < grid->GetNumberCols(); ) + { if ( grid->IsInSelection( 0 , n ) ) grid->DeleteCols( n, 1 ); - else - n++; + else + n++; + } grid->EndBatch(); } } @@ -708,7 +726,8 @@ void GridFrame::SetCellBgColour( wxCommandEvent& WXUNUSED(ev) ) { // Check the new Refresh function by passing it a rectangle // which exactly fits the grid. - wxRect r(wxPoint(0, 0), grid->GetSize()); + wxPoint pt(0, 0); + wxRect r(pt, grid->GetSize()); grid->SetDefaultCellBackgroundColour(col); grid->Refresh(true, &r); } @@ -761,7 +780,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(); @@ -787,7 +806,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() ); @@ -801,7 +820,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() ); @@ -811,7 +830,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() ); @@ -821,7 +840,7 @@ void GridFrame::OnColSize( wxGridSizeEvent& ev ) void GridFrame::OnSelectCell( wxGridEvent& ev ) { - logBuf = _T(""); + logBuf = wxEmptyString; if ( ev.Selecting() ) logBuf << _T("Selected "); else @@ -841,7 +860,7 @@ void GridFrame::OnSelectCell( wxGridEvent& ev ) void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) { - logBuf = _T(""); + logBuf = wxEmptyString; if ( ev.Selecting() ) logBuf << _T("Selected "); else @@ -861,7 +880,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(); @@ -871,6 +890,18 @@ void GridFrame::OnCellValueChanged( wxGridEvent& ev ) ev.Skip(); } +void GridFrame::OnCellBeginDrag( wxGridEvent& ev ) +{ + logBuf = wxEmptyString; + 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 ) { @@ -908,8 +939,7 @@ void GridFrame::OnEditorHidden( wxGridEvent& ev ) void GridFrame::About( wxCommandEvent& WXUNUSED(ev) ) { (void)wxMessageBox( _T("\n\nwxGrid demo \n\n") - _T("Michael Bedward \n") - _T("mbedward@ozemail.com.au \n\n"), + _T("Michael Bedward, Julian Smart, Vadim Zeitlin"), _T("About"), wxOK ); } @@ -1170,10 +1200,13 @@ wxString BugsGridTable::GetValue( int row, int col ) switch ( col ) { case Col_Id: + return wxString::Format(_T("%d"), gd.id); + case Col_Priority: + return wxString::Format(_T("%d"), gd.prio); + case Col_Opened: - wxFAIL_MSG(_T("unexpected column")); - break; + return gd.opened ? _T("1") : _T("0"); case Col_Severity: return severities[gd.severity]; @@ -1231,7 +1264,10 @@ void BugsGridTable::SetValue( int row, int col, const wxString& value ) } } -bool BugsGridTable::CanGetValueAs( int WXUNUSED(row), int col, const wxString& typeName ) +bool +BugsGridTable::CanGetValueAs(int WXUNUSED(row), + int col, + const wxString& typeName) { if ( typeName == wxGRID_VALUE_STRING ) { @@ -1323,10 +1359,6 @@ wxString BugsGridTable::GetColLabelValue( int col ) return headers[col]; } -BugsGridTable::BugsGridTable() -{ -} - // ---------------------------------------------------------------------------- // BugsGridFrame // ----------------------------------------------------------------------------