2001-02-06 05:52:57 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2001-04-22 08:38:56 +08:00
|
|
|
* gimpcontainergridview.c
|
2001-10-18 00:11:28 +08:00
|
|
|
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
|
2001-04-22 08:38:56 +08:00
|
|
|
*
|
2001-02-06 05:52:57 +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>
|
2003-03-27 20:06:55 +08:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-03-12 01:24:47 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
2001-05-08 11:48:54 +08:00
|
|
|
#include "widgets-types.h"
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
2003-03-27 20:06:55 +08:00
|
|
|
#include "core/gimpmarshal.h"
|
2003-04-01 21:53:47 +08:00
|
|
|
#include "core/gimpviewable.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-02-06 05:52:57 +08:00
|
|
|
#include "gimpcontainergridview.h"
|
2003-09-30 23:55:23 +08:00
|
|
|
#include "gimpitemfactory.h"
|
2001-02-06 05:52:57 +08:00
|
|
|
#include "gimppreview.h"
|
2003-03-01 11:53:41 +08:00
|
|
|
#include "gimppreviewrenderer.h"
|
2003-11-20 02:08:15 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2002-03-16 23:02:23 +08:00
|
|
|
#include "gtkhwrapbox.h"
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-05-13 19:35:20 +08:00
|
|
|
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2003-03-27 20:06:55 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
MOVE_CURSOR,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-02-06 05:52:57 +08:00
|
|
|
static void gimp_container_grid_view_class_init (GimpContainerGridViewClass *klass);
|
2003-03-27 20:06:55 +08:00
|
|
|
static void gimp_container_grid_view_init (GimpContainerGridView *view);
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2003-03-27 20:06:55 +08:00
|
|
|
static gboolean gimp_container_grid_view_move_cursor (GimpContainerGridView *view,
|
|
|
|
GtkMovementStep step,
|
|
|
|
gint count);
|
2003-03-26 23:28:17 +08:00
|
|
|
static gboolean gimp_container_grid_view_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction);
|
2003-09-30 23:55:23 +08:00
|
|
|
static gboolean gimp_container_grid_view_popup_menu (GtkWidget *widget);
|
2003-03-26 23:28:17 +08:00
|
|
|
|
2001-02-06 05:52:57 +08:00
|
|
|
static gpointer gimp_container_grid_view_insert_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gint index);
|
|
|
|
static void gimp_container_grid_view_remove_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data);
|
2001-02-18 05:20:10 +08:00
|
|
|
static void gimp_container_grid_view_reorder_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gint new_index,
|
|
|
|
gpointer insert_data);
|
2004-01-30 00:34:41 +08:00
|
|
|
static void gimp_container_grid_view_rename_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data);
|
2003-05-18 21:28:27 +08:00
|
|
|
static gboolean gimp_container_grid_view_select_item (GimpContainerView *view,
|
2001-02-08 07:14:14 +08:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data);
|
2001-02-06 05:52:57 +08:00
|
|
|
static void gimp_container_grid_view_clear_items (GimpContainerView *view);
|
2001-02-06 07:14:14 +08:00
|
|
|
static void gimp_container_grid_view_set_preview_size (GimpContainerView *view);
|
2003-06-27 00:37:43 +08:00
|
|
|
static gboolean gimp_container_grid_view_item_selected(GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent,
|
2001-02-07 23:01:52 +08:00
|
|
|
gpointer data);
|
2001-02-27 22:14:13 +08:00
|
|
|
static void gimp_container_grid_view_item_activated (GtkWidget *widget,
|
2001-02-19 03:44:28 +08:00
|
|
|
gpointer data);
|
2001-07-09 05:44:52 +08:00
|
|
|
static void gimp_container_grid_view_item_context (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2001-02-08 07:14:14 +08:00
|
|
|
static void gimp_container_grid_view_highlight_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data);
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2003-10-13 20:35:52 +08:00
|
|
|
static void gimp_container_grid_view_viewport_resized (GtkWidget *widget,
|
2002-03-16 23:02:23 +08:00
|
|
|
GtkAllocation *allocation,
|
|
|
|
GimpContainerGridView *view);
|
|
|
|
|
2001-02-06 05:52:57 +08:00
|
|
|
|
|
|
|
static GimpContainerViewClass *parent_class = NULL;
|
2004-01-30 00:34:41 +08:00
|
|
|
|
2003-03-27 20:06:55 +08:00
|
|
|
static guint grid_view_signals[LAST_SIGNAL] = { 0 };
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-03-12 01:24:47 +08:00
|
|
|
static GimpRGB white_color;
|
|
|
|
static GimpRGB black_color;
|
|
|
|
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
GType
|
2001-02-06 05:52:57 +08:00
|
|
|
gimp_container_grid_view_get_type (void)
|
|
|
|
{
|
2001-10-17 19:33:43 +08:00
|
|
|
static GType view_type = 0;
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
if (! view_type)
|
2001-02-06 05:52:57 +08:00
|
|
|
{
|
2001-10-17 19:33:43 +08:00
|
|
|
static const GTypeInfo view_info =
|
2001-02-06 05:52:57 +08:00
|
|
|
{
|
2001-10-17 19:33:43 +08:00
|
|
|
sizeof (GimpContainerGridViewClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gimp_container_grid_view_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpContainerGridView),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_container_grid_view_init,
|
2001-02-06 05:52:57 +08:00
|
|
|
};
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
view_type = g_type_register_static (GIMP_TYPE_CONTAINER_VIEW,
|
|
|
|
"GimpContainerGridView",
|
|
|
|
&view_info, 0);
|
2001-02-06 05:52:57 +08:00
|
|
|
}
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
return view_type;
|
2001-02-06 05:52:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_grid_view_class_init (GimpContainerGridViewClass *klass)
|
|
|
|
{
|
|
|
|
GimpContainerViewClass *container_view_class;
|
2003-03-26 23:28:17 +08:00
|
|
|
GtkWidgetClass *widget_class;
|
2003-03-27 20:06:55 +08:00
|
|
|
GtkBindingSet *binding_set;
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
container_view_class = GIMP_CONTAINER_VIEW_CLASS (klass);
|
2003-03-26 23:28:17 +08:00
|
|
|
widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2001-10-17 19:33:43 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2003-03-27 20:06:55 +08:00
|
|
|
binding_set = gtk_binding_set_by_class (klass);
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2003-03-26 23:28:17 +08:00
|
|
|
widget_class->focus = gimp_container_grid_view_focus;
|
2003-09-30 23:55:23 +08:00
|
|
|
widget_class->popup_menu = gimp_container_grid_view_popup_menu;
|
2003-03-26 23:28:17 +08:00
|
|
|
|
2001-02-06 07:14:14 +08:00
|
|
|
container_view_class->insert_item = gimp_container_grid_view_insert_item;
|
|
|
|
container_view_class->remove_item = gimp_container_grid_view_remove_item;
|
2001-02-18 05:20:10 +08:00
|
|
|
container_view_class->reorder_item = gimp_container_grid_view_reorder_item;
|
2004-01-30 00:34:41 +08:00
|
|
|
container_view_class->rename_item = gimp_container_grid_view_rename_item;
|
2001-02-08 07:14:14 +08:00
|
|
|
container_view_class->select_item = gimp_container_grid_view_select_item;
|
2001-02-06 07:14:14 +08:00
|
|
|
container_view_class->clear_items = gimp_container_grid_view_clear_items;
|
|
|
|
container_view_class->set_preview_size = gimp_container_grid_view_set_preview_size;
|
2001-02-06 07:44:19 +08:00
|
|
|
|
2003-03-27 20:06:55 +08:00
|
|
|
klass->move_cursor = gimp_container_grid_view_move_cursor;
|
|
|
|
|
|
|
|
grid_view_signals[MOVE_CURSOR] =
|
|
|
|
g_signal_new ("move_cursor",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET (GimpContainerGridViewClass, move_cursor),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_BOOLEAN__ENUM_INT,
|
|
|
|
G_TYPE_BOOLEAN, 2,
|
|
|
|
GTK_TYPE_MOVEMENT_STEP,
|
|
|
|
G_TYPE_INT);
|
|
|
|
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
|
|
|
|
"move_cursor", 2,
|
|
|
|
G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
|
|
|
|
G_TYPE_INT, -1);
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
|
|
|
|
"move_cursor", 2,
|
|
|
|
G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
|
|
|
|
G_TYPE_INT, 1);
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, 0,
|
|
|
|
"move_cursor", 2,
|
|
|
|
G_TYPE_ENUM, GTK_MOVEMENT_PAGES,
|
|
|
|
G_TYPE_INT, -1);
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, 0,
|
|
|
|
"move_cursor", 2,
|
|
|
|
G_TYPE_ENUM, GTK_MOVEMENT_PAGES,
|
|
|
|
G_TYPE_INT, 1);
|
2003-09-21 22:57:30 +08:00
|
|
|
|
2001-03-12 01:24:47 +08:00
|
|
|
gimp_rgba_set (&white_color, 1.0, 1.0, 1.0, 1.0);
|
|
|
|
gimp_rgba_set (&black_color, 0.0, 0.0, 0.0, 1.0);
|
2001-02-06 05:52:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_grid_view_init (GimpContainerGridView *grid_view)
|
|
|
|
{
|
2004-01-30 00:34:41 +08:00
|
|
|
GimpContainerView *view = GIMP_CONTAINER_VIEW (grid_view);
|
2003-03-26 22:56:10 +08:00
|
|
|
|
2003-04-15 22:13:14 +08:00
|
|
|
grid_view->rows = 1;
|
|
|
|
grid_view->columns = 1;
|
|
|
|
grid_view->visible_rows = 0;
|
|
|
|
grid_view->selected_item = NULL;
|
2002-03-16 23:02:23 +08:00
|
|
|
|
2003-03-26 22:56:10 +08:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view->scrolled_win),
|
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
|
|
|
|
2001-05-13 19:35:20 +08:00
|
|
|
grid_view->name_label = gtk_label_new (_("(None)"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (grid_view->name_label), 0.0, 0.5);
|
|
|
|
gtk_box_pack_start (GTK_BOX (grid_view), grid_view->name_label,
|
|
|
|
FALSE, FALSE, 0);
|
2003-03-26 22:56:10 +08:00
|
|
|
gtk_box_reorder_child (GTK_BOX (grid_view), grid_view->name_label, 0);
|
2001-05-13 19:35:20 +08:00
|
|
|
gtk_widget_show (grid_view->name_label);
|
|
|
|
|
2002-03-16 23:02:23 +08:00
|
|
|
grid_view->wrap_box = gtk_hwrap_box_new (FALSE);
|
2003-03-26 22:56:10 +08:00
|
|
|
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (view->scrolled_win),
|
2002-03-16 23:02:23 +08:00
|
|
|
grid_view->wrap_box);
|
2001-08-05 04:38:54 +08:00
|
|
|
gtk_widget_show (grid_view->wrap_box);
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (grid_view->wrap_box->parent, "size_allocate",
|
2003-10-13 20:35:52 +08:00
|
|
|
G_CALLBACK (gimp_container_grid_view_viewport_resized),
|
2002-03-16 23:02:23 +08:00
|
|
|
grid_view);
|
|
|
|
|
2003-03-26 23:28:17 +08:00
|
|
|
GTK_WIDGET_SET_FLAGS (grid_view, GTK_CAN_FOCUS);
|
2001-02-06 05:52:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gimp_container_grid_view_new (GimpContainer *container,
|
2001-02-07 23:01:52 +08:00
|
|
|
GimpContext *context,
|
2001-02-10 05:49:47 +08:00
|
|
|
gint preview_size,
|
2003-04-08 20:39:02 +08:00
|
|
|
gint preview_border_width,
|
|
|
|
gboolean reorderable)
|
2001-02-06 05:52:57 +08:00
|
|
|
{
|
|
|
|
GimpContainerGridView *grid_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-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, 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);
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-08-10 22:41:39 +08:00
|
|
|
grid_view = g_object_new (GIMP_TYPE_CONTAINER_GRID_VIEW, NULL);
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2003-03-27 01:49:42 +08:00
|
|
|
gimp_container_view_construct (GIMP_CONTAINER_VIEW (grid_view),
|
|
|
|
container, context,
|
2003-04-08 20:39:02 +08:00
|
|
|
preview_size, preview_border_width,
|
|
|
|
reorderable);
|
2001-02-07 23:01:52 +08:00
|
|
|
|
2001-02-06 05:52:57 +08:00
|
|
|
return GTK_WIDGET (grid_view);
|
|
|
|
}
|
|
|
|
|
2003-03-27 20:06:55 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_container_grid_view_move_by (GimpContainerGridView *view,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
|
|
|
GimpContainer *container;
|
|
|
|
GimpViewable *item;
|
|
|
|
gint index;
|
|
|
|
|
2003-04-15 22:13:14 +08:00
|
|
|
if (! view->selected_item)
|
2003-03-27 20:06:55 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
container = GIMP_CONTAINER_VIEW (view)->container;
|
|
|
|
|
2003-04-15 22:13:14 +08:00
|
|
|
item = view->selected_item->viewable;
|
|
|
|
|
|
|
|
index = gimp_container_get_child_index (container, GIMP_OBJECT (item));
|
2003-03-27 20:06:55 +08:00
|
|
|
|
|
|
|
index += x;
|
|
|
|
index = CLAMP (index, 0, container->num_children - 1);
|
|
|
|
|
|
|
|
index += y * view->columns;
|
|
|
|
while (index < 0)
|
|
|
|
index += view->columns;
|
|
|
|
while (index >= container->num_children)
|
|
|
|
index -= view->columns;
|
|
|
|
|
|
|
|
item = (GimpViewable *) gimp_container_get_child_by_index (container, index);
|
|
|
|
if (item)
|
|
|
|
gimp_container_view_item_selected (GIMP_CONTAINER_VIEW (view), item);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_container_grid_view_move_cursor (GimpContainerGridView *view,
|
|
|
|
GtkMovementStep step,
|
|
|
|
gint count)
|
|
|
|
{
|
|
|
|
GimpContainer *container;
|
|
|
|
GimpViewable *item;
|
|
|
|
|
|
|
|
if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (view)) || count == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (step)
|
|
|
|
{
|
|
|
|
case GTK_MOVEMENT_PAGES:
|
|
|
|
return gimp_container_grid_view_move_by (view,
|
|
|
|
0, count * view->visible_rows);
|
|
|
|
|
|
|
|
case GTK_MOVEMENT_BUFFER_ENDS:
|
|
|
|
container = GIMP_CONTAINER_VIEW (view)->container;
|
|
|
|
count = count < 0 ? 0 : container->num_children - 1;
|
|
|
|
|
|
|
|
item = (GimpViewable *) gimp_container_get_child_by_index (container,
|
|
|
|
count);
|
|
|
|
if (item)
|
|
|
|
gimp_container_view_item_selected (GIMP_CONTAINER_VIEW (view), item);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-03-26 23:28:17 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_container_grid_view_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
2004-01-30 00:34:41 +08:00
|
|
|
GimpContainerGridView *view = GIMP_CONTAINER_GRID_VIEW (widget);
|
2003-03-26 23:28:17 +08:00
|
|
|
|
|
|
|
if (GTK_WIDGET_CAN_FOCUS (widget) && !GTK_WIDGET_HAS_FOCUS (widget))
|
|
|
|
{
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (widget));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case GTK_DIR_UP:
|
2003-03-27 20:06:55 +08:00
|
|
|
return gimp_container_grid_view_move_by (view, 0, -1);
|
2003-03-26 23:28:17 +08:00
|
|
|
case GTK_DIR_DOWN:
|
2003-03-27 20:06:55 +08:00
|
|
|
return gimp_container_grid_view_move_by (view, 0, 1);
|
2003-03-26 23:28:17 +08:00
|
|
|
case GTK_DIR_LEFT:
|
2003-03-27 20:06:55 +08:00
|
|
|
return gimp_container_grid_view_move_by (view, -1, 0);
|
2003-03-26 23:28:17 +08:00
|
|
|
case GTK_DIR_RIGHT:
|
2003-03-27 20:06:55 +08:00
|
|
|
return gimp_container_grid_view_move_by (view, 1, 0);
|
|
|
|
|
|
|
|
case GTK_DIR_TAB_FORWARD:
|
|
|
|
case GTK_DIR_TAB_BACKWARD:
|
2003-03-26 23:28:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-27 20:06:55 +08:00
|
|
|
return FALSE;
|
2003-09-30 23:55:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_grid_view_menu_position (GtkMenu *menu,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2003-11-20 02:08:15 +08:00
|
|
|
GtkWidget *widget = GTK_WIDGET (data);
|
2003-09-30 23:55:23 +08:00
|
|
|
|
|
|
|
gdk_window_get_origin (widget->window, x, y);
|
|
|
|
|
|
|
|
if (GTK_WIDGET_NO_WINDOW (widget))
|
|
|
|
{
|
|
|
|
*x += widget->allocation.x;
|
|
|
|
*y += widget->allocation.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
*x += widget->allocation.width / 2;
|
|
|
|
*y += widget->allocation.height / 2;
|
|
|
|
|
2003-11-20 02:08:15 +08:00
|
|
|
gimp_menu_position (menu, x, y);
|
2003-09-30 23:55:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_container_grid_view_popup_menu (GtkWidget *widget)
|
|
|
|
{
|
2004-01-30 00:34:41 +08:00
|
|
|
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (widget);
|
|
|
|
GimpEditor *editor = GIMP_EDITOR (widget);
|
2003-09-30 23:55:23 +08:00
|
|
|
|
|
|
|
if (editor->item_factory && grid_view->selected_item)
|
|
|
|
{
|
|
|
|
gimp_item_factory_popup_with_data (editor->item_factory,
|
|
|
|
editor->item_factory_data,
|
2003-11-08 23:32:38 +08:00
|
|
|
GTK_WIDGET (editor),
|
2003-09-30 23:55:23 +08:00
|
|
|
gimp_container_grid_view_menu_position,
|
|
|
|
grid_view->selected_item,
|
|
|
|
NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2003-03-26 23:28:17 +08:00
|
|
|
}
|
|
|
|
|
2001-02-06 05:52:57 +08:00
|
|
|
static gpointer
|
|
|
|
gimp_container_grid_view_insert_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gint index)
|
|
|
|
{
|
2004-01-30 00:34:41 +08:00
|
|
|
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
|
2001-02-06 05:52:57 +08:00
|
|
|
GtkWidget *preview;
|
|
|
|
|
2001-02-09 23:12:01 +08:00
|
|
|
preview = gimp_preview_new_full (viewable,
|
2001-02-10 05:49:47 +08:00
|
|
|
view->preview_size,
|
|
|
|
view->preview_size,
|
2001-02-09 23:12:01 +08:00
|
|
|
1,
|
|
|
|
FALSE, TRUE, TRUE);
|
2003-04-11 19:18:12 +08:00
|
|
|
gimp_preview_renderer_set_border_color (GIMP_PREVIEW (preview)->renderer,
|
|
|
|
&white_color);
|
2003-10-13 20:35:52 +08:00
|
|
|
gimp_preview_renderer_remove_idle (GIMP_PREVIEW (preview)->renderer);
|
2001-02-08 07:14:14 +08:00
|
|
|
|
2001-02-06 23:57:07 +08:00
|
|
|
gtk_wrap_box_pack (GTK_WRAP_BOX (grid_view->wrap_box), preview,
|
|
|
|
FALSE, FALSE, FALSE, FALSE);
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2001-02-06 07:14:14 +08:00
|
|
|
if (index != -1)
|
2001-02-06 23:57:07 +08:00
|
|
|
gtk_wrap_box_reorder_child (GTK_WRAP_BOX (grid_view->wrap_box),
|
2001-02-06 07:14:14 +08:00
|
|
|
preview, index);
|
|
|
|
|
|
|
|
gtk_widget_show (preview);
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2003-06-27 00:37:43 +08:00
|
|
|
g_signal_connect (preview, "button_press_event",
|
2001-07-25 07:11:30 +08:00
|
|
|
G_CALLBACK (gimp_container_grid_view_item_selected),
|
|
|
|
view);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (preview, "double_clicked",
|
2001-07-25 07:11:30 +08:00
|
|
|
G_CALLBACK (gimp_container_grid_view_item_activated),
|
|
|
|
view);
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (preview, "context",
|
2001-07-25 07:11:30 +08:00
|
|
|
G_CALLBACK (gimp_container_grid_view_item_context),
|
|
|
|
view);
|
2001-07-09 05:44:52 +08:00
|
|
|
|
2001-02-06 05:52:57 +08:00
|
|
|
return (gpointer) preview;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_grid_view_remove_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data)
|
|
|
|
{
|
2004-01-30 00:34:41 +08:00
|
|
|
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
|
|
|
|
GtkWidget *preview = GTK_WIDGET (insert_data);
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2004-01-30 00:34:41 +08:00
|
|
|
if (preview == (GtkWidget *) grid_view->selected_item)
|
|
|
|
grid_view->selected_item = NULL;
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2004-01-30 00:34:41 +08:00
|
|
|
gtk_container_remove (GTK_CONTAINER (grid_view->wrap_box), preview);
|
2001-02-06 05:52:57 +08:00
|
|
|
}
|
|
|
|
|
2001-02-18 05:20:10 +08:00
|
|
|
static void
|
|
|
|
gimp_container_grid_view_reorder_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gint new_index,
|
|
|
|
gpointer insert_data)
|
|
|
|
{
|
2004-01-30 00:34:41 +08:00
|
|
|
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
|
|
|
|
GtkWidget *preview = GTK_WIDGET (insert_data);
|
2001-02-18 05:20:10 +08:00
|
|
|
|
|
|
|
gtk_wrap_box_reorder_child (GTK_WRAP_BOX (grid_view->wrap_box),
|
|
|
|
preview, new_index);
|
|
|
|
}
|
|
|
|
|
2004-01-30 00:34:41 +08:00
|
|
|
static void
|
|
|
|
gimp_container_grid_view_rename_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data)
|
|
|
|
{
|
|
|
|
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
|
|
|
|
GtkWidget *preview = GTK_WIDGET (insert_data);
|
|
|
|
|
|
|
|
if (preview == (GtkWidget *) grid_view->selected_item)
|
|
|
|
{
|
|
|
|
gchar *name = gimp_viewable_get_description (viewable, NULL);
|
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (grid_view->name_label), name);
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-18 21:28:27 +08:00
|
|
|
static gboolean
|
2001-02-08 07:14:14 +08:00
|
|
|
gimp_container_grid_view_select_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data)
|
|
|
|
{
|
|
|
|
gimp_container_grid_view_highlight_item (view, viewable, insert_data);
|
2003-05-18 21:28:27 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2001-02-08 07:14:14 +08:00
|
|
|
}
|
|
|
|
|
2001-02-06 05:52:57 +08:00
|
|
|
static void
|
|
|
|
gimp_container_grid_view_clear_items (GimpContainerView *view)
|
|
|
|
{
|
2004-01-30 00:34:41 +08:00
|
|
|
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
|
2001-02-06 05:52:57 +08:00
|
|
|
|
2003-04-15 22:13:14 +08:00
|
|
|
grid_view->selected_item = NULL;
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2001-02-06 23:57:07 +08:00
|
|
|
while (GTK_WRAP_BOX (grid_view->wrap_box)->children)
|
|
|
|
gtk_container_remove (GTK_CONTAINER (grid_view->wrap_box),
|
|
|
|
GTK_WRAP_BOX (grid_view->wrap_box)->children->widget);
|
2001-02-08 12:16:41 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
GIMP_CONTAINER_VIEW_CLASS (parent_class)->clear_items (view);
|
2001-02-06 07:14:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_grid_view_set_preview_size (GimpContainerView *view)
|
|
|
|
{
|
2004-01-30 00:34:41 +08:00
|
|
|
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
|
2001-02-06 07:14:14 +08:00
|
|
|
GtkWrapBoxChild *child;
|
|
|
|
|
2001-02-06 23:57:07 +08:00
|
|
|
for (child = GTK_WRAP_BOX (grid_view->wrap_box)->children;
|
2001-02-06 07:14:14 +08:00
|
|
|
child;
|
|
|
|
child = child->next)
|
2001-02-06 05:52:57 +08:00
|
|
|
{
|
2003-04-11 19:18:12 +08:00
|
|
|
GimpPreview *preview = GIMP_PREVIEW (child->widget);
|
2001-02-08 07:14:14 +08:00
|
|
|
|
2003-04-11 19:18:12 +08:00
|
|
|
gimp_preview_renderer_set_size (preview->renderer,
|
|
|
|
view->preview_size,
|
|
|
|
preview->renderer->border_width);
|
2001-02-06 05:52:57 +08:00
|
|
|
}
|
2001-02-06 07:14:14 +08:00
|
|
|
|
2001-02-06 23:57:07 +08:00
|
|
|
gtk_widget_queue_resize (grid_view->wrap_box);
|
2001-02-06 05:52:57 +08:00
|
|
|
}
|
2001-02-07 23:01:52 +08:00
|
|
|
|
2003-06-27 00:37:43 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_container_grid_view_item_selected (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
gpointer data)
|
2001-02-07 23:01:52 +08:00
|
|
|
{
|
2003-06-27 00:37:43 +08:00
|
|
|
if (bevent->type == GDK_BUTTON_PRESS && bevent->button == 1)
|
|
|
|
{
|
|
|
|
if (GTK_WIDGET_CAN_FOCUS (data) && !GTK_WIDGET_HAS_FOCUS (data))
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (data));
|
2003-09-21 22:57:30 +08:00
|
|
|
|
2003-06-27 00:37:43 +08:00
|
|
|
gimp_container_view_item_selected (GIMP_CONTAINER_VIEW (data),
|
|
|
|
GIMP_PREVIEW (widget)->viewable);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2001-02-07 23:01:52 +08:00
|
|
|
}
|
2001-02-08 07:14:14 +08:00
|
|
|
|
2001-02-19 03:44:28 +08:00
|
|
|
static void
|
2001-02-27 22:14:13 +08:00
|
|
|
gimp_container_grid_view_item_activated (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2001-02-19 03:44:28 +08:00
|
|
|
{
|
2001-02-27 22:14:13 +08:00
|
|
|
gimp_container_view_item_activated (GIMP_CONTAINER_VIEW (data),
|
|
|
|
GIMP_PREVIEW (widget)->viewable);
|
2001-02-19 03:44:28 +08:00
|
|
|
}
|
|
|
|
|
2001-07-09 05:44:52 +08:00
|
|
|
static void
|
|
|
|
gimp_container_grid_view_item_context (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2003-05-18 21:28:27 +08:00
|
|
|
if (gimp_container_view_item_selected (GIMP_CONTAINER_VIEW (data),
|
|
|
|
GIMP_PREVIEW (widget)->viewable))
|
|
|
|
{
|
|
|
|
gimp_container_view_item_context (GIMP_CONTAINER_VIEW (data),
|
|
|
|
GIMP_PREVIEW (widget)->viewable);
|
|
|
|
}
|
2001-07-09 05:44:52 +08:00
|
|
|
}
|
|
|
|
|
2001-02-08 07:14:14 +08:00
|
|
|
static void
|
|
|
|
gimp_container_grid_view_highlight_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data)
|
|
|
|
{
|
2004-01-30 00:34:41 +08:00
|
|
|
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
|
|
|
|
GimpPreview *preview = NULL;
|
2001-02-08 07:14:14 +08:00
|
|
|
|
2003-04-15 22:13:14 +08:00
|
|
|
if (insert_data)
|
|
|
|
preview = GIMP_PREVIEW (insert_data);
|
2001-02-08 07:14:14 +08:00
|
|
|
|
2003-04-15 22:13:14 +08:00
|
|
|
if (grid_view->selected_item && grid_view->selected_item != preview)
|
2003-03-27 20:06:55 +08:00
|
|
|
{
|
2003-04-15 22:13:14 +08:00
|
|
|
gimp_preview_renderer_set_border_color (grid_view->selected_item->renderer,
|
|
|
|
&white_color);
|
|
|
|
gimp_preview_renderer_update (grid_view->selected_item->renderer);
|
2003-03-27 20:06:55 +08:00
|
|
|
}
|
2001-02-08 07:14:14 +08:00
|
|
|
|
|
|
|
if (preview)
|
|
|
|
{
|
2003-04-15 22:13:14 +08:00
|
|
|
GtkRequisition preview_requisition;
|
|
|
|
GtkAdjustment *adj;
|
|
|
|
gint item_height;
|
|
|
|
gint index;
|
|
|
|
gint row;
|
|
|
|
gchar *name;
|
2001-02-09 07:24:06 +08:00
|
|
|
|
|
|
|
adj = gtk_scrolled_window_get_vadjustment
|
2003-03-26 22:56:10 +08:00
|
|
|
(GTK_SCROLLED_WINDOW (view->scrolled_win));
|
2001-02-09 07:24:06 +08:00
|
|
|
|
2003-04-15 22:13:14 +08:00
|
|
|
gtk_widget_size_request (GTK_WIDGET (preview), &preview_requisition);
|
|
|
|
|
|
|
|
item_height = preview_requisition.height;
|
2001-02-09 07:24:06 +08:00
|
|
|
|
|
|
|
index = gimp_container_get_child_index (view->container,
|
|
|
|
GIMP_OBJECT (viewable));
|
|
|
|
|
2002-03-16 23:02:23 +08:00
|
|
|
row = index / grid_view->columns;
|
2001-02-09 07:24:06 +08:00
|
|
|
|
|
|
|
if (row * item_height < adj->value)
|
|
|
|
{
|
|
|
|
gtk_adjustment_set_value (adj, row * item_height);
|
|
|
|
}
|
|
|
|
else if ((row + 1) * item_height > adj->value + adj->page_size)
|
|
|
|
{
|
|
|
|
gtk_adjustment_set_value (adj,
|
|
|
|
(row + 1) * item_height - adj->page_size);
|
|
|
|
}
|
|
|
|
|
2003-04-11 19:18:12 +08:00
|
|
|
gimp_preview_renderer_set_border_color (preview->renderer, &black_color);
|
2003-03-27 20:06:55 +08:00
|
|
|
gimp_preview_renderer_update (preview->renderer);
|
2001-05-13 19:35:20 +08:00
|
|
|
|
2003-04-09 00:01:01 +08:00
|
|
|
name = gimp_viewable_get_description (preview->renderer->viewable, NULL);
|
|
|
|
gtk_label_set_text (GTK_LABEL (grid_view->name_label), name);
|
|
|
|
g_free (name);
|
2001-05-13 19:35:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_label_set_text (GTK_LABEL (grid_view->name_label), _("(None)"));
|
2001-02-08 07:14:14 +08:00
|
|
|
}
|
|
|
|
|
2003-04-15 22:13:14 +08:00
|
|
|
grid_view->selected_item = preview;
|
2001-02-08 07:14:14 +08:00
|
|
|
}
|
2002-03-16 23:02:23 +08:00
|
|
|
|
|
|
|
static void
|
2003-10-13 20:35:52 +08:00
|
|
|
gimp_container_grid_view_viewport_resized (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
GimpContainerGridView *grid_view)
|
2002-03-16 23:02:23 +08:00
|
|
|
{
|
2004-01-30 00:34:41 +08:00
|
|
|
GimpContainerView *view = GIMP_CONTAINER_VIEW (grid_view);
|
2002-03-16 23:02:23 +08:00
|
|
|
|
|
|
|
if (view->container)
|
|
|
|
{
|
|
|
|
GList *children;
|
|
|
|
gint n_children;
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (grid_view->wrap_box));
|
|
|
|
n_children = g_list_length (children);
|
|
|
|
|
|
|
|
if (children)
|
|
|
|
{
|
|
|
|
GtkRequisition preview_requisition;
|
|
|
|
gint columns;
|
|
|
|
gint rows;
|
|
|
|
|
|
|
|
gtk_widget_size_request (GTK_WIDGET (children->data),
|
|
|
|
&preview_requisition);
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
|
|
|
columns = MAX (1, allocation->width / preview_requisition.width);
|
|
|
|
|
|
|
|
rows = n_children / columns;
|
|
|
|
|
|
|
|
if (n_children % columns)
|
|
|
|
rows++;
|
|
|
|
|
|
|
|
if ((rows != grid_view->rows) || (columns != grid_view->columns))
|
|
|
|
{
|
|
|
|
grid_view->rows = rows;
|
|
|
|
grid_view->columns = columns;
|
|
|
|
|
|
|
|
gtk_widget_set_size_request (grid_view->wrap_box,
|
|
|
|
columns * preview_requisition.width,
|
|
|
|
rows * preview_requisition.height);
|
2003-03-27 20:06:55 +08:00
|
|
|
|
2002-03-16 23:02:23 +08:00
|
|
|
}
|
2003-09-21 22:57:30 +08:00
|
|
|
|
2003-03-27 20:06:55 +08:00
|
|
|
grid_view->visible_rows = (allocation->height /
|
|
|
|
preview_requisition.height);
|
2002-03-16 23:02:23 +08:00
|
|
|
}
|
2003-04-15 22:13:14 +08:00
|
|
|
|
|
|
|
if (grid_view->selected_item)
|
|
|
|
{
|
2004-01-30 00:34:41 +08:00
|
|
|
GimpPreview *preview = grid_view->selected_item;
|
2003-04-15 22:13:14 +08:00
|
|
|
|
|
|
|
gimp_container_grid_view_highlight_item (view,
|
|
|
|
preview->viewable,
|
|
|
|
preview);
|
|
|
|
}
|
2002-03-16 23:02:23 +08:00
|
|
|
}
|
|
|
|
}
|