From c13cace12594b37706e9520a6fbd602c949f8127 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 17 Oct 2000 22:14:35 +0000 Subject: [PATCH] added automatic growing of in-place wxTextCtrls for generic wxListCtrl and wxTreeCtrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8574 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/listctrl.cpp | 17 +++++++++++++++++ src/generic/treectlg.cpp | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 8e7857291f..6b0861d9b0 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -264,6 +264,7 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString &name = "listctrltextctrl" ); void OnChar( wxKeyEvent &event ); + void OnKeyUp( wxKeyEvent &event ); void OnKillFocus( wxFocusEvent &event ); private: @@ -1469,6 +1470,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxListTextCtrl,wxTextCtrl); BEGIN_EVENT_TABLE(wxListTextCtrl,wxTextCtrl) EVT_CHAR (wxListTextCtrl::OnChar) + EVT_KEY_UP (wxListTextCtrl::OnKeyUp) EVT_KILL_FOCUS (wxListTextCtrl::OnKillFocus) END_EVENT_TABLE() @@ -1522,6 +1524,21 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event ) event.Skip(); } +void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) +{ + // auto-grow the textctrl: + wxSize parentSize = m_owner->GetSize(); + wxPoint myPos = GetPosition(); + wxSize mySize = GetSize(); + int sx, sy; + GetTextExtent(GetValue() + _T("MM"), &sx, &sy); + if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x; + if (mySize.x > sx) sx = mySize.x; + SetSize(sx, -1); + + event.Skip(); +} + void wxListTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) { if (!wxPendingDelete.Member(this)) diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 01072caca3..172514f0b6 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -89,6 +89,7 @@ public: const wxString &name = wxTextCtrlNameStr ); void OnChar( wxKeyEvent &event ); + void OnKeyUp( wxKeyEvent &event ); void OnKillFocus( wxFocusEvent &event ); private: @@ -266,6 +267,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxTreeTextCtrl,wxTextCtrl); BEGIN_EVENT_TABLE(wxTreeTextCtrl,wxTextCtrl) EVT_CHAR (wxTreeTextCtrl::OnChar) + EVT_KEY_UP (wxTreeTextCtrl::OnKeyUp) EVT_KILL_FOCUS (wxTreeTextCtrl::OnKillFocus) END_EVENT_TABLE() @@ -318,6 +320,21 @@ void wxTreeTextCtrl::OnChar( wxKeyEvent &event ) event.Skip(); } +void wxTreeTextCtrl::OnKeyUp( wxKeyEvent &event ) +{ + // auto-grow the textctrl: + wxSize parentSize = m_owner->GetSize(); + wxPoint myPos = GetPosition(); + wxSize mySize = GetSize(); + int sx, sy; + GetTextExtent(GetValue() + _T("MM"), &sx, &sy); + if (myPos.x + sx > parentSize.x) sx = parentSize.x - myPos.x; + if (mySize.x > sx) sx = mySize.x; + SetSize(sx, -1); + + event.Skip(); +} + void wxTreeTextCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) ) { if (!wxPendingDelete.Member(this)) -- 2.45.2