Mercurial > pidgin
annotate src/dnd-hints.c @ 4469:d76095396a0e
[gaim-migrate @ 4744]
Phase 2 of the conversation rewrite! Did you think I was done?
Okay everybody, the prefs page was slightly redesigned. Not much, though.
It needs an overhaul, and still, not everything works.. What we have now
is:
Conversations
|
|- IMs
|- Chats
`- Tabs
But that's not the good part of this patch. Oh no, not close. You see, in
Conversations, we now have a "Placement" drop-down box. Though this prefs
page is ugly and will eventually be redesigned, this gives you the
opportunity to set one of a number of different types of conversation
placement options.
The defaults are:
- Last created window: Adds the new conversation to the last created
window, like how things have been lately.
- New window: Adds the new conversation to a brand new window, every
time. Tabs are still there, so you can drag them between windows if you
want to manually group them.
- By group: This is my new favorite. This will put the new conversation
in whatever window it finds first that has another member from that
same group on your buddy list. If it doesn't find one, it creates a new
window. If the person you IM'd or the person who IM'd you is not on your
list, it gets put in a window with other people not on your list.
These are the only ones implemented, but don't think you're limited to
that. You see, we have new API functions for registering these
Conversation Placement functions. All a plugin would need to do is to write
a function, take into account OPT_CONVO_COMBINE (oh yeah, "Show IMs and
chats in same tabbed window" works again), make sure the conversation is
added _somewhere_, and then just register that function. If the plugin is
loaded, the user can select it from the existing drop-down box.
Cool, huh? Make sure to unregister the function when the plugin is
unloaded.
Have fun.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Thu, 30 Jan 2003 09:22:15 +0000 |
| parents | 65d98b565fbe |
| children | 42d53c416bb9 |
| rev | line source |
|---|---|
| 4359 | 1 /* |
| 2 * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org> | |
| 3 * | |
| 4 * Copyright (C) 2001 Ricardo Fernández Pascual | |
| 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
65d98b565fbe
[gaim-migrate @ 4629]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
27 #ifdef _WIN32 |
|
65d98b565fbe
[gaim-migrate @ 4629]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
28 #include "win32dep.h" |
|
65d98b565fbe
[gaim-migrate @ 4629]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
29 #endif |
|
65d98b565fbe
[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); | |
| 64 gdk_pixbuf_unref(pixbuf); | |
| 65 | |
| 66 gtk_widget_push_visual(gdk_rgb_get_visual()); | |
| 67 gtk_widget_push_colormap(gdk_rgb_get_cmap()); | |
| 68 win = gtk_window_new(GTK_WINDOW_POPUP); | |
| 69 pix = gtk_pixmap_new(pixmap, bitmap); | |
| 70 gtk_widget_realize(win); | |
| 71 gtk_container_add(GTK_CONTAINER(win), pix); | |
| 72 gtk_widget_shape_combine_mask(win, bitmap, 0, 0); | |
| 73 gtk_widget_pop_visual(); | |
| 74 gtk_widget_pop_colormap(); | |
| 75 | |
| 76 gdk_pixmap_unref(pixmap); | |
| 77 gdk_bitmap_unref(bitmap); | |
| 78 | |
| 79 gtk_widget_show_all(pix); | |
| 80 | |
| 81 return win; | |
| 82 } | |
| 83 | |
| 84 static void | |
| 85 get_widget_coords(GtkWidget *w, gint *x1, gint *y1, gint *x2, gint *y2) | |
| 86 { | |
| 87 gint ox, oy, width, height; | |
| 88 | |
| 89 if (w->parent && w->parent->window == w->window) | |
| 90 { | |
| 91 get_widget_coords(w->parent, &ox, &oy, NULL, NULL); | |
| 92 ox += w->allocation.x; | |
| 93 oy += w->allocation.y; | |
| 94 height = w->allocation.height; | |
| 95 width = w->allocation.width; | |
| 96 } | |
| 97 else | |
| 98 { | |
| 99 gdk_window_get_origin(w->window, &ox, &oy); | |
| 100 gdk_window_get_size(w->window, &width, &height); | |
| 101 } | |
| 102 | |
| 103 if (x1) *x1 = ox; | |
| 104 if (y1) *y1 = oy; | |
| 105 if (x2) *x2 = ox + width; | |
| 106 if (y2) *y2 = oy + height; | |
| 107 } | |
| 108 | |
| 109 static void | |
| 110 dnd_hints_init(void) | |
| 111 { | |
| 112 static gboolean done = FALSE; | |
| 113 gint i; | |
| 114 | |
| 115 if (done) | |
| 116 return; | |
| 117 | |
| 118 done = TRUE; | |
| 119 | |
| 120 for (i = 0; hint_windows[i].filename != NULL; i++) { | |
| 121 gchar *fname; | |
| 122 | |
| 123 fname = g_build_filename(DATADIR, "pixmaps", "gaim", | |
| 124 hint_windows[i].filename, NULL); | |
| 125 | |
| 126 hint_windows[i].widget = dnd_hints_init_window(fname); | |
| 127 | |
| 128 g_free(fname); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 void | |
| 133 dnd_hints_hide_all(void) | |
| 134 { | |
| 135 gint i; | |
| 136 | |
| 137 for (i = 0; hint_windows[i].filename != NULL; i++) | |
| 138 dnd_hints_hide(i); | |
| 139 } | |
| 140 | |
| 141 void | |
| 142 dnd_hints_hide(DndHintWindowId i) | |
| 143 { | |
| 144 GtkWidget *w = hint_windows[i].widget; | |
| 145 | |
| 146 if (w && GTK_IS_WIDGET(w)) | |
| 147 gtk_widget_hide(w); | |
| 148 } | |
| 149 | |
| 150 void | |
| 151 dnd_hints_show(DndHintWindowId id, gint x, gint y) | |
| 152 { | |
| 153 GtkWidget *w; | |
| 154 | |
| 155 dnd_hints_init(); | |
| 156 | |
| 157 w = hint_windows[id].widget; | |
| 158 | |
| 159 if (w && GTK_IS_WIDGET(w)) | |
| 160 { | |
| 161 gtk_widget_set_uposition(w, hint_windows[id].ox + x, | |
| 162 hint_windows[id].oy + y); | |
| 163 gtk_widget_show(w); | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 void | |
| 168 dnd_hints_show_relative(DndHintWindowId id, GtkWidget *widget, | |
| 169 DndHintPosition horiz, DndHintPosition vert) | |
| 170 { | |
| 171 gint x1, x2, y1, y2; | |
| 172 gint x = 0, y = 0; | |
| 173 | |
| 174 get_widget_coords(widget, &x1, &y1, &x2, &y2); | |
| 175 | |
| 176 switch (horiz) | |
| 177 { | |
| 178 case HINT_POSITION_RIGHT: x = x2; break; | |
| 179 case HINT_POSITION_LEFT: x = x1; break; | |
| 180 case HINT_POSITION_CENTER: x = (x1 + x2) / 2; break; | |
| 181 default: | |
| 182 /* should not happen */ | |
| 183 g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 184 break; | |
| 185 } | |
| 186 | |
| 187 switch (vert) | |
| 188 { | |
| 189 case HINT_POSITION_TOP: y = y1; break; | |
| 190 case HINT_POSITION_BOTTOM: y = y2; break; | |
| 191 case HINT_POSITION_CENTER: y = (y1 + y2) / 2; break; | |
| 192 default: | |
| 193 /* should not happen */ | |
| 194 g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 195 break; | |
| 196 } | |
| 197 | |
| 198 dnd_hints_show(id, x, y); | |
| 199 } | |
| 200 |
