diff --git a/include/wx/univ/textctrl.h b/include/wx/univ/textctrl.h index e1c2f67629..c05405d3b4 100644 --- a/include/wx/univ/textctrl.h +++ b/include/wx/univ/textctrl.h @@ -287,7 +287,8 @@ protected: // more readable flag testing methods bool IsSingleLine() const { return !(GetWindowStyle() & wxTE_MULTILINE); } bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD) != 0; } - bool WrapLines() const { return !(GetWindowStyle() & wxHSCROLL); } + bool WrapLines() const + { return !IsSingleLine() && !(GetWindowStyle() & wxHSCROLL); } // get the extent (width) of the text wxCoord GetTextWidth(const wxString& text) const; diff --git a/samples/textctrl/texttest.cpp b/samples/textctrl/texttest.cpp index 8207e2de3b..c94a01e125 100644 --- a/samples/textctrl/texttest.cpp +++ b/samples/textctrl/texttest.cpp @@ -446,7 +446,7 @@ TextTestFrame::TextTestFrame(const wxString& title) #else wxDefaultSize, #endif - wxTE_MULTILINE); + wxTE_MULTILINE | wxHSCROLL); sizerDown->Add(m_textLog, 1, wxGROW | wxALL, 5); wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL); btn = new wxButton(m_panel, TextTest_ClearLog, _T("Clear &log")); diff --git a/src/univ/textctrl.cpp b/src/univ/textctrl.cpp index c79b276cdb..0ac059d374 100644 --- a/src/univ/textctrl.cpp +++ b/src/univ/textctrl.cpp @@ -1884,6 +1884,63 @@ wxRect wxTextCtrl::GetRealTextArea() const size_t wxTextCtrl::GetPartOfWrappedLine(const wxChar* text, wxCoord *widthReal) const { + // this function is slow, it shouldn't be called unless really needed + wxASSERT_MSG( WrapLines(), _T("shouldn't be called") ); + + wxString s(text); + wxTextCoord col; + wxCoord wReal = -1; + switch ( HitTestLine(s, m_rectText.width, &col) ) + { + /* + case wxTE_HT_BEFORE: + case wxTE_HT_BELOW: + */ + default: + wxFAIL_MSG(_T("unexpected HitTestLine() return value")); + // fall through + + case wxTE_HT_ON_TEXT: + if ( col > 0 ) + { + // the last entirely seen character is the last one unless the + // width of the string is exactly the max width + wReal = GetTextWidth(s.Truncate(col)); + if ( wReal > m_rectText.width ) + { + // this character is not entirely visible, take the + // previous one + col--; + } + //else: we can just see it + } + break; + + case wxTE_HT_BEYOND: + break; + } + + // we return the number of characters, not the index of the last one + if ( (size_t)col < s.length() ) + { + // but don't return more than this (empty) string has + col++; + } + + if ( widthReal ) + { + if ( wReal == -1 ) + { + // calc it if not done yet + wReal = GetTextWidth(s.Truncate(col)); + } + + *widthReal = wReal; + } + + // VZ: old, horribly inefficient code which can still be used for checking + // the result - to be removed later +#if 0 wxTextCtrl *self = wxConstCast(this, wxTextCtrl); wxClientDC dc(self); dc.SetFont(GetFont()); @@ -1921,12 +1978,19 @@ size_t wxTextCtrl::GetPartOfWrappedLine(const wxChar* text, wOld = w; } + wxASSERT( col == str.length() ); + if ( widthReal ) { + wxASSERT( *widthReal == wOld ); + *widthReal = wOld; } - return str.length(); + //return str.length(); +#endif + + return col; } wxTextCtrlHitTestResult wxTextCtrl::HitTestLine(const wxString& line, @@ -1946,8 +2010,14 @@ wxTextCtrlHitTestResult wxTextCtrl::HitTestLine(const wxString& line, if ( x >= width ) { // clicking beyond the end of line is equivalent to clicking at - // the end of it - col = line.length() - 1; + // the end of it, so return the last line column + col = line.length(); + if ( col ) + { + // unless the line is empty and so doesn't have any column at all - + // in this case return 0, what else can we do? + col--; + } res = wxTE_HT_BEYOND; } diff --git a/src/univ/themes/win32.cpp b/src/univ/themes/win32.cpp index 04367683bd..a09955ed82 100644 --- a/src/univ/themes/win32.cpp +++ b/src/univ/themes/win32.cpp @@ -1185,7 +1185,7 @@ void wxWin32Renderer::DrawTextBorder(wxDC& dc, wxRect *rectIn) { // text controls are not special under windows - return DrawBorder(dc, border, rect, flags, rectIn); + DrawBorder(dc, border, rect, flags, rectIn); } void wxWin32Renderer::DrawButtonBorder(wxDC& dc,