]>
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
22 #include "wx/window.h"
25 #include "wx/gdicmn.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 wxDropTarget::wxDropTarget()
41 wxDropTarget::~wxDropTarget()
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) )
51 OnDropText( x
, y
, (const char*)data
);
55 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz
)
57 wxLogDebug( "Got dropped text: %s.", psz
);
58 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
62 size_t wxTextDropTarget::GetFormatCount() const
67 wxDataFormat
wxTextDropTarget::GetFormat(size_t WXUNUSED(n
)) const
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] )
78 wxLogDebug( "Got %d dropped files.", (int)nFiles
);
79 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
81 for (i
= 0; i
< nFiles
; i
++)
83 wxLogDebug( aszFiles
[i
] );
88 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size
)
91 char *text
= (char*) data
;
93 for (i
= 0; i
< size
; i
++)
94 if (text
[i
] == 0) number
++;
96 if (number
== 0) return true;
98 char **files
= new char*[number
];
101 for ( i
= 0; i
< number
; i
++)
104 int len
= strlen( text
);
108 bool ret
= OnDropFiles( x
, y
, 1, files
);
115 size_t wxFileDropTarget::GetFormatCount() const
120 wxDataFormat
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const
122 return wxDF_FILENAME
;
125 //-------------------------------------------------------------------------
127 //-------------------------------------------------------------------------
129 wxDropSource::wxDropSource( wxWindow
*win
)
133 m_data
= (wxDataObject
*) NULL
;
134 m_retValue
= wxDragCancel
;
136 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
137 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
141 wxDropSource::wxDropSource( wxDataObject
&data
, wxWindow
*win
)
144 g_blockEventsOnDrag
= true;
147 m_widget
= win
->m_widget
;
148 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
149 m_retValue
= wxDragCancel
;
153 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
154 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
158 void wxDropSource::SetData( wxDataObject
&data
)
163 wxDropSource::~wxDropSource(void)
165 // if (m_data) delete m_data;
168 wxDragResult
wxDropSource::DoDragDrop( int WXUNUSED(flags
) )
170 // wxASSERT_MSG( m_data, "wxDragSource: no data" );
174 if (!m_data
) return (wxDragResult
) wxDragNone
;
175 if (m_data
->GetDataSize() == 0) return (wxDragResult
) wxDragNone
;
183 g_blockEventsOnDrag
= false;
190 void wxDropSource::RegisterWindow(void)
196 wxDataFormat df
= m_data
->GetPreferredFormat();
201 formats
+= "text/plain";
204 formats
+= "file:ALL";
210 char *str
= WXSTRINGCAST formats
;
215 void wxDropSource::UnregisterWindow(void)
217 if (!m_widget
) return;
223 wxPrivateDropTarget::wxPrivateDropTarget()
225 m_id
= wxTheApp
->GetAppName();
228 size_t wxPrivateDropTarget::GetFormatCount() const
233 wxDataFormat
wxPrivateDropTarget::GetFormat(size_t n
) const
239 // wxUSE_DRAG_AND_DROP