]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/dnd.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/dnd.cpp
3 // Purpose: wxDropTarget, wxDropSource classes
4 // Author: Julian Smart
6 // Copyright: (c) 1998 Julian Smart
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DRAG_AND_DROP
16 #include "wx/window.h"
18 #include "wx/gdicmn.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 wxDropTarget::wxDropTarget()
37 wxDropTarget::~wxDropTarget()
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) )
47 OnDropText( x
, y
, (const char*)data
);
51 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz
)
53 wxLogDebug( "Got dropped text: %s.", psz
);
54 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
58 size_t wxTextDropTarget::GetFormatCount() const
63 wxDataFormat
wxTextDropTarget::GetFormat(size_t WXUNUSED(n
)) const
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] )
74 wxLogDebug( "Got %d dropped files.", (int)nFiles
);
75 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
77 for (i
= 0; i
< nFiles
; i
++)
79 wxLogDebug( aszFiles
[i
] );
84 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size
)
87 char *text
= (char*) data
;
89 for (i
= 0; i
< size
; i
++)
90 if (text
[i
] == 0) number
++;
92 if (number
== 0) return true;
94 char **files
= new char*[number
];
97 for ( i
= 0; i
< number
; i
++)
100 int len
= strlen( text
);
104 bool ret
= OnDropFiles( x
, y
, 1, files
);
111 size_t wxFileDropTarget::GetFormatCount() const
116 wxDataFormat
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const
118 return wxDF_FILENAME
;
121 //-------------------------------------------------------------------------
123 //-------------------------------------------------------------------------
125 wxDropSource::wxDropSource( wxWindow
*win
)
129 m_data
= (wxDataObject
*) NULL
;
130 m_retValue
= wxDragCancel
;
132 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
133 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
137 wxDropSource::wxDropSource( wxDataObject
&data
, wxWindow
*win
)
140 g_blockEventsOnDrag
= true;
143 m_widget
= win
->m_widget
;
144 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
145 m_retValue
= wxDragCancel
;
149 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
150 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
154 void wxDropSource::SetData( wxDataObject
&data
)
159 wxDropSource::~wxDropSource(void)
161 // if (m_data) delete m_data;
164 wxDragResult
wxDropSource::DoDragDrop( int WXUNUSED(flags
) )
166 // wxASSERT_MSG( m_data, "wxDragSource: no data" );
170 if (!m_data
) return (wxDragResult
) wxDragNone
;
171 if (m_data
->GetDataSize() == 0) return (wxDragResult
) wxDragNone
;
179 g_blockEventsOnDrag
= false;
186 void wxDropSource::RegisterWindow(void)
192 wxDataFormat df
= m_data
->GetPreferredFormat();
197 formats
+= "text/plain";
200 formats
+= "file:ALL";
206 char *str
= WXSTRINGCAST formats
;
211 void wxDropSource::UnregisterWindow(void)
213 if (!m_widget
) return;
219 wxPrivateDropTarget::wxPrivateDropTarget()
221 m_id
= wxTheApp
->GetAppName();
224 size_t wxPrivateDropTarget::GetFormatCount() const
229 wxDataFormat
wxPrivateDropTarget::GetFormat(size_t n
) const
235 // wxUSE_DRAG_AND_DROP