Fri, 03 Dec 2010 23:03:58 +0000
updates to work with the latest GTK+
| 10298 | 1 | /* |
| 2 | * @file gtkdnd-hints.c GTK+ Drag-and-Drop arrow hints | |
|
16254
eeb2bba4dc94
Rename the Doxygen group from gtkui to pidgin.
Richard Laager <rlaager@pidgin.im>
parents:
15946
diff
changeset
|
3 | * @ingroup pidgin |
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
4 | */ |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
5 | |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
6 | /* pidgin |
| 10298 | 7 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
8 | * Pidgin is the legal property of its developers, whose names are too numerous |
| 10298 | 9 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 10 | * source distribution. | |
| 11 | * | |
| 12 | * This program is free software; you can redistribute it and/or modify | |
| 13 | * it under the terms of the GNU General Public License as published by | |
| 14 | * the Free Software Foundation; either version 2, or(at your option) | |
| 15 | * any later version. | |
| 16 | * | |
| 17 | * This program is distributed in the hope that it will be useful, | |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | * GNU General Public License for more details. | |
| 21 | * | |
| 22 | * You should have received a copy of the GNU General Public License | |
| 23 | * 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
|
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA. |
| 10298 | 25 | */ |
| 26 | ||
| 27 | #include "gtkdnd-hints.h" | |
| 28 | ||
| 29 | #include <gtk/gtk.h> | |
| 30 | #include <gdk/gdk.h> | |
| 31 | #include <gdk-pixbuf/gdk-pixbuf.h> | |
| 32 | ||
| 33 | #ifdef _WIN32 | |
| 34 | #include "win32dep.h" | |
| 35 | #endif | |
| 36 | ||
| 37 | typedef struct | |
| 38 | { | |
| 39 | GtkWidget *widget; | |
| 40 | gchar *filename; | |
| 41 | gint ox; | |
| 42 | gint oy; | |
| 43 | ||
| 44 | } HintWindowInfo; | |
| 45 | ||
| 46 | /** | |
| 47 | * Info about each hint widget. See DndHintWindowId enum. | |
| 48 | */ | |
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
49 | static HintWindowInfo hint_windows[] = { |
|
16274
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
50 | { NULL, "arrow-up.xpm", -13/2, 0 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
51 | { NULL, "arrow-down.xpm", -13/2, -16 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
52 | { NULL, "arrow-left.xpm", 0, -13/2 }, |
|
7d61ad2c489a
Some icon improvements from hbons
Sean Egan <seanegan@pidgin.im>
parents:
16254
diff
changeset
|
53 | { NULL, "arrow-right.xpm", -16, -13/2 }, |
| 10298 | 54 | { NULL, NULL, 0, 0 } |
| 55 | }; | |
| 56 | ||
| 57 | static GtkWidget * | |
| 58 | dnd_hints_init_window(const gchar *fname) | |
| 59 | { | |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
60 | /* TODO: this is likely very broken right now, I think this needs to be |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
61 | Cairo-ified */ |
| 10298 | 62 | GdkPixbuf *pixbuf; |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
63 | /*GdkPixmap *pixmap;*/ |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
64 | /*GdkBitmap *bitmap;*/ |
| 10298 | 65 | GtkWidget *pix; |
| 66 | GtkWidget *win; | |
| 67 | ||
| 68 | pixbuf = gdk_pixbuf_new_from_file(fname, NULL); | |
| 69 | g_return_val_if_fail(pixbuf, NULL); | |
| 70 | ||
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
71 | /* |
| 10298 | 72 | gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &bitmap, 128); |
| 73 | g_object_unref(G_OBJECT(pixbuf)); | |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
74 | */ |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
75 | |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
76 | /*gtk_widget_push_colormap(gdk_rgb_get_colormap());*/ |
| 10298 | 77 | win = gtk_window_new(GTK_WINDOW_POPUP); |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
78 | pix = gtk_image_new_from_pixbuf(pixbuf); |
| 10298 | 79 | gtk_container_add(GTK_CONTAINER(win), pix); |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
80 | /*gtk_widget_shape_combine_mask(win, bitmap, 0, 0); |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
81 | gtk_widget_pop_colormap();*/ |
| 10298 | 82 | |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
83 | /* |
| 10298 | 84 | g_object_unref(G_OBJECT(pixmap)); |
| 85 | g_object_unref(G_OBJECT(bitmap)); | |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
86 | */ |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
87 | |
| 10298 | 88 | gtk_widget_show_all(pix); |
| 89 | ||
| 90 | return win; | |
| 91 | } | |
| 92 | ||
| 93 | static void | |
| 94 | get_widget_coords(GtkWidget *w, gint *x1, gint *y1, gint *x2, gint *y2) | |
| 95 | { | |
| 96 | gint ox, oy, width, height; | |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
97 | GtkWidget *parent = gtk_widget_get_parent(w); |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
98 | |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
99 | if (parent && gtk_widget_get_window(parent) == gtk_widget_get_window(w)) |
| 10298 | 100 | { |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
101 | GtkAllocation allocation; |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
102 | |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
103 | gtk_widget_get_allocation(w, &allocation); |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
104 | get_widget_coords(parent, &ox, &oy, NULL, NULL); |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
105 | height = allocation.height; |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
106 | width = allocation.width; |
| 10298 | 107 | } |
| 108 | else | |
| 109 | { | |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
110 | gdk_window_get_origin(gtk_widget_get_window(w), &ox, &oy); |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
111 | width = gdk_window_get_width(gtk_widget_get_window(w)); |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
112 | height = gdk_window_get_height(gtk_widget_get_window(w)); |
| 10298 | 113 | } |
| 114 | ||
| 115 | if (x1) *x1 = ox; | |
| 116 | if (y1) *y1 = oy; | |
| 117 | if (x2) *x2 = ox + width; | |
| 118 | if (y2) *y2 = oy + height; | |
| 119 | } | |
| 120 | ||
| 121 | static void | |
| 122 | dnd_hints_init(void) | |
| 123 | { | |
| 124 | static gboolean done = FALSE; | |
| 125 | gint i; | |
| 126 | ||
| 127 | if (done) | |
| 128 | return; | |
| 129 | ||
| 130 | done = TRUE; | |
| 131 | ||
| 132 | for (i = 0; hint_windows[i].filename != NULL; i++) { | |
| 133 | gchar *fname; | |
| 134 | ||
|
15946
d40e8847e825
More s/gaim/pidgin/ and s/gaim/purple/ and make the RPM spec file work a bit
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15931
diff
changeset
|
135 | fname = g_build_filename(DATADIR, "pixmaps", "pidgin", |
| 10298 | 136 | hint_windows[i].filename, NULL); |
| 137 | ||
| 138 | hint_windows[i].widget = dnd_hints_init_window(fname); | |
| 139 | ||
| 140 | g_free(fname); | |
| 141 | } | |
| 142 | } | |
| 143 | ||
| 144 | void | |
| 145 | dnd_hints_hide_all(void) | |
| 146 | { | |
| 147 | gint i; | |
| 148 | ||
| 149 | for (i = 0; hint_windows[i].filename != NULL; i++) | |
| 150 | dnd_hints_hide(i); | |
| 151 | } | |
| 152 | ||
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
153 | void |
| 10298 | 154 | dnd_hints_hide(DndHintWindowId i) |
| 155 | { | |
| 156 | GtkWidget *w = hint_windows[i].widget; | |
| 157 | ||
| 158 | if (w && GTK_IS_WIDGET(w)) | |
| 159 | gtk_widget_hide(w); | |
| 160 | } | |
| 161 | ||
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
162 | void |
| 10298 | 163 | dnd_hints_show(DndHintWindowId id, gint x, gint y) |
| 164 | { | |
| 165 | GtkWidget *w; | |
| 166 | ||
| 167 | dnd_hints_init(); | |
| 168 | ||
| 169 | w = hint_windows[id].widget; | |
| 170 | ||
| 171 | if (w && GTK_IS_WIDGET(w)) | |
| 172 | { | |
| 173 | gtk_window_move(GTK_WINDOW(w), hint_windows[id].ox + x, | |
| 174 | hint_windows[id].oy + y); | |
| 175 | gtk_widget_show(w); | |
| 176 | } | |
| 177 | } | |
| 178 | ||
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
20147
diff
changeset
|
179 | void |
| 10298 | 180 | dnd_hints_show_relative(DndHintWindowId id, GtkWidget *widget, |
| 181 | DndHintPosition horiz, DndHintPosition vert) | |
| 182 | { | |
| 183 | gint x1, x2, y1, y2; | |
| 184 | gint x = 0, y = 0; | |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
185 | GtkAllocation allocation; |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
186 | |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
187 | gtk_widget_get_allocation(widget, &allocation); |
| 10298 | 188 | |
| 189 | get_widget_coords(widget, &x1, &y1, &x2, &y2); | |
|
32394
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
190 | x1 += allocation.x; x2 += allocation.x; |
|
f883709bdba4
compiles using GTK+ 3 from git, beware it does not yet run, in fact it crashes...
Marcus Lundblad <malu@pidgin.im>
parents:
25888
diff
changeset
|
191 | y1 += allocation.y; y2 += allocation.y; |
| 10298 | 192 | |
| 193 | switch (horiz) | |
| 194 | { | |
| 195 | case HINT_POSITION_RIGHT: x = x2; break; | |
| 196 | case HINT_POSITION_LEFT: x = x1; break; | |
| 197 | case HINT_POSITION_CENTER: x = (x1 + x2) / 2; break; | |
| 198 | default: | |
| 199 | /* should not happen */ | |
| 200 | g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 201 | break; | |
| 202 | } | |
| 203 | ||
| 204 | switch (vert) | |
| 205 | { | |
| 206 | case HINT_POSITION_TOP: y = y1; break; | |
| 207 | case HINT_POSITION_BOTTOM: y = y2; break; | |
| 208 | case HINT_POSITION_CENTER: y = (y1 + y2) / 2; break; | |
| 209 | default: | |
| 210 | /* should not happen */ | |
| 211 | g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 212 | break; | |
| 213 | } | |
| 214 | ||
| 215 | dnd_hints_show(id, x, y); | |
| 216 | } | |
| 217 |