static gboolean
image_drag_drop_cb (GtkWidget *widget,
		    GdkDragContext *context,
		    gint x, gint y, guint time, EImageChooser *chooser)
{
	GList *p;

	if (!chooser->priv->editable)
		return FALSE;

	if (context->targets == NULL) {
		return FALSE;
	}

	for (p = context->targets; p != NULL; p = p->next) {
		char *possible_type;

		possible_type = gdk_atom_name (GDK_POINTER_TO_ATOM (p->data));
		if (!strcmp (possible_type, URI_LIST_TYPE)) {
			g_free (possible_type);
			gtk_drag_get_data (widget, context,
					   GDK_POINTER_TO_ATOM (p->data),
					   time);
			return TRUE;
		}

		g_free (possible_type);
	}

	return FALSE;
}
static gboolean
avatar_chooser_drag_drop_cb (GtkWidget          *widget,
			    GdkDragContext     *context,
			    gint                x,
			    gint                y,
			    guint               time,
			    EmpathyAvatarChooser *chooser)
{
	EmpathyAvatarChooserPriv *priv;
	GList                  *p;

	priv = GET_PRIV (chooser);

	if (context->targets == NULL) {
		return FALSE;
	}

	for (p = context->targets; p != NULL; p = p->next) {
		char *possible_type;

		possible_type = gdk_atom_name (GDK_POINTER_TO_ATOM (p->data));
		if (!strcmp (possible_type, URI_LIST_TYPE)) {
			g_free (possible_type);
			gtk_drag_get_data (widget, context,
					   GDK_POINTER_TO_ATOM (p->data),
					   time);

			return TRUE;
		}

		g_free (possible_type);
	}

	return FALSE;
}
示例#3
0
gboolean
on_extensions_view_drag_drop(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, guint time)
{
	/* Iterate through the list of target types provided by the source */
	GdkAtom target_type = NULL;
	GList *iter;
	for(iter = gdk_drag_context_list_targets(drag_context); iter != NULL; iter = g_list_next(iter)) {
		gchar *type_name = gdk_atom_name(GDK_POINTER_TO_ATOM(iter->data));
		/* Select 'text/uri-list' from the list of available targets */
		if(!strcmp(type_name, "text/uri-list")) {
			g_free(type_name);
			target_type = GDK_POINTER_TO_ATOM(iter->data);
			break;
		}
		g_free(type_name);
	}
	/* If URI list not supported, then cancel */
	if(!target_type)
		return FALSE;

	/* Request the data from the source. */
	gtk_drag_get_data(
	  widget,         /* this widget, which will get 'drag-data-received' */
	  drag_context,   /* represents the current state of the DnD */
	  target_type,    /* the target type we want */
	  time);            /* time stamp */
	return TRUE;
}
static gboolean
image_drag_motion_cb (GtkWidget *widget,
		      GdkDragContext *context,
		      gint x, gint y, guint time, EImageChooser *chooser)
{
	GList *p;

	if (!chooser->priv->editable)
		return FALSE;

	for (p = gdk_drag_context_list_targets (context); p; p = p->next) {
		char *possible_type;

		possible_type = gdk_atom_name (GDK_POINTER_TO_ATOM (p->data));
		if (!strcmp (possible_type, URI_LIST_TYPE)) {
			g_free (possible_type);
			gdk_drag_status (context, GDK_ACTION_COPY, time);
			return TRUE;
		}

		g_free (possible_type);
	}

	return FALSE;
}
示例#5
0
static gboolean
is_this_drop_ok (GtkWidget      *widget,
		 GdkDragContext *context)
{
	static GdkAtom  text_uri_list = GDK_NONE;
	GList           *l;
	GtkWidget       *source;

	source = gtk_drag_get_source_widget (context);

	if (source == widget)
		return FALSE;

	if (!(gdk_drag_context_get_actions (context) & GDK_ACTION_COPY))
		return FALSE;

	if (!text_uri_list)
		text_uri_list = gdk_atom_intern_static_string ("text/uri-list");

	for (l = gdk_drag_context_list_targets (context); l; l = l->next) {
		if (GDK_POINTER_TO_ATOM (l->data) == text_uri_list)
			break;
	}

	return l ? TRUE : FALSE;
}
gboolean
contact_list_editor_drag_motion_cb (GtkWidget *widget,
                                    GdkDragContext *context,
                                    gint x, gint y,
                                    guint time)
{
	EContactListEditor *editor;
	GList *iter;

	editor = contact_list_editor_extract (widget);

	for (iter = context->targets; iter != NULL; iter = iter->next) {
		GdkAtom target = GDK_POINTER_TO_ATOM (iter->data);
		gchar *possible_type;
		gboolean match;

		possible_type = gdk_atom_name (target);
		match = (strcmp (possible_type, VCARD_TYPE) == 0);
		g_free (possible_type);

		if (match) {
			gdk_drag_status (context, GDK_ACTION_LINK, time);
			return TRUE;
		}
	}

	return FALSE;
}
示例#7
0
文件: testdnd.c 项目: BYC/gtk
gboolean
target_drag_motion	   (GtkWidget	       *widget,
			    GdkDragContext     *context,
			    gint                x,
			    gint                y,
			    guint               time)
{
  GtkWidget *source_widget;
  GList *tmp_list;

  if (!have_drag)
    {
      have_drag = TRUE;
      gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_open);
    }

  source_widget = gtk_drag_get_source_widget (context);
  g_print ("motion, source %s\n", source_widget ?
	   G_OBJECT_TYPE_NAME (source_widget) :
	   "NULL");

  tmp_list = gdk_drag_context_list_targets (context);
  while (tmp_list)
    {
      char *name = gdk_atom_name (GDK_POINTER_TO_ATOM (tmp_list->data));
      g_print ("%s\n", name);
      g_free (name);
      
      tmp_list = tmp_list->next;
    }

  gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time);

  return TRUE;
}
示例#8
0
gboolean
panel_check_dnd_target_data (GtkWidget      *widget,
			     GdkDragContext *context,
			     guint          *ret_info,
			     GdkAtom        *ret_atom)
{
	GList *l;

	g_return_val_if_fail (widget, FALSE);

	if (!PANEL_IS_TOPLEVEL  (widget) &&
	    !BUTTON_IS_WIDGET (widget))
		return FALSE;

	if (!(gdk_drag_context_get_actions (context) & (GDK_ACTION_COPY|GDK_ACTION_MOVE)))
		return FALSE;

	for (l = gdk_drag_context_list_targets (context); l; l = l->next) {
		GdkAtom atom;
		guint   info;

		atom = GDK_POINTER_TO_ATOM (l->data);

		if (gtk_target_list_find (get_target_list (), atom, &info)) {
			if (ret_info)
				*ret_info = info;

			if (ret_atom)
				*ret_atom = atom;
			break;
		}
	}

	return l ? TRUE : FALSE;
}
示例#9
0
文件: dragdrop.c 项目: AreaScout/vice
/* Emitted when the user releases (drops) the selection. It should check that
 * the drop is over a valid part of the widget (if its a complex widget), and
 * itself to return true if the operation should continue. Next choose the
 * target type it wishes to ask the source for. Finally call gtk_drag_get_data
 * which will emit "drag-data-get" on the source. */
static gboolean drag_drop_handler(GtkWidget *widget, GdkDragContext *context, 
    gint x, gint y, guint time, gpointer user_data)
{
    GdkAtom target_type;
    GList *targets = gdk_drag_context_list_targets(context);

    DBG(("drag_drop_handler"));

    /* If the source offers a target */
    if (targets) {
        /* Choose the best target type */
        target_type = GDK_POINTER_TO_ATOM(g_list_nth_data (targets, TARGET_STRING));

        dropdata = 1;
        /* Request the data from the source. */
        gtk_drag_get_data(
            widget,         /* will receive 'drag-data-received' signal */
            context,        /* represents the current state of the DnD */
            target_type,    /* the target type we want */
            time            /* time stamp */
        );
        return TRUE;
    }
    /* No target offered by source => error */
    return FALSE;
}
static gboolean dnd_drop (GtkWidget * widget, GdkDragContext * context, gint x, gint y, guint time, AudioModulePanel * action) {
	GdkAtom target_type;
	action -> not_ready_for_drop = false;
	if (context -> targets) {
		target_type = GDK_POINTER_TO_ATOM (g_list_nth_data (context -> targets, 0));
		gtk_drag_get_data (widget, context, target_type, time);
	} else return FALSE;
	return TRUE;
}
jobjectArray dnd_target_get_mimes(JNIEnv *env)
{
    if (check_state_in_drag(env)) {
        return NULL;
    }
    if (!enter_ctx.mimes) {
        GList* targets = GLASS_GDK_DRAG_CONTEXT_LIST_TARGETS(enter_ctx.ctx);
        jobject set = env->NewObject(jHashSetCls, jHashSetInit, NULL);

        while (targets) {
            GdkAtom target = GDK_POINTER_TO_ATOM(targets->data);
            gchar *name = gdk_atom_name(target);

            if (target_is_text(target)) {
                env->CallBooleanMethod(set, jSetAdd, env->NewStringUTF("text/plain"), NULL);
            }

            if (target_is_image(target)) {
                env->CallBooleanMethod(set, jSetAdd, env->NewStringUTF("application/x-java-rawimage"), NULL);
            }

            if (target_is_uri(target)) {
                selection_data_ctx ctx;
                if (dnd_target_receive_data(env, TARGET_MIME_URI_LIST_ATOM, &ctx)) {
                    gchar** uris = g_uri_list_extract_uris((gchar *) ctx.data);
                    guint size = g_strv_length(uris);
                    guint files_cnt = get_files_count(uris);
                    if (files_cnt) {
                        env->CallBooleanMethod(set, jSetAdd, env->NewStringUTF("application/x-java-file-list"), NULL);
                    }
                    if (size - files_cnt) {
                        env->CallBooleanMethod(set, jSetAdd, env->NewStringUTF("text/uri-list"), NULL);
                    }
                    g_strfreev(uris);
                }
                g_free(ctx.data);
            } else {
                env->CallBooleanMethod(set, jSetAdd, env->NewStringUTF(name), NULL);
            }

            g_free(name);
            targets = targets->next;
        }
        enter_ctx.mimes = env->NewObjectArray(env->CallIntMethod(set, jSetSize, NULL),
                jStringCls, NULL);
        enter_ctx.mimes = (jobjectArray)env->CallObjectMethod(set, jSetToArray, enter_ctx.mimes, NULL);
        enter_ctx.mimes = (jobjectArray)env->NewGlobalRef(enter_ctx.mimes);
    }
    return enter_ctx.mimes;
}
/**
 * gdk_x11_xatom_to_atom_for_display:
 * @display: A #GdkDisplay
 * @xatom: an X atom 
 * 
 * Convert from an X atom for a #GdkDisplay to the corresponding
 * #GdkAtom.
 * 
 * Return value: the corresponding #GdkAtom.
 *
 * Since: 2.2
 **/
GdkAtom
gdk_x11_xatom_to_atom_for_display (GdkDisplay *display,
				   Atom	       xatom)
{
  GdkDisplayX11 *display_x11;
  GdkAtom virtual_atom = GDK_NONE;
  
  g_return_val_if_fail (GDK_IS_DISPLAY (display), GDK_NONE);

  if (xatom == None)
    return GDK_NONE;

  if (display->closed)
    return GDK_NONE;

  display_x11 = GDK_DISPLAY_X11 (display);
  
  if (xatom < G_N_ELEMENTS (xatoms_offset) - N_CUSTOM_PREDEFINED)
    return INDEX_TO_ATOM (xatom);
  
  if (display_x11->atom_to_virtual)
    virtual_atom = GDK_POINTER_TO_ATOM (g_hash_table_lookup (display_x11->atom_to_virtual,
							     GUINT_TO_POINTER (xatom)));
  
  if (!virtual_atom)
    {
      /* If this atom doesn't exist, we'll die with an X error unless
       * we take precautions
       */
      char *name;
      gdk_error_trap_push ();
      name = XGetAtomName (GDK_DISPLAY_XDISPLAY (display), xatom);
      if (gdk_error_trap_pop ())
	{
	  g_warning (G_STRLOC " invalid X atom: %ld", xatom);
	}
      else
	{
	  virtual_atom = gdk_atom_intern (name, FALSE);
	  XFree (name);
	  
	  insert_atom_pair (display, virtual_atom, xatom);
	}
    }

  return virtual_atom;
}
示例#13
0
static gboolean drag_drop(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, guint time, gpointer user_data){
#if GTK_CHECK_VERSION(2,21,0)
	GList *l=gdk_drag_context_list_targets(drag_context);
	GList *elem;

	if (l){
		ms_message("drag_drop");
		/* Choose the best target type */
		for(elem=l;elem!=NULL;elem=g_list_next(elem)){
			char *name=gdk_atom_name(GDK_POINTER_TO_ATOM(elem->data));
			ms_message("target: %s",name);
			g_free(name);
		}
	}else{
		ms_warning("drag_drop no targets");
		return FALSE;
	}
#endif
	return TRUE;
}
static GdkAtom
intern_atom (const gchar *atom_name, 
	     gboolean     dup)
{
  GdkAtom result;

  virtual_atom_check_init ();
  
  result = GDK_POINTER_TO_ATOM (g_hash_table_lookup (virtual_atom_hash, atom_name));
  if (!result)
    {
      result = INDEX_TO_ATOM (virtual_atom_array->len);
      
      g_ptr_array_add (virtual_atom_array, dup ? g_strdup (atom_name) : (gchar *)atom_name);
      g_hash_table_insert (virtual_atom_hash, 
			   g_ptr_array_index (virtual_atom_array,
					      ATOM_TO_INDEX (result)),
			   GDK_ATOM_TO_POINTER (result));
    }

  return result;
}
示例#15
0
文件: testdnd.c 项目: BYC/gtk
gboolean
target_drag_drop	   (GtkWidget	       *widget,
			    GdkDragContext     *context,
			    gint                x,
			    gint                y,
			    guint               time)
{
  g_print("drop\n");
  have_drag = FALSE;

  gtk_image_set_from_pixbuf (GTK_IMAGE (widget), trashcan_closed);

  if (gdk_drag_context_list_targets (context))
    {
      gtk_drag_get_data (widget, context,
			 GDK_POINTER_TO_ATOM (gdk_drag_context_list_targets (context)->data),
			 time);
      return TRUE;
    }
  
  return FALSE;
}
示例#16
0
文件: dnd.cpp 项目: madnessw/thesnow
static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget),
                                    GdkDragContext *context,
                                    gint x,
                                    gint y,
                                    guint time,
                                    wxDropTarget *drop_target )
{
    /* Owen Taylor: "if the coordinates not in a drop zone,
       return FALSE, otherwise call gtk_drag_status() and
       return TRUE" */

#if 0
    wxPrintf( "motion\n" );
    GList *tmp_list;
    for (tmp_list = context->targets; tmp_list; tmp_list = tmp_list->next)
    {
        wxString atom = wxString::FromAscii( gdk_atom_name (GDK_POINTER_TO_ATOM (tmp_list->data)) );
        wxPrintf( "Atom: %s\n", atom );
    }
#endif

    // Inform the wxDropTarget about the current GdkDragContext.
    // This is only valid for the duration of this call.
    drop_target->GTKSetDragContext( context );

    // Does the source actually accept the data type?
    if (drop_target->GTKGetMatchingPair() == (GdkAtom) 0)
    {
        drop_target->GTKSetDragContext( NULL );
        return FALSE;
    }

    wxDragResult suggested_action = drop_target->GTKFigureOutSuggestedAction();

    wxDragResult result = wxDragNone;

    if (drop_target->m_firstMotion)
    {
        // the first "drag_motion" event substitutes a "drag_enter" event
        result = drop_target->OnEnter( x, y, suggested_action );
    }
    else
    {
        // give program a chance to react (i.e. to say no by returning FALSE)
        result = drop_target->OnDragOver( x, y, suggested_action );
    }

    GdkDragAction result_action = GDK_ACTION_DEFAULT;
    if (result == wxDragCopy)
        result_action = GDK_ACTION_COPY;
    else if (result == wxDragLink)
        result_action = GDK_ACTION_LINK;
    else
        result_action = GDK_ACTION_MOVE;

    // is result action actually supported
    bool ret ((result_action != GDK_ACTION_DEFAULT) &&
              (context->actions & result_action));

    if (ret)
        gdk_drag_status( context, result_action, time );

    // after this, invalidate the drop_target's GdkDragContext
    drop_target->GTKSetDragContext( NULL );

    // this has to be done because GDK has no "drag_enter" event
    drop_target->m_firstMotion = false;

    return ret;
}
示例#17
0
文件: dnd.cpp 项目: jonntd/dynamica
static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget),
                                    GdkDragContext *context,
                                    gint x,
                                    gint y,
                                    guint time,
                                    wxDropTarget *drop_target )
{
    /* Owen Taylor: "if the coordinates not in a drop zone,
       return FALSE, otherwise call gtk_drag_status() and
       return TRUE" */

#if 0
    wxPrintf( "motion\n" );
    GList *tmp_list;
    for (tmp_list = context->targets; tmp_list; tmp_list = tmp_list->next)
    {
        wxString atom = wxString::FromAscii( gdk_atom_name (GDK_POINTER_TO_ATOM (tmp_list->data)) );
        wxPrintf( "Atom: %s\n", atom );
    }
#endif

    /* inform the wxDropTarget about the current GdkDragContext.
       this is only valid for the duration of this call */
    drop_target->GtkSetDragContext( context );

    // GTK+ always supposes that we want to copy the data by default while we
    // might want to move it, so examine not only suggested_action - which is
    // only good if we don't have our own preferences - but also the actions
    // field
    wxDragResult result;
    if (drop_target->GetDefaultAction() == wxDragNone)
    {
        // use default action set by wxDropSource::DoDragDrop()
        if ( (gs_flagsForDrag & wxDrag_DefaultMove) == wxDrag_DefaultMove &&
            (context->actions & GDK_ACTION_MOVE ) )
        {
             // move is requested by the program and allowed by GTK+ - do it, even
            // though suggested_action may be currently wxDragCopy
            result = wxDragMove;
        }
        else // use whatever GTK+ says we should
        {
            result = ConvertFromGTK(context->suggested_action);

            if ( (result == wxDragMove) && !(gs_flagsForDrag & wxDrag_AllowMove) )
            {
                // we're requested to move but we can't
                result = wxDragCopy;
            }
        }
    }
    else if (drop_target->GetDefaultAction() == wxDragMove &&
                (context->actions & GDK_ACTION_MOVE))
    {
        
       result = wxDragMove;
    }
    else
    {
        if (context->actions & GDK_ACTION_COPY)
            result = wxDragCopy;
        else if (context->actions & GDK_ACTION_MOVE)
            result = wxDragMove;
        else
            result = wxDragNone;
    }

    if (drop_target->m_firstMotion)
    {
        /* the first "drag_motion" event substitutes a "drag_enter" event */
        result = drop_target->OnEnter( x, y, result );
    }
    else
    {
        /* give program a chance to react (i.e. to say no by returning FALSE) */
        result = drop_target->OnDragOver( x, y, result );
    }

    bool ret = wxIsDragResultOk( result );
    if (ret)
    {
        GdkDragAction action;
        if (result == wxDragCopy)
            action = GDK_ACTION_COPY;
        else if (result == wxDragLink)
            action = GDK_ACTION_LINK;
        else
            action = GDK_ACTION_MOVE;

        gdk_drag_status( context, action, time );
    }

    /* after this, invalidate the drop_target's GdkDragContext */
    drop_target->GtkSetDragContext( NULL );

    /* this has to be done because GDK has no "drag_enter" event */
    drop_target->m_firstMotion = false;

    return ret;
}