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
This commit is contained in:
Robert Roebling
2009-03-08 21:41:57 +00:00
parent 235d5f88e6
commit c937344c8f
3 changed files with 96 additions and 22 deletions

View File

@@ -463,6 +463,8 @@ public:
virtual wxBorder GetDefaultBorder() const; virtual wxBorder GetDefaultBorder() const;
void StartEditor( const wxDataViewItem & item, unsigned int column );
protected: protected:
virtual int GetSelections( wxArrayInt & sel ) const; virtual int GetSelections( wxArrayInt & sel ) const;
virtual void SetSelections( const wxArrayInt & sel ); virtual void SetSelections( const wxArrayInt & sel );

View File

@@ -702,6 +702,10 @@ bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect la
m_editorCtrl->PushEventHandler( handler ); 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) #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
handler->SetFocusOnIdle(); handler->SetFocusOnIdle();
#else #else

View File

@@ -1130,19 +1130,33 @@ wxSize wxDataViewIconTextRenderer::GetSize() const
return wxSize(80,20); return wxSize(80,20);
} }
wxControl * wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value)
wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow * WXUNUSED(parent),
wxRect WXUNUSED(labelRect),
const wxVariant& WXUNUSED(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;
} }
bool return new wxTextCtrl( parent, wxID_ANY, text,
wxDataViewIconTextRenderer::GetValueFromEditorCtrl(wxControl* WXUNUSED(editor), wxPoint(labelRect.x,labelRect.y),
wxVariant& WXUNUSED(value)) wxSize(labelRect.width,labelRect.height) );
}
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, wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item,
const wxDataViewColumn* column ) const wxDataViewColumn* column )
{ {
int row = GetRowByItem(item); int xpos = 0;
int y = GetLineStart( row ); int width = 0;
int h = GetLineHeight( m_lineHeight );
int x = 0; unsigned int cols = GetOwner()->GetColumnCount();
wxDataViewColumn *col = NULL; // If column is null the loop will compute the combined width of all columns.
for( int i = 0, cols = GetOwner()->GetColumnCount(); i < cols; i ++ ) // Otherwise, it will compute the x position of the column we are looking for.
for (unsigned int i = 0; i < cols; i++)
{ {
col = GetOwner()->GetColumnAt( i ); wxDataViewColumn* col = GetOwner()->GetColumnAt( i );
x += col->GetWidth();
if( GetOwner()->GetColumnAt(i+1) == column ) if (col == column)
break; break;
if (col->IsHidden())
continue; // skip it!
xpos += col->GetWidth();
width += col->GetWidth();
} }
int w = col->GetWidth();
m_owner->CalcScrolledPosition( x, y, &x, &y ); if(column != 0)
return wxRect(x, y, w, h); {
// 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);
if (!IsVirtualList() && (column == 0 || GetOwner()->GetExpanderColumn() == column) )
{
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;
}
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() int wxDataViewMainWindow::RecalculateCount()
@@ -4367,6 +4424,17 @@ bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const
return false; 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 #endif
// !wxUSE_GENERICDATAVIEWCTRL // !wxUSE_GENERICDATAVIEWCTRL