]>
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
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 defined(__BORLANDC__)
17 #if wxUSE_DRAG_AND_DROP
26 #include "wx/window.h"
28 #include "wx/gdicmn.h"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 wxDropTarget::wxDropTarget()
45 wxDropTarget::~wxDropTarget()
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) )
55 OnDropText( x
, y
, (const char*)data
);
59 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz
)
61 wxLogDebug( "Got dropped text: %s.", psz
);
62 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
66 size_t wxTextDropTarget::GetFormatCount() const
71 wxDataFormat
wxTextDropTarget::GetFormat(size_t WXUNUSED(n
)) const
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] )
82 wxLogDebug( "Got %d dropped files.", (int)nFiles
);
83 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
85 for (i
= 0; i
< nFiles
; i
++)
87 wxLogDebug( aszFiles
[i
] );
92 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size
)
95 char *text
= (char*) data
;
97 for (i
= 0; i
< size
; i
++)
98 if (text
[i
] == 0) number
++;
100 if (number
== 0) return true;
102 char **files
= new char*[number
];
105 for ( i
= 0; i
< number
; i
++)
108 int len
= strlen( text
);
112 bool ret
= OnDropFiles( x
, y
, 1, files
);
119 size_t wxFileDropTarget::GetFormatCount() const
124 wxDataFormat
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const
126 return wxDF_FILENAME
;
129 //-------------------------------------------------------------------------
131 //-------------------------------------------------------------------------
133 wxDropSource::wxDropSource( wxWindow
*win
)
137 m_data
= (wxDataObject
*) NULL
;
138 m_retValue
= wxDragCancel
;
140 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
141 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
145 wxDropSource::wxDropSource( wxDataObject
&data
, wxWindow
*win
)
148 g_blockEventsOnDrag
= true;
151 m_widget
= win
->m_widget
;
152 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
153 m_retValue
= wxDragCancel
;
157 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
158 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
162 void wxDropSource::SetData( wxDataObject
&data
)
167 wxDropSource::~wxDropSource(void)
169 // if (m_data) delete m_data;
172 wxDragResult
wxDropSource::DoDragDrop( int WXUNUSED(flags
) )
174 // wxASSERT_MSG( m_data, "wxDragSource: no data" );
178 if (!m_data
) return (wxDragResult
) wxDragNone
;
179 if (m_data
->GetDataSize() == 0) return (wxDragResult
) wxDragNone
;
187 g_blockEventsOnDrag
= FALSE
;
194 void wxDropSource::RegisterWindow(void)
200 wxDataFormat df
= m_data
->GetPreferredFormat();
205 formats
+= "text/plain";
208 formats
+= "file:ALL";
214 char *str
= WXSTRINGCAST formats
;
219 void wxDropSource::UnregisterWindow(void)
221 if (!m_widget
) return;
227 wxPrivateDropTarget::wxPrivateDropTarget()
229 m_id
= wxTheApp
->GetAppName();
232 size_t wxPrivateDropTarget::GetFormatCount() const
237 wxDataFormat
wxPrivateDropTarget::GetFormat(size_t n
) const
243 // wxUSE_DRAG_AND_DROP