]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/dnd.cpp
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
);
79 for (size_t i
= 0; i
< nFiles
; i
++)
81 wxLogDebug( aszFiles
[i
] );
86 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size
)
89 char *text
= (char*) data
;
90 for (size_t i
= 0; i
< size
; i
++)
91 if (text
[i
] == 0) number
++;
93 if (number
== 0) return TRUE
;
95 char **files
= new char*[number
];
98 for (size_t i
= 0; i
< number
; i
++)
101 int len
= strlen( text
);
105 bool ret
= OnDropFiles( x
, y
, 1, files
);
112 size_t wxFileDropTarget::GetFormatCount() const
117 wxDataFormat
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const
119 return wxDF_FILENAME
;
122 //-------------------------------------------------------------------------
124 //-------------------------------------------------------------------------
126 wxDropSource::wxDropSource( wxWindow
*win
)
130 m_data
= (wxDataObject
*) NULL
;
131 m_retValue
= wxDragCancel
;
133 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
134 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
138 wxDropSource::wxDropSource( wxDataObject
&data
, wxWindow
*win
)
141 g_blockEventsOnDrag
= TRUE
;
144 m_widget
= win
->m_widget
;
145 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
146 m_retValue
= wxDragCancel
;
150 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
151 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
155 void wxDropSource::SetData( wxDataObject
&data
)
160 wxDropSource::~wxDropSource(void)
162 // if (m_data) delete m_data;
165 wxDragResult
wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove
) )
167 // wxASSERT_MSG( m_data, "wxDragSource: no data" );
171 if (!m_data
) return (wxDragResult
) wxDragNone
;
172 if (m_data
->GetDataSize() == 0) return (wxDragResult
) wxDragNone
;
180 g_blockEventsOnDrag
= FALSE
;
187 void wxDropSource::RegisterWindow(void)
193 wxDataFormat df
= m_data
->GetPreferredFormat();
198 formats
+= "text/plain";
201 formats
+= "file:ALL";
207 char *str
= WXSTRINGCAST formats
;
212 void wxDropSource::UnregisterWindow(void)
214 if (!m_widget
) return;
222 // wxUSE_DRAG_AND_DROP