From: Robert Roebling Date: Tue, 28 Aug 2007 09:32:43 +0000 (+0000) Subject: Applied patch from Bo, WIP X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/57f2a6529245d54274a4c56469f1828a6f8fd497 Applied patch from Bo, WIP git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48424 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 37ae7f74b1..9bdbd25d67 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -328,7 +328,8 @@ class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase, public: wxDataViewCtrl() : wxScrollHelperNative(this) { - m_sortingColumn = 0; + //No sorting column at start, I think + m_sortingColumn = NULL; Init(); } @@ -338,6 +339,7 @@ public: const wxValidator& validator = wxDefaultValidator ) : wxScrollHelperNative(this) { + m_sortingColumn = NULL; Create(parent, id, pos, size, style, validator ); } @@ -393,8 +395,8 @@ protected: virtual wxDataViewItem GetItemByRow( unsigned int row ) const; virtual int GetRowByItem( const wxDataViewItem & item ) const; - unsigned int GetSortingColumn() { return m_sortingColumn; } - void SetSortingColumn( unsigned int column ) { m_sortingColumn = column; } + wxDataViewColumn* GetSortingColumn() { return m_sortingColumn; } + void SetSortingColumn( wxDataViewColumn* column ) { m_sortingColumn = column; } public: // utility functions not part of the API @@ -414,7 +416,7 @@ private: wxDataViewModelNotifier *m_notifier; wxDataViewMainWindow *m_clientArea; wxDataViewHeaderWindow *m_headerArea; - unsigned int m_sortingColumn; + wxDataViewColumn* m_sortingColumn; private: void OnSize( wxSizeEvent &event ); diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index aa1a08a028..b3dd8f5ef3 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -68,6 +68,12 @@ static const int EXPANDER_MARGIN = 4; #define USE_NATIVE_HEADER_WINDOW 0 +//Below is the compare stuff +//For the generic implements, both the leaf nodes and the nodes are sorted for fast search when needed +static wxDataViewModel * g_model; +static int g_column; +static bool g_asending; + // NB: for some reason, this class must be dllexport'ed or we get warnings from // MSVC in DLL build class WXDLLIMPEXP_ADV wxDataViewHeaderWindowBase : public wxControl @@ -254,18 +260,16 @@ public: // wxDataViewTreeNode //----------------------------------------------------------------------------- class wxDataViewTreeNode; -WX_DEFINE_SORTED_ARRAY( wxDataViewTreeNode *, wxDataViewTreeNodes ); -WX_DEFINE_SORTED_ARRAY( void* , wxDataViewTreeLeaves); +WX_DEFINE_ARRAY( wxDataViewTreeNode *, wxDataViewTreeNodes ); +WX_DEFINE_ARRAY( void* , wxDataViewTreeLeaves); -int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode * node1, wxDataViewTreeNode * node2); -int LINKAGEMODE wxGenericTreeModelItemCmp( void * id1, void * id2); +int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode ** node1, wxDataViewTreeNode ** node2); +int LINKAGEMODE wxGenericTreeModelItemCmp( void ** id1, void ** id2); class wxDataViewTreeNode { public: wxDataViewTreeNode( wxDataViewTreeNode * parent = NULL ) - :leaves( wxGenericTreeModelItemCmp ), - nodes(wxGenericTreeModelNodeCmp) { this->parent = parent; if( parent == NULL ) open = true; @@ -287,10 +291,19 @@ public: void AddNode( wxDataViewTreeNode * node ) { - nodes.Add( node ); leaves.Add( node->GetItem().GetID() ); + if (g_column >= 0) + leaves.Sort( &wxGenericTreeModelItemCmp ); + nodes.Add( node ); + if (g_column >= 0) + nodes.Sort( &wxGenericTreeModelNodeCmp ); + } + void AddLeaf( void * leaf ) + { + leaves.Add( leaf ); + if (g_column >= 0) + leaves.Sort( &wxGenericTreeModelItemCmp ); } - void AddLeaf( void * leaf ) { leaves.Add( leaf ); } wxDataViewItem & GetItem() { return item; } void SetItem( const wxDataViewItem & item ) { this->item = item; } @@ -349,26 +362,15 @@ public: void Resort() { - wxDataViewTreeNodes nds = nodes; - wxDataViewTreeLeaves lvs = leaves; - nodes.Empty(); - leaves.Empty(); - - int len = nds.GetCount(); - if(len > 0) + if (g_column >= 0) { - int i; - for(i = 0; i < len; i ++) - nodes.Add(nds[i]); - for(i = 0; i < len; i ++) + nodes.Sort( &wxGenericTreeModelNodeCmp ); + int len = nodes.GetCount(); + for (int i = 0; i < len; i ++) + { nodes[i]->Resort(); - } - - len = lvs.GetCount(); - if(len > 0) - { - for(int i = 0; i < len; i++) - leaves.Add(lvs[i]); + } + leaves.Sort( &wxGenericTreeModelItemCmp ); } } @@ -382,20 +384,14 @@ private: int subTreeCount; }; -//Below is the compare stuff -//For the generic implements, both the leaf nodes and the nodes are sorted for fast search when needed -static wxDataViewModel * g_model; -static unsigned int g_column; -static bool g_asending; - -int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode * node1, wxDataViewTreeNode * node2) +int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode ** node1, wxDataViewTreeNode ** node2) { - return g_model->Compare( node1->GetItem(), node2->GetItem(), g_column, g_asending ); + return g_model->Compare( (*node1)->GetItem(), (*node2)->GetItem(), g_column, g_asending ); } -int LINKAGEMODE wxGenericTreeModelItemCmp( void * id1, void * id2) +int LINKAGEMODE wxGenericTreeModelItemCmp( void ** id1, void ** id2) { - return g_model->Compare( id1, id2, g_column, g_asending ); + return g_model->Compare( *id1, *id2, g_column, g_asending ); } @@ -436,13 +432,14 @@ public: void SortPrepare() { g_model = GetOwner()->GetModel(); - g_column = GetOwner()->GetSortingColumn(); - wxDataViewColumn * col = GetOwner()->GetColumn(g_column); + wxDataViewColumn* col = GetOwner()->GetSortingColumn(); if( !col ) { + g_column = -1; g_asending = true; return; } + g_column = col->GetModelColumn(); g_asending = col->IsSortOrderAscending(); } @@ -1222,7 +1219,7 @@ void wxDataViewHeaderWindowMSW::UpdateDisplay() //hdi.fmt &= ~(HDF_SORTDOWN|HDF_SORTUP); //sorting support - if(model && m_owner->GetSortingColumn() == i) + if(model && m_owner->GetSortingColumn() == col) { //The Microsoft Comctrl32.dll 6.0 support SORTUP/SORTDOWN, but they are not default //see http://msdn2.microsoft.com/en-us/library/ms649534.aspx for more detail @@ -1357,14 +1354,14 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA wxDataViewColumn *col = GetColumn(idx); if(col->IsSortable()) { - if(model && m_owner->GetSortingColumn() == idx) + if(model && m_owner->GetSortingColumn() == col) { bool order = col->IsSortOrderAscending(); col->SetSortOrder(!order); } else if(model) { - m_owner->SetSortingColumn(idx); + m_owner->SetSortingColumn(col); } } UpdateDisplay(); @@ -1528,7 +1525,7 @@ void wxGenericDataViewHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) int ch = h; wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE; - if (col->IsSortable() && GetOwner()->GetSortingColumn() == i) + if (col->IsSortable() && GetOwner()->GetSortingColumn() == col) { if (col->IsSortOrderAscending()) sortArrow = wxHDR_SORT_ICON_UP; @@ -1693,15 +1690,15 @@ void wxGenericDataViewHeaderWindow::OnMouse( wxMouseEvent &event ) wxDataViewColumn *col = GetColumn(m_column); if(col->IsSortable()) { - unsigned int colnum = m_owner->GetSortingColumn(); - if(model && static_cast(colnum) == m_column) + wxDataViewColumn* sortCol = m_owner->GetSortingColumn(); + if(model && sortCol == col) { bool order = col->IsSortOrderAscending(); col->SetSortOrder(!order); } else if(model) { - m_owner->SetSortingColumn(m_column); + m_owner->SetSortingColumn(col); } } UpdateDisplay(); @@ -2016,9 +2013,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent, //Manuplate selection if( m_selection.GetCount() > 1 ) { - int row = m_selection[0]; m_selection.Empty(); - m_selection.Add(row); } if( GetOwner()->GetModel()->IsContainer( item ) ) @@ -3407,9 +3402,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) } if (event.LeftDown() || forceClick) { -#ifdef __WXMSW__ SetFocus(); -#endif m_lineBeforeLastClicked = m_lineLastClicked; m_lineLastClicked = current; @@ -3713,7 +3706,12 @@ void wxDataViewCtrl::Select( const wxDataViewItem & item ) { int row = m_clientArea->GetRowByItem( item ); if( row >= 0 ) + { + //Unselect all rows before select another in the single select mode + if (m_clientArea->IsSingleSel()) + m_clientArea->SelectAllRows(false); m_clientArea->SelectRow(row, true); + } } void wxDataViewCtrl::Unselect( const wxDataViewItem & item ) @@ -3763,7 +3761,11 @@ void wxDataViewCtrl::SetSelections( const wxArrayInt & sel ) void wxDataViewCtrl::Select( int row ) { if( row >= 0 ) + { + if (m_clientArea->IsSingleSel()) + m_clientArea->SelectAllRows(false); m_clientArea->SelectRow( row, true ); + } } void wxDataViewCtrl::Unselect( int row )