diff options
author | Owen Taylor <otaylor@redhat.com> | 2002-03-03 19:59:29 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2002-03-03 19:59:29 +0000 |
commit | c848fbbcfe7813b6347a00452a890aeb17e767bb (patch) | |
tree | 91b2e23d465dc215130c97d2d6d46cc8a8fe3739 /gtk/gtklabel.c | |
parent | 5d5cfcd435d00ffa11ffce63d3b708904faf2182 (diff) | |
download | gtk+-c848fbbcfe7813b6347a00452a890aeb17e767bb.tar.gz |
Centralize lookup and caching of cursor GC's here.
Sun Mar 3 14:26:33 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkstyle.[ch] (_gtk_get_insertion_cursor_gc):
Centralize lookup and caching of cursor GC's here.
* gtk/gtkentry.[ch] gtk/gtktextview.[ch] gtk/gtktextdisplay.c
gtk/gtklabel.c: Move to using _gtk_get_insertion_cursor_gc().
* gtk/gtkentry.c (gtk_entry_expose): Draw cursors
under the text, not over the text.
* gtk/gtkwidget.c (gtk_widget_class_init): add
a secondary-cursor-color property.
* gtk/gtkwidget.c (gtk_widget_class_init): Decrease
the default aspect ratio to 1/25 (0.04).
* tests/testgtkrc (bell_duration): Comment out
cursor color setting.
Diffstat (limited to 'gtk/gtklabel.c')
-rw-r--r-- | gtk/gtklabel.c | 71 |
1 files changed, 12 insertions, 59 deletions
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 8538e458f7..36fdb44b2b 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -46,7 +46,6 @@ struct _GtkLabelSelectionInfo GdkWindow *window; gint selection_anchor; gint selection_end; - GdkGC *cursor_gc; GtkWidget *popup_menu; }; @@ -1676,8 +1675,7 @@ gtk_label_draw_cursor (GtkLabel *label, gint xoffset, gint yoffset) GdkRectangle cursor_location; GtkTextDirection dir1 = GTK_TEXT_DIR_NONE; GtkTextDirection dir2 = GTK_TEXT_DIR_NONE; - GdkGC *gc1 = NULL; - GdkGC *gc2 = NULL; + GdkGC *gc; keymap_direction = (gdk_keymap_get_direction (gdk_keymap_get_default ()) == PANGO_DIRECTION_LTR) ? @@ -1698,22 +1696,17 @@ gtk_label_draw_cursor (GtkLabel *label, gint xoffset, gint yoffset) if (split_cursor) { - gc1 = label->select_info->cursor_gc; cursor1 = &strong_pos; if (strong_pos.x != weak_pos.x || strong_pos.y != weak_pos.y) { dir2 = (widget_direction == GTK_TEXT_DIR_LTR) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR; - - gc2 = widget->style->black_gc; cursor2 = &weak_pos; } } else { - gc1 = label->select_info->cursor_gc; - if (keymap_direction == widget_direction) cursor1 = &strong_pos; else @@ -1724,10 +1717,12 @@ gtk_label_draw_cursor (GtkLabel *label, gint xoffset, gint yoffset) cursor_location.y = yoffset + PANGO_PIXELS (cursor1->y); cursor_location.width = 0; cursor_location.height = PANGO_PIXELS (cursor1->height); - - _gtk_draw_insertion_cursor (widget, widget->window, gc1, + + gc = _gtk_get_insertion_cursor_gc (widget, TRUE); + _gtk_draw_insertion_cursor (widget, widget->window, gc, &cursor_location, dir1, dir2 != GTK_TEXT_DIR_NONE); + g_object_unref (gc); if (dir2 != GTK_TEXT_DIR_NONE) { @@ -1735,9 +1730,11 @@ gtk_label_draw_cursor (GtkLabel *label, gint xoffset, gint yoffset) cursor_location.y = yoffset + PANGO_PIXELS (cursor2->y); cursor_location.width = 0; cursor_location.height = PANGO_PIXELS (cursor2->height); - - _gtk_draw_insertion_cursor (widget, widget->window, gc2, + + gc = _gtk_get_insertion_cursor_gc (widget, FALSE); + _gtk_draw_insertion_cursor (widget, widget->window, gc, &cursor_location, dir2, TRUE); + g_object_unref (gc); } } } @@ -1968,26 +1965,6 @@ gtk_label_set_text_with_mnemonic (GtkLabel *label, } static void -gtk_label_realize_cursor_gc (GtkLabel *label) -{ - GdkColor *cursor_color; - GdkColor red = {0, 0xffff, 0x0000, 0x0000}; - - if (label->select_info == NULL) - return; - - if (label->select_info->cursor_gc) - gdk_gc_unref (label->select_info->cursor_gc); - - gtk_widget_style_get (GTK_WIDGET (label), "cursor-color", &cursor_color, NULL); - label->select_info->cursor_gc = gdk_gc_new (GTK_WIDGET (label)->window); - if (cursor_color) - gdk_gc_set_rgb_fg_color (label->select_info->cursor_gc, cursor_color); - else - gdk_gc_set_rgb_fg_color (label->select_info->cursor_gc, &red); -} - -static void gtk_label_realize (GtkWidget *widget) { GtkLabel *label; @@ -1997,23 +1974,7 @@ gtk_label_realize (GtkWidget *widget) (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); if (label->select_info) - { - gtk_label_create_window (label); - gtk_label_realize_cursor_gc (label); - } -} - -static void -gtk_label_unrealize_cursor_gc (GtkLabel *label) -{ - if (label->select_info == NULL) - return; - - if (label->select_info->cursor_gc) - { - gdk_gc_unref (label->select_info->cursor_gc); - label->select_info->cursor_gc = NULL; - } + gtk_label_create_window (label); } static void @@ -2024,10 +1985,7 @@ gtk_label_unrealize (GtkWidget *widget) label = GTK_LABEL (widget); if (label->select_info) - { - gtk_label_unrealize_cursor_gc (label); - gtk_label_destroy_window (label); - } + gtk_label_destroy_window (label); (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); } @@ -2374,10 +2332,7 @@ gtk_label_set_selectable (GtkLabel *label, GTK_WIDGET_SET_FLAGS (label, GTK_CAN_FOCUS); if (GTK_WIDGET_REALIZED (label)) - { - gtk_label_create_window (label); - gtk_label_realize_cursor_gc (label); - } + gtk_label_create_window (label); if (GTK_WIDGET_MAPPED (label)) gdk_window_show (label->select_info->window); @@ -2390,8 +2345,6 @@ gtk_label_set_selectable (GtkLabel *label, /* unselect, to give up the selection */ gtk_label_select_region (label, 0, 0); - gtk_label_unrealize_cursor_gc (label); - if (label->select_info->window) { gtk_label_destroy_window (label); |