virtual GtkWidget *GetConnectWidget();
virtual bool IsOwnGtkWindow( GdkWindow *window );
void ConnectWidget( GtkWidget *widget );
- void ConnectDnDWidget( GtkWidget *widget );
- void DisconnectDnDWidget( GtkWidget *widget );
bool HasVMT();
virtual GtkWidget *GetConnectWidget();
virtual bool IsOwnGtkWindow( GdkWindow *window );
void ConnectWidget( GtkWidget *widget );
- void ConnectDnDWidget( GtkWidget *widget );
- void DisconnectDnDWidget( GtkWidget *widget );
bool HasVMT();
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;
}
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;
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)
{
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;
}
{
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 );
#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()
{
}
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:
}
}
- 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 );
}
// ----------------------------------------------------------------------------
// 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
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 );
}
// ----------------------------------------------------------------------------
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;
}
// ----------------------------------------------------------------------------
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;
}
//-------------------------------------------------------------------------
ConnectWidget( list_item );
- ConnectDnDWidget( list_item );
+ if (m_dropTarget) m_dropTarget->RegisterWidget( list_item );
}
void wxListBox::Append( const wxString &item )
{
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;
+ }
}
}
*/
-//-----------------------------------------------------------------------------
-// cond comp
-//-----------------------------------------------------------------------------
-
-#if (GTK_MINOR_VERSION == 1)
-#if (GTK_MICRO_VERSION >= 3)
-#define NEW_GTK_DND_CODE
-#endif
-#endif
-
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
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.
//-----------------------------------------------------------------------------
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);
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
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;
wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" );
if (!m_wxwindow) return;
+
+ m_hasScrolling = TRUE;
if (orient == wxHORIZONTAL)
{
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;
}
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;
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)
{
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;
}
{
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 );
#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()
{
}
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:
}
}
- 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 );
}
// ----------------------------------------------------------------------------
// 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
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 );
}
// ----------------------------------------------------------------------------
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;
}
// ----------------------------------------------------------------------------
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;
}
//-------------------------------------------------------------------------
ConnectWidget( list_item );
- ConnectDnDWidget( list_item );
+ if (m_dropTarget) m_dropTarget->RegisterWidget( list_item );
}
void wxListBox::Append( const wxString &item )
{
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;
+ }
}
}
*/
-//-----------------------------------------------------------------------------
-// cond comp
-//-----------------------------------------------------------------------------
-
-#if (GTK_MINOR_VERSION == 1)
-#if (GTK_MICRO_VERSION >= 3)
-#define NEW_GTK_DND_CODE
-#endif
-#endif
-
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
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.
//-----------------------------------------------------------------------------
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);
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
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;
wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" );
if (!m_wxwindow) return;
+
+ m_hasScrolling = TRUE;
if (orient == wxHORIZONTAL)
{