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
, "applications/" );
175 strcat( buf
, WXSTRINGCAST pdt
->GetID() );
183 wxASSERT_MSG( valid
!= 0, "No valid DnD format supported." );
185 gtk_drag_dest_set( widget
,
186 GTK_DEST_DEFAULT_ALL
,
189 (GdkDragAction
)(GDK_ACTION_COPY
| GDK_ACTION_MOVE
) );
191 gtk_signal_connect( GTK_OBJECT(widget
), "drag_leave",
192 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
194 gtk_signal_connect( GTK_OBJECT(widget
), "drag_motion",
195 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
197 gtk_signal_connect( GTK_OBJECT(widget
), "drag_drop",
198 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
200 gtk_signal_connect( GTK_OBJECT(widget
), "drag_data_received",
201 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
208 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) )
210 OnDropText( x
, y
, (const char*)data
);
214 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz
)
216 printf( "Got dropped text: %s.\n", psz
);
217 printf( "At x: %d, y: %d.\n", (int)x
, (int)y
);
221 size_t wxTextDropTarget::GetFormatCount() const
226 wxDataFormat
wxTextDropTarget::GetFormat(size_t WXUNUSED(n
)) const
231 // ----------------------------------------------------------------------------
233 // ----------------------------------------------------------------------------
235 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] )
237 printf( "Got %d dropped files.\n", (int)nFiles
);
238 printf( "At x: %d, y: %d.\n", (int)x
, (int)y
);
239 for (size_t i
= 0; i
< nFiles
; i
++)
241 printf( aszFiles
[i
] );
247 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size
)
250 char *text
= (char*) data
;
251 for (size_t i
= 0; i
< size
; i
++)
252 if (text
[i
] == 0) number
++;
254 if (number
== 0) return TRUE
;
256 char **files
= new char*[number
];
259 for (size_t i
= 0; i
< number
; i
++)
262 int len
= strlen( text
);
266 bool ret
= OnDropFiles( x
, y
, 1, files
);
273 size_t wxFileDropTarget::GetFormatCount() const
278 wxDataFormat
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const
280 return wxDF_FILENAME
;
283 //-------------------------------------------------------------------------
285 //-------------------------------------------------------------------------
287 wxDropSource::wxDropSource( wxWindow
*win
)
289 g_blockEventsOnDrag
= TRUE
;
292 m_widget
= win
->m_widget
;
293 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
295 m_data
= (wxDataObject
*) NULL
;
296 m_retValue
= wxDragCancel
;
298 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
299 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
302 wxDropSource::wxDropSource( wxDataObject
&data
, wxWindow
*win
)
304 g_blockEventsOnDrag
= TRUE
;
307 m_widget
= win
->m_widget
;
308 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
309 m_retValue
= wxDragCancel
;
313 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
314 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
317 void wxDropSource::SetData( wxDataObject
&data
)
322 wxDropSource::~wxDropSource(void)
324 // if (m_data) delete m_data;
326 g_blockEventsOnDrag
= FALSE
;
329 wxDragResult
wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove
) )
331 wxASSERT_MSG( m_data
, "wxDragSource: no data" );
333 if (!m_data
) return (wxDragResult
) wxDragNone
;
334 if (m_data
->GetDataSize() == 0) return (wxDragResult
) wxDragNone
;
342 g_blockEventsOnDrag
= FALSE
;
347 void wxDropSource::RegisterWindow(void)
353 wxDataFormat df
= m_data
->GetPreferredFormat();
358 formats
+= "text/plain";
361 formats
+= "file:ALL";
367 char *str
= WXSTRINGCAST formats
;
372 void wxDropSource::UnregisterWindow(void)
374 if (!m_widget
) return;
382 GtkWidget
*shape_create_icon (char **data
,
390 static char * gv_xpm
[] = {
402 " .XXXXXXXXXXXXXX. ",
403 " .XXX..XXXX..XXX. ",
404 " ....XX....XX....XX. ",
405 " .XXX.XXX..XXXX..XXX.... ",
406 " .XXXXXXXXXXXXXXXXXXX.XXX. ",
407 " .XXXXXXXXXXXXXXXXXXXXXXXX. ",
408 " .XXXXXXXXXXXXXXXXXXXXXXXX. ",
409 " ..XXXXXXXXXXXXXXXXXXXXXX. ",
410 " .XXXXXXXXXXXXXXXXXX... ",
411 " ..XXXXXXXXXXXXXXXX. ",
412 " .XXXXXXXXXXXXXXXX. ",
413 " .XXXXXXXXXXXXXXXX. ",
414 " .XXXXXXXXXXXXXXXXX. ",
415 " .XXXXXXXXXXXXXXXXX. ",
416 " .XXXXXXXXXXXXXXXXXX. ",
417 " .XXXXXXXXXXXXXXXXXXX. ",
418 " .XXXXXXXXXXXXXXXXXXXXX. ",
419 " .XXXXXXXXXXXXXX.XXXXXXX. ",
420 " .XXXXXXX.XXXXXXX.XXXXXXX. ",
421 " .XXXXXXXX.XXXXXXX.XXXXXXX. ",
422 " .XXXXXXX...XXXXX...XXXXX. ",
423 " .XXXXXXX. ..... ..... ",
431 static char * page_xpm
[] = {
432 /* width height ncolors chars_per_pixel */
441 " ................... ",
442 " .XXXXXXXXXXXXXXXXX.. ",
443 " .XXXXXXXXXXXXXXXXX.o. ",
444 " .XXXXXXXXXXXXXXXXX.oo. ",
445 " .XXXXXXXXXXXXXXXXX.ooo. ",
446 " .XXXXXXXXXXXXXXXXX.oooo. ",
447 " .XXXXXXXXXXXXXXXXX....... ",
448 " .XXXXXOOOOOOOOOOXXXooooo. ",
449 " .XXXXXXXXXXXXXXXXXXooooo. ",
450 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
451 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
452 " .XXXXXXXOOOOOOOOOXXXXXXX. ",
453 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
454 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
455 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
456 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
457 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
458 " .XXXXXXXOOOOOOOOOXXXXXXX. ",
459 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
460 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
461 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
462 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
463 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
464 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
465 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
466 " .XXXXXOOOOOOOXXXXXXXXXXX. ",
467 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
468 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
469 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
470 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
471 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
472 " ......................... "};
475 //-----------------------------------------------------------------------------
476 // "drop_data_available_event"
477 //-----------------------------------------------------------------------------
479 static void gtk_target_callback( GtkWidget
*widget
,
480 GdkEventDropDataAvailable
*event
,
481 wxDropTarget
*target
)
487 gdk_window_get_pointer( widget
->window
, &x
, &y
, (GdkModifierType
*) NULL
);
489 printf( "Drop data is of type %s.\n", event->data_type );
491 target
->OnDrop( x
, y
, (const void*)event
->data
, (size_t)event
->data_numbytes
);
495 g_free (event->data);
496 g_free (event->data_type);
500 // ----------------------------------------------------------------------------
502 // ----------------------------------------------------------------------------
504 wxDropTarget::wxDropTarget()
508 wxDropTarget::~wxDropTarget()
512 void wxDropTarget::UnregisterWidget( GtkWidget
*widget
)
516 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
517 GTK_SIGNAL_FUNC(gtk_target_callback
), (gpointer
) this );
519 gtk_widget_dnd_drop_set( widget
, FALSE
, (gchar
**) NULL
, 0, FALSE
);
522 void wxDropTarget::RegisterWidget( GtkWidget
*widget
)
527 for ( size_t i
= 0; i
< GetFormatCount(); i
++ )
529 wxDataFormat df
= GetFormat( i
);
534 if (i
> 0) formats
+= ";";
535 formats
+= "text/plain";
541 if (i
> 0) formats
+= ";";
542 formats
+= "file:ALL";
548 if (i
> 0) formats
+= ";";
549 wxPrivateDropTarget
*pdt
= (wxPrivateDropTarget
*)this;
550 formats
+= "applications/";
551 formats
+= pdt
->GetId();
560 char *str
= WXSTRINGCAST formats
;
562 gtk_widget_dnd_drop_set( widget
, TRUE
, &str
, valid
, FALSE
);
564 gtk_signal_connect( GTK_OBJECT(widget
), "drop_data_available_event",
565 GTK_SIGNAL_FUNC(gtk_target_callback
), (gpointer
) this );
568 // ----------------------------------------------------------------------------
570 // ----------------------------------------------------------------------------
572 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) )
574 OnDropText( x
, y
, (const char*)data
);
578 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz
)
581 printf( "Got dropped text: %s.\n", psz );
582 printf( "At x: %d, y: %d.\n", (int)x, (int)y );
587 size_t wxTextDropTarget::GetFormatCount() const
592 wxDataFormat
wxTextDropTarget::GetFormat(size_t WXUNUSED(n
)) const
597 // ----------------------------------------------------------------------------
598 // wxPrivateDropTarget
599 // ----------------------------------------------------------------------------
601 wxPrivateDropTarget::wxPrivateDropTarget()
603 m_id
= wxTheApp
->GetAppName();
606 size_t wxPrivateDropTarget::GetFormatCount() const
611 wxDataFormat
wxPrivateDropTarget::GetFormat(size_t WXUNUSED(n
)) const
616 // ----------------------------------------------------------------------------
618 // ----------------------------------------------------------------------------
620 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] )
622 printf( "Got %d dropped files.\n", (int)nFiles
);
623 printf( "At x: %d, y: %d.\n", (int)x
, (int)y
);
625 for (size_t i
= 0; i
< nFiles
; i
++)
627 printf( aszFiles
[i
] );
634 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size
)
637 char *text
= (char*) data
;
638 for (size_t i
= 0; i
< size
; i
++)
639 if (text
[i
] == 0) number
++;
641 if (number
== 0) return TRUE
;
643 char **files
= new char*[number
];
646 for (size_t i
= 0; i
< number
; i
++)
649 int len
= strlen( text
);
653 bool ret
= OnDropFiles( x
, y
, 1, files
);
660 size_t wxFileDropTarget::GetFormatCount() const
665 wxDataFormat
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const
667 return wxDF_FILENAME
;
670 //-------------------------------------------------------------------------
672 //-------------------------------------------------------------------------
675 shape_motion (GtkWidget
*widget
,
676 GdkEventMotion */
*event*/
);
678 //-----------------------------------------------------------------------------
681 void gtk_drag_callback( GtkWidget
*widget
, GdkEvent
*event
, wxDropSource
*source
)
683 wxDataObject
*data
= source
->m_data
;
685 switch (data
->GetFormat())
689 wxPrivateDataObject
*pdo
= (wxPrivateDataObject
*) data
;
691 gtk_widget_dnd_data_set( widget
,
693 (unsigned char*) pdo
->GetData(),
694 (int) pdo
->GetDataSize() );
700 wxTextDataObject
*text_object
= (wxTextDataObject
*) data
;
702 wxString text
= text_object
->GetText();
704 char *s
= WXSTRINGCAST text
;
706 gtk_widget_dnd_data_set( widget
,
709 (int) text
.Length()+1 );
716 wxFileDataObject
*file_object
= (wxFileDataObject
*) data
;
718 wxString text
= file_object
->GetFiles();
720 char *s
= WXSTRINGCAST text
;
722 gtk_widget_dnd_data_set( widget
,
725 (int) text
.Length()+1 );
736 source
->m_retValue
= wxDragCopy
;
739 wxDropSource::wxDropSource( wxWindow
*win
)
741 g_blockEventsOnDrag
= TRUE
;
744 m_widget
= win
->m_widget
;
745 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
747 m_data
= (wxDataObject
*) NULL
;
748 m_retValue
= wxDragCancel
;
750 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
751 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
754 wxDropSource::wxDropSource( wxDataObject
&data
, wxWindow
*win
)
756 g_blockEventsOnDrag
= TRUE
;
759 m_widget
= win
->m_widget
;
760 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
761 m_retValue
= wxDragCancel
;
765 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
766 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
769 void wxDropSource::SetData( wxDataObject
&data
)
774 wxDropSource::~wxDropSource(void)
776 // if (m_data) delete m_data;
778 g_blockEventsOnDrag
= FALSE
;
781 wxDragResult
wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove
) )
783 if (gdk_dnd
.dnd_grabbed
) return (wxDragResult
) wxDragNone
;
784 if (gdk_dnd
.drag_really
) return (wxDragResult
) wxDragNone
;
786 wxASSERT_MSG( m_data
, "wxDragSource: no data" );
788 if (!m_data
) return (wxDragResult
) wxDragNone
;
790 static GtkWidget
*drag_icon
= (GtkWidget
*) NULL
;
791 static GtkWidget
*drop_icon
= (GtkWidget
*) NULL
;
793 GdkPoint hotspot_1
= {0,-5 };
797 drag_icon
= shape_create_icon ( gv_xpm
,
798 440, 140, 0,0, GTK_WINDOW_POPUP
);
800 gtk_signal_connect (GTK_OBJECT (drag_icon
), "destroy",
801 GTK_SIGNAL_FUNC(gtk_widget_destroyed
),
804 gtk_widget_hide (drag_icon
);
807 GdkPoint hotspot_2
= {-5,-5};
811 drop_icon
= shape_create_icon ( page_xpm
,
812 440, 140, 0,0, GTK_WINDOW_POPUP
);
814 gtk_signal_connect (GTK_OBJECT (drop_icon
), "destroy",
815 GTK_SIGNAL_FUNC(gtk_widget_destroyed
),
818 gtk_widget_hide (drop_icon
);
822 gdk_dnd_set_drag_shape( drag_icon
->window
,
828 GdkWindowPrivate
*wp
= (GdkWindowPrivate
*) m_widget
->window
;
832 gdk_dnd
.drag_perhaps
= TRUE
;
834 gdk_dnd
.dnd_drag_start
.x
= 5;
835 gdk_dnd
.dnd_drag_start
.y
= 5;
836 gdk_dnd
.real_sw
= wp
;
838 if (gdk_dnd
.drag_startwindows
)
840 g_free( gdk_dnd
.drag_startwindows
);
841 gdk_dnd
.drag_startwindows
= (GdkWindow
**) NULL
;
843 gdk_dnd
.drag_numwindows
= gdk_dnd
.drag_really
= 0;
845 XWindowAttributes dnd_winattr
;
846 XGetWindowAttributes( gdk_display
, wp
->xwindow
, &dnd_winattr
);
847 wp
->dnd_drag_savedeventmask
= dnd_winattr
.your_event_mask
;
849 gdk_dnd_drag_addwindow( m_widget
->window
);
851 GdkEventDragBegin ev
;
852 ev
.type
= GDK_DRAG_BEGIN
;
853 ev
.window
= m_widget
->window
;
855 ev
.u
.flags
.protocol_version
= DND_PROTOCOL_VERSION
;
857 gdk_event_put( (GdkEvent
*)&ev
);
859 XGrabPointer( gdk_display
, wp
->xwindow
, False
,
860 ButtonMotionMask
| ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
,
861 GrabModeAsync
, GrabModeAsync
, gdk_root_window
, None
, CurrentTime
);
863 gdk_dnd_set_drag_cursors( m_defaultCursor
.GetCursor(), m_goaheadCursor
.GetCursor() );
865 gdk_dnd
.dnd_grabbed
= TRUE
;
866 gdk_dnd
.drag_really
= 1;
870 wxGetMousePosition( &x
, &y
);
872 gdk_dnd_display_drag_cursor( x
, y
, FALSE
, TRUE
);
874 while (gdk_dnd
.drag_really
|| gdk_dnd
.drag_perhaps
) wxYield();
878 g_blockEventsOnDrag
= FALSE
;
883 void wxDropSource::RegisterWindow(void)
889 wxDataFormat df
= m_data
->GetFormat();
895 formats
+= "text/plain";
900 formats
+= "file:ALL";
905 wxPrivateDataObject
* pdo
= (wxPrivateDataObject
*) m_data
;
906 formats
+= "applications/";
907 formats
+= pdo
->GetId();
914 char *str
= WXSTRINGCAST formats
;
916 gtk_widget_dnd_drag_set( m_widget
, TRUE
, &str
, 1 );
918 gtk_signal_connect( GTK_OBJECT(m_widget
), "drag_request_event",
919 GTK_SIGNAL_FUNC(gtk_drag_callback
), (gpointer
)this );
922 void wxDropSource::UnregisterWindow(void)
924 if (!m_widget
) return;
926 gtk_widget_dnd_drag_set( m_widget
, FALSE
, (gchar
**) NULL
, 0 );
928 gtk_signal_disconnect_by_data( GTK_OBJECT(m_widget
), (gpointer
)this );
935 static GdkWindow
*root_win
= (GdkWindow
*) NULL
;
937 typedef struct _cursoroffset
{gint x
,y
;} CursorOffset
;
940 shape_pressed (GtkWidget
*widget
, GdkEventButton
*event
)
944 /* ignore double and triple click */
945 if (event
->type
!= GDK_BUTTON_PRESS
)
948 p
= (CursorOffset
*)gtk_object_get_user_data (GTK_OBJECT(widget
));
949 p
->x
= (int) event
->x
;
950 p
->y
= (int) event
->y
;
952 gtk_grab_add (widget
);
953 gdk_pointer_grab (widget
->window
, TRUE
,
955 (GDK_BUTTON_RELEASE_MASK
|
956 GDK_BUTTON_MOTION_MASK
|
957 GDK_POINTER_MOTION_HINT_MASK
),
959 (GdkCursor
*) NULL
, 0);
964 shape_released (GtkWidget
*widget
)
966 gtk_grab_remove (widget
);
967 gdk_pointer_ungrab (0);
971 shape_motion (GtkWidget
*widget
,
972 GdkEventMotion */
*event*/
)
976 GdkModifierType mask
;
978 p
= (CursorOffset
*)gtk_object_get_user_data (GTK_OBJECT (widget
));
981 * Can't use event->x / event->y here
982 * because I need absolute coordinates.
984 gdk_window_get_pointer (root_win
, &xp
, &yp
, &mask
);
985 gtk_widget_set_uposition (widget
, xp
- p
->x
, yp
- p
->y
);
989 shape_create_icon (char **data
,
999 CursorOffset
* icon_pos
;
1001 GdkBitmap
*gdk_pixmap_mask
;
1002 GdkPixmap
*gdk_pixmap
;
1005 style
= gtk_widget_get_default_style ();
1006 gc
= style
->black_gc
;
1009 * GDK_WINDOW_TOPLEVEL works also, giving you a title border
1011 window
= gtk_window_new ((GtkWindowType
)window_type
);
1013 fixed
= gtk_fixed_new ();
1014 gtk_widget_set_usize (fixed
, 100,100);
1015 gtk_container_add (GTK_CONTAINER (window
), fixed
);
1016 gtk_widget_show (fixed
);
1018 gtk_widget_set_events (window
,
1019 gtk_widget_get_events (window
) |
1020 GDK_BUTTON_MOTION_MASK
|
1021 GDK_POINTER_MOTION_HINT_MASK
|
1022 GDK_BUTTON_PRESS_MASK
);
1024 gtk_widget_realize (window
);
1026 gdk_pixmap
= gdk_pixmap_create_from_xpm_d (window
->window
, &gdk_pixmap_mask
,
1027 &style
->bg
[GTK_STATE_NORMAL
],
1030 pixmap
= gtk_pixmap_new (gdk_pixmap
, gdk_pixmap_mask
);
1031 gtk_fixed_put (GTK_FIXED (fixed
), pixmap
, px
,py
);
1032 gtk_widget_show (pixmap
);
1034 gtk_widget_shape_combine_mask (window
, gdk_pixmap_mask
, px
,py
);
1037 gtk_signal_connect (GTK_OBJECT (window
), "button_press_event",
1038 GTK_SIGNAL_FUNC (shape_pressed
),NULL
);
1039 gtk_signal_connect (GTK_OBJECT (window
), "button_release_event",
1040 GTK_SIGNAL_FUNC (shape_released
),NULL
);
1041 gtk_signal_connect (GTK_OBJECT (window
), "motion_notify_event",
1042 GTK_SIGNAL_FUNC (shape_motion
),NULL
);
1044 icon_pos
= g_new (CursorOffset
, 1);
1045 gtk_object_set_user_data(GTK_OBJECT(window
), icon_pos
);
1047 gtk_widget_set_uposition (window
, x
, y
);
1048 gtk_widget_show (window
);
1058 // wxUSE_DRAG_AND_DROP