Fri, 05 Mar 2021 03:31:29 -0600
Create a PidginAvatar widget.
This does everything the existing code does, but trying to integrate right now
is kind of difficult. The plan is to use this in a new PidginInfoPane I have
started, but that change got very large so I just packed it into the end of
the existing info pane.
The only things that are not implement right now, are making menu items
insensitive and that's because we need to figure out a better want to handle
custom avatars for users.
Testing Done:
Ran locally.
Reviewed at https://reviews.imfreedom.org/r/528/
|
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 | ||
|
40439
e9838d634d5e
Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents:
40197
diff
changeset
|
22 | #ifdef HAVE_CONFIG_H |
|
e9838d634d5e
Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents:
40197
diff
changeset
|
23 | # include <config.h> |
|
e9838d634d5e
Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents:
40197
diff
changeset
|
24 | #endif |
| 10298 | 25 | |
|
40669
48dfed6f4f1f
Fix Windows builds and tests
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40439
diff
changeset
|
26 | #include <purple.h> |
|
48dfed6f4f1f
Fix Windows builds and tests
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40439
diff
changeset
|
27 | |
|
40439
e9838d634d5e
Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents:
40197
diff
changeset
|
28 | #include "gtkdnd-hints.h" |
|
35850
1abeda205d6c
cross-win32: make dirs more flexible, add them to the config.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35501
diff
changeset
|
29 | |
| 10298 | 30 | #include <gdk/gdk.h> |
| 31 | #include <gdk-pixbuf/gdk-pixbuf.h> | |
| 32 | ||
| 33 | typedef struct | |
| 34 | { | |
| 35 | GtkWidget *widget; | |
| 36 | gchar *filename; | |
| 37 | gint ox; | |
| 38 | gint oy; | |
| 39 | ||
| 40 | } HintWindowInfo; | |
| 41 | ||
|
35455
216a37403c5b
Fix a bunch of gtk-doc warnings in pidgin
Ankit Vani <a@nevitus.org>
parents:
35454
diff
changeset
|
42 | /* |
|
35500
ae6432ea326f
Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents:
35455
diff
changeset
|
43 | * Info about each hint widget. See PidginDndHintWindowId enum. |
| 10298 | 44 | */ |
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
45 | static HintWindowInfo hint_windows[] = { |
|
16274
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
46 | { NULL, "arrow-up.xpm", -13/2, 0 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
47 | { NULL, "arrow-down.xpm", -13/2, -16 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
48 | { NULL, "arrow-left.xpm", 0, -13/2 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
49 | { NULL, "arrow-right.xpm", -16, -13/2 }, |
| 10298 | 50 | { NULL, NULL, 0, 0 } |
| 51 | }; | |
| 52 | ||
|
33135
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
53 | static void |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
54 | 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
|
55 | { |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
56 | GdkPixbuf *pixbuf; |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
57 | cairo_surface_t *surface; |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
58 | cairo_region_t *region; |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
59 | cairo_t *cr; |
|
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 | 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
|
62 | |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
63 | 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
|
64 | gdk_pixbuf_get_width(pixbuf), |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
65 | gdk_pixbuf_get_height(pixbuf)); |
|
33158
ad941796372e
Remove some added trailing spaces.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33135
diff
changeset
|
66 | |
|
33135
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
67 | cr = cairo_create(surface); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
68 | 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
|
69 | cairo_paint(cr); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
70 | cairo_destroy(cr); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
71 | |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
72 | 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
|
73 | 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
|
74 | cairo_region_destroy(region); |
|
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 | cairo_surface_destroy(surface); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
77 | } |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
78 | |
| 10298 | 79 | static GtkWidget * |
| 80 | dnd_hints_init_window(const gchar *fname) | |
| 81 | { | |
| 82 | GdkPixbuf *pixbuf; | |
|
33135
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
83 | GtkWidget *pix; |
| 10298 | 84 | GtkWidget *win; |
| 85 | ||
| 86 | pixbuf = gdk_pixbuf_new_from_file(fname, NULL); | |
| 87 | g_return_val_if_fail(pixbuf, NULL); | |
| 88 | ||
|
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
|
89 | 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
|
90 | 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
|
91 | 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
|
92 | gtk_widget_show_all(pix); |
|
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
93 | |
| 10298 | 94 | g_object_unref(G_OBJECT(pixbuf)); |
| 95 | ||
|
33135
b6978ea2cce0
Fix DND hints on GTK+3.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33133
diff
changeset
|
96 | 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
|
97 | G_CALLBACK(dnd_hints_realized_cb), pix); |
| 10298 | 98 | |
| 99 | return win; | |
| 100 | } | |
| 101 | ||
| 102 | static void | |
| 103 | get_widget_coords(GtkWidget *w, gint *x1, gint *y1, gint *x2, gint *y2) | |
| 104 | { | |
| 105 | gint ox, oy, width, height; | |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
106 | GtkWidget *parent = gtk_widget_get_parent(w); |
| 10298 | 107 | |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
108 | if (parent && gtk_widget_get_window(parent) == gtk_widget_get_window(w)) |
| 10298 | 109 | { |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
110 | GtkAllocation allocation; |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
111 | |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
112 | gtk_widget_get_allocation(w, &allocation); |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
113 | get_widget_coords(parent, &ox, &oy, NULL, NULL); |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
114 | height = allocation.height; |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
115 | width = allocation.width; |
| 10298 | 116 | } |
| 117 | else | |
| 118 | { | |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
119 | GdkWindow *win = gtk_widget_get_window(w); |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
120 | gdk_window_get_origin(win, &ox, &oy); |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
121 | width = gdk_window_get_width(win); |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
122 | height = gdk_window_get_height(win); |
| 10298 | 123 | } |
| 124 | ||
| 125 | if (x1) *x1 = ox; | |
| 126 | if (y1) *y1 = oy; | |
| 127 | if (x2) *x2 = ox + width; | |
| 128 | if (y2) *y2 = oy + height; | |
| 129 | } | |
| 130 | ||
| 131 | static void | |
| 132 | dnd_hints_init(void) | |
| 133 | { | |
| 134 | static gboolean done = FALSE; | |
| 135 | gint i; | |
| 136 | ||
| 137 | if (done) | |
| 138 | return; | |
| 139 | ||
| 140 | done = TRUE; | |
| 141 | ||
| 142 | for (i = 0; hint_windows[i].filename != NULL; i++) { | |
| 143 | gchar *fname; | |
| 144 | ||
|
35850
1abeda205d6c
cross-win32: make dirs more flexible, add them to the config.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35501
diff
changeset
|
145 | 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
|
146 | hint_windows[i].filename, NULL); |
| 10298 | 147 | |
| 148 | hint_windows[i].widget = dnd_hints_init_window(fname); | |
| 149 | ||
| 150 | g_free(fname); | |
| 151 | } | |
| 152 | } | |
| 153 | ||
| 154 | void | |
| 35501 | 155 | pidgin_dnd_hints_hide_all(void) |
| 10298 | 156 | { |
| 157 | gint i; | |
| 158 | ||
| 159 | 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
|
160 | pidgin_dnd_hints_hide(i); |
| 10298 | 161 | } |
| 162 | ||
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
163 | void |
|
35500
ae6432ea326f
Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents:
35455
diff
changeset
|
164 | pidgin_dnd_hints_hide(PidginDndHintWindowId i) |
| 10298 | 165 | { |
| 166 | GtkWidget *w = hint_windows[i].widget; | |
| 167 | ||
| 168 | if (w && GTK_IS_WIDGET(w)) | |
| 169 | gtk_widget_hide(w); | |
| 170 | } | |
| 171 | ||
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
172 | void |
|
35500
ae6432ea326f
Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents:
35455
diff
changeset
|
173 | pidgin_dnd_hints_show(PidginDndHintWindowId id, gint x, gint y) |
| 10298 | 174 | { |
| 175 | GtkWidget *w; | |
| 176 | ||
| 177 | dnd_hints_init(); | |
| 178 | ||
| 179 | w = hint_windows[id].widget; | |
| 180 | ||
| 181 | if (w && GTK_IS_WIDGET(w)) | |
| 182 | { | |
| 183 | gtk_window_move(GTK_WINDOW(w), hint_windows[id].ox + x, | |
| 184 | hint_windows[id].oy + y); | |
| 185 | gtk_widget_show(w); | |
| 186 | } | |
| 187 | } | |
| 188 | ||
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
189 | void |
| 35501 | 190 | 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
|
191 | PidginDndHintPosition horiz, PidginDndHintPosition vert) |
| 10298 | 192 | { |
| 193 | gint x1, x2, y1, y2; | |
| 194 | gint x = 0, y = 0; | |
|
33133
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
195 | GtkAllocation allocation; |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
196 | |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
197 | gtk_widget_get_allocation(widget, &allocation); |
| 10298 | 198 | |
| 199 | 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
|
200 | x1 += allocation.x; x2 += allocation.x; |
|
9a31f084f259
Fix some merge errors.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
33132
diff
changeset
|
201 | y1 += allocation.y; y2 += allocation.y; |
| 10298 | 202 | |
| 203 | switch (horiz) | |
| 204 | { | |
| 205 | case HINT_POSITION_RIGHT: x = x2; break; | |
| 206 | case HINT_POSITION_LEFT: x = x1; break; | |
| 207 | case HINT_POSITION_CENTER: x = (x1 + x2) / 2; break; | |
| 208 | default: | |
| 209 | /* should not happen */ | |
| 35501 | 210 | g_warning("Invalid parameter to pidgin_dnd_hints_show_relative"); |
| 10298 | 211 | break; |
| 212 | } | |
| 213 | ||
| 214 | switch (vert) | |
| 215 | { | |
| 216 | case HINT_POSITION_TOP: y = y1; break; | |
| 217 | case HINT_POSITION_BOTTOM: y = y2; break; | |
| 218 | case HINT_POSITION_CENTER: y = (y1 + y2) / 2; break; | |
| 219 | default: | |
| 220 | /* should not happen */ | |
| 35501 | 221 | g_warning("Invalid parameter to pidgin_dnd_hints_show_relative"); |
| 10298 | 222 | break; |
| 223 | } | |
| 224 | ||
|
35500
ae6432ea326f
Fixed namespace issues in Pidgin.
Ankit Vani <a@nevitus.org>
parents:
35455
diff
changeset
|
225 | pidgin_dnd_hints_show(id, x, y); |
| 10298 | 226 | } |
| 227 |