]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: dnd.cpp | |
3 | // Purpose: wxDropTarget class | |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 RR |
6 | // Copyright: (c) 1998 Robert Roebling |
7 | // Licence: wxWindows licence | |
c801d85f KB |
8 | /////////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "dnd.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/dnd.h" | |
ac57418f | 15 | |
06cfab17 | 16 | #if wxUSE_DRAG_AND_DROP |
ac57418f | 17 | |
c801d85f KB |
18 | #include "wx/window.h" |
19 | #include "wx/app.h" | |
20 | #include "wx/gdicmn.h" | |
b527aac5 RR |
21 | #include "wx/intl.h" |
22 | #include "wx/utils.h" | |
c801d85f | 23 | |
83624f79 RR |
24 | #include "gdk/gdk.h" |
25 | #include "gtk/gtk.h" | |
c801d85f KB |
26 | #include "gdk/gdkprivate.h" |
27 | ||
28 | #include <X11/Xlib.h> | |
29 | ||
30 | // ---------------------------------------------------------------------------- | |
31 | // global | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
34 | extern bool g_blockEventsOnDrag; | |
35 | ||
f5368809 RR |
36 | #ifdef NEW_GTK_DND_CODE |
37 | ||
33a5bc52 RR |
38 | #include "gtk/gtkdnd.h" |
39 | #include "gtk/gtkselection.h" | |
40 | ||
41 | // ---------------------------------------------------------------------------- | |
42 | // "drag_leave" | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
45 | static void target_drag_leave( GtkWidget *WXUNUSED(widget), | |
46 | GdkDragContext *WXUNUSED(context), | |
47 | guint WXUNUSED(time) ) | |
48 | { | |
49 | printf( "leave.\n" ); | |
50 | } | |
51 | ||
52 | // ---------------------------------------------------------------------------- | |
53 | // "drag_motion" | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
56 | static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), | |
57 | GdkDragContext *context, | |
58 | gint WXUNUSED(x), | |
59 | gint WXUNUSED(y), | |
60 | guint time ) | |
61 | { | |
62 | printf( "motion.\n" ); | |
63 | gdk_drag_status( context, context->suggested_action, time ); | |
64 | return TRUE; | |
65 | } | |
66 | ||
67 | // ---------------------------------------------------------------------------- | |
68 | // "drag_drop" | |
69 | // ---------------------------------------------------------------------------- | |
70 | ||
71 | static gboolean target_drag_drop( GtkWidget *widget, | |
72 | GdkDragContext *context, | |
73 | gint x, | |
74 | gint y, | |
75 | guint time ) | |
76 | { | |
77 | printf( "drop at: %d,%d.\n", x, y ); | |
78 | ||
79 | if (context->targets) | |
80 | { | |
81 | gtk_drag_get_data( widget, | |
82 | context, | |
83 | GPOINTER_TO_INT (context->targets->data), | |
84 | time ); | |
85 | } | |
86 | return FALSE; | |
87 | } | |
88 | ||
89 | // ---------------------------------------------------------------------------- | |
90 | // "drag_data_received" | |
91 | // ---------------------------------------------------------------------------- | |
92 | ||
93 | static void target_drag_data_received( GtkWidget *WXUNUSED(widget), | |
94 | GdkDragContext *context, | |
95 | gint x, | |
96 | gint y, | |
97 | GtkSelectionData *data, | |
98 | guint WXUNUSED(info), | |
99 | guint time ) | |
100 | { | |
101 | printf( "data receive at: %d,%d.\n", x, y ); | |
102 | ||
103 | if ((data->length >= 0) && (data->format == 8)) | |
104 | { | |
ab8884ac RR |
105 | wxString str = (const char*)data->data; |
106 | printf( "Received %s\n.", WXSTRINGCAST str ); | |
107 | gtk_drag_finish( context, TRUE, FALSE, time ); | |
108 | return; | |
33a5bc52 RR |
109 | } |
110 | ||
111 | gtk_drag_finish (context, FALSE, FALSE, time); | |
112 | } | |
113 | ||
114 | // ---------------------------------------------------------------------------- | |
115 | // wxDropTarget | |
116 | // ---------------------------------------------------------------------------- | |
117 | ||
f5368809 RR |
118 | wxDropTarget::wxDropTarget() |
119 | { | |
120 | } | |
121 | ||
122 | wxDropTarget::~wxDropTarget() | |
123 | { | |
124 | } | |
125 | ||
126 | void wxDropTarget::UnregisterWidget( GtkWidget *widget ) | |
127 | { | |
33a5bc52 | 128 | wxCHECK_RET( widget != NULL, "unregister widget is NULL" ); |
f5368809 | 129 | |
33a5bc52 RR |
130 | gtk_drag_dest_set( widget, |
131 | (GtkDestDefaults) 0, | |
132 | (GtkTargetEntry*) NULL, | |
133 | 0, | |
134 | (GdkDragAction) 0 ); | |
135 | ||
136 | gtk_signal_disconnect_by_func( GTK_OBJECT(widget), | |
137 | GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this ); | |
138 | ||
139 | gtk_signal_disconnect_by_func( GTK_OBJECT(widget), | |
140 | GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this ); | |
141 | ||
142 | gtk_signal_disconnect_by_func( GTK_OBJECT(widget), | |
143 | GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this ); | |
144 | ||
145 | gtk_signal_disconnect_by_func( GTK_OBJECT(widget), | |
146 | GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); | |
f5368809 RR |
147 | } |
148 | ||
149 | void wxDropTarget::RegisterWidget( GtkWidget *widget ) | |
150 | { | |
33a5bc52 | 151 | wxCHECK_RET( widget != NULL, "register widget is NULL" ); |
f5368809 | 152 | |
33a5bc52 RR |
153 | GtkTargetEntry format; |
154 | format.info = 0; | |
155 | format.flags = 0; | |
ab8884ac | 156 | char buf[100]; |
f5368809 | 157 | |
33a5bc52 | 158 | int valid = 0; |
f5368809 RR |
159 | for ( size_t i = 0; i < GetFormatCount(); i++ ) |
160 | { | |
161 | wxDataFormat df = GetFormat( i ); | |
162 | switch (df) | |
163 | { | |
164 | case wxDF_TEXT: | |
33a5bc52 | 165 | format.target = "text/plain"; |
f5368809 RR |
166 | valid++; |
167 | break; | |
168 | case wxDF_FILENAME: | |
33a5bc52 | 169 | format.target = "file:ALL"; |
f5368809 RR |
170 | valid++; |
171 | break; | |
ab8884ac RR |
172 | case wxDF_PRIVATE: |
173 | wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this; | |
0d2a2b60 | 174 | strcpy( buf, WXSTRINGCAST pdt->GetID() ); |
ab8884ac RR |
175 | format.target = buf; |
176 | valid++; | |
f5368809 RR |
177 | default: |
178 | break; | |
179 | } | |
180 | } | |
181 | ||
33a5bc52 | 182 | wxASSERT_MSG( valid != 0, "No valid DnD format supported." ); |
f5368809 | 183 | |
33a5bc52 RR |
184 | gtk_drag_dest_set( widget, |
185 | GTK_DEST_DEFAULT_ALL, | |
186 | &format, | |
187 | 1, | |
188 | (GdkDragAction)(GDK_ACTION_COPY | GDK_ACTION_MOVE) ); | |
189 | ||
190 | gtk_signal_connect( GTK_OBJECT(widget), "drag_leave", | |
191 | GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this ); | |
192 | ||
193 | gtk_signal_connect( GTK_OBJECT(widget), "drag_motion", | |
194 | GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this ); | |
195 | ||
196 | gtk_signal_connect( GTK_OBJECT(widget), "drag_drop", | |
197 | GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this ); | |
198 | ||
199 | gtk_signal_connect( GTK_OBJECT(widget), "drag_data_received", | |
200 | GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); | |
f5368809 RR |
201 | } |
202 | ||
203 | // ---------------------------------------------------------------------------- | |
204 | // wxTextDropTarget | |
205 | // ---------------------------------------------------------------------------- | |
206 | ||
207 | bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) ) | |
208 | { | |
209 | OnDropText( x, y, (const char*)data ); | |
210 | return TRUE; | |
211 | } | |
212 | ||
213 | bool wxTextDropTarget::OnDropText( long x, long y, const char *psz ) | |
214 | { | |
215 | printf( "Got dropped text: %s.\n", psz ); | |
216 | printf( "At x: %d, y: %d.\n", (int)x, (int)y ); | |
217 | return TRUE; | |
218 | } | |
219 | ||
220 | size_t wxTextDropTarget::GetFormatCount() const | |
221 | { | |
222 | return 1; | |
223 | } | |
224 | ||
225 | wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const | |
226 | { | |
227 | return wxDF_TEXT; | |
228 | } | |
229 | ||
230 | // ---------------------------------------------------------------------------- | |
231 | // wxFileDropTarget | |
232 | // ---------------------------------------------------------------------------- | |
233 | ||
234 | bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] ) | |
235 | { | |
236 | printf( "Got %d dropped files.\n", (int)nFiles ); | |
237 | printf( "At x: %d, y: %d.\n", (int)x, (int)y ); | |
238 | for (size_t i = 0; i < nFiles; i++) | |
239 | { | |
240 | printf( aszFiles[i] ); | |
241 | printf( "\n" ); | |
242 | } | |
243 | return TRUE; | |
244 | } | |
245 | ||
246 | bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size ) | |
247 | { | |
248 | size_t number = 0; | |
249 | char *text = (char*) data; | |
250 | for (size_t i = 0; i < size; i++) | |
251 | if (text[i] == 0) number++; | |
252 | ||
253 | if (number == 0) return TRUE; | |
254 | ||
255 | char **files = new char*[number]; | |
256 | ||
257 | text = (char*) data; | |
258 | for (size_t i = 0; i < number; i++) | |
259 | { | |
260 | files[i] = text; | |
261 | int len = strlen( text ); | |
262 | text += len+1; | |
263 | } | |
264 | ||
265 | bool ret = OnDropFiles( x, y, 1, files ); | |
266 | ||
267 | free( files ); | |
268 | ||
269 | return ret; | |
270 | } | |
271 | ||
272 | size_t wxFileDropTarget::GetFormatCount() const | |
273 | { | |
274 | return 1; | |
275 | } | |
276 | ||
277 | wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const | |
278 | { | |
279 | return wxDF_FILENAME; | |
280 | } | |
281 | ||
282 | //------------------------------------------------------------------------- | |
283 | // wxDropSource | |
284 | //------------------------------------------------------------------------- | |
285 | ||
286 | wxDropSource::wxDropSource( wxWindow *win ) | |
287 | { | |
288 | g_blockEventsOnDrag = TRUE; | |
289 | ||
290 | m_window = win; | |
291 | m_widget = win->m_widget; | |
292 | if (win->m_wxwindow) m_widget = win->m_wxwindow; | |
293 | ||
294 | m_data = (wxDataObject *) NULL; | |
295 | m_retValue = wxDragCancel; | |
296 | ||
297 | m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); | |
298 | m_goaheadCursor = wxCursor( wxCURSOR_HAND ); | |
299 | } | |
300 | ||
301 | wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win ) | |
302 | { | |
303 | g_blockEventsOnDrag = TRUE; | |
304 | ||
305 | m_window = win; | |
306 | m_widget = win->m_widget; | |
307 | if (win->m_wxwindow) m_widget = win->m_wxwindow; | |
308 | m_retValue = wxDragCancel; | |
309 | ||
310 | m_data = &data; | |
311 | ||
312 | m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); | |
313 | m_goaheadCursor = wxCursor( wxCURSOR_HAND ); | |
314 | } | |
315 | ||
316 | void wxDropSource::SetData( wxDataObject &data ) | |
317 | { | |
318 | m_data = &data; | |
319 | } | |
320 | ||
321 | wxDropSource::~wxDropSource(void) | |
322 | { | |
323 | // if (m_data) delete m_data; | |
324 | ||
325 | g_blockEventsOnDrag = FALSE; | |
326 | } | |
327 | ||
328 | wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) | |
329 | { | |
330 | wxASSERT_MSG( m_data, "wxDragSource: no data" ); | |
331 | ||
332 | if (!m_data) return (wxDragResult) wxDragNone; | |
333 | if (m_data->GetDataSize() == 0) return (wxDragResult) wxDragNone; | |
334 | ||
335 | RegisterWindow(); | |
336 | ||
337 | // TODO | |
338 | ||
339 | UnregisterWindow(); | |
340 | ||
341 | g_blockEventsOnDrag = FALSE; | |
342 | ||
343 | return m_retValue; | |
344 | } | |
345 | ||
346 | void wxDropSource::RegisterWindow(void) | |
347 | { | |
348 | if (!m_data) return; | |
349 | ||
350 | wxString formats; | |
351 | ||
352 | wxDataFormat df = m_data->GetPreferredFormat(); | |
353 | ||
354 | switch (df) | |
355 | { | |
356 | case wxDF_TEXT: | |
357 | formats += "text/plain"; | |
358 | break; | |
359 | case wxDF_FILENAME: | |
360 | formats += "file:ALL"; | |
361 | break; | |
362 | default: | |
363 | break; | |
364 | } | |
365 | ||
366 | char *str = WXSTRINGCAST formats; | |
367 | ||
368 | // TODO | |
369 | } | |
370 | ||
371 | void wxDropSource::UnregisterWindow(void) | |
372 | { | |
373 | if (!m_widget) return; | |
374 | ||
375 | // TODO | |
376 | } | |
377 | ||
33a5bc52 RR |
378 | |
379 | #else // NEW_CODE | |
380 | ||
a802c3a1 RR |
381 | GtkWidget *shape_create_icon (char **data, |
382 | gint x, | |
383 | gint y, | |
384 | gint px, | |
385 | gint py, | |
386 | gint window_type); | |
387 | ||
388 | /* XPM */ | |
389 | static char * gv_xpm[] = { | |
390 | "40 34 3 1", | |
391 | " s None c None", | |
392 | ". c black", | |
393 | "X c white", | |
394 | " ", | |
395 | " ", | |
396 | " ...... ", | |
397 | " ..XXXXXX.. ", | |
398 | " .XXXXXXXXXX. ", | |
399 | " .XXXXXXXXXXXX. ", | |
400 | " .XXXXXXXXXXXX. ", | |
401 | " .XXXXXXXXXXXXXX. ", | |
402 | " .XXX..XXXX..XXX. ", | |
403 | " ....XX....XX....XX. ", | |
404 | " .XXX.XXX..XXXX..XXX.... ", | |
405 | " .XXXXXXXXXXXXXXXXXXX.XXX. ", | |
406 | " .XXXXXXXXXXXXXXXXXXXXXXXX. ", | |
407 | " .XXXXXXXXXXXXXXXXXXXXXXXX. ", | |
408 | " ..XXXXXXXXXXXXXXXXXXXXXX. ", | |
409 | " .XXXXXXXXXXXXXXXXXX... ", | |
410 | " ..XXXXXXXXXXXXXXXX. ", | |
411 | " .XXXXXXXXXXXXXXXX. ", | |
412 | " .XXXXXXXXXXXXXXXX. ", | |
413 | " .XXXXXXXXXXXXXXXXX. ", | |
414 | " .XXXXXXXXXXXXXXXXX. ", | |
415 | " .XXXXXXXXXXXXXXXXXX. ", | |
416 | " .XXXXXXXXXXXXXXXXXXX. ", | |
417 | " .XXXXXXXXXXXXXXXXXXXXX. ", | |
418 | " .XXXXXXXXXXXXXX.XXXXXXX. ", | |
419 | " .XXXXXXX.XXXXXXX.XXXXXXX. ", | |
420 | " .XXXXXXXX.XXXXXXX.XXXXXXX. ", | |
421 | " .XXXXXXX...XXXXX...XXXXX. ", | |
422 | " .XXXXXXX. ..... ..... ", | |
423 | " ..XXXX.. ", | |
424 | " .... ", | |
425 | " ", | |
426 | " ", | |
427 | " "}; | |
428 | ||
429 | /* XPM */ | |
430 | static char * page_xpm[] = { | |
431 | /* width height ncolors chars_per_pixel */ | |
432 | "32 32 5 1", | |
433 | /* colors */ | |
434 | " s None c None", | |
435 | ". c black", | |
436 | "X c wheat", | |
437 | "o c tan", | |
438 | "O c #6699FF", | |
439 | /* pixels */ | |
440 | " ................... ", | |
441 | " .XXXXXXXXXXXXXXXXX.. ", | |
442 | " .XXXXXXXXXXXXXXXXX.o. ", | |
443 | " .XXXXXXXXXXXXXXXXX.oo. ", | |
444 | " .XXXXXXXXXXXXXXXXX.ooo. ", | |
445 | " .XXXXXXXXXXXXXXXXX.oooo. ", | |
446 | " .XXXXXXXXXXXXXXXXX....... ", | |
447 | " .XXXXXOOOOOOOOOOXXXooooo. ", | |
448 | " .XXXXXXXXXXXXXXXXXXooooo. ", | |
449 | " .XXXXXOOOOOOOOOOXXXXXXXX. ", | |
450 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
451 | " .XXXXXXXOOOOOOOOOXXXXXXX. ", | |
452 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
453 | " .XXXXXXOOOOOOOOOOXXXXXXX. ", | |
454 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
455 | " .XXXXXOOOOOOOOOOXXXXXXXX. ", | |
456 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
457 | " .XXXXXXXOOOOOOOOOXXXXXXX. ", | |
458 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
459 | " .XXXXXXOOOOOOOOOOXXXXXXX. ", | |
460 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
461 | " .XXXXXOOOOOOOOOOXXXXXXXX. ", | |
462 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
463 | " .XXXXXXOOOOOOOOOOXXXXXXX. ", | |
464 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
465 | " .XXXXXOOOOOOOXXXXXXXXXXX. ", | |
466 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
467 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
468 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
469 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
470 | " .XXXXXXXXXXXXXXXXXXXXXXX. ", | |
471 | " ......................... "}; | |
472 | ||
473 | ||
b666df2c RR |
474 | //----------------------------------------------------------------------------- |
475 | // globals | |
476 | //----------------------------------------------------------------------------- | |
477 | ||
478 | wxDropSource *gs_currentDropSource = (wxDropSource*) NULL; | |
479 | ||
480 | //----------------------------------------------------------------------------- | |
481 | // "drop_enter_event" | |
482 | //----------------------------------------------------------------------------- | |
483 | ||
484 | static void gtk_target_enter_callback( GtkWidget *WXUNUSED(widget), | |
485 | GdkEventDropEnter *WXUNUSED(event), | |
486 | wxDropTarget *target ) | |
487 | { | |
488 | if (target) | |
489 | target->OnEnter(); | |
490 | } | |
491 | ||
492 | //----------------------------------------------------------------------------- | |
493 | // "drop_leave_event" | |
494 | //----------------------------------------------------------------------------- | |
495 | ||
496 | static void gtk_target_leave_callback( GtkWidget *WXUNUSED(widget), | |
497 | GdkEventDropLeave *WXUNUSED(event), | |
498 | wxDropTarget *target ) | |
499 | { | |
500 | if (target) | |
501 | target->OnLeave(); | |
502 | } | |
503 | ||
33a5bc52 RR |
504 | //----------------------------------------------------------------------------- |
505 | // "drop_data_available_event" | |
506 | //----------------------------------------------------------------------------- | |
507 | ||
508 | static void gtk_target_callback( GtkWidget *widget, | |
509 | GdkEventDropDataAvailable *event, | |
510 | wxDropTarget *target ) | |
511 | { | |
512 | if (target) | |
513 | { | |
514 | int x = 0; | |
515 | int y = 0; | |
516 | gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL ); | |
ab8884ac RR |
517 | /* |
518 | printf( "Drop data is of type %s.\n", event->data_type ); | |
519 | */ | |
33a5bc52 RR |
520 | target->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes ); |
521 | } | |
522 | ||
523 | /* | |
524 | g_free (event->data); | |
525 | g_free (event->data_type); | |
526 | */ | |
527 | } | |
f5368809 | 528 | |
c801d85f KB |
529 | // ---------------------------------------------------------------------------- |
530 | // wxDropTarget | |
531 | // ---------------------------------------------------------------------------- | |
532 | ||
533 | wxDropTarget::wxDropTarget() | |
534 | { | |
0d2a2b60 | 535 | m_format = (wxDataFormat*) NULL; |
ff7b1510 | 536 | } |
c801d85f KB |
537 | |
538 | wxDropTarget::~wxDropTarget() | |
539 | { | |
0d2a2b60 RR |
540 | if (m_format) delete m_format; |
541 | } | |
542 | ||
543 | wxDataFormat &wxDropTarget::GetFormat(size_t n) const | |
544 | { | |
545 | return (*m_format); | |
ff7b1510 | 546 | } |
c801d85f | 547 | |
c801d85f KB |
548 | void wxDropTarget::UnregisterWidget( GtkWidget *widget ) |
549 | { | |
33a5bc52 | 550 | if (!widget) return; |
e3e65dac | 551 | |
33a5bc52 RR |
552 | gtk_signal_disconnect_by_func( GTK_OBJECT(widget), |
553 | GTK_SIGNAL_FUNC(gtk_target_callback), (gpointer) this ); | |
554 | ||
555 | gtk_widget_dnd_drop_set( widget, FALSE, (gchar **) NULL, 0, FALSE ); | |
ff7b1510 | 556 | } |
c801d85f | 557 | |
e3e65dac RR |
558 | void wxDropTarget::RegisterWidget( GtkWidget *widget ) |
559 | { | |
33a5bc52 RR |
560 | wxString formats; |
561 | int valid = 0; | |
e3e65dac | 562 | |
33a5bc52 | 563 | for ( size_t i = 0; i < GetFormatCount(); i++ ) |
e3e65dac | 564 | { |
0d2a2b60 | 565 | switch (GetFormat(i).GetType()) |
33a5bc52 RR |
566 | { |
567 | case wxDF_TEXT: | |
ab8884ac RR |
568 | { |
569 | if (i > 0) formats += ";"; | |
570 | formats += "text/plain"; | |
571 | valid++; | |
572 | break; | |
573 | } | |
574 | case wxDF_FILENAME: | |
575 | { | |
576 | if (i > 0) formats += ";"; | |
577 | formats += "file:ALL"; | |
578 | valid++; | |
579 | break; | |
580 | } | |
581 | case wxDF_PRIVATE: | |
582 | { | |
583 | if (i > 0) formats += ";"; | |
584 | wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this; | |
ab8884ac RR |
585 | formats += pdt->GetId(); |
586 | valid++; | |
587 | break; | |
588 | } | |
589 | default: | |
33a5bc52 RR |
590 | break; |
591 | } | |
ff7b1510 | 592 | } |
e3e65dac | 593 | |
33a5bc52 | 594 | char *str = WXSTRINGCAST formats; |
ab8884ac | 595 | |
33a5bc52 RR |
596 | gtk_widget_dnd_drop_set( widget, TRUE, &str, valid, FALSE ); |
597 | ||
598 | gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event", | |
599 | GTK_SIGNAL_FUNC(gtk_target_callback), (gpointer) this ); | |
b666df2c RR |
600 | |
601 | gtk_signal_connect( GTK_OBJECT(widget), "drop_enter_event", | |
602 | GTK_SIGNAL_FUNC(gtk_target_enter_callback), (gpointer) this ); | |
603 | ||
604 | gtk_signal_connect( GTK_OBJECT(widget), "drop_leave_event", | |
605 | GTK_SIGNAL_FUNC(gtk_target_leave_callback), (gpointer) this ); | |
ff7b1510 | 606 | } |
e3e65dac | 607 | |
c801d85f KB |
608 | // ---------------------------------------------------------------------------- |
609 | // wxTextDropTarget | |
610 | // ---------------------------------------------------------------------------- | |
611 | ||
0d2a2b60 RR |
612 | wxTextDropTarget::wxTextDropTarget() |
613 | { | |
614 | m_format = new wxDataFormat( wxDF_TEXT ); | |
615 | } | |
616 | ||
dc86cb34 | 617 | bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) ) |
c801d85f | 618 | { |
33a5bc52 RR |
619 | OnDropText( x, y, (const char*)data ); |
620 | return TRUE; | |
ff7b1510 | 621 | } |
c801d85f KB |
622 | |
623 | bool wxTextDropTarget::OnDropText( long x, long y, const char *psz ) | |
624 | { | |
ab8884ac | 625 | /* |
33a5bc52 RR |
626 | printf( "Got dropped text: %s.\n", psz ); |
627 | printf( "At x: %d, y: %d.\n", (int)x, (int)y ); | |
ab8884ac | 628 | */ |
33a5bc52 | 629 | return TRUE; |
ff7b1510 | 630 | } |
c801d85f | 631 | |
e3e65dac | 632 | size_t wxTextDropTarget::GetFormatCount() const |
c801d85f | 633 | { |
33a5bc52 | 634 | return 1; |
e3e65dac RR |
635 | } |
636 | ||
ab8884ac RR |
637 | // ---------------------------------------------------------------------------- |
638 | // wxPrivateDropTarget | |
639 | // ---------------------------------------------------------------------------- | |
640 | ||
641 | wxPrivateDropTarget::wxPrivateDropTarget() | |
642 | { | |
643 | m_id = wxTheApp->GetAppName(); | |
0d2a2b60 | 644 | m_format = new wxDataFormat( m_id ); |
ab8884ac RR |
645 | } |
646 | ||
0d2a2b60 | 647 | void wxPrivateDropTarget::SetId( const wxString& id ) |
ab8884ac | 648 | { |
0d2a2b60 RR |
649 | m_id = id; |
650 | m_format->SetId( id ); | |
ab8884ac RR |
651 | } |
652 | ||
0d2a2b60 | 653 | size_t wxPrivateDropTarget::GetFormatCount() const |
ab8884ac | 654 | { |
0d2a2b60 | 655 | return 1; |
ab8884ac RR |
656 | } |
657 | ||
e3e65dac RR |
658 | // ---------------------------------------------------------------------------- |
659 | // wxFileDropTarget | |
660 | // ---------------------------------------------------------------------------- | |
661 | ||
0d2a2b60 RR |
662 | wxFileDropTarget::wxFileDropTarget() |
663 | { | |
664 | m_format = new wxDataFormat( wxDF_FILENAME ); | |
665 | } | |
666 | ||
e5403d7c | 667 | bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] ) |
e3e65dac | 668 | { |
33a5bc52 RR |
669 | printf( "Got %d dropped files.\n", (int)nFiles ); |
670 | printf( "At x: %d, y: %d.\n", (int)x, (int)y ); | |
ab8884ac | 671 | |
33a5bc52 RR |
672 | for (size_t i = 0; i < nFiles; i++) |
673 | { | |
674 | printf( aszFiles[i] ); | |
675 | printf( "\n" ); | |
676 | } | |
ab8884ac | 677 | |
33a5bc52 | 678 | return TRUE; |
e3e65dac RR |
679 | } |
680 | ||
dc86cb34 | 681 | bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size ) |
e3e65dac | 682 | { |
33a5bc52 RR |
683 | size_t number = 0; |
684 | char *text = (char*) data; | |
685 | for (size_t i = 0; i < size; i++) | |
686 | if (text[i] == 0) number++; | |
e5403d7c | 687 | |
33a5bc52 | 688 | if (number == 0) return TRUE; |
e5403d7c | 689 | |
33a5bc52 | 690 | char **files = new char*[number]; |
e5403d7c | 691 | |
33a5bc52 RR |
692 | text = (char*) data; |
693 | for (size_t i = 0; i < number; i++) | |
694 | { | |
695 | files[i] = text; | |
696 | int len = strlen( text ); | |
697 | text += len+1; | |
698 | } | |
e3e65dac | 699 | |
33a5bc52 | 700 | bool ret = OnDropFiles( x, y, 1, files ); |
e5403d7c | 701 | |
33a5bc52 | 702 | free( files ); |
e5403d7c | 703 | |
33a5bc52 | 704 | return ret; |
e3e65dac RR |
705 | } |
706 | ||
707 | size_t wxFileDropTarget::GetFormatCount() const | |
708 | { | |
33a5bc52 | 709 | return 1; |
e3e65dac RR |
710 | } |
711 | ||
c801d85f | 712 | //------------------------------------------------------------------------- |
e3e65dac | 713 | // wxDropSource |
c801d85f KB |
714 | //------------------------------------------------------------------------- |
715 | ||
b527aac5 RR |
716 | static void |
717 | shape_motion (GtkWidget *widget, | |
b666df2c | 718 | GdkEventMotion * /*event*/); |
b527aac5 | 719 | |
c801d85f | 720 | //----------------------------------------------------------------------------- |
0d2a2b60 RR |
721 | // "drag_request_event" |
722 | //----------------------------------------------------------------------------- | |
c801d85f | 723 | |
0d2a2b60 | 724 | void gtk_drag_callback( GtkWidget *widget, GdkEventDragRequest *event, wxDropSource *source ) |
c801d85f | 725 | { |
0d2a2b60 RR |
726 | wxDataBroker *data = source->m_data; |
727 | ||
728 | if (!data) return; | |
729 | ||
730 | wxNode *node = data->m_dataObjects.First(); | |
8b53e5a2 | 731 | { |
0d2a2b60 RR |
732 | wxDataObject *dobj = (wxDataObject*) node->Data(); |
733 | ||
734 | if ((strcmp(event->data_type,"file:ALL") == 0) && | |
735 | (dobj->GetFormat().GetType() == wxDF_FILENAME)) | |
8b53e5a2 | 736 | { |
0d2a2b60 | 737 | wxFileDataObject *file_object = (wxFileDataObject*) dobj; |
8b53e5a2 | 738 | |
0d2a2b60 | 739 | wxString text = file_object->GetFiles(); |
8b53e5a2 | 740 | |
2830bf19 RR |
741 | char *s = WXSTRINGCAST text; |
742 | ||
8b53e5a2 | 743 | gtk_widget_dnd_data_set( widget, |
0d2a2b60 | 744 | (GdkEvent*)event, |
2830bf19 RR |
745 | (unsigned char*) s, |
746 | (int) text.Length()+1 ); | |
8b53e5a2 | 747 | |
0d2a2b60 RR |
748 | source->m_retValue = wxDragCopy; |
749 | ||
750 | return; | |
8b53e5a2 RR |
751 | } |
752 | ||
0d2a2b60 RR |
753 | if ((strcmp(event->data_type,"text/plain") == 0) && |
754 | (dobj->GetFormat().GetType() == wxDF_TEXT)) | |
8b53e5a2 | 755 | { |
0d2a2b60 | 756 | wxTextDataObject *text_object = (wxTextDataObject*) dobj; |
8b53e5a2 | 757 | |
0d2a2b60 | 758 | wxString text = text_object->GetText(); |
8b53e5a2 | 759 | |
2830bf19 RR |
760 | char *s = WXSTRINGCAST text; |
761 | ||
8b53e5a2 | 762 | gtk_widget_dnd_data_set( widget, |
0d2a2b60 | 763 | (GdkEvent*)event, |
2830bf19 RR |
764 | (unsigned char*) s, |
765 | (int) text.Length()+1 ); | |
8b53e5a2 | 766 | |
0d2a2b60 RR |
767 | source->m_retValue = wxDragCopy; |
768 | ||
769 | return; | |
8b53e5a2 RR |
770 | } |
771 | ||
0d2a2b60 | 772 | if (dobj->GetFormat().GetType() == wxDF_PRIVATE) |
8b53e5a2 | 773 | { |
0d2a2b60 RR |
774 | wxPrivateDataObject *pdo = (wxPrivateDataObject*) dobj; |
775 | ||
776 | if (pdo->GetId() == event->data_type) | |
777 | { | |
778 | gtk_widget_dnd_data_set( widget, | |
779 | (GdkEvent*)event, | |
780 | (unsigned char*) pdo->GetData(), | |
781 | (int) pdo->GetSize() ); | |
782 | ||
783 | source->m_retValue = wxDragCopy; | |
784 | ||
785 | return; | |
786 | } | |
8b53e5a2 | 787 | } |
0d2a2b60 RR |
788 | |
789 | node = node->Next(); | |
8b53e5a2 | 790 | } |
ff7b1510 | 791 | } |
c801d85f | 792 | |
e3e65dac | 793 | wxDropSource::wxDropSource( wxWindow *win ) |
c801d85f | 794 | { |
ab8884ac | 795 | g_blockEventsOnDrag = TRUE; |
e3e65dac | 796 | |
ab8884ac RR |
797 | m_window = win; |
798 | m_widget = win->m_widget; | |
799 | if (win->m_wxwindow) m_widget = win->m_wxwindow; | |
c801d85f | 800 | |
0d2a2b60 | 801 | m_data = (wxDataBroker*) NULL; |
ab8884ac | 802 | m_retValue = wxDragCancel; |
e3e65dac | 803 | |
ab8884ac RR |
804 | m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); |
805 | m_goaheadCursor = wxCursor( wxCURSOR_HAND ); | |
ff7b1510 | 806 | } |
c801d85f | 807 | |
0d2a2b60 | 808 | wxDropSource::wxDropSource( wxDataObject *data, wxWindow *win ) |
c801d85f | 809 | { |
ab8884ac | 810 | g_blockEventsOnDrag = TRUE; |
e3e65dac | 811 | |
ab8884ac RR |
812 | m_window = win; |
813 | m_widget = win->m_widget; | |
814 | if (win->m_wxwindow) m_widget = win->m_wxwindow; | |
815 | m_retValue = wxDragCancel; | |
e3e65dac | 816 | |
0d2a2b60 RR |
817 | if (data) |
818 | { | |
819 | m_data = new wxDataBroker(); | |
820 | m_data->Add( data ); | |
821 | } | |
822 | else | |
823 | { | |
824 | m_data = (wxDataBroker*) NULL; | |
825 | } | |
e3e65dac | 826 | |
ab8884ac RR |
827 | m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); |
828 | m_goaheadCursor = wxCursor( wxCURSOR_HAND ); | |
ff7b1510 | 829 | } |
e3e65dac | 830 | |
0d2a2b60 RR |
831 | wxDropSource::wxDropSource( wxDataBroker *data, wxWindow *win ) |
832 | { | |
833 | g_blockEventsOnDrag = TRUE; | |
834 | ||
835 | m_window = win; | |
836 | m_widget = win->m_widget; | |
837 | if (win->m_wxwindow) m_widget = win->m_wxwindow; | |
838 | m_retValue = wxDragCancel; | |
839 | ||
840 | m_data = data; | |
841 | ||
842 | m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); | |
843 | m_goaheadCursor = wxCursor( wxCURSOR_HAND ); | |
844 | } | |
845 | ||
846 | void wxDropSource::SetData( wxDataObject *data ) | |
847 | { | |
848 | if (m_data) delete m_data; | |
849 | ||
850 | if (data) | |
851 | { | |
852 | m_data = new wxDataBroker(); | |
853 | m_data->Add( data ); | |
854 | } | |
855 | else | |
856 | { | |
857 | m_data = (wxDataBroker*) NULL; | |
858 | } | |
859 | } | |
860 | ||
861 | void wxDropSource::SetData( wxDataBroker *data ) | |
c801d85f | 862 | { |
0d2a2b60 RR |
863 | if (m_data) delete m_data; |
864 | ||
865 | m_data = data; | |
ff7b1510 | 866 | } |
c801d85f | 867 | |
e3e65dac | 868 | wxDropSource::~wxDropSource(void) |
c801d85f | 869 | { |
0d2a2b60 | 870 | if (m_data) delete m_data; |
e3e65dac | 871 | |
ab8884ac | 872 | g_blockEventsOnDrag = FALSE; |
ff7b1510 | 873 | } |
e3e65dac | 874 | |
46ccb510 | 875 | wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) |
e3e65dac | 876 | { |
ab8884ac RR |
877 | if (gdk_dnd.dnd_grabbed) return (wxDragResult) wxDragNone; |
878 | if (gdk_dnd.drag_really) return (wxDragResult) wxDragNone; | |
e3e65dac | 879 | |
ab8884ac | 880 | wxASSERT_MSG( m_data, "wxDragSource: no data" ); |
b6af8d80 | 881 | |
ab8884ac | 882 | if (!m_data) return (wxDragResult) wxDragNone; |
c801d85f | 883 | |
ab8884ac RR |
884 | static GtkWidget *drag_icon = (GtkWidget*) NULL; |
885 | static GtkWidget *drop_icon = (GtkWidget*) NULL; | |
a802c3a1 | 886 | |
ab8884ac | 887 | GdkPoint hotspot_1 = {0,-5 }; |
a802c3a1 | 888 | |
ab8884ac RR |
889 | if (!drag_icon) |
890 | { | |
a802c3a1 RR |
891 | drag_icon = shape_create_icon ( gv_xpm, |
892 | 440, 140, 0,0, GTK_WINDOW_POPUP); | |
893 | ||
894 | gtk_signal_connect (GTK_OBJECT (drag_icon), "destroy", | |
895 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), | |
896 | &drag_icon); | |
897 | ||
898 | gtk_widget_hide (drag_icon); | |
ab8884ac | 899 | } |
a802c3a1 | 900 | |
ab8884ac | 901 | GdkPoint hotspot_2 = {-5,-5}; |
a802c3a1 | 902 | |
ab8884ac RR |
903 | if (!drop_icon) |
904 | { | |
a802c3a1 RR |
905 | drop_icon = shape_create_icon ( page_xpm, |
906 | 440, 140, 0,0, GTK_WINDOW_POPUP); | |
907 | ||
908 | gtk_signal_connect (GTK_OBJECT (drop_icon), "destroy", | |
909 | GTK_SIGNAL_FUNC(gtk_widget_destroyed), | |
910 | &drop_icon); | |
911 | ||
912 | gtk_widget_hide (drop_icon); | |
ab8884ac | 913 | } |
b527aac5 | 914 | |
a802c3a1 | 915 | |
b527aac5 | 916 | gdk_dnd_set_drag_shape( drag_icon->window, |
a802c3a1 RR |
917 | &hotspot_1, |
918 | drop_icon->window, | |
919 | &hotspot_2); | |
920 | ||
921 | ||
ab8884ac | 922 | GdkWindowPrivate *wp = (GdkWindowPrivate*) m_widget->window; |
c801d85f | 923 | |
ab8884ac | 924 | RegisterWindow(); |
c801d85f | 925 | |
ab8884ac | 926 | gdk_dnd.drag_perhaps = TRUE; |
c801d85f | 927 | |
ab8884ac RR |
928 | gdk_dnd.dnd_drag_start.x = 5; |
929 | gdk_dnd.dnd_drag_start.y = 5; | |
930 | gdk_dnd.real_sw = wp; | |
c801d85f | 931 | |
ab8884ac RR |
932 | if (gdk_dnd.drag_startwindows) |
933 | { | |
934 | g_free( gdk_dnd.drag_startwindows ); | |
935 | gdk_dnd.drag_startwindows = (GdkWindow **) NULL; | |
936 | } | |
937 | gdk_dnd.drag_numwindows = gdk_dnd.drag_really = 0; | |
c801d85f | 938 | |
ab8884ac RR |
939 | XWindowAttributes dnd_winattr; |
940 | XGetWindowAttributes( gdk_display, wp->xwindow, &dnd_winattr ); | |
941 | wp->dnd_drag_savedeventmask = dnd_winattr.your_event_mask; | |
c801d85f | 942 | |
ab8884ac | 943 | gdk_dnd_drag_addwindow( m_widget->window ); |
c801d85f | 944 | |
ab8884ac RR |
945 | GdkEventDragBegin ev; |
946 | ev.type = GDK_DRAG_BEGIN; | |
947 | ev.window = m_widget->window; | |
948 | ev.u.allflags = 0; | |
949 | ev.u.flags.protocol_version = DND_PROTOCOL_VERSION; | |
c801d85f | 950 | |
ab8884ac | 951 | gdk_event_put( (GdkEvent*)&ev ); |
c801d85f | 952 | |
ab8884ac RR |
953 | XGrabPointer( gdk_display, wp->xwindow, False, |
954 | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, | |
955 | GrabModeAsync, GrabModeAsync, gdk_root_window, None, CurrentTime ); | |
c801d85f | 956 | |
ab8884ac | 957 | gdk_dnd_set_drag_cursors( m_defaultCursor.GetCursor(), m_goaheadCursor.GetCursor() ); |
c801d85f | 958 | |
ab8884ac RR |
959 | gdk_dnd.dnd_grabbed = TRUE; |
960 | gdk_dnd.drag_really = 1; | |
e3e65dac | 961 | |
ab8884ac RR |
962 | int x = 0; |
963 | int y = 0; | |
964 | wxGetMousePosition( &x, &y ); | |
e3e65dac | 965 | |
ab8884ac | 966 | gdk_dnd_display_drag_cursor( x, y, FALSE, TRUE ); |
b666df2c RR |
967 | |
968 | gs_currentDropSource = this; | |
969 | ||
ab8884ac | 970 | while (gdk_dnd.drag_really || gdk_dnd.drag_perhaps) wxYield(); |
b666df2c RR |
971 | |
972 | gs_currentDropSource = (wxDropSource*) NULL; | |
c801d85f | 973 | |
ab8884ac | 974 | UnregisterWindow(); |
e3e65dac | 975 | |
ab8884ac | 976 | g_blockEventsOnDrag = FALSE; |
30dea054 | 977 | |
ab8884ac | 978 | return m_retValue; |
ff7b1510 | 979 | } |
c801d85f | 980 | |
e3e65dac | 981 | void wxDropSource::RegisterWindow(void) |
c801d85f | 982 | { |
ab8884ac | 983 | if (!m_data) return; |
c801d85f | 984 | |
ab8884ac | 985 | wxString formats; |
e3e65dac | 986 | |
0d2a2b60 RR |
987 | wxNode *node = m_data->m_dataObjects.First(); |
988 | while (node) | |
e3e65dac | 989 | { |
0d2a2b60 RR |
990 | wxDataObject* dobj = (wxDataObject*) node->Data(); |
991 | ||
992 | switch (dobj->GetFormat().GetType()) | |
993 | { | |
994 | case wxDF_TEXT: | |
995 | { | |
996 | formats += "text/plain"; | |
997 | break; | |
998 | } | |
999 | case wxDF_FILENAME: | |
1000 | { | |
1001 | formats += "file:ALL"; | |
1002 | break; | |
1003 | } | |
1004 | case wxDF_PRIVATE: | |
1005 | { | |
1006 | wxPrivateDataObject* pdo = (wxPrivateDataObject*) m_data; | |
1007 | formats += pdo->GetId(); | |
1008 | break; | |
1009 | } | |
1010 | default: | |
1011 | break; | |
ab8884ac | 1012 | } |
0d2a2b60 | 1013 | node = node->Next(); |
e3e65dac | 1014 | } |
c801d85f | 1015 | |
ab8884ac | 1016 | char *str = WXSTRINGCAST formats; |
c801d85f | 1017 | |
ab8884ac | 1018 | gtk_widget_dnd_drag_set( m_widget, TRUE, &str, 1 ); |
c801d85f | 1019 | |
ab8884ac RR |
1020 | gtk_signal_connect( GTK_OBJECT(m_widget), "drag_request_event", |
1021 | GTK_SIGNAL_FUNC(gtk_drag_callback), (gpointer)this ); | |
ff7b1510 | 1022 | } |
c801d85f | 1023 | |
e3e65dac | 1024 | void wxDropSource::UnregisterWindow(void) |
c801d85f | 1025 | { |
ab8884ac | 1026 | if (!m_widget) return; |
c801d85f | 1027 | |
ab8884ac | 1028 | gtk_widget_dnd_drag_set( m_widget, FALSE, (gchar **) NULL, 0 ); |
e3e65dac | 1029 | |
ab8884ac | 1030 | gtk_signal_disconnect_by_data( GTK_OBJECT(m_widget), (gpointer)this ); |
ff7b1510 | 1031 | } |
f5368809 | 1032 | |
a802c3a1 RR |
1033 | |
1034 | /* | |
1035 | * Shaped Windows | |
1036 | */ | |
bbe0af5b | 1037 | static GdkWindow *root_win = (GdkWindow*) NULL; |
a802c3a1 RR |
1038 | |
1039 | typedef struct _cursoroffset {gint x,y;} CursorOffset; | |
1040 | ||
1041 | static void | |
1042 | shape_pressed (GtkWidget *widget, GdkEventButton *event) | |
1043 | { | |
1044 | CursorOffset *p; | |
1045 | ||
1046 | /* ignore double and triple click */ | |
1047 | if (event->type != GDK_BUTTON_PRESS) | |
1048 | return; | |
1049 | ||
b527aac5 | 1050 | p = (CursorOffset *)gtk_object_get_user_data (GTK_OBJECT(widget)); |
a802c3a1 RR |
1051 | p->x = (int) event->x; |
1052 | p->y = (int) event->y; | |
1053 | ||
1054 | gtk_grab_add (widget); | |
1055 | gdk_pointer_grab (widget->window, TRUE, | |
b527aac5 RR |
1056 | (GdkEventMask) |
1057 | (GDK_BUTTON_RELEASE_MASK | | |
1058 | GDK_BUTTON_MOTION_MASK | | |
1059 | GDK_POINTER_MOTION_HINT_MASK), | |
bbe0af5b RR |
1060 | (GdkWindow*)NULL, |
1061 | (GdkCursor*) NULL, 0); | |
a802c3a1 RR |
1062 | } |
1063 | ||
1064 | ||
1065 | static void | |
1066 | shape_released (GtkWidget *widget) | |
1067 | { | |
1068 | gtk_grab_remove (widget); | |
1069 | gdk_pointer_ungrab (0); | |
1070 | } | |
1071 | ||
1072 | static void | |
1073 | shape_motion (GtkWidget *widget, | |
b666df2c | 1074 | GdkEventMotion * /*event*/ ) |
a802c3a1 RR |
1075 | { |
1076 | gint xp, yp; | |
1077 | CursorOffset * p; | |
1078 | GdkModifierType mask; | |
1079 | ||
b527aac5 | 1080 | p = (CursorOffset *)gtk_object_get_user_data (GTK_OBJECT (widget)); |
a802c3a1 RR |
1081 | |
1082 | /* | |
1083 | * Can't use event->x / event->y here | |
1084 | * because I need absolute coordinates. | |
1085 | */ | |
b666df2c | 1086 | |
a802c3a1 RR |
1087 | gdk_window_get_pointer (root_win, &xp, &yp, &mask); |
1088 | gtk_widget_set_uposition (widget, xp - p->x, yp - p->y); | |
b666df2c RR |
1089 | |
1090 | if (gs_currentDropSource) gs_currentDropSource->GiveFeedback( wxDragCopy, FALSE ); | |
a802c3a1 RR |
1091 | } |
1092 | ||
1093 | GtkWidget * | |
1094 | shape_create_icon (char **data, | |
1095 | gint x, | |
1096 | gint y, | |
1097 | gint px, | |
1098 | gint py, | |
1099 | gint window_type) | |
1100 | { | |
1101 | GtkWidget *window; | |
1102 | GtkWidget *pixmap; | |
1103 | GtkWidget *fixed; | |
1104 | CursorOffset* icon_pos; | |
1105 | GdkGC* gc; | |
1106 | GdkBitmap *gdk_pixmap_mask; | |
1107 | GdkPixmap *gdk_pixmap; | |
1108 | GtkStyle *style; | |
1109 | ||
1110 | style = gtk_widget_get_default_style (); | |
1111 | gc = style->black_gc; | |
1112 | ||
1113 | /* | |
1114 | * GDK_WINDOW_TOPLEVEL works also, giving you a title border | |
1115 | */ | |
b527aac5 | 1116 | window = gtk_window_new ((GtkWindowType)window_type); |
a802c3a1 RR |
1117 | |
1118 | fixed = gtk_fixed_new (); | |
1119 | gtk_widget_set_usize (fixed, 100,100); | |
1120 | gtk_container_add (GTK_CONTAINER (window), fixed); | |
1121 | gtk_widget_show (fixed); | |
1122 | ||
1123 | gtk_widget_set_events (window, | |
1124 | gtk_widget_get_events (window) | | |
1125 | GDK_BUTTON_MOTION_MASK | | |
1126 | GDK_POINTER_MOTION_HINT_MASK | | |
1127 | GDK_BUTTON_PRESS_MASK); | |
1128 | ||
1129 | gtk_widget_realize (window); | |
1130 | ||
1131 | gdk_pixmap = gdk_pixmap_create_from_xpm_d (window->window, &gdk_pixmap_mask, | |
1132 | &style->bg[GTK_STATE_NORMAL], | |
1133 | (gchar**) data ); | |
1134 | ||
1135 | pixmap = gtk_pixmap_new (gdk_pixmap, gdk_pixmap_mask); | |
1136 | gtk_fixed_put (GTK_FIXED (fixed), pixmap, px,py); | |
1137 | gtk_widget_show (pixmap); | |
1138 | ||
1139 | gtk_widget_shape_combine_mask (window, gdk_pixmap_mask, px,py); | |
1140 | ||
1141 | ||
1142 | gtk_signal_connect (GTK_OBJECT (window), "button_press_event", | |
1143 | GTK_SIGNAL_FUNC (shape_pressed),NULL); | |
1144 | gtk_signal_connect (GTK_OBJECT (window), "button_release_event", | |
1145 | GTK_SIGNAL_FUNC (shape_released),NULL); | |
1146 | gtk_signal_connect (GTK_OBJECT (window), "motion_notify_event", | |
1147 | GTK_SIGNAL_FUNC (shape_motion),NULL); | |
1148 | ||
1149 | icon_pos = g_new (CursorOffset, 1); | |
1150 | gtk_object_set_user_data(GTK_OBJECT(window), icon_pos); | |
1151 | ||
1152 | gtk_widget_set_uposition (window, x, y); | |
1153 | gtk_widget_show (window); | |
1154 | ||
1155 | return window; | |
1156 | } | |
1157 | ||
f5368809 RR |
1158 | #endif |
1159 | // NEW_GTK_DND_CODE | |
1160 | ||
ac57418f RR |
1161 | #endif |
1162 | ||
1163 | // wxUSE_DRAG_AND_DROP |