static gboolean
egg_tree_multi_drag_motion_event (GtkWidget      *widget,
				  GdkEventMotion *event,
				  gpointer        data)
{
  EggTreeMultiDndData *priv_data;

  priv_data = g_object_get_data (G_OBJECT (widget), EGG_TREE_MULTI_DND_STRING);

  if (gtk_drag_check_threshold (widget,
				priv_data->x,
				priv_data->y,
				event->x,
				event->y))
    {
      GList *path_list = NULL;
      GtkTreeSelection *selection;
      GtkTreeModel *model;
      GdkDragContext *context;
      TreeViewDragInfo *di;

      di = get_info (GTK_TREE_VIEW (widget));

      if (di == NULL)
	return FALSE;
      
      selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
      stop_drag_check (widget);
      gtk_tree_selection_selected_foreach (selection, selection_foreach, &path_list);
      path_list = g_list_reverse (path_list);
      model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
      if (egg_tree_multi_drag_source_row_draggable (EGG_TREE_MULTI_DRAG_SOURCE (model), path_list))
	{

	  context = gtk_drag_begin (widget,
#if GTK_CHECK_VERSION (2, 14, 0)
                                    gtk_drag_source_get_target_list (widget),
#else
				    di->source_target_list,
#endif
				    di->source_actions,
				    priv_data->pressed_button,
				    (GdkEvent*)event);
	  set_context_data (context, path_list);
	  gtk_drag_set_icon_default (context);

	}
      else
	{
	  path_list_free (path_list);
	}
    }

  return TRUE;
}
Beispiel #2
0
static gboolean
egg_tree_multi_drag_motion_event (GtkWidget      *widget,
				  GdkEventMotion *event,
				  gpointer        data)
{
  EggTreeMultiDndData *priv_data;

  priv_data = g_object_get_data (G_OBJECT (widget), EGG_TREE_MULTI_DND_STRING);

  if (gtk_drag_check_threshold (widget,
				priv_data->x,
				priv_data->y,
				event->x,
				event->y))
    {
      GList            *path_list = NULL;
      GtkTreeSelection *selection;
      GtkTreeModel     *model;
      GdkDragContext   *context;

      stop_drag_check (widget);

      selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
      gtk_tree_selection_selected_foreach (selection, selection_foreach, &path_list);
      if (path_list == NULL)
	      return FALSE;

      path_list = g_list_reverse (path_list);

      model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
      if (egg_tree_multi_drag_source_row_draggable (EGG_TREE_MULTI_DRAG_SOURCE (model), path_list))
	{
	  GtkTargetList *target_list = gtk_target_list_new (target_table,
							    G_N_ELEMENTS (target_table));

	  context = gtk_drag_begin (widget,
				    target_list,
				    GDK_ACTION_COPY,
				    priv_data->pressed_button,
				    (GdkEvent*)event);
	  set_context_data (context, path_list);
	  gtk_drag_set_icon_default (context);

	  gtk_target_list_unref (target_list);
	}
      else
	{
	  path_list_free (path_list);
	}
    }

  return TRUE;
}
static gboolean
rb_tree_dnd_motion_notify_event_cb (GtkWidget      *widget,
				     GdkEventMotion *event,
                 		     gpointer        data)
{
	RbTreeDndData *priv_data;

	priv_data = g_object_get_data (G_OBJECT (widget), RB_TREE_DND_STRING);

	if (gtk_drag_check_threshold (widget,
				      priv_data->x,
				      priv_data->y,
				      event->x,
				      event->y))
	{
		GList *path_list = NULL;
		GtkTreeSelection *selection;
		GtkTreeModel *model;
		GdkDragContext *context;

		selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
		stop_drag_check (widget);
		gtk_tree_selection_selected_foreach (selection, selection_foreach, &path_list);
		path_list = g_list_reverse (path_list);
		model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));

		if (rb_tree_drag_source_row_draggable (RB_TREE_DRAG_SOURCE (model), path_list))
		{
			rb_debug ("drag begin");
			context = gtk_drag_begin (widget,
						  priv_data->source_target_list,
						  priv_data->source_actions,
						  priv_data->pressed_button,
						  (GdkEvent*)event);
	  		set_context_data (context, path_list);
	  		gtk_drag_set_icon_default (context);

		} else {
			path_list_free (path_list);
		}
	}

	return TRUE;
}
static gboolean
egg_tree_multi_drag_motion_event (GtkWidget      *widget,
				  GdkEventMotion *event,
				  gpointer        data)
{
  EggTreeMultiDndData *priv_data;

  priv_data = g_object_get_data (G_OBJECT (widget), EGG_TREE_MULTI_DND_STRING);

  if (gtk_drag_check_threshold (widget,
				priv_data->x,
				priv_data->y,
				event->x,
				event->y))
    {
      GList *path_list = NULL;
      GtkTreeSelection *selection;
      GtkTreeModel *model;
      GdkDragContext *context;
      TreeViewDragInfo *di;

      di = get_info (GTK_TREE_VIEW (widget));

      if (di == NULL)
	return FALSE;
      
      selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
      if (priv_data->motion_notify_handler) {
        g_signal_handler_disconnect (widget, priv_data->motion_notify_handler);
        priv_data->motion_notify_handler = 0;
      }
      if (priv_data->button_release_handler) {
        g_signal_handler_disconnect (widget, priv_data->button_release_handler);
        priv_data->button_release_handler = 0;
      }
      stop_drag_check (widget);
      gtk_tree_selection_selected_foreach (selection, selection_foreach, &path_list);
      path_list = g_list_reverse (path_list);
      model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
      if (egg_tree_multi_drag_source_row_draggable (EGG_TREE_MULTI_DRAG_SOURCE (model), path_list))
	{
	  gulong sig;

	  /* This is to disconnect the default signal handler for treeviews as
  	   * it sometimes gives a warning. The default handler just sets the
	   * icon which we do as well in our callback so it is fine. */
	  sig = g_signal_connect (widget,
	                          "drag-begin",
	                          G_CALLBACK (egg_tree_multi_drag_begin),
	                          NULL);
	  context = gtk_drag_begin (widget,
				    gtk_drag_source_get_target_list (widget),
				    di->source_actions,
	                            priv_data->pressed_button,
				    (GdkEvent*)event);
	  g_signal_handler_disconnect (widget, sig);
	  set_context_data (context, path_list);
	}
      else
	{
	  path_list_free (path_list);
	}
    }
  return TRUE;
}
static gboolean
egg_tree_multi_drag_motion_event (GtkWidget      *widget,
				  GdkEventMotion *event,
				  gpointer        data)
{
  EggTreeMultiDndData *priv_data;

  priv_data = g_object_get_data (G_OBJECT (widget), EGG_TREE_MULTI_DND_STRING);

  if (! priv_data->pending_event)
    return FALSE;

  if (gtk_drag_check_threshold (widget,
				priv_data->x,
				priv_data->y,
				event->x,
				event->y))
    {
      GList            *path_list = NULL;
      GtkTreeSelection *selection;
      GtkTreeModel     *model;
      GdkDragContext   *context;

      stop_drag_check (widget);

      selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
      gtk_tree_selection_selected_foreach (selection, selection_foreach, &path_list);
      if (path_list == NULL)
	      return FALSE;

      path_list = g_list_reverse (path_list);

      model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
      if (egg_tree_multi_drag_source_row_draggable (EGG_TREE_MULTI_DRAG_SOURCE (model), path_list))
	{
	  GtkTargetList *target_list;
	  GtkTreePath   *tree_path;
	  int            cell_x;
	  int            cell_y;

	  target_list = gtk_target_list_new (target_table, G_N_ELEMENTS (target_table));
	  context = gtk_drag_begin_with_coordinates (widget,
			  	  	  	     target_list,
			  	  	  	     GDK_ACTION_COPY,
			  	  	  	     priv_data->pressed_button,
			  	  	  	     (GdkEvent*) event,
			  	  	  	     event->x,
			  	  	  	     event->y);
	  set_context_data (context, path_list);

	  if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
					     priv_data->x,
					     priv_data->y,
					     &tree_path,
					     NULL,
					     &cell_x,
					     &cell_y))
	  {
		  cairo_surface_t *drag_icon;

		  drag_icon = gtk_tree_view_create_row_drag_icon (GTK_TREE_VIEW (widget), tree_path);

		  if (path_list->next != NULL) {

			  /* create a multi row drag icon */

			  const int        icon_offset = DRAG_ICON_OFFSET;
			  GdkRectangle     icon_extents;
			  cairo_surface_t *multi_drag_icon;
			  cairo_t         *cr;
			  int              n_icons, i, offset;

			  n_icons = MIN (DRAG_ICON_MAX_ROWS, g_list_length (path_list));
			  _gtk_cairo_surface_extents (drag_icon, &icon_extents);

			  multi_drag_icon = gdk_window_create_similar_surface (gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget)),
									       CAIRO_CONTENT_COLOR_ALPHA,
									       icon_extents.width + (icon_offset * (n_icons - 1)),
									       icon_extents.height + (icon_offset * (n_icons - 1)));

			  cr = cairo_create (multi_drag_icon);

			  cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0);
			  cairo_rectangle(cr, 0, 0, icon_extents.width + icon_offset, icon_extents.height + icon_offset);
			  cairo_fill (cr);

			  offset = icon_offset * (n_icons - 1);
			  for (i = 0; i < n_icons; i++) {
				  cairo_set_source_surface (cr, drag_icon, -icon_extents.x + offset, -icon_extents.y + offset);
				  cairo_rectangle (cr, offset, offset, icon_extents.width, icon_extents.height);
				  cairo_fill (cr);
				  offset -= icon_offset;
			  }

			  cairo_destroy (cr);

			  cairo_surface_set_device_offset (multi_drag_icon, - (cell_x + 1), - (cell_y + 1));
			  gtk_drag_set_icon_surface (context, multi_drag_icon);

			  cairo_surface_destroy (multi_drag_icon);
		  }
		  else {
			  cairo_surface_set_device_offset (drag_icon, - (cell_x + 1), - (cell_y + 1));
			  gtk_drag_set_icon_surface (context, drag_icon);
		  }

		  cairo_surface_destroy (drag_icon);
		  gtk_tree_path_free (tree_path);
	  }
	  else
		  gtk_drag_set_icon_default (context);

	  gtk_target_list_unref (target_list);
	}
      else
	{
	  path_list_free (path_list);
	}
    }

  return TRUE;
}