From e6b21147db30d82b25e2af2abc355c013033547b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Thu, 14 Nov 2013 12:13:28 +0000 Subject: [PATCH] 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 --- src/generic/datavgen.cpp | 50 ++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 6b4bf50e75..196bcb25a2 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -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 )