From: Robert Roebling Date: Fri, 24 Aug 2007 11:21:52 +0000 (+0000) Subject: Minor API changes X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/fbda518cb73c410f88838b8f9df3e525720106a6?hp=daf5b37afdda9e8ab7f909e01ffd6387219a80ea Minor API changes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48368 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 55e3d1e944..cf9aea83d0 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -25,7 +25,7 @@ #if defined(__WXGTK20__) // for testing - // #define wxUSE_GENERICDATAVIEWCTRL 1 + #define wxUSE_GENERICDATAVIEWCTRL 1 #elif defined(__WXMAC__) #else #define wxUSE_GENERICDATAVIEWCTRL 1 @@ -463,7 +463,7 @@ public: virtual bool DeleteColumn( unsigned int pos ); virtual bool ClearColumns(); - virtual wxDataViewColumn* GetColumn( unsigned int pos ); + virtual wxDataViewColumn* GetColumn( unsigned int pos ) const; void SetExpanderColumn( unsigned int col ) { m_expander_column = col ; DoSetExpanderColumn(); } @@ -475,7 +475,7 @@ public: int GetIndent() const { return m_indent; } - virtual wxDataViewItem GetSelection() = 0; + virtual wxDataViewItem GetSelection() const = 0; virtual int GetSelections( wxDataViewItemArray & sel ) const = 0; virtual void SetSelections( const wxDataViewItemArray & sel ) = 0; virtual void Select( const wxDataViewItem & item ) = 0; @@ -486,12 +486,9 @@ public: virtual void UnselectAll() = 0; virtual void EnsureVisible( const wxDataViewItem & item, - wxDataViewColumn *column = NULL ) = 0; - - virtual void HitTest( const wxPoint &point, - wxDataViewItem &item, unsigned int &column ) const = 0; - virtual wxRect GetItemRect( const wxDataViewItem &item, - unsigned int column ) const = 0; + const wxDataViewColumn *column = NULL ) = 0; + virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* column ) const = 0; + virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0; protected: virtual void DoSetExpanderColumn() = 0 ; diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 4207e50ef6..86a84f042a 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -354,7 +354,7 @@ public: virtual void DoSetExpanderColumn(); virtual void DoSetIndent(); - virtual wxDataViewItem GetSelection(); + virtual wxDataViewItem GetSelection() const; virtual int GetSelections( wxDataViewItemArray & sel ) const; virtual void SetSelections( const wxDataViewItemArray & sel ); virtual void Select( const wxDataViewItem & item ); @@ -365,9 +365,9 @@ public: virtual void UnselectAll(); virtual void EnsureVisible( const wxDataViewItem & item, - wxDataViewColumn *column = NULL ); - virtual void HitTest( const wxPoint & point, wxDataViewItem & item, unsigned int & column ) const; - virtual wxRect GetItemRect( const wxDataViewItem & item, unsigned int column ) const; + const wxDataViewColumn *column = NULL ); + virtual void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* column ) const; + virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const; protected: virtual int GetSelections( wxArrayInt & sel ) const; @@ -378,7 +378,7 @@ protected: virtual void SelectRange( int from, int to ); virtual void UnselectRange( int from, int to ); - virtual void EnsureVisible( int row ); + virtual void EnsureVisible( int row, int column ); virtual wxDataViewItem GetItemByRow( unsigned int row ) const; virtual int GetRowByItem( const wxDataViewItem & item ) const; diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index 6a94076629..76b2ecffe3 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -306,7 +306,7 @@ public: virtual bool AssociateModel( wxDataViewModel *model ); virtual bool AppendColumn( wxDataViewColumn *col ); - virtual wxDataViewItem GetSelection(); + virtual wxDataViewItem GetSelection() const; virtual int GetSelections( wxDataViewItemArray & sel ) const; virtual void SetSelections( const wxDataViewItemArray & sel ); virtual void Select( const wxDataViewItem & item ); @@ -315,12 +315,13 @@ public: virtual void SelectAll(); virtual void UnselectAll(); - virtual void EnsureVisible( const wxDataViewItem & item, wxDataViewColumn *column = NULL ); - + virtual void EnsureVisible( const wxDataViewItem& item, + const wxDataViewColumn *column = NULL ); virtual void HitTest( const wxPoint &point, - wxDataViewItem &item, unsigned int &column ) const; + wxDataViewItem &item, + wxDataViewColumn *column ) const; virtual wxRect GetItemRect( const wxDataViewItem &item, - unsigned int column ) const; + const wxDataViewColumn *column = NULL ) const; static wxVisualAttributes diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index e46d35b60d..ed5013cc1c 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -240,12 +240,11 @@ public: MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); switch (col) { - case 0: node->m_title = variant.GetString(); return true; - case 1: node->m_artist = variant.GetString(); return true; - case 2: node->m_year = variant.GetString(); return true; + case 0: node->m_title = variant.GetString(); break; + case 1: node->m_artist = variant.GetString(); break; + case 2: node->m_year = variant.GetString(); break; default: wxLogError( "MyMusicModel::SetValue: wrong column" ); } - return false; } virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const @@ -454,6 +453,8 @@ private: wxDataViewCtrl* m_listCtrl; wxObjectDataPtr m_list_model; + + wxDataViewColumn * m_col; wxTextCtrl * m_log; wxLog *m_logOld; @@ -540,6 +541,7 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h): wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)) { m_log = NULL; + m_col = NULL; SetIcon(wxICON(sample)); @@ -594,7 +596,7 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h): m_listCtrl->AssociateModel( m_list_model.get() ); m_listCtrl->AppendTextColumn( "editable string", 0, wxDATAVIEW_CELL_EDITABLE, 120 ); - m_listCtrl->AppendTextColumn( "index", 1, wxDATAVIEW_CELL_INERT, 120 ); + m_col = m_listCtrl->AppendTextColumn( "index", 1, wxDATAVIEW_CELL_INERT, 120 ); data_sizer->Add( m_listCtrl, 2, wxGROW ); @@ -762,7 +764,7 @@ void MyFrame::OnRightClick( wxMouseEvent &event ) void MyFrame::OnGoto( wxCommandEvent &event) { wxDataViewItem item = m_list_model->GetItem( 50 ); - m_listCtrl->EnsureVisible(item); + m_listCtrl->EnsureVisible(item,m_col); } void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index d63625fcb7..daf8f220c8 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -36,7 +36,7 @@ bool operator == (const wxDataViewItem &left, const wxDataViewItem &right) // wxDataViewModel // --------------------------------------------------------- -#include "wx/listimpl.cpp" +#include WX_DEFINE_LIST(wxDataViewModelNotifiers); wxDataViewModel::wxDataViewModel() @@ -268,6 +268,7 @@ unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) cons wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const { + wxASSERT( row < m_hash.GetCount() ); return wxDataViewItem( m_hash[row] ); } @@ -713,7 +714,7 @@ bool wxDataViewCtrlBase::ClearColumns() return false; } -wxDataViewColumn* wxDataViewCtrlBase::GetColumn( unsigned int pos ) +wxDataViewColumn* wxDataViewCtrlBase::GetColumn( unsigned int pos ) const { if( pos >= m_cols.GetCount() ) return NULL; diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 09e9a8cd82..fa4dd8c5c2 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -464,7 +464,7 @@ public: void OnRenameTimer(); void ScrollWindow( int dx, int dy, const wxRect *rect = NULL ); - void ScrollTo( int rows ); + void ScrollTo( int rows, int column ); bool HasCurrentRow() { return m_currentRow != (unsigned int)-1; } void ChangeCurrentRow( unsigned int row ); @@ -479,7 +479,7 @@ public: unsigned int GetLastVisibleRow(); unsigned int GetRowCount() ; - wxDataViewItem GetSelection(); + wxDataViewItem GetSelection() const; wxDataViewSelection GetSelections(){ return m_selection; } void SetSelections( const wxDataViewSelection & sel ) { m_selection = sel; UpdateDisplay(); } void Select( const wxArrayInt& aSelections ); @@ -503,14 +503,14 @@ public: wxRect GetLineRect( unsigned int row ) const; //Some useful functions for row and item mapping - wxDataViewItem GetItemByRow( unsigned int row ); + wxDataViewItem GetItemByRow( unsigned int row ) const; int GetRowByItem( const wxDataViewItem & item ); //Methods for building the mapping tree void BuildTree( wxDataViewModel * model ); void DestroyTree(); - void HitTest( const wxPoint & point, wxDataViewItem & item, unsigned int & column ); - wxRect GetItemRect( const wxDataViewItem & item, unsigned int column ); + void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* column ); + wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn* column ); private: wxDataViewTreeNode * GetTreeNodeByRow( unsigned int row ); //We did not need this temporarily @@ -1987,7 +1987,7 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData m_count = -1; UpdateDisplay(); - + return true; } @@ -2000,8 +2000,8 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent, wxDataViewTreeNode * node; node = FindNode(parent); - SendModelEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED, item); + SendModelEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED, item); if( node == NULL || node->GetChildren().Index( item.GetID() ) == wxNOT_FOUND ) { return false; @@ -2009,6 +2009,14 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent, int sub = -1; node->GetChildren().Remove( item.GetID() ); + //Manuplate selection + if( m_selection.GetCount() > 1 ) + { + int row = m_selection[0]; + m_selection.Empty(); + m_selection.Add(row); + } + if( GetOwner()->GetModel()->IsContainer( item ) ) { wxDataViewTreeNode * n = NULL; @@ -2140,12 +2148,41 @@ void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect ) GetOwner()->m_headerArea->ScrollWindow( dx, 0 ); } -void wxDataViewMainWindow::ScrollTo( int rows ) +void wxDataViewMainWindow::ScrollTo( int rows, int column ) { int x, y; m_owner->GetScrollPixelsPerUnit( &x, &y ); - int sc = rows*m_lineHeight/y; - m_owner->Scroll(0, sc ); + int sy = rows*m_lineHeight/y; + int sx = 0; + if( column != -1 ) + { + wxRect rect = GetClientRect(); + unsigned int colnum = 0; + unsigned int x_start = 0, x_end = 0, w = 0; + int xx, yy, xe; + m_owner->CalcUnscrolledPosition( rect.x, rect.y, &xx, &yy ); + for (x_start = 0; colnum < column; colnum++) + { + wxDataViewColumn *col = GetOwner()->GetColumn(colnum); + if (col->IsHidden()) + continue; // skip it! + + w = col->GetWidth(); + x_start += w; + } + + x_end = x_start + w; + xe = xx + rect.width; + if( x_end > xe ) + { + sx = ( xx + x_end - xe )/x; + } + if( x_start < xx ) + { + sx = x_start/x; + } + } + m_owner->Scroll( sx, sy ); } void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) @@ -2415,7 +2452,12 @@ unsigned int wxDataViewMainWindow::GetLastVisibleRow() m_owner->CalcUnscrolledPosition( client_size.x, client_size.y, &client_size.x, &client_size.y ); - return wxMin( GetRowCount()-1, ((unsigned)client_size.y/m_lineHeight)+1 ); + //we should deal with the pixel here + unsigned int row = (client_size.y)/m_lineHeight; + if( client_size.y % m_lineHeight < m_lineHeight/2 ) + row -= 1; + + return wxMin( GetRowCount()-1, row ); } unsigned int wxDataViewMainWindow::GetRowCount() @@ -2693,7 +2735,7 @@ private: wxDataViewItem ret; }; -wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row) +wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row) const { RowToItemJob job( row, -2 ); Walker( m_root , job ); @@ -2901,8 +2943,9 @@ wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item return node; } -void wxDataViewMainWindow::HitTest( const wxPoint & point, wxDataViewItem & item, unsigned int & column ) +void wxDataViewMainWindow::HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* column ) { + wxDataViewColumn *col = NULL; unsigned int cols = GetOwner()->GetColumnCount(); unsigned int colnum = 0; unsigned int x_start = 0; @@ -2910,7 +2953,7 @@ void wxDataViewMainWindow::HitTest( const wxPoint & point, wxDataViewItem & item m_owner->CalcUnscrolledPosition( point.x, point.y, &x, &y ); for (x_start = 0; colnum < cols; colnum++) { - wxDataViewColumn *col = GetOwner()->GetColumn(colnum); + col = GetOwner()->GetColumn(colnum); if (col->IsHidden()) continue; // skip it! @@ -2921,11 +2964,11 @@ void wxDataViewMainWindow::HitTest( const wxPoint & point, wxDataViewItem & item x_start += w; } - column = colnum; + column = col; item = GetItemByRow( y/m_lineHeight ); } -wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item, unsigned int column ) +wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item, const wxDataViewColumn* column ) { int row = GetRowByItem(item); int y = row*m_lineHeight; @@ -2936,7 +2979,7 @@ wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item, unsigned { col = GetOwner()->GetColumn( i ); x += col->GetWidth(); - if( i == column - 1 ) + if( GetOwner()->GetColumn(i+1) == column ) break; } int w = col->GetWidth(); @@ -2998,7 +3041,7 @@ int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item) { wxDataViewModel * model = GetOwner()->GetModel(); if( model == NULL ) - return 0; + return -1; if( !item.IsOk() ) return -1; @@ -3442,7 +3485,7 @@ void wxDataViewMainWindow::OnKillFocus( wxFocusEvent &event ) event.Skip(); } -wxDataViewItem wxDataViewMainWindow::GetSelection() +wxDataViewItem wxDataViewMainWindow::GetSelection() const { if( m_selection.GetCount() != 1 ) return wxDataViewItem(); @@ -3580,7 +3623,7 @@ void wxDataViewCtrl::DoSetIndent() } //Selection code with wxDataViewItem as parameters -wxDataViewItem wxDataViewCtrl::GetSelection() +wxDataViewItem wxDataViewCtrl::GetSelection() const { return m_clientArea->GetSelection(); } @@ -3708,24 +3751,52 @@ void wxDataViewCtrl::UnselectAll() m_clientArea->SelectAllRows(false); } -void wxDataViewCtrl::EnsureVisible( int row ) +void wxDataViewCtrl::EnsureVisible( int row, int column ) { - m_clientArea->ScrollTo( row ); + if( row < 0 ) + row = 0; + if( row > m_clientArea->GetRowCount() ) + row = m_clientArea->GetRowCount(); + + int first = m_clientArea->GetFirstVisibleRow(); + int last = m_clientArea->GetLastVisibleRow(); + if( row < first ) + m_clientArea->ScrollTo( row, column ); + else if( row > last ) + m_clientArea->ScrollTo( row - last + first, column ); + else + m_clientArea->ScrollTo( first, column ); } -void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, wxDataViewColumn * column ) +void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, const wxDataViewColumn * column ) { int row = m_clientArea->GetRowByItem(item); if( row >= 0 ) - EnsureVisible(row); + { + if( column == NULL ) + return EnsureVisible(row, -1); + else + { + int col = 0; + int len = GetColumnCount(); + for( int i = 0; i < len; i ++ ) + if( GetColumn(i) == column ) + { + col = i; + break; + } + EnsureVisible( row, col ); + } + } + } -void wxDataViewCtrl::HitTest( const wxPoint & point, wxDataViewItem & item, unsigned int & column ) const +void wxDataViewCtrl::HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* column ) const { m_clientArea->HitTest(point, item, column); } -wxRect wxDataViewCtrl::GetItemRect( const wxDataViewItem & item, unsigned int column ) const +wxRect wxDataViewCtrl::GetItemRect( const wxDataViewItem & item, const wxDataViewColumn* column ) const { return m_clientArea->GetItemRect(item, column); } diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 06836322f2..9023c13680 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -2934,7 +2934,7 @@ bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) return true; } -wxDataViewItem wxDataViewCtrl::GetSelection() +wxDataViewItem wxDataViewCtrl::GetSelection() const { GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) ); @@ -3092,7 +3092,7 @@ void wxDataViewCtrl::UnselectAll() GtkEnableSelectionEvents(); } -void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, wxDataViewColumn *column ) +void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, const wxDataViewColumn *column ) { GtkTreeIter iter; iter.user_data = (gpointer) item.GetID(); @@ -3102,14 +3102,14 @@ void wxDataViewCtrl::EnsureVisible( const wxDataViewItem & item, wxDataViewColum } void wxDataViewCtrl::HitTest( const wxPoint &point, - wxDataViewItem &item, unsigned int &column ) const + wxDataViewItem &item, wxDataViewColumn *column ) const { item = wxDataViewItem(0); column = 0; } wxRect wxDataViewCtrl::GetItemRect( const wxDataViewItem &item, - unsigned int column ) const + const wxDataViewColumn *column ) const { return wxRect(); }