summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog30
-rw-r--r--ChangeLog.pre-2-030
-rw-r--r--ChangeLog.pre-2-1030
-rw-r--r--ChangeLog.pre-2-230
-rw-r--r--ChangeLog.pre-2-430
-rw-r--r--ChangeLog.pre-2-630
-rw-r--r--ChangeLog.pre-2-830
-rw-r--r--gtk/gtkentry.c64
-rw-r--r--gtk/gtkentry.h2
-rw-r--r--gtk/gtklabel.c71
-rw-r--r--gtk/gtkstyle.c133
-rw-r--r--gtk/gtkstyle.h14
-rw-r--r--gtk/gtktextdisplay.c9
-rw-r--r--gtk/gtktextview.c30
-rw-r--r--gtk/gtktextview.h1
-rw-r--r--gtk/gtkwidget.c8
-rw-r--r--tests/testgtkrc2
17 files changed, 323 insertions, 221 deletions
diff --git a/ChangeLog b/ChangeLog
index 92bd984cc5..e4d4bd859e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+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
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index 92bd984cc5..e4d4bd859e 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -1,3 +1,23 @@
+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
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 92bd984cc5..e4d4bd859e 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,23 @@
+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
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index 92bd984cc5..e4d4bd859e 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -1,3 +1,23 @@
+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
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index 92bd984cc5..e4d4bd859e 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,23 @@
+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
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index 92bd984cc5..e4d4bd859e 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,23 @@
+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
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index 92bd984cc5..e4d4bd859e 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,23 @@
+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
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 7752125799..86949860f8 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -926,23 +926,6 @@ gtk_entry_finalize (GObject *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)
{
GtkEntry *entry;
@@ -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);
}
}
}
diff --git a/gtk/gtkentry.h b/gtk/gtkentry.h
index 86856c5126..259b960953 100644
--- a/gtk/gtkentry.h
+++ b/gtk/gtkentry.h
@@ -111,8 +111,6 @@ struct _GtkEntry
gunichar invisible_char;
gint width_chars;
-
- GdkGC *cursor_gc;
};
struct _GtkEntryClass
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);
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index 472a20c418..5ac1002d09 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -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);
+
+ return g_object_ref (cursor_info->primary_gc);
+ }
+ else
+ {
+ static GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 };
+
+ if (!cursor_info->secondary_gc)
+ cursor_info->secondary_gc = make_cursor_gc (widget,
+ "secondary-cursor-color",
+ &gray);
+
+ return g_object_ref (cursor_info->secondary_gc);
+ }
+}
+
/**
* _gtk_draw_insertion_cursor:
* @widget: a #GtkWidget
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index 844187466c..ce4c3901c1 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -882,12 +882,14 @@ void gtk_paint_string (GtkStyle *style,
const gchar *string);
#endif /* GTK_DISABLE_DEPRECATED */
-void _gtk_draw_insertion_cursor (GtkWidget *widget,
- GdkDrawable *drawable,
- GdkGC *gc,
- GdkRectangle *location,
- GtkTextDirection direction,
- gboolean draw_arrow);
+GdkGC *_gtk_get_insertion_cursor_gc (GtkWidget *widget,
+ gboolean is_primary);
+void _gtk_draw_insertion_cursor (GtkWidget *widget,
+ GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkRectangle *location,
+ GtkTextDirection direction,
+ gboolean draw_arrow);
#ifdef __cplusplus
}
diff --git a/gtk/gtktextdisplay.c b/gtk/gtktextdisplay.c
index cfb5225d74..99b8631fce 100644
--- a/gtk/gtktextdisplay.c
+++ b/gtk/gtktextdisplay.c
@@ -834,14 +834,8 @@ gtk_text_layout_draw (GtkTextLayout *layout,
GtkTextCursorDisplay *cursor = cursor_list->data;
GtkTextDirection dir;
GdkRectangle cursor_location;
-
GdkGC *gc;
- if (cursor->is_strong)
- gc = cursor_gc;
- else
- gc = widget->style->text_gc[GTK_STATE_NORMAL];
-
dir = line_display->direction;
if (have_strong && have_weak)
{
@@ -854,11 +848,14 @@ gtk_text_layout_draw (GtkTextLayout *layout,
cursor_location.width = 0;
cursor_location.height = cursor->height;
+ gc = _gtk_get_insertion_cursor_gc (widget, cursor->is_strong);
gdk_gc_set_clip_rectangle(gc, &clip);
_gtk_draw_insertion_cursor (widget, drawable, gc, &cursor_location,
dir, have_strong && have_weak);
gdk_gc_set_clip_rectangle (gc, NULL);
+ g_object_unref (gc);
+
cursor_list = cursor_list->next;
}
} /* line_display->height > 0 */
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index defa2cfb0c..adc3b1a828 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -3252,24 +3252,6 @@ 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;
@@ -3320,8 +3302,6 @@ 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)
@@ -3350,12 +3330,6 @@ 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;
- }
-
gtk_text_view_remove_validate_idles (text_view);
if (text_view->popup_menu)
@@ -3411,8 +3385,6 @@ 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)
@@ -4060,7 +4032,7 @@ gtk_text_view_paint (GtkWidget *widget,
gtk_text_layout_draw (text_view->layout,
widget,
text_view->text_window->bin_window,
- text_view->cursor_gc,
+ NULL,
text_view->xoffset,
text_view->yoffset,
area->x, area->y,
diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h
index 5a50518c7e..ad8f6e1802 100644
--- a/gtk/gtktextview.h
+++ b/gtk/gtktextview.h
@@ -147,7 +147,6 @@ struct _GtkTextView
GSList *children;
GtkTextPendingScroll *pending_scroll;
- GdkGC *cursor_gc;
gint pending_place_cursor_button;
};
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 0c1587fd7c..550f5ebda3 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -1079,10 +1079,16 @@ gtk_widget_class_init (GtkWidgetClass *klass)
GDK_TYPE_COLOR,
G_PARAM_READABLE));
gtk_widget_class_install_style_property (klass,
+ g_param_spec_boxed ("secondary-cursor-color",
+ _("Secondary cursor color"),
+ _("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text."),
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (klass,
g_param_spec_float ("cursor-aspect-ratio",
_("Cursor line aspect ratio"),
_("Aspect ratio with which to draw insertion cursor"),
- 0.0, 1.0, 0.033,
+ 0.0, 1.0, 0.04,
G_PARAM_READABLE));
}
diff --git a/tests/testgtkrc b/tests/testgtkrc
index 307c0689c6..7e540fa325 100644
--- a/tests/testgtkrc
+++ b/tests/testgtkrc
@@ -34,7 +34,7 @@ style "global-style-properties"
# xthickness = 20
GtkButton::child_displacement_x = 1
GtkButton::child_displacement_y = 1
- GtkWidget::cursor_color = "#ff0000"
+# GtkWidget::cursor_color = "#ff0000"
GtkToolbar::space_size = 10
GtkToolbar::space_style = line
GtkToolbar::button_relief = none