]>
git.saurik.com Git - wxWidgets.git/blob - src/x11/dnd.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDropTarget, wxDropSource classes
4 // Author: Julian Smart
6 // Copyright: (c) 1998 Julian Smart
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
12 #if wxUSE_DRAG_AND_DROP
15 #include "wx/window.h"
17 #include "wx/gdicmn.h"
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 wxDropTarget::wxDropTarget()
36 wxDropTarget::~wxDropTarget()
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) )
46 OnDropText( x
, y
, (const char*)data
);
50 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz
)
52 wxLogDebug( "Got dropped text: %s.", psz
);
53 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
57 size_t wxTextDropTarget::GetFormatCount() const
62 wxDataFormat
wxTextDropTarget::GetFormat(size_t WXUNUSED(n
)) const
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] )
73 wxLogDebug( "Got %d dropped files.", (int)nFiles
);
74 wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y
);
76 for (i
= 0; i
< nFiles
; i
++)
78 wxLogDebug( aszFiles
[i
] );
83 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size
)
86 char *text
= (char*) data
;
88 for (i
= 0; i
< size
; i
++)
89 if (text
[i
] == 0) number
++;
91 if (number
== 0) return TRUE
;
93 char **files
= new char*[number
];
96 for ( i
= 0; i
< number
; i
++)
99 int len
= strlen( text
);
103 bool ret
= OnDropFiles( x
, y
, 1, files
);
110 size_t wxFileDropTarget::GetFormatCount() const
115 wxDataFormat
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const
117 return wxDF_FILENAME
;
120 //-------------------------------------------------------------------------
122 //-------------------------------------------------------------------------
124 wxDropSource::wxDropSource( wxWindow
*win
)
128 m_data
= (wxDataObject
*) NULL
;
129 m_retValue
= wxDragCancel
;
131 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
132 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
136 wxDropSource::wxDropSource( wxDataObject
&data
, wxWindow
*win
)
139 g_blockEventsOnDrag
= TRUE
;
142 m_widget
= win
->m_widget
;
143 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
144 m_retValue
= wxDragCancel
;
148 m_defaultCursor
= wxCursor( wxCURSOR_NO_ENTRY
);
149 m_goaheadCursor
= wxCursor( wxCURSOR_HAND
);
153 void wxDropSource::SetData( wxDataObject
&data
)
158 wxDropSource::~wxDropSource(void)
160 // if (m_data) delete m_data;
163 wxDragResult
wxDropSource::DoDragDrop( int WXUNUSED(flags
) )
165 // wxASSERT_MSG( m_data, "wxDragSource: no data" );
169 if (!m_data
) return (wxDragResult
) wxDragNone
;
170 if (m_data
->GetDataSize() == 0) return (wxDragResult
) wxDragNone
;
178 g_blockEventsOnDrag
= FALSE
;
185 void wxDropSource::RegisterWindow(void)
191 wxDataFormat df
= m_data
->GetPreferredFormat();
196 formats
+= "text/plain";
199 formats
+= "file:ALL";
205 char *str
= WXSTRINGCAST formats
;
210 void wxDropSource::UnregisterWindow(void)
212 if (!m_widget
) return;
218 wxPrivateDropTarget::wxPrivateDropTarget()
220 m_id
= wxTheApp
->GetAppName();
223 size_t wxPrivateDropTarget::GetFormatCount() const
228 wxDataFormat
wxPrivateDropTarget::GetFormat(size_t n
) const
234 // wxUSE_DRAG_AND_DROP