summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasmine Hassan <[email protected]>2012-10-18 13:12:33 +0200
committerJasmine Hassan <[email protected]>2012-11-13 06:25:03 +0200
commit0fdc303dd11b419465d299b36307010ce3221cfa (patch)
tree0085f40126e109b63b6a346ba897c593cacb85cd
parente68ea5c0a9cd2f4f1d88cc9fd38f1e80b2399291 (diff)
downloadcaja-0fdc303dd11b419465d299b36307010ce3221cfa.tar.bz2
caja-0fdc303dd11b419465d299b36307010ce3221cfa.tar.xz
[eel] port EelEditableLabel to cairo drawing
http://git.gnome.org/browse/nautilus/commit/?id=6cb78fb15c89e53e60ee54dc8b773db6ca0def73
-rw-r--r--eel/eel-editable-label.c221
-rw-r--r--eel/eel-editable-label.h3
2 files changed, 48 insertions, 176 deletions
diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c
index 2c7ea7b0..fb20af85 100644
--- a/eel/eel-editable-label.c
+++ b/eel/eel-editable-label.c
@@ -182,10 +182,6 @@ static void editable_real_set_position (GtkEditable *editable,
gint position);
static gint editable_get_position (GtkEditable *editable);
-static GdkGC * make_cursor_gc (GtkWidget *widget,
- const gchar *property_name,
- GdkColor *fallback);
-
G_DEFINE_TYPE_WITH_CODE (EelEditableLabel, eel_editable_label, GTK_TYPE_MISC,
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, eel_editable_label_editable_init));
@@ -1169,7 +1165,6 @@ eel_editable_label_style_set (GtkWidget *widget,
GtkStyle *previous_style)
{
EelEditableLabel *label;
- static GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 };
g_assert (EEL_IS_EDITABLE_LABEL (widget));
@@ -1187,26 +1182,6 @@ eel_editable_label_style_set (GtkWidget *widget,
style = gtk_widget_get_style (widget);
gdk_window_set_background (gtk_widget_get_window (widget), &style->base[gtk_widget_get_state (widget)]);
-
- if (label->primary_cursor_gc != NULL)
- {
- gtk_gc_release (label->primary_cursor_gc);
- label->primary_cursor_gc = NULL;
- }
-
- if (label->secondary_cursor_gc != NULL)
- {
- gtk_gc_release (label->secondary_cursor_gc);
- label->secondary_cursor_gc = NULL;
- }
-
- label->primary_cursor_gc = make_cursor_gc (widget,
- "cursor-color",
- &style->black);
-
- label->secondary_cursor_gc = make_cursor_gc (widget,
- "secondary-cursor-color",
- &gray);
}
}
@@ -1409,96 +1384,6 @@ eel_editable_label_get_block_cursor_location (EelEditableLabel *label,
/* These functions are copies from gtk+, as they are not exported from gtk+ */
-static GdkGC *
-make_cursor_gc (GtkWidget *widget,
- const gchar *property_name,
- GdkColor *fallback)
-{
- GdkGCValues gc_values;
- GdkGCValuesMask gc_values_mask;
- GdkColor *cursor_color;
- GtkStyle *style;
-
- style = gtk_widget_get_style (widget);
- 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 (style->colormap, &gc_values.foreground);
- return gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
-}
-
-static void
-_eel_draw_insertion_cursor (GtkWidget *widget,
- GdkDrawable *drawable,
- GdkGC *gc,
- GdkRectangle *location,
- GtkTextDirection direction,
- gboolean draw_arrow)
-{
- gint stem_width;
- gint arrow_width;
- gint x, y;
- gint i;
- gfloat cursor_aspect_ratio;
- gint offset;
-
- g_assert (direction != GTK_TEXT_DIR_NONE);
-
- gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
-
- stem_width = location->height * cursor_aspect_ratio + 1;
- arrow_width = stem_width + 1;
-
- /* put (stem_width % 2) on the proper side of the cursor */
- if (direction == GTK_TEXT_DIR_LTR)
- offset = stem_width / 2;
- else
- offset = stem_width - stem_width / 2;
-
- for (i = 0; i < stem_width; i++)
- gdk_draw_line (drawable, gc,
- location->x + i - offset, location->y,
- location->x + i - offset, location->y + location->height - 1);
-
- if (draw_arrow)
- {
- if (direction == GTK_TEXT_DIR_RTL)
- {
- x = location->x - offset - 1;
- y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
-
- for (i = 0; i < arrow_width; i++)
- {
- gdk_draw_line (drawable, gc,
- x, y + i + 1,
- x, y + 2 * arrow_width - i - 1);
- x --;
- }
- }
- else if (direction == GTK_TEXT_DIR_LTR)
- {
- x = location->x + stem_width - offset;
- y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
-
- for (i = 0; i < arrow_width; i++)
- {
- gdk_draw_line (drawable, gc,
- x, y + i + 1,
- x, y + 2 * arrow_width - i - 1);
- x++;
- }
- }
- }
-}
-
static void
eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yoffset)
{
@@ -1567,10 +1452,9 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof
cursor_location.width = 0;
cursor_location.height = PANGO_PIXELS (cursor1->height);
- _eel_draw_insertion_cursor (widget, gtk_widget_get_window (widget),
- label->primary_cursor_gc,
- &cursor_location, dir1,
- dir2 != GTK_TEXT_DIR_NONE);
+ gtk_draw_insertion_cursor (widget, gtk_widget_get_window (widget),
+ NULL, &cursor_location,
+ TRUE, dir1, dir2 != GTK_TEXT_DIR_NONE);
if (dir2 != GTK_TEXT_DIR_NONE)
{
@@ -1579,43 +1463,47 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof
cursor_location.width = 0;
cursor_location.height = PANGO_PIXELS (cursor2->height);
- _eel_draw_insertion_cursor (widget, gtk_widget_get_window (widget),
- label->secondary_cursor_gc,
- &cursor_location, dir2, TRUE);
+ gtk_draw_insertion_cursor (widget, gtk_widget_get_window (widget),
+ NULL, &cursor_location,
+ FALSE, dir1, TRUE);
}
}
else /* Block cursor */
{
cairo_region_t *clip;
+ cairo_t *cr;
- gdk_draw_rectangle (gtk_widget_get_window (widget), label->primary_cursor_gc, TRUE,
- xoffset + PANGO_PIXELS (strong_pos.x),
- yoffset + PANGO_PIXELS (strong_pos.y),
- PANGO_PIXELS (strong_pos.width),
- PANGO_PIXELS (strong_pos.height));
+ cr = gdk_cairo_create (gtk_widget_get_window (widget));
+
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_rectangle (cr,
+ xoffset + PANGO_PIXELS (strong_pos.x),
+ yoffset + PANGO_PIXELS (strong_pos.y),
+ PANGO_PIXELS (strong_pos.width),
+ PANGO_PIXELS (strong_pos.height));
if (!block_at_line_end)
{
clip = gdk_pango_layout_get_clip_region (label->layout,
- xoffset, yoffset,
- range, 1);
+ xoffset, yoffset,
+ range, 1);
+
+ gdk_cairo_region (cr, clip);
+ cairo_clip (cr);
/* FIXME should use gtk_paint, but it can't use a clip
* region
*/
- gdk_gc_set_clip_region (label->primary_cursor_gc, clip);
+ gdk_cairo_set_source_color (cr,
+ &gtk_widget_get_style (widget)->base[GTK_STATE_NORMAL]);
+ cairo_move_to (cr, xoffset, yoffset);
+ pango_cairo_show_layout (cr, label->layout);
- gdk_draw_layout_with_colors (gtk_widget_get_window (widget),
- label->primary_cursor_gc,
- xoffset, yoffset,
- label->layout,
- &gtk_widget_get_style (widget)->base[GTK_STATE_NORMAL],
- NULL);
-
- gdk_gc_set_clip_region (label->primary_cursor_gc, NULL);
cairo_region_destroy (clip);
}
+
+ cairo_destroy (cr);
}
}
}
@@ -1658,6 +1546,7 @@ eel_editable_label_expose (GtkWidget *widget,
const char *text;
cairo_region_t *clip;
GtkStateType state;
+ cairo_t *cr;
range[0] = label->selection_anchor;
range[1] = label->selection_end;
@@ -1677,30 +1566,26 @@ eel_editable_label_expose (GtkWidget *widget,
range[1] = tmp;
}
+ cr = gdk_cairo_create (gtk_widget_get_window (widget));
clip = gdk_pango_layout_get_clip_region (label->layout,
x, y,
range,
1);
-
- /* FIXME should use gtk_paint, but it can't use a clip
- * region
- */
-
- gdk_gc_set_clip_region (style->black_gc, clip);
-
+ gdk_cairo_region (cr, clip);
+ cairo_clip (cr);
state = GTK_STATE_SELECTED;
if (!gtk_widget_has_focus (widget))
state = GTK_STATE_ACTIVE;
- gdk_draw_layout_with_colors (gtk_widget_get_window (widget),
- style->black_gc,
- x, y,
- label->layout,
- &style->text[state],
- &style->base[state]);
+ gdk_cairo_set_source_color (cr, &style->base[state]);
+ cairo_paint (cr);
+
+ gdk_cairo_set_source_color (cr, &style->text[state]);
+ cairo_move_to (cr, x, y);
+ pango_cairo_show_layout (cr, label->layout);
- gdk_gc_set_clip_region (style->black_gc, NULL);
+ cairo_destroy (cr);
cairo_region_destroy (clip);
}
else if (gtk_widget_has_focus (widget))
@@ -1709,13 +1594,18 @@ eel_editable_label_expose (GtkWidget *widget,
if (label->draw_outline)
{
GtkAllocation allocation;
+ cairo_t *cr;
+
gtk_widget_get_allocation (widget, &allocation);
- gdk_draw_rectangle (gtk_widget_get_window (widget),
- style->text_gc [gtk_widget_get_state (widget)],
- FALSE,
- 0, 0,
- allocation.width - 1,
- allocation.height - 1);
+ cr = gdk_cairo_create (gtk_widget_get_window (widget));
+ gdk_cairo_set_source_color (cr, &style->text [gtk_widget_get_state (widget)]);
+ cairo_set_line_width (cr, 1.0);
+ cairo_rectangle (cr, 0.5, 0.5,
+ allocation.width - 1,
+ allocation.height - 1);
+ cairo_stroke (cr);
+
+ cairo_destroy (cr);
}
}
@@ -1728,7 +1618,6 @@ eel_editable_label_realize (GtkWidget *widget)
EelEditableLabel *label;
GdkWindowAttr attributes;
gint attributes_mask;
- static GdkColor gray = { 0, 0x8888, 0x8888, 0x8888 };
GtkAllocation allocation;
GdkWindow *window;
GtkStyle *style;
@@ -1772,14 +1661,6 @@ eel_editable_label_realize (GtkWidget *widget)
gdk_window_set_background (gtk_widget_get_window (widget), &style->base[gtk_widget_get_state (widget)]);
gtk_im_context_set_client_window (label->im_context, gtk_widget_get_window (widget));
-
- label->primary_cursor_gc = make_cursor_gc (widget,
- "cursor-color",
- &style->black);
-
- label->secondary_cursor_gc = make_cursor_gc (widget,
- "secondary-cursor-color",
- &gray);
}
static void
@@ -1789,12 +1670,6 @@ eel_editable_label_unrealize (GtkWidget *widget)
label = EEL_EDITABLE_LABEL (widget);
- gtk_gc_release (label->primary_cursor_gc);
- label->primary_cursor_gc = NULL;
-
- gtk_gc_release (label->secondary_cursor_gc);
- label->secondary_cursor_gc = NULL;
-
/* Strange. Copied from GtkEntry, should be NULL? */
gtk_im_context_set_client_window (label->im_context, NULL);
diff --git a/eel/eel-editable-label.h b/eel/eel-editable-label.h
index 249a3367..b19c2417 100644
--- a/eel/eel-editable-label.h
+++ b/eel/eel-editable-label.h
@@ -79,9 +79,6 @@ extern "C" {
int preedit_length; /* length of preedit string, in bytes */
int preedit_cursor; /* offset of cursor within preedit string, in chars */
- GdkGC *primary_cursor_gc;
- GdkGC *secondary_cursor_gc;
-
PangoFontDescription *font_desc;
};