X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f03fc89fff2d6e823e7d4d14fbe14822ad6777b1..d6538e2c55535a747aec939d0f6659f91bc623d4:/src/gtk1/dnd.cpp diff --git a/src/gtk1/dnd.cpp b/src/gtk1/dnd.cpp index 5ca90425da..dbf3456d02 100644 --- a/src/gtk1/dnd.cpp +++ b/src/gtk1/dnd.cpp @@ -35,6 +35,15 @@ extern void wxapp_install_idle_handler(); extern bool g_isIdle; +//----------------------------------------------------------------------------- +// thread system +//----------------------------------------------------------------------------- + +#if wxUSE_THREADS +extern void wxapp_install_thread_wakeup(); +extern void wxapp_uninstall_thread_wakeup(); +#endif + //---------------------------------------------------------------------------- // global data //---------------------------------------------------------------------------- @@ -337,17 +346,17 @@ void wxDropTarget::OnLeave() { } -bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) +bool wxDropTarget::OnMove( long WXUNUSED(x), long WXUNUSED(y) ) { return TRUE; } -bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) ) +bool wxDropTarget::OnDrop( long WXUNUSED(x), long WXUNUSED(y) ) { return FALSE; } -bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) ) +bool wxDropTarget::OnData( long WXUNUSED(x), long WXUNUSED(y) ) { return FALSE; } @@ -358,17 +367,27 @@ bool wxDropTarget::RequestData( wxDataFormat format ) if (!m_dragWidget) return FALSE; /* - wxPrintf( _T("format: %s.\n"), format.GetId().c_str() ); - if (format.GetType() == wxDF_PRIVATE) wxPrintf( _T("private data.\n") ); - if (format.GetType() == wxDF_TEXT) wxPrintf( _T("text data.\n") ); + wxPrintf( wxT("format: %s.\n"), format.GetId().c_str() ); + if (format.GetType() == wxDF_PRIVATE) wxPrintf( wxT("private data.\n") ); + if (format.GetType() == wxDF_TEXT) wxPrintf( wxT("text data.\n") ); */ +#if wxUSE_THREADS + /* disable GUI threads */ + wxapp_uninstall_thread_wakeup(); +#endif + /* this should trigger an "drag_data_received" event */ gtk_drag_get_data( m_dragWidget, m_dragContext, - format.GetAtom(), + format, m_dragTime ); +#if wxUSE_THREADS + /* re-enable GUI threads */ + wxapp_install_thread_wakeup(); +#endif + return TRUE; } @@ -384,7 +403,7 @@ bool wxDropTarget::IsSupported( wxDataFormat format ) // char *name = gdk_atom_name( formatAtom ); // if (name) printf( "Format available: %s.\n", name ); - if (formatAtom == format.GetAtom()) return TRUE; + if (formatAtom == format) return TRUE; child = child->next; } @@ -395,7 +414,7 @@ bool wxDropTarget::GetData( wxDataObject *data_object ) { if (!m_dragData) return FALSE; - if (m_dragData->target != data_object->GetFormat().GetAtom()) return FALSE; + if (m_dragData->target != data_object->GetFormat()) return FALSE; if (data_object->GetFormat().GetType() == wxDF_TEXT) { @@ -418,7 +437,7 @@ bool wxDropTarget::GetData( wxDataObject *data_object ) void wxDropTarget::UnregisterWidget( GtkWidget *widget ) { - wxCHECK_RET( widget != NULL, _T("unregister widget is NULL") ); + wxCHECK_RET( widget != NULL, wxT("unregister widget is NULL") ); gtk_drag_dest_unset( widget ); @@ -437,7 +456,7 @@ void wxDropTarget::UnregisterWidget( GtkWidget *widget ) void wxDropTarget::RegisterWidget( GtkWidget *widget ) { - wxCHECK_RET( widget != NULL, _T("register widget is NULL") ); + wxCHECK_RET( widget != NULL, wxT("register widget is NULL") ); /* gtk_drag_dest_set() determines what default behaviour we'd like GTK to supply. we don't want to specify out targets (=formats) @@ -472,12 +491,12 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget ) // wxTextDropTarget //------------------------------------------------------------------------- -bool wxTextDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) +bool wxTextDropTarget::OnMove( long WXUNUSED(x), long WXUNUSED(y) ) { return IsSupported( wxDF_TEXT ); } -bool wxTextDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) ) +bool wxTextDropTarget::OnDrop( long WXUNUSED(x), long WXUNUSED(y) ) { if (IsSupported( wxDF_TEXT )) { @@ -488,7 +507,7 @@ bool wxTextDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) ) return FALSE; } -bool wxTextDropTarget::OnData( int x, int y ) +bool wxTextDropTarget::OnData( long x, long y ) { wxTextDataObject data; if (!GetData( &data )) return FALSE; @@ -502,6 +521,7 @@ bool wxTextDropTarget::OnData( int x, int y ) // wxPrivateDropTarget //------------------------------------------------------------------------- +/* wxPrivateDropTarget::wxPrivateDropTarget() { m_id = wxTheApp->GetAppName(); @@ -512,12 +532,12 @@ wxPrivateDropTarget::wxPrivateDropTarget( const wxString &id ) m_id = id; } -bool wxPrivateDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) +bool wxPrivateDropTarget::OnMove( long WXUNUSED(x), long WXUNUSED(y) ) { return IsSupported( m_id ); } -bool wxPrivateDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) ) +bool wxPrivateDropTarget::OnDrop( long WXUNUSED(x), long WXUNUSED(y) ) { if (!IsSupported( m_id )) { @@ -528,7 +548,7 @@ bool wxPrivateDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) ) return FALSE; } -bool wxPrivateDropTarget::OnData( int x, int y ) +bool wxPrivateDropTarget::OnData( long x, long y ) { if (!IsSupported( m_id )) return FALSE; @@ -539,17 +559,18 @@ bool wxPrivateDropTarget::OnData( int x, int y ) return TRUE; } +*/ //---------------------------------------------------------------------------- // A drop target which accepts files (dragged from File Manager or Explorer) //---------------------------------------------------------------------------- -bool wxFileDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) +bool wxFileDropTarget::OnMove( long WXUNUSED(x), long WXUNUSED(y) ) { return IsSupported( wxDF_FILENAME ); } -bool wxFileDropTarget::OnDrop( int x, int y ) +bool wxFileDropTarget::OnDrop( long x, long y ) { if (IsSupported( wxDF_FILENAME )) { @@ -560,12 +581,12 @@ bool wxFileDropTarget::OnDrop( int x, int y ) return FALSE; } -bool wxFileDropTarget::OnData( int x, int y ) +bool wxFileDropTarget::OnData( long x, long y ) { wxFileDataObject data; if (!GetData( &data )) return FALSE; - /* get number of substrings /root/mytext.txt/0/root/myothertext.txt/0/0 */ + // get number of substrings /root/mytext.txt/0/root/myothertext.txt/0/0 size_t number = 0; size_t i; size_t size = data.GetFiles().Length(); @@ -611,42 +632,51 @@ source_drag_data_get (GtkWidget *WXUNUSED(widget), // char *name = gdk_atom_name( selection_data->target ); // if (name) printf( "Format requested: %s.\n", name ); - wxNode *node = drop_source->m_data->m_dataObjects.First(); - while (node) - { - wxDataObject *data_object = (wxDataObject*) node->Data(); - if (data_object->GetFormat().GetAtom() == selection_data->target) - { -// printf( "format found.\n" ); + drop_source->m_retValue = wxDragCancel; + + wxDataObject *data = drop_source->m_data; + + if (!data) + return; - size_t data_size = data_object->GetSize(); + if (!data->IsSupportedFormat(selection_data->target)) + return; - if (data_size > 0) - { -// printf( "data size: %d.\n", (int)data_size ); + if (data->GetDataSize(selection_data->target) == 0) + return; + + size_t size = data->GetDataSize(selection_data->target); - guchar *buffer = new guchar[data_size]; - data_object->WriteData( buffer ); +// printf( "data size: %d.\n", (int)data_size ); + + guchar *d = new guchar[size]; + + if (!data->GetDataHere( selection_data->target, (void*)d )) + { + free( d ); + return; + } + +#if wxUSE_THREADS + /* disable GUI threads */ + wxapp_uninstall_thread_wakeup(); +#endif gtk_selection_data_set( selection_data, selection_data->target, 8, // 8-bit - buffer, - data_size ); - - free( buffer ); - - /* so far only copy, no moves. TODO. */ - drop_source->m_retValue = wxDragCopy; + d, + size ); - return; - } - } - - node = node->Next(); - } +#if wxUSE_THREADS + /* enable GUI threads */ + wxapp_install_thread_wakeup(); +#endif - drop_source->m_retValue = wxDragCancel; + free( d ); + + /* so far only copy, no moves. TODO. */ + drop_source->m_retValue = wxDragCopy; } //---------------------------------------------------------------------------- @@ -659,7 +689,7 @@ static void source_drag_data_delete( GtkWidget *WXUNUSED(widget), { if (g_isIdle) wxapp_install_idle_handler(); -// printf( "Delete the data!\n" ); +// printf( "Delete the data!\n" ); drop_source->m_retValue = wxDragMove; } @@ -674,7 +704,7 @@ static void source_drag_begin( GtkWidget *WXUNUSED(widget), { if (g_isIdle) wxapp_install_idle_handler(); -// printf( "drag_begin.\n" ); +// printf( "drag_begin.\n" ); } //---------------------------------------------------------------------------- @@ -687,7 +717,7 @@ static void source_drag_end( GtkWidget *WXUNUSED(widget), { if (g_isIdle) wxapp_install_idle_handler(); -// printf( "drag_end.\n" ); +// printf( "drag_end.\n" ); drop_source->m_waiting = FALSE; } @@ -702,10 +732,10 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop m_waiting = TRUE; m_window = win; - m_widget = win->GetWidget(); - if (win->GetWxWindow()) m_widget = win->GetWxWindow(); + m_widget = win->m_widget; + if (win->m_wxwindow) m_widget = win->m_wxwindow; - m_data = (wxDataBroker*) NULL; + m_data = (wxDataObject*) NULL; m_retValue = wxDragCancel; m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); @@ -717,24 +747,17 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm ); } -wxDropSource::wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go, const wxIcon &stop ) +wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win, + const wxIcon &go, const wxIcon &stop ) { m_waiting = TRUE; m_window = win; - m_widget = win->GetWidget(); - if (win->GetWxWindow()) m_widget = win->GetWxWindow(); + m_widget = win->m_widget; + if (win->m_wxwindow) m_widget = win->m_wxwindow; m_retValue = wxDragCancel; - if (data) - { - m_data = new wxDataBroker(); - m_data->Add( data ); - } - else - { - m_data = (wxDataBroker*) NULL; - } + m_data = &data; m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); m_goaheadCursor = wxCursor( wxCURSOR_HAND ); @@ -745,51 +768,25 @@ wxDropSource::wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go, if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm ); } -wxDropSource::wxDropSource( wxDataBroker *data, wxWindow *win ) +void wxDropSource::SetData( wxDataObject& data ) { - m_window = win; - m_widget = win->GetWidget(); - if (win->GetWxWindow()) m_widget = win->GetWxWindow(); - m_retValue = wxDragCancel; - - m_data = data; + if (m_data) + delete m_data; - m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); - m_goaheadCursor = wxCursor( wxCURSOR_HAND ); + m_data = &data; } -void wxDropSource::SetData( wxDataObject *data ) +wxDropSource::~wxDropSource() { - if (m_data) delete m_data; - - if (data) - { - m_data = new wxDataBroker(); - m_data->Add( data ); - } - else - { - m_data = (wxDataBroker*) NULL; - } -} - -void wxDropSource::SetData( wxDataBroker *data ) -{ - if (m_data) delete m_data; - - m_data = data; -} - -wxDropSource::~wxDropSource(void) -{ - if (m_data) delete m_data; + if (m_data) +// delete m_data; g_blockEventsOnDrag = FALSE; } wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) { - wxASSERT_MSG( m_data, _T("wxDragSource: no data") ); + wxASSERT_MSG( m_data, wxT("wxDragSource: no data") ); if (!m_data) return (wxDragResult) wxDragNone; @@ -800,7 +797,7 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) m_waiting = TRUE; GdkAtom atom = gdk_atom_intern( "STRING", FALSE ); -// wxPrintf( _T("atom id: %d.\n"), (int)atom ); +// printf( "atom id: %d.\n", (int)atom ); GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 ); gtk_target_list_add( target_list, atom, 0, 0 ); @@ -822,6 +819,11 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) else if (event.state & GDK_BUTTON2_MASK) button_number = 2; else if (event.state & GDK_BUTTON3_MASK) button_number = 3; +#if wxUSE_THREADS + /* disable GUI threads */ + wxapp_uninstall_thread_wakeup(); +#endif + /* don't start dragging if no button is down */ if (button_number) { @@ -846,6 +848,11 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) while (m_waiting) gtk_main_iteration();; } +#if wxUSE_THREADS + /* re-enable GUI threads */ + wxapp_install_thread_wakeup(); +#endif + g_blockEventsOnDrag = FALSE; UnregisterWindow();