1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDropTarget class
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dnd.h"
16 #if wxUSE_DRAG_AND_DROP
18 #include "wx/window.h"
20 #include "wx/gdicmn.h"
26 #include "gdk/gdkprivate.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 extern bool g_blockEventsOnDrag
;
36 #ifdef NEW_GTK_DND_CODE
38 #include "gtk/gtkdnd.h"
39 #include "gtk/gtkselection.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 static void target_drag_leave( GtkWidget
*WXUNUSED(widget
),
46 GdkDragContext
*WXUNUSED(context
),
47 guint
WXUNUSED(time
) )
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 static gboolean
target_drag_motion( GtkWidget
*WXUNUSED(widget
),
57 GdkDragContext
*context
,
62 printf( "motion.\n" );
63 gdk_drag_status( context
, context
->suggested_action
, time
);
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 static gboolean
target_drag_drop( GtkWidget
*widget
,
72 GdkDragContext
*context
,
77 printf( "drop at: %d,%d.\n", x
, y
);
81 gtk_drag_get_data( widget
,
83 GPOINTER_TO_INT (context
->targets
->data
),
89 // ----------------------------------------------------------------------------
90 // "drag_data_received"
91 // ----------------------------------------------------------------------------
93 static void target_drag_data_received( GtkWidget
*WXUNUSED(widget
),
94 GdkDragContext
*context
,
97 GtkSelectionData
*data
,
101 printf( "data receive at: %d,%d.\n", x
, y
);
103 if ((data
->length
>= 0) && (data
->format
== 8))
105 wxString str
= (const char*)data
->data
;
106 printf( "Received %s\n.", WXSTRINGCAST str
);
107 gtk_drag_finish( context
, TRUE
, FALSE
, time
);
111 gtk_drag_finish (context
, FALSE
, FALSE
, time
);
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 wxDropTarget::wxDropTarget()
122 wxDropTarget::~wxDropTarget()
126 void wxDropTarget::UnregisterWidget( GtkWidget
*widget
)
128 wxCHECK_RET( widget
!= NULL
, "unregister widget is NULL" );
130 gtk_drag_dest_set( widget
,
132 (GtkTargetEntry
*) NULL
,
136 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
137 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
139 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
140 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
142 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
143 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
145 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
146 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
149 void wxDropTarget::RegisterWidget( GtkWidget
*widget
)
151 wxCHECK_RET( widget
!= NULL
, "register widget is NULL" );
153 GtkTargetEntry format
;
159 for ( size_t i
= 0; i
< GetFormatCount(); i
++ )
161 wxDataFormat df
= GetFormat( i
);
165 format
.target
= "text/plain";
169 format
.target
= "file:ALL";
173 wxPrivateDropTarget
*pdt
= (wxPrivateDropTarget
*)this;
174 strcpy( buf
, WXSTRINGCAST pdt
->GetID() );
182 wxASSERT_MSG( valid
!= 0, "No valid DnD format supported." );
184 gtk_drag_dest_set( widget
,
185 GTK_DEST_DEFAULT_ALL
,
188 (GdkDragAction
)(GDK_ACTION_COPY
| GDK_ACTION_MOVE
) );
190 gtk_signal_connect( GTK_OBJECT(widget
), "drag_leave",
191 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
193 gtk_signal_connect( GTK_OBJECT(widget
), "drag_motion",
194 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
196 gtk_signal_connect( GTK_OBJECT(widget
), "drag_drop",
197 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
199 gtk_signal_connect( GTK_OBJECT(widget
), "drag_data_received",
200 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
203 // ----------------------------------------------------------------------------
205 // ----------------------------------------------------------------------------
207 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) )
209 OnDropText( x
, y
, (const char*)data
);
213 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz
)
215 printf( "Got dropped text: %s.\n", psz
);
216 printf( "At x: %d, y: %d.\n", (int)x
, (int)y
);
220 size_t wxTextDropTarget::GetFormatCount() const
225 wxDataFormat
wxTextDropTarget::GetFormat(size_t WXUNUSED(n
)) const
230 // ----------------------------------------------------------------------------
232 // ----------------------------------------------------------------------------
234 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] )
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
++)
240 printf( aszFiles
[i
] );
246 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size
)
249 char *text
= (char*) data
;
250 for (size_t i
= 0; i
< size
; i
++)
251 if (text
[i
] == 0) number
++;
253 if (number
== 0) return TRUE
;
255 char **files
= new char*[number
];
258 for (size_t i
= 0; i
< number
; i
++)
261 int len
= strlen( text
);
265 bool ret
= OnDropFiles( x
, y
, 1, files
);
272 size_t wxFileDropTarget::GetFormatCount() const
277 wxDataFormat
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const
279 return wxDF_FILENAME
;
282 //-------------------------------------------------------------------------
284 //-------------------------------------------------------------------------
286 wxDropSource::wxDropSource( wxWindow
*win
)
288 g_blockEventsOnDrag
= TRUE
;
291 m_widget
= win
->m_widget
;
292 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
294 m_data
= (wxDataObject
*) NULL
;
295 m_retValue
= wxDragCancel
;
297 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
298 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
301 wxDropSource::wxDropSource( wxDataObject
&data
, wxWindow
*win
)
303 g_blockEventsOnDrag
= TRUE
;
306 m_widget
= win
->m_widget
;
307 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
308 m_retValue
= wxDragCancel
;
312 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
313 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
316 void wxDropSource::SetData( wxDataObject
&data
)
321 wxDropSource::~wxDropSource(void)
323 // if (m_data) delete m_data;
325 g_blockEventsOnDrag
= FALSE
;
328 wxDragResult
wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove
) )
330 wxASSERT_MSG( m_data
, "wxDragSource: no data" );
332 if (!m_data
) return (wxDragResult
) wxDragNone
;
333 if (m_data
->GetDataSize() == 0) return (wxDragResult
) wxDragNone
;
341 g_blockEventsOnDrag
= FALSE
;
346 void wxDropSource::RegisterWindow(void)
352 wxDataFormat df
= m_data
->GetPreferredFormat();
357 formats
+= "text/plain";
360 formats
+= "file:ALL";
366 char *str
= WXSTRINGCAST formats
;
371 void wxDropSource::UnregisterWindow(void)
373 if (!m_widget
) return;
381 GtkWidget
*shape_create_icon (char **data
,
389 static char * gv_xpm
[] = {
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. ..... ..... ",
430 static char * page_xpm
[] = {
431 /* width height ncolors chars_per_pixel */
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 " ......................... "};
474 //-----------------------------------------------------------------------------
476 //-----------------------------------------------------------------------------
478 wxDropSource
*gs_currentDropSource
= (wxDropSource
*) NULL
;
480 //-----------------------------------------------------------------------------
481 // "drop_enter_event"
482 //-----------------------------------------------------------------------------
484 static void gtk_target_enter_callback( GtkWidget
*WXUNUSED(widget
),
485 GdkEventDropEnter
*WXUNUSED(event
),
486 wxDropTarget
*target
)
492 //-----------------------------------------------------------------------------
493 // "drop_leave_event"
494 //-----------------------------------------------------------------------------
496 static void gtk_target_leave_callback( GtkWidget
*WXUNUSED(widget
),
497 GdkEventDropLeave
*WXUNUSED(event
),
498 wxDropTarget
*target
)
504 //-----------------------------------------------------------------------------
505 // "drop_data_available_event"
506 //-----------------------------------------------------------------------------
508 static void gtk_target_callback( GtkWidget
*widget
,
509 GdkEventDropDataAvailable
*event
,
510 wxDropTarget
*target
)
516 gdk_window_get_pointer( widget
->window
, &x
, &y
, (GdkModifierType
*) NULL
);
518 printf( "Drop data is of type %s.\n", event->data_type );
520 target
->OnDrop( x
, y
, (const void*)event
->data
, (size_t)event
->data_numbytes
);
524 g_free (event->data);
525 g_free (event->data_type);
529 // ----------------------------------------------------------------------------
531 // ----------------------------------------------------------------------------
533 wxDropTarget::wxDropTarget()
535 m_format
= (wxDataFormat
*) NULL
;
538 wxDropTarget::~wxDropTarget()
540 if (m_format
) delete m_format
;
543 wxDataFormat
&wxDropTarget::GetFormat(size_t n
) const
548 void wxDropTarget::UnregisterWidget( GtkWidget
*widget
)
552 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
553 GTK_SIGNAL_FUNC(gtk_target_callback
), (gpointer
) this );
555 gtk_widget_dnd_drop_set( widget
, FALSE
, (gchar
**) NULL
, 0, FALSE
);
558 void wxDropTarget::RegisterWidget( GtkWidget
*widget
)
563 for ( size_t i
= 0; i
< GetFormatCount(); i
++ )
565 switch (GetFormat(i
).GetType())
569 if (i
> 0) formats
+= ";";
570 formats
+= "text/plain";
576 if (i
> 0) formats
+= ";";
577 formats
+= "file:ALL";
583 if (i
> 0) formats
+= ";";
584 wxPrivateDropTarget
*pdt
= (wxPrivateDropTarget
*)this;
585 formats
+= pdt
->GetId();
594 char *str
= WXSTRINGCAST formats
;
596 gtk_widget_dnd_drop_set( widget
, TRUE
, &str
, valid
, FALSE
);
598 gtk_signal_connect( GTK_OBJECT(widget
), "drop_data_available_event",
599 GTK_SIGNAL_FUNC(gtk_target_callback
), (gpointer
) this );
601 gtk_signal_connect( GTK_OBJECT(widget
), "drop_enter_event",
602 GTK_SIGNAL_FUNC(gtk_target_enter_callback
), (gpointer
) this );
604 gtk_signal_connect( GTK_OBJECT(widget
), "drop_leave_event",
605 GTK_SIGNAL_FUNC(gtk_target_leave_callback
), (gpointer
) this );
608 // ----------------------------------------------------------------------------
610 // ----------------------------------------------------------------------------
612 wxTextDropTarget::wxTextDropTarget()
614 m_format
= new wxDataFormat( wxDF_TEXT
);
617 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) )
619 OnDropText( x
, y
, (const char*)data
);
623 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz
)
626 printf( "Got dropped text: %s.\n", psz );
627 printf( "At x: %d, y: %d.\n", (int)x, (int)y );
632 size_t wxTextDropTarget::GetFormatCount() const
637 // ----------------------------------------------------------------------------
638 // wxPrivateDropTarget
639 // ----------------------------------------------------------------------------
641 wxPrivateDropTarget::wxPrivateDropTarget()
643 m_id
= wxTheApp
->GetAppName();
644 m_format
= new wxDataFormat( m_id
);
647 void wxPrivateDropTarget::SetId( const wxString
& id
)
650 m_format
->SetId( id
);
653 size_t wxPrivateDropTarget::GetFormatCount() const
658 // ----------------------------------------------------------------------------
660 // ----------------------------------------------------------------------------
662 wxFileDropTarget::wxFileDropTarget()
664 m_format
= new wxDataFormat( wxDF_FILENAME
);
667 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] )
669 printf( "Got %d dropped files.\n", (int)nFiles
);
670 printf( "At x: %d, y: %d.\n", (int)x
, (int)y
);
672 for (size_t i
= 0; i
< nFiles
; i
++)
674 printf( aszFiles
[i
] );
681 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size
)
684 char *text
= (char*) data
;
685 for (size_t i
= 0; i
< size
; i
++)
686 if (text
[i
] == 0) number
++;
688 if (number
== 0) return TRUE
;
690 char **files
= new char*[number
];
693 for (size_t i
= 0; i
< number
; i
++)
696 int len
= strlen( text
);
700 bool ret
= OnDropFiles( x
, y
, 1, files
);
707 size_t wxFileDropTarget::GetFormatCount() const
712 //-------------------------------------------------------------------------
714 //-------------------------------------------------------------------------
717 shape_motion (GtkWidget
*widget
,
718 GdkEventMotion
* /*event*/);
720 //-----------------------------------------------------------------------------
721 // "drag_request_event"
722 //-----------------------------------------------------------------------------
724 void gtk_drag_callback( GtkWidget
*widget
, GdkEventDragRequest
*event
, wxDropSource
*source
)
726 wxDataBroker
*data
= source
->m_data
;
730 wxNode
*node
= data
->m_dataObjects
.First();
732 wxDataObject
*dobj
= (wxDataObject
*) node
->Data();
734 if ((strcmp(event
->data_type
,"file:ALL") == 0) &&
735 (dobj
->GetFormat().GetType() == wxDF_FILENAME
))
737 wxFileDataObject
*file_object
= (wxFileDataObject
*) dobj
;
739 wxString text
= file_object
->GetFiles();
741 char *s
= WXSTRINGCAST text
;
743 gtk_widget_dnd_data_set( widget
,
746 (int) text
.Length()+1 );
748 source
->m_retValue
= wxDragCopy
;
753 if ((strcmp(event
->data_type
,"text/plain") == 0) &&
754 (dobj
->GetFormat().GetType() == wxDF_TEXT
))
756 wxTextDataObject
*text_object
= (wxTextDataObject
*) dobj
;
758 wxString text
= text_object
->GetText();
760 char *s
= WXSTRINGCAST text
;
762 gtk_widget_dnd_data_set( widget
,
765 (int) text
.Length()+1 );
767 source
->m_retValue
= wxDragCopy
;
772 if (dobj
->GetFormat().GetType() == wxDF_PRIVATE
)
774 wxPrivateDataObject
*pdo
= (wxPrivateDataObject
*) dobj
;
776 if (pdo
->GetId() == event
->data_type
)
778 gtk_widget_dnd_data_set( widget
,
780 (unsigned char*) pdo
->GetData(),
781 (int) pdo
->GetSize() );
783 source
->m_retValue
= wxDragCopy
;
793 wxDropSource::wxDropSource( wxWindow
*win
)
795 g_blockEventsOnDrag
= TRUE
;
798 m_widget
= win
->m_widget
;
799 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
801 m_data
= (wxDataBroker
*) NULL
;
802 m_retValue
= wxDragCancel
;
804 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
805 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
808 wxDropSource::wxDropSource( wxDataObject
*data
, wxWindow
*win
)
810 g_blockEventsOnDrag
= TRUE
;
813 m_widget
= win
->m_widget
;
814 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
815 m_retValue
= wxDragCancel
;
819 m_data
= new wxDataBroker();
824 m_data
= (wxDataBroker
*) NULL
;
827 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
828 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
831 wxDropSource::wxDropSource( wxDataBroker
*data
, wxWindow
*win
)
833 g_blockEventsOnDrag
= TRUE
;
836 m_widget
= win
->m_widget
;
837 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
838 m_retValue
= wxDragCancel
;
842 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
843 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
846 void wxDropSource::SetData( wxDataObject
*data
)
848 if (m_data
) delete m_data
;
852 m_data
= new wxDataBroker();
857 m_data
= (wxDataBroker
*) NULL
;
861 void wxDropSource::SetData( wxDataBroker
*data
)
863 if (m_data
) delete m_data
;
868 wxDropSource::~wxDropSource(void)
870 if (m_data
) delete m_data
;
872 g_blockEventsOnDrag
= FALSE
;
875 wxDragResult
wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove
) )
877 if (gdk_dnd
.dnd_grabbed
) return (wxDragResult
) wxDragNone
;
878 if (gdk_dnd
.drag_really
) return (wxDragResult
) wxDragNone
;
880 wxASSERT_MSG( m_data
, "wxDragSource: no data" );
882 if (!m_data
) return (wxDragResult
) wxDragNone
;
884 static GtkWidget
*drag_icon
= (GtkWidget
*) NULL
;
885 static GtkWidget
*drop_icon
= (GtkWidget
*) NULL
;
887 GdkPoint hotspot_1
= {0,-5 };
891 drag_icon
= shape_create_icon ( gv_xpm
,
892 440, 140, 0,0, GTK_WINDOW_POPUP
);
894 gtk_signal_connect (GTK_OBJECT (drag_icon
), "destroy",
895 GTK_SIGNAL_FUNC(gtk_widget_destroyed
),
898 gtk_widget_hide (drag_icon
);
901 GdkPoint hotspot_2
= {-5,-5};
905 drop_icon
= shape_create_icon ( page_xpm
,
906 440, 140, 0,0, GTK_WINDOW_POPUP
);
908 gtk_signal_connect (GTK_OBJECT (drop_icon
), "destroy",
909 GTK_SIGNAL_FUNC(gtk_widget_destroyed
),
912 gtk_widget_hide (drop_icon
);
916 gdk_dnd_set_drag_shape( drag_icon
->window
,
922 GdkWindowPrivate
*wp
= (GdkWindowPrivate
*) m_widget
->window
;
926 gdk_dnd
.drag_perhaps
= TRUE
;
928 gdk_dnd
.dnd_drag_start
.x
= 5;
929 gdk_dnd
.dnd_drag_start
.y
= 5;
930 gdk_dnd
.real_sw
= wp
;
932 if (gdk_dnd
.drag_startwindows
)
934 g_free( gdk_dnd
.drag_startwindows
);
935 gdk_dnd
.drag_startwindows
= (GdkWindow
**) NULL
;
937 gdk_dnd
.drag_numwindows
= gdk_dnd
.drag_really
= 0;
939 XWindowAttributes dnd_winattr
;
940 XGetWindowAttributes( gdk_display
, wp
->xwindow
, &dnd_winattr
);
941 wp
->dnd_drag_savedeventmask
= dnd_winattr
.your_event_mask
;
943 gdk_dnd_drag_addwindow( m_widget
->window
);
945 GdkEventDragBegin ev
;
946 ev
.type
= GDK_DRAG_BEGIN
;
947 ev
.window
= m_widget
->window
;
949 ev
.u
.flags
.protocol_version
= DND_PROTOCOL_VERSION
;
951 gdk_event_put( (GdkEvent
*)&ev
);
953 XGrabPointer( gdk_display
, wp
->xwindow
, False
,
954 ButtonMotionMask
| ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
,
955 GrabModeAsync
, GrabModeAsync
, gdk_root_window
, None
, CurrentTime
);
957 gdk_dnd_set_drag_cursors( m_defaultCursor
.GetCursor(), m_goaheadCursor
.GetCursor() );
959 gdk_dnd
.dnd_grabbed
= TRUE
;
960 gdk_dnd
.drag_really
= 1;
964 wxGetMousePosition( &x
, &y
);
966 gdk_dnd_display_drag_cursor( x
, y
, FALSE
, TRUE
);
968 gs_currentDropSource
= this;
970 while (gdk_dnd
.drag_really
|| gdk_dnd
.drag_perhaps
) wxYield();
972 gs_currentDropSource
= (wxDropSource
*) NULL
;
976 g_blockEventsOnDrag
= FALSE
;
981 void wxDropSource::RegisterWindow(void)
987 wxNode
*node
= m_data
->m_dataObjects
.First();
990 wxDataObject
* dobj
= (wxDataObject
*) node
->Data();
992 switch (dobj
->GetFormat().GetType())
996 formats
+= "text/plain";
1001 formats
+= "file:ALL";
1006 wxPrivateDataObject
* pdo
= (wxPrivateDataObject
*) m_data
;
1007 formats
+= pdo
->GetId();
1013 node
= node
->Next();
1016 char *str
= WXSTRINGCAST formats
;
1018 gtk_widget_dnd_drag_set( m_widget
, TRUE
, &str
, 1 );
1020 gtk_signal_connect( GTK_OBJECT(m_widget
), "drag_request_event",
1021 GTK_SIGNAL_FUNC(gtk_drag_callback
), (gpointer
)this );
1024 void wxDropSource::UnregisterWindow(void)
1026 if (!m_widget
) return;
1028 gtk_widget_dnd_drag_set( m_widget
, FALSE
, (gchar
**) NULL
, 0 );
1030 gtk_signal_disconnect_by_data( GTK_OBJECT(m_widget
), (gpointer
)this );
1037 static GdkWindow
*root_win
= (GdkWindow
*) NULL
;
1039 typedef struct _cursoroffset
{gint x
,y
;} CursorOffset
;
1042 shape_pressed (GtkWidget
*widget
, GdkEventButton
*event
)
1046 /* ignore double and triple click */
1047 if (event
->type
!= GDK_BUTTON_PRESS
)
1050 p
= (CursorOffset
*)gtk_object_get_user_data (GTK_OBJECT(widget
));
1051 p
->x
= (int) event
->x
;
1052 p
->y
= (int) event
->y
;
1054 gtk_grab_add (widget
);
1055 gdk_pointer_grab (widget
->window
, TRUE
,
1057 (GDK_BUTTON_RELEASE_MASK
|
1058 GDK_BUTTON_MOTION_MASK
|
1059 GDK_POINTER_MOTION_HINT_MASK
),
1061 (GdkCursor
*) NULL
, 0);
1066 shape_released (GtkWidget
*widget
)
1068 gtk_grab_remove (widget
);
1069 gdk_pointer_ungrab (0);
1073 shape_motion (GtkWidget
*widget
,
1074 GdkEventMotion
* /*event*/ )
1078 GdkModifierType mask
;
1080 p
= (CursorOffset
*)gtk_object_get_user_data (GTK_OBJECT (widget
));
1083 * Can't use event->x / event->y here
1084 * because I need absolute coordinates.
1087 gdk_window_get_pointer (root_win
, &xp
, &yp
, &mask
);
1088 gtk_widget_set_uposition (widget
, xp
- p
->x
, yp
- p
->y
);
1090 if (gs_currentDropSource
) gs_currentDropSource
->GiveFeedback( wxDragCopy
, FALSE
);
1094 shape_create_icon (char **data
,
1104 CursorOffset
* icon_pos
;
1106 GdkBitmap
*gdk_pixmap_mask
;
1107 GdkPixmap
*gdk_pixmap
;
1110 style
= gtk_widget_get_default_style ();
1111 gc
= style
->black_gc
;
1114 * GDK_WINDOW_TOPLEVEL works also, giving you a title border
1116 window
= gtk_window_new ((GtkWindowType
)window_type
);
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
);
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
);
1129 gtk_widget_realize (window
);
1131 gdk_pixmap
= gdk_pixmap_create_from_xpm_d (window
->window
, &gdk_pixmap_mask
,
1132 &style
->bg
[GTK_STATE_NORMAL
],
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
);
1139 gtk_widget_shape_combine_mask (window
, gdk_pixmap_mask
, px
,py
);
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
);
1149 icon_pos
= g_new (CursorOffset
, 1);
1150 gtk_object_set_user_data(GTK_OBJECT(window
), icon_pos
);
1152 gtk_widget_set_uposition (window
, x
, y
);
1153 gtk_widget_show (window
);
1163 // wxUSE_DRAG_AND_DROP