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:
Vadim Zeitlin
1999-01-26 13:48:10 +00:00
parent 24178e4a14
commit 9638564219
2 changed files with 84 additions and 60 deletions

View File

@@ -431,20 +431,18 @@ void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
{
if (!(m_windowStyle & wxTE_MULTILINE))
return 0;
gint len = gtk_text_get_length( GTK_TEXT(m_text) );
char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
if(!text)
return 0;
if( pos >= len)
return pos=len-1;
if ( m_windowStyle & wxTE_MULTILINE )
{
wxString text = GetValue();
if( pos >= text.Len() )
return FALSE;
*x=1; // Col 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)++;
*x=1;
@@ -452,8 +450,22 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
else
(*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

View File

@@ -431,20 +431,18 @@ void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
{
if (!(m_windowStyle & wxTE_MULTILINE))
return 0;
gint len = gtk_text_get_length( GTK_TEXT(m_text) );
char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
if(!text)
return 0;
if( pos >= len)
return pos=len-1;
if ( m_windowStyle & wxTE_MULTILINE )
{
wxString text = GetValue();
if( pos >= text.Len() )
return FALSE;
*x=1; // Col 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)++;
*x=1;
@@ -452,8 +450,22 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
else
(*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