2003-02-22 03:03:19 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpcontainertreeview.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"
|
|
|
|
|
2003-03-26 22:56:10 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2003-02-22 03:03:19 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2003-02-27 00:17:10 +08:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2003-02-22 03:03:19 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpviewable.h"
|
|
|
|
|
2003-03-19 23:17:13 +08:00
|
|
|
#include "gimpcellrenderertoggle.h"
|
2003-02-27 00:17:10 +08:00
|
|
|
#include "gimpcellrendererviewable.h"
|
2003-02-22 03:03:19 +08:00
|
|
|
#include "gimpcontainertreeview.h"
|
2003-03-19 23:17:13 +08:00
|
|
|
#include "gimpcontainertreeview-dnd.h"
|
2003-02-22 03:03:19 +08:00
|
|
|
#include "gimpdnd.h"
|
2003-03-01 11:53:41 +08:00
|
|
|
#include "gimppreviewrenderer.h"
|
2003-03-16 19:14:29 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
COLUMN_RENDERER,
|
2003-02-22 03:03:19 +08:00
|
|
|
COLUMN_NAME,
|
2003-05-21 19:34:00 +08:00
|
|
|
COLUMN_NAME_ATTRIBUTES,
|
2003-02-22 03:03:19 +08:00
|
|
|
NUM_COLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_container_tree_view_class_init (GimpContainerTreeViewClass *klass);
|
|
|
|
static void gimp_container_tree_view_init (GimpContainerTreeView *view);
|
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
static GObject *gimp_container_tree_view_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
2003-02-22 03:03:19 +08:00
|
|
|
static void gimp_container_tree_view_set_container (GimpContainerView *view,
|
|
|
|
GimpContainer *container);
|
|
|
|
|
|
|
|
static gpointer gimp_container_tree_view_insert_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gint index);
|
|
|
|
static void gimp_container_tree_view_remove_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data);
|
|
|
|
static void gimp_container_tree_view_reorder_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gint new_index,
|
|
|
|
gpointer insert_data);
|
2003-05-18 21:28:27 +08:00
|
|
|
static gboolean gimp_container_tree_view_select_item (GimpContainerView *view,
|
2003-02-22 03:03:19 +08:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data);
|
|
|
|
static void gimp_container_tree_view_clear_items (GimpContainerView *view);
|
2003-03-07 00:47:34 +08:00
|
|
|
static void gimp_container_tree_view_set_preview_size (GimpContainerView *view);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
static void gimp_container_tree_view_selection_changed (GtkTreeSelection *sel,
|
|
|
|
GimpContainerTreeView *tree_view);
|
|
|
|
static gboolean gimp_container_tree_view_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GimpContainerTreeView *tree_view);
|
2003-03-07 00:47:34 +08:00
|
|
|
static void gimp_container_tree_view_renderer_update (GimpPreviewRenderer *renderer,
|
|
|
|
GimpContainerTreeView *tree_view);
|
|
|
|
static void gimp_container_tree_view_name_changed (GimpObject *object,
|
|
|
|
GimpContainerTreeView *tree_view);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
static GimpViewable * gimp_container_tree_view_drag_viewable (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2003-02-25 04:31:14 +08:00
|
|
|
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
static GimpContainerViewClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_container_tree_view_get_type (void)
|
|
|
|
{
|
|
|
|
static GType view_type = 0;
|
|
|
|
|
|
|
|
if (! view_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo view_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpContainerTreeViewClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gimp_container_tree_view_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpContainerTreeView),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_container_tree_view_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
view_type = g_type_register_static (GIMP_TYPE_CONTAINER_VIEW,
|
|
|
|
"GimpContainerTreeView",
|
|
|
|
&view_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_class_init (GimpContainerTreeViewClass *klass)
|
|
|
|
{
|
2003-03-16 19:14:29 +08:00
|
|
|
GObjectClass *object_class;
|
2003-02-22 03:03:19 +08:00
|
|
|
GimpContainerViewClass *container_view_class;
|
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
2003-02-22 03:03:19 +08:00
|
|
|
container_view_class = GIMP_CONTAINER_VIEW_CLASS (klass);
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
object_class->constructor = gimp_container_tree_view_constructor;
|
|
|
|
|
2003-02-22 03:03:19 +08:00
|
|
|
container_view_class->set_container = gimp_container_tree_view_set_container;
|
|
|
|
container_view_class->insert_item = gimp_container_tree_view_insert_item;
|
|
|
|
container_view_class->remove_item = gimp_container_tree_view_remove_item;
|
|
|
|
container_view_class->reorder_item = gimp_container_tree_view_reorder_item;
|
|
|
|
container_view_class->select_item = gimp_container_tree_view_select_item;
|
|
|
|
container_view_class->clear_items = gimp_container_tree_view_clear_items;
|
|
|
|
container_view_class->set_preview_size = gimp_container_tree_view_set_preview_size;
|
2003-02-25 04:31:14 +08:00
|
|
|
|
|
|
|
container_view_class->insert_data_free = (GDestroyNotify) g_free;
|
2003-03-19 23:17:13 +08:00
|
|
|
|
|
|
|
klass->drop_possible = gimp_container_tree_view_real_drop_possible;
|
|
|
|
klass->drop = gimp_container_tree_view_real_drop;
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_init (GimpContainerTreeView *tree_view)
|
|
|
|
{
|
2003-03-26 22:56:10 +08:00
|
|
|
GimpContainerView *view;
|
|
|
|
|
|
|
|
view = GIMP_CONTAINER_VIEW (tree_view);
|
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
tree_view->n_model_columns = NUM_COLUMNS;
|
|
|
|
|
2003-05-21 19:34:00 +08:00
|
|
|
tree_view->model_columns[COLUMN_RENDERER] = GIMP_TYPE_PREVIEW_RENDERER;
|
|
|
|
tree_view->model_columns[COLUMN_NAME] = G_TYPE_STRING;
|
|
|
|
tree_view->model_columns[COLUMN_NAME_ATTRIBUTES] = PANGO_TYPE_ATTR_LIST;
|
2003-03-16 19:14:29 +08:00
|
|
|
|
2003-05-21 19:34:00 +08:00
|
|
|
tree_view->model_column_renderer = COLUMN_RENDERER;
|
|
|
|
tree_view->model_column_name = COLUMN_NAME;
|
|
|
|
tree_view->model_column_name_attributes = COLUMN_NAME_ATTRIBUTES;
|
2003-03-16 19:14:29 +08:00
|
|
|
|
2003-03-26 22:56:10 +08:00
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view->scrolled_win),
|
2003-02-22 03:03:19 +08:00
|
|
|
GTK_SHADOW_IN);
|
2003-03-26 22:56:10 +08:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view->scrolled_win),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2003-03-16 19:14:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
gimp_container_tree_view_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
2003-03-26 22:56:10 +08:00
|
|
|
GimpContainerView *view;
|
2003-03-16 19:14:29 +08:00
|
|
|
GtkListStore *list;
|
|
|
|
GObject *object;
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
|
|
|
tree_view = GIMP_CONTAINER_TREE_VIEW (object);
|
2003-03-26 22:56:10 +08:00
|
|
|
view = GIMP_CONTAINER_VIEW (object);
|
2003-03-16 19:14:29 +08:00
|
|
|
|
|
|
|
list = gtk_list_store_newv (tree_view->n_model_columns,
|
|
|
|
tree_view->model_columns);
|
2003-03-14 06:17:31 +08:00
|
|
|
tree_view->model = GTK_TREE_MODEL (list);
|
|
|
|
|
|
|
|
tree_view->view =
|
|
|
|
GTK_TREE_VIEW (gtk_tree_view_new_with_model (tree_view->model));
|
|
|
|
g_object_unref (list);
|
2003-03-20 22:34:16 +08:00
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
gtk_tree_view_set_headers_visible (tree_view->view, FALSE);
|
2003-03-26 22:56:10 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (view->scrolled_win),
|
2003-03-16 19:14:29 +08:00
|
|
|
GTK_WIDGET (tree_view->view));
|
|
|
|
gtk_widget_show (GTK_WIDGET (tree_view->view));
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-02-25 04:31:14 +08:00
|
|
|
GIMP_CONTAINER_VIEW (tree_view)->dnd_widget = GTK_WIDGET (tree_view->view);
|
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
tree_view->main_column = gtk_tree_view_column_new ();
|
|
|
|
gtk_tree_view_insert_column (tree_view->view, tree_view->main_column, 0);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
tree_view->renderer_cell = gimp_cell_renderer_viewable_new ();
|
|
|
|
gtk_tree_view_column_pack_start (tree_view->main_column,
|
|
|
|
tree_view->renderer_cell,
|
|
|
|
FALSE);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
gtk_tree_view_column_set_attributes (tree_view->main_column,
|
|
|
|
tree_view->renderer_cell,
|
|
|
|
"renderer", COLUMN_RENDERER,
|
|
|
|
NULL);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
tree_view->name_cell = gtk_cell_renderer_text_new ();
|
|
|
|
g_object_set (tree_view->name_cell, "xalign", 0.0, NULL);
|
|
|
|
gtk_tree_view_column_pack_end (tree_view->main_column,
|
|
|
|
tree_view->name_cell,
|
|
|
|
FALSE);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
gtk_tree_view_column_set_attributes (tree_view->main_column,
|
|
|
|
tree_view->name_cell,
|
2003-05-21 19:34:00 +08:00
|
|
|
"text", COLUMN_NAME,
|
|
|
|
"attributes", COLUMN_NAME_ATTRIBUTES,
|
2003-03-16 19:14:29 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
tree_view->renderer_cells = g_list_prepend (tree_view->renderer_cells,
|
|
|
|
tree_view->renderer_cell);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
tree_view->selection = gtk_tree_view_get_selection (tree_view->view);
|
|
|
|
|
|
|
|
g_signal_connect (tree_view->selection, "changed",
|
|
|
|
G_CALLBACK (gimp_container_tree_view_selection_changed),
|
|
|
|
tree_view);
|
2003-03-16 19:14:29 +08:00
|
|
|
|
2003-03-19 23:17:13 +08:00
|
|
|
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);
|
|
|
|
|
2003-03-26 22:56:10 +08:00
|
|
|
gtk_tree_view_set_search_column (tree_view->view, COLUMN_NAME);
|
|
|
|
gtk_tree_view_set_enable_search (tree_view->view, TRUE);
|
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
return object;
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gimp_container_tree_view_new (GimpContainer *container,
|
|
|
|
GimpContext *context,
|
|
|
|
gint preview_size,
|
2003-04-08 20:39:02 +08:00
|
|
|
gint preview_border_width,
|
|
|
|
gboolean reorderable)
|
2003-02-22 03:03:19 +08:00
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
|
|
|
|
2003-03-26 22:56:10 +08:00
|
|
|
g_return_val_if_fail (container == NULL || GIMP_IS_CONTAINER (container),
|
|
|
|
NULL);
|
|
|
|
g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
|
2003-02-27 00:17:10 +08:00
|
|
|
g_return_val_if_fail (preview_size > 0 &&
|
2003-04-01 21:53:47 +08:00
|
|
|
preview_size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, NULL);
|
2003-04-08 20:39:02 +08:00
|
|
|
g_return_val_if_fail (preview_border_width >= 0 &&
|
|
|
|
preview_border_width <= GIMP_PREVIEW_MAX_BORDER_WIDTH,
|
|
|
|
NULL);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
tree_view = g_object_new (GIMP_TYPE_CONTAINER_TREE_VIEW, NULL);
|
|
|
|
|
2003-03-27 01:49:42 +08:00
|
|
|
gimp_container_view_construct (GIMP_CONTAINER_VIEW (tree_view),
|
|
|
|
container, context,
|
2003-04-08 20:39:02 +08:00
|
|
|
preview_size, preview_border_width,
|
|
|
|
reorderable);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
return GTK_WIDGET (tree_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_set (GimpContainerTreeView *tree_view,
|
|
|
|
GtkTreeIter *iter,
|
2003-03-01 11:53:41 +08:00
|
|
|
GimpViewable *viewable)
|
2003-02-22 03:03:19 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
GimpContainerView *view;
|
|
|
|
GimpPreviewRenderer *renderer;
|
|
|
|
gchar *name;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
view = GIMP_CONTAINER_VIEW (tree_view);
|
|
|
|
|
2003-04-09 00:01:01 +08:00
|
|
|
name = gimp_viewable_get_description (viewable, NULL);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2003-03-03 20:59:03 +08:00
|
|
|
renderer = gimp_preview_renderer_new (G_TYPE_FROM_INSTANCE (viewable),
|
2003-03-16 19:14:29 +08:00
|
|
|
view->preview_size,
|
2003-04-05 05:16:58 +08:00
|
|
|
view->preview_border_width,
|
2003-03-16 19:14:29 +08:00
|
|
|
FALSE);
|
2003-03-03 20:59:03 +08:00
|
|
|
gimp_preview_renderer_set_viewable (renderer, viewable);
|
|
|
|
gimp_preview_renderer_remove_idle (renderer);
|
2003-02-25 04:31:14 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
g_signal_connect (renderer, "update",
|
|
|
|
G_CALLBACK (gimp_container_tree_view_renderer_update),
|
|
|
|
tree_view);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_list_store_set (GTK_LIST_STORE (tree_view->model), iter,
|
2003-03-01 11:53:41 +08:00
|
|
|
COLUMN_RENDERER, renderer,
|
|
|
|
COLUMN_NAME, name,
|
2003-02-22 03:03:19 +08:00
|
|
|
-1);
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
g_object_unref (renderer);
|
|
|
|
g_free (name);
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* GimpContainerView methods */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_set_container (GimpContainerView *view,
|
|
|
|
GimpContainer *container)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
|
|
|
|
|
|
|
tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
|
|
|
|
if (view->container)
|
|
|
|
{
|
|
|
|
gimp_container_remove_handler (view->container,
|
|
|
|
tree_view->name_changed_handler_id);
|
2003-02-25 04:31:14 +08:00
|
|
|
|
|
|
|
if (! container)
|
|
|
|
{
|
|
|
|
if (gimp_dnd_viewable_source_unset (GTK_WIDGET (tree_view->view),
|
|
|
|
view->container->children_type))
|
|
|
|
{
|
|
|
|
gtk_drag_source_unset (GTK_WIDGET (tree_view->view));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (tree_view->view,
|
|
|
|
gimp_container_tree_view_button_press,
|
|
|
|
tree_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (container)
|
|
|
|
{
|
|
|
|
if (gimp_dnd_drag_source_set_by_type (GTK_WIDGET (tree_view->view),
|
|
|
|
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
|
|
|
|
container->children_type,
|
|
|
|
GDK_ACTION_COPY))
|
|
|
|
{
|
|
|
|
gimp_dnd_viewable_source_set (GTK_WIDGET (tree_view->view),
|
|
|
|
container->children_type,
|
|
|
|
gimp_container_tree_view_drag_viewable,
|
|
|
|
tree_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* connect button_press_event after DND so we can keep the list from
|
|
|
|
* selecting the item on button2
|
|
|
|
*/
|
|
|
|
g_signal_connect (tree_view->view, "button_press_event",
|
|
|
|
G_CALLBACK (gimp_container_tree_view_button_press),
|
|
|
|
tree_view);
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GIMP_CONTAINER_VIEW_CLASS (parent_class)->set_container (view, container);
|
|
|
|
|
|
|
|
if (view->container)
|
|
|
|
{
|
2003-02-25 04:31:14 +08:00
|
|
|
GimpViewableClass *viewable_class;
|
|
|
|
|
|
|
|
viewable_class = g_type_class_ref (container->children_type);
|
|
|
|
|
2003-02-22 03:03:19 +08:00
|
|
|
tree_view->name_changed_handler_id =
|
2003-02-25 04:31:14 +08:00
|
|
|
gimp_container_add_handler (view->container,
|
|
|
|
viewable_class->name_changed_signal,
|
2003-02-22 03:03:19 +08:00
|
|
|
G_CALLBACK (gimp_container_tree_view_name_changed),
|
|
|
|
tree_view);
|
2003-02-25 04:31:14 +08:00
|
|
|
|
|
|
|
g_type_class_unref (viewable_class);
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
gimp_container_tree_view_insert_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gint index)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
|
|
|
GtkTreeIter *iter;
|
|
|
|
|
|
|
|
tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
|
|
|
|
iter = g_new0 (GtkTreeIter, 1);
|
|
|
|
|
|
|
|
if (index == -1)
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_list_store_append (GTK_LIST_STORE (tree_view->model), iter);
|
2003-02-22 03:03:19 +08:00
|
|
|
else
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_list_store_insert (GTK_LIST_STORE (tree_view->model), iter, index);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_container_tree_view_set (tree_view, iter, viewable);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
return (gpointer) iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_remove_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
|
|
|
GtkTreeIter *iter;
|
|
|
|
|
|
|
|
tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
iter = (GtkTreeIter *) insert_data;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
if (iter)
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_list_store_remove (GTK_LIST_STORE (tree_view->model), iter);
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_reorder_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gint new_index,
|
|
|
|
gpointer insert_data)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
|
|
|
GtkTreeIter *iter;
|
|
|
|
|
|
|
|
tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
iter = (GtkTreeIter *) insert_data;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
if (iter)
|
|
|
|
{
|
2003-03-14 06:17:31 +08:00
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter selected_iter;
|
|
|
|
gboolean selected;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
selected = gtk_tree_selection_get_selected (tree_view->selection,
|
|
|
|
NULL, &selected_iter);
|
2003-02-27 00:17:10 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
if (selected)
|
|
|
|
{
|
2003-03-16 19:14:29 +08:00
|
|
|
GimpPreviewRenderer *renderer;
|
2003-02-27 00:17:10 +08:00
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_tree_model_get (tree_view->model, &selected_iter,
|
2003-03-16 19:14:29 +08:00
|
|
|
COLUMN_RENDERER, &renderer,
|
2003-03-07 00:47:34 +08:00
|
|
|
-1);
|
2003-02-27 00:17:10 +08:00
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
if (renderer->viewable != viewable)
|
2003-03-07 00:47:34 +08:00
|
|
|
selected = FALSE;
|
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
g_object_unref (renderer);
|
2003-03-07 00:47:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (new_index == -1 || new_index == view->container->num_children - 1)
|
|
|
|
{
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_list_store_move_before (GTK_LIST_STORE (tree_view->model),
|
|
|
|
iter, NULL);
|
2003-03-07 00:47:34 +08:00
|
|
|
}
|
|
|
|
else if (new_index == 0)
|
|
|
|
{
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_list_store_move_after (GTK_LIST_STORE (tree_view->model),
|
|
|
|
iter, NULL);
|
2003-03-07 00:47:34 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkTreeIter place_iter;
|
|
|
|
gint old_index;
|
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
path = gtk_tree_model_get_path (tree_view->model, iter);
|
2003-03-16 19:14:29 +08:00
|
|
|
old_index = gtk_tree_path_get_indices (path)[0];
|
2003-03-07 00:47:34 +08:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
if (new_index != old_index)
|
|
|
|
{
|
|
|
|
path = gtk_tree_path_new_from_indices (new_index, -1);
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_tree_model_get_iter (tree_view->model, &place_iter, path);
|
2003-03-07 00:47:34 +08:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
if (new_index > old_index)
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_list_store_move_after (GTK_LIST_STORE (tree_view->model),
|
|
|
|
iter, &place_iter);
|
2003-03-07 00:47:34 +08:00
|
|
|
else
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_list_store_move_before (GTK_LIST_STORE (tree_view->model),
|
|
|
|
iter, &place_iter);
|
2003-03-07 00:47:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected)
|
|
|
|
{
|
2003-03-14 06:17:31 +08:00
|
|
|
path = gtk_tree_model_get_path (tree_view->model, iter);
|
2003-03-07 00:47:34 +08:00
|
|
|
gtk_tree_view_scroll_to_cell (tree_view->view, path,
|
|
|
|
NULL, FALSE, 0.0, 0.0);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-18 21:28:27 +08:00
|
|
|
static gboolean
|
2003-02-22 03:03:19 +08:00
|
|
|
gimp_container_tree_view_select_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
|
|
|
GtkTreeIter *iter;
|
|
|
|
|
|
|
|
tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
iter = (GtkTreeIter *) insert_data;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
if (iter)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter selected_iter;
|
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected (tree_view->selection, NULL,
|
|
|
|
&selected_iter))
|
|
|
|
{
|
2003-03-16 19:14:29 +08:00
|
|
|
GimpPreviewRenderer *renderer;
|
|
|
|
gboolean equal;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_tree_model_get (tree_view->model, &selected_iter,
|
2003-03-16 19:14:29 +08:00
|
|
|
COLUMN_RENDERER, &renderer,
|
2003-02-22 03:03:19 +08:00
|
|
|
-1);
|
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
equal = (renderer->viewable == viewable);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
g_object_unref (renderer);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
if (equal)
|
2003-05-18 21:28:27 +08:00
|
|
|
return TRUE;
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
path = gtk_tree_model_get_path (tree_view->model, iter);
|
|
|
|
|
2003-02-22 03:03:19 +08:00
|
|
|
g_signal_handlers_block_by_func (tree_view->selection,
|
|
|
|
gimp_container_tree_view_selection_changed,
|
|
|
|
tree_view);
|
|
|
|
|
2003-03-23 00:26:11 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning FIXME: remove this hack as soon as #108956 is fixed.
|
|
|
|
#endif
|
|
|
|
if (tree_view->main_column->editable_widget)
|
|
|
|
gtk_cell_editable_remove_widget (tree_view->main_column->editable_widget);
|
|
|
|
|
|
|
|
gtk_tree_view_set_cursor (tree_view->view, path, NULL, FALSE);
|
2003-03-29 00:08:00 +08:00
|
|
|
gtk_tree_selection_select_iter (tree_view->selection, iter);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (tree_view->selection,
|
|
|
|
gimp_container_tree_view_selection_changed,
|
|
|
|
tree_view);
|
|
|
|
|
|
|
|
gtk_tree_view_scroll_to_cell (tree_view->view, path,
|
2003-03-07 00:47:34 +08:00
|
|
|
NULL, FALSE, 0.0, 0.0);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_tree_selection_unselect_all (tree_view->selection);
|
|
|
|
}
|
2003-05-18 21:28:27 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_clear_items (GimpContainerView *view)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
|
|
|
|
|
|
|
tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_list_store_clear (GTK_LIST_STORE (tree_view->model));
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
GIMP_CONTAINER_VIEW_CLASS (parent_class)->clear_items (view);
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_set_preview_size (GimpContainerView *view)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
2003-03-16 19:14:29 +08:00
|
|
|
GtkWidget *tree_widget;
|
2003-02-22 03:03:19 +08:00
|
|
|
GtkTreeIter iter;
|
2003-03-13 21:08:37 +08:00
|
|
|
gboolean iter_valid;
|
2003-03-16 19:14:29 +08:00
|
|
|
GList *list;
|
|
|
|
|
|
|
|
tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
|
|
|
|
tree_widget = GTK_WIDGET (tree_view->view);
|
|
|
|
|
|
|
|
for (list = tree_view->toggle_cells; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
gchar *stock_id;
|
|
|
|
GtkIconSize icon_size;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
g_object_get (list->data, "stock-id", &stock_id, NULL);
|
|
|
|
|
|
|
|
if (stock_id)
|
|
|
|
{
|
|
|
|
icon_size = gimp_get_icon_size (tree_widget,
|
|
|
|
stock_id,
|
|
|
|
GTK_ICON_SIZE_BUTTON,
|
|
|
|
view->preview_size -
|
|
|
|
2 * tree_widget->style->xthickness,
|
|
|
|
view->preview_size -
|
|
|
|
2 * tree_widget->style->ythickness);
|
|
|
|
|
|
|
|
g_object_set (list->data, "stock-size", icon_size, NULL);
|
|
|
|
|
|
|
|
g_free (stock_id);
|
|
|
|
}
|
|
|
|
}
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
for (iter_valid = gtk_tree_model_get_iter_first (tree_view->model, &iter);
|
2003-03-13 21:08:37 +08:00
|
|
|
iter_valid;
|
2003-03-14 06:17:31 +08:00
|
|
|
iter_valid = gtk_tree_model_iter_next (tree_view->model, &iter))
|
2003-02-22 03:03:19 +08:00
|
|
|
{
|
2003-03-13 21:08:37 +08:00
|
|
|
GimpPreviewRenderer *renderer;
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_tree_model_get (tree_view->model, &iter,
|
2003-03-13 21:08:37 +08:00
|
|
|
COLUMN_RENDERER, &renderer,
|
|
|
|
-1);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2003-04-05 05:16:58 +08:00
|
|
|
gimp_preview_renderer_set_size (renderer,
|
|
|
|
view->preview_size,
|
|
|
|
view->preview_border_width);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2003-03-13 21:08:37 +08:00
|
|
|
g_object_unref (renderer);
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
2003-03-14 06:17:31 +08:00
|
|
|
|
|
|
|
gtk_tree_view_columns_autosize (tree_view->view);
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_selection_changed (GtkTreeSelection *selection,
|
|
|
|
GimpContainerTreeView *tree_view)
|
|
|
|
{
|
2003-03-16 19:14:29 +08:00
|
|
|
GtkTreeIter iter;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
|
|
|
|
{
|
|
|
|
GimpPreviewRenderer *renderer;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
gtk_tree_model_get (tree_view->model, &iter,
|
|
|
|
COLUMN_RENDERER, &renderer,
|
|
|
|
-1);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
gimp_container_view_item_selected (GIMP_CONTAINER_VIEW (tree_view),
|
2003-03-16 19:14:29 +08:00
|
|
|
renderer->viewable);
|
|
|
|
g_object_unref (renderer);
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-16 21:19:43 +08:00
|
|
|
static GtkCellRenderer *
|
|
|
|
gimp_container_tree_view_find_click_cell (GList *cells,
|
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
GdkRectangle *column_area,
|
|
|
|
gint tree_x,
|
|
|
|
gint tree_y)
|
|
|
|
{
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = cells; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
gint start_pos;
|
|
|
|
gint width;
|
|
|
|
|
|
|
|
renderer = (GtkCellRenderer *) list->data;
|
|
|
|
|
|
|
|
if (renderer->visible &&
|
|
|
|
gtk_tree_view_column_cell_get_position (column, renderer,
|
|
|
|
&start_pos, &width) &&
|
|
|
|
width > 0 &&
|
|
|
|
column_area->x + start_pos + renderer->xpad <= tree_x &&
|
|
|
|
column_area->x + start_pos + renderer->xpad + width - 1 >= tree_x)
|
|
|
|
{
|
2003-03-23 00:26:11 +08:00
|
|
|
#if 0
|
2003-03-29 00:08:00 +08:00
|
|
|
g_print ("click on cell at %d (%d width) (%d column->x) (%d tree_x)\n",
|
|
|
|
start_pos, width, column_area->x, tree_x);
|
2003-03-23 00:26:11 +08:00
|
|
|
#endif
|
2003-03-16 21:19:43 +08:00
|
|
|
|
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-02-22 03:03:19 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_container_tree_view_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GimpContainerTreeView *tree_view)
|
|
|
|
{
|
2003-03-16 19:14:29 +08:00
|
|
|
GimpContainerView *container_view;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
container_view = GIMP_CONTAINER_VIEW (tree_view);
|
2003-02-25 04:31:14 +08:00
|
|
|
|
|
|
|
tree_view->dnd_viewable = NULL;
|
|
|
|
|
2003-03-26 22:56:10 +08:00
|
|
|
if (! GTK_WIDGET_HAS_FOCUS (widget))
|
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
|
2003-02-25 04:31:14 +08:00
|
|
|
if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
|
|
|
|
bevent->x,
|
|
|
|
bevent->y,
|
2003-03-16 19:14:29 +08:00
|
|
|
&path, &column, NULL, NULL))
|
2003-02-22 03:03:19 +08:00
|
|
|
{
|
2003-03-19 23:17:13 +08:00
|
|
|
GimpPreviewRenderer *renderer;
|
|
|
|
GimpCellRendererToggle *toggled_cell = NULL;
|
|
|
|
GimpCellRendererViewable *clicked_cell = NULL;
|
2003-03-23 00:26:11 +08:00
|
|
|
GtkCellRenderer *edit_cell = NULL;
|
2003-03-19 23:17:13 +08:00
|
|
|
GdkRectangle column_area;
|
|
|
|
gint tree_x;
|
|
|
|
gint tree_y;
|
|
|
|
GtkTreeIter iter;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_tree_model_get_iter (tree_view->model, &iter, path);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_tree_model_get (tree_view->model, &iter,
|
2003-03-16 19:14:29 +08:00
|
|
|
COLUMN_RENDERER, &renderer,
|
2003-02-25 04:31:14 +08:00
|
|
|
-1);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
tree_view->dnd_viewable = renderer->viewable;
|
|
|
|
|
|
|
|
gtk_tree_view_widget_to_tree_coords (tree_view->view,
|
|
|
|
bevent->x, bevent->y,
|
|
|
|
&tree_x, &tree_y);
|
|
|
|
gtk_tree_view_get_background_area (tree_view->view, path,
|
|
|
|
column, &column_area);
|
|
|
|
|
|
|
|
gtk_tree_view_column_cell_set_cell_data (column,
|
|
|
|
tree_view->model,
|
|
|
|
&iter,
|
|
|
|
FALSE, FALSE);
|
|
|
|
|
2003-03-19 23:17:13 +08:00
|
|
|
toggled_cell = (GimpCellRendererToggle *)
|
2003-03-16 21:19:43 +08:00
|
|
|
gimp_container_tree_view_find_click_cell (tree_view->toggle_cells,
|
|
|
|
column, &column_area,
|
|
|
|
tree_x, tree_y);
|
2003-03-16 19:14:29 +08:00
|
|
|
|
2003-03-16 21:19:43 +08:00
|
|
|
if (! toggled_cell)
|
2003-03-19 23:17:13 +08:00
|
|
|
clicked_cell = (GimpCellRendererViewable *)
|
2003-03-16 21:19:43 +08:00
|
|
|
gimp_container_tree_view_find_click_cell (tree_view->renderer_cells,
|
|
|
|
column, &column_area,
|
|
|
|
tree_x, tree_y);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-03-23 00:26:11 +08:00
|
|
|
if (! toggled_cell && ! clicked_cell)
|
|
|
|
edit_cell =
|
|
|
|
gimp_container_tree_view_find_click_cell (tree_view->editable_cells,
|
|
|
|
column, &column_area,
|
|
|
|
tree_x, tree_y);
|
|
|
|
|
|
|
|
g_object_ref (tree_view);
|
|
|
|
|
2003-02-25 04:31:14 +08:00
|
|
|
switch (bevent->button)
|
|
|
|
{
|
|
|
|
case 1:
|
2003-03-16 19:14:29 +08:00
|
|
|
if (bevent->type == GDK_BUTTON_PRESS)
|
2003-03-07 00:47:34 +08:00
|
|
|
{
|
2003-05-18 21:28:27 +08:00
|
|
|
gboolean success = TRUE;
|
|
|
|
|
2003-03-23 00:26:11 +08:00
|
|
|
/* don't select item if a toggle was clicked */
|
|
|
|
if (! toggled_cell)
|
2003-05-18 21:28:27 +08:00
|
|
|
success = gimp_container_view_item_selected (container_view,
|
|
|
|
renderer->viewable);
|
2003-03-23 00:26:11 +08:00
|
|
|
|
|
|
|
/* a callback invoked by selecting the item may have
|
|
|
|
* destroyed us, so check if the container is still there
|
|
|
|
*/
|
|
|
|
if (container_view->container)
|
2003-03-16 19:14:29 +08:00
|
|
|
{
|
2003-03-23 00:26:11 +08:00
|
|
|
gchar *path_str = NULL;
|
2003-03-16 19:14:29 +08:00
|
|
|
|
2003-03-25 09:25:39 +08:00
|
|
|
/* another row may have been set by selecting */
|
|
|
|
gtk_tree_view_column_cell_set_cell_data (column,
|
|
|
|
tree_view->model,
|
|
|
|
&iter,
|
|
|
|
FALSE, FALSE);
|
|
|
|
|
2003-03-23 00:26:11 +08:00
|
|
|
if (toggled_cell || clicked_cell)
|
|
|
|
path_str = gtk_tree_path_to_string (path);
|
2003-03-16 19:14:29 +08:00
|
|
|
|
|
|
|
if (toggled_cell)
|
|
|
|
{
|
2003-03-19 23:17:13 +08:00
|
|
|
gimp_cell_renderer_toggle_clicked (toggled_cell,
|
|
|
|
path_str,
|
|
|
|
bevent->state);
|
2003-03-16 19:14:29 +08:00
|
|
|
}
|
2003-03-16 21:19:43 +08:00
|
|
|
else if (clicked_cell)
|
2003-03-16 19:14:29 +08:00
|
|
|
{
|
2003-03-19 23:17:13 +08:00
|
|
|
gimp_cell_renderer_viewable_clicked (clicked_cell,
|
|
|
|
path_str,
|
|
|
|
bevent->state);
|
2003-03-16 19:14:29 +08:00
|
|
|
}
|
|
|
|
|
2003-03-23 00:26:11 +08:00
|
|
|
if (path_str)
|
|
|
|
g_free (path_str);
|
2003-03-16 19:14:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bevent->type == GDK_2BUTTON_PRESS)
|
|
|
|
{
|
2003-05-18 21:28:27 +08:00
|
|
|
gboolean success = TRUE;
|
|
|
|
|
|
|
|
/* don't select item if a toggle was clicked */
|
|
|
|
if (! toggled_cell)
|
|
|
|
success = gimp_container_view_item_selected (container_view,
|
|
|
|
renderer->viewable);
|
|
|
|
|
|
|
|
if (success)
|
2003-03-23 00:26:11 +08:00
|
|
|
{
|
2003-05-18 21:28:27 +08:00
|
|
|
if (edit_cell)
|
|
|
|
{
|
2003-03-23 00:26:11 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning FIXME: remove this hack as soon as #108956 is fixed.
|
|
|
|
#endif
|
2003-05-18 21:28:27 +08:00
|
|
|
if (column->editable_widget)
|
|
|
|
gtk_cell_editable_remove_widget (column->editable_widget);
|
2003-03-23 00:26:11 +08:00
|
|
|
|
2003-04-30 02:25:12 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#warning FIXME: make sure the orig text gets restored when cancelling editing
|
|
|
|
#endif
|
2003-05-18 21:28:27 +08:00
|
|
|
if (edit_cell == tree_view->name_cell)
|
|
|
|
{
|
|
|
|
const gchar *real_name;
|
|
|
|
|
|
|
|
real_name =
|
|
|
|
gimp_object_get_name (GIMP_OBJECT (renderer->viewable));
|
|
|
|
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (tree_view->model),
|
|
|
|
&iter,
|
|
|
|
tree_view->model_column_name,
|
|
|
|
real_name,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_view_set_cursor_on_cell (tree_view->view, path,
|
|
|
|
column, edit_cell, TRUE);
|
|
|
|
}
|
|
|
|
else if (! toggled_cell) /* ignore double click on toggles */
|
2003-04-30 02:25:12 +08:00
|
|
|
{
|
2003-05-18 21:28:27 +08:00
|
|
|
gimp_container_view_item_activated (container_view,
|
|
|
|
renderer->viewable);
|
2003-04-30 02:25:12 +08:00
|
|
|
}
|
2003-03-23 00:26:11 +08:00
|
|
|
}
|
2003-03-07 00:47:34 +08:00
|
|
|
}
|
2003-02-25 04:31:14 +08:00
|
|
|
break;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-02-25 04:31:14 +08:00
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2003-05-18 21:28:27 +08:00
|
|
|
if (gimp_container_view_item_selected (container_view,
|
|
|
|
renderer->viewable))
|
|
|
|
{
|
|
|
|
if (container_view->container)
|
|
|
|
gimp_container_view_item_context (GIMP_CONTAINER_VIEW (tree_view),
|
|
|
|
renderer->viewable);
|
|
|
|
}
|
2003-02-25 04:31:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
2003-02-25 04:31:14 +08:00
|
|
|
|
2003-03-23 00:26:11 +08:00
|
|
|
g_object_unref (tree_view);
|
|
|
|
|
2003-03-16 19:14:29 +08:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
g_object_unref (renderer);
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
2003-03-23 00:26:11 +08:00
|
|
|
return TRUE;
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_container_tree_view_renderer_update (GimpPreviewRenderer *renderer,
|
|
|
|
GimpContainerTreeView *tree_view)
|
2003-02-22 03:03:19 +08:00
|
|
|
{
|
|
|
|
GimpContainerView *view;
|
|
|
|
GtkTreeIter *iter;
|
|
|
|
|
|
|
|
view = GIMP_CONTAINER_VIEW (tree_view);
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
iter = g_hash_table_lookup (view->hash_table, renderer->viewable);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
|
|
|
if (iter)
|
2003-03-01 11:53:41 +08:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
path = gtk_tree_model_get_path (tree_view->model, iter);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_tree_model_row_changed (tree_view->model, path, iter);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_name_changed (GimpObject *object,
|
|
|
|
GimpContainerTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GimpContainerView *view;
|
|
|
|
GtkTreeIter *iter;
|
|
|
|
|
|
|
|
view = GIMP_CONTAINER_VIEW (tree_view);
|
|
|
|
|
|
|
|
iter = g_hash_table_lookup (view->hash_table, object);
|
|
|
|
|
|
|
|
if (iter)
|
2003-03-01 11:53:41 +08:00
|
|
|
{
|
|
|
|
gchar *name;
|
|
|
|
|
2003-04-09 00:01:01 +08:00
|
|
|
name = gimp_viewable_get_description (GIMP_VIEWABLE (object), NULL);
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2003-03-14 06:17:31 +08:00
|
|
|
gtk_list_store_set (GTK_LIST_STORE (tree_view->model), iter,
|
2003-03-01 11:53:41 +08:00
|
|
|
COLUMN_NAME, name,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
}
|
2003-02-25 04:31:14 +08:00
|
|
|
}
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-02-25 04:31:14 +08:00
|
|
|
static GimpViewable *
|
|
|
|
gimp_container_tree_view_drag_viewable (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-02-25 04:31:14 +08:00
|
|
|
tree_view = GIMP_CONTAINER_TREE_VIEW (data);
|
2003-02-22 03:03:19 +08:00
|
|
|
|
2003-02-25 04:31:14 +08:00
|
|
|
return tree_view->dnd_viewable;
|
2003-02-22 03:03:19 +08:00
|
|
|
}
|