]>
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
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 wxUSE_DRAG_AND_DROP
21 #include "wx/window.h"
22 #include "wx/gdicmn.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 wxDropTarget::wxDropTarget()
39 wxDropTarget::~wxDropTarget()
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) )
49 OnDropText( x
, y
, (const char*)data
);
53 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz
)
55 wxLogDebug( "Got dropped text: %s.", psz
);
56 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
60 size_t wxTextDropTarget::GetFormatCount() const
65 wxDataFormat
wxTextDropTarget::GetFormat(size_t WXUNUSED(n
)) const
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] )
76 wxLogDebug( "Got %d dropped files.", (int)nFiles
);
77 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
79 for (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
;
91 for (i
= 0; i
< size
; i
++)
92 if (text
[i
] == 0) number
++;
94 if (number
== 0) return true;
96 char **files
= new char*[number
];
99 for ( i
= 0; i
< number
; i
++)
102 int len
= strlen( text
);
106 bool ret
= OnDropFiles( x
, y
, 1, files
);
113 size_t wxFileDropTarget::GetFormatCount() const
118 wxDataFormat
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const
120 return wxDF_FILENAME
;
123 //-------------------------------------------------------------------------
125 //-------------------------------------------------------------------------
127 wxDropSource::wxDropSource( wxWindow
*win
)
132 m_retValue
= wxDragCancel
;
134 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
135 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
139 wxDropSource::wxDropSource( wxDataObject
&data
, wxWindow
*win
)
142 g_blockEventsOnDrag
= true;
145 m_widget
= win
->m_widget
;
146 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
147 m_retValue
= wxDragCancel
;
151 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
152 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
156 void wxDropSource::SetData( wxDataObject
&data
)
161 wxDropSource::~wxDropSource(void)
163 // if (m_data) delete m_data;
166 wxDragResult
wxDropSource::DoDragDrop( int WXUNUSED(flags
) )
168 // wxASSERT_MSG( m_data, "wxDragSource: no data" );
172 if (!m_data
) return (wxDragResult
) wxDragNone
;
173 if (m_data
->GetDataSize() == 0) return (wxDragResult
) wxDragNone
;
181 g_blockEventsOnDrag
= false;
188 void wxDropSource::RegisterWindow(void)
194 wxDataFormat df
= m_data
->GetPreferredFormat();
199 formats
+= "text/plain";
202 formats
+= "file:ALL";
208 char *str
= WXSTRINGCAST formats
;
213 void wxDropSource::UnregisterWindow(void)
215 if (!m_widget
) return;
221 wxPrivateDropTarget::wxPrivateDropTarget()
223 m_id
= wxTheApp
->GetAppName();
226 size_t wxPrivateDropTarget::GetFormatCount() const
231 wxDataFormat
wxPrivateDropTarget::GetFormat(size_t n
) const
237 // wxUSE_DRAG_AND_DROP