From f29a481a66ab2da4424a3127be0c17c3e660e16d Mon Sep 17 00:00:00 2001 From: Mart Raudsepp Date: Wed, 3 Aug 2005 13:14:36 +0000 Subject: [PATCH] [wxGTK2] multiline wxTextCtrl: Implement XYToPosition, PositionToXY and GetLineLength natively, making them not take an eternity per call. Also closes bug #1250464. Not sure if this should go into changes.txt. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35060 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/textctrl.cpp | 36 ++++++++++++++++++++++++++++++++++-- src/gtk1/textctrl.cpp | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 5ffdf7d7d4..878b9d06ee 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1117,6 +1117,15 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const { if ( m_windowStyle & wxTE_MULTILINE ) { +#ifdef __WXGTK20__ + GtkTextIter iter; + gtk_text_buffer_get_iter_at_offset(m_buffer, &iter, pos); + if (gtk_text_iter_is_end(&iter)) + return false; + + *y = gtk_text_iter_get_line(&iter); + *x = gtk_text_iter_get_line_offset(&iter); +#else wxString text = GetValue(); // cast to prevent warning. But pos really should've been unsigned. @@ -1137,6 +1146,7 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const else (*x)++; } +#endif } else // single line control { @@ -1159,17 +1169,39 @@ long wxTextCtrl::XYToPosition(long x, long y ) const { if (!(m_windowStyle & wxTE_MULTILINE)) return 0; +#ifdef __WXGTK20__ + GtkTextIter iter; + gtk_text_buffer_get_iter_at_line_offset(m_buffer, &iter, y, x); + return gtk_text_iter_get_offset(&iter); +#else long pos=0; for( int i=0; i last_line) + return -1; + + GtkTextIter iter; + gtk_text_buffer_get_iter_at_line(m_buffer, &iter, lineNo); + // get_chars_in_line return includes paragraph delimiters, so need to subtract 1 IF it is not the last line + return gtk_text_iter_get_chars_in_line(&iter) - ((lineNo == last_line) ? 0 : 1); + } + else +#endif + { + wxString str = GetLineText (lineNo); + return (int) str.Length(); + } } int wxTextCtrl::GetNumberOfLines() const diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 5ffdf7d7d4..878b9d06ee 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -1117,6 +1117,15 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const { if ( m_windowStyle & wxTE_MULTILINE ) { +#ifdef __WXGTK20__ + GtkTextIter iter; + gtk_text_buffer_get_iter_at_offset(m_buffer, &iter, pos); + if (gtk_text_iter_is_end(&iter)) + return false; + + *y = gtk_text_iter_get_line(&iter); + *x = gtk_text_iter_get_line_offset(&iter); +#else wxString text = GetValue(); // cast to prevent warning. But pos really should've been unsigned. @@ -1137,6 +1146,7 @@ bool wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const else (*x)++; } +#endif } else // single line control { @@ -1159,17 +1169,39 @@ long wxTextCtrl::XYToPosition(long x, long y ) const { if (!(m_windowStyle & wxTE_MULTILINE)) return 0; +#ifdef __WXGTK20__ + GtkTextIter iter; + gtk_text_buffer_get_iter_at_line_offset(m_buffer, &iter, y, x); + return gtk_text_iter_get_offset(&iter); +#else long pos=0; for( int i=0; i last_line) + return -1; + + GtkTextIter iter; + gtk_text_buffer_get_iter_at_line(m_buffer, &iter, lineNo); + // get_chars_in_line return includes paragraph delimiters, so need to subtract 1 IF it is not the last line + return gtk_text_iter_get_chars_in_line(&iter) - ((lineNo == last_line) ? 0 : 1); + } + else +#endif + { + wxString str = GetLineText (lineNo); + return (int) str.Length(); + } } int wxTextCtrl::GetNumberOfLines() const -- 2.45.2