Fri, 07 Dec 2018 13:18:54 -0600
gtkblist: Port plugin actions mostly off of GtkUIManager
Pidgin generates menu items in the buddy list from PurplePluginActions.
This patch ports these menu items off of the deprecated GtkUIManager
in favor of the GMenu API, except for getting the parent menu,
currently still generated with GtkUIManager. Once more of the buddy
list menu is ported to GMenu, this can be simplified some more.
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
1 | /* pidgin |
| 10298 | 2 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
3 | * Pidgin is the legal property of its developers, whose names are too numerous |
| 10298 | 4 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 5 | * source distribution. | |
| 6 | * | |
| 7 | * This program is free software; you can redistribute it and/or modify | |
| 8 | * it under the terms of the GNU General Public License as published by | |
| 9 | * the Free Software Foundation; either version 2, or(at your option) | |
| 10 | * any later version. | |
| 11 | * | |
| 12 | * This program is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | * GNU General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU General Public License | |
| 18 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17176
diff
changeset
|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA. |
| 10298 | 20 | */ |
| 21 | ||
| 22 | #include "gtkdnd-hints.h" | |
| 23 | ||
|
35850
1abeda205d6c
cross-win32: make dirs more flexible, add them to the config.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35501
diff
changeset
|
24 | #include "internal.h" |
|
1abeda205d6c
cross-win32: make dirs more flexible, add them to the config.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35501
diff
changeset
|
25 | |
| 10298 | 26 | #include <gdk/gdk.h> |
| 27 | #include <gdk-pixbuf/gdk-pixbuf.h> | |
| 28 | ||
|
33170
ce4447562d64
Add checks for old GTK+2 stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33158
diff
changeset
|
29 | #include "gtk3compat.h" |
|
ce4447562d64
Add checks for old GTK+2 stuff.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33158
diff
changeset
|
30 | |
| 10298 | 31 | typedef struct |
| 32 | { | |
| 33 | GtkWidget *widget; | |
| 34 | gchar *filename; | |
| 35 | gint ox; | |
| 36 | gint oy; | |
| 37 | ||
| 38 | } HintWindowInfo; | |
| 39 | ||
|
35455
216a37403c5b
Fix a bunch of gtk-doc warnings in pidgin
Ankit Vani <a@nevitus.org>
parents:
35454
diff
changeset
|
40 | /* |
|
35500
ae6432ea326f
Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents:
35455
diff
changeset
|
41 | * Info about each hint widget. See PidginDndHintWindowId enum. |
| 10298 | 42 | */ |
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
43 | static HintWindowInfo hint_windows[] = { |
|
16274
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
44 | { NULL, "arrow-up.xpm", -13/2, 0 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
45 | { NULL, "arrow-down.xpm", -13/2, -16 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
46 | { NULL, "arrow-left.xpm", 0, -13/2 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
47 | { NULL, "arrow-right.xpm", -16, -13/2 }, |
| 10298 | 48 | { NULL, NULL, 0, 0 } |
| 49 | }; | |
| 50 | ||
|
33135
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
51 | static void |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
52 | dnd_hints_realized_cb(GtkWidget *window, GtkWidget *pix) |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
53 | { |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
54 | GdkPixbuf *pixbuf; |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
55 | cairo_surface_t *surface; |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
56 | cairo_region_t *region; |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
57 | cairo_t *cr; |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
58 | |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
59 | pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(pix)); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
60 | |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
61 | surface = cairo_image_surface_create(CAIRO_FORMAT_A1, |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
62 | gdk_pixbuf_get_width(pixbuf), |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
63 | gdk_pixbuf_get_height(pixbuf)); |
|
33158
ad941796372e
Remove some added trailing spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33135
diff
changeset
|
64 | |
|
33135
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
65 | cr = cairo_create(surface); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
66 | gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
67 | cairo_paint(cr); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
68 | cairo_destroy(cr); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
69 | |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
70 | region = gdk_cairo_region_create_from_surface(surface); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
71 | gtk_widget_shape_combine_region(window, region); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
72 | cairo_region_destroy(region); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
73 | |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
74 | cairo_surface_destroy(surface); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
75 | } |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
76 | |
| 10298 | 77 | static GtkWidget * |
| 78 | dnd_hints_init_window(const gchar *fname) | |
| 79 | { | |
| 80 | GdkPixbuf *pixbuf; | |
|
33135
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
81 | GtkWidget *pix; |
| 10298 | 82 | GtkWidget *win; |
| 83 | ||
| 84 | pixbuf = gdk_pixbuf_new_from_file(fname, NULL); | |
| 85 | g_return_val_if_fail(pixbuf, NULL); | |
| 86 | ||
|
32919
d6b32e557879
Render the DND hint windows using the new window's colourmap instead
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25888
diff
changeset
|
87 | win = gtk_window_new(GTK_WINDOW_POPUP); |
|
33135
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
88 | pix = gtk_image_new_from_pixbuf(pixbuf); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
89 | gtk_container_add(GTK_CONTAINER(win), pix); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
90 | gtk_widget_show_all(pix); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
91 | |
| 10298 | 92 | g_object_unref(G_OBJECT(pixbuf)); |
| 93 | ||
|
33135
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
94 | g_signal_connect(G_OBJECT(win), "realize", |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
95 | G_CALLBACK(dnd_hints_realized_cb), pix); |
| 10298 | 96 | |
| 97 | return win; | |
| 98 | } | |
| 99 | ||
| 100 | static void | |
| 101 | get_widget_coords(GtkWidget *w, gint *x1, gint *y1, gint *x2, gint *y2) | |
| 102 | { | |
| 103 | gint ox, oy, width, height; | |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
104 | GtkWidget *parent = gtk_widget_get_parent(w); |
| 10298 | 105 | |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
106 | if (parent && gtk_widget_get_window(parent) == gtk_widget_get_window(w)) |
| 10298 | 107 | { |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
108 | GtkAllocation allocation; |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
109 | |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
110 | gtk_widget_get_allocation(w, &allocation); |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
111 | get_widget_coords(parent, &ox, &oy, NULL, NULL); |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
112 | height = allocation.height; |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
113 | width = allocation.width; |
| 10298 | 114 | } |
| 115 | else | |
| 116 | { | |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
117 | GdkWindow *win = gtk_widget_get_window(w); |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
118 | gdk_window_get_origin(win, &ox, &oy); |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
119 | width = gdk_window_get_width(win); |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
120 | height = gdk_window_get_height(win); |
| 10298 | 121 | } |
| 122 | ||
| 123 | if (x1) *x1 = ox; | |
| 124 | if (y1) *y1 = oy; | |
| 125 | if (x2) *x2 = ox + width; | |
| 126 | if (y2) *y2 = oy + height; | |
| 127 | } | |
| 128 | ||
| 129 | static void | |
| 130 | dnd_hints_init(void) | |
| 131 | { | |
| 132 | static gboolean done = FALSE; | |
| 133 | gint i; | |
| 134 | ||
| 135 | if (done) | |
| 136 | return; | |
| 137 | ||
| 138 | done = TRUE; | |
| 139 | ||
| 140 | for (i = 0; hint_windows[i].filename != NULL; i++) { | |
| 141 | gchar *fname; | |
| 142 | ||
|
35850
1abeda205d6c
cross-win32: make dirs more flexible, add them to the config.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35501
diff
changeset
|
143 | fname = g_build_filename(PURPLE_DATADIR, "pixmaps", "pidgin", |
|
1abeda205d6c
cross-win32: make dirs more flexible, add them to the config.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35501
diff
changeset
|
144 | hint_windows[i].filename, NULL); |
| 10298 | 145 | |
| 146 | hint_windows[i].widget = dnd_hints_init_window(fname); | |
| 147 | ||
| 148 | g_free(fname); | |
| 149 | } | |
| 150 | } | |
| 151 | ||
| 152 | void | |
| 35501 | 153 | pidgin_dnd_hints_hide_all(void) |
| 10298 | 154 | { |
| 155 | gint i; | |
| 156 | ||
| 157 | for (i = 0; hint_windows[i].filename != NULL; i++) | |
|
35500
ae6432ea326f
Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents:
35455
diff
changeset
|
158 | pidgin_dnd_hints_hide(i); |
| 10298 | 159 | } |
| 160 | ||
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
161 | void |
|
35500
ae6432ea326f
Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents:
35455
diff
changeset
|
162 | pidgin_dnd_hints_hide(PidginDndHintWindowId i) |
| 10298 | 163 | { |
| 164 | GtkWidget *w = hint_windows[i].widget; | |
| 165 | ||
| 166 | if (w && GTK_IS_WIDGET(w)) | |
| 167 | gtk_widget_hide(w); | |
| 168 | } | |
| 169 | ||
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
170 | void |
|
35500
ae6432ea326f
Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents:
35455
diff
changeset
|
171 | pidgin_dnd_hints_show(PidginDndHintWindowId id, gint x, gint y) |
| 10298 | 172 | { |
| 173 | GtkWidget *w; | |
| 174 | ||
| 175 | dnd_hints_init(); | |
| 176 | ||
| 177 | w = hint_windows[id].widget; | |
| 178 | ||
| 179 | if (w && GTK_IS_WIDGET(w)) | |
| 180 | { | |
| 181 | gtk_window_move(GTK_WINDOW(w), hint_windows[id].ox + x, | |
| 182 | hint_windows[id].oy + y); | |
| 183 | gtk_widget_show(w); | |
| 184 | } | |
| 185 | } | |
| 186 | ||
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
187 | void |
| 35501 | 188 | pidgin_dnd_hints_show_relative(PidginDndHintWindowId id, GtkWidget *widget, |
|
35500
ae6432ea326f
Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents:
35455
diff
changeset
|
189 | PidginDndHintPosition horiz, PidginDndHintPosition vert) |
| 10298 | 190 | { |
| 191 | gint x1, x2, y1, y2; | |
| 192 | gint x = 0, y = 0; | |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
193 | GtkAllocation allocation; |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
194 | |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
195 | gtk_widget_get_allocation(widget, &allocation); |
| 10298 | 196 | |
| 197 | get_widget_coords(widget, &x1, &y1, &x2, &y2); | |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
198 | x1 += allocation.x; x2 += allocation.x; |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
199 | y1 += allocation.y; y2 += allocation.y; |
| 10298 | 200 | |
| 201 | switch (horiz) | |
| 202 | { | |
| 203 | case HINT_POSITION_RIGHT: x = x2; break; | |
| 204 | case HINT_POSITION_LEFT: x = x1; break; | |
| 205 | case HINT_POSITION_CENTER: x = (x1 + x2) / 2; break; | |
| 206 | default: | |
| 207 | /* should not happen */ | |
| 35501 | 208 | g_warning("Invalid parameter to pidgin_dnd_hints_show_relative"); |
| 10298 | 209 | break; |
| 210 | } | |
| 211 | ||
| 212 | switch (vert) | |
| 213 | { | |
| 214 | case HINT_POSITION_TOP: y = y1; break; | |
| 215 | case HINT_POSITION_BOTTOM: y = y2; break; | |
| 216 | case HINT_POSITION_CENTER: y = (y1 + y2) / 2; break; | |
| 217 | default: | |
| 218 | /* should not happen */ | |
| 35501 | 219 | g_warning("Invalid parameter to pidgin_dnd_hints_show_relative"); |
| 10298 | 220 | break; |
| 221 | } | |
| 222 | ||
|
35500
ae6432ea326f
Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents:
35455
diff
changeset
|
223 | pidgin_dnd_hints_show(id, x, y); |
| 10298 | 224 | } |
| 225 |