2001-06-26 20:09:43 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpcontainereditor.c
|
2001-10-18 00:11:28 +08:00
|
|
|
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
|
2001-06-26 20:09:43 +08:00
|
|
|
*
|
|
|
|
* 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 "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimpcontext.h"
|
2004-05-28 17:52:15 +08:00
|
|
|
#include "core/gimplist.h"
|
2003-04-01 21:53:47 +08:00
|
|
|
#include "core/gimpviewable.h"
|
2001-06-26 20:09:43 +08:00
|
|
|
|
|
|
|
#include "gimpcontainereditor.h"
|
|
|
|
#include "gimpcontainergridview.h"
|
2003-02-22 03:03:19 +08:00
|
|
|
#include "gimpcontainertreeview.h"
|
2004-05-11 07:22:39 +08:00
|
|
|
#include "gimpcontainerview.h"
|
2003-10-11 05:24:12 +08:00
|
|
|
#include "gimpdocked.h"
|
2003-01-11 01:55:53 +08:00
|
|
|
#include "gimpmenufactory.h"
|
2003-04-08 20:39:02 +08:00
|
|
|
#include "gimppreviewrenderer.h"
|
2004-04-23 01:14:22 +08:00
|
|
|
#include "gimpuimanager.h"
|
2001-06-26 20:09:43 +08:00
|
|
|
|
|
|
|
|
2003-10-11 05:24:12 +08:00
|
|
|
static void gimp_container_editor_class_init (GimpContainerEditorClass *klass);
|
|
|
|
static void gimp_container_editor_init (GimpContainerEditor *view);
|
2003-10-11 22:30:18 +08:00
|
|
|
static void gimp_container_editor_docked_iface_init (GimpDockedInterface *docked_iface);
|
2001-08-04 03:43:19 +08:00
|
|
|
|
2003-05-18 21:28:27 +08:00
|
|
|
static gboolean gimp_container_editor_select_item (GtkWidget *widget,
|
2001-06-30 03:25:03 +08:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data,
|
|
|
|
GimpContainerEditor *editor);
|
|
|
|
static void gimp_container_editor_activate_item (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data,
|
|
|
|
GimpContainerEditor *editor);
|
|
|
|
static void gimp_container_editor_context_item (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data,
|
|
|
|
GimpContainerEditor *editor);
|
2001-07-09 05:44:52 +08:00
|
|
|
static void gimp_container_editor_real_context_item(GimpContainerEditor *editor,
|
|
|
|
GimpViewable *viewable);
|
2001-06-30 03:25:03 +08:00
|
|
|
|
2004-05-23 18:04:41 +08:00
|
|
|
static GtkWidget * gimp_container_editor_get_preview (GimpDocked *docked,
|
|
|
|
GimpContext *context,
|
|
|
|
GtkIconSize size);
|
|
|
|
static void gimp_container_editor_set_context (GimpDocked *docked,
|
|
|
|
GimpContext *context);
|
|
|
|
static GimpUIManager * gimp_container_editor_get_menu(GimpDocked *docked,
|
|
|
|
const gchar **ui_path,
|
|
|
|
gpointer *popup_data);
|
2003-10-11 05:24:12 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
|
|
|
|
static GtkVBoxClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
2001-08-04 03:43:19 +08:00
|
|
|
GType
|
2001-06-26 20:09:43 +08:00
|
|
|
gimp_container_editor_get_type (void)
|
|
|
|
{
|
2003-10-11 05:24:12 +08:00
|
|
|
static GType type = 0;
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2003-10-11 05:24:12 +08:00
|
|
|
if (! type)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
2001-10-17 19:33:43 +08:00
|
|
|
static const GTypeInfo view_info =
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
2001-10-17 19:33:43 +08:00
|
|
|
sizeof (GimpContainerEditorClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gimp_container_editor_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpContainerEditor),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_container_editor_init,
|
2001-06-26 20:09:43 +08:00
|
|
|
};
|
2004-05-11 18:01:25 +08:00
|
|
|
|
2003-10-11 05:24:12 +08:00
|
|
|
static const GInterfaceInfo docked_iface_info =
|
|
|
|
{
|
|
|
|
(GInterfaceInitFunc) gimp_container_editor_docked_iface_init,
|
|
|
|
NULL, /* iface_finalize */
|
|
|
|
NULL /* iface_data */
|
|
|
|
};
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2003-10-11 05:24:12 +08:00
|
|
|
type = g_type_register_static (GTK_TYPE_VBOX,
|
|
|
|
"GimpContainerEditor",
|
|
|
|
&view_info, 0);
|
|
|
|
|
|
|
|
g_type_add_interface_static (type, GIMP_TYPE_DOCKED,
|
|
|
|
&docked_iface_info);
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
|
|
|
|
2003-10-11 05:24:12 +08:00
|
|
|
return type;
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_editor_class_init (GimpContainerEditorClass *klass)
|
|
|
|
{
|
2001-08-04 03:43:19 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2001-11-30 22:41:56 +08:00
|
|
|
klass->select_item = NULL;
|
|
|
|
klass->activate_item = NULL;
|
|
|
|
klass->context_item = gimp_container_editor_real_context_item;
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_editor_init (GimpContainerEditor *view)
|
|
|
|
{
|
2003-03-21 19:47:37 +08:00
|
|
|
view->view = NULL;
|
2001-11-30 22:41:56 +08:00
|
|
|
}
|
|
|
|
|
2003-10-11 05:24:12 +08:00
|
|
|
static void
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_container_editor_docked_iface_init (GimpDockedInterface *docked_iface)
|
2003-10-11 05:24:12 +08:00
|
|
|
{
|
|
|
|
docked_iface->get_preview = gimp_container_editor_get_preview;
|
|
|
|
docked_iface->set_context = gimp_container_editor_set_context;
|
|
|
|
docked_iface->get_menu = gimp_container_editor_get_menu;
|
|
|
|
}
|
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
gboolean
|
2001-11-30 22:41:56 +08:00
|
|
|
gimp_container_editor_construct (GimpContainerEditor *editor,
|
|
|
|
GimpViewType view_type,
|
|
|
|
GimpContainer *container,
|
|
|
|
GimpContext *context,
|
|
|
|
gint preview_size,
|
2003-04-08 20:39:02 +08:00
|
|
|
gint preview_border_width,
|
2003-01-11 01:55:53 +08:00
|
|
|
GimpMenuFactory *menu_factory,
|
2004-04-22 00:33:17 +08:00
|
|
|
const gchar *menu_identifier,
|
|
|
|
const gchar *ui_identifier)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTAINER_EDITOR (editor), FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
|
2003-01-05 02:47:55 +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, FALSE);
|
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,
|
|
|
|
FALSE);
|
2003-03-23 00:26:11 +08:00
|
|
|
g_return_val_if_fail (menu_factory == NULL ||
|
|
|
|
GIMP_IS_MENU_FACTORY (menu_factory), FALSE);
|
2001-06-26 20:09:43 +08:00
|
|
|
|
|
|
|
switch (view_type)
|
|
|
|
{
|
|
|
|
case GIMP_VIEW_TYPE_GRID:
|
|
|
|
editor->view =
|
|
|
|
GIMP_CONTAINER_VIEW (gimp_container_grid_view_new (container,
|
2004-05-11 18:01:25 +08:00
|
|
|
context,
|
|
|
|
preview_size,
|
2004-05-28 17:52:15 +08:00
|
|
|
preview_border_width));
|
2001-06-26 20:09:43 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_VIEW_TYPE_LIST:
|
2003-02-22 03:03:19 +08:00
|
|
|
editor->view =
|
|
|
|
GIMP_CONTAINER_VIEW (gimp_container_tree_view_new (container,
|
2004-05-11 18:01:25 +08:00
|
|
|
context,
|
|
|
|
preview_size,
|
2004-05-28 17:52:15 +08:00
|
|
|
preview_border_width));
|
2003-02-22 03:03:19 +08:00
|
|
|
break;
|
2003-02-25 04:31:14 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
default:
|
2004-05-11 18:01:25 +08:00
|
|
|
g_warning ("%s: unknown GimpViewType passed", G_STRFUNC);
|
2001-06-26 20:09:43 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-05-28 17:52:15 +08:00
|
|
|
if (GIMP_IS_LIST (container))
|
|
|
|
gimp_container_view_set_reorderable (GIMP_CONTAINER_VIEW (editor->view),
|
|
|
|
! GIMP_LIST (container)->sort_func);
|
|
|
|
|
2004-04-22 00:33:17 +08:00
|
|
|
if (menu_factory && menu_identifier && ui_identifier)
|
2003-03-23 00:26:11 +08:00
|
|
|
gimp_editor_create_menu (GIMP_EDITOR (editor->view),
|
2004-04-22 00:33:17 +08:00
|
|
|
menu_factory, menu_identifier, ui_identifier,
|
|
|
|
editor);
|
2003-03-21 19:47:37 +08:00
|
|
|
|
2003-02-25 04:31:14 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (editor), GTK_WIDGET (editor->view));
|
2001-06-26 20:09:43 +08:00
|
|
|
gtk_widget_show (GTK_WIDGET (editor->view));
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect_object (editor->view, "select_item",
|
2004-05-11 18:01:25 +08:00
|
|
|
G_CALLBACK (gimp_container_editor_select_item),
|
|
|
|
editor, 0);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect_object (editor->view, "activate_item",
|
2004-05-11 18:01:25 +08:00
|
|
|
G_CALLBACK (gimp_container_editor_activate_item),
|
|
|
|
editor, 0);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect_object (editor->view, "context_item",
|
2004-05-11 18:01:25 +08:00
|
|
|
G_CALLBACK (gimp_container_editor_context_item),
|
|
|
|
editor, 0);
|
2001-06-30 03:25:03 +08:00
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-06-30 03:25:03 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2003-05-18 21:28:27 +08:00
|
|
|
static gboolean
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_container_editor_select_item (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data,
|
|
|
|
GimpContainerEditor *editor)
|
|
|
|
{
|
2004-05-11 18:01:25 +08:00
|
|
|
GimpContainerEditorClass *klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
|
2001-06-30 03:25:03 +08:00
|
|
|
|
|
|
|
if (klass->select_item)
|
|
|
|
klass->select_item (editor, viewable);
|
2003-05-18 21:28:27 +08:00
|
|
|
|
2004-05-13 02:36:33 +08:00
|
|
|
if (GIMP_EDITOR (editor->view)->ui_manager)
|
|
|
|
gimp_ui_manager_update (GIMP_EDITOR (editor->view)->ui_manager, editor);
|
|
|
|
|
2003-05-18 21:28:27 +08:00
|
|
|
return TRUE;
|
2001-06-30 03:25:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_editor_activate_item (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data,
|
|
|
|
GimpContainerEditor *editor)
|
|
|
|
{
|
2004-05-11 18:01:25 +08:00
|
|
|
GimpContainerEditorClass *klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
|
2001-06-30 03:25:03 +08:00
|
|
|
|
|
|
|
if (klass->activate_item)
|
|
|
|
klass->activate_item (editor, viewable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_editor_context_item (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data,
|
|
|
|
GimpContainerEditor *editor)
|
|
|
|
{
|
2004-05-11 18:01:25 +08:00
|
|
|
GimpContainerEditorClass *klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
|
2001-06-30 03:25:03 +08:00
|
|
|
|
|
|
|
if (klass->context_item)
|
|
|
|
klass->context_item (editor, viewable);
|
|
|
|
}
|
2001-07-09 05:44:52 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_editor_real_context_item (GimpContainerEditor *editor,
|
|
|
|
GimpViewable *viewable)
|
|
|
|
{
|
2004-05-11 01:16:50 +08:00
|
|
|
GimpContainer *container = gimp_container_view_get_container (editor->view);
|
|
|
|
|
|
|
|
if (viewable && gimp_container_have (container, GIMP_OBJECT (viewable)))
|
2001-07-09 05:44:52 +08:00
|
|
|
{
|
2004-05-17 21:38:03 +08:00
|
|
|
gimp_editor_popup_menu (GIMP_EDITOR (editor->view), NULL, NULL);
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
}
|
2003-10-11 05:24:12 +08:00
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
gimp_container_editor_get_preview (GimpDocked *docked,
|
|
|
|
GimpContext *context,
|
|
|
|
GtkIconSize size)
|
|
|
|
{
|
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (docked);
|
|
|
|
|
|
|
|
return gimp_docked_get_preview (GIMP_DOCKED (editor->view),
|
|
|
|
context, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_editor_set_context (GimpDocked *docked,
|
2004-05-23 18:04:41 +08:00
|
|
|
GimpContext *context)
|
2003-10-11 05:24:12 +08:00
|
|
|
{
|
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (docked);
|
|
|
|
|
2004-05-23 18:04:41 +08:00
|
|
|
gimp_docked_set_context (GIMP_DOCKED (editor->view), context);
|
2003-10-11 05:24:12 +08:00
|
|
|
}
|
|
|
|
|
2004-04-29 20:52:29 +08:00
|
|
|
static GimpUIManager *
|
|
|
|
gimp_container_editor_get_menu (GimpDocked *docked,
|
|
|
|
const gchar **ui_path,
|
|
|
|
gpointer *popup_data)
|
2003-10-11 05:24:12 +08:00
|
|
|
{
|
|
|
|
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (docked);
|
|
|
|
|
2004-04-29 20:52:29 +08:00
|
|
|
return gimp_docked_get_menu (GIMP_DOCKED (editor->view), ui_path, popup_data);
|
2003-10-11 05:24:12 +08:00
|
|
|
}
|