* added gtk_text_changed callback and implemented DiscardEdits(), so that

now IsModified() works correctly
* corrected several "off by 1" errors for wxTE_MULTILINE controls
  (apparently it was a GTK bug so perhaps it doesn't work correctly with
   previous GTK versions, but it works correctly with the latest, GTK 1.0.4)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@164 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1998-07-01 18:58:24 +00:00
parent 3259263158
commit 484e45bff5
2 changed files with 46 additions and 44 deletions

View File

@@ -22,7 +22,7 @@
IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl) IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl)
void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
{ {
win->m_modified = TRUE; win->m_modified = TRUE;
}; };
@@ -36,8 +36,8 @@ wxTextCtrl::wxTextCtrl(void) : streambuf()
m_modified = FALSE; m_modified = FALSE;
}; };
wxTextCtrl::wxTextCtrl( wxWindow *parent, const wxWindowID id, const wxString &value, wxTextCtrl::wxTextCtrl( wxWindow *parent, const wxWindowID id, const wxString &value,
const wxPoint &pos, const wxSize &size, const wxPoint &pos, const wxSize &size,
const int style, const wxString &name ) : streambuf() const int style, const wxString &name ) : streambuf()
{ {
m_modified = FALSE; m_modified = FALSE;
@@ -45,36 +45,36 @@ wxTextCtrl::wxTextCtrl( wxWindow *parent, const wxWindowID id, const wxString &v
}; };
bool wxTextCtrl::Create( wxWindow *parent, const wxWindowID id, const wxString &value, bool wxTextCtrl::Create( wxWindow *parent, const wxWindowID id, const wxString &value,
const wxPoint &pos, const wxSize &size, const wxPoint &pos, const wxSize &size,
const int style, const wxString &name ) const int style, const wxString &name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
if (style & wxTE_MULTILINE) if (style & wxTE_MULTILINE)
m_widget = gtk_text_new( NULL, NULL ); m_widget = gtk_text_new( NULL, NULL );
else else
m_widget = gtk_entry_new(); m_widget = gtk_entry_new();
wxSize newSize = size; wxSize newSize = size;
if (newSize.x == -1) newSize.x = 80; if (newSize.x == -1) newSize.x = 80;
if (newSize.y == -1) newSize.y = 26; if (newSize.y == -1) newSize.y = 26;
SetSize( newSize.x, newSize.y ); SetSize( newSize.x, newSize.y );
PostCreation(); PostCreation();
// we want to be notified about text changes
gtk_signal_connect(GTK_OBJECT(m_widget), "changed",
GTK_SIGNAL_FUNC(gtk_text_changed_callback),
(gpointer)this);
if (!value.IsNull()) if (!value.IsNull())
{ {
gint tmp = 0; gint tmp = 0;
gtk_editable_insert_text( GTK_EDITABLE(m_widget), value, value.Length(), &tmp );
// Don't know why this is so
if (style & wxTE_MULTILINE)
gtk_editable_insert_text( GTK_EDITABLE(m_widget), value, value.Length()+1, &tmp );
else
gtk_editable_insert_text( GTK_EDITABLE(m_widget), value, value.Length(), &tmp );
}; };
if (style & wxREADONLY) if (style & wxREADONLY)
{ {
} }
@@ -82,9 +82,9 @@ bool wxTextCtrl::Create( wxWindow *parent, const wxWindowID id, const wxString &
{ {
if (style & wxTE_MULTILINE) gtk_text_set_editable( GTK_TEXT(m_widget), 1 ); if (style & wxTE_MULTILINE) gtk_text_set_editable( GTK_TEXT(m_widget), 1 );
}; };
Show( TRUE ); Show( TRUE );
return TRUE; return TRUE;
}; };
@@ -94,7 +94,7 @@ wxString wxTextCtrl::GetValue(void) const
if (m_windowStyle & wxTE_MULTILINE) if (m_windowStyle & wxTE_MULTILINE)
{ {
gint len = gtk_text_get_length( GTK_TEXT(m_widget) ); gint len = gtk_text_get_length( GTK_TEXT(m_widget) );
tmp = gtk_editable_get_chars( GTK_EDITABLE(m_widget), 0, len-1 ); tmp = gtk_editable_get_chars( GTK_EDITABLE(m_widget), 0, len );
} }
else else
{ {
@@ -110,7 +110,7 @@ void wxTextCtrl::SetValue( const wxString &value )
if (m_windowStyle & wxTE_MULTILINE) if (m_windowStyle & wxTE_MULTILINE)
{ {
gint len = gtk_text_get_length( GTK_TEXT(m_widget) ); gint len = gtk_text_get_length( GTK_TEXT(m_widget) );
gtk_editable_delete_text( GTK_EDITABLE(m_widget), 0, len-1 ); gtk_editable_delete_text( GTK_EDITABLE(m_widget), 0, len );
len = 0; len = 0;
gtk_editable_insert_text( GTK_EDITABLE(m_widget), tmp, tmp.Length(), &len ); gtk_editable_insert_text( GTK_EDITABLE(m_widget), tmp, tmp.Length(), &len );
} }
@@ -123,7 +123,7 @@ void wxTextCtrl::SetValue( const wxString &value )
void wxTextCtrl::WriteText( const wxString &text ) void wxTextCtrl::WriteText( const wxString &text )
{ {
if (text.IsNull()) return; if (text.IsNull()) return;
if (m_windowStyle & wxTE_MULTILINE) if (m_windowStyle & wxTE_MULTILINE)
{ {
gint len = gtk_text_get_length( GTK_TEXT(m_widget) ); gint len = gtk_text_get_length( GTK_TEXT(m_widget) );
@@ -156,6 +156,7 @@ bool wxTextCtrl::IsModified(void)
void wxTextCtrl::DiscardEdits(void) void wxTextCtrl::DiscardEdits(void)
{ {
m_modified = FALSE;
}; };
/* /*
@@ -278,7 +279,7 @@ int wxTextCtrl::overflow(int c)
wxError("Streambuf allocation failed","Internal error"); wxError("Streambuf allocation failed","Internal error");
return EOF; return EOF;
} }
// Verify that there are no characters in get area // Verify that there are no characters in get area
if ( gptr() && gptr() < egptr() ) if ( gptr() && gptr() < egptr() )
{ {

View File

@@ -22,7 +22,7 @@
IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl) IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl)
void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win ) void gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
{ {
win->m_modified = TRUE; win->m_modified = TRUE;
}; };
@@ -36,8 +36,8 @@ wxTextCtrl::wxTextCtrl(void) : streambuf()
m_modified = FALSE; m_modified = FALSE;
}; };
wxTextCtrl::wxTextCtrl( wxWindow *parent, const wxWindowID id, const wxString &value, wxTextCtrl::wxTextCtrl( wxWindow *parent, const wxWindowID id, const wxString &value,
const wxPoint &pos, const wxSize &size, const wxPoint &pos, const wxSize &size,
const int style, const wxString &name ) : streambuf() const int style, const wxString &name ) : streambuf()
{ {
m_modified = FALSE; m_modified = FALSE;
@@ -45,36 +45,36 @@ wxTextCtrl::wxTextCtrl( wxWindow *parent, const wxWindowID id, const wxString &v
}; };
bool wxTextCtrl::Create( wxWindow *parent, const wxWindowID id, const wxString &value, bool wxTextCtrl::Create( wxWindow *parent, const wxWindowID id, const wxString &value,
const wxPoint &pos, const wxSize &size, const wxPoint &pos, const wxSize &size,
const int style, const wxString &name ) const int style, const wxString &name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
if (style & wxTE_MULTILINE) if (style & wxTE_MULTILINE)
m_widget = gtk_text_new( NULL, NULL ); m_widget = gtk_text_new( NULL, NULL );
else else
m_widget = gtk_entry_new(); m_widget = gtk_entry_new();
wxSize newSize = size; wxSize newSize = size;
if (newSize.x == -1) newSize.x = 80; if (newSize.x == -1) newSize.x = 80;
if (newSize.y == -1) newSize.y = 26; if (newSize.y == -1) newSize.y = 26;
SetSize( newSize.x, newSize.y ); SetSize( newSize.x, newSize.y );
PostCreation(); PostCreation();
// we want to be notified about text changes
gtk_signal_connect(GTK_OBJECT(m_widget), "changed",
GTK_SIGNAL_FUNC(gtk_text_changed_callback),
(gpointer)this);
if (!value.IsNull()) if (!value.IsNull())
{ {
gint tmp = 0; gint tmp = 0;
gtk_editable_insert_text( GTK_EDITABLE(m_widget), value, value.Length(), &tmp );
// Don't know why this is so
if (style & wxTE_MULTILINE)
gtk_editable_insert_text( GTK_EDITABLE(m_widget), value, value.Length()+1, &tmp );
else
gtk_editable_insert_text( GTK_EDITABLE(m_widget), value, value.Length(), &tmp );
}; };
if (style & wxREADONLY) if (style & wxREADONLY)
{ {
} }
@@ -82,9 +82,9 @@ bool wxTextCtrl::Create( wxWindow *parent, const wxWindowID id, const wxString &
{ {
if (style & wxTE_MULTILINE) gtk_text_set_editable( GTK_TEXT(m_widget), 1 ); if (style & wxTE_MULTILINE) gtk_text_set_editable( GTK_TEXT(m_widget), 1 );
}; };
Show( TRUE ); Show( TRUE );
return TRUE; return TRUE;
}; };
@@ -94,7 +94,7 @@ wxString wxTextCtrl::GetValue(void) const
if (m_windowStyle & wxTE_MULTILINE) if (m_windowStyle & wxTE_MULTILINE)
{ {
gint len = gtk_text_get_length( GTK_TEXT(m_widget) ); gint len = gtk_text_get_length( GTK_TEXT(m_widget) );
tmp = gtk_editable_get_chars( GTK_EDITABLE(m_widget), 0, len-1 ); tmp = gtk_editable_get_chars( GTK_EDITABLE(m_widget), 0, len );
} }
else else
{ {
@@ -110,7 +110,7 @@ void wxTextCtrl::SetValue( const wxString &value )
if (m_windowStyle & wxTE_MULTILINE) if (m_windowStyle & wxTE_MULTILINE)
{ {
gint len = gtk_text_get_length( GTK_TEXT(m_widget) ); gint len = gtk_text_get_length( GTK_TEXT(m_widget) );
gtk_editable_delete_text( GTK_EDITABLE(m_widget), 0, len-1 ); gtk_editable_delete_text( GTK_EDITABLE(m_widget), 0, len );
len = 0; len = 0;
gtk_editable_insert_text( GTK_EDITABLE(m_widget), tmp, tmp.Length(), &len ); gtk_editable_insert_text( GTK_EDITABLE(m_widget), tmp, tmp.Length(), &len );
} }
@@ -123,7 +123,7 @@ void wxTextCtrl::SetValue( const wxString &value )
void wxTextCtrl::WriteText( const wxString &text ) void wxTextCtrl::WriteText( const wxString &text )
{ {
if (text.IsNull()) return; if (text.IsNull()) return;
if (m_windowStyle & wxTE_MULTILINE) if (m_windowStyle & wxTE_MULTILINE)
{ {
gint len = gtk_text_get_length( GTK_TEXT(m_widget) ); gint len = gtk_text_get_length( GTK_TEXT(m_widget) );
@@ -156,6 +156,7 @@ bool wxTextCtrl::IsModified(void)
void wxTextCtrl::DiscardEdits(void) void wxTextCtrl::DiscardEdits(void)
{ {
m_modified = FALSE;
}; };
/* /*
@@ -278,7 +279,7 @@ int wxTextCtrl::overflow(int c)
wxError("Streambuf allocation failed","Internal error"); wxError("Streambuf allocation failed","Internal error");
return EOF; return EOF;
} }
// Verify that there are no characters in get area // Verify that there are no characters in get area
if ( gptr() && gptr() < egptr() ) if ( gptr() && gptr() < egptr() )
{ {