X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2a9f020897307179a18df7cb7d30ffc75b488a2b..83666e99093aa0b65c497f7e6c75d98a875667cc:/src/generic/datavgen.cpp diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index e1caf28c3c..ed190733d2 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -153,6 +153,8 @@ public: virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL); virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + + virtual bool AcceptsFocusFromKeyboard() const { return false; } protected: virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); @@ -168,6 +170,7 @@ protected: int m_scrollOffsetX; int m_buttonHeight; + bool m_vetoColumnDrag; bool m_delayedUpdate; wxImageList *m_imageList; @@ -332,7 +335,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 +347,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 +377,7 @@ public: void ChangeSubTreeCount( int num ) { if( !m_open ) - return ; + return; m_subTreeCount += num; if( m_parent ) m_parent->ChangeSubTreeCount(num); @@ -432,7 +435,7 @@ public: const wxSize &size = wxDefaultSize, const wxString &name = wxT("wxdataviewctrlmainwindow") ); virtual ~wxDataViewMainWindow(); - + bool IsVirtualList() const { return m_root == NULL; } // notifications from wxDataViewModel @@ -500,7 +503,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; } @@ -524,7 +527,7 @@ public: } wxRect GetLineRect( unsigned int row ) const; - + int GetLineStart( unsigned int row ) const; // row * m_lineHeight in fixed mode int GetLineHeight( unsigned int row ) const; // m_lineHeight in fixed mode int GetLineAt( unsigned int y ) const; // y / m_lineHeight in fixed mode @@ -532,7 +535,7 @@ public: //Some useful functions for row and item mapping wxDataViewItem GetItemByRow( unsigned int row ) const; int GetRowByItem( const wxDataViewItem & item ) const; - + //Methods for building the mapping tree void BuildTree( wxDataViewModel * model ); void DestroyTree(); @@ -546,7 +549,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 ); @@ -657,7 +660,7 @@ wxDC *wxDataViewRenderer::GetDC() } void wxDataViewRenderer::SetAlignment( int align ) -{ +{ m_align=align; } @@ -667,15 +670,15 @@ int wxDataViewRenderer::GetAlignment() const } int wxDataViewRenderer::CalculateAlignment() const -{ +{ if (m_align == wxDVR_DEFAULT_ALIGNMENT) { if (GetOwner() == NULL) return wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL; - + return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL; } - + return m_align; } @@ -1327,6 +1330,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 +1366,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 @@ -1400,7 +1404,7 @@ void wxDataViewHeaderWindowMSW::UpdateDisplay() // remove old columns for (int j=0, max=Header_GetItemCount((HWND)m_hWnd); j < max; j++) Header_DeleteItem((HWND)m_hWnd, 0); - + m_imageList->RemoveAll(); // add the updated array of columns to the header control @@ -1427,7 +1431,7 @@ void wxDataViewHeaderWindowMSW::UpdateDisplay() hdi.fmt = HDF_LEFT | HDF_STRING; if (col->GetBitmap().IsOk()) hdi.fmt |= HDF_IMAGE; - + //hdi.fmt &= ~(HDF_SORTDOWN|HDF_SORTUP); if (col->IsSortable() && GetOwner()->GetSortingColumn() == col) @@ -1506,6 +1510,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 +1528,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 +2054,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(); } @@ -2074,7 +2095,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) // compute which columns needs to be redrawn unsigned int cols = GetOwner()->GetColumnCount(); unsigned int col_start = 0; - unsigned int x_start = 0; + unsigned int x_start; for (x_start = 0; col_start < cols; col_start++) { wxDataViewColumn *col = GetOwner()->GetColumn(col_start); @@ -2175,7 +2196,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) cell_rect.x = x_start; for (unsigned int i = col_start; i < col_last; i++) { - + wxDataViewColumn *col = GetOwner()->GetColumn( i ); wxDataViewRenderer *cell = col->GetRenderer(); cell_rect.width = col->GetWidth(); @@ -2203,7 +2224,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) } else { - dataitem = wxDataViewItem( (void*) item ); + dataitem = wxDataViewItem( wxUIntToPtr(item) ); } model->GetValue( value, dataitem, col->GetModelColumn()); @@ -2235,7 +2256,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 +2279,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 @@ -2334,9 +2355,9 @@ void wxDataViewMainWindow::OnRenameTimer() break; xpos += c->GetWidth(); } - wxRect labelRect( xpos, + wxRect labelRect( xpos, GetLineStart( m_currentRow ), - m_currentCol->GetWidth(), + m_currentCol->GetWidth(), GetLineHeight( m_currentRow ) ); GetOwner()->CalcScrolledPosition( labelRect.x, labelRect.y, @@ -2353,15 +2374,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 +2394,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 +2409,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 +2425,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 +2518,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 ) { @@ -2632,7 +2653,7 @@ void wxDataViewMainWindow::ScrollTo( int rows, int column ) { wxRect rect = GetClientRect(); int colnum = 0; - int x_start = 0, x_end = 0, w = 0; + int x_start, w = 0; int xx, yy, xe; m_owner->CalcUnscrolledPosition( rect.x, rect.y, &xx, &yy ); for (x_start = 0; colnum < column; colnum++) @@ -2645,7 +2666,7 @@ void wxDataViewMainWindow::ScrollTo( int rows, int column ) x_start += w; } - x_end = x_start + w; + int x_end = x_start + w; xe = xx + rect.width; if( x_end > xe ) { @@ -2672,7 +2693,7 @@ int wxDataViewMainWindow::GetEndOfLastCol() const for (i = 0; i < GetOwner()->GetColumnCount(); i++) { const wxDataViewColumn *c = - wx_const_cast(wxDataViewCtrl*, GetOwner())->GetColumn( i ); + const_cast(GetOwner())->GetColumn( i ); if (!c->IsHidden()) width += c->GetWidth(); @@ -2867,7 +2888,7 @@ void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow ) if (start > client_size.y) return; wxRect rect( 0, start, client_size.x, client_size.y - start ); - + Refresh( true, &rect ); } @@ -2937,44 +2958,52 @@ wxRect wxDataViewMainWindow::GetLineRect( unsigned int row ) const int wxDataViewMainWindow::GetLineStart( unsigned int row ) const { const wxDataViewModel *model = GetOwner()->GetModel(); - + if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) { // TODO make more efficient - + int start = 0; - + unsigned int r; for (r = 0; r < row; r++) { - const wxDataViewTreeNode* node = GetTreeNodeByRow(r); - if (!node) return start; - - wxDataViewItem item = node->GetItem(); - - unsigned int cols = GetOwner()->GetColumnCount(); - unsigned int col; - int height = m_lineHeight; - for (col = 0; col < cols; col++) - { + const wxDataViewTreeNode* node = GetTreeNodeByRow(r); + if (!node) return start; + + wxDataViewItem item = node->GetItem(); + + if (node && !node->HasChildren()) + { + // 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); + } + + unsigned int cols = GetOwner()->GetColumnCount(); + unsigned int col; + int height = m_lineHeight; + for (col = 0; col < cols; col++) + { const wxDataViewColumn *column = GetOwner()->GetColumn(col); if (column->IsHidden()) continue; // skip it! - + if ((col != 0) && model->IsContainer(item) && !model->HasContainerColumns(item)) continue; // skip it! - + const wxDataViewRenderer *renderer = column->GetRenderer(); wxVariant value; model->GetValue( value, item, column->GetModelColumn() ); wxDataViewRenderer *renderer2 = const_cast(renderer); renderer2->SetValue( value ); height = wxMax( height, renderer->GetSize().y ); - } - - start += height; + } + + + start += height; } - + return start; } else @@ -2987,74 +3016,82 @@ int wxDataViewMainWindow::GetLineAt( unsigned int y ) const { const wxDataViewModel *model = GetOwner()->GetModel(); - if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) + // check for the easy case first + if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT) ) + return y / m_lineHeight; + + // TODO make more efficient + unsigned int row = 0; + unsigned int yy = 0; + for (;;) { - // TODO make more efficient - - unsigned int row = 0; - unsigned int yy = 0; - for (;;) + const wxDataViewTreeNode* node = GetTreeNodeByRow(row); + if (!node) + { + // not really correct... + return row + ((y-yy) / m_lineHeight); + } + + wxDataViewItem item = node->GetItem(); + + if (node && !node->HasChildren()) { - const wxDataViewTreeNode* node = GetTreeNodeByRow(row); - if (!node) - { - // not really correct... - return row + ((y-yy) / m_lineHeight); - } - - wxDataViewItem item = node->GetItem(); - - unsigned int cols = GetOwner()->GetColumnCount(); - unsigned int col; - int height = m_lineHeight; - for (col = 0; col < cols; col++) - { - const wxDataViewColumn *column = GetOwner()->GetColumn(col); - if (column->IsHidden()) - continue; // skip it! - - if ((col != 0) && model->IsContainer(item) && !model->HasContainerColumns(item)) - continue; // skip it! - - const wxDataViewRenderer *renderer = column->GetRenderer(); - wxVariant value; - model->GetValue( value, item, column->GetModelColumn() ); - wxDataViewRenderer *renderer2 = const_cast(renderer); - renderer2->SetValue( value ); - height = wxMax( height, renderer->GetSize().y ); - } - - yy += height; - if (y < yy) - return row; - - row++; + // 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); } - - return -1; - } - else - { - return y / m_lineHeight; + + unsigned int cols = GetOwner()->GetColumnCount(); + unsigned int col; + int height = m_lineHeight; + for (col = 0; col < cols; col++) + { + const wxDataViewColumn *column = GetOwner()->GetColumn(col); + if (column->IsHidden()) + continue; // skip it! + + if ((col != 0) && model->IsContainer(item) && !model->HasContainerColumns(item)) + continue; // skip it! + + const wxDataViewRenderer *renderer = column->GetRenderer(); + wxVariant value; + model->GetValue( value, item, column->GetModelColumn() ); + wxDataViewRenderer *renderer2 = const_cast(renderer); + renderer2->SetValue( value ); + height = wxMax( height, renderer->GetSize().y ); + } + + yy += height; + if (y < yy) + return row; + + row++; } } int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const { const wxDataViewModel *model = GetOwner()->GetModel(); - + if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) { wxASSERT( !IsVirtualList() ); - + const wxDataViewTreeNode* node = GetTreeNodeByRow(row); // wxASSERT( node ); if (!node) return m_lineHeight; wxDataViewItem item = node->GetItem(); - + + if (node && !node->HasChildren()) + { + // 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); + } + int height = m_lineHeight; - + unsigned int cols = GetOwner()->GetColumnCount(); unsigned int col; for (col = 0; col < cols; col++) @@ -3065,7 +3102,7 @@ int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const if ((col != 0) && model->IsContainer(item) && !model->HasContainerColumns(item)) continue; // skip it! - + const wxDataViewRenderer *renderer = column->GetRenderer(); wxVariant value; model->GetValue( value, item, column->GetModelColumn() ); @@ -3085,15 +3122,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; } @@ -3121,7 +3158,7 @@ public: current ++; if( current == static_cast(row)) { - ret = wxDataViewItem( n ) ; + ret = wxDataViewItem( n ); return DoJob::OK; } return DoJob::CONT; @@ -3129,7 +3166,7 @@ public: wxDataViewItem GetResult(){ return ret; } private: unsigned int row; - int current ; + int current; wxDataViewItem ret; }; @@ -3137,7 +3174,7 @@ wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row) const { if (!m_root) { - return wxDataViewItem( (void*) row ); + return wxDataViewItem( wxUIntToPtr(row) ); } else { @@ -3153,18 +3190,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; } @@ -3182,7 +3219,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; @@ -3198,7 +3235,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; @@ -3209,16 +3246,16 @@ public: wxDataViewTreeNode * GetResult(){ return ret; } private: unsigned int row; - int current ; + int current; wxDataViewTreeNode * ret; - wxDataViewTreeNode * parent ; + wxDataViewTreeNode * parent; }; wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row) const { wxASSERT( !IsVirtualList() ); - + RowToTreeNodeJob job( row , -2, m_root ); Walker( m_root , job ); return job.GetResult(); @@ -3239,6 +3276,9 @@ wxDataViewEvent wxDataViewMainWindow::SendExpanderEvent( wxEventType type, const void wxDataViewMainWindow::OnExpanding( unsigned int row ) { + if (IsVirtualList()) + return; + wxDataViewTreeNode * node = GetTreeNodeByRow(row); if( node != NULL ) { @@ -3278,6 +3318,9 @@ void wxDataViewMainWindow::OnExpanding( unsigned int row ) void wxDataViewMainWindow::OnCollapsing(unsigned int row) { + if (IsVirtualList()) + return; + wxDataViewTreeNode * node = GetTreeNodeByRow(row); if( node != NULL ) { @@ -3298,7 +3341,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); @@ -3333,7 +3376,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() ) { @@ -3346,14 +3389,14 @@ wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item wxDataViewTreeNodes nodes = node->GetNodes(); unsigned int i; bool found = false; - + for (i = 0; i < nodes.GetCount(); i ++) { if (nodes[i]->GetItem() == (**iter)) { if (nodes[i]->GetItem() == item) return nodes[i]; - + node = nodes[i]; found = true; break; @@ -3373,10 +3416,9 @@ void wxDataViewMainWindow::HitTest( const wxPoint & point, wxDataViewItem & item wxDataViewColumn *col = NULL; unsigned int cols = GetOwner()->GetColumnCount(); unsigned int colnum = 0; - unsigned int x_start = 0; int x, y; m_owner->CalcUnscrolledPosition( point.x, point.y, &x, &y ); - for (x_start = 0; colnum < cols; colnum++) + for (unsigned x_start = 0; colnum < cols; colnum++) { col = GetOwner()->GetColumn(colnum); if (col->IsHidden()) @@ -3432,9 +3474,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) @@ -3447,7 +3492,7 @@ public: if( node->GetItem() == **m_iter ) { - m_iter++ ; + m_iter++; return DoJob::CONT; } else @@ -3466,7 +3511,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; @@ -3491,7 +3537,7 @@ int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item) const //Compose the a parent-chain of the finding item ItemList list; - wxDataViewItem * pItem = NULL; + wxDataViewItem * pItem; list.DeleteContents( true ); wxDataViewItem it( item ); while( it.IsOk() ) @@ -3512,7 +3558,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); @@ -3523,7 +3569,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 @@ -3545,7 +3591,7 @@ void wxDataViewMainWindow::BuildTree(wxDataViewModel * model) if (GetOwner()->GetModel()->IsVirtualListModel()) { - m_count = -1 ; + m_count = -1; return; } @@ -3556,7 +3602,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 ) @@ -3564,9 +3610,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]); } @@ -3586,7 +3632,7 @@ void wxDataViewMainWindow::DestroyTree() void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) { - if ( HandleAsNavigationKey(event) ) + if ( GetParent()->HandleAsNavigationKey(event) ) return; // no item -> nothing to do @@ -3720,7 +3766,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) { int indent = node->GetIndentLevel(); indent = GetOwner()->GetIndent()*indent; - wxRect rect( xpos + indent + EXPANDER_MARGIN, + wxRect rect( xpos + indent + EXPANDER_MARGIN, GetLineStart( current ) + EXPANDER_MARGIN + (GetLineHeight(current)/2) - (m_lineHeight/2) - EXPANDER_OFFSET, m_lineHeight-2*EXPANDER_MARGIN, m_lineHeight-2*EXPANDER_MARGIN + EXPANDER_OFFSET); @@ -3848,11 +3894,11 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) { int indent = node->GetIndentLevel(); indent = GetOwner()->GetIndent()*indent; - wxRect rect( xpos + indent + EXPANDER_MARGIN, + wxRect rect( xpos + indent + EXPANDER_MARGIN, GetLineStart( current ) + EXPANDER_MARGIN + (GetLineHeight(current)/2) - (m_lineHeight/2) - EXPANDER_OFFSET, m_lineHeight-2*EXPANDER_MARGIN, m_lineHeight-2*EXPANDER_MARGIN + EXPANDER_OFFSET); - + if( rect.Contains( x, y) ) { expander = true; @@ -3971,7 +4017,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) wxFAIL_MSG( _T("how did we get here?") ); } } - + if (m_currentRow != oldCurrentRow) RefreshRow( oldCurrentRow ); @@ -4041,16 +4087,17 @@ 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; + + // No sorting column at start + m_sortingColumn = NULL; + m_headerArea = NULL; } bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, @@ -4059,17 +4106,17 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, { if ( (style & wxBORDER_MASK) == 0) style |= wxBORDER_SUNKEN; - + + Init(); + if (!wxControl::Create( parent, id, pos, size, style | wxScrolledWindowStyle, validator)) return false; SetInitialSize(size); - Init(); - #ifdef __WXMAC__ - MacSetClipChildren( true ) ; + MacSetClipChildren( true ); #endif m_clientArea = new wxDataViewMainWindow( this, wxID_ANY ); @@ -4109,6 +4156,15 @@ WXLRESULT wxDataViewCtrl::MSWWindowProc(WXUINT nMsg, } #endif +wxSize wxDataViewCtrl::GetSizeAvailableForScrollTarget(const wxSize& size) +{ + wxSize newsize = size; + if (!HasFlag(wxDV_NO_HEADER) && (m_headerArea)) + newsize.y -= m_headerArea->GetSize().y; + + return newsize; +} + void wxDataViewCtrl::OnSize( wxSizeEvent &WXUNUSED(event) ) { // We need to override OnSize so that our scrolled @@ -4123,6 +4179,12 @@ void wxDataViewCtrl::OnSize( wxSizeEvent &WXUNUSED(event) ) AdjustScrollbars(); } +void wxDataViewCtrl::SetFocus() +{ + if (m_clientArea) + m_clientArea->SetFocus(); +} + bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model ) { if (!wxDataViewCtrlBase::AssociateModel( model )) @@ -4161,6 +4223,16 @@ bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col ) return true; } +bool wxDataViewCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col ) +{ + if (!wxDataViewCtrlBase::InsertColumn(pos,col)) + return false; + + m_cols.Insert( pos, col ); + OnColumnChange(); + return true; +} + void wxDataViewCtrl::OnColumnChange() { if (m_headerArea) @@ -4203,20 +4275,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; @@ -4224,7 +4299,7 @@ bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column ) bool wxDataViewCtrl::ClearColumns() { - m_cols.clear(); + m_cols.Clear(); OnColumnChange(); return true; } @@ -4274,7 +4349,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 ++ ) { @@ -4330,7 +4405,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 ++ ) {