1. don't call GetPartOfWrappendLine() unnecessarily
2. optimized it (replaced by a call to HitTestLine) for the other cases git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8826 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -287,7 +287,8 @@ protected:
|
|||||||
// more readable flag testing methods
|
// more readable flag testing methods
|
||||||
bool IsSingleLine() const { return !(GetWindowStyle() & wxTE_MULTILINE); }
|
bool IsSingleLine() const { return !(GetWindowStyle() & wxTE_MULTILINE); }
|
||||||
bool IsPassword() const { return (GetWindowStyle() & wxTE_PASSWORD) != 0; }
|
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
|
// get the extent (width) of the text
|
||||||
wxCoord GetTextWidth(const wxString& text) const;
|
wxCoord GetTextWidth(const wxString& text) const;
|
||||||
|
@@ -446,7 +446,7 @@ TextTestFrame::TextTestFrame(const wxString& title)
|
|||||||
#else
|
#else
|
||||||
wxDefaultSize,
|
wxDefaultSize,
|
||||||
#endif
|
#endif
|
||||||
wxTE_MULTILINE);
|
wxTE_MULTILINE | wxHSCROLL);
|
||||||
sizerDown->Add(m_textLog, 1, wxGROW | wxALL, 5);
|
sizerDown->Add(m_textLog, 1, wxGROW | wxALL, 5);
|
||||||
wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL);
|
wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL);
|
||||||
btn = new wxButton(m_panel, TextTest_ClearLog, _T("Clear &log"));
|
btn = new wxButton(m_panel, TextTest_ClearLog, _T("Clear &log"));
|
||||||
|
@@ -1884,6 +1884,63 @@ wxRect wxTextCtrl::GetRealTextArea() const
|
|||||||
size_t wxTextCtrl::GetPartOfWrappedLine(const wxChar* text,
|
size_t wxTextCtrl::GetPartOfWrappedLine(const wxChar* text,
|
||||||
wxCoord *widthReal) const
|
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);
|
wxTextCtrl *self = wxConstCast(this, wxTextCtrl);
|
||||||
wxClientDC dc(self);
|
wxClientDC dc(self);
|
||||||
dc.SetFont(GetFont());
|
dc.SetFont(GetFont());
|
||||||
@@ -1921,12 +1978,19 @@ size_t wxTextCtrl::GetPartOfWrappedLine(const wxChar* text,
|
|||||||
wOld = w;
|
wOld = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxASSERT( col == str.length() );
|
||||||
|
|
||||||
if ( widthReal )
|
if ( widthReal )
|
||||||
{
|
{
|
||||||
|
wxASSERT( *widthReal == wOld );
|
||||||
|
|
||||||
*widthReal = wOld;
|
*widthReal = wOld;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.length();
|
//return str.length();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxTextCtrlHitTestResult wxTextCtrl::HitTestLine(const wxString& line,
|
wxTextCtrlHitTestResult wxTextCtrl::HitTestLine(const wxString& line,
|
||||||
@@ -1946,8 +2010,14 @@ wxTextCtrlHitTestResult wxTextCtrl::HitTestLine(const wxString& line,
|
|||||||
if ( x >= width )
|
if ( x >= width )
|
||||||
{
|
{
|
||||||
// clicking beyond the end of line is equivalent to clicking at
|
// clicking beyond the end of line is equivalent to clicking at
|
||||||
// the end of it
|
// the end of it, so return the last line column
|
||||||
col = line.length() - 1;
|
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;
|
res = wxTE_HT_BEYOND;
|
||||||
}
|
}
|
||||||
|
@@ -1185,7 +1185,7 @@ void wxWin32Renderer::DrawTextBorder(wxDC& dc,
|
|||||||
wxRect *rectIn)
|
wxRect *rectIn)
|
||||||
{
|
{
|
||||||
// text controls are not special under windows
|
// 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,
|
void wxWin32Renderer::DrawButtonBorder(wxDC& dc,
|
||||||
|
Reference in New Issue
Block a user