1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDropTarget, wxDropSource classes
4 // Author: Julian Smart
6 // Copyright: (c) 1998 Julian Smart
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dnd.h"
16 #if wxUSE_DRAG_AND_DROP
19 #include "wx/window.h"
21 #include "wx/gdicmn.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 wxDropTarget::wxDropTarget()
40 wxDropTarget::~wxDropTarget()
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) )
50 OnDropText( x
, y
, (const char*)data
);
54 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz
)
56 wxLogDebug( "Got dropped text: %s.", psz
);
57 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
61 size_t wxTextDropTarget::GetFormatCount() const
66 wxDataFormat
wxTextDropTarget::GetFormat(size_t WXUNUSED(n
)) const
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] )
77 wxLogDebug( "Got %d dropped files.", (int)nFiles
);
78 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
80 for (i
= 0; i
< nFiles
; i
++)
82 wxLogDebug( aszFiles
[i
] );
87 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size
)
90 char *text
= (char*) data
;
92 for (i
= 0; i
< size
; i
++)
93 if (text
[i
] == 0) number
++;
95 if (number
== 0) return TRUE
;
97 char **files
= new char*[number
];
100 for ( i
= 0; i
< number
; i
++)
103 int len
= strlen( text
);
107 bool ret
= OnDropFiles( x
, y
, 1, files
);
114 size_t wxFileDropTarget::GetFormatCount() const
119 wxDataFormat
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const
121 return wxDF_FILENAME
;
124 //-------------------------------------------------------------------------
126 //-------------------------------------------------------------------------
128 wxDropSource::wxDropSource( wxWindow
*win
)
132 m_data
= (wxDataObject
*) NULL
;
133 m_retValue
= wxDragCancel
;
135 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
136 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
140 wxDropSource::wxDropSource( wxDataObject
&data
, wxWindow
*win
)
143 g_blockEventsOnDrag
= TRUE
;
146 m_widget
= win
->m_widget
;
147 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
148 m_retValue
= wxDragCancel
;
152 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
153 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
157 void wxDropSource::SetData( wxDataObject
&data
)
162 wxDropSource::~wxDropSource(void)
164 // if (m_data) delete m_data;
167 wxDragResult
wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove
) )
169 // wxASSERT_MSG( m_data, "wxDragSource: no data" );
173 if (!m_data
) return (wxDragResult
) wxDragNone
;
174 if (m_data
->GetDataSize() == 0) return (wxDragResult
) wxDragNone
;
182 g_blockEventsOnDrag
= FALSE
;
189 void wxDropSource::RegisterWindow(void)
195 wxDataFormat df
= m_data
->GetPreferredFormat();
200 formats
+= "text/plain";
203 formats
+= "file:ALL";
209 char *str
= WXSTRINGCAST formats
;
214 void wxDropSource::UnregisterWindow(void)
216 if (!m_widget
) return;
222 wxPrivateDropTarget::wxPrivateDropTarget()
224 m_id
= wxTheApp
->GetAppName();
227 size_t wxPrivateDropTarget::GetFormatCount() const
232 wxDataFormat
wxPrivateDropTarget::GetFormat(size_t n
) const
238 // wxUSE_DRAG_AND_DROP