app/widgets/gimpcellrenderertoggle.[ch] added public functions to emit the

2003-03-19  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpcellrenderertoggle.[ch]
	* app/widgets/gimpcellrendererviewable.[ch]: added public
	functions to emit the "clicked" signal.

	* app/widgets/gimpcontainertreeview.c: use them instead of
	g_signal_emit_by_name().

	* app/widgets/Makefile.am
	* app/widgets/gimpcontainertreeview-dnd.[ch]: new files
	implementing DND for tree views.

	* app/widgets/gimpcontainertreeview.[ch]: added virtual
	functions drop_possible() and drop().

	* app/widgets/gimpitemtreeview.c
	* app/widgets/gimplayertreeview.c: implement drop_possible()
	and drop().
This commit is contained in:
Michael Natterer 2003-03-19 15:17:13 +00:00 committed by Michael Natterer
parent 7bb3536f88
commit 0b401af44f
14 changed files with 629 additions and 46 deletions

View File

@ -1,3 +1,23 @@
2003-03-19 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcellrenderertoggle.[ch]
* app/widgets/gimpcellrendererviewable.[ch]: added public
functions to emit the "clicked" signal.
* app/widgets/gimpcontainertreeview.c: use them instead of
g_signal_emit_by_name().
* app/widgets/Makefile.am
* app/widgets/gimpcontainertreeview-dnd.[ch]: new files
implementing DND for tree views.
* app/widgets/gimpcontainertreeview.[ch]: added virtual
functions drop_possible() and drop().
* app/widgets/gimpitemtreeview.c
* app/widgets/gimplayertreeview.c: implement drop_possible()
and drop().
2003-03-19 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpdatafactoryview.c: enable in-place name

View File

@ -55,6 +55,8 @@ libappwidgets_a_sources = \
gimpcontainermenuimpl.h \
gimpcontainertreeview.c \
gimpcontainertreeview.h \
gimpcontainertreeview-dnd.c \
gimpcontainertreeview-dnd.h \
gimpcontainerview.c \
gimpcontainerview.h \
gimpcontainerview-utils.c \

View File

@ -145,6 +145,7 @@ gimp_cell_renderer_toggle_class_init (GimpCellRendererToggleClass *klass)
cell_class->get_size = gimp_cell_renderer_toggle_get_size;
cell_class->render = gimp_cell_renderer_toggle_render;
cell_class->activate = gimp_cell_renderer_toggle_activate;
g_object_class_install_property (object_class,
PROP_STOCK_ID,
@ -451,3 +452,14 @@ gimp_cell_renderer_toggle_new (const gchar *stock_id)
"stock_id", stock_id,
NULL);
}
void
gimp_cell_renderer_toggle_clicked (GimpCellRendererToggle *cell,
const gchar *path,
GdkModifierType state)
{
g_return_if_fail (GIMP_IS_CELL_RENDERER_TOGGLE (cell));
g_return_if_fail (path != NULL);
g_signal_emit (cell, toggle_cell_signals[CLICKED], 0, path, state);
}

View File

@ -49,9 +49,9 @@ struct _GimpCellRendererToggleClass
{
GtkCellRendererToggleClass parent_class;
void (* clicked) (GimpCellRendererViewable *cell,
const gchar *path,
GdkModifierType state);
void (* clicked) (GimpCellRendererToggle *cell,
const gchar *path,
GdkModifierType state);
};
@ -59,5 +59,9 @@ GType gimp_cell_renderer_toggle_get_type (void) G_GNUC_CONST;
GtkCellRenderer * gimp_cell_renderer_toggle_new (const gchar *stock_id);
void gimp_cell_renderer_toggle_clicked (GimpCellRendererToggle *cell,
const gchar *path,
GdkModifierType state);
#endif /* __GIMP_CELL_RENDERER_TOGGLE_H__ */

View File

@ -341,3 +341,14 @@ gimp_cell_renderer_viewable_new (void)
{
return g_object_new (GIMP_TYPE_CELL_RENDERER_VIEWABLE, NULL);
}
void
gimp_cell_renderer_viewable_clicked (GimpCellRendererViewable *cell,
const gchar *path,
GdkModifierType state)
{
g_return_if_fail (GIMP_IS_CELL_RENDERER_VIEWABLE (cell));
g_return_if_fail (path != NULL);
g_signal_emit (cell, viewable_cell_signals[CLICKED], 0, path, state);
}

View File

@ -57,5 +57,8 @@ GType gimp_cell_renderer_viewable_get_type (void) G_GNUC_CONST;
GtkCellRenderer * gimp_cell_renderer_viewable_new (void);
void gimp_cell_renderer_viewable_clicked (GimpCellRendererViewable *cell,
const gchar *path,
GdkModifierType state);
#endif /* __GIMP_CELL_RENDERER_VIEWABLE_H__ */

View File

@ -0,0 +1,266 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpcontainertreeview-dnd.c
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
*
* 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.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "widgets-types.h"
#include "core/gimpcontainer.h"
#include "core/gimpviewable.h"
#include "gimpcontainertreeview.h"
#include "gimpcontainertreeview-dnd.h"
#include "gimpdnd.h"
#include "gimppreviewrenderer.h"
static gboolean
gimp_container_tree_view_drop_status (GimpContainerTreeView *tree_view,
GdkDragContext *context,
gint x,
gint y,
guint time,
GtkTreePath **return_path,
GimpViewable **return_src,
GimpViewable **return_dest,
GtkTreeViewDropPosition *return_pos)
{
GtkWidget *src_widget;
GimpViewable *src_viewable;
GtkTreePath *path;
if (! GIMP_CONTAINER_VIEW (tree_view)->reorderable)
return FALSE;
src_widget = gtk_drag_get_source_widget (context);
if (! src_widget)
return FALSE;
src_viewable = gimp_dnd_get_drag_data (src_widget);
if (! GIMP_IS_VIEWABLE (src_viewable))
return FALSE;
if (gtk_tree_view_get_path_at_pos (tree_view->view, x, y,
&path, NULL, NULL, NULL))
{
GimpPreviewRenderer *renderer;
GimpViewable *dest_viewable;
GtkTreeIter iter;
GdkRectangle cell_area;
GtkTreeViewDropPosition drop_pos;
GdkDragAction drag_action;
gtk_tree_model_get_iter (tree_view->model, &iter, path);
gtk_tree_model_get (tree_view->model, &iter,
tree_view->model_column_renderer, &renderer,
-1);
dest_viewable = renderer->viewable;
gtk_tree_view_get_cell_area (tree_view->view, path, NULL, &cell_area);
if (y >= (cell_area.y + cell_area.height / 2))
drop_pos = GTK_TREE_VIEW_DROP_AFTER;
else
drop_pos = GTK_TREE_VIEW_DROP_BEFORE;
g_object_unref (renderer);
if (GIMP_CONTAINER_TREE_VIEW_GET_CLASS (tree_view)->drop_possible (tree_view,
src_viewable,
dest_viewable,
drop_pos,
&drag_action))
{
gdk_drag_status (context, drag_action, time);
if (return_path)
*return_path = path;
else
gtk_tree_path_free (path);
if (return_src)
*return_src = src_viewable;
if (return_dest)
*return_dest = dest_viewable;
if (return_pos)
*return_pos = drop_pos;
return TRUE;
}
gdk_drag_status (context, GDK_ACTION_DEFAULT, time);
gtk_tree_path_free (path);
}
return FALSE;
}
void
gimp_container_tree_view_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time,
GimpContainerTreeView *tree_view)
{
gtk_tree_view_unset_rows_drag_dest (tree_view->view);
}
gboolean
gimp_container_tree_view_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time,
GimpContainerTreeView *tree_view)
{
GtkTreePath *path;
GtkTreeViewDropPosition drop_pos;
if (gimp_container_tree_view_drop_status (tree_view,
context, x, y, time,
&path, NULL, NULL, &drop_pos))
{
gtk_tree_view_set_drag_dest_row (tree_view->view, path, drop_pos);
gtk_tree_path_free (path);
return TRUE;
}
gtk_tree_view_unset_rows_drag_dest (tree_view->view);
return FALSE;
}
gboolean
gimp_container_tree_view_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time,
GimpContainerTreeView *tree_view)
{
GimpViewable *src_viewable;
GimpViewable *dest_viewable;
GtkTreeViewDropPosition drop_pos;
if (gimp_container_tree_view_drop_status (tree_view,
context, x, y, time,
NULL, &src_viewable, &dest_viewable,
&drop_pos))
{
GIMP_CONTAINER_TREE_VIEW_GET_CLASS (tree_view)->drop (tree_view,
src_viewable,
dest_viewable,
drop_pos);
return TRUE;
}
return TRUE;
}
gboolean
gimp_container_tree_view_real_drop_possible (GimpContainerTreeView *tree_view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos,
GdkDragAction *drag_action)
{
GimpContainerView *container_view;
GimpObject *src_object;
GimpObject *dest_object;
gint src_index;
gint dest_index;
container_view = GIMP_CONTAINER_VIEW (tree_view);
if (src_viewable == dest_viewable)
return FALSE;
src_object = GIMP_OBJECT (src_viewable);
dest_object = GIMP_OBJECT (dest_viewable);
src_index = gimp_container_get_child_index (container_view->container,
src_object);
dest_index = gimp_container_get_child_index (container_view->container,
dest_object);
if (src_index == -1 || dest_index == -1)
return FALSE;
if (drop_pos == GTK_TREE_VIEW_DROP_BEFORE)
{
if (dest_index == (src_index + 1))
return FALSE;
}
else
{
if (dest_index == (src_index - 1))
return FALSE;
}
if (drag_action)
*drag_action = GDK_ACTION_MOVE;
return TRUE;
}
void
gimp_container_tree_view_real_drop (GimpContainerTreeView *tree_view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos)
{
GimpContainerView *container_view;
GimpObject *src_object;
GimpObject *dest_object;
gint src_index;
gint dest_index;
container_view = GIMP_CONTAINER_VIEW (tree_view);
src_object = GIMP_OBJECT (src_viewable);
dest_object = GIMP_OBJECT (dest_viewable);
src_index = gimp_container_get_child_index (container_view->container,
src_object);
dest_index = gimp_container_get_child_index (container_view->container,
dest_object);
if (drop_pos == GTK_TREE_VIEW_DROP_AFTER && src_index > dest_index)
{
dest_index++;
}
else if (drop_pos == GTK_TREE_VIEW_DROP_BEFORE && src_index < dest_index)
{
dest_index--;
}
gimp_container_reorder (container_view->container, src_object, dest_index);
}

View File

@ -0,0 +1,56 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpcontainertreeview-dnd.h
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
*
* 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.
*/
#ifndef __GIMP_CONTAINER_TREE_VIEW_DND_H__
#define __GIMP_CONTAINER_TREE_VIEW_DND_H__
void gimp_container_tree_view_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time,
GimpContainerTreeView *view);
gboolean gimp_container_tree_view_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time,
GimpContainerTreeView *view);
gboolean gimp_container_tree_view_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time,
GimpContainerTreeView *view);
gboolean
gimp_container_tree_view_real_drop_possible (GimpContainerTreeView *tree_view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos,
GdkDragAction *drag_action);
void
gimp_container_tree_view_real_drop (GimpContainerTreeView *tree_view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos);
#endif /* __GIMP_CONTAINER_TREE_VIEW_DND_H__ */

View File

@ -31,8 +31,10 @@
#include "core/gimpcontext.h"
#include "core/gimpviewable.h"
#include "gimpcellrenderertoggle.h"
#include "gimpcellrendererviewable.h"
#include "gimpcontainertreeview.h"
#include "gimpcontainertreeview-dnd.h"
#include "gimpdnd.h"
#include "gimppreview.h"
#include "gimppreviewrenderer.h"
@ -139,6 +141,9 @@ gimp_container_tree_view_class_init (GimpContainerTreeViewClass *klass)
container_view_class->set_preview_size = gimp_container_tree_view_set_preview_size;
container_view_class->insert_data_free = (GDestroyNotify) g_free;
klass->drop_possible = gimp_container_tree_view_real_drop_possible;
klass->drop = gimp_container_tree_view_real_drop;
}
static void
@ -229,6 +234,16 @@ gimp_container_tree_view_constructor (GType type,
G_CALLBACK (gimp_container_tree_view_selection_changed),
tree_view);
g_signal_connect (tree_view->view, "drag_leave",
G_CALLBACK (gimp_container_tree_view_drag_leave),
tree_view);
g_signal_connect (tree_view->view, "drag_motion",
G_CALLBACK (gimp_container_tree_view_drag_motion),
tree_view);
g_signal_connect (tree_view->view, "drag_drop",
G_CALLBACK (gimp_container_tree_view_drag_drop),
tree_view);
return object;
}
@ -697,13 +712,13 @@ gimp_container_tree_view_button_press (GtkWidget *widget,
bevent->y,
&path, &column, NULL, NULL))
{
GimpPreviewRenderer *renderer;
GtkCellRenderer *toggled_cell = NULL;
GtkCellRenderer *clicked_cell = NULL;
GdkRectangle column_area;
gint tree_x;
gint tree_y;
GtkTreeIter iter;
GimpPreviewRenderer *renderer;
GimpCellRendererToggle *toggled_cell = NULL;
GimpCellRendererViewable *clicked_cell = NULL;
GdkRectangle column_area;
gint tree_x;
gint tree_y;
GtkTreeIter iter;
gtk_tree_model_get_iter (tree_view->model, &iter, path);
@ -724,13 +739,13 @@ gimp_container_tree_view_button_press (GtkWidget *widget,
&iter,
FALSE, FALSE);
toggled_cell =
toggled_cell = (GimpCellRendererToggle *)
gimp_container_tree_view_find_click_cell (tree_view->toggle_cells,
column, &column_area,
tree_x, tree_y);
if (! toggled_cell)
clicked_cell =
clicked_cell = (GimpCellRendererViewable *)
gimp_container_tree_view_find_click_cell (tree_view->renderer_cells,
column, &column_area,
tree_x, tree_y);
@ -749,15 +764,17 @@ gimp_container_tree_view_button_press (GtkWidget *widget,
if (toggled_cell)
{
/* don't select path */
g_signal_emit_by_name (toggled_cell, "clicked",
path_str, bevent->state);
gimp_cell_renderer_toggle_clicked (toggled_cell,
path_str,
bevent->state);
}
else if (clicked_cell)
{
gtk_tree_selection_select_path (tree_view->selection,
path);
g_signal_emit_by_name (clicked_cell, "clicked",
path_str, bevent->state);
gimp_cell_renderer_viewable_clicked (clicked_cell,
path_str,
bevent->state);
}
g_free (path_str);

View File

@ -70,6 +70,16 @@ struct _GimpContainerTreeView
struct _GimpContainerTreeViewClass
{
GimpContainerViewClass parent_class;
gboolean (* drop_possible) (GimpContainerTreeView *tree_view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos,
GdkDragAction *drag_action);
void (* drop) (GimpContainerTreeView *tree_view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos);
};

View File

@ -78,6 +78,16 @@ static void gimp_item_tree_view_context_item (GimpContainerView *view,
GimpViewable *item,
gpointer insert_data);
static gboolean gimp_item_tree_view_drop_possible (GimpContainerTreeView *view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos,
GdkDragAction *drag_action);
static void gimp_item_tree_view_drop (GimpContainerTreeView *view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos);
static void gimp_item_tree_view_new_clicked (GtkWidget *widget,
GimpItemTreeView *view);
static void gimp_item_tree_view_new_dropped (GtkWidget *widget,
@ -151,13 +161,15 @@ gimp_item_tree_view_get_type (void)
static void
gimp_item_tree_view_class_init (GimpItemTreeViewClass *klass)
{
GObjectClass *object_class;
GtkObjectClass *gtk_object_class;
GimpContainerViewClass *container_view_class;
GObjectClass *object_class;
GtkObjectClass *gtk_object_class;
GimpContainerViewClass *container_view_class;
GimpContainerTreeViewClass *tree_view_class;
object_class = G_OBJECT_CLASS (klass);
gtk_object_class = GTK_OBJECT_CLASS (klass);
container_view_class = GIMP_CONTAINER_VIEW_CLASS (klass);
tree_view_class = GIMP_CONTAINER_TREE_VIEW_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@ -179,6 +191,9 @@ gimp_item_tree_view_class_init (GimpItemTreeViewClass *klass)
container_view_class->activate_item = gimp_item_tree_view_activate_item;
container_view_class->context_item = gimp_item_tree_view_context_item;
tree_view_class->drop_possible = gimp_item_tree_view_drop_possible;
tree_view_class->drop = gimp_item_tree_view_drop;
klass->set_image = gimp_item_tree_view_real_set_image;
klass->get_container = NULL;
@ -337,8 +352,9 @@ gimp_item_tree_view_new (gint preview_size,
GimpMenuFactory *menu_factory,
const gchar *menu_identifier)
{
GimpItemTreeView *tree_view;
GimpContainerView *view;
GimpItemTreeView *item_view;
GimpContainerView *view;
GimpContainerTreeView *tree_view;
g_return_val_if_fail (preview_size > 0 &&
preview_size <= GIMP_PREVIEW_MAX_SIZE, NULL);
@ -352,15 +368,15 @@ gimp_item_tree_view_new (gint preview_size,
if (item_type == GIMP_TYPE_LAYER)
{
tree_view = g_object_new (GIMP_TYPE_LAYER_TREE_VIEW, NULL);
item_view = g_object_new (GIMP_TYPE_LAYER_TREE_VIEW, NULL);
}
else if (item_type == GIMP_TYPE_CHANNEL)
{
tree_view = g_object_new (GIMP_TYPE_CHANNEL_TREE_VIEW, NULL);
item_view = g_object_new (GIMP_TYPE_CHANNEL_TREE_VIEW, NULL);
}
else if (item_type == GIMP_TYPE_VECTORS)
{
tree_view = g_object_new (GIMP_TYPE_VECTORS_TREE_VIEW, NULL);
item_view = g_object_new (GIMP_TYPE_VECTORS_TREE_VIEW, NULL);
}
else
{
@ -369,45 +385,52 @@ gimp_item_tree_view_new (gint preview_size,
return NULL;
}
view = GIMP_CONTAINER_VIEW (tree_view);
view = GIMP_CONTAINER_VIEW (item_view);
tree_view = GIMP_CONTAINER_TREE_VIEW (item_view);
view->preview_size = preview_size;
view->reorderable = TRUE;
view->dnd_widget = NULL;
tree_view->item_type = item_type;
tree_view->signal_name = g_strdup (signal_name);
tree_view->new_item_func = new_item_func;
tree_view->edit_item_func = edit_item_func;
tree_view->activate_item_func = activate_item_func;
gimp_dnd_drag_dest_set_by_type (GTK_WIDGET (tree_view->view),
GTK_DEST_DEFAULT_ALL,
item_type,
GDK_ACTION_MOVE | GDK_ACTION_COPY);
tree_view->menu_factory = menu_factory;
tree_view->item_factory = gimp_menu_factory_menu_new (menu_factory,
item_view->item_type = item_type;
item_view->signal_name = g_strdup (signal_name);
item_view->new_item_func = new_item_func;
item_view->edit_item_func = edit_item_func;
item_view->activate_item_func = activate_item_func;
item_view->menu_factory = menu_factory;
item_view->item_factory = gimp_menu_factory_menu_new (menu_factory,
menu_identifier,
GTK_TYPE_MENU,
tree_view,
item_view,
FALSE);
/* connect "drop to new" manually as it makes a difference whether
* it was clicked or dropped
*/
gimp_dnd_viewable_dest_add (tree_view->new_button,
gimp_dnd_viewable_dest_add (item_view->new_button,
item_type,
gimp_item_tree_view_new_dropped,
view);
gimp_container_view_enable_dnd (view,
GTK_BUTTON (tree_view->duplicate_button),
GTK_BUTTON (item_view->duplicate_button),
item_type);
gimp_container_view_enable_dnd (view,
GTK_BUTTON (tree_view->edit_button),
GTK_BUTTON (item_view->edit_button),
item_type);
gimp_container_view_enable_dnd (view,
GTK_BUTTON (tree_view->delete_button),
GTK_BUTTON (item_view->delete_button),
item_type);
gimp_item_tree_view_set_image (tree_view, gimage);
gimp_item_tree_view_set_image (item_view, gimage);
return GTK_WIDGET (tree_view);
return GTK_WIDGET (item_view);
}
void
@ -565,6 +588,100 @@ gimp_item_tree_view_context_item (GimpContainerView *view,
NULL);
}
static gboolean
gimp_item_tree_view_drop_possible (GimpContainerTreeView *tree_view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos,
GdkDragAction *drag_action)
{
GimpItemTreeView *item_view;
item_view = GIMP_ITEM_TREE_VIEW (tree_view);
if (gimp_item_get_image (GIMP_ITEM (src_viewable)) !=
gimp_item_get_image (GIMP_ITEM (dest_viewable)))
{
if (GIMP_ITEM_TREE_VIEW_GET_CLASS (item_view)->convert_item)
{
if (drag_action)
*drag_action = GDK_ACTION_COPY;
return TRUE;
}
return FALSE;
}
return GIMP_CONTAINER_TREE_VIEW_CLASS (parent_class)->drop_possible (tree_view,
src_viewable,
dest_viewable,
drop_pos,
drag_action);
}
static void
gimp_item_tree_view_drop (GimpContainerTreeView *tree_view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos)
{
GimpContainerView *container_view;
GimpItemTreeView *item_view;
GimpItemTreeViewClass *item_view_class;
GimpObject *src_object;
GimpObject *dest_object;
gint src_index;
gint dest_index;
container_view = GIMP_CONTAINER_VIEW (tree_view);
item_view = GIMP_ITEM_TREE_VIEW (tree_view);
src_object = GIMP_OBJECT (src_viewable);
dest_object = GIMP_OBJECT (dest_viewable);
src_index = gimp_container_get_child_index (container_view->container,
src_object);
dest_index = gimp_container_get_child_index (container_view->container,
dest_object);
item_view_class = GIMP_ITEM_TREE_VIEW_GET_CLASS (item_view);
if (item_view->gimage != gimp_item_get_image (GIMP_ITEM (src_viewable)))
{
GimpItem *new_item;
if (drop_pos == GTK_TREE_VIEW_DROP_AFTER)
dest_index++;
new_item = item_view_class->convert_item (GIMP_ITEM (src_viewable),
item_view->gimage);
item_view_class->add_item (item_view->gimage,
new_item,
dest_index);
}
else
{
if (drop_pos == GTK_TREE_VIEW_DROP_AFTER && src_index > dest_index)
{
dest_index++;
}
else if (drop_pos == GTK_TREE_VIEW_DROP_BEFORE && src_index < dest_index)
{
dest_index--;
}
item_view_class->reorder_item (item_view->gimage,
GIMP_ITEM (src_object),
dest_index,
TRUE,
_("Reorder Item"));
}
gimp_image_flush (item_view->gimage);
}
/* "New" functions */

View File

@ -66,6 +66,12 @@ static void gimp_layer_tree_view_select_item (GimpContainerView *view,
gpointer insert_data);
static void gimp_layer_tree_view_set_preview_size (GimpContainerView *view);
static gboolean gimp_layer_tree_view_drop_possible (GimpContainerTreeView *view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos,
GdkDragAction *drag_action);
static void gimp_layer_tree_view_remove_item (GimpImage *gimage,
GimpItem *layer);
@ -156,14 +162,16 @@ gimp_layer_tree_view_get_type (void)
static void
gimp_layer_tree_view_class_init (GimpLayerTreeViewClass *klass)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
GimpContainerViewClass *container_view_class;
GimpItemTreeViewClass *item_view_class;
GObjectClass *object_class;
GtkWidgetClass *widget_class;
GimpContainerViewClass *container_view_class;
GimpContainerTreeViewClass *tree_view_class;
GimpItemTreeViewClass *item_view_class;
object_class = G_OBJECT_CLASS (klass);
widget_class = GTK_WIDGET_CLASS (klass);
container_view_class = GIMP_CONTAINER_VIEW_CLASS (klass);
tree_view_class = GIMP_CONTAINER_TREE_VIEW_CLASS (klass);
item_view_class = GIMP_ITEM_TREE_VIEW_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@ -177,6 +185,8 @@ gimp_layer_tree_view_class_init (GimpLayerTreeViewClass *klass)
container_view_class->select_item = gimp_layer_tree_view_select_item;
container_view_class->set_preview_size = gimp_layer_tree_view_set_preview_size;
tree_view_class->drop_possible = gimp_layer_tree_view_drop_possible;
item_view_class->get_container = gimp_image_get_layers;
item_view_class->get_active_item = (GimpGetItemFunc) gimp_image_get_active_layer;
item_view_class->set_active_item = (GimpSetItemFunc) gimp_image_set_active_layer;
@ -546,6 +556,45 @@ gimp_layer_tree_view_set_preview_size (GimpContainerView *view)
}
/* GimpContainerTreeView methods */
static gboolean
gimp_layer_tree_view_drop_possible (GimpContainerTreeView *tree_view,
GimpViewable *src_viewable,
GimpViewable *dest_viewable,
GtkTreeViewDropPosition drop_pos,
GdkDragAction *drag_action)
{
GimpLayer *src_layer;
GimpLayer *dest_layer;
GimpImage *src_image;
GimpImage *dest_image;
src_layer = GIMP_LAYER (src_viewable);
dest_layer = GIMP_LAYER (dest_viewable);
src_image = gimp_item_get_image (GIMP_ITEM (src_layer));
dest_image = gimp_item_get_image (GIMP_ITEM (dest_layer));
if (gimp_image_floating_sel (dest_image))
return FALSE;
if (! gimp_drawable_has_alpha (GIMP_DRAWABLE (dest_layer)) &&
drop_pos == GTK_TREE_VIEW_DROP_AFTER)
return FALSE;
if (src_image == dest_image &&
! gimp_drawable_has_alpha (GIMP_DRAWABLE (src_layer)))
return FALSE;
return GIMP_CONTAINER_TREE_VIEW_CLASS (parent_class)->drop_possible (tree_view,
src_viewable,
dest_viewable,
drop_pos,
drag_action);
}
/* GimpItemTreeView methods */
static void

View File

@ -145,6 +145,7 @@ gimp_cell_renderer_toggle_class_init (GimpCellRendererToggleClass *klass)
cell_class->get_size = gimp_cell_renderer_toggle_get_size;
cell_class->render = gimp_cell_renderer_toggle_render;
cell_class->activate = gimp_cell_renderer_toggle_activate;
g_object_class_install_property (object_class,
PROP_STOCK_ID,
@ -451,3 +452,14 @@ gimp_cell_renderer_toggle_new (const gchar *stock_id)
"stock_id", stock_id,
NULL);
}
void
gimp_cell_renderer_toggle_clicked (GimpCellRendererToggle *cell,
const gchar *path,
GdkModifierType state)
{
g_return_if_fail (GIMP_IS_CELL_RENDERER_TOGGLE (cell));
g_return_if_fail (path != NULL);
g_signal_emit (cell, toggle_cell_signals[CLICKED], 0, path, state);
}

View File

@ -49,9 +49,9 @@ struct _GimpCellRendererToggleClass
{
GtkCellRendererToggleClass parent_class;
void (* clicked) (GimpCellRendererViewable *cell,
const gchar *path,
GdkModifierType state);
void (* clicked) (GimpCellRendererToggle *cell,
const gchar *path,
GdkModifierType state);
};
@ -59,5 +59,9 @@ GType gimp_cell_renderer_toggle_get_type (void) G_GNUC_CONST;
GtkCellRenderer * gimp_cell_renderer_toggle_new (const gchar *stock_id);
void gimp_cell_renderer_toggle_clicked (GimpCellRendererToggle *cell,
const gchar *path,
GdkModifierType state);
#endif /* __GIMP_CELL_RENDERER_TOGGLE_H__ */