Grow text editor control to contain all text in generic wxDataViewCtrl.
Implement the behavior that Explorer uses: if the column is too narrow to fit the current text of a cell into it, don't create a too-small text control for it, because it is annoying and confusing (typically, the beginning of the text would be hidden, which is disastrous if it happens to contain numbers). Instead, grow the text control to be larger than the column for more comfortable editing. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75183 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
0082512adf
commit
e6b21147db
@ -119,6 +119,34 @@ wxDataViewColumn* GetExpanderColumnOrFirstOne(wxDataViewCtrl* dataview)
|
||||
return expander;
|
||||
}
|
||||
|
||||
wxTextCtrl *CreateEditorTextCtrl(wxWindow *parent, const wxRect& labelRect, const wxString& value)
|
||||
{
|
||||
wxTextCtrl* ctrl = new wxTextCtrl(parent, wxID_ANY, value,
|
||||
wxPoint(labelRect.x,labelRect.y),
|
||||
wxSize(labelRect.width,labelRect.height),
|
||||
wxTE_PROCESS_ENTER);
|
||||
|
||||
// Adjust size of wxTextCtrl editor to fit text, even if it means being
|
||||
// wider than the corresponding column (this is how Explorer behaves).
|
||||
const int fitting = ctrl->GetSizeFromTextSize(ctrl->GetTextExtent(ctrl->GetValue())).x;
|
||||
const int current = ctrl->GetSize().x;
|
||||
const int maxwidth = ctrl->GetParent()->GetSize().x - ctrl->GetPosition().x;
|
||||
|
||||
// Adjust size so that it fits all content. Don't change anything if the
|
||||
// allocated space is already larger than needed and don't extend wxDVC's
|
||||
// boundaries.
|
||||
int width = wxMin(wxMax(current, fitting), maxwidth);
|
||||
|
||||
if ( width != current )
|
||||
ctrl->SetSize(wxSize(width, -1));
|
||||
|
||||
// select the text in the control an place the cursor at the end
|
||||
ctrl->SetInsertionPointEnd();
|
||||
ctrl->SelectAll();
|
||||
|
||||
return ctrl;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -958,16 +986,7 @@ bool wxDataViewTextRenderer::HasEditorCtrl() const
|
||||
wxWindow* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
|
||||
wxRect labelRect, const wxVariant &value )
|
||||
{
|
||||
wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY, value,
|
||||
wxPoint(labelRect.x,labelRect.y),
|
||||
wxSize(labelRect.width,labelRect.height),
|
||||
wxTE_PROCESS_ENTER );
|
||||
|
||||
// select the text in the control an place the cursor at the end
|
||||
ctrl->SetInsertionPointEnd();
|
||||
ctrl->SelectAll();
|
||||
|
||||
return ctrl;
|
||||
return CreateEditorTextCtrl(parent, labelRect, value);
|
||||
}
|
||||
|
||||
bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxWindow *editor, wxVariant &value )
|
||||
@ -1239,16 +1258,7 @@ wxWindow* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect
|
||||
labelRect.width -= w;
|
||||
}
|
||||
|
||||
wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY, text,
|
||||
wxPoint(labelRect.x,labelRect.y),
|
||||
wxSize(labelRect.width,labelRect.height),
|
||||
wxTE_PROCESS_ENTER );
|
||||
|
||||
// select the text in the control an place the cursor at the end
|
||||
ctrl->SetInsertionPointEnd();
|
||||
ctrl->SelectAll();
|
||||
|
||||
return ctrl;
|
||||
return CreateEditorTextCtrl(parent, labelRect, text);
|
||||
}
|
||||
|
||||
bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxWindow *editor, wxVariant& value )
|
||||
|
Loading…
Reference in New Issue
Block a user