From c937344c8f4bbd14b96ddba8adcdd15341c06ffd Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 8 Mar 2009 21:41:57 +0000 Subject: [PATCH] Commit most parts of #10495 wxDataViewCtrl needs a way to start the label editor programmatically git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59438 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/dataview.h | 2 + src/common/datavcmn.cpp | 4 ++ src/generic/datavgen.cpp | 110 +++++++++++++++++++++++++++------- 3 files changed, 95 insertions(+), 21 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 267e2c98a9..35bee5a82a 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -463,6 +463,8 @@ public: virtual wxBorder GetDefaultBorder() const; + void StartEditor( const wxDataViewItem & item, unsigned int column ); + protected: virtual int GetSelections( wxArrayInt & sel ) const; virtual void SetSelections( const wxArrayInt & sel ); diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 17f3e911d3..6a62fa9692 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -702,6 +702,10 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la m_editorCtrl->PushEventHandler( handler ); + // there might be no editor control for the given item + if (!m_editorCtrl) + return false; + #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL) handler->SetFocusOnIdle(); #else diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index cd8b74d5d7..35961c86ce 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -1130,19 +1130,33 @@ wxSize wxDataViewIconTextRenderer::GetSize() const return wxSize(80,20); } -wxControl * -wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow * WXUNUSED(parent), - wxRect WXUNUSED(labelRect), - const wxVariant& WXUNUSED(value)) +wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value) { - return NULL; + wxDataViewIconText iconText; + iconText << value; + + wxString text = iconText.GetText(); + + // adjust the label rect to take the width of the icon into account + if (iconText.GetIcon().IsOk()) + { + int w = iconText.GetIcon().GetWidth() + 4; + labelRect.x += w; + labelRect.width -= w; + } + + return new wxTextCtrl( parent, wxID_ANY, text, + wxPoint(labelRect.x,labelRect.y), + wxSize(labelRect.width,labelRect.height) ); } -bool -wxDataViewIconTextRenderer::GetValueFromEditorCtrl(wxControl* WXUNUSED(editor), - wxVariant& WXUNUSED(value)) +bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant& value ) { - return false; + wxTextCtrl *text = (wxTextCtrl*) editor; + + wxDataViewIconText iconText(text->GetValue(), m_value.GetIcon()); + value << iconText; + return true; } //----------------------------------------------------------------------------- @@ -3143,21 +3157,64 @@ void wxDataViewMainWindow::HitTest( const wxPoint & point, wxDataViewItem & item wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item, const wxDataViewColumn* column ) { + int xpos = 0; + int width = 0; + + unsigned int cols = GetOwner()->GetColumnCount(); + // If column is null the loop will compute the combined width of all columns. + // Otherwise, it will compute the x position of the column we are looking for. + for (unsigned int i = 0; i < cols; i++) + { + wxDataViewColumn* col = GetOwner()->GetColumnAt( i ); + + if (col == column) + break; + + if (col->IsHidden()) + continue; // skip it! + + xpos += col->GetWidth(); + width += col->GetWidth(); + } + + if(column != 0) + { + // If we have a column, we need can get its width directly. + if(column->IsHidden()) + width = 0; + else + width = column->GetWidth(); + + } + else + { + // If we have no column, we reset the x position back to zero. + xpos = 0; + } + + // we have to take an expander column into account and compute its indentation + // to get the correct x position where the actual text is + int indent = 0; int row = GetRowByItem(item); - int y = GetLineStart( row ); - int h = GetLineHeight( m_lineHeight ); - int x = 0; - wxDataViewColumn *col = NULL; - for( int i = 0, cols = GetOwner()->GetColumnCount(); i < cols; i ++ ) + if (!IsVirtualList() && (column == 0 || GetOwner()->GetExpanderColumn() == column) ) { - col = GetOwner()->GetColumnAt( i ); - x += col->GetWidth(); - if( GetOwner()->GetColumnAt(i+1) == column ) - break; + wxDataViewTreeNode* node = GetTreeNodeByRow(row); + indent = GetOwner()->GetIndent() * node->GetIndentLevel(); + indent = indent + m_lineHeight; // use m_lineHeight as the width of the expander + + if(!node->HasChildren()) + delete node; } - int w = col->GetWidth(); - m_owner->CalcScrolledPosition( x, y, &x, &y ); - return wxRect(x, y, w, h); + + wxRect itemRect( xpos + indent, + GetLineStart( row ), + width - indent, + GetLineHeight( row ) ); + + GetOwner()->CalcScrolledPosition( itemRect.x, itemRect.y, + &itemRect.x, &itemRect.y ); + + return itemRect; } int wxDataViewMainWindow::RecalculateCount() @@ -4367,6 +4424,17 @@ bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const return false; } +void wxDataViewCtrl::StartEditor( const wxDataViewItem & item, unsigned int column ) +{ + wxDataViewColumn* col = GetColumn( column ); + if (!col) + return; + + wxRect itemRect = GetItemRect(item, col); + wxDataViewRenderer* renderer = col->GetRenderer(); + renderer->StartEditing(item, itemRect); +} + #endif // !wxUSE_GENERICDATAVIEWCTRL -- 2.45.2