//------------------------------------------------------------------------- // Filename: dnd.cc // Version: $Id: dnd.cc,v 1.1.4.2 1999/05/24 22:54:49 erik Exp $ // Copyright: Copyright (C) 1999, Erik Mouw (J.A.K.Mouw@its.tudelft.nl) // Author: Erik Mouw // Description: GUI drag-n-drop functions // Created at: Sun May 2 16:33:19 1999 // Modified by: Erik Mouw // Modified at: Mon May 24 14:16:06 1999 //------------------------------------------------------------------------- // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // #ident "$Id: dnd.cc,v 1.1.4.2 1999/05/24 22:54:49 erik Exp $" #ifdef HAVE_CONFIG_H # include "config.h" #endif #ifdef MUSICA_DEBUG # include #endif #include #ifdef STDC_HEADERS # include # include #endif #include #include "gui.hh" #include "dnd.hh" #ifndef HAVE_STRSTR extern "C" char *strstr(const char *haystack, const char *needle); #endif #ifndef HAVE_STRDUP extern "C" char *strdup(const char *s); #endif static void makeDropStyles(void); GtkWidget *dropEventbox = 0; GtkWidget *dropFrame = 0; static bool have_drag = false; static GtkStyle *eventBoxDefaultStyle = 0; static GtkStyle *eventBoxDropStyle = 0; static GtkStyle *frameDefaultStyle = 0; static GtkStyle *frameDropStyle = 0; gboolean dndMotionCallback(GtkWidget *widget, GdkDragContext *context, int x, int y, guint time) { if(have_drag == false) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< ": drop pocket: enter"<< endl; #endif if(eventBoxDropStyle == 0) makeDropStyles(); gtk_widget_set_style(dropFrame, eventBoxDropStyle); gtk_widget_set_style(dropEventbox, frameDropStyle); have_drag = true; } gdk_drag_status(context, context->suggested_action, time); return TRUE; } void dndLeaveCallback(GtkWidget *widget, GdkDragContext *context, guint time) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< ": drop pocket: leave"<< endl; #endif if(eventBoxDefaultStyle == 0) makeDropStyles(); gtk_widget_set_style(dropEventbox, eventBoxDefaultStyle); gtk_widget_set_style(dropFrame, frameDefaultStyle); have_drag = false; } gboolean dndDropCallback(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< ": drop pocket: drop!"<< endl; #endif if(context->targets) { gtk_drag_get_data (widget, context, GPOINTER_TO_INT (context->targets->data), time); return(TRUE); } else { return(FALSE); } } void dndDataReceivedCallback(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time) { char *filename; char *tmp; #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< ": drop pocket: "; #endif if ((data->length >= 0) && (data->format == 8)) { #ifdef MUSICA_DEBUG cerr<< "received "<< (char *)data->data<< endl; #endif // strip the "file:" part that the GNOME Midnight Commander gives us filename = strdup(strstr((char *)data->data, "/")); if(filename != 0) { // strip \r and \n tmp = strstr(filename, "\r"); if(tmp != 0) *tmp = '\0'; tmp = strstr(filename, "\n"); if(tmp != 0) *tmp = '\0'; openFile(filename); free(filename); } gtk_drag_finish(context, TRUE, FALSE, time); } else { #ifdef MUSICA_DEBUG cerr<< "unable to handle data"<< endl; #endif gtk_drag_finish(context, FALSE, FALSE, time); } } static void makeDropStyles(void) { GdkColor color = { 0,0,0,0 }; int i; if(eventBoxDefaultStyle == 0) { #ifdef MUSICA_DEBUG cerr<< __PRETTY_FUNCTION__<< endl; #endif // get the default widget style for the event box so its // background is no longer transparent eventBoxDefaultStyle = gtk_widget_get_default_style(); eventBoxDropStyle = gtk_style_copy(eventBoxDefaultStyle); // get the default style of the widget because only the // background color has to be changed frameDefaultStyle = gtk_widget_get_style(dropFrame); frameDropStyle = gtk_style_copy(frameDefaultStyle); color.red = 0x4100; color.green = 0x6900; color.blue = 0xe100; for(i = 0; i < 5; i++) { eventBoxDropStyle->bg[i] = color; frameDropStyle->bg[i] = color; } } }