diff options
Diffstat (limited to 'gtk/gtktextview.c')
-rw-r--r-- | gtk/gtktextview.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 0e864b178..254ad44c5 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -620,6 +620,18 @@ gtk_text_view_class_init (GtkTextViewClass *klass) /* + * Style properties + */ + + gtk_widget_class_install_style_property (widget_class, + g_param_spec_boxed ("cursor_color", + _("Cursor color"), + _("Color with which to draw insertion cursor"), + GDK_TYPE_COLOR, + G_PARAM_READABLE)); + + + /* * Signals */ @@ -2909,6 +2921,24 @@ changed_handler (GtkTextLayout *layout, } static void +gtk_text_view_realize_cursor_gc (GtkTextView *text_view) +{ + GdkColor *cursor_color; + GdkColor red = { 0, 0xffff, 0x0000, 0x0000 }; + + if (text_view->cursor_gc) + gdk_gc_unref (text_view->cursor_gc); + + gtk_widget_style_get (GTK_WIDGET (text_view), "cursor_color", &cursor_color, NULL); + + if (!cursor_color) + cursor_color = &red; + + text_view->cursor_gc = gdk_gc_new (text_view->text_window->bin_window); + gdk_gc_set_rgb_fg_color (text_view->cursor_gc, cursor_color); +} + +static void gtk_text_view_realize (GtkWidget *widget) { GtkTextView *text_view; @@ -2958,6 +2988,8 @@ gtk_text_view_realize (GtkWidget *widget) text_window_realize (text_view->bottom_window, widget->window); + gtk_text_view_realize_cursor_gc (text_view); + gtk_text_view_ensure_layout (text_view); if (text_view->buffer) @@ -2976,6 +3008,12 @@ gtk_text_view_unrealize (GtkWidget *widget) gtk_text_buffer_remove_selection_clipboard (text_view->buffer, gtk_clipboard_get (GDK_SELECTION_PRIMARY)); + if (text_view->cursor_gc) + { + gdk_gc_unref (text_view->cursor_gc); + text_view->cursor_gc = NULL; + } + if (text_view->first_validate_idle) { g_source_remove (text_view->first_validate_idle); @@ -3041,6 +3079,8 @@ gtk_text_view_style_set (GtkWidget *widget, if (text_view->bottom_window) gdk_window_set_background (text_view->bottom_window->bin_window, &widget->style->bg[GTK_WIDGET_STATE (widget)]); + + gtk_text_view_realize_cursor_gc (text_view); } if (text_view->layout && previous_style) @@ -3575,6 +3615,7 @@ gtk_text_view_paint (GtkWidget *widget, GdkRectangle *area) gtk_text_layout_draw (text_view->layout, widget, text_view->text_window->bin_window, + text_view->cursor_gc, text_view->xoffset, text_view->yoffset, area->x, area->y, |