X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d59051dd0a4cbb3b51dfcc89025eb19a4671a912..0812732316f715a480526cedcd481e7fc31a130c:/src/gtk/textctrl.cpp diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index f165c20805..c738901fb5 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -435,12 +435,18 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const { wxString text = GetValue(); - if( pos >= (long)text.Len() ) + // cast to prevent warning. But pos really should've been unsigned. + if( (unsigned long)pos > text.Len() ) return FALSE; *x=1; // Col 1 *y=1; // Line 1 - for ( const char *p = text.c_str(); *p; p++ ) + + if (pos == 0) + return TRUE; + + const char* stop = text.c_str() + pos; + for ( const char *p = text.c_str(); p < stop; p++ ) { if (*p == '\n') { @@ -453,7 +459,7 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const } else // single line control { - if ( pos < GTK_ENTRY(m_text)->text_length ) + if ( pos <= GTK_ENTRY(m_text)->text_length ) { *y = 1; *x = pos; @@ -473,10 +479,11 @@ long wxTextCtrl::XYToPosition(long x, long y ) const if (!(m_windowStyle & wxTE_MULTILINE)) return 0; long pos=0; + /* This is a kludge; our XY values are 1-based, but GetLineLength() + * and --Text() start counting at 0. (and so say the docs) */ + for( int i=1; i