Mercurial > pidgin
annotate src/dnd-hints.c @ 9608:204f5d66a863
[gaim-migrate @ 10451]
" I added two possible commands to gtk-remote: away and back.
away causes the away dialog to appear with the default
message and sets the status to away, back hides the
dialog and sets the status to online.
To implement this, I added to new CUI packet subtypes:
CUI_USER_AWAY and CUI_USER_BACK. This are processed in
core.c by calling do_away_message and do_im_back,
respectively." --Istv?n V?radi
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 28 Jul 2004 00:29:52 +0000 |
parents | 03be9d653123 |
children |
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_container_add(GTK_CONTAINER(win), pix); |
70 gtk_widget_shape_combine_mask(win, bitmap, 0, 0); | |
71 gtk_widget_pop_colormap(); | |
72 | |
4793 | 73 g_object_unref(G_OBJECT(pixmap)); |
74 g_object_unref(G_OBJECT(bitmap)); | |
4359 | 75 |
76 gtk_widget_show_all(pix); | |
77 | |
78 return win; | |
79 } | |
80 | |
81 static void | |
82 get_widget_coords(GtkWidget *w, gint *x1, gint *y1, gint *x2, gint *y2) | |
83 { | |
84 gint ox, oy, width, height; | |
85 | |
86 if (w->parent && w->parent->window == w->window) | |
87 { | |
88 get_widget_coords(w->parent, &ox, &oy, NULL, NULL); | |
89 ox += w->allocation.x; | |
90 oy += w->allocation.y; | |
91 height = w->allocation.height; | |
92 width = w->allocation.width; | |
93 } | |
94 else | |
95 { | |
96 gdk_window_get_origin(w->window, &ox, &oy); | |
4793 | 97 gdk_drawable_get_size(w->window, &width, &height); |
4359 | 98 } |
99 | |
100 if (x1) *x1 = ox; | |
101 if (y1) *y1 = oy; | |
102 if (x2) *x2 = ox + width; | |
103 if (y2) *y2 = oy + height; | |
104 } | |
105 | |
106 static void | |
107 dnd_hints_init(void) | |
108 { | |
109 static gboolean done = FALSE; | |
110 gint i; | |
111 | |
112 if (done) | |
113 return; | |
114 | |
115 done = TRUE; | |
116 | |
117 for (i = 0; hint_windows[i].filename != NULL; i++) { | |
118 gchar *fname; | |
119 | |
120 fname = g_build_filename(DATADIR, "pixmaps", "gaim", | |
121 hint_windows[i].filename, NULL); | |
122 | |
123 hint_windows[i].widget = dnd_hints_init_window(fname); | |
124 | |
125 g_free(fname); | |
126 } | |
127 } | |
128 | |
129 void | |
130 dnd_hints_hide_all(void) | |
131 { | |
132 gint i; | |
133 | |
134 for (i = 0; hint_windows[i].filename != NULL; i++) | |
135 dnd_hints_hide(i); | |
136 } | |
137 | |
138 void | |
139 dnd_hints_hide(DndHintWindowId i) | |
140 { | |
141 GtkWidget *w = hint_windows[i].widget; | |
142 | |
143 if (w && GTK_IS_WIDGET(w)) | |
144 gtk_widget_hide(w); | |
145 } | |
146 | |
147 void | |
148 dnd_hints_show(DndHintWindowId id, gint x, gint y) | |
149 { | |
150 GtkWidget *w; | |
151 | |
152 dnd_hints_init(); | |
153 | |
154 w = hint_windows[id].widget; | |
155 | |
156 if (w && GTK_IS_WIDGET(w)) | |
157 { | |
4635 | 158 gtk_window_move(GTK_WINDOW(w), hint_windows[id].ox + x, |
4359 | 159 hint_windows[id].oy + y); |
160 gtk_widget_show(w); | |
161 } | |
162 } | |
163 | |
164 void | |
165 dnd_hints_show_relative(DndHintWindowId id, GtkWidget *widget, | |
166 DndHintPosition horiz, DndHintPosition vert) | |
167 { | |
168 gint x1, x2, y1, y2; | |
169 gint x = 0, y = 0; | |
170 | |
171 get_widget_coords(widget, &x1, &y1, &x2, &y2); | |
172 | |
173 switch (horiz) | |
174 { | |
175 case HINT_POSITION_RIGHT: x = x2; break; | |
176 case HINT_POSITION_LEFT: x = x1; break; | |
177 case HINT_POSITION_CENTER: x = (x1 + x2) / 2; break; | |
178 default: | |
179 /* should not happen */ | |
180 g_warning("Invalid parameter to dnd_hints_show_relative"); | |
181 break; | |
182 } | |
183 | |
184 switch (vert) | |
185 { | |
186 case HINT_POSITION_TOP: y = y1; break; | |
187 case HINT_POSITION_BOTTOM: y = y2; break; | |
188 case HINT_POSITION_CENTER: y = (y1 + y2) / 2; break; | |
189 default: | |
190 /* should not happen */ | |
191 g_warning("Invalid parameter to dnd_hints_show_relative"); | |
192 break; | |
193 } | |
194 | |
195 dnd_hints_show(id, x, y); | |
196 } | |
197 |