Merge lp:~cimi/indicator-messages/fix-draw-gtk3 into lp:indicator-messages/0.5

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 227
Merged at revision: 225
Proposed branch: lp:~cimi/indicator-messages/fix-draw-gtk3
Merge into: lp:indicator-messages/0.5
Diff against target: 154 lines (+54/-7)
1 file modified
src/indicator-messages.c (+54/-7)
To merge this branch: bzr merge lp:~cimi/indicator-messages/fix-draw-gtk3
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+71919@code.launchpad.net

Description of the change

Fix the draw methods in gtk3

To post a comment you must log in.
226. By Andrea Cimitan

Whitespace

227. By Andrea Cimitan

Whitespace

Revision history for this message
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/indicator-messages.c'
2--- src/indicator-messages.c 2011-07-21 21:31:18 +0000
3+++ src/indicator-messages.c 2011-08-17 16:48:57 +0000
4@@ -416,12 +416,18 @@
5 }
6
7 /* Draws a triangle on the left, using fg[STATE_TYPE] color. */
8+#if GTK_CHECK_VERSION(3, 0, 0)
9+static gboolean
10+application_triangle_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
11+{
12+#else
13 static gboolean
14 application_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
15 {
16+ cairo_t *cr;
17+#endif
18 GtkAllocation allocation;
19 GtkStyle *style;
20- cairo_t *cr;
21 int x, y, arrow_width, arrow_height;
22
23 if (!GTK_IS_WIDGET (widget)) return FALSE;
24@@ -438,13 +444,22 @@
25 arrow_width = 5; /* the pixel-based reference triangle is 5x9 */
26 arrow_height = 9;
27 gtk_widget_get_allocation (widget, &allocation);
28+#if GTK_CHECK_VERSION(3, 0, 0)
29+ x = 0;
30+ y = allocation.height/2.0 - (double)arrow_height/2.0;
31+#else
32 x = allocation.x;
33 y = allocation.y + allocation.height/2.0 - (double)arrow_height/2.0;
34+#endif
35
36+#if GTK_CHECK_VERSION(3, 0, 0)
37+ cairo_save (cr);
38+#else
39 /* initialize cairo drawing area */
40 cr = (cairo_t*) gdk_cairo_create (gtk_widget_get_window (widget));
41+#endif
42
43- /* set line width */
44+ /* set line width */
45 cairo_set_line_width (cr, 1.0);
46
47 /* cairo drawing code */
48@@ -457,8 +472,12 @@
49 style->fg[gtk_widget_get_state(widget)].blue/65535.0);
50 cairo_fill (cr);
51
52+#if GTK_CHECK_VERSION(3, 0, 0)
53+ cairo_restore (cr);
54+#else
55 /* remember to destroy cairo context to avoid leaks */
56 cairo_destroy (cr);
57+#endif
58
59 return FALSE;
60 }
61@@ -478,12 +497,18 @@
62 }
63
64 /* Draws a rounded rectangle with text inside. */
65+#if GTK_CHECK_VERSION(3, 0, 0)
66+static gboolean
67+numbers_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
68+{
69+#else
70 static gboolean
71 numbers_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
72 {
73+ cairo_t *cr;
74+#endif
75 GtkAllocation allocation;
76 GtkStyle *style;
77- cairo_t *cr;
78 double x, y, w, h;
79 PangoLayout * layout;
80 gint font_size = RIGHT_LABEL_FONT_SIZE;
81@@ -495,10 +520,15 @@
82
83 /* set arrow position / dimensions */
84 gtk_widget_get_allocation (widget, &allocation);
85+#if GTK_CHECK_VERSION(3, 0, 0)
86+ x = 0;
87+ y = 0;
88+#else
89+ x = allocation.x;
90+ y = allocation.y;
91+#endif
92 w = allocation.width;
93 h = allocation.height;
94- x = allocation.x;
95- y = allocation.y;
96
97 layout = gtk_label_get_layout (GTK_LABEL(widget));
98
99@@ -508,10 +538,14 @@
100 /* const PangoFontDescription * font_description = pango_layout_get_font_description (layout);
101 font_size = pango_font_description_get_size (font_description); */
102
103+#if GTK_CHECK_VERSION(3, 0, 0)
104+ cairo_save (cr);
105+#else
106 /* initialize cairo drawing area */
107 cr = (cairo_t*) gdk_cairo_create (gtk_widget_get_window (widget));
108+#endif
109
110- /* set line width */
111+ /* set line width */
112 cairo_set_line_width (cr, 1.0);
113
114 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
115@@ -527,8 +561,12 @@
116 pango_cairo_layout_path (cr, layout);
117 cairo_fill (cr);
118
119+#if GTK_CHECK_VERSION(3, 0, 0)
120+ cairo_restore (cr);
121+#else
122 /* remember to destroy cairo context to avoid leaks */
123- cairo_destroy (cr);
124+ cairo_destroy (cr);
125+#endif
126
127 return TRUE;
128 }
129@@ -577,7 +615,11 @@
130 /* Make sure we can handle the label changing */
131 g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(application_prop_change_cb), label);
132 g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(application_icon_change_cb), icon);
133+#if GTK_CHECK_VERSION(3, 0, 0)
134+ g_signal_connect_after(G_OBJECT (gmi), "draw", G_CALLBACK (application_triangle_draw_cb), newitem);
135+#else
136 g_signal_connect_after(G_OBJECT (gmi), "expose_event", G_CALLBACK (application_triangle_draw_cb), newitem);
137+#endif
138
139 return TRUE;
140 }
141@@ -710,8 +752,13 @@
142 mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT));
143 gtk_size_group_add_widget(indicator_right_group, mi_data->right);
144 /* install extra decoration overlay */
145+#if GTK_CHECK_VERSION(3, 0, 0)
146+ g_signal_connect (G_OBJECT (mi_data->right), "draw",
147+ G_CALLBACK (numbers_draw_cb), NULL);
148+#else
149 g_signal_connect (G_OBJECT (mi_data->right), "expose_event",
150 G_CALLBACK (numbers_draw_cb), NULL);
151+#endif
152
153 gtk_misc_set_alignment(GTK_MISC(mi_data->right), 1.0, 0.5);
154 gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, padding + font_size/2.0);

Subscribers

People subscribed via source and target branches