+ 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)
+ {
+ /* this moves the cursor pos to behind the inserted text */
+ gint len = GTK_EDITABLE(m_text)->current_pos;
+
+#if wxUSE_UNICODE
+ wxWX2MBbuf buf = text.mbc_str();
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &len );
+#else
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
+#endif
+
+ /* bring editable's cursor uptodate. bug in GTK. */
+ GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
+ }
+ else
+ {
+ /* this moves the cursor pos to behind the inserted text */
+ gint len = GTK_EDITABLE(m_text)->current_pos;
+#if wxUSE_UNICODE
+ wxWX2MBbuf buf = text.mbc_str();
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &len );
+#else
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
+#endif
+
+ /* bring editable's cursor uptodate. bug in GTK. */
+ GTK_EDITABLE(m_text)->current_pos += text.Len();
+
+ /* 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)
+ {
+ bool hasSpecialAttributes = m_font.Ok() ||
+ m_foregroundColour.Ok() ||
+ m_backgroundColour.Ok();
+ if ( hasSpecialAttributes )
+ {
+ gtk_text_insert( GTK_TEXT(m_text),
+ m_font.GetInternalFont(),
+ m_foregroundColour.GetColor(),
+ m_backgroundColour.GetColor(),
+ text, text.length());
+
+ }
+ else
+ {
+ /* we'll insert at the last position */
+ gint len = gtk_text_get_length( GTK_TEXT(m_text) );
+#if wxUSE_UNICODE
+ wxWX2MBbuf buf = text.mbc_str();
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &len );
+#else
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
+#endif
+ }
+
+ /* bring editable's cursor uptodate. bug in GTK. */
+ GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
+ }
+ else
+ {
+ 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") );
+
+ if (!wxFileExists(file)) return FALSE;
+
+ Clear();
+
+ 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))))
+ {
+ fclose (fp);
+ return FALSE;
+ }
+ if (fread (text, sizeof (char), len, fp) != (size_t) len)
+ {
+ }
+ fclose (fp);
+
+ text[len] = 0;
+
+ 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;
+ }
+ return FALSE;
+}
+
+bool wxTextCtrl::SaveFile( const wxString &file )
+{
+ wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") );
+
+ if (file == _T("")) return FALSE;
+
+ FILE *fp;
+
+ if (!(fp = fopen (FNSTRINGCAST file.fn_str(), "w")))
+ {
+ return FALSE;
+ }
+ 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 );
+ }
+ else
+ {
+ text = gtk_entry_get_text( GTK_ENTRY(m_text) );
+ }
+
+ if (fwrite (text, sizeof (char), len, fp) != (size_t) len)
+ {
+ // Did not write whole file
+ }
+
+ // Make sure newline terminates the file
+ if (text[len - 1] != '\n')
+ fputc ('\n', fp);
+
+ fclose (fp);
+
+ if (m_windowStyle & wxTE_MULTILINE) g_free( text );
+
+ m_modified = FALSE;
+ return TRUE;
+ }
+
+ return TRUE;
+}
+
+wxString wxTextCtrl::GetLineText( long lineNo ) const
+{