static void
drag_data_get_cb (GtkWidget *widget,
		  GdkDragContext *context,
		  GtkSelectionData *selection_data,
		  guint info,
		  guint time)
{
	GtkTreeView *tree_view;
	GtkTreeModel *model;
	GList *ref_list;

	tree_view = GTK_TREE_VIEW (widget);

	model = gtk_tree_view_get_model (tree_view);
	g_return_if_fail (model != NULL);

	ref_list = g_object_get_data (G_OBJECT (context), "drag-info");

	if (ref_list == NULL)
	{
		return;
	}

	if (EGG_IS_TREE_MULTI_DRAG_SOURCE (model))
	{
		egg_tree_multi_drag_source_drag_data_get (EGG_TREE_MULTI_DRAG_SOURCE (model),
							  ref_list,
							  selection_data);
	}
}
Beispiel #2
0
static gboolean
egg_tree_multi_drag_drag_data_get (GtkWidget        *widget,
				   GdkDragContext   *context,
				   GtkSelectionData *selection_data,
				   guint             info,
				   guint             time)
{
  GtkTreeView  *tree_view;
  GtkTreeModel *model;
  GList        *path_list;

  tree_view = GTK_TREE_VIEW (widget);
  model = gtk_tree_view_get_model (tree_view);
  if (model == NULL)
    return FALSE;

  path_list = get_context_data (context);
  if (path_list == NULL)
    return FALSE;

  /* We can implement the GTK_TREE_MODEL_ROW target generically for
   * any model; for DragSource models there are some other targets
   * we also support.
   */

  if (! EGG_IS_TREE_MULTI_DRAG_SOURCE (model))
    return FALSE;

  return egg_tree_multi_drag_source_drag_data_get (EGG_TREE_MULTI_DRAG_SOURCE (model),
      						   context,
						   selection_data,
						   path_list);
}
static gboolean
on_drag_data_get( GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint info, guint time )
{
	static const gchar *thisfn = "egg_tree_multi_dnd_on_drag_data_get";
	GtkTreeView  *tree_view;
	GtkTreeModel *model;
	GList        *path_list;

	g_debug( "%s: widget=%p, context=%p, selection_data=%p, info=%d, time=%d",
			thisfn, ( void * ) widget, ( void * ) context, ( void * ) selection_data, info, time );

	tree_view = GTK_TREE_VIEW( widget );
	model = gtk_tree_view_get_model( tree_view );
	g_assert( model );
	g_assert( EGG_IS_TREE_MULTI_DRAG_SOURCE( model ));

	path_list = get_treeview_data( widget );
	if( path_list == NULL ){
		return( FALSE );
	}

	/* We can implement the GTK_TREE_MODEL_ROW target generically for
	 * any model; for DragSource models there are some other targets
	 * we also support.
	 */
  return( egg_tree_multi_drag_source_drag_data_get(
		  EGG_TREE_MULTI_DRAG_SOURCE( model ), context, selection_data, path_list, info ));
}
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 #5
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
on_motion_event( GtkWidget *widget, GdkEventMotion *event, EggTreeMultiDragSource *drag_source )
{
	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, ( GtkTreeSelectionForeachFunc ) 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 )){

			GtkTargetList *target_list = v_get_target_list( drag_source );
			GdkDragAction actions = v_get_drag_actions( drag_source );

			context = gtk_drag_begin(
					widget, target_list, actions, priv_data->pressed_button, ( GdkEvent * ) event );

			set_treeview_data( widget, path_list );

			gtk_drag_set_icon_default( context );

			v_free_target_list( drag_source, target_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 (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;
}