Mercurial > pidgin
annotate src/dnd-hints.c @ 8986:8cf32769ba1b
[gaim-migrate @ 9761]
" This patch adds a Plugin Actions menu item after the
Account Actions menu. The Plugin Actions menu is
populated from the added 'actions' slot in
GaimPluginInfo. As a demonstration, the Idle Maker
plugin has been converted to no longer require GTK code
and the Preferences interface just to perform its
actions. Instead, it uses a Plugin Action to spawn a
Fields Request.
There's also a minor fix for consistency in the menu
building for buddy actions. The pre-existing method for
instructing a menu list to display a separator was to
insert a NULL rather than a proto_buddy_menu into the
GList of actions. The code for the buddy menus was
instead checking for a proto_buddy_menu with a '-'
label. This has been fixed, and it now correctly uses
NULL to indicate a separator."
"Date: 2004-05-16 02:25
Sender: taliesein
Logged In: YES
user_id=77326
I need to add a callback to this patch to watch for
loading/unloading of plugins (to determine when to rebuild
the menu). Since the appropriate way to handle Plugin
Actions is still mildly up for debate, I'm holding of on
correcting the patch until I know for sure whether I should
fix this patch, or scrap it and write a new one using a
different method."
"Date: 2004-05-18 12:26
Sender: taliesein
Logged In: YES
user_id=77326
I've completed changes to this patch to also add plugin load
and unload signals (it looks like plugin.c actually had
pre-signal callbacks in place, but they were never used or
converted to signals)
This patch now will correctly update the Plugin Action menu
as plugins load and unload."
I'm not entirely sure i like the ui of a plugins actions menu, but i think
that having some way for plugins to add actions on an account is a good
thing, and i'm not sure that every viable action fits under the accounts
actions menu. we may want to merge the two (the existing accounts actions
and this plugins actions), but both times it came up in #gaim no one seemed
to want to comment, and on one commented to the gaim-devel post either.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 20 May 2004 05:11:44 +0000 |
parents | fa6395637e2c |
children | 03be9d653123 |
rev | line source |
---|---|
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
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); | |
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 |