SetInsertionPointEnd() bug corrected (was off by 1)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1485 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-01-26 12:56:58 +00:00
parent 1eddcfafba
commit 805dd538bb
4 changed files with 258 additions and 276 deletions

View File

@@ -4,7 +4,7 @@
// Author: Robert Roebling // Author: Robert Roebling
// Id: $Id$ // Id: $Id$
// Copyright: (c) 1998 Robert Roebling // Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
@@ -78,7 +78,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
int n, const wxString choices[], int n, const wxString choices[],
long style, const wxValidator& validator, long style, const wxValidator& validator,
const wxString& name ) const wxString& name )
{ {
m_alreadySent = FALSE; m_alreadySent = FALSE;
m_needParent = TRUE; m_needParent = TRUE;
@@ -460,17 +460,14 @@ void wxComboBox::SetInsertionPoint( long pos )
wxCHECK_RET( m_widget != NULL, "invalid combobox" ); wxCHECK_RET( m_widget != NULL, "invalid combobox" );
GtkWidget *entry = GTK_COMBO(m_widget)->entry; GtkWidget *entry = GTK_COMBO(m_widget)->entry;
int tmp = (int) pos; gtk_entry_set_position( GTK_ENTRY(entry), (int)tmp );
gtk_entry_set_position( GTK_ENTRY(entry), tmp );
} }
void wxComboBox::SetInsertionPointEnd() void wxComboBox::SetInsertionPointEnd()
{ {
wxCHECK_RET( m_widget != NULL, "invalid combobox" ); wxCHECK_RET( m_widget != NULL, "invalid combobox" );
GtkWidget *entry = GTK_COMBO(m_widget)->entry; SetInsertionPoint( -1 );
int pos = GTK_ENTRY(entry)->text_length;
SetInsertionPoint( pos-1 );
} }
long wxComboBox::GetInsertionPoint() const long wxComboBox::GetInsertionPoint() const

View File

@@ -224,18 +224,18 @@ void wxTextCtrl::CalculateScrollbar()
{ {
if (m_vScrollbarVisible) if (m_vScrollbarVisible)
{ {
gtk_widget_hide( m_vScrollbar ); gtk_widget_hide( m_vScrollbar );
m_vScrollbarVisible = FALSE; m_vScrollbarVisible = FALSE;
} }
} }
else else
{ {
if (!m_vScrollbarVisible) if (!m_vScrollbarVisible)
{ {
gtk_widget_show( m_vScrollbar ); gtk_widget_show( m_vScrollbar );
m_vScrollbarVisible = TRUE; m_vScrollbarVisible = TRUE;
} }
} }
} }
@@ -321,8 +321,8 @@ bool wxTextCtrl::LoadFile( const wxString &file )
return FALSE; return FALSE;
} }
if (fread (text, sizeof (char), len, fp) != (size_t) len) if (fread (text, sizeof (char), len, fp) != (size_t) len)
{ {
} }
fclose (fp); fclose (fp);
text[len] = 0; text[len] = 0;
@@ -372,13 +372,13 @@ bool wxTextCtrl::SaveFile( const wxString &file )
} }
if (fwrite (text, sizeof (char), len, fp) != (size_t) len) if (fwrite (text, sizeof (char), len, fp) != (size_t) len)
{ {
// Did not write whole file // Did not write whole file
} }
// Make sure newline terminates the file // Make sure newline terminates the file
if (text[len - 1] != '\n') if (text[len - 1] != '\n')
fputc ('\n', fp); fputc ('\n', fp);
fclose (fp); fclose (fp);
@@ -445,12 +445,12 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
for (int i = 0; i < pos; i++ ) for (int i = 0; i < pos; i++ )
{ {
if (text[i] == '\n') if (text[i] == '\n')
{ {
(*y)++; (*y)++;
*x=1; *x=1;
} }
else else
(*x)++; (*x)++;
} }
g_free( text ); g_free( text );
return 1; return 1;
@@ -485,17 +485,17 @@ int wxTextCtrl::GetNumberOfLines() const
{ {
int currentLine = 0; int currentLine = 0;
for (int i = 0; i < len; i++ ) for (int i = 0; i < len; i++ )
{ {
if (text[i] == '\n') if (text[i] == '\n')
currentLine++; currentLine++;
} }
g_free( text ); g_free( text );
return currentLine; return currentLine;
} }
else else
{ {
return 0; return 0;
} }
} }
else else
{ {
@@ -518,13 +518,7 @@ void wxTextCtrl::SetInsertionPointEnd()
{ {
wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
int pos = 0; SetInsertionPoint(-1);
if (m_windowStyle & wxTE_MULTILINE)
pos = gtk_text_get_length( GTK_TEXT(m_text) );
else
pos = GTK_ENTRY(m_text)->text_length;
SetInsertionPoint((pos-1)>0 ? (pos-1):0);
} }
void wxTextCtrl::SetEditable( bool editable ) void wxTextCtrl::SetEditable( bool editable )

View File

@@ -4,7 +4,7 @@
// Author: Robert Roebling // Author: Robert Roebling
// Id: $Id$ // Id: $Id$
// Copyright: (c) 1998 Robert Roebling // Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
@@ -78,7 +78,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
int n, const wxString choices[], int n, const wxString choices[],
long style, const wxValidator& validator, long style, const wxValidator& validator,
const wxString& name ) const wxString& name )
{ {
m_alreadySent = FALSE; m_alreadySent = FALSE;
m_needParent = TRUE; m_needParent = TRUE;
@@ -460,17 +460,14 @@ void wxComboBox::SetInsertionPoint( long pos )
wxCHECK_RET( m_widget != NULL, "invalid combobox" ); wxCHECK_RET( m_widget != NULL, "invalid combobox" );
GtkWidget *entry = GTK_COMBO(m_widget)->entry; GtkWidget *entry = GTK_COMBO(m_widget)->entry;
int tmp = (int) pos; gtk_entry_set_position( GTK_ENTRY(entry), (int)tmp );
gtk_entry_set_position( GTK_ENTRY(entry), tmp );
} }
void wxComboBox::SetInsertionPointEnd() void wxComboBox::SetInsertionPointEnd()
{ {
wxCHECK_RET( m_widget != NULL, "invalid combobox" ); wxCHECK_RET( m_widget != NULL, "invalid combobox" );
GtkWidget *entry = GTK_COMBO(m_widget)->entry; SetInsertionPoint( -1 );
int pos = GTK_ENTRY(entry)->text_length;
SetInsertionPoint( pos-1 );
} }
long wxComboBox::GetInsertionPoint() const long wxComboBox::GetInsertionPoint() const

View File

@@ -224,18 +224,18 @@ void wxTextCtrl::CalculateScrollbar()
{ {
if (m_vScrollbarVisible) if (m_vScrollbarVisible)
{ {
gtk_widget_hide( m_vScrollbar ); gtk_widget_hide( m_vScrollbar );
m_vScrollbarVisible = FALSE; m_vScrollbarVisible = FALSE;
} }
} }
else else
{ {
if (!m_vScrollbarVisible) if (!m_vScrollbarVisible)
{ {
gtk_widget_show( m_vScrollbar ); gtk_widget_show( m_vScrollbar );
m_vScrollbarVisible = TRUE; m_vScrollbarVisible = TRUE;
} }
} }
} }
@@ -321,8 +321,8 @@ bool wxTextCtrl::LoadFile( const wxString &file )
return FALSE; return FALSE;
} }
if (fread (text, sizeof (char), len, fp) != (size_t) len) if (fread (text, sizeof (char), len, fp) != (size_t) len)
{ {
} }
fclose (fp); fclose (fp);
text[len] = 0; text[len] = 0;
@@ -372,13 +372,13 @@ bool wxTextCtrl::SaveFile( const wxString &file )
} }
if (fwrite (text, sizeof (char), len, fp) != (size_t) len) if (fwrite (text, sizeof (char), len, fp) != (size_t) len)
{ {
// Did not write whole file // Did not write whole file
} }
// Make sure newline terminates the file // Make sure newline terminates the file
if (text[len - 1] != '\n') if (text[len - 1] != '\n')
fputc ('\n', fp); fputc ('\n', fp);
fclose (fp); fclose (fp);
@@ -445,12 +445,12 @@ long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
for (int i = 0; i < pos; i++ ) for (int i = 0; i < pos; i++ )
{ {
if (text[i] == '\n') if (text[i] == '\n')
{ {
(*y)++; (*y)++;
*x=1; *x=1;
} }
else else
(*x)++; (*x)++;
} }
g_free( text ); g_free( text );
return 1; return 1;
@@ -485,17 +485,17 @@ int wxTextCtrl::GetNumberOfLines() const
{ {
int currentLine = 0; int currentLine = 0;
for (int i = 0; i < len; i++ ) for (int i = 0; i < len; i++ )
{ {
if (text[i] == '\n') if (text[i] == '\n')
currentLine++; currentLine++;
} }
g_free( text ); g_free( text );
return currentLine; return currentLine;
} }
else else
{ {
return 0; return 0;
} }
} }
else else
{ {
@@ -518,13 +518,7 @@ void wxTextCtrl::SetInsertionPointEnd()
{ {
wxCHECK_RET( m_text != NULL, "invalid text ctrl" ); wxCHECK_RET( m_text != NULL, "invalid text ctrl" );
int pos = 0; SetInsertionPoint(-1);
if (m_windowStyle & wxTE_MULTILINE)
pos = gtk_text_get_length( GTK_TEXT(m_text) );
else
pos = GTK_ENTRY(m_text)->text_length;
SetInsertionPoint((pos-1)>0 ? (pos-1):0);
} }
void wxTextCtrl::SetEditable( bool editable ) void wxTextCtrl::SetEditable( bool editable )