summaryrefslogtreecommitdiff
path: root/eel/eel-editable-label.c
diff options
context:
space:
mode:
Diffstat (limited to 'eel/eel-editable-label.c')
-rw-r--r--eel/eel-editable-label.c82
1 files changed, 69 insertions, 13 deletions
diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c
index 5a916aed..014caabd 100644
--- a/eel/eel-editable-label.c
+++ b/eel/eel-editable-label.c
@@ -90,8 +90,13 @@ static void eel_editable_label_style_set (GtkWidget
GtkStyle *previous_style);
static void eel_editable_label_direction_changed (GtkWidget *widget,
GtkTextDirection previous_dir);
+#if GTK_CHECK_VERSION(3,0,0)
+static gint eel_editable_label_draw (GtkWidget *widget,
+ cairo_t *cr);
+#else
static gint eel_editable_label_expose (GtkWidget *widget,
- GdkEventExpose *event);
+ GdkEventExpose *event);
+#endif
static void eel_editable_label_realize (GtkWidget *widget);
static void eel_editable_label_unrealize (GtkWidget *widget);
static void eel_editable_label_map (GtkWidget *widget);
@@ -225,7 +230,11 @@ eel_editable_label_class_init (EelEditableLabelClass *class)
widget_class->state_changed = eel_editable_label_state_changed;
widget_class->style_set = eel_editable_label_style_set;
widget_class->direction_changed = eel_editable_label_direction_changed;
+#if GTK_CHECK_VERSION(3,0,0)
+ widget_class->draw = eel_editable_label_draw;
+#else
widget_class->expose_event = eel_editable_label_expose;
+#endif
widget_class->realize = eel_editable_label_realize;
widget_class->unrealize = eel_editable_label_unrealize;
widget_class->map = eel_editable_label_map;
@@ -1389,7 +1398,11 @@ eel_editable_label_get_block_cursor_location (EelEditableLabel *label,
/* These functions are copies from gtk+, as they are not exported from gtk+ */
static void
+#if GTK_CHECK_VERSION(3,0,0)
+eel_editable_label_draw_cursor (EelEditableLabel *label, cairo_t *cr, gint xoffset, gint yoffset)
+#else
eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yoffset)
+#endif
{
if (gtk_widget_is_drawable (GTK_WIDGET (label)))
{
@@ -1456,8 +1469,14 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof
cursor_location.width = 0;
cursor_location.height = PANGO_PIXELS (cursor1->height);
- gtk_draw_insertion_cursor (widget, gtk_widget_get_window (widget),
+ gtk_draw_insertion_cursor (widget,
+#if GTK_CHECK_VERSION(3,0,0)
+ cr,
+ &cursor_location,
+#else
+ gtk_widget_get_window (widget),
NULL, &cursor_location,
+#endif
TRUE, dir1, dir2 != GTK_TEXT_DIR_NONE);
if (dir2 != GTK_TEXT_DIR_NONE)
@@ -1467,17 +1486,23 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof
cursor_location.width = 0;
cursor_location.height = PANGO_PIXELS (cursor2->height);
- gtk_draw_insertion_cursor (widget, gtk_widget_get_window (widget),
- NULL, &cursor_location,
- FALSE, dir1, TRUE);
+ gtk_draw_insertion_cursor (widget,
+#if GTK_CHECK_VERSION(3,0,0)
+ cr,
+ &cursor_location,
+#else
+ gtk_widget_get_window (widget),
+ NULL, &cursor_location,
+#endif
+ FALSE, dir1, TRUE);
}
}
else /* Block cursor */
{
cairo_region_t *clip;
- cairo_t *cr;
-
- cr = gdk_cairo_create (gtk_widget_get_window (widget));
+#if !GTK_CHECK_VERSION(3,0,0)
+ cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
+#endif
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_rectangle (cr,
@@ -1507,22 +1532,31 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof
cairo_region_destroy (clip);
}
+#if !GTK_CHECK_VERSION(3,0,0)
cairo_destroy (cr);
+#endif
}
}
}
static gint
+#if GTK_CHECK_VERSION(3,0,0)
+eel_editable_label_draw (GtkWidget *widget,
+ cairo_t *cr)
+#else
eel_editable_label_expose (GtkWidget *widget,
GdkEventExpose *event)
+#endif
{
EelEditableLabel *label;
GtkStyle *style;
gint x, y;
g_assert (EEL_IS_EDITABLE_LABEL (widget));
+#if !GTK_CHECK_VERSION(3,0,0)
g_assert (event != NULL);
+#endif
label = EEL_EDITABLE_LABEL (widget);
style = gtk_widget_get_style (widget);
@@ -1535,10 +1569,16 @@ eel_editable_label_expose (GtkWidget *widget,
get_layout_location (label, &x, &y);
gtk_paint_layout (style,
+#if GTK_CHECK_VERSION(3,0,0)
+ cr,
+#else
gtk_widget_get_window (widget),
+#endif
gtk_widget_get_state (widget),
TRUE,
+#if !GTK_CHECK_VERSION(3,0,0)
&event->area,
+#endif
widget,
"label",
x, y,
@@ -1550,14 +1590,13 @@ 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;
/* Handle possible preedit string */
if (label->preedit_length > 0 &&
- range[1] > label->selection_anchor)
+ range[1] > label->selection_anchor)
{
text = pango_layout_get_text (label->layout) + label->selection_anchor;
range[1] += g_utf8_offset_to_pointer (text, label->preedit_length) - text;
@@ -1570,7 +1609,9 @@ eel_editable_label_expose (GtkWidget *widget,
range[1] = tmp;
}
- cr = gdk_cairo_create (gtk_widget_get_window (widget));
+#if !GTK_CHECK_VERSION(3,0,0)
+ cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
+#endif
clip = gdk_pango_layout_get_clip_region (label->layout,
x, y,
range,
@@ -1589,19 +1630,26 @@ eel_editable_label_expose (GtkWidget *widget,
cairo_move_to (cr, x, y);
pango_cairo_show_layout (cr, label->layout);
+#if !GTK_CHECK_VERSION(3,0,0)
cairo_destroy (cr);
+#endif
cairo_region_destroy (clip);
}
else if (gtk_widget_has_focus (widget))
+#if GTK_CHECK_VERSION(3,0,0)
+ eel_editable_label_draw_cursor (label, cr, x, y);
+#else
eel_editable_label_draw_cursor (label, x, y);
+#endif
if (label->draw_outline)
{
GtkAllocation allocation;
- cairo_t *cr;
gtk_widget_get_allocation (widget, &allocation);
- cr = gdk_cairo_create (gtk_widget_get_window (widget));
+#if !GTK_CHECK_VERSION(3,0,0)
+ cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
+#endif
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,
@@ -1609,7 +1657,9 @@ eel_editable_label_expose (GtkWidget *widget,
allocation.height - 1);
cairo_stroke (cr);
+#if !GTK_CHECK_VERSION(3,0,0)
cairo_destroy (cr);
+#endif
}
}
@@ -1637,7 +1687,9 @@ eel_editable_label_realize (GtkWidget *widget)
attributes.width = allocation.width;
attributes.height = allocation.height;
attributes.visual = gtk_widget_get_visual (widget);
+#if !GTK_CHECK_VERSION(3,0,0)
attributes.colormap = gtk_widget_get_colormap (widget);
+#endif
attributes.cursor = gdk_cursor_new (GDK_XTERM);
attributes.event_mask = gtk_widget_get_events (widget) |
(GDK_EXPOSURE_MASK |
@@ -1650,7 +1702,11 @@ eel_editable_label_realize (GtkWidget *widget)
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK);
+#if GTK_CHECK_VERSION(3,0,0)
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_CURSOR;
+#else
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_CURSOR;
+#endif
window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);