]>
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" 
  27     #include "wx/gdicmn.h" 
  32 // ---------------------------------------------------------------------------- 
  34 // ---------------------------------------------------------------------------- 
  36 // ---------------------------------------------------------------------------- 
  38 // ---------------------------------------------------------------------------- 
  40 wxDropTarget::wxDropTarget() 
  44 wxDropTarget::~wxDropTarget() 
  48 // ---------------------------------------------------------------------------- 
  50 // ---------------------------------------------------------------------------- 
  52 bool wxTextDropTarget::OnDrop( long x
, long y
, const void *data
, size_t WXUNUSED(size
) ) 
  54   OnDropText( x
, y
, (const char*)data 
); 
  58 bool wxTextDropTarget::OnDropText( long x
, long y
, const char *psz 
) 
  60   wxLogDebug( "Got dropped text: %s.", psz 
); 
  61   wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y 
); 
  65 size_t wxTextDropTarget::GetFormatCount() const 
  70 wxDataFormat 
wxTextDropTarget::GetFormat(size_t WXUNUSED(n
)) const 
  75 // ---------------------------------------------------------------------------- 
  77 // ---------------------------------------------------------------------------- 
  79 bool wxFileDropTarget::OnDropFiles( long x
, long y
, size_t nFiles
, const char * const aszFiles
[] ) 
  81   wxLogDebug( "Got %d dropped files.", (int)nFiles 
); 
  82   wxLogDebug( "At x: %d, y: %d.", (int)x
, (int)y 
); 
  84   for (i 
= 0; i 
< nFiles
; i
++) 
  86     wxLogDebug( aszFiles
[i
] ); 
  91 bool wxFileDropTarget::OnDrop(long x
, long y
, const void *data
, size_t size 
) 
  94   char *text 
= (char*) data
; 
  96   for (i 
= 0; i 
< size
; i
++) 
  97     if (text
[i
] == 0) number
++; 
  99   if (number 
== 0) return true; 
 101   char **files 
= new char*[number
]; 
 104   for ( i 
= 0; i 
< number
; i
++) 
 107     int len 
= strlen( text 
); 
 111   bool ret 
= OnDropFiles( x
, y
, 1, files 
); 
 118 size_t wxFileDropTarget::GetFormatCount() const 
 123 wxDataFormat 
wxFileDropTarget::GetFormat(size_t WXUNUSED(n
)) const 
 125   return wxDF_FILENAME
; 
 128 //------------------------------------------------------------------------- 
 130 //------------------------------------------------------------------------- 
 132 wxDropSource::wxDropSource( wxWindow 
*win 
) 
 136   m_data 
= (wxDataObject 
*) NULL
; 
 137   m_retValue 
= wxDragCancel
; 
 139   m_defaultCursor 
= wxCursor( wxCURSOR_NO_ENTRY 
); 
 140   m_goaheadCursor 
= wxCursor( wxCURSOR_HAND 
); 
 144 wxDropSource::wxDropSource( wxDataObject 
&data
, wxWindow 
*win 
) 
 147   g_blockEventsOnDrag 
= true; 
 150   m_widget 
= win
->m_widget
; 
 151   if (win
->m_wxwindow
) m_widget 
= win
->m_wxwindow
; 
 152   m_retValue 
= wxDragCancel
; 
 156   m_defaultCursor 
= wxCursor( wxCURSOR_NO_ENTRY 
); 
 157   m_goaheadCursor 
= wxCursor( wxCURSOR_HAND 
); 
 161 void wxDropSource::SetData( wxDataObject 
&data 
) 
 166 wxDropSource::~wxDropSource(void) 
 168 //  if (m_data) delete m_data; 
 171 wxDragResult 
wxDropSource::DoDragDrop( int WXUNUSED(flags
) ) 
 173   //  wxASSERT_MSG( m_data, "wxDragSource: no data" ); 
 177   if (!m_data
) return (wxDragResult
) wxDragNone
; 
 178   if (m_data
->GetDataSize() == 0) return (wxDragResult
) wxDragNone
; 
 186   g_blockEventsOnDrag 
= false; 
 193 void wxDropSource::RegisterWindow(void) 
 199   wxDataFormat df 
= m_data
->GetPreferredFormat(); 
 204         formats 
+= "text/plain"; 
 207         formats 
+= "file:ALL"; 
 213   char *str 
= WXSTRINGCAST formats
; 
 218 void wxDropSource::UnregisterWindow(void) 
 220   if (!m_widget
) return; 
 226 wxPrivateDropTarget::wxPrivateDropTarget() 
 228     m_id 
= wxTheApp
->GetAppName(); 
 231 size_t wxPrivateDropTarget::GetFormatCount() const 
 236 wxDataFormat 
wxPrivateDropTarget::GetFormat(size_t n
) const 
 242       // wxUSE_DRAG_AND_DROP