From 2df7be7f2cca699a02ee0c9ce69de9bfe6b0922f Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 22 Jun 1999 08:36:29 +0000 Subject: [PATCH] Some #include and #if wxUSE_XX things Shut up notification in wxTextCtrl Made things compile again... git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2858 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/docmdi.h | 7 ++ include/wx/gtk/statbmp.h | 4 +- include/wx/gtk1/statbmp.h | 4 +- include/wx/sckaddr.h | 24 +++--- include/wx/sckint.h | 10 ++- src/common/config.cpp | 4 - src/common/date.cpp | 4 - src/common/datstrm.cpp | 4 - src/common/dcbase.cpp | 2 +- src/common/docmdi.cpp | 10 +-- src/common/docview.cpp | 6 +- src/common/dynlib.cpp | 6 +- src/common/file.cpp | 4 - src/common/fileconf.cpp | 4 - src/common/ftp.cpp | 4 +- src/common/http.cpp | 6 +- src/common/mstream.cpp | 4 - src/common/objstrm.cpp | 4 - src/common/protocol.cpp | 6 +- src/common/sckaddr.cpp | 4 +- src/generic/gridg.cpp | 7 +- src/gtk/statbmp.cpp | 9 +++ src/gtk/textctrl.cpp | 149 +++++++++++++++++++++++++------------- src/gtk1/statbmp.cpp | 9 +++ src/gtk1/textctrl.cpp | 149 +++++++++++++++++++++++++------------- 25 files changed, 263 insertions(+), 181 deletions(-) diff --git a/include/wx/docmdi.h b/include/wx/docmdi.h index 1fd76e1abe..5c58befd40 100644 --- a/include/wx/docmdi.h +++ b/include/wx/docmdi.h @@ -16,6 +16,10 @@ #pragma interface "docmdi.h" #endif +#include "wx/defs.h" + +#if wxUSE_MDI_ARCHITECTURE + #include "wx/docview.h" #include "wx/mdi.h" @@ -79,5 +83,8 @@ DECLARE_EVENT_TABLE() }; +#endif + // wxUSE_MDI_ARCHITECTURE + #endif // _WX_DOCMDI_H_ diff --git a/include/wx/gtk/statbmp.h b/include/wx/gtk/statbmp.h index c24b212870..7f902acf83 100644 --- a/include/wx/gtk/statbmp.h +++ b/include/wx/gtk/statbmp.h @@ -22,6 +22,7 @@ #include "wx/object.h" #include "wx/control.h" #include "wx/bitmap.h" +#include "wx/icon.h" //----------------------------------------------------------------------------- // classes @@ -66,8 +67,7 @@ public: const wxBitmap& GetBitmap() const { return m_bitmap; } // for compatibility with wxMSW - wxIcon& GetIcon() - { return *(wxDynamicCast(&m_bitmap, wxIcon)); } + wxIcon& GetIcon(); private: wxBitmap m_bitmap; diff --git a/include/wx/gtk1/statbmp.h b/include/wx/gtk1/statbmp.h index c24b212870..7f902acf83 100644 --- a/include/wx/gtk1/statbmp.h +++ b/include/wx/gtk1/statbmp.h @@ -22,6 +22,7 @@ #include "wx/object.h" #include "wx/control.h" #include "wx/bitmap.h" +#include "wx/icon.h" //----------------------------------------------------------------------------- // classes @@ -66,8 +67,7 @@ public: const wxBitmap& GetBitmap() const { return m_bitmap; } // for compatibility with wxMSW - wxIcon& GetIcon() - { return *(wxDynamicCast(&m_bitmap, wxIcon)); } + wxIcon& GetIcon(); private: wxBitmap m_bitmap; diff --git a/include/wx/sckaddr.h b/include/wx/sckaddr.h index 392a9d1387..b182548948 100644 --- a/include/wx/sckaddr.h +++ b/include/wx/sckaddr.h @@ -8,9 +8,18 @@ // Copyright: (c) 1997, 1998 Guilhem Lavaux // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// + #ifndef _WX_NETWORK_ADDRESS_H #define _WX_NETWORK_ADDRESS_H +#ifdef __GNUG__ +#pragma interface +#endif + +#include "wx/defs.h" + +#if wxUSE_SOCKETS + #if defined(__WINDOWS__) && defined(WXSOCK_INTERNAL) #include @@ -21,15 +30,7 @@ #include #endif -#ifdef __GNUG__ -#pragma interface -#endif - -#ifdef WXPREC -#include -#else -#include -#endif +#include "wx/string.h" class WXDLLEXPORT wxSockAddress : public wxObject { DECLARE_ABSTRACT_CLASS(wxSockAddress) @@ -132,5 +133,10 @@ public: inline int Type() { return wxSockAddress::UNIX; } }; #endif + // __UNIX__ #endif + // wxUSE_SOCKETS + +#endif + // _WX_NETWORK_ADDRESS_H diff --git a/include/wx/sckint.h b/include/wx/sckint.h index 3fec426a7a..1b1ae55083 100644 --- a/include/wx/sckint.h +++ b/include/wx/sckint.h @@ -15,12 +15,14 @@ #pragma interface #endif +#include "wx/defs.h" + #if wxUSE_SOCKETS -#include -#include -#include -#include +#include "wx/object.h" +#include "wx/list.h" +#include "wx/socket.h" +#include "wx/thread.h" // Socket state class SocketState diff --git a/src/common/config.cpp b/src/common/config.cpp index c0b5c85700..fc96bb57f6 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -23,10 +23,6 @@ #pragma hdrstop #endif //__BORLANDC__ -#ifndef WX_PRECOMP - #include "wx/defs.h" -#endif - #if wxUSE_CONFIG && ((wxUSE_FILE && wxUSE_TEXTFILE) || defined(wxCONFIG_WIN32_NATIVE)) #include "wx/app.h" diff --git a/src/common/date.cpp b/src/common/date.cpp index db287ab316..4d8a901c8c 100644 --- a/src/common/date.cpp +++ b/src/common/date.cpp @@ -26,10 +26,6 @@ #pragma hdrstop #endif -#ifndef WX_PRECOMP - #include "wx/defs.h" -#endif - #if wxUSE_TIMEDATE #include "wx/date.h" diff --git a/src/common/datstrm.cpp b/src/common/datstrm.cpp index aff9c5355c..4ccada0e88 100644 --- a/src/common/datstrm.cpp +++ b/src/common/datstrm.cpp @@ -20,10 +20,6 @@ #pragma hdrstop #endif -#ifndef WX_PRECOMP - #include "wx/defs.h" -#endif - #if wxUSE_STREAMS #include "wx/datstrm.h" diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index 755f2ccbb3..3f2efc403c 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -17,7 +17,7 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP diff --git a/src/common/docmdi.cpp b/src/common/docmdi.cpp index 6e92c70f57..4038ddb700 100644 --- a/src/common/docmdi.cpp +++ b/src/common/docmdi.cpp @@ -17,19 +17,11 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WX_PRECOMP -#include "wx/defs.h" + #pragma hdrstop #endif #if wxUSE_DOC_VIEW_ARCHITECTURE -#ifndef WX_PRECOMP -#include "wx/wx.h" -#endif - #include "wx/docmdi.h" /* diff --git a/src/common/docview.cpp b/src/common/docview.cpp index a7fd1a2209..fed454d4e8 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -25,11 +25,7 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ - #pragma hdrstop -#endif - -#ifndef WX_PRECOMP - #include "wx/defs.h" + #pragma hdrstop #endif #if wxUSE_DOC_VIEW_ARCHITECTURE diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index 40bba2b170..d7b654faa1 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -23,9 +23,9 @@ #include "wx/wxprec.h" -#ifdef __BORLANDC__ -# pragma hdrstop -#endif //__BORLANDC__ +#ifdef __BORLANDC__ + #pragma hdrstop +#endif #if wxUSE_DYNLIB_CLASS diff --git a/src/common/file.cpp b/src/common/file.cpp index 6702d2dd83..8f1f1deb76 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -25,10 +25,6 @@ #pragma hdrstop #endif -#ifndef WX_PRECOMP - #include "wx/defs.h" -#endif - #if wxUSE_FILE // standard diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 231c156482..c15130a184 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -14,10 +14,6 @@ #pragma implementation "fileconf.h" #endif -// ============================================================================ -// declarations -// ============================================================================ - // ---------------------------------------------------------------------------- // headers // ---------------------------------------------------------------------------- diff --git a/src/common/ftp.cpp b/src/common/ftp.cpp index 090138b5d7..b513f7e404 100644 --- a/src/common/ftp.cpp +++ b/src/common/ftp.cpp @@ -10,14 +10,14 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "ftp.h" + #pragma implementation "ftp.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #if wxUSE_SOCKETS diff --git a/src/common/http.cpp b/src/common/http.cpp index a7e14752b4..c13c7a1bb7 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -10,7 +10,7 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "http.h" + #pragma implementation "http.h" #endif // For compilers that support precompilation, includes "wx.h". @@ -20,10 +20,6 @@ #pragma hdrstop #endif -#ifndef WX_PRECOMP - #include "wx/defs.h" -#endif - #if wxUSE_SOCKETS #include diff --git a/src/common/mstream.cpp b/src/common/mstream.cpp index c9f2370466..c6a58a04a1 100644 --- a/src/common/mstream.cpp +++ b/src/common/mstream.cpp @@ -20,10 +20,6 @@ #pragma hdrstop #endif -#ifndef WX_PRECOMP - #include "wx/defs.h" -#endif - #if wxUSE_STREAMS #include diff --git a/src/common/objstrm.cpp b/src/common/objstrm.cpp index 4de828ae72..0f4a38608a 100644 --- a/src/common/objstrm.cpp +++ b/src/common/objstrm.cpp @@ -19,10 +19,6 @@ #pragma hdrstop #endif -#ifndef WX_PRECOMP - #include "wx/defs.h" -#endif - #if wxUSE_SERIAL && wxUSE_STREAMS #include "wx/object.h" diff --git a/src/common/protocol.cpp b/src/common/protocol.cpp index ac5020956f..736b38fd13 100644 --- a/src/common/protocol.cpp +++ b/src/common/protocol.cpp @@ -17,15 +17,11 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #if wxUSE_SOCKETS -#ifndef WX_PRECOMP -#include -#endif - #include "wx/protocol/protocol.h" #include "wx/url.h" #include "wx/module.h" diff --git a/src/common/sckaddr.cpp b/src/common/sckaddr.cpp index 1656a2c8b7..ab9a1f78c6 100644 --- a/src/common/sckaddr.cpp +++ b/src/common/sckaddr.cpp @@ -10,14 +10,14 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "sckaddr.h" + #pragma implementation "sckaddr.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #if wxUSE_SOCKETS diff --git a/src/generic/gridg.cpp b/src/generic/gridg.cpp index bfd5c3928b..82e11ce420 100644 --- a/src/generic/gridg.cpp +++ b/src/generic/gridg.cpp @@ -18,11 +18,14 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP -#include "wx/wx.h" + #include "wx/utils.h" + #include "wx/dcclient.h" + #include "wx/dcmemory.h" + #include "wx/textctrl.h" #endif #include diff --git a/src/gtk/statbmp.cpp b/src/gtk/statbmp.cpp index 30431837bf..ad12ed7cf2 100644 --- a/src/gtk/statbmp.cpp +++ b/src/gtk/statbmp.cpp @@ -83,4 +83,13 @@ void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap ) } } +wxIcon& wxStaticBitmap::GetIcon() +{ + wxIcon *icon = wxDynamicCast(&m_bitmap, wxIcon); + + if (!icon) return wxNullIcon; + + return *icon; +} + #endif diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index fb10ca0a24..c83a8aeb71 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -345,8 +345,11 @@ void wxTextCtrl::WriteText( const wxString &text ) { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); - if (text.IsNull()) return; + if (text.IsEmpty()) return; + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + if (m_windowStyle & wxTE_MULTILINE) { /* this moves the cursor pos to behind the inserted text */ @@ -379,12 +382,20 @@ void wxTextCtrl::WriteText( const wxString &text ) /* bring entry's cursor uptodate. bug in GTK. */ gtk_entry_set_position( GTK_ENTRY(m_text), GTK_EDITABLE(m_text)->current_pos ); } + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } void wxTextCtrl::AppendText( const wxString &text ) { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); + if (text.IsEmpty()) return; + + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + if (m_windowStyle & wxTE_MULTILINE) { /* we'll insert at the last position */ @@ -403,82 +414,91 @@ void wxTextCtrl::AppendText( const wxString &text ) { gtk_entry_append_text( GTK_ENTRY(m_text), text.mbc_str() ); } + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } bool wxTextCtrl::LoadFile( const wxString &file ) { - wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") ); + wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") ); - if (!wxFileExists(file)) return FALSE; + if (!wxFileExists(file)) return FALSE; - Clear(); + Clear(); - FILE *fp = (FILE*) NULL; - struct stat statb; + FILE *fp = (FILE*) NULL; + struct stat statb; - if ((stat (FNSTRINGCAST file.fn_str(), &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG || - !(fp = fopen (FNSTRINGCAST file.fn_str(), "r"))) - { - return FALSE; - } - else - { - gint len = statb.st_size; - char *text; - if (!(text = (char*)malloc ((unsigned) (len + 1)))) + if ((stat (FNSTRINGCAST file.fn_str(), &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG || + !(fp = fopen (FNSTRINGCAST file.fn_str(), "r"))) { - fclose (fp); - return FALSE; + return FALSE; } - if (fread (text, sizeof (char), len, fp) != (size_t) len) + else { - } - fclose (fp); + gint len = statb.st_size; + char *text; + if (!(text = (char*)malloc ((unsigned) (len + 1)))) + { + fclose (fp); + return FALSE; + } + if (fread (text, sizeof (char), len, fp) != (size_t) len) + { + } + fclose (fp); - text[len] = 0; + text[len] = 0; - if (m_windowStyle & wxTE_MULTILINE) - { - gint pos = 0; - gtk_editable_insert_text( GTK_EDITABLE(m_text), text, len, &pos ); - } - else - { - gtk_entry_set_text( GTK_ENTRY(m_text), text ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + + if (m_windowStyle & wxTE_MULTILINE) + { + gint pos = 0; + gtk_editable_insert_text( GTK_EDITABLE(m_text), text, len, &pos ); + } + else + { + gtk_entry_set_text( GTK_ENTRY(m_text), text ); + } + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + + free (text); + m_modified = FALSE; + return TRUE; } - - free (text); - m_modified = FALSE; - return TRUE; - } - return FALSE; + return FALSE; } bool wxTextCtrl::SaveFile( const wxString &file ) { - wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") ); + wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") ); - if (file == _T("")) return FALSE; + if (file == _T("")) return FALSE; - FILE *fp; + FILE *fp; - if (!(fp = fopen (FNSTRINGCAST file.fn_str(), "w"))) + if (!(fp = fopen (FNSTRINGCAST file.fn_str(), "w"))) { - return FALSE; + return FALSE; } - else + else { char *text = (char*) NULL; gint len = 0; if (m_windowStyle & wxTE_MULTILINE) { - len = gtk_text_get_length( GTK_TEXT(m_text) ); - text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); + len = gtk_text_get_length( GTK_TEXT(m_text) ); + text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); } else { - text = gtk_entry_get_text( GTK_ENTRY(m_text) ); + text = gtk_entry_get_text( GTK_ENTRY(m_text) ); } if (fwrite (text, sizeof (char), len, fp) != (size_t) len) @@ -498,7 +518,7 @@ bool wxTextCtrl::SaveFile( const wxString &file ) return TRUE; } - return TRUE; + return TRUE; } wxString wxTextCtrl::GetLineText( long lineNo ) const @@ -724,33 +744,54 @@ void wxTextCtrl::Remove( long from, long to ) { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } void wxTextCtrl::Replace( long from, long to, const wxString &value ) { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); - if (value.IsNull()) return; - gint pos = (gint)from; + + if (!value.IsEmpty()) + { + gint pos = (gint)from; #if wxUSE_UNICODE - wxWX2MBbuf buf = value.mbc_str(); - gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &pos ); + wxWX2MBbuf buf = value.mbc_str(); + gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &pos ); #else - gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos ); + gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos ); #endif + } + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } void wxTextCtrl::Cut() { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + #if (GTK_MINOR_VERSION > 0) gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) ); #else gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 ); #endif + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } void wxTextCtrl::Copy() @@ -768,11 +809,17 @@ void wxTextCtrl::Paste() { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + #if (GTK_MINOR_VERSION > 0) gtk_editable_paste_clipboard( GTK_EDITABLE(m_text) ); #else gtk_editable_paste_clipboard( GTK_EDITABLE(m_text), 0 ); #endif + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } bool wxTextCtrl::CanCopy() const diff --git a/src/gtk1/statbmp.cpp b/src/gtk1/statbmp.cpp index 30431837bf..ad12ed7cf2 100644 --- a/src/gtk1/statbmp.cpp +++ b/src/gtk1/statbmp.cpp @@ -83,4 +83,13 @@ void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap ) } } +wxIcon& wxStaticBitmap::GetIcon() +{ + wxIcon *icon = wxDynamicCast(&m_bitmap, wxIcon); + + if (!icon) return wxNullIcon; + + return *icon; +} + #endif diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index fb10ca0a24..c83a8aeb71 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -345,8 +345,11 @@ void wxTextCtrl::WriteText( const wxString &text ) { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); - if (text.IsNull()) return; + if (text.IsEmpty()) return; + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + if (m_windowStyle & wxTE_MULTILINE) { /* this moves the cursor pos to behind the inserted text */ @@ -379,12 +382,20 @@ void wxTextCtrl::WriteText( const wxString &text ) /* bring entry's cursor uptodate. bug in GTK. */ gtk_entry_set_position( GTK_ENTRY(m_text), GTK_EDITABLE(m_text)->current_pos ); } + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } void wxTextCtrl::AppendText( const wxString &text ) { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); + if (text.IsEmpty()) return; + + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + if (m_windowStyle & wxTE_MULTILINE) { /* we'll insert at the last position */ @@ -403,82 +414,91 @@ void wxTextCtrl::AppendText( const wxString &text ) { gtk_entry_append_text( GTK_ENTRY(m_text), text.mbc_str() ); } + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } bool wxTextCtrl::LoadFile( const wxString &file ) { - wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") ); + wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") ); - if (!wxFileExists(file)) return FALSE; + if (!wxFileExists(file)) return FALSE; - Clear(); + Clear(); - FILE *fp = (FILE*) NULL; - struct stat statb; + FILE *fp = (FILE*) NULL; + struct stat statb; - if ((stat (FNSTRINGCAST file.fn_str(), &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG || - !(fp = fopen (FNSTRINGCAST file.fn_str(), "r"))) - { - return FALSE; - } - else - { - gint len = statb.st_size; - char *text; - if (!(text = (char*)malloc ((unsigned) (len + 1)))) + if ((stat (FNSTRINGCAST file.fn_str(), &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG || + !(fp = fopen (FNSTRINGCAST file.fn_str(), "r"))) { - fclose (fp); - return FALSE; + return FALSE; } - if (fread (text, sizeof (char), len, fp) != (size_t) len) + else { - } - fclose (fp); + gint len = statb.st_size; + char *text; + if (!(text = (char*)malloc ((unsigned) (len + 1)))) + { + fclose (fp); + return FALSE; + } + if (fread (text, sizeof (char), len, fp) != (size_t) len) + { + } + fclose (fp); - text[len] = 0; + text[len] = 0; - if (m_windowStyle & wxTE_MULTILINE) - { - gint pos = 0; - gtk_editable_insert_text( GTK_EDITABLE(m_text), text, len, &pos ); - } - else - { - gtk_entry_set_text( GTK_ENTRY(m_text), text ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + + if (m_windowStyle & wxTE_MULTILINE) + { + gint pos = 0; + gtk_editable_insert_text( GTK_EDITABLE(m_text), text, len, &pos ); + } + else + { + gtk_entry_set_text( GTK_ENTRY(m_text), text ); + } + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + + free (text); + m_modified = FALSE; + return TRUE; } - - free (text); - m_modified = FALSE; - return TRUE; - } - return FALSE; + return FALSE; } bool wxTextCtrl::SaveFile( const wxString &file ) { - wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") ); + wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") ); - if (file == _T("")) return FALSE; + if (file == _T("")) return FALSE; - FILE *fp; + FILE *fp; - if (!(fp = fopen (FNSTRINGCAST file.fn_str(), "w"))) + if (!(fp = fopen (FNSTRINGCAST file.fn_str(), "w"))) { - return FALSE; + return FALSE; } - else + else { char *text = (char*) NULL; gint len = 0; if (m_windowStyle & wxTE_MULTILINE) { - len = gtk_text_get_length( GTK_TEXT(m_text) ); - text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); + len = gtk_text_get_length( GTK_TEXT(m_text) ); + text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len ); } else { - text = gtk_entry_get_text( GTK_ENTRY(m_text) ); + text = gtk_entry_get_text( GTK_ENTRY(m_text) ); } if (fwrite (text, sizeof (char), len, fp) != (size_t) len) @@ -498,7 +518,7 @@ bool wxTextCtrl::SaveFile( const wxString &file ) return TRUE; } - return TRUE; + return TRUE; } wxString wxTextCtrl::GetLineText( long lineNo ) const @@ -724,33 +744,54 @@ void wxTextCtrl::Remove( long from, long to ) { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } void wxTextCtrl::Replace( long from, long to, const wxString &value ) { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to ); - if (value.IsNull()) return; - gint pos = (gint)from; + + if (!value.IsEmpty()) + { + gint pos = (gint)from; #if wxUSE_UNICODE - wxWX2MBbuf buf = value.mbc_str(); - gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &pos ); + wxWX2MBbuf buf = value.mbc_str(); + gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &pos ); #else - gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos ); + gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos ); #endif + } + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } void wxTextCtrl::Cut() { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + #if (GTK_MINOR_VERSION > 0) gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) ); #else gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 ); #endif + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } void wxTextCtrl::Copy() @@ -768,11 +809,17 @@ void wxTextCtrl::Paste() { wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_text), + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); + #if (GTK_MINOR_VERSION > 0) gtk_editable_paste_clipboard( GTK_EDITABLE(m_text) ); #else gtk_editable_paste_clipboard( GTK_EDITABLE(m_text), 0 ); #endif + + gtk_signal_connect( GTK_OBJECT(m_text), "changed", + GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } bool wxTextCtrl::CanCopy() const -- 2.45.2