some gixes to PositionToXY() - not sure if I made it work better or worse
though git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1489 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -431,20 +431,18 @@ void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
|
|||||||
|
|
||||||
long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
|
long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
|
||||||
{
|
{
|
||||||
if (!(m_windowStyle & wxTE_MULTILINE))
|
if ( m_windowStyle & wxTE_MULTILINE )
|
||||||
return 0;
|
{
|
||||||
gint len = gtk_text_get_length( GTK_TEXT(m_text) );
|
wxString text = GetValue();
|
||||||
char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
|
|
||||||
if(!text)
|
if( pos >= text.Len() )
|
||||||
return 0;
|
return FALSE;
|
||||||
if( pos >= len)
|
|
||||||
return pos=len-1;
|
|
||||||
|
|
||||||
*x=1; // Col 1
|
*x=1; // Col 1
|
||||||
*y=1; // Line 1
|
*y=1; // Line 1
|
||||||
for (int i = 0; i < pos; i++ )
|
for ( const char *p = text.c_str(); *p; p++ )
|
||||||
{
|
{
|
||||||
if (text[i] == '\n')
|
if (*p == '\n')
|
||||||
{
|
{
|
||||||
(*y)++;
|
(*y)++;
|
||||||
*x=1;
|
*x=1;
|
||||||
@@ -452,8 +450,22 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
|
|||||||
else
|
else
|
||||||
(*x)++;
|
(*x)++;
|
||||||
}
|
}
|
||||||
g_free( text );
|
}
|
||||||
return 1;
|
else // single line control
|
||||||
|
{
|
||||||
|
if ( pos < GTK_ENTRY(m_text)->text_length )
|
||||||
|
{
|
||||||
|
*y = 1;
|
||||||
|
*x = pos;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// index out of bounds
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
long wxTextCtrl::XYToPosition(long x, long y ) const
|
long wxTextCtrl::XYToPosition(long x, long y ) const
|
||||||
|
@@ -431,20 +431,18 @@ void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
|
|||||||
|
|
||||||
long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
|
long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
|
||||||
{
|
{
|
||||||
if (!(m_windowStyle & wxTE_MULTILINE))
|
if ( m_windowStyle & wxTE_MULTILINE )
|
||||||
return 0;
|
{
|
||||||
gint len = gtk_text_get_length( GTK_TEXT(m_text) );
|
wxString text = GetValue();
|
||||||
char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
|
|
||||||
if(!text)
|
if( pos >= text.Len() )
|
||||||
return 0;
|
return FALSE;
|
||||||
if( pos >= len)
|
|
||||||
return pos=len-1;
|
|
||||||
|
|
||||||
*x=1; // Col 1
|
*x=1; // Col 1
|
||||||
*y=1; // Line 1
|
*y=1; // Line 1
|
||||||
for (int i = 0; i < pos; i++ )
|
for ( const char *p = text.c_str(); *p; p++ )
|
||||||
{
|
{
|
||||||
if (text[i] == '\n')
|
if (*p == '\n')
|
||||||
{
|
{
|
||||||
(*y)++;
|
(*y)++;
|
||||||
*x=1;
|
*x=1;
|
||||||
@@ -452,8 +450,22 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
|
|||||||
else
|
else
|
||||||
(*x)++;
|
(*x)++;
|
||||||
}
|
}
|
||||||
g_free( text );
|
}
|
||||||
return 1;
|
else // single line control
|
||||||
|
{
|
||||||
|
if ( pos < GTK_ENTRY(m_text)->text_length )
|
||||||
|
{
|
||||||
|
*y = 1;
|
||||||
|
*x = pos;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// index out of bounds
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
long wxTextCtrl::XYToPosition(long x, long y ) const
|
long wxTextCtrl::XYToPosition(long x, long y ) const
|
||||||
|
Reference in New Issue
Block a user