X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/777f9cef025177773ad424e77a72019a0d9b6e94..298c25c3a5b9d5d6b92310a54f860cd48627888b:/src/generic/datavgen.cpp diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 0d226bf965..44eef8c70e 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -168,6 +168,7 @@ protected: int m_scrollOffsetX; int m_buttonHeight; + bool m_vetoColumnDrag; bool m_delayedUpdate; wxImageList *m_imageList; @@ -332,7 +333,7 @@ public: unsigned int GetNodeNumber() const { return m_nodes.GetCount(); } int GetIndentLevel() const { - int ret = 0 ; + int ret = 0; const wxDataViewTreeNode * node = this; while( node->GetParent()->GetParent() != NULL ) { @@ -344,14 +345,14 @@ public: bool IsOpen() const { - return m_open ; + return m_open; } void ToggleOpen() { int len = m_nodes.GetCount(); int sum = 0; - for ( int i = 0 ;i < len ; i ++) + for ( int i = 0;i < len; i ++) sum += m_nodes[i]->GetSubTreeCount(); sum += m_leaves.GetCount(); @@ -374,7 +375,7 @@ public: void ChangeSubTreeCount( int num ) { if( !m_open ) - return ; + return; m_subTreeCount += num; if( m_parent ) m_parent->ChangeSubTreeCount(num); @@ -500,7 +501,7 @@ public: unsigned int GetFirstVisibleRow() const; //I change this method to un const because in the tree view, the displaying number of the tree are changing along with the expanding/collapsing of the tree nodes unsigned int GetLastVisibleRow(); - unsigned int GetRowCount() ; + unsigned int GetRowCount(); wxDataViewItem GetSelection() const; wxDataViewSelection GetSelections(){ return m_selection; } @@ -546,7 +547,7 @@ private: //We did not need this temporarily //wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item ); - int RecalculateCount() ; + int RecalculateCount(); wxDataViewEvent SendExpanderEvent( wxEventType type, const wxDataViewItem & item ); void OnExpanding( unsigned int row ); @@ -1327,6 +1328,7 @@ bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, m_scrollOffsetX = 0; m_delayedUpdate = false; + m_vetoColumnDrag = false; m_buttonHeight = wxRendererNative::Get().GetHeaderButtonHeight( this ); int x = pos.x == wxDefaultCoord ? 0 : pos.x, @@ -1362,7 +1364,7 @@ bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, } m_imageList = new wxImageList( 16, 16 ); - Header_SetImageList( (HWND) m_hWnd, m_imageList->GetHIMAGELIST() ); + (void)Header_SetImageList((HWND) m_hWnd, m_imageList->GetHIMAGELIST()); // we need to subclass the m_hWnd to force wxWindow::HandleNotify // to call wxDataViewHeaderWindow::MSWOnNotify @@ -1506,6 +1508,13 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA NMHEADER *nmHDR = (NMHEADER *)nmhdr; switch ( nmhdr->code ) { + case NM_RELEASEDCAPTURE: + { + // user has released the mouse + m_vetoColumnDrag = false; + } + break; + case HDN_BEGINTRACK: // user has started to resize a column: // do we need to veto it? @@ -1517,11 +1526,21 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA break; case HDN_BEGINDRAG: - // user has started to reorder a column - if ((nmHDR->iItem != -1) && (!GetColumn(nmHDR->iItem)->IsReorderable())) + // valid column + if (nmHDR->iItem != -1) + { + // user has started to reorder a valid column + if ((m_vetoColumnDrag == true) || (!GetColumn(nmHDR->iItem)->IsReorderable())) + { + // veto it! + *result = TRUE; + m_vetoColumnDrag = true; + } + } + else { // veto it! - *result = TRUE; + m_vetoColumnDrag = true; } break; @@ -2033,7 +2052,7 @@ wxDataViewMainWindow::wxDataViewMainWindow( wxDataViewCtrl *parent, wxWindowID i m_root->SetHasChildren(true); //Make m_count = -1 will cause the class recaculate the real displaying number of rows. - m_count = -1 ; + m_count = -1; m_underMouse = NULL; UpdateDisplay(); } @@ -2235,7 +2254,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) // change the cell_rect.x to the appropriate pos int expander_x = indent + EXPANDER_MARGIN; int expander_y = cell_rect.y + EXPANDER_MARGIN + (GetLineHeight(item) / 2) - (expander_width/2) - EXPANDER_OFFSET; - indent = indent + m_lineHeight ; //try to use the m_lineHeight as the expander space + indent = indent + m_lineHeight; //try to use the m_lineHeight as the expander space dc.SetPen( m_penExpander ); dc.SetBrush( wxNullBrush ); if( node->HasChildren() ) @@ -2258,7 +2277,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) { // Yes, if the node does not have any child, it must be a leaf which // mean that it is a temporarily created by GetTreeNodeByRow - wxDELETE(node) + wxDELETE(node); } // cannot be bigger than allocated space @@ -2353,15 +2372,15 @@ void wxDataViewMainWindow::OnRenameTimer() class DoJob { public: - DoJob(){}; - virtual ~DoJob(){}; + DoJob() { } + virtual ~DoJob() { } //The return value control how the tree-walker tranverse the tree // 0: Job done, stop tranverse and return // 1: Ignore the current node's subtree and continue // 2: Job not done, continue enum { OK = 0 , IGR = 1, CONT = 2 }; - virtual int operator() ( wxDataViewTreeNode * node ) = 0 ; + virtual int operator() ( wxDataViewTreeNode * node ) = 0; virtual int operator() ( void * n ) = 0; }; @@ -2373,12 +2392,12 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func ) switch( func( node ) ) { case DoJob::OK : - return true ; + return true; case DoJob::IGR: return false; case DoJob::CONT: - default: - ; + default: + ; } wxDataViewTreeNodes nodes = node->GetNodes(); @@ -2388,7 +2407,7 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func ) int len = leaves.GetCount(); int i = 0, nodes_i = 0; - for( ; i < len ; i ++ ) + for(; i < len; i ++ ) { void * n = leaves[i]; if( nodes_i < len_nodes && n == nodes[nodes_i]->GetItem().GetID() ) @@ -2404,12 +2423,12 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func ) switch( func( n ) ) { case DoJob::OK : - return true ; + return true; case DoJob::IGR: continue; case DoJob::CONT: default: - ; + ; } } return false; @@ -2497,7 +2516,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent, wxDataViewTreeNode * n = NULL; wxDataViewTreeNodes nodes = node->GetNodes(); int len = nodes.GetCount(); - for( int i = 0 ; i < len; i ++) + for( int i = 0; i < len; i ++) { if( nodes[i]->GetItem() == item ) { @@ -2956,7 +2975,7 @@ int wxDataViewMainWindow::GetLineStart( unsigned int row ) const { // Yes, if the node does not have any child, it must be a leaf which // mean that it is a temporarily created by GetTreeNodeByRow - wxDELETE(node) + wxDELETE(node); } unsigned int cols = GetOwner()->GetColumnCount(); @@ -3017,7 +3036,7 @@ int wxDataViewMainWindow::GetLineAt( unsigned int y ) const { // Yes, if the node does not have any child, it must be a leaf which // mean that it is a temporarily created by GetTreeNodeByRow - wxDELETE(node) + wxDELETE(node); } unsigned int cols = GetOwner()->GetColumnCount(); @@ -3066,7 +3085,7 @@ int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const { // Yes, if the node does not have any child, it must be a leaf which // mean that it is a temporarily created by GetTreeNodeByRow - wxDELETE(node) + wxDELETE(node); } int height = m_lineHeight; @@ -3101,15 +3120,15 @@ int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const class RowToItemJob: public DoJob { public: - RowToItemJob( unsigned int row , int current ) { this->row = row; this->current = current ;} - virtual ~RowToItemJob(){}; + RowToItemJob( unsigned int row , int current ) { this->row = row; this->current = current;} + virtual ~RowToItemJob() { } virtual int operator() ( wxDataViewTreeNode * node ) { current ++; if( current == static_cast(row)) { - ret = node->GetItem() ; + ret = node->GetItem(); return DoJob::OK; } @@ -3137,7 +3156,7 @@ public: current ++; if( current == static_cast(row)) { - ret = wxDataViewItem( n ) ; + ret = wxDataViewItem( n ); return DoJob::OK; } return DoJob::CONT; @@ -3145,7 +3164,7 @@ public: wxDataViewItem GetResult(){ return ret; } private: unsigned int row; - int current ; + int current; wxDataViewItem ret; }; @@ -3169,18 +3188,18 @@ public: RowToTreeNodeJob( unsigned int row , int current, wxDataViewTreeNode * node ) { this->row = row; - this->current = current ; - ret = NULL ; + this->current = current; + ret = NULL; parent = node; } - virtual ~RowToTreeNodeJob(){}; + virtual ~RowToTreeNodeJob(){ } virtual int operator() ( wxDataViewTreeNode * node ) { current ++; if( current == static_cast(row)) { - ret = node ; + ret = node; return DoJob::OK; } @@ -3198,7 +3217,7 @@ public: { int index = static_cast(row) - current - 1; void * n = node->GetChildren().Item( index ); - ret = new wxDataViewTreeNode( parent ) ; + ret = new wxDataViewTreeNode( parent ); ret->SetItem( wxDataViewItem( n )); ret->SetHasChildren(false); return DoJob::OK; @@ -3214,7 +3233,7 @@ public: current ++; if( current == static_cast(row)) { - ret = new wxDataViewTreeNode( parent ) ; + ret = new wxDataViewTreeNode( parent ); ret->SetItem( wxDataViewItem( n )); ret->SetHasChildren(false); return DoJob::OK; @@ -3225,9 +3244,9 @@ public: wxDataViewTreeNode * GetResult(){ return ret; } private: unsigned int row; - int current ; + int current; wxDataViewTreeNode * ret; - wxDataViewTreeNode * parent ; + wxDataViewTreeNode * parent; }; @@ -3255,6 +3274,9 @@ wxDataViewEvent wxDataViewMainWindow::SendExpanderEvent( wxEventType type, const void wxDataViewMainWindow::OnExpanding( unsigned int row ) { + if (IsVirtualList()) + return; + wxDataViewTreeNode * node = GetTreeNodeByRow(row); if( node != NULL ) { @@ -3294,6 +3316,9 @@ void wxDataViewMainWindow::OnExpanding( unsigned int row ) void wxDataViewMainWindow::OnCollapsing(unsigned int row) { + if (IsVirtualList()) + return; + wxDataViewTreeNode * node = GetTreeNodeByRow(row); if( node != NULL ) { @@ -3314,7 +3339,7 @@ void wxDataViewMainWindow::OnCollapsing(unsigned int row) node = node->GetParent(); if( node != NULL ) { - int parent = GetRowByItem( node->GetItem() ) ; + int parent = GetRowByItem( node->GetItem() ); if( parent >= 0 ) { SelectRow( row, false); @@ -3349,7 +3374,7 @@ wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item //Find the item along the parent-chain. //This algorithm is designed to speed up the node-finding method wxDataViewTreeNode * node = m_root; - for( ItemList::const_iterator iter = list.begin(); iter !=list.end() ; iter++ ) + for( ItemList::const_iterator iter = list.begin(); iter !=list.end(); iter++ ) { if( node->HasChildren() ) { @@ -3448,9 +3473,12 @@ int wxDataViewMainWindow::RecalculateCount() class ItemToRowJob : public DoJob { public: - ItemToRowJob(const wxDataViewItem & item, ItemList::const_iterator iter ) - { this->item = item ; ret = -1 ; m_iter = iter ; } - virtual ~ItemToRowJob(){}; + ItemToRowJob(const wxDataViewItem& item_, ItemList::const_iterator iter) + : m_iter(iter), + item(item_) + { + ret = -1; + } //Maybe binary search will help to speed up this process virtual int operator() ( wxDataViewTreeNode * node) @@ -3463,7 +3491,7 @@ public: if( node->GetItem() == **m_iter ) { - m_iter++ ; + m_iter++; return DoJob::CONT; } else @@ -3482,7 +3510,8 @@ public: return DoJob::CONT; } //the row number is begin from zero - int GetResult(){ return ret -1 ; } + int GetResult() { return ret -1; } + private: ItemList::const_iterator m_iter; wxDataViewItem item; @@ -3528,7 +3557,7 @@ int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item) const static void BuildTreeHelper( wxDataViewModel * model, wxDataViewItem & item, wxDataViewTreeNode * node) { if( !model->IsContainer( item ) ) - return ; + return; wxDataViewItemArray children; unsigned int num = model->GetChildren( item, children); @@ -3539,7 +3568,7 @@ static void BuildTreeHelper( wxDataViewModel * model, wxDataViewItem & item, wx { wxDataViewTreeNode * n = new wxDataViewTreeNode( node ); n->SetItem(children[index]); - n->SetHasChildren( true ) ; + n->SetHasChildren( true ); node->AddNode( n ); } else @@ -3561,7 +3590,7 @@ void wxDataViewMainWindow::BuildTree(wxDataViewModel * model) if (GetOwner()->GetModel()->IsVirtualListModel()) { - m_count = -1 ; + m_count = -1; return; } @@ -3572,7 +3601,7 @@ void wxDataViewMainWindow::BuildTree(wxDataViewModel * model) wxDataViewItem item; SortPrepare(); BuildTreeHelper( model, item, m_root); - m_count = -1 ; + m_count = -1; } static void DestroyTreeHelper( wxDataViewTreeNode * node ) @@ -3580,9 +3609,9 @@ static void DestroyTreeHelper( wxDataViewTreeNode * node ) if( node->GetNodeNumber() != 0 ) { int len = node->GetNodeNumber(); - int i = 0 ; + int i = 0; wxDataViewTreeNodes& nodes = node->GetNodes(); - for( ; i < len; i ++ ) + for(; i < len; i ++ ) { DestroyTreeHelper(nodes[i]); } @@ -4057,15 +4086,12 @@ wxDataViewCtrl::~wxDataViewCtrl() if (m_notifier) GetModel()->RemoveNotifier( m_notifier ); - wxDataViewColumnList::const_iterator iter; - for (iter = m_cols.begin(); iter!=m_cols.end(); iter++) - { - delete *iter; - } + m_cols.Clear(); } void wxDataViewCtrl::Init() { + m_cols.DeleteContents(true); m_notifier = NULL; } @@ -4085,7 +4111,7 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, Init(); #ifdef __WXMAC__ - MacSetClipChildren( true ) ; + MacSetClipChildren( true ); #endif m_clientArea = new wxDataViewMainWindow( this, wxID_ANY ); @@ -4229,20 +4255,23 @@ wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const void wxDataViewCtrl::ColumnMoved( wxDataViewColumn* col, unsigned int new_pos ) { if (new_pos > m_cols.GetCount()) return; + + // Exchange position + m_cols.DeleteContents(false); m_cols.DeleteObject( col ); m_cols.Insert( new_pos, col ); + m_cols.DeleteContents(true); m_clientArea->UpdateDisplay(); } bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column ) { - wxDataViewColumnList::compatibility_iterator ret = m_cols.Find( column ); + wxDataViewColumnList::compatibility_iterator ret = m_cols.Find( column ); if (!ret) return false; m_cols.Erase(ret); - delete column; OnColumnChange(); return true; @@ -4250,7 +4279,7 @@ bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column ) bool wxDataViewCtrl::ClearColumns() { - m_cols.clear(); + m_cols.Clear(); OnColumnChange(); return true; } @@ -4300,7 +4329,7 @@ int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const void wxDataViewCtrl::SetSelections( const wxDataViewItemArray & sel ) { - wxDataViewSelection selection(wxDataViewSelectionCmp) ; + wxDataViewSelection selection(wxDataViewSelectionCmp); int len = sel.GetCount(); for( int i = 0; i < len; i ++ ) { @@ -4356,7 +4385,7 @@ int wxDataViewCtrl::GetSelections( wxArrayInt & sel ) const void wxDataViewCtrl::SetSelections( const wxArrayInt & sel ) { - wxDataViewSelection selection(wxDataViewSelectionCmp) ; + wxDataViewSelection selection(wxDataViewSelectionCmp); int len = sel.GetCount(); for( int i = 0; i < len; i ++ ) {