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
This commit is contained in:
Robert Roebling
1998-11-23 22:54:15 +00:00
parent 8baa0e6180
commit 33a5bc5299
10 changed files with 486 additions and 408 deletions

View File

@@ -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" );
GtkTargetEntry format;
format.info = 0;
format.flags = 0;
wxString formats;
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;
}
//-------------------------------------------------------------------------