-wxTextCtrl::wxTextCtrl(void) : streambuf()
-{
-  m_modified = FALSE;
-};
-
-wxTextCtrl::wxTextCtrl( wxWindow *parent, const wxWindowID id, const wxString &value,
-      const wxPoint &pos, const wxSize &size,
-      const int style, const wxString &name ) : streambuf()
-{
-  m_modified = FALSE;
-  Create( parent, id, value, pos, size, style, name );
-};
-
-bool wxTextCtrl::Create( wxWindow *parent, const wxWindowID id, const wxString &value,
-      const wxPoint &pos, const wxSize &size,
-      const int style, const wxString &name )
-{
-  m_needParent = TRUE;
-
-  PreCreation( parent, id, pos, size, style, name );
-
-  if (style & wxTE_MULTILINE)
-    m_widget = gtk_text_new( NULL, NULL );
-  else
-    m_widget = 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 );
-
-  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())
-  {
-    gint tmp = 0;
-    gtk_editable_insert_text( GTK_EDITABLE(m_widget), value, value.Length(), &tmp );
-  };
-
-  if (style & wxREADONLY)
-  {
-  }
-  else
-  {
-    if (style & wxTE_MULTILINE) gtk_text_set_editable( GTK_TEXT(m_widget), 1 );
-  };
-
-  Show( TRUE );
-
-  return TRUE;
-};
-
-wxString wxTextCtrl::GetValue(void) const
-{
-  wxString tmp;
-  if (m_windowStyle & wxTE_MULTILINE)
-  {
-    gint len = gtk_text_get_length( GTK_TEXT(m_widget) );
-    tmp = gtk_editable_get_chars( GTK_EDITABLE(m_widget), 0, len );
-  }
-  else
-  {
-    tmp = gtk_entry_get_text( GTK_ENTRY(m_widget) );
-  };
-  return tmp;
-};
-
-void wxTextCtrl::SetValue( const wxString &value )
-{
-  wxString tmp = "";
-  if (!value.IsNull()) tmp = value;
-  if (m_windowStyle & wxTE_MULTILINE)
-  {
-    gint len = gtk_text_get_length( GTK_TEXT(m_widget) );
-    gtk_editable_delete_text( GTK_EDITABLE(m_widget), 0, len );
-    len = 0;
-    gtk_editable_insert_text( GTK_EDITABLE(m_widget), tmp, tmp.Length(), &len );
-  }
-  else
-  {
-    gtk_entry_set_text( GTK_ENTRY(m_widget), tmp );
-  };
-};
+void wxTextCtrl::Init()
+{
+    m_ignoreNextUpdate =
+    m_modified = false;
+    SetUpdateFont(false);
+    m_text =
+    m_vScrollbar = (GtkWidget *)NULL;
+}
+
+wxTextCtrl::~wxTextCtrl()
+{
+}
+
+wxTextCtrl::wxTextCtrl( wxWindow *parent,
+                        wxWindowID id,
+                        const wxString &value,
+                        const wxPoint &pos,
+                        const wxSize &size,
+                        long style,
+                        const wxValidator& validator,
+                        const wxString &name )
+{
+    Init();
+
+    Create( parent, id, value, pos, size, style, validator, name );
+}
+
+bool wxTextCtrl::Create( wxWindow *parent,
+                         wxWindowID id,
+                         const wxString &value,
+                         const wxPoint &pos,
+                         const wxSize &size,
+                         long style,
+                         const wxValidator& validator,
+                         const wxString &name )
+{
+    m_needParent = true;
+    m_acceptsFocus = true;
+
+    if (!PreCreation( parent, pos, size ) ||
+        !CreateBase( parent, id, pos, size, style, validator, name ))
+    {
+        wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
+        return false;
+    }
+
+
+    m_vScrollbarVisible = false;
+
+    bool multi_line = (style & wxTE_MULTILINE) != 0;
+
+    if (multi_line)
+    {
+        // create our control ...
+        m_text = gtk_text_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
+
+        // ... and put into the upper left hand corner of the table
+        bool bHasHScrollbar = false;
+        m_widget = gtk_table_new(bHasHScrollbar ? 2 : 1, 2, FALSE);
+        GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
+        gtk_table_attach( GTK_TABLE(m_widget), m_text, 0, 1, 0, 1,
+                      (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK),
+                      (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK),
+                       0, 0);
+
+        // always wrap words
+        gtk_text_set_word_wrap( GTK_TEXT(m_text), TRUE );
+
+        // finally, put the vertical scrollbar in the upper right corner
+        m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj );
+        GTK_WIDGET_UNSET_FLAGS( m_vScrollbar, GTK_CAN_FOCUS );
+        gtk_table_attach(GTK_TABLE(m_widget), m_vScrollbar, 1, 2, 0, 1,
+                     GTK_FILL,
+                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK),
+                     0, 0);
+    }
+    else
+    {
+        // a single-line text control: no need for scrollbars
+        m_widget =
+        m_text = gtk_entry_new();
+    }
+
+    m_parent->DoAddChild( this );
+
+    m_focusWidget = m_text;
+
+    PostCreation(size);
+
+    if (multi_line)
+        gtk_widget_show(m_text);
+
+    if (multi_line)
+    {
+        gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text)->vadj), "changed",
+          (GtkSignalFunc) gtk_scrollbar_changed_callback, (gpointer) this );
+
+        // only initialize gs_gtk_text_draw once, starting from the next the
+        // klass::draw will already be wxgtk_text_draw
+        if ( !gs_gtk_text_draw )
+        {
+            GtkDrawCallback&
+                draw = GTK_WIDGET_CLASS(GTK_OBJECT(m_text)->klass)->draw;
+
+            gs_gtk_text_draw = draw;
+
+            draw = wxgtk_text_draw;
+        }
+    }
+
+    if (!value.empty())
+    {
+#if !GTK_CHECK_VERSION(1, 2, 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
+
+        gint tmp = 0;
+#if wxUSE_UNICODE
+        wxWX2MBbuf val = value.mbc_str();
+        gtk_editable_insert_text( GTK_EDITABLE(m_text), val, strlen(val), &tmp );
+#else
+        gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.length(), &tmp );
+#endif
+
+        if (multi_line)
+        {
+            // Bring editable's cursor uptodate. Bug in GTK.
+            SET_EDITABLE_POS(m_text, 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 );
+    }
+
+    // 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);
+
+    m_cursor = wxCursor( wxCURSOR_IBEAM );
+
+    wxTextAttr attrDef(GetForegroundColour(), GetBackgroundColour(), GetFont());
+    SetDefaultStyle( attrDef );
+
+    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, wxEmptyString, wxT("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 = text;
+        g_free( text );
+    }
+    else
+    {
+        tmp = wxGTK_CONV_BACK( gtk_entry_get_text( GTK_ENTRY(m_text) ) );
+    }
+
+    return tmp;
+}
+
+void wxTextCtrl::DoSetValue( const wxString &value, int flags )
+{
+    wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
+
+    if ( !(flags & SetValue_SendEvent) )
+    {
+        // do not generate events
+        IgnoreNextTextUpdate();
+    }
+
+    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;
+        gtk_editable_insert_text( GTK_EDITABLE(m_text), value.mbc_str(), value.length(), &len );
+    }
+    else
+    {
+        gtk_entry_set_text( GTK_ENTRY(m_text), wxGTK_CONV( value ) );
+    }
+
+    // GRG, Jun/2000: Changed this after a lot of discussion in
+    //   the lists. wxWidgets 2.2 will have a set of flags to
+    //   customize this behaviour.
+    SetInsertionPoint(0);
+
+    m_modified = false;
+}