Mon, 10 Oct 2005 17:59:48 +0000
[gaim-migrate @ 13914]
Some bits'n'pieces:
A bunch of memory leak fixes
Fix newly created accounts to connect in the currently active global
status
Fix the modify account dialog to only show relevant user options etc.
Update sametime to use some more of the new status stuff, it still
needs more love though.
Some s/online/available/ for consistency across prpls
Fix a racyness in disconnecting connections that want to die (fixes
the Yahoo crash when signing on somewhere else)
Sorry if I caused any conflicts!
| 10298 | 1 | /* |
| 2 | * @file gtkdnd-hints.c GTK+ Drag-and-Drop arrow hints | |
| 3 | * @ingroup gtkui | |
| 4 | * | |
| 5 | * gaim | |
| 6 | * | |
| 7 | * Gaim is the legal property of its developers, whose names are too numerous | |
| 8 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 9 | * source distribution. | |
| 10 | * | |
| 11 | * This program is free software; you can redistribute it and/or modify | |
| 12 | * it under the terms of the GNU General Public License as published by | |
| 13 | * the Free Software Foundation; either version 2, or(at your option) | |
| 14 | * any later version. | |
| 15 | * | |
| 16 | * This program is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with this program; if not, write to the Free Software | |
| 23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 24 | */ | |
| 25 | ||
| 26 | #include "gtkdnd-hints.h" | |
| 27 | ||
| 28 | #include <gtk/gtk.h> | |
| 29 | #include <gdk/gdk.h> | |
| 30 | #include <gdk-pixbuf/gdk-pixbuf.h> | |
| 31 | ||
| 32 | #ifdef _WIN32 | |
| 33 | #include "win32dep.h" | |
| 34 | #endif | |
| 35 | ||
| 36 | typedef struct | |
| 37 | { | |
| 38 | GtkWidget *widget; | |
| 39 | gchar *filename; | |
| 40 | gint ox; | |
| 41 | gint oy; | |
| 42 | ||
| 43 | } HintWindowInfo; | |
| 44 | ||
| 45 | /** | |
| 46 | * Info about each hint widget. See DndHintWindowId enum. | |
| 47 | */ | |
|
10871
c0282a4f2250
[gaim-migrate @ 12558]
Mark Doliner <markdoliner@pidgin.im>
parents:
10298
diff
changeset
|
48 | static HintWindowInfo hint_windows[] = { |
| 10298 | 49 | { NULL, "tb_drag_arrow_up.xpm", -13/2, 0 }, |
| 50 | { NULL, "tb_drag_arrow_down.xpm", -13/2, -16 }, | |
| 51 | { NULL, "tb_drag_arrow_left.xpm", 0, -13/2 }, | |
| 52 | { NULL, "tb_drag_arrow_right.xpm", -16, -13/2 }, | |
| 53 | { NULL, NULL, 0, 0 } | |
| 54 | }; | |
| 55 | ||
| 56 | static GtkWidget * | |
| 57 | dnd_hints_init_window(const gchar *fname) | |
| 58 | { | |
| 59 | GdkPixbuf *pixbuf; | |
| 60 | GdkPixmap *pixmap; | |
| 61 | GdkBitmap *bitmap; | |
| 62 | GtkWidget *pix; | |
| 63 | GtkWidget *win; | |
| 64 | ||
| 65 | pixbuf = gdk_pixbuf_new_from_file(fname, NULL); | |
| 66 | g_return_val_if_fail(pixbuf, NULL); | |
| 67 | ||
| 68 | gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &bitmap, 128); | |
| 69 | g_object_unref(G_OBJECT(pixbuf)); | |
| 70 | ||
| 71 | gtk_widget_push_colormap(gdk_rgb_get_colormap()); | |
| 72 | win = gtk_window_new(GTK_WINDOW_POPUP); | |
| 73 | pix = gtk_image_new_from_pixmap(pixmap, bitmap); | |
| 74 | gtk_container_add(GTK_CONTAINER(win), pix); | |
| 75 | gtk_widget_shape_combine_mask(win, bitmap, 0, 0); | |
| 76 | gtk_widget_pop_colormap(); | |
| 77 | ||
| 78 | g_object_unref(G_OBJECT(pixmap)); | |
| 79 | g_object_unref(G_OBJECT(bitmap)); | |
| 80 | ||
| 81 | gtk_widget_show_all(pix); | |
| 82 | ||
| 83 | return win; | |
| 84 | } | |
| 85 | ||
| 86 | static void | |
| 87 | get_widget_coords(GtkWidget *w, gint *x1, gint *y1, gint *x2, gint *y2) | |
| 88 | { | |
| 89 | gint ox, oy, width, height; | |
| 90 | ||
| 91 | if (w->parent && w->parent->window == w->window) | |
| 92 | { | |
| 93 | get_widget_coords(w->parent, &ox, &oy, NULL, NULL); | |
| 94 | ox += w->allocation.x; | |
| 95 | oy += w->allocation.y; | |
| 96 | height = w->allocation.height; | |
| 97 | width = w->allocation.width; | |
| 98 | } | |
| 99 | else | |
| 100 | { | |
| 101 | gdk_window_get_origin(w->window, &ox, &oy); | |
| 102 | gdk_drawable_get_size(w->window, &width, &height); | |
| 103 | } | |
| 104 | ||
| 105 | if (x1) *x1 = ox; | |
| 106 | if (y1) *y1 = oy; | |
| 107 | if (x2) *x2 = ox + width; | |
| 108 | if (y2) *y2 = oy + height; | |
| 109 | } | |
| 110 | ||
| 111 | static void | |
| 112 | dnd_hints_init(void) | |
| 113 | { | |
| 114 | static gboolean done = FALSE; | |
| 115 | gint i; | |
| 116 | ||
| 117 | if (done) | |
| 118 | return; | |
| 119 | ||
| 120 | done = TRUE; | |
| 121 | ||
| 122 | for (i = 0; hint_windows[i].filename != NULL; i++) { | |
| 123 | gchar *fname; | |
| 124 | ||
| 125 | fname = g_build_filename(DATADIR, "pixmaps", "gaim", | |
| 126 | hint_windows[i].filename, NULL); | |
| 127 | ||
| 128 | hint_windows[i].widget = dnd_hints_init_window(fname); | |
| 129 | ||
| 130 | g_free(fname); | |
| 131 | } | |
| 132 | } | |
| 133 | ||
| 134 | void | |
| 135 | dnd_hints_hide_all(void) | |
| 136 | { | |
| 137 | gint i; | |
| 138 | ||
| 139 | for (i = 0; hint_windows[i].filename != NULL; i++) | |
| 140 | dnd_hints_hide(i); | |
| 141 | } | |
| 142 | ||
| 143 | void | |
| 144 | dnd_hints_hide(DndHintWindowId i) | |
| 145 | { | |
| 146 | GtkWidget *w = hint_windows[i].widget; | |
| 147 | ||
| 148 | if (w && GTK_IS_WIDGET(w)) | |
| 149 | gtk_widget_hide(w); | |
| 150 | } | |
| 151 | ||
| 152 | void | |
| 153 | dnd_hints_show(DndHintWindowId id, gint x, gint y) | |
| 154 | { | |
| 155 | GtkWidget *w; | |
| 156 | ||
| 157 | dnd_hints_init(); | |
| 158 | ||
| 159 | w = hint_windows[id].widget; | |
| 160 | ||
| 161 | if (w && GTK_IS_WIDGET(w)) | |
| 162 | { | |
| 163 | gtk_window_move(GTK_WINDOW(w), hint_windows[id].ox + x, | |
| 164 | hint_windows[id].oy + y); | |
| 165 | gtk_widget_show(w); | |
| 166 | } | |
| 167 | } | |
| 168 | ||
| 169 | void | |
| 170 | dnd_hints_show_relative(DndHintWindowId id, GtkWidget *widget, | |
| 171 | DndHintPosition horiz, DndHintPosition vert) | |
| 172 | { | |
| 173 | gint x1, x2, y1, y2; | |
| 174 | gint x = 0, y = 0; | |
| 175 | ||
| 176 | get_widget_coords(widget, &x1, &y1, &x2, &y2); | |
| 177 | ||
| 178 | switch (horiz) | |
| 179 | { | |
| 180 | case HINT_POSITION_RIGHT: x = x2; break; | |
| 181 | case HINT_POSITION_LEFT: x = x1; break; | |
| 182 | case HINT_POSITION_CENTER: x = (x1 + x2) / 2; break; | |
| 183 | default: | |
| 184 | /* should not happen */ | |
| 185 | g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 186 | break; | |
| 187 | } | |
| 188 | ||
| 189 | switch (vert) | |
| 190 | { | |
| 191 | case HINT_POSITION_TOP: y = y1; break; | |
| 192 | case HINT_POSITION_BOTTOM: y = y2; break; | |
| 193 | case HINT_POSITION_CENTER: y = (y1 + y2) / 2; break; | |
| 194 | default: | |
| 195 | /* should not happen */ | |
| 196 | g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 197 | break; | |
| 198 | } | |
| 199 | ||
| 200 | dnd_hints_show(id, x, y); | |
| 201 | } | |
| 202 |