+ {
+ /* a single-line text control: no need for scrollbars */
+ m_widget =
+ m_text = gtk_entry_new();
+ }
+
+ wxSize newSize = size;
+ if (newSize.x == -1) newSize.x = 80;
+ if (newSize.y == -1) newSize.y = 26;
+ SetSize( newSize.x, newSize.y );
+
+ m_parent->DoAddChild( this );
+
+ PostCreation();
+
+ if (multi_line)
+ gtk_widget_show(m_text);
+
+ /* we want to be notified about text changes */
+ gtk_signal_connect( GTK_OBJECT(m_text), "changed",
+ GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
+
+ if (multi_line)
+ {
+ gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text)->vadj), "changed",
+ (GtkSignalFunc) gtk_scrollbar_changed_callback, (gpointer) this );
+ }
+
+ if (!value.IsEmpty())
+ {
+ gint tmp = 0;
+
+#if GTK_MINOR_VERSION == 0
+ // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
+ // gtk_editable_insert_text()
+ gtk_widget_realize(m_text);
+#endif // GTK 1.0
+
+#if wxUSE_UNICODE
+ wxWX2MBbuf val = value.mbc_str();
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), val, strlen(val), &tmp );
+#else // !Unicode
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &tmp );
+#endif // Unicode/!Unicode
+
+ if (multi_line)
+ {
+ /* bring editable's cursor uptodate. bug in GTK. */
+
+ GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
+ }
+ }
+
+ if (style & wxTE_PASSWORD)
+ {
+ if (!multi_line)
+ gtk_entry_set_visibility( GTK_ENTRY(m_text), FALSE );
+ }
+
+ if (style & wxTE_READONLY)
+ {
+ if (!multi_line)
+ gtk_entry_set_editable( GTK_ENTRY(m_text), FALSE );
+ }
+ else
+ {
+ if (multi_line)
+ gtk_text_set_editable( GTK_TEXT(m_text), 1 );
+ }
+
+ SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) );
+ SetForegroundColour( parent->GetForegroundColour() );
+
+ Show( TRUE );
+
+ return TRUE;
+}
+
+void wxTextCtrl::CalculateScrollbar()
+{
+ if ((m_windowStyle & wxTE_MULTILINE) == 0) return;
+
+ GtkAdjustment *adj = GTK_TEXT(m_text)->vadj;
+
+ if (adj->upper - adj->page_size < 0.8)
+ {
+ if (m_vScrollbarVisible)
+ {
+ gtk_widget_hide( m_vScrollbar );
+ m_vScrollbarVisible = FALSE;
+ }
+ }
+ else
+ {
+ if (!m_vScrollbarVisible)
+ {
+ gtk_widget_show( m_vScrollbar );
+ m_vScrollbarVisible = TRUE;
+ }
+ }
+}
+
+wxString wxTextCtrl::GetValue() const
+{
+ wxCHECK_MSG( m_text != NULL, _T(""), _T("invalid text ctrl") );
+
+ wxString tmp;
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ gint len = gtk_text_get_length( GTK_TEXT(m_text) );
+ char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
+ tmp = wxString(text,*wxConvCurrent);
+ g_free( text );
+ }
+ else
+ {
+ tmp = wxString(gtk_entry_get_text( GTK_ENTRY(m_text) ),*wxConvCurrent);
+ }
+ return tmp;
+}
+
+void wxTextCtrl::SetValue( 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);
+
+ wxString tmp = _T("");
+ if (!value.IsNull()) tmp = value;
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ gint len = gtk_text_get_length( GTK_TEXT(m_text) );
+ gtk_editable_delete_text( GTK_EDITABLE(m_text), 0, len );
+ len = 0;
+#if wxUSE_UNICODE
+ wxWX2MBbuf tmpbuf = tmp.mbc_str();
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), tmpbuf, strlen(tmpbuf), &len );
+#else
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), tmp.mbc_str(), tmp.Length(), &len );
+#endif
+ }
+ else
+ {
+ gtk_entry_set_text( GTK_ENTRY(m_text), tmp.mbc_str() );
+ }