+extern void wxapp_install_idle_handler();
+extern bool g_isIdle;
+
+//-----------------------------------------------------------------------------
+// data
+//-----------------------------------------------------------------------------
+
+extern bool g_blockEventsOnDrag;
+extern wxCursor g_globalCursor;
+extern wxWindowGTK *g_delayedFocus;
+
+// ----------------------------------------------------------------------------
+// helpers
+// ----------------------------------------------------------------------------
+
+#ifdef __WXGTK20__
+static void wxGtkTextInsert(GtkWidget *text,
+ GtkTextBuffer *text_buffer,
+ const wxTextAttr& attr,
+ wxCharBuffer buffer)
+
+{
+ PangoFontDescription *font_description = attr.HasFont()
+ ? attr.GetFont().GetNativeFontInfo()->description
+ : NULL;
+
+ GdkColor *colFg = attr.HasTextColour() ? attr.GetTextColour().GetColor()
+ : NULL;
+
+ GdkColor *colBg = attr.HasBackgroundColour()
+ ? attr.GetBackgroundColour().GetColor()
+ : NULL;
+
+ GtkTextTag *tag;
+ tag = gtk_text_buffer_create_tag( text_buffer, NULL, "font-desc", font_description,
+ "foreground-gdk", colFg,
+ "background-gdk", colBg, NULL );
+
+ GtkTextIter iter;
+ gtk_text_buffer_get_iter_at_mark( text_buffer, &iter,
+ gtk_text_buffer_get_insert (text_buffer) );
+
+ gtk_text_buffer_insert_with_tags( text_buffer, &iter, buffer, strlen(buffer), tag, NULL );
+}
+#else
+static void wxGtkTextInsert(GtkWidget *text,
+ const wxTextAttr& attr,
+ const char *txt,
+ size_t len)
+{
+ GdkFont *font = attr.HasFont() ? attr.GetFont().GetInternalFont()
+ : NULL;
+
+ GdkColor *colFg = attr.HasTextColour() ? attr.GetTextColour().GetColor()
+ : NULL;
+
+ GdkColor *colBg = attr.HasBackgroundColour()
+ ? attr.GetBackgroundColour().GetColor()
+ : NULL;
+
+ gtk_text_insert( GTK_TEXT(text), font, colFg, colBg, txt, len );
+}
+#endif // GTK 1.x
+
+// ----------------------------------------------------------------------------
+// "insert_text" for GtkEntry
+// ----------------------------------------------------------------------------
+
+static void
+gtk_insert_text_callback(GtkEditable *editable,
+ const gchar *new_text,
+ gint new_text_length,
+ gint *position,
+ wxTextCtrl *win)
+{
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+
+ // we should only be called if we have a max len limit at all
+ GtkEntry *entry = GTK_ENTRY (editable);
+
+ wxCHECK_RET( entry->text_max_length, _T("shouldn't be called") );
+
+ // check that we don't overflow the max length limit
+ //
+ // FIXME: this doesn't work when we paste a string which is going to be
+ // truncated
+ if ( entry->text_length == entry->text_max_length )
+ {
+ // we don't need to run the base class version at all
+ gtk_signal_emit_stop_by_name(GTK_OBJECT(editable), "insert_text");
+
+ // remember that the next changed signal is to be ignored to avoid
+ // generating a dummy wxEVT_COMMAND_TEXT_UPDATED event
+ win->IgnoreNextTextUpdate();
+
+ // and generate the correct one ourselves
+ wxCommandEvent event(wxEVT_COMMAND_TEXT_MAXLEN, win->GetId());
+ event.SetEventObject(win);
+ event.SetString(win->GetValue());
+ win->GetEventHandler()->ProcessEvent( event );
+ }
+}
+
+//-----------------------------------------------------------------------------
+// "changed"
+//-----------------------------------------------------------------------------
+
+static void
+gtk_text_changed_callback( GtkWidget *widget, wxTextCtrl *win )
+{
+ if ( win->IgnoreTextUpdate() )
+ return;
+
+ if (!win->m_hasVMT) return;
+
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+
+ win->SetModified();
+#ifndef __WXGTK20__
+ win->UpdateFontIfNeeded();
+#endif // !__WXGTK20__
+
+ wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
+ event.SetEventObject( win );
+ event.SetString( win->GetValue() );
+ win->GetEventHandler()->ProcessEvent( event );
+}
+
+//-----------------------------------------------------------------------------
+// "changed" from vertical scrollbar
+//-----------------------------------------------------------------------------
+
+#ifndef __WXGTK20__
+static void
+gtk_scrollbar_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
+{
+ if (!win->m_hasVMT) return;
+
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+
+ win->CalculateScrollbar();
+}
+#endif
+
+// ----------------------------------------------------------------------------
+// redraw callback for multiline text
+// ----------------------------------------------------------------------------
+
+#ifndef __WXGTK20__
+
+// redrawing a GtkText from inside a wxYield() call results in crashes (the
+// text sample shows it in its "Add lines" command which shows wxProgressDialog
+// which implicitly calls wxYield()) so we override GtkText::draw() and simply
+// don't do anything if we're inside wxYield()
+
+extern bool wxIsInsideYield;
+
+extern "C" {
+ typedef void (*GtkDrawCallback)(GtkWidget *widget, GdkRectangle *rect);
+}