]>
git.saurik.com Git - wxWidgets.git/blob - src/x11/dnd.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/dnd.cpp
3 // Purpose: wxDropTarget, wxDropSource classes
4 // Author: Julian Smart
5 // Copyright: (c) 1998 Julian Smart
6 // Licence: wxWindows licence
7 ///////////////////////////////////////////////////////////////////////////////
9 // for compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
12 #if defined(__BORLANDC__)
16 #if wxUSE_DRAG_AND_DROP
25 #include "wx/window.h"
26 #include "wx/gdicmn.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 wxDropTarget::wxDropTarget()
43 wxDropTarget::~wxDropTarget()
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) )
53 OnDropText( x
, y
, (const char*)data
);
57 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz
)
59 wxLogDebug( "Got dropped text: %s.", psz
);
60 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
64 size_t wxTextDropTarget::GetFormatCount() const
69 wxDataFormat
wxTextDropTarget::GetFormat(size_t WXUNUSED(n
)) const
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] )
80 wxLogDebug( "Got %d dropped files.", (int)nFiles
);
81 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
83 for (i
= 0; i
< nFiles
; i
++)
85 wxLogDebug( aszFiles
[i
] );
90 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size
)
93 char *text
= (char*) data
;
95 for (i
= 0; i
< size
; i
++)
96 if (text
[i
] == 0) number
++;
98 if (number
== 0) return true;
100 char **files
= new char*[number
];
103 for ( i
= 0; i
< number
; i
++)
106 int len
= strlen( text
);
110 bool ret
= OnDropFiles( x
, y
, 1, files
);
117 size_t wxFileDropTarget::GetFormatCount() const
122 wxDataFormat
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const
124 return wxDF_FILENAME
;
127 //-------------------------------------------------------------------------
129 //-------------------------------------------------------------------------
131 wxDropSource::wxDropSource( wxWindow
*win
)
136 m_retValue
= wxDragCancel
;
138 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
139 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
143 wxDropSource::wxDropSource( wxDataObject
&data
, wxWindow
*win
)
146 g_blockEventsOnDrag
= true;
149 m_widget
= win
->m_widget
;
150 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
151 m_retValue
= wxDragCancel
;
155 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
156 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
160 void wxDropSource::SetData( wxDataObject
&data
)
165 wxDropSource::~wxDropSource(void)
167 // if (m_data) delete m_data;
170 wxDragResult
wxDropSource::DoDragDrop( int WXUNUSED(flags
) )
172 // wxASSERT_MSG( m_data, "wxDragSource: no data" );
176 if (!m_data
) return (wxDragResult
) wxDragNone
;
177 if (m_data
->GetDataSize() == 0) return (wxDragResult
) wxDragNone
;
185 g_blockEventsOnDrag
= false;
192 void wxDropSource::RegisterWindow(void)
198 wxDataFormat df
= m_data
->GetPreferredFormat();
203 formats
+= "text/plain";
206 formats
+= "file:ALL";
212 char *str
= WXSTRINGCAST formats
;
217 void wxDropSource::UnregisterWindow(void)
219 if (!m_widget
) return;
225 wxPrivateDropTarget::wxPrivateDropTarget()
227 m_id
= wxTheApp
->GetAppName();
230 size_t wxPrivateDropTarget::GetFormatCount() const
235 wxDataFormat
wxPrivateDropTarget::GetFormat(size_t n
) const
241 // wxUSE_DRAG_AND_DROP