+ wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") );
+
+ if ( !wxControl::SetBackgroundColour( colour ) )
+ return FALSE;
+
+ if (!m_widget->window)
+ return FALSE;
+
+ if (!m_backgroundColour.Ok())
+ return FALSE;
+
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+#ifndef __WXGTK20__
+ GdkWindow *window = GTK_TEXT(m_text)->text_area;
+ if (!window)
+ return FALSE;
+ m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
+ gdk_window_set_background( window, m_backgroundColour.GetColor() );
+ gdk_window_clear( window );
+#endif
+ }
+
+ // change active background color too
+ m_defaultStyle.SetBackgroundColour( colour );
+
+ return TRUE;
+}
+
+bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style )
+{
+ if ( m_windowStyle & wxTE_MULTILINE )
+ {
+ if ( style.IsDefault() )
+ {
+ // nothing to do
+ return TRUE;
+ }
+#ifdef __WXGTK20__
+ GtkTextBuffer *text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(m_text) );
+ gint l = gtk_text_buffer_get_char_count( text_buffer );
+
+ wxCHECK_MSG( start >= 0 && end <= l, FALSE,
+ _T("invalid range in wxTextCtrl::SetStyle") );
+
+ GtkTextIter starti, endi;
+ gtk_text_buffer_get_iter_at_offset( text_buffer, &starti, start );
+ gtk_text_buffer_get_iter_at_offset( text_buffer, &endi, end );
+
+ // use the attributes from style which are set in it and fall back
+ // first to the default style and then to the text control default
+ // colours for the others
+ wxTextAttr attr = wxTextAttr::Combine(style, m_defaultStyle, this);
+
+ 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 );
+ gtk_text_buffer_apply_tag( text_buffer, tag, &starti, &endi );
+
+ return TRUE;
+#else
+ // VERY dirty way to do that - removes the required text and re-adds it
+ // with styling (FIXME)
+
+ gint l = gtk_text_get_length( GTK_TEXT(m_text) );
+
+ wxCHECK_MSG( start >= 0 && end <= l, FALSE,
+ _T("invalid range in wxTextCtrl::SetStyle") );
+
+ gint old_pos = gtk_editable_get_position( GTK_EDITABLE(m_text) );
+ char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), start, end );
+ wxString tmp(text,*wxConvCurrent);
+ g_free( text );
+
+ gtk_editable_delete_text( GTK_EDITABLE(m_text), start, end );
+ gtk_editable_set_position( GTK_EDITABLE(m_text), start );
+
+#if wxUSE_UNICODE
+ wxWX2MBbuf buf = tmp.mbc_str();
+ const char *txt = buf;
+ size_t txtlen = strlen(buf);
+#else
+ const char *txt = tmp;
+ size_t txtlen = tmp.length();
+#endif
+
+ // use the attributes from style which are set in it and fall back
+ // first to the default style and then to the text control default
+ // colours for the others
+ wxGtkTextInsert(m_text,
+ wxTextAttr::Combine(style, m_defaultStyle, this),
+ txt,
+ txtlen);
+
+ /* does not seem to help under GTK+ 1.2 !!!
+ gtk_editable_set_position( GTK_EDITABLE(m_text), old_pos ); */
+ SetInsertionPoint( old_pos );
+#endif
+ return TRUE;
+ }
+ else // singe line
+ {
+ // cannot do this for GTK+'s Entry widget
+ return FALSE;
+ }