Fri, 21 May 2004 14:33:32 +0000
[gaim-migrate @ 9774]
" This patch renames the existing received-*-msg signals
to receiving-*msg to fit the naming of other signals
where a pointer to the message is passed (writing,
sending, displaying)
It adds new received-*-msg signals which are emitted
after the receiving signals, in line with the other
conversation signals (wrote, sent, displayed)
This is necessary to allow plugins which depend on the
final received message to work alongside plugins which
may modify the message.
One known example of this is festival-gaim alongside
gaim-encryption - festival-gaim would try to "speak"
the encrypted text:
http://sf.net/tracker/?func=detail&aid=943216&group_id=89763&atid=591320
I've tested this with gaim-encryption and festival-gaim
(locally modified so gaim-encryption uses the receiving
signal and festival uses the received signal)
All in-tree users of received-*-msg are updated to use
receiving-*-msg if they do modify the message, the
conversation-signals documentation is updated, the
signals-test.c & signal-test.tcl plugins are also updated." --Stu Tomlinson
committer: Luke Schierer <lschiere@pidgin.im>
| 4359 | 1 | /* |
| 8046 | 2 | * Gaim is the legal property of its developers, whose names are too numerous |
| 3 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 4 | * source distribution. | |
| 4359 | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2, or(at your option) | |
| 9 | * any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 19 | */ | |
| 20 | ||
| 21 | #include "dnd-hints.h" | |
| 22 | ||
| 23 | #include <gtk/gtk.h> | |
| 24 | #include <gdk/gdk.h> | |
| 25 | #include <gdk-pixbuf/gdk-pixbuf.h> | |
| 26 | ||
|
4363
08b6dea58732
[gaim-migrate @ 4629]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
27 | #ifdef _WIN32 |
|
08b6dea58732
[gaim-migrate @ 4629]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
28 | #include "win32dep.h" |
|
08b6dea58732
[gaim-migrate @ 4629]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
29 | #endif |
|
08b6dea58732
[gaim-migrate @ 4629]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
30 | |
| 4359 | 31 | typedef struct |
| 32 | { | |
| 33 | GtkWidget *widget; | |
| 34 | gchar *filename; | |
| 35 | gint ox; | |
| 36 | gint oy; | |
| 37 | ||
| 38 | } HintWindowInfo; | |
| 39 | ||
| 40 | /** | |
| 41 | * Info about each hint widget. See DndHintWindowId enum. | |
| 42 | */ | |
| 43 | HintWindowInfo hint_windows[] = { | |
| 44 | { NULL, "tb_drag_arrow_up.xpm", -13/2, 0 }, | |
| 45 | { NULL, "tb_drag_arrow_down.xpm", -13/2, -16 }, | |
| 46 | { NULL, "tb_drag_arrow_left.xpm", 0, -13/2 }, | |
| 47 | { NULL, "tb_drag_arrow_right.xpm", -16, -13/2 }, | |
| 48 | { NULL, NULL, 0, 0 } | |
| 49 | }; | |
| 50 | ||
| 51 | static GtkWidget * | |
| 52 | dnd_hints_init_window(const gchar *fname) | |
| 53 | { | |
| 54 | GdkPixbuf *pixbuf; | |
| 55 | GdkPixmap *pixmap; | |
| 56 | GdkBitmap *bitmap; | |
| 57 | GtkWidget *pix; | |
| 58 | GtkWidget *win; | |
| 59 | ||
| 60 | pixbuf = gdk_pixbuf_new_from_file(fname, NULL); | |
| 61 | g_return_val_if_fail(pixbuf, NULL); | |
| 62 | ||
| 63 | gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &bitmap, 128); | |
| 4793 | 64 | g_object_unref(G_OBJECT(pixbuf)); |
| 4359 | 65 | |
| 4793 | 66 | gtk_widget_push_colormap(gdk_rgb_get_colormap()); |
| 4359 | 67 | win = gtk_window_new(GTK_WINDOW_POPUP); |
| 4635 | 68 | pix = gtk_image_new_from_pixmap(pixmap, bitmap); |
| 4359 | 69 | gtk_widget_realize(win); |
| 70 | gtk_container_add(GTK_CONTAINER(win), pix); | |
| 71 | gtk_widget_shape_combine_mask(win, bitmap, 0, 0); | |
| 72 | gtk_widget_pop_colormap(); | |
| 73 | ||
| 4793 | 74 | g_object_unref(G_OBJECT(pixmap)); |
| 75 | g_object_unref(G_OBJECT(bitmap)); | |
| 4359 | 76 | |
| 77 | gtk_widget_show_all(pix); | |
| 78 | ||
| 79 | return win; | |
| 80 | } | |
| 81 | ||
| 82 | static void | |
| 83 | get_widget_coords(GtkWidget *w, gint *x1, gint *y1, gint *x2, gint *y2) | |
| 84 | { | |
| 85 | gint ox, oy, width, height; | |
| 86 | ||
| 87 | if (w->parent && w->parent->window == w->window) | |
| 88 | { | |
| 89 | get_widget_coords(w->parent, &ox, &oy, NULL, NULL); | |
| 90 | ox += w->allocation.x; | |
| 91 | oy += w->allocation.y; | |
| 92 | height = w->allocation.height; | |
| 93 | width = w->allocation.width; | |
| 94 | } | |
| 95 | else | |
| 96 | { | |
| 97 | gdk_window_get_origin(w->window, &ox, &oy); | |
| 4793 | 98 | gdk_drawable_get_size(w->window, &width, &height); |
| 4359 | 99 | } |
| 100 | ||
| 101 | if (x1) *x1 = ox; | |
| 102 | if (y1) *y1 = oy; | |
| 103 | if (x2) *x2 = ox + width; | |
| 104 | if (y2) *y2 = oy + height; | |
| 105 | } | |
| 106 | ||
| 107 | static void | |
| 108 | dnd_hints_init(void) | |
| 109 | { | |
| 110 | static gboolean done = FALSE; | |
| 111 | gint i; | |
| 112 | ||
| 113 | if (done) | |
| 114 | return; | |
| 115 | ||
| 116 | done = TRUE; | |
| 117 | ||
| 118 | for (i = 0; hint_windows[i].filename != NULL; i++) { | |
| 119 | gchar *fname; | |
| 120 | ||
| 121 | fname = g_build_filename(DATADIR, "pixmaps", "gaim", | |
| 122 | hint_windows[i].filename, NULL); | |
| 123 | ||
| 124 | hint_windows[i].widget = dnd_hints_init_window(fname); | |
| 125 | ||
| 126 | g_free(fname); | |
| 127 | } | |
| 128 | } | |
| 129 | ||
| 130 | void | |
| 131 | dnd_hints_hide_all(void) | |
| 132 | { | |
| 133 | gint i; | |
| 134 | ||
| 135 | for (i = 0; hint_windows[i].filename != NULL; i++) | |
| 136 | dnd_hints_hide(i); | |
| 137 | } | |
| 138 | ||
| 139 | void | |
| 140 | dnd_hints_hide(DndHintWindowId i) | |
| 141 | { | |
| 142 | GtkWidget *w = hint_windows[i].widget; | |
| 143 | ||
| 144 | if (w && GTK_IS_WIDGET(w)) | |
| 145 | gtk_widget_hide(w); | |
| 146 | } | |
| 147 | ||
| 148 | void | |
| 149 | dnd_hints_show(DndHintWindowId id, gint x, gint y) | |
| 150 | { | |
| 151 | GtkWidget *w; | |
| 152 | ||
| 153 | dnd_hints_init(); | |
| 154 | ||
| 155 | w = hint_windows[id].widget; | |
| 156 | ||
| 157 | if (w && GTK_IS_WIDGET(w)) | |
| 158 | { | |
| 4635 | 159 | gtk_window_move(GTK_WINDOW(w), hint_windows[id].ox + x, |
| 4359 | 160 | hint_windows[id].oy + y); |
| 161 | gtk_widget_show(w); | |
| 162 | } | |
| 163 | } | |
| 164 | ||
| 165 | void | |
| 166 | dnd_hints_show_relative(DndHintWindowId id, GtkWidget *widget, | |
| 167 | DndHintPosition horiz, DndHintPosition vert) | |
| 168 | { | |
| 169 | gint x1, x2, y1, y2; | |
| 170 | gint x = 0, y = 0; | |
| 171 | ||
| 172 | get_widget_coords(widget, &x1, &y1, &x2, &y2); | |
| 173 | ||
| 174 | switch (horiz) | |
| 175 | { | |
| 176 | case HINT_POSITION_RIGHT: x = x2; break; | |
| 177 | case HINT_POSITION_LEFT: x = x1; break; | |
| 178 | case HINT_POSITION_CENTER: x = (x1 + x2) / 2; break; | |
| 179 | default: | |
| 180 | /* should not happen */ | |
| 181 | g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 182 | break; | |
| 183 | } | |
| 184 | ||
| 185 | switch (vert) | |
| 186 | { | |
| 187 | case HINT_POSITION_TOP: y = y1; break; | |
| 188 | case HINT_POSITION_BOTTOM: y = y2; break; | |
| 189 | case HINT_POSITION_CENTER: y = (y1 + y2) / 2; break; | |
| 190 | default: | |
| 191 | /* should not happen */ | |
| 192 | g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 193 | break; | |
| 194 | } | |
| 195 | ||
| 196 | dnd_hints_show(id, x, y); | |
| 197 | } | |
| 198 |