1 | #include "gtk/gtk.h" |
---|
2 | |
---|
3 | /* Target side drag signals */ |
---|
4 | |
---|
5 | /* XPM */ |
---|
6 | static char * drag_icon_xpm[] = { |
---|
7 | "36 48 9 1", |
---|
8 | " c None", |
---|
9 | ". c #020204", |
---|
10 | "+ c #8F8F90", |
---|
11 | "@ c #D3D3D2", |
---|
12 | "# c #AEAEAC", |
---|
13 | "$ c #ECECEC", |
---|
14 | "% c #A2A2A4", |
---|
15 | "& c #FEFEFC", |
---|
16 | "* c #BEBEBC", |
---|
17 | " .....................", |
---|
18 | " ..&&&&&&&&&&&&&&&&&&&.", |
---|
19 | " ...&&&&&&&&&&&&&&&&&&&.", |
---|
20 | " ..&.&&&&&&&&&&&&&&&&&&&.", |
---|
21 | " ..&&.&&&&&&&&&&&&&&&&&&&.", |
---|
22 | " ..&&&.&&&&&&&&&&&&&&&&&&&.", |
---|
23 | " ..&&&&.&&&&&&&&&&&&&&&&&&&.", |
---|
24 | " ..&&&&&.&&&@&&&&&&&&&&&&&&&.", |
---|
25 | " ..&&&&&&.*$%$+$&&&&&&&&&&&&&.", |
---|
26 | " ..&&&&&&&.%$%$+&&&&&&&&&&&&&&.", |
---|
27 | " ..&&&&&&&&.#&#@$&&&&&&&&&&&&&&.", |
---|
28 | " ..&&&&&&&&&.#$**#$&&&&&&&&&&&&&.", |
---|
29 | " ..&&&&&&&&&&.&@%&%$&&&&&&&&&&&&&.", |
---|
30 | " ..&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.", |
---|
31 | " ..&&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.", |
---|
32 | "................&$@&&&@&&&&&&&&&&&&.", |
---|
33 | ".&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&&&&&.", |
---|
34 | ".&&&&&&&+&&#@#@&&@*%$%$+&&&&&&&&&&&.", |
---|
35 | ".&&&&&&&+&$%&#@&#@@#&#@$&&&&&&&&&&&.", |
---|
36 | ".&&&&&&@#@@$&*@&@#@#$**#$&&&&&&&&&&.", |
---|
37 | ".&&&&&&&&&&&&&&&&&&&@%&%$&&&&&&&&&&.", |
---|
38 | ".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.", |
---|
39 | ".&&&&&&&&$#@@$&&&&&&&&&&&&&&&&&&&&&.", |
---|
40 | ".&&&&&&&&&+&$+&$&@&$@&&$@&&&&&&&&&&.", |
---|
41 | ".&&&&&&&&&+&&#@%#+@#@*$%&+$&&&&&&&&.", |
---|
42 | ".&&&&&&&&&+&&#@#@&&@*%$%$+&&&&&&&&&.", |
---|
43 | ".&&&&&&&&&+&$%&#@&#@@#&#@$&&&&&&&&&.", |
---|
44 | ".&&&&&&&&@#@@$&*@&@#@#$#*#$&&&&&&&&.", |
---|
45 | ".&&&&&&&&&&&&&&&&&&&&&$%&%$&&&&&&&&.", |
---|
46 | ".&&&&&&&&&&$#@@$&&&&&&&&&&&&&&&&&&&.", |
---|
47 | ".&&&&&&&&&&&+&$%&$$@&$@&&$@&&&&&&&&.", |
---|
48 | ".&&&&&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&.", |
---|
49 | ".&&&&&&&&&&&+&&#@#@&&@*#$%$+&&&&&&&.", |
---|
50 | ".&&&&&&&&&&&+&$+&*@&#@@#&#@$&&&&&&&.", |
---|
51 | ".&&&&&&&&&&$%@@&&*@&@#@#$#*#&&&&&&&.", |
---|
52 | ".&&&&&&&&&&&&&&&&&&&&&&&$%&%$&&&&&&.", |
---|
53 | ".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.", |
---|
54 | ".&&&&&&&&&&&&&&$#@@$&&&&&&&&&&&&&&&.", |
---|
55 | ".&&&&&&&&&&&&&&&+&$%&$$@&$@&&$@&&&&.", |
---|
56 | ".&&&&&&&&&&&&&&&+&&#@%#+@#@*$%$+$&&.", |
---|
57 | ".&&&&&&&&&&&&&&&+&&#@#@&&@*#$%$+&&&.", |
---|
58 | ".&&&&&&&&&&&&&&&+&$+&*@&#@@#&#@$&&&.", |
---|
59 | ".&&&&&&&&&&&&&&$%@@&&*@&@#@#$#*#&&&.", |
---|
60 | ".&&&&&&&&&&&&&&&&&&&&&&&&&&&$%&%$&&.", |
---|
61 | ".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.", |
---|
62 | ".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.", |
---|
63 | ".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.", |
---|
64 | "...................................."}; |
---|
65 | |
---|
66 | /* XPM */ |
---|
67 | static char * trashcan_closed_xpm[] = { |
---|
68 | "64 80 17 1", |
---|
69 | " c None", |
---|
70 | ". c #030304", |
---|
71 | "+ c #5A5A5C", |
---|
72 | "@ c #323231", |
---|
73 | "# c #888888", |
---|
74 | "$ c #1E1E1F", |
---|
75 | "% c #767677", |
---|
76 | "& c #494949", |
---|
77 | "* c #9E9E9C", |
---|
78 | "= c #111111", |
---|
79 | "- c #3C3C3D", |
---|
80 | "; c #6B6B6B", |
---|
81 | "> c #949494", |
---|
82 | ", c #282828", |
---|
83 | "' c #808080", |
---|
84 | ") c #545454", |
---|
85 | "! c #AEAEAC", |
---|
86 | " ", |
---|
87 | " ", |
---|
88 | " ", |
---|
89 | " ", |
---|
90 | " ", |
---|
91 | " ", |
---|
92 | " ", |
---|
93 | " ", |
---|
94 | " ", |
---|
95 | " ", |
---|
96 | " ", |
---|
97 | " ", |
---|
98 | " ", |
---|
99 | " ", |
---|
100 | " ", |
---|
101 | " ", |
---|
102 | " ", |
---|
103 | " ", |
---|
104 | " ", |
---|
105 | " ", |
---|
106 | " ", |
---|
107 | " ", |
---|
108 | " ==......=$$...=== ", |
---|
109 | " ..$------)+++++++++++++@$$... ", |
---|
110 | " ..=@@-------&+++++++++++++++++++-.... ", |
---|
111 | " =.$$@@@-&&)++++)-,$$$$=@@&+++++++++++++,..$ ", |
---|
112 | " .$$$$@@&+++++++&$$$@@@@-&,$,-++++++++++;;;&.. ", |
---|
113 | " $$$$,@--&++++++&$$)++++++++-,$&++++++;%%'%%;;$@ ", |
---|
114 | " .-@@-@-&++++++++-@++++++++++++,-++++++;''%;;;%*-$ ", |
---|
115 | " +------++++++++++++++++++++++++++++++;;%%%;;##*!. ", |
---|
116 | " =+----+++++++++++++++++++++++;;;;;;;;;;;;%'>>). ", |
---|
117 | " .=)&+++++++++++++++++;;;;;;;;;;;;;;%''>>#>#@. ", |
---|
118 | " =..=&++++++++++++;;;;;;;;;;;;;%###>>###+%== ", |
---|
119 | " .&....=-+++++%;;####''''''''''##'%%%)..#. ", |
---|
120 | " .+-++@....=,+%#####'%%%%%%%%%;@$-@-@*++!. ", |
---|
121 | " .+-++-+++-&-@$$=$=......$,,,@;&)+!++!++!. ", |
---|
122 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
123 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
124 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
125 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
126 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
127 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
128 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
129 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
130 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
131 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
132 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
133 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
134 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
135 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
136 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
137 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
138 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
139 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
140 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
141 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
142 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
143 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
144 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
145 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
146 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
147 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
148 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
149 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
150 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
151 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
152 | " =+-++-+++-+++++++++!++++!++++!+++!++!+++= ", |
---|
153 | " $.++-+++-+++++++++!++++!++++!+++!++!+.$ ", |
---|
154 | " =.++++++++++++++!++++!++++!+++!++.= ", |
---|
155 | " $..+++++++++++++++!++++++...$ ", |
---|
156 | " $$=.............=$$ ", |
---|
157 | " ", |
---|
158 | " ", |
---|
159 | " ", |
---|
160 | " ", |
---|
161 | " ", |
---|
162 | " ", |
---|
163 | " ", |
---|
164 | " ", |
---|
165 | " "}; |
---|
166 | |
---|
167 | /* XPM */ |
---|
168 | static char * trashcan_open_xpm[] = { |
---|
169 | "64 80 17 1", |
---|
170 | " c None", |
---|
171 | ". c #030304", |
---|
172 | "+ c #5A5A5C", |
---|
173 | "@ c #323231", |
---|
174 | "# c #888888", |
---|
175 | "$ c #1E1E1F", |
---|
176 | "% c #767677", |
---|
177 | "& c #494949", |
---|
178 | "* c #9E9E9C", |
---|
179 | "= c #111111", |
---|
180 | "- c #3C3C3D", |
---|
181 | "; c #6B6B6B", |
---|
182 | "> c #949494", |
---|
183 | ", c #282828", |
---|
184 | "' c #808080", |
---|
185 | ") c #545454", |
---|
186 | "! c #AEAEAC", |
---|
187 | " ", |
---|
188 | " ", |
---|
189 | " ", |
---|
190 | " ", |
---|
191 | " ", |
---|
192 | " ", |
---|
193 | " .=.==.,@ ", |
---|
194 | " ==.,@-&&&)-= ", |
---|
195 | " .$@,&++;;;%>*- ", |
---|
196 | " $,-+)+++%%;;'#+. ", |
---|
197 | " =---+++++;%%%;%##@. ", |
---|
198 | " @)++++++++;%%%%'#%$ ", |
---|
199 | " $&++++++++++;%%;%##@= ", |
---|
200 | " ,-++++)+++++++;;;'#%) ", |
---|
201 | " @+++&&--&)++++;;%'#'-. ", |
---|
202 | " ,&++-@@,,,,-)++;;;'>'+, ", |
---|
203 | " =-++&@$@&&&&-&+;;;%##%+@ ", |
---|
204 | " =,)+)-,@@&+++++;;;;%##%&@ ", |
---|
205 | " @--&&,,@&)++++++;;;;'#)@ ", |
---|
206 | " ---&)-,@)+++++++;;;%''+, ", |
---|
207 | " $--&)+&$-+++++++;;;%%'';- ", |
---|
208 | " .,-&+++-$&++++++;;;%''%&= ", |
---|
209 | " $,-&)++)-@++++++;;%''%), ", |
---|
210 | " =,@&)++++&&+++++;%'''+$@&++++++ ", |
---|
211 | " .$@-++++++++++++;'#';,........=$@&++++ ", |
---|
212 | " =$@@&)+++++++++++'##-.................=&++ ", |
---|
213 | " .$$@-&)+++++++++;%#+$.....................=)+ ", |
---|
214 | " $$,@-)+++++++++;%;@=........................,+ ", |
---|
215 | " .$$@@-++++++++)-)@=............................ ", |
---|
216 | " $,@---)++++&)@===............................,. ", |
---|
217 | " $-@---&)))-$$=..............................=)!. ", |
---|
218 | " --&-&&,,$=,==...........................=&+++!. ", |
---|
219 | " =,=$..=$+)+++++&@$=.............=$@&+++++!++!. ", |
---|
220 | " .)-++-+++++++++++++++++++++++++++!++!++!. ", |
---|
221 | " .+-++-+++++++++++++++++++++++!+++!++!++!. ", |
---|
222 | " .+-++-+++-+++++++++!+++!!++++!+++!++!++!. ", |
---|
223 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
224 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
225 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
226 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
227 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
228 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
229 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
230 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
231 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
232 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
233 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
234 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
235 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
236 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
237 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
238 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
239 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
240 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
241 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
242 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
243 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
244 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
245 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
246 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
247 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
248 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
249 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
250 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
251 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
252 | " .+-++-+++-+++++++++!++++!++++!+++!++!++!. ", |
---|
253 | " =+-++-+++-+++++++++!++++!++++!+++!++!+++= ", |
---|
254 | " $.++-+++-+++++++++!++++!++++!+++!++!+.$ ", |
---|
255 | " =.++++++++++++++!++++!++++!+++!++.= ", |
---|
256 | " $..+++++++++++++++!++++++...$ ", |
---|
257 | " $$==...........==$$ ", |
---|
258 | " ", |
---|
259 | " ", |
---|
260 | " ", |
---|
261 | " ", |
---|
262 | " ", |
---|
263 | " ", |
---|
264 | " ", |
---|
265 | " ", |
---|
266 | " "}; |
---|
267 | |
---|
268 | GdkPixmap *trashcan_open; |
---|
269 | GdkPixmap *trashcan_open_mask; |
---|
270 | GdkPixmap *trashcan_closed; |
---|
271 | GdkPixmap *trashcan_closed_mask; |
---|
272 | |
---|
273 | gboolean have_drag; |
---|
274 | |
---|
275 | enum { |
---|
276 | TARGET_STRING, |
---|
277 | TARGET_ROOTWIN, |
---|
278 | TARGET_URL |
---|
279 | }; |
---|
280 | |
---|
281 | static GtkTargetEntry target_table[] = { |
---|
282 | { "STRING", 0, TARGET_STRING }, |
---|
283 | { "text/plain", 0, TARGET_STRING }, |
---|
284 | { "text/uri-list", 0, TARGET_URL }, |
---|
285 | { "application/x-rootwin-drop", 0, TARGET_ROOTWIN } |
---|
286 | }; |
---|
287 | |
---|
288 | static guint n_targets = sizeof(target_table) / sizeof(target_table[0]); |
---|
289 | |
---|
290 | void |
---|
291 | target_drag_leave (GtkWidget *widget, |
---|
292 | GdkDragContext *context, |
---|
293 | guint time) |
---|
294 | { |
---|
295 | g_print("leave\n"); |
---|
296 | have_drag = FALSE; |
---|
297 | gtk_pixmap_set (GTK_PIXMAP (widget), trashcan_closed, trashcan_closed_mask); |
---|
298 | } |
---|
299 | |
---|
300 | gboolean |
---|
301 | target_drag_motion (GtkWidget *widget, |
---|
302 | GdkDragContext *context, |
---|
303 | gint x, |
---|
304 | gint y, |
---|
305 | guint time) |
---|
306 | { |
---|
307 | GtkWidget *source_widget; |
---|
308 | |
---|
309 | if (!have_drag) |
---|
310 | { |
---|
311 | have_drag = TRUE; |
---|
312 | gtk_pixmap_set (GTK_PIXMAP (widget), trashcan_open, trashcan_open_mask); |
---|
313 | } |
---|
314 | |
---|
315 | source_widget = gtk_drag_get_source_widget (context); |
---|
316 | g_print("motion, source %s\n", source_widget ? |
---|
317 | gtk_type_name (GTK_OBJECT (source_widget)->klass->type) : |
---|
318 | "unknown"); |
---|
319 | |
---|
320 | gdk_drag_status (context, context->suggested_action, time); |
---|
321 | return TRUE; |
---|
322 | } |
---|
323 | |
---|
324 | gboolean |
---|
325 | target_drag_drop (GtkWidget *widget, |
---|
326 | GdkDragContext *context, |
---|
327 | gint x, |
---|
328 | gint y, |
---|
329 | guint time) |
---|
330 | { |
---|
331 | g_print("drop\n"); |
---|
332 | have_drag = FALSE; |
---|
333 | |
---|
334 | gtk_pixmap_set (GTK_PIXMAP (widget), trashcan_closed, trashcan_closed_mask); |
---|
335 | |
---|
336 | if (context->targets) |
---|
337 | { |
---|
338 | gtk_drag_get_data (widget, context, |
---|
339 | GPOINTER_TO_INT (context->targets->data), |
---|
340 | time); |
---|
341 | return TRUE; |
---|
342 | } |
---|
343 | |
---|
344 | return FALSE; |
---|
345 | } |
---|
346 | |
---|
347 | void |
---|
348 | target_drag_data_received (GtkWidget *widget, |
---|
349 | GdkDragContext *context, |
---|
350 | gint x, |
---|
351 | gint y, |
---|
352 | GtkSelectionData *data, |
---|
353 | guint info, |
---|
354 | guint time) |
---|
355 | { |
---|
356 | if ((data->length >= 0) && (data->format == 8)) |
---|
357 | { |
---|
358 | g_print ("Received \"%s\" in trashcan\n", (gchar *)data->data); |
---|
359 | gtk_drag_finish (context, TRUE, FALSE, time); |
---|
360 | return; |
---|
361 | } |
---|
362 | |
---|
363 | gtk_drag_finish (context, FALSE, FALSE, time); |
---|
364 | } |
---|
365 | |
---|
366 | void |
---|
367 | label_drag_data_received (GtkWidget *widget, |
---|
368 | GdkDragContext *context, |
---|
369 | gint x, |
---|
370 | gint y, |
---|
371 | GtkSelectionData *data, |
---|
372 | guint info, |
---|
373 | guint time) |
---|
374 | { |
---|
375 | if ((data->length >= 0) && (data->format == 8)) |
---|
376 | { |
---|
377 | g_print ("Received \"%s\" in label\n", (gchar *)data->data); |
---|
378 | gtk_drag_finish (context, TRUE, FALSE, time); |
---|
379 | return; |
---|
380 | } |
---|
381 | |
---|
382 | gtk_drag_finish (context, FALSE, FALSE, time); |
---|
383 | } |
---|
384 | |
---|
385 | void |
---|
386 | source_drag_data_get (GtkWidget *widget, |
---|
387 | GdkDragContext *context, |
---|
388 | GtkSelectionData *selection_data, |
---|
389 | guint info, |
---|
390 | guint time, |
---|
391 | gpointer data) |
---|
392 | { |
---|
393 | if (info == TARGET_ROOTWIN) |
---|
394 | g_print ("I was dropped on the rootwin\n"); |
---|
395 | else if (info == TARGET_URL) |
---|
396 | gtk_selection_data_set (selection_data, |
---|
397 | selection_data->target, |
---|
398 | 8, "file:///home/otaylor/images/weave.png", 37); |
---|
399 | else |
---|
400 | gtk_selection_data_set (selection_data, |
---|
401 | selection_data->target, |
---|
402 | 8, "I'm Data!", 9); |
---|
403 | } |
---|
404 | |
---|
405 | /* The following is a rather elaborate example demonstrating/testing |
---|
406 | * changing of the window heirarchy during a drag - in this case, |
---|
407 | * via a "spring-loaded" popup window. |
---|
408 | */ |
---|
409 | static GtkWidget *popup_window = NULL; |
---|
410 | |
---|
411 | static gboolean popped_up = FALSE; |
---|
412 | static gboolean in_popup = FALSE; |
---|
413 | static guint popdown_timer = 0; |
---|
414 | static guint popup_timer = 0; |
---|
415 | |
---|
416 | gint |
---|
417 | popdown_cb (gpointer data) |
---|
418 | { |
---|
419 | popdown_timer = 0; |
---|
420 | |
---|
421 | gtk_widget_hide (popup_window); |
---|
422 | popped_up = FALSE; |
---|
423 | |
---|
424 | return FALSE; |
---|
425 | } |
---|
426 | |
---|
427 | gboolean |
---|
428 | popup_motion (GtkWidget *widget, |
---|
429 | GdkDragContext *context, |
---|
430 | gint x, |
---|
431 | gint y, |
---|
432 | guint time) |
---|
433 | { |
---|
434 | if (!in_popup) |
---|
435 | { |
---|
436 | in_popup = TRUE; |
---|
437 | if (popdown_timer) |
---|
438 | { |
---|
439 | g_print ("removed popdown\n"); |
---|
440 | gtk_timeout_remove (popdown_timer); |
---|
441 | popdown_timer = 0; |
---|
442 | } |
---|
443 | } |
---|
444 | |
---|
445 | return TRUE; |
---|
446 | } |
---|
447 | |
---|
448 | void |
---|
449 | popup_leave (GtkWidget *widget, |
---|
450 | GdkDragContext *context, |
---|
451 | guint time) |
---|
452 | { |
---|
453 | if (in_popup) |
---|
454 | { |
---|
455 | in_popup = FALSE; |
---|
456 | if (!popdown_timer) |
---|
457 | { |
---|
458 | g_print ("added popdown\n"); |
---|
459 | popdown_timer = gtk_timeout_add (500, popdown_cb, NULL); |
---|
460 | } |
---|
461 | } |
---|
462 | } |
---|
463 | |
---|
464 | gint |
---|
465 | popup_cb (gpointer data) |
---|
466 | { |
---|
467 | if (!popped_up) |
---|
468 | { |
---|
469 | if (!popup_window) |
---|
470 | { |
---|
471 | GtkWidget *button; |
---|
472 | GtkWidget *table; |
---|
473 | int i, j; |
---|
474 | |
---|
475 | popup_window = gtk_window_new (GTK_WINDOW_POPUP); |
---|
476 | gtk_window_set_position (GTK_WINDOW (popup_window), GTK_WIN_POS_MOUSE); |
---|
477 | |
---|
478 | table = gtk_table_new (3,3, FALSE); |
---|
479 | |
---|
480 | for (i=0; i<3; i++) |
---|
481 | for (j=0; j<3; j++) |
---|
482 | { |
---|
483 | char buffer[128]; |
---|
484 | g_snprintf(buffer, sizeof(buffer), "%d,%d", i, j); |
---|
485 | button = gtk_button_new_with_label (buffer); |
---|
486 | gtk_table_attach (GTK_TABLE (table), button, i, i+1, j, j+1, |
---|
487 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
488 | 0, 0); |
---|
489 | |
---|
490 | gtk_drag_dest_set (button, |
---|
491 | GTK_DEST_DEFAULT_ALL, |
---|
492 | target_table, n_targets - 1, /* no rootwin */ |
---|
493 | GDK_ACTION_COPY | GDK_ACTION_MOVE); |
---|
494 | gtk_signal_connect (GTK_OBJECT (button), "drag_motion", |
---|
495 | GTK_SIGNAL_FUNC (popup_motion), NULL); |
---|
496 | gtk_signal_connect (GTK_OBJECT (button), "drag_leave", |
---|
497 | GTK_SIGNAL_FUNC (popup_leave), NULL); |
---|
498 | } |
---|
499 | |
---|
500 | gtk_widget_show_all (table); |
---|
501 | gtk_container_add (GTK_CONTAINER (popup_window), table); |
---|
502 | |
---|
503 | } |
---|
504 | gtk_widget_show (popup_window); |
---|
505 | popped_up = TRUE; |
---|
506 | } |
---|
507 | |
---|
508 | popdown_timer = gtk_timeout_add (500, popdown_cb, NULL); |
---|
509 | g_print ("added popdown\n"); |
---|
510 | |
---|
511 | popup_timer = FALSE; |
---|
512 | |
---|
513 | return FALSE; |
---|
514 | } |
---|
515 | |
---|
516 | gboolean |
---|
517 | popsite_motion (GtkWidget *widget, |
---|
518 | GdkDragContext *context, |
---|
519 | gint x, |
---|
520 | gint y, |
---|
521 | guint time) |
---|
522 | { |
---|
523 | if (!popup_timer) |
---|
524 | popup_timer = gtk_timeout_add (500, popup_cb, NULL); |
---|
525 | |
---|
526 | return TRUE; |
---|
527 | } |
---|
528 | |
---|
529 | void |
---|
530 | popsite_leave (GtkWidget *widget, |
---|
531 | GdkDragContext *context, |
---|
532 | guint time) |
---|
533 | { |
---|
534 | if (popup_timer) |
---|
535 | { |
---|
536 | gtk_timeout_remove (popup_timer); |
---|
537 | popup_timer = 0; |
---|
538 | } |
---|
539 | } |
---|
540 | |
---|
541 | void |
---|
542 | source_drag_data_delete (GtkWidget *widget, |
---|
543 | GdkDragContext *context, |
---|
544 | gpointer data) |
---|
545 | { |
---|
546 | g_print ("Delete the data!\n"); |
---|
547 | } |
---|
548 | |
---|
549 | int |
---|
550 | main (int argc, char **argv) |
---|
551 | { |
---|
552 | GtkWidget *window; |
---|
553 | GtkWidget *table; |
---|
554 | GtkWidget *label; |
---|
555 | GtkWidget *pixmap; |
---|
556 | GtkWidget *button; |
---|
557 | GdkPixmap *drag_icon; |
---|
558 | GdkPixmap *drag_mask; |
---|
559 | |
---|
560 | gtk_init (&argc, &argv); |
---|
561 | |
---|
562 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
---|
563 | gtk_signal_connect (GTK_OBJECT(window), "destroy", |
---|
564 | GTK_SIGNAL_FUNC (gtk_main_quit), NULL); |
---|
565 | |
---|
566 | |
---|
567 | table = gtk_table_new (2, 2, FALSE); |
---|
568 | gtk_container_add (GTK_CONTAINER (window), table); |
---|
569 | |
---|
570 | drag_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, |
---|
571 | gtk_widget_get_colormap (window), |
---|
572 | &drag_mask, |
---|
573 | NULL, drag_icon_xpm); |
---|
574 | |
---|
575 | trashcan_open = gdk_pixmap_colormap_create_from_xpm_d (NULL, |
---|
576 | gtk_widget_get_colormap (window), |
---|
577 | &trashcan_open_mask, |
---|
578 | NULL, trashcan_open_xpm); |
---|
579 | trashcan_closed = gdk_pixmap_colormap_create_from_xpm_d (NULL, |
---|
580 | gtk_widget_get_colormap (window), |
---|
581 | &trashcan_closed_mask, |
---|
582 | NULL, trashcan_closed_xpm); |
---|
583 | |
---|
584 | label = gtk_label_new ("Drop Here\n"); |
---|
585 | |
---|
586 | gtk_drag_dest_set (label, |
---|
587 | GTK_DEST_DEFAULT_ALL, |
---|
588 | target_table, n_targets - 1, /* no rootwin */ |
---|
589 | GDK_ACTION_COPY | GDK_ACTION_MOVE); |
---|
590 | |
---|
591 | gtk_signal_connect( GTK_OBJECT(label), "drag_data_received", |
---|
592 | GTK_SIGNAL_FUNC( label_drag_data_received), NULL); |
---|
593 | |
---|
594 | gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, |
---|
595 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
596 | 0, 0); |
---|
597 | |
---|
598 | label = gtk_label_new ("Popup\n"); |
---|
599 | |
---|
600 | gtk_drag_dest_set (label, |
---|
601 | GTK_DEST_DEFAULT_ALL, |
---|
602 | target_table, n_targets - 1, /* no rootwin */ |
---|
603 | GDK_ACTION_COPY | GDK_ACTION_MOVE); |
---|
604 | |
---|
605 | gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2, |
---|
606 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
607 | 0, 0); |
---|
608 | |
---|
609 | gtk_signal_connect (GTK_OBJECT (label), "drag_motion", |
---|
610 | GTK_SIGNAL_FUNC (popsite_motion), NULL); |
---|
611 | gtk_signal_connect (GTK_OBJECT (label), "drag_leave", |
---|
612 | GTK_SIGNAL_FUNC (popsite_leave), NULL); |
---|
613 | |
---|
614 | pixmap = gtk_pixmap_new (trashcan_closed, trashcan_closed_mask); |
---|
615 | gtk_drag_dest_set (pixmap, 0, NULL, 0, 0); |
---|
616 | gtk_table_attach (GTK_TABLE (table), pixmap, 1, 2, 0, 1, |
---|
617 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
618 | 0, 0); |
---|
619 | |
---|
620 | gtk_signal_connect (GTK_OBJECT (pixmap), "drag_leave", |
---|
621 | GTK_SIGNAL_FUNC (target_drag_leave), NULL); |
---|
622 | |
---|
623 | gtk_signal_connect (GTK_OBJECT (pixmap), "drag_motion", |
---|
624 | GTK_SIGNAL_FUNC (target_drag_motion), NULL); |
---|
625 | |
---|
626 | gtk_signal_connect (GTK_OBJECT (pixmap), "drag_drop", |
---|
627 | GTK_SIGNAL_FUNC (target_drag_drop), NULL); |
---|
628 | |
---|
629 | gtk_signal_connect (GTK_OBJECT (pixmap), "drag_data_received", |
---|
630 | GTK_SIGNAL_FUNC (target_drag_data_received), NULL); |
---|
631 | |
---|
632 | /* Drag site */ |
---|
633 | |
---|
634 | button = gtk_button_new_with_label ("Drag Here\n"); |
---|
635 | |
---|
636 | gtk_drag_source_set (button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK, |
---|
637 | target_table, n_targets, |
---|
638 | GDK_ACTION_COPY | GDK_ACTION_MOVE); |
---|
639 | gtk_drag_source_set_icon (button, |
---|
640 | gtk_widget_get_colormap (window), |
---|
641 | drag_icon, drag_mask); |
---|
642 | |
---|
643 | gdk_pixmap_unref (drag_icon); |
---|
644 | gdk_pixmap_unref (drag_mask); |
---|
645 | |
---|
646 | gtk_table_attach (GTK_TABLE (table), button, 0, 1, 1, 2, |
---|
647 | GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, |
---|
648 | 0, 0); |
---|
649 | |
---|
650 | gtk_signal_connect (GTK_OBJECT (button), "drag_data_get", |
---|
651 | GTK_SIGNAL_FUNC (source_drag_data_get), NULL); |
---|
652 | gtk_signal_connect (GTK_OBJECT (button), "drag_data_delete", |
---|
653 | GTK_SIGNAL_FUNC (source_drag_data_delete), NULL); |
---|
654 | |
---|
655 | gtk_widget_show_all (window); |
---|
656 | |
---|
657 | gtk_main (); |
---|
658 | |
---|
659 | return 0; |
---|
660 | } |
---|