Commit c848fbbc authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

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.
parent 5d5cfcd4
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.
Sun Mar 3 20:48:12 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_set_submenu_navigation_region): change
......@@ -26,16 +46,6 @@ Sun Mar 3 12:13:56 2002 Owen Taylor <otaylor@redhat.com>
required instead of pangox. (Reported by Miles
Lane)
Sun Mar 3 12:06:02 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkentry.c (gtk_entry_expose): Draw cursors
_under_ the text, not over.
Sun Mar 3 11:26:20 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): add
a secondary-cursor-color property.
Sun Mar 3 11:12:16 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtktextlayout.c (add_cursor): When in split cursor
......
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.
Sun Mar 3 20:48:12 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_set_submenu_navigation_region): change
......@@ -26,16 +46,6 @@ Sun Mar 3 12:13:56 2002 Owen Taylor <otaylor@redhat.com>
required instead of pangox. (Reported by Miles
Lane)
Sun Mar 3 12:06:02 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkentry.c (gtk_entry_expose): Draw cursors
_under_ the text, not over.
Sun Mar 3 11:26:20 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): add
a secondary-cursor-color property.
Sun Mar 3 11:12:16 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtktextlayout.c (add_cursor): When in split cursor
......
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.
Sun Mar 3 20:48:12 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_set_submenu_navigation_region): change
......@@ -26,16 +46,6 @@ Sun Mar 3 12:13:56 2002 Owen Taylor <otaylor@redhat.com>
required instead of pangox. (Reported by Miles
Lane)
Sun Mar 3 12:06:02 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkentry.c (gtk_entry_expose): Draw cursors
_under_ the text, not over.
Sun Mar 3 11:26:20 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): add
a secondary-cursor-color property.
Sun Mar 3 11:12:16 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtktextlayout.c (add_cursor): When in split cursor
......
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.
Sun Mar 3 20:48:12 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_set_submenu_navigation_region): change
......@@ -26,16 +46,6 @@ Sun Mar 3 12:13:56 2002 Owen Taylor <otaylor@redhat.com>
required instead of pangox. (Reported by Miles
Lane)
Sun Mar 3 12:06:02 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkentry.c (gtk_entry_expose): Draw cursors
_under_ the text, not over.
Sun Mar 3 11:26:20 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): add
a secondary-cursor-color property.
Sun Mar 3 11:12:16 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtktextlayout.c (add_cursor): When in split cursor
......
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.
Sun Mar 3 20:48:12 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_set_submenu_navigation_region): change
......@@ -26,16 +46,6 @@ Sun Mar 3 12:13:56 2002 Owen Taylor <otaylor@redhat.com>
required instead of pangox. (Reported by Miles
Lane)
Sun Mar 3 12:06:02 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkentry.c (gtk_entry_expose): Draw cursors
_under_ the text, not over.
Sun Mar 3 11:26:20 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): add
a secondary-cursor-color property.
Sun Mar 3 11:12:16 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtktextlayout.c (add_cursor): When in split cursor
......
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.
Sun Mar 3 20:48:12 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_set_submenu_navigation_region): change
......@@ -26,16 +46,6 @@ Sun Mar 3 12:13:56 2002 Owen Taylor <otaylor@redhat.com>
required instead of pangox. (Reported by Miles
Lane)
Sun Mar 3 12:06:02 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkentry.c (gtk_entry_expose): Draw cursors
_under_ the text, not over.
Sun Mar 3 11:26:20 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): add
a secondary-cursor-color property.
Sun Mar 3 11:12:16 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtktextlayout.c (add_cursor): When in split cursor
......
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.
Sun Mar 3 20:48:12 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_set_submenu_navigation_region): change
......@@ -26,16 +46,6 @@ Sun Mar 3 12:13:56 2002 Owen Taylor <otaylor@redhat.com>
required instead of pangox. (Reported by Miles
Lane)
Sun Mar 3 12:06:02 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkentry.c (gtk_entry_expose): Draw cursors
_under_ the text, not over.
Sun Mar 3 11:26:20 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwidget.c (gtk_widget_class_init): add
a secondary-cursor-color property.
Sun Mar 3 11:12:16 2002 Owen Taylor <otaylor@redhat.com>
* gtk/gtktextlayout.c (add_cursor): When in split cursor
......
......@@ -925,23 +925,6 @@ gtk_entry_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gtk_entry_realize_cursor_gc (GtkEntry *entry)
{
GdkColor *cursor_color;
GdkColor red = {0, 0xffff, 0x0000, 0x0000};
if (entry->cursor_gc)
gdk_gc_unref (entry->cursor_gc);
gtk_widget_style_get (GTK_WIDGET (entry), "cursor-color", &cursor_color, NULL);
entry->cursor_gc = gdk_gc_new (entry->text_area);
if (cursor_color)
gdk_gc_set_rgb_fg_color (entry->cursor_gc, cursor_color);
else
gdk_gc_set_rgb_fg_color (entry->cursor_gc, &red);
}
static void
gtk_entry_realize (GtkWidget *widget)
{
......@@ -988,8 +971,6 @@ gtk_entry_realize (GtkWidget *widget)
widget->style = gtk_style_attach (widget->style, widget->window);
gtk_entry_realize_cursor_gc (entry);
gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
......@@ -1014,12 +995,6 @@ gtk_entry_unrealize (GtkWidget *widget)
entry->text_area = NULL;
}
if (entry->cursor_gc)
{
gdk_gc_unref (entry->cursor_gc);
entry->cursor_gc = NULL;
}
if (entry->popup_menu)
{
gtk_widget_destroy (entry->popup_menu);
......@@ -1241,8 +1216,15 @@ gtk_entry_expose (GtkWidget *widget,
gtk_entry_draw_frame (widget);
else if (entry->text_area == event->window)
{
gtk_entry_draw_text (GTK_ENTRY (widget));
gint area_width, area_height;
get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
gtk_paint_flat_box (widget->style, entry->text_area,
GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE,
NULL, widget, "entry_bg",
0, 0, area_width, area_height);
if ((entry->visible || entry->invisible_char != 0) &&
GTK_WIDGET_HAS_FOCUS (widget) &&
entry->selection_bound == entry->current_pos && entry->cursor_visible)
......@@ -1250,6 +1232,8 @@ gtk_entry_expose (GtkWidget *widget,
if (entry->dnd_position != -1)
gtk_entry_draw_cursor (GTK_ENTRY (widget), CURSOR_DND);
gtk_entry_draw_text (GTK_ENTRY (widget));
}
return FALSE;
......@@ -1799,8 +1783,6 @@ gtk_entry_style_set (GtkWidget *widget,
gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
gdk_window_set_background (entry->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
gtk_entry_realize_cursor_gc (entry);
}
}
......@@ -2617,7 +2599,6 @@ gtk_entry_draw_text (GtkEntry *entry)
if (GTK_WIDGET_DRAWABLE (entry))
{
PangoLayout *layout = gtk_entry_ensure_layout (entry, TRUE);
gint area_width, area_height;
gint x, y;
gint start_pos, end_pos;
......@@ -2625,13 +2606,6 @@ gtk_entry_draw_text (GtkEntry *entry)
get_layout_position (entry, &x, &y);
get_text_area_size (entry, NULL, NULL, &area_width, &area_height);
gtk_paint_flat_box (widget->style, entry->text_area,
GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE,
NULL, widget, "entry_bg",
0, 0, area_width, area_height);
gdk_draw_layout (entry->text_area, widget->style->text_gc [widget->state],
x, y,
layout);
......@@ -2710,12 +2684,11 @@ gtk_entry_draw_cursor (GtkEntry *entry,
gint xoffset = INNER_BORDER - entry->scroll_offset;
gint strong_x, weak_x;
gint text_area_height;
GdkGC *gc1 = NULL;
GdkGC *gc2 = NULL;
GtkTextDirection dir1 = GTK_TEXT_DIR_NONE;
GtkTextDirection dir2 = GTK_TEXT_DIR_NONE;
gint x1 = 0;
gint x2 = 0;
GdkGC *gc;
gdk_window_get_size (entry->text_area, NULL, &text_area_height);
......@@ -2729,21 +2702,16 @@ gtk_entry_draw_cursor (GtkEntry *entry,
if (split_cursor)
{
gc1 = entry->cursor_gc;
x1 = strong_x;
if (weak_x != strong_x)
{
dir2 = (widget_direction == GTK_TEXT_DIR_LTR) ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR;
gc2 = widget->style->text_gc[GTK_STATE_NORMAL];
x2 = weak_x;
}
}
else
{
gc1 = entry->cursor_gc;
if (keymap_direction == widget_direction)
x1 = strong_x;
else
......@@ -2754,17 +2722,21 @@ gtk_entry_draw_cursor (GtkEntry *entry,
cursor_location.y = INNER_BORDER;
cursor_location.width = 0;
cursor_location.height = text_area_height - 2 * INNER_BORDER ;
_gtk_draw_insertion_cursor (widget, entry->text_area, gc1,
gc = _gtk_get_insertion_cursor_gc (widget, TRUE);
_gtk_draw_insertion_cursor (widget, entry->text_area, gc,
&cursor_location, dir1,
dir2 != GTK_TEXT_DIR_NONE);
g_object_unref (gc);
if (dir2 != GTK_TEXT_DIR_NONE)
{
cursor_location.x = xoffset + x2;
_gtk_draw_insertion_cursor (widget, entry->text_area, gc2,
gc = _gtk_get_insertion_cursor_gc (widget, FALSE);
_gtk_draw_insertion_cursor (widget, entry->text_area, gc,
&cursor_location, dir2,
TRUE);
g_object_unref (gc);
}
}
}
......
......@@ -111,8 +111,6 @@ struct _GtkEntry
gunichar invisible_char;
gint width_chars;
GdkGC *cursor_gc;
};
struct _GtkEntryClass
......
......@@ -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);
}
}
}
......@@ -1967,26 +1964,6 @@ gtk_label_set_text_with_mnemonic (GtkLabel *label,
gtk_label_setup_mnemonic (label, last_keyval);
}
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)
{
......@@ -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);
......
......@@ -312,6 +312,7 @@ static void hls_to_rgb (gdouble *h,
gdouble *l,
gdouble *s);
static void style_unrealize_cursor_gcs (GtkStyle *style);
/*
* Data for default check and radio buttons
......@@ -1774,6 +1775,8 @@ gtk_style_real_unrealize (GtkStyle *style)
gdk_colormap_free_colors (style->colormap, style->text, 5);
gdk_colormap_free_colors (style->colormap, style->base, 5);
gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
style_unrealize_cursor_gcs (style);
}
static void
......@@ -5645,6 +5648,136 @@ gtk_style_set_font (GtkStyle *style,
}
}
typedef struct _CursorInfo CursorInfo;
struct _CursorInfo
{
GType for_type;
GdkGC *primary_gc;
GdkGC *secondary_gc;
};
static void
style_unrealize_cursor_gcs (GtkStyle *style)
{
CursorInfo *
cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
if (cursor_info)
{
if (cursor_info->primary_gc)
gtk_gc_release (cursor_info->primary_gc);
if (cursor_info->secondary_gc)
gtk_gc_release (cursor_info->secondary_gc);
g_free (cursor_info);
g_object_set_data (G_OBJECT (style), "gtk-style-cursor-info", NULL);
}
}
static GdkGC *
make_cursor_gc (GtkWidget *widget,
const gchar *property_name,
GdkColor *fallback)
{
GdkGCValues gc_values;
GdkGCValuesMask gc_values_mask;
GdkColor *cursor_color;
gtk_widget_style_get (widget, property_name, &cursor_color, NULL);
gc_values_mask = GDK_GC_FOREGROUND;
if (cursor_color)
{
gc_values.foreground = *cursor_color;
gdk_color_free (cursor_color);
}
else
gc_values.foreground = *fallback;
gdk_rgb_find_color (widget->style->colormap, &gc_values.foreground);
return gtk_gc_get (widget->style->depth, widget->style->colormap, &gc_values, gc_values_mask);
}
/**
* _gtk_get_insertion_cursor_gc:
* @widget: a #GtkWidget
* @is_primary: if the cursor should be the primary cursor color.
*
* Get a GC suitable for drawing the primary or secondary text
* cursor.
*
* Note: the return value is ref'ed because calls to this function
* on other widgets could result in this the GC being released
* which would be an unexpected side effect. If made public,
* this function should possibly be called create_insertion_cursor_gc().
*
* Return value: an appropriate #GdkGC. Call g_object_unref() on
* the gc when you are done with it; this GC may be shared with
* other users, so you must not modify the GC except for temporarily
* setting the clip before drawing with the GC, and then unsetting the clip
* again afterwards.
**/
GdkGC *
_gtk_get_insertion_cursor_gc (GtkWidget *widget,
gboolean is_primary)
{
CursorInfo *cursor_info;
cursor_info = g_object_get_data (G_OBJECT (widget->style), "gtk-style-cursor-info");
if (!cursor_info)
{
cursor_info = g_new (CursorInfo, 1);
g_object_set_data (G_OBJECT (widget->style), "gtk-style-cursor-info", cursor_info);
cursor_info->primary_gc = NULL;
cursor_info->secondary_gc = NULL;
cursor_info->for_type = G_TYPE_INVALID;
}
/* We have to keep track of the type because gtk_widget_style_get()
* can return different results when called on the same property and
* same style but for different widgets. :-(. That is,
* GtkEntry::cursor-color = "red" in a style will modify the cursor
* color for entries but not for text view.
*/
if (cursor_info->for_type != G_OBJECT_TYPE (widget))
{
cursor_info->for_type = G_OBJECT_TYPE (widget);
if (cursor_info->primary_gc)
{
gtk_gc_release (cursor_info->primary_gc);
cursor_info->primary_gc = NULL;
}
if (cursor_info->secondary_gc)
{
gtk_gc_release (cursor_info->secondary_gc);
cursor_info->secondary_gc = NULL;
}
}
if (is_primary)
{
if (!cursor_info->primary_gc)
cursor_info->primary_gc = make_cursor_gc (widget,
"cursor-color",
&widget->style->black);