From: Robert Roebling Date: Mon, 23 Nov 1998 22:54:15 +0000 (+0000) Subject: Corrected wxCHECK calls in bitmap.cpp X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/33a5bc5299a068b4d6a313a7dc830a74edb5780a Corrected wxCHECK calls in bitmap.cpp Added drop side of new DnD for GTK 1.1.3 without success Streamlined DnD Corrected frame resize for GTK 1.06 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1029 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index ce51c4ea02..1aefc002f6 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -280,8 +280,6 @@ public: virtual GtkWidget *GetConnectWidget(); virtual bool IsOwnGtkWindow( GdkWindow *window ); void ConnectWidget( GtkWidget *widget ); - void ConnectDnDWidget( GtkWidget *widget ); - void DisconnectDnDWidget( GtkWidget *widget ); bool HasVMT(); diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index ce51c4ea02..1aefc002f6 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -280,8 +280,6 @@ public: virtual GtkWidget *GetConnectWidget(); virtual bool IsOwnGtkWindow( GdkWindow *window ); void ConnectWidget( GtkWidget *widget ); - void ConnectDnDWidget( GtkWidget *widget ); - void DisconnectDnDWidget( GtkWidget *widget ); bool HasVMT(); diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 4fcbd352e0..476a09919f 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -227,33 +227,21 @@ bool wxBitmap::Ok(void) const int wxBitmap::GetHeight(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return -1; - } + wxCHECK_MSG( Ok(), -1, "invalid bitmap" ); return M_BMPDATA->m_height; } int wxBitmap::GetWidth(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return -1; - } + wxCHECK_MSG( Ok(), -1, "invalid bitmap" ); return M_BMPDATA->m_width; } int wxBitmap::GetDepth(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return -1; - } + wxCHECK_MSG( Ok(), -1, "invalid bitmap" ); return M_BMPDATA->m_bpp; } @@ -287,22 +275,14 @@ void wxBitmap::SetDepth( int depth ) wxMask *wxBitmap::GetMask(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return (wxMask *) NULL; - } + wxCHECK_MSG( Ok(), (wxMask *) NULL, "invalid bitmap" ); return M_BMPDATA->m_mask; } void wxBitmap::SetMask( wxMask *mask ) { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return; - } + wxCHECK_RET( Ok(), "invalid bitmap" ); if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; @@ -311,11 +291,7 @@ void wxBitmap::SetMask( wxMask *mask ) bool wxBitmap::SaveFile( const wxString &name, int type, wxPalette *WXUNUSED(palette) ) { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return FALSE; - } + wxCHECK_MSG( Ok(), FALSE, "invalid bitmap" ); if (type == wxBITMAP_TYPE_PNG) { @@ -371,27 +347,20 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) wxPalette *wxBitmap::GetPalette(void) const { if (!Ok()) return (wxPalette *) NULL; + return M_BMPDATA->m_palette; } GdkPixmap *wxBitmap::GetPixmap(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return (GdkPixmap *) NULL; - } + wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, "invalid bitmap" ); return M_BMPDATA->m_pixmap; } GdkBitmap *wxBitmap::GetBitmap(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return (GdkBitmap *) NULL; - } + wxCHECK_MSG( Ok(), (GdkBitmap *) NULL, "invalid bitmap" ); return M_BMPDATA->m_bitmap; } @@ -561,11 +530,7 @@ wxImage wxBitmap::ConvertToImage() const { wxImage image; - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return image; - } + wxCHECK_MSG( Ok(), image, "invalid bitmap" ); GdkImage *gdk_image = gdk_image_get( M_BMPDATA->m_pixmap, 0, 0, M_BMPDATA->m_width, M_BMPDATA->m_height ); diff --git a/src/gtk/dnd.cpp b/src/gtk/dnd.cpp index a9fa2f763a..6cdb19747f 100644 --- a/src/gtk/dnd.cpp +++ b/src/gtk/dnd.cpp @@ -36,6 +36,86 @@ extern bool g_blockEventsOnDrag; #ifdef NEW_GTK_DND_CODE +#include "gtk/gtkdnd.h" +#include "gtk/gtkselection.h" + +// ---------------------------------------------------------------------------- +// "drag_leave" +// ---------------------------------------------------------------------------- + +static void target_drag_leave( GtkWidget *WXUNUSED(widget), + GdkDragContext *WXUNUSED(context), + guint WXUNUSED(time) ) +{ + printf( "leave.\n" ); +} + +// ---------------------------------------------------------------------------- +// "drag_motion" +// ---------------------------------------------------------------------------- + +static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), + GdkDragContext *context, + gint WXUNUSED(x), + gint WXUNUSED(y), + guint time ) +{ + printf( "motion.\n" ); + gdk_drag_status( context, context->suggested_action, time ); + return TRUE; +} + +// ---------------------------------------------------------------------------- +// "drag_drop" +// ---------------------------------------------------------------------------- + +static gboolean target_drag_drop( GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time ) +{ + printf( "drop at: %d,%d.\n", x, y ); + + if (context->targets) + { + gtk_drag_get_data( widget, + context, + GPOINTER_TO_INT (context->targets->data), + time ); + } + return FALSE; +} + +// ---------------------------------------------------------------------------- +// "drag_data_received" +// ---------------------------------------------------------------------------- + +static void target_drag_data_received( GtkWidget *WXUNUSED(widget), + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *data, + guint WXUNUSED(info), + guint time ) +{ + printf( "data receive at: %d,%d.\n", x, y ); + + if ((data->length >= 0) && (data->format == 8)) + { + wxString str = (const char*)data->data; + printf( "Received %s\n.", WXSTRINGCAST str ); + gtk_drag_finish( context, TRUE, FALSE, time ); + return; + } + + gtk_drag_finish (context, FALSE, FALSE, time); +} + +// ---------------------------------------------------------------------------- +// wxDropTarget +// ---------------------------------------------------------------------------- + wxDropTarget::wxDropTarget() { } @@ -46,31 +126,47 @@ wxDropTarget::~wxDropTarget() void wxDropTarget::UnregisterWidget( GtkWidget *widget ) { - if (!widget) return; + wxCHECK_RET( widget != NULL, "unregister widget is NULL" ); - // TODO + gtk_drag_dest_set( widget, + (GtkDestDefaults) 0, + (GtkTargetEntry*) NULL, + 0, + (GdkDragAction) 0 ); + + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this ); + + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this ); + + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this ); + + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); } void wxDropTarget::RegisterWidget( GtkWidget *widget ) { - if (!widget) return; + wxCHECK_RET( widget != NULL, "register widget is NULL" ); - wxString formats; - int valid = 0; + GtkTargetEntry format; + format.info = 0; + format.flags = 0; + int valid = 0; for ( size_t i = 0; i < GetFormatCount(); i++ ) { wxDataFormat df = GetFormat( i ); switch (df) { case wxDF_TEXT: - if (i > 0) formats += ";"; - formats += "text/plain"; + format.target = "text/plain"; valid++; break; case wxDF_FILENAME: - if (i > 0) formats += ";"; - formats += "file:ALL"; + format.target = "file:ALL"; valid++; break; default: @@ -78,9 +174,25 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget ) } } - char *str = WXSTRINGCAST formats; + wxASSERT_MSG( valid != 0, "No valid DnD format supported." ); - // TODO + gtk_drag_dest_set( widget, + GTK_DEST_DEFAULT_ALL, + &format, + 1, + (GdkDragAction)(GDK_ACTION_COPY | GDK_ACTION_MOVE) ); + + gtk_signal_connect( GTK_OBJECT(widget), "drag_leave", + GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(widget), "drag_motion", + GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(widget), "drag_drop", + GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(widget), "drag_data_received", + GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); } // ---------------------------------------------------------------------------- @@ -258,7 +370,35 @@ void wxDropSource::UnregisterWindow(void) // TODO } -#else + +#else // NEW_CODE + + + +//----------------------------------------------------------------------------- +// "drop_data_available_event" +//----------------------------------------------------------------------------- + +static void gtk_target_callback( GtkWidget *widget, + GdkEventDropDataAvailable *event, + wxDropTarget *target ) +{ + if (target) + { + int x = 0; + int y = 0; + gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL ); + + printf( "Drop data is of type %s.\n", event->data_type ); + + target->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes ); + } + +/* + g_free (event->data); + g_free (event->data_type); +*/ +} // ---------------------------------------------------------------------------- // wxDropTarget @@ -274,39 +414,45 @@ wxDropTarget::~wxDropTarget() void wxDropTarget::UnregisterWidget( GtkWidget *widget ) { - if (!widget) return; + if (!widget) return; - gtk_widget_dnd_drop_set( widget, FALSE, (gchar **) NULL, 0, FALSE ); + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + GTK_SIGNAL_FUNC(gtk_target_callback), (gpointer) this ); + + gtk_widget_dnd_drop_set( widget, FALSE, (gchar **) NULL, 0, FALSE ); } void wxDropTarget::RegisterWidget( GtkWidget *widget ) { - wxString formats; - int valid = 0; + wxString formats; + int valid = 0; - for ( size_t i = 0; i < GetFormatCount(); i++ ) - { - wxDataFormat df = GetFormat( i ); - switch (df) + for ( size_t i = 0; i < GetFormatCount(); i++ ) { - case wxDF_TEXT: - if (i > 0) formats += ";"; - formats += "text/plain"; - valid++; - break; - case wxDF_FILENAME: - if (i > 0) formats += ";"; - formats += "file:ALL"; - valid++; - break; - default: - break; + wxDataFormat df = GetFormat( i ); + switch (df) + { + case wxDF_TEXT: + if (i > 0) formats += ";"; + formats += "text/plain"; + valid++; + break; + case wxDF_FILENAME: + if (i > 0) formats += ";"; + formats += "file:ALL"; + valid++; + break; + default: + break; + } } - } - char *str = WXSTRINGCAST formats; + char *str = WXSTRINGCAST formats; + + gtk_widget_dnd_drop_set( widget, TRUE, &str, valid, FALSE ); - gtk_widget_dnd_drop_set( widget, TRUE, &str, valid, FALSE ); + gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event", + GTK_SIGNAL_FUNC(gtk_target_callback), (gpointer) this ); } // ---------------------------------------------------------------------------- @@ -315,25 +461,25 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget ) bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) ) { - OnDropText( x, y, (const char*)data ); - return TRUE; + OnDropText( x, y, (const char*)data ); + return TRUE; } bool wxTextDropTarget::OnDropText( long x, long y, const char *psz ) { - printf( "Got dropped text: %s.\n", psz ); - printf( "At x: %d, y: %d.\n", (int)x, (int)y ); - return TRUE; + printf( "Got dropped text: %s.\n", psz ); + printf( "At x: %d, y: %d.\n", (int)x, (int)y ); + return TRUE; } size_t wxTextDropTarget::GetFormatCount() const { - return 1; + return 1; } wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const { - return wxDF_TEXT; + return wxDF_TEXT; } // ---------------------------------------------------------------------------- @@ -342,50 +488,50 @@ wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] ) { - printf( "Got %d dropped files.\n", (int)nFiles ); - printf( "At x: %d, y: %d.\n", (int)x, (int)y ); - for (size_t i = 0; i < nFiles; i++) - { - printf( aszFiles[i] ); - printf( "\n" ); - } - return TRUE; + printf( "Got %d dropped files.\n", (int)nFiles ); + printf( "At x: %d, y: %d.\n", (int)x, (int)y ); + for (size_t i = 0; i < nFiles; i++) + { + printf( aszFiles[i] ); + printf( "\n" ); + } + return TRUE; } bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size ) { - size_t number = 0; - char *text = (char*) data; - for (size_t i = 0; i < size; i++) - if (text[i] == 0) number++; + size_t number = 0; + char *text = (char*) data; + for (size_t i = 0; i < size; i++) + if (text[i] == 0) number++; - if (number == 0) return TRUE; + if (number == 0) return TRUE; - char **files = new char*[number]; + char **files = new char*[number]; - text = (char*) data; - for (size_t i = 0; i < number; i++) - { - files[i] = text; - int len = strlen( text ); - text += len+1; - } + text = (char*) data; + for (size_t i = 0; i < number; i++) + { + files[i] = text; + int len = strlen( text ); + text += len+1; + } - bool ret = OnDropFiles( x, y, 1, files ); + bool ret = OnDropFiles( x, y, 1, files ); - free( files ); + free( files ); - return ret; + return ret; } size_t wxFileDropTarget::GetFormatCount() const { - return 1; + return 1; } wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const { - return wxDF_FILENAME; + return wxDF_FILENAME; } //------------------------------------------------------------------------- diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 066cc2a8e9..2734acb622 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -163,7 +163,7 @@ void wxListBox::AppendCommon( const wxString &item ) ConnectWidget( list_item ); - ConnectDnDWidget( list_item ); + if (m_dropTarget) m_dropTarget->RegisterWidget( list_item ); } void wxListBox::Append( const wxString &item ) @@ -481,20 +481,26 @@ void wxListBox::SetDropTarget( wxDropTarget *dropTarget ) { wxCHECK_RET( m_list != NULL, "invalid listbox" ); - GList *child = m_list->children; - while (child) + if (m_dropTarget) { - DisconnectDnDWidget( GTK_WIDGET( child->data ) ); - child = child->next; + GList *child = m_list->children; + while (child) + { + m_dropTarget->UnregisterWidget( GTK_WIDGET( child->data ) ); + child = child->next; + } } wxWindow::SetDropTarget( dropTarget ); - child = m_list->children; - while (child) + if (m_dropTarget) { - ConnectDnDWidget( GTK_WIDGET( child->data ) ); - child = child->next; + GList *child = m_list->children; + while (child) + { + m_dropTarget->RegisterWidget( GTK_WIDGET( child->data ) ); + child = child->next; + } } } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 451e4313fd..95aa2af173 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -109,16 +109,6 @@ */ -//----------------------------------------------------------------------------- -// cond comp -//----------------------------------------------------------------------------- - -#if (GTK_MINOR_VERSION == 1) -#if (GTK_MICRO_VERSION >= 3) -#define NEW_GTK_DND_CODE -#endif -#endif - //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -852,39 +842,6 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventBut return FALSE; } - -#ifdef NEW_GTK_DND_CODE - -#else - -//----------------------------------------------------------------------------- -// "drop_data_available_event" -//----------------------------------------------------------------------------- - -static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailable *event, wxWindow *win ) -{ - if (!win->HasVMT()) return; - - if (win->GetDropTarget()) - { - int x = 0; - int y = 0; - gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL ); - - printf( "Drop data is of type %s.\n", event->data_type ); - - win->GetDropTarget()->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes ); - } - -/* - g_free (event->dropdataavailable.data); - g_free (event->dropdataavailable.data_type); -*/ -} - -#endif - // NEW_GTK_DND_CODE - //----------------------------------------------------------------------------- // InsertChild for wxWindow. //----------------------------------------------------------------------------- @@ -999,7 +956,6 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, PreCreation( parent, id, pos, size, style, name ); m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); - m_hasScrolling = TRUE; GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget); @@ -2207,12 +2163,12 @@ void wxWindow::SetDropTarget( wxDropTarget *dropTarget ) GtkWidget *dnd_widget = GetConnectWidget(); - DisconnectDnDWidget( dnd_widget ); + if (m_dropTarget) m_dropTarget->UnregisterWidget( dnd_widget ); if (m_dropTarget) delete m_dropTarget; m_dropTarget = dropTarget; - ConnectDnDWidget( dnd_widget ); + if (m_dropTarget) m_dropTarget->RegisterWidget( dnd_widget ); } wxDropTarget *wxWindow::GetDropTarget() const @@ -2220,40 +2176,6 @@ wxDropTarget *wxWindow::GetDropTarget() const return m_dropTarget; } -void wxWindow::ConnectDnDWidget( GtkWidget *widget ) -{ - if (!m_dropTarget) return; - - m_dropTarget->RegisterWidget( widget ); - -#ifdef NEW_GTK_DND_CODE - -#else - - gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event", - GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this ); - -#endif - -} - -void wxWindow::DisconnectDnDWidget( GtkWidget *widget ) -{ - if (!m_dropTarget) return; - -#ifdef NEW_GTK_DND_CODE - -#else - - gtk_signal_disconnect_by_func( GTK_OBJECT(widget), - GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this ); - - m_dropTarget->UnregisterWidget( widget ); - -#endif - -} - GtkWidget* wxWindow::GetConnectWidget() { GtkWidget *connect_widget = m_widget; @@ -2394,6 +2316,8 @@ void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible, wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); if (!m_wxwindow) return; + + m_hasScrolling = TRUE; if (orient == wxHORIZONTAL) { diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index 4fcbd352e0..476a09919f 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -227,33 +227,21 @@ bool wxBitmap::Ok(void) const int wxBitmap::GetHeight(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return -1; - } + wxCHECK_MSG( Ok(), -1, "invalid bitmap" ); return M_BMPDATA->m_height; } int wxBitmap::GetWidth(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return -1; - } + wxCHECK_MSG( Ok(), -1, "invalid bitmap" ); return M_BMPDATA->m_width; } int wxBitmap::GetDepth(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return -1; - } + wxCHECK_MSG( Ok(), -1, "invalid bitmap" ); return M_BMPDATA->m_bpp; } @@ -287,22 +275,14 @@ void wxBitmap::SetDepth( int depth ) wxMask *wxBitmap::GetMask(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return (wxMask *) NULL; - } + wxCHECK_MSG( Ok(), (wxMask *) NULL, "invalid bitmap" ); return M_BMPDATA->m_mask; } void wxBitmap::SetMask( wxMask *mask ) { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return; - } + wxCHECK_RET( Ok(), "invalid bitmap" ); if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask; @@ -311,11 +291,7 @@ void wxBitmap::SetMask( wxMask *mask ) bool wxBitmap::SaveFile( const wxString &name, int type, wxPalette *WXUNUSED(palette) ) { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return FALSE; - } + wxCHECK_MSG( Ok(), FALSE, "invalid bitmap" ); if (type == wxBITMAP_TYPE_PNG) { @@ -371,27 +347,20 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) wxPalette *wxBitmap::GetPalette(void) const { if (!Ok()) return (wxPalette *) NULL; + return M_BMPDATA->m_palette; } GdkPixmap *wxBitmap::GetPixmap(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return (GdkPixmap *) NULL; - } + wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, "invalid bitmap" ); return M_BMPDATA->m_pixmap; } GdkBitmap *wxBitmap::GetBitmap(void) const { - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return (GdkBitmap *) NULL; - } + wxCHECK_MSG( Ok(), (GdkBitmap *) NULL, "invalid bitmap" ); return M_BMPDATA->m_bitmap; } @@ -561,11 +530,7 @@ wxImage wxBitmap::ConvertToImage() const { wxImage image; - if (!Ok()) - { - wxFAIL_MSG( "invalid bitmap" ); - return image; - } + wxCHECK_MSG( Ok(), image, "invalid bitmap" ); GdkImage *gdk_image = gdk_image_get( M_BMPDATA->m_pixmap, 0, 0, M_BMPDATA->m_width, M_BMPDATA->m_height ); diff --git a/src/gtk1/dnd.cpp b/src/gtk1/dnd.cpp index a9fa2f763a..6cdb19747f 100644 --- a/src/gtk1/dnd.cpp +++ b/src/gtk1/dnd.cpp @@ -36,6 +36,86 @@ extern bool g_blockEventsOnDrag; #ifdef NEW_GTK_DND_CODE +#include "gtk/gtkdnd.h" +#include "gtk/gtkselection.h" + +// ---------------------------------------------------------------------------- +// "drag_leave" +// ---------------------------------------------------------------------------- + +static void target_drag_leave( GtkWidget *WXUNUSED(widget), + GdkDragContext *WXUNUSED(context), + guint WXUNUSED(time) ) +{ + printf( "leave.\n" ); +} + +// ---------------------------------------------------------------------------- +// "drag_motion" +// ---------------------------------------------------------------------------- + +static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), + GdkDragContext *context, + gint WXUNUSED(x), + gint WXUNUSED(y), + guint time ) +{ + printf( "motion.\n" ); + gdk_drag_status( context, context->suggested_action, time ); + return TRUE; +} + +// ---------------------------------------------------------------------------- +// "drag_drop" +// ---------------------------------------------------------------------------- + +static gboolean target_drag_drop( GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time ) +{ + printf( "drop at: %d,%d.\n", x, y ); + + if (context->targets) + { + gtk_drag_get_data( widget, + context, + GPOINTER_TO_INT (context->targets->data), + time ); + } + return FALSE; +} + +// ---------------------------------------------------------------------------- +// "drag_data_received" +// ---------------------------------------------------------------------------- + +static void target_drag_data_received( GtkWidget *WXUNUSED(widget), + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *data, + guint WXUNUSED(info), + guint time ) +{ + printf( "data receive at: %d,%d.\n", x, y ); + + if ((data->length >= 0) && (data->format == 8)) + { + wxString str = (const char*)data->data; + printf( "Received %s\n.", WXSTRINGCAST str ); + gtk_drag_finish( context, TRUE, FALSE, time ); + return; + } + + gtk_drag_finish (context, FALSE, FALSE, time); +} + +// ---------------------------------------------------------------------------- +// wxDropTarget +// ---------------------------------------------------------------------------- + wxDropTarget::wxDropTarget() { } @@ -46,31 +126,47 @@ wxDropTarget::~wxDropTarget() void wxDropTarget::UnregisterWidget( GtkWidget *widget ) { - if (!widget) return; + wxCHECK_RET( widget != NULL, "unregister widget is NULL" ); - // TODO + gtk_drag_dest_set( widget, + (GtkDestDefaults) 0, + (GtkTargetEntry*) NULL, + 0, + (GdkDragAction) 0 ); + + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this ); + + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this ); + + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this ); + + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); } void wxDropTarget::RegisterWidget( GtkWidget *widget ) { - if (!widget) return; + wxCHECK_RET( widget != NULL, "register widget is NULL" ); - wxString formats; - int valid = 0; + GtkTargetEntry format; + format.info = 0; + format.flags = 0; + int valid = 0; for ( size_t i = 0; i < GetFormatCount(); i++ ) { wxDataFormat df = GetFormat( i ); switch (df) { case wxDF_TEXT: - if (i > 0) formats += ";"; - formats += "text/plain"; + format.target = "text/plain"; valid++; break; case wxDF_FILENAME: - if (i > 0) formats += ";"; - formats += "file:ALL"; + format.target = "file:ALL"; valid++; break; default: @@ -78,9 +174,25 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget ) } } - char *str = WXSTRINGCAST formats; + wxASSERT_MSG( valid != 0, "No valid DnD format supported." ); - // TODO + gtk_drag_dest_set( widget, + GTK_DEST_DEFAULT_ALL, + &format, + 1, + (GdkDragAction)(GDK_ACTION_COPY | GDK_ACTION_MOVE) ); + + gtk_signal_connect( GTK_OBJECT(widget), "drag_leave", + GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(widget), "drag_motion", + GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(widget), "drag_drop", + GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this ); + + gtk_signal_connect( GTK_OBJECT(widget), "drag_data_received", + GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); } // ---------------------------------------------------------------------------- @@ -258,7 +370,35 @@ void wxDropSource::UnregisterWindow(void) // TODO } -#else + +#else // NEW_CODE + + + +//----------------------------------------------------------------------------- +// "drop_data_available_event" +//----------------------------------------------------------------------------- + +static void gtk_target_callback( GtkWidget *widget, + GdkEventDropDataAvailable *event, + wxDropTarget *target ) +{ + if (target) + { + int x = 0; + int y = 0; + gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL ); + + printf( "Drop data is of type %s.\n", event->data_type ); + + target->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes ); + } + +/* + g_free (event->data); + g_free (event->data_type); +*/ +} // ---------------------------------------------------------------------------- // wxDropTarget @@ -274,39 +414,45 @@ wxDropTarget::~wxDropTarget() void wxDropTarget::UnregisterWidget( GtkWidget *widget ) { - if (!widget) return; + if (!widget) return; - gtk_widget_dnd_drop_set( widget, FALSE, (gchar **) NULL, 0, FALSE ); + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + GTK_SIGNAL_FUNC(gtk_target_callback), (gpointer) this ); + + gtk_widget_dnd_drop_set( widget, FALSE, (gchar **) NULL, 0, FALSE ); } void wxDropTarget::RegisterWidget( GtkWidget *widget ) { - wxString formats; - int valid = 0; + wxString formats; + int valid = 0; - for ( size_t i = 0; i < GetFormatCount(); i++ ) - { - wxDataFormat df = GetFormat( i ); - switch (df) + for ( size_t i = 0; i < GetFormatCount(); i++ ) { - case wxDF_TEXT: - if (i > 0) formats += ";"; - formats += "text/plain"; - valid++; - break; - case wxDF_FILENAME: - if (i > 0) formats += ";"; - formats += "file:ALL"; - valid++; - break; - default: - break; + wxDataFormat df = GetFormat( i ); + switch (df) + { + case wxDF_TEXT: + if (i > 0) formats += ";"; + formats += "text/plain"; + valid++; + break; + case wxDF_FILENAME: + if (i > 0) formats += ";"; + formats += "file:ALL"; + valid++; + break; + default: + break; + } } - } - char *str = WXSTRINGCAST formats; + char *str = WXSTRINGCAST formats; + + gtk_widget_dnd_drop_set( widget, TRUE, &str, valid, FALSE ); - gtk_widget_dnd_drop_set( widget, TRUE, &str, valid, FALSE ); + gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event", + GTK_SIGNAL_FUNC(gtk_target_callback), (gpointer) this ); } // ---------------------------------------------------------------------------- @@ -315,25 +461,25 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget ) bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) ) { - OnDropText( x, y, (const char*)data ); - return TRUE; + OnDropText( x, y, (const char*)data ); + return TRUE; } bool wxTextDropTarget::OnDropText( long x, long y, const char *psz ) { - printf( "Got dropped text: %s.\n", psz ); - printf( "At x: %d, y: %d.\n", (int)x, (int)y ); - return TRUE; + printf( "Got dropped text: %s.\n", psz ); + printf( "At x: %d, y: %d.\n", (int)x, (int)y ); + return TRUE; } size_t wxTextDropTarget::GetFormatCount() const { - return 1; + return 1; } wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const { - return wxDF_TEXT; + return wxDF_TEXT; } // ---------------------------------------------------------------------------- @@ -342,50 +488,50 @@ wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] ) { - printf( "Got %d dropped files.\n", (int)nFiles ); - printf( "At x: %d, y: %d.\n", (int)x, (int)y ); - for (size_t i = 0; i < nFiles; i++) - { - printf( aszFiles[i] ); - printf( "\n" ); - } - return TRUE; + printf( "Got %d dropped files.\n", (int)nFiles ); + printf( "At x: %d, y: %d.\n", (int)x, (int)y ); + for (size_t i = 0; i < nFiles; i++) + { + printf( aszFiles[i] ); + printf( "\n" ); + } + return TRUE; } bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size ) { - size_t number = 0; - char *text = (char*) data; - for (size_t i = 0; i < size; i++) - if (text[i] == 0) number++; + size_t number = 0; + char *text = (char*) data; + for (size_t i = 0; i < size; i++) + if (text[i] == 0) number++; - if (number == 0) return TRUE; + if (number == 0) return TRUE; - char **files = new char*[number]; + char **files = new char*[number]; - text = (char*) data; - for (size_t i = 0; i < number; i++) - { - files[i] = text; - int len = strlen( text ); - text += len+1; - } + text = (char*) data; + for (size_t i = 0; i < number; i++) + { + files[i] = text; + int len = strlen( text ); + text += len+1; + } - bool ret = OnDropFiles( x, y, 1, files ); + bool ret = OnDropFiles( x, y, 1, files ); - free( files ); + free( files ); - return ret; + return ret; } size_t wxFileDropTarget::GetFormatCount() const { - return 1; + return 1; } wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const { - return wxDF_FILENAME; + return wxDF_FILENAME; } //------------------------------------------------------------------------- diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 066cc2a8e9..2734acb622 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -163,7 +163,7 @@ void wxListBox::AppendCommon( const wxString &item ) ConnectWidget( list_item ); - ConnectDnDWidget( list_item ); + if (m_dropTarget) m_dropTarget->RegisterWidget( list_item ); } void wxListBox::Append( const wxString &item ) @@ -481,20 +481,26 @@ void wxListBox::SetDropTarget( wxDropTarget *dropTarget ) { wxCHECK_RET( m_list != NULL, "invalid listbox" ); - GList *child = m_list->children; - while (child) + if (m_dropTarget) { - DisconnectDnDWidget( GTK_WIDGET( child->data ) ); - child = child->next; + GList *child = m_list->children; + while (child) + { + m_dropTarget->UnregisterWidget( GTK_WIDGET( child->data ) ); + child = child->next; + } } wxWindow::SetDropTarget( dropTarget ); - child = m_list->children; - while (child) + if (m_dropTarget) { - ConnectDnDWidget( GTK_WIDGET( child->data ) ); - child = child->next; + GList *child = m_list->children; + while (child) + { + m_dropTarget->RegisterWidget( GTK_WIDGET( child->data ) ); + child = child->next; + } } } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 451e4313fd..95aa2af173 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -109,16 +109,6 @@ */ -//----------------------------------------------------------------------------- -// cond comp -//----------------------------------------------------------------------------- - -#if (GTK_MINOR_VERSION == 1) -#if (GTK_MICRO_VERSION >= 3) -#define NEW_GTK_DND_CODE -#endif -#endif - //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -852,39 +842,6 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventBut return FALSE; } - -#ifdef NEW_GTK_DND_CODE - -#else - -//----------------------------------------------------------------------------- -// "drop_data_available_event" -//----------------------------------------------------------------------------- - -static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailable *event, wxWindow *win ) -{ - if (!win->HasVMT()) return; - - if (win->GetDropTarget()) - { - int x = 0; - int y = 0; - gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL ); - - printf( "Drop data is of type %s.\n", event->data_type ); - - win->GetDropTarget()->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes ); - } - -/* - g_free (event->dropdataavailable.data); - g_free (event->dropdataavailable.data_type); -*/ -} - -#endif - // NEW_GTK_DND_CODE - //----------------------------------------------------------------------------- // InsertChild for wxWindow. //----------------------------------------------------------------------------- @@ -999,7 +956,6 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, PreCreation( parent, id, pos, size, style, name ); m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); - m_hasScrolling = TRUE; GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget); @@ -2207,12 +2163,12 @@ void wxWindow::SetDropTarget( wxDropTarget *dropTarget ) GtkWidget *dnd_widget = GetConnectWidget(); - DisconnectDnDWidget( dnd_widget ); + if (m_dropTarget) m_dropTarget->UnregisterWidget( dnd_widget ); if (m_dropTarget) delete m_dropTarget; m_dropTarget = dropTarget; - ConnectDnDWidget( dnd_widget ); + if (m_dropTarget) m_dropTarget->RegisterWidget( dnd_widget ); } wxDropTarget *wxWindow::GetDropTarget() const @@ -2220,40 +2176,6 @@ wxDropTarget *wxWindow::GetDropTarget() const return m_dropTarget; } -void wxWindow::ConnectDnDWidget( GtkWidget *widget ) -{ - if (!m_dropTarget) return; - - m_dropTarget->RegisterWidget( widget ); - -#ifdef NEW_GTK_DND_CODE - -#else - - gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event", - GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this ); - -#endif - -} - -void wxWindow::DisconnectDnDWidget( GtkWidget *widget ) -{ - if (!m_dropTarget) return; - -#ifdef NEW_GTK_DND_CODE - -#else - - gtk_signal_disconnect_by_func( GTK_OBJECT(widget), - GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this ); - - m_dropTarget->UnregisterWidget( widget ); - -#endif - -} - GtkWidget* wxWindow::GetConnectWidget() { GtkWidget *connect_widget = m_widget; @@ -2394,6 +2316,8 @@ void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible, wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" ); if (!m_wxwindow) return; + + m_hasScrolling = TRUE; if (orient == wxHORIZONTAL) {