gimp/app/widgets/gimplistitem.c

482 lines
15 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimplistitem.c
cleanup. 2001-04-22 Michael Natterer <mitch@gimp.org> * app/Makefile.am: cleanup. * app/interface.c: #include "gimpui.h" * app/gui/dialogs-constructors.[ch] * app/gui/dialogs.c * app/gui/menus.c * app/gui/test-commands.[ch]: changes for the image menu below. * app/apptypes.h * app/widgets/Makefile.am * app/widgets/gimpcontainermenu.[ch] * app/widgets/gimpcontainermenuimpl.[ch]: new widgets. The actual implemtation lives in a separate file because gimpcontainermenu.c's code is identical to gimpcontainerview.c's except for the base class. This will become an interface with Gtk 2.0. * app/widgets/gimpimagedock.[ch]: a dock with an image menu. The pages still don't follow the context correctly. * app/widgets/gimpmenuitem.[ch]: a menu item with a preview. * app/widgets/gimpdialogfactory.[ch]: pass a dock constructor to the constructor and provide a method to create a new dock within this factory's context. * app/widgets/gimpdock.[ch]: removed the constructor because we create only image docks now. Put the vbox into a main_vbox (which also contains the image menu). * app/widgets/gimpdockbook.[ch]: create new docks with the dialog factory. * app/gimpcontainer.[ch] * app/gimpdata.[ch] * app/gimpdatafactory.[ch] * app/gimpdatalist.[ch] * app/gimplist.[ch] * app/gimpviewable.[ch] * app/widgets/gimpbrushpreview.[ch] * app/widgets/gimpcontainergridview.[ch] * app/widgets/gimpcontainerlistview.[ch] * app/widgets/gimpcontainerview.[ch] * app/widgets/gimpdatafactoryview.[ch] * app/widgets/gimpdockable.[ch] * app/widgets/gimpdrawablelistitem.[ch] * app/widgets/gimpdrawablelistview.[ch] * app/widgets/gimpdrawablepreview.[ch] * app/widgets/gimplayerlistitem.[ch] * app/widgets/gimplayerlistview.[ch] * app/widgets/gimplistitem.[ch] * app/widgets/gimppalettepreview.[ch] * app/widgets/gimppatternpreview.[ch] * app/widgets/gimppreview.[ch]: ass-sign some copyrights.
2001-04-22 08:38:56 +08:00
* Copyright (C) 2001 Michael Natterer
*
* 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 "apptypes.h"
#include "gimpcontainer.h"
#include "gimpdnd.h"
#include "gimpdrawable.h"
#include "gimpdrawablelistitem.h"
#include "gimplayer.h"
#include "gimplayerlistitem.h"
#include "gimplistitem.h"
#include "gimpmarshal.h"
#include "gimppreview.h"
#include "gimpviewable.h"
enum
{
SET_VIEWABLE,
LAST_SIGNAL
};
static void gimp_list_item_class_init (GimpListItemClass *klass);
static void gimp_list_item_init (GimpListItem *list_item);
static void gimp_list_item_real_set_viewable (GimpListItem *list_item,
GimpViewable *viewable);
static void gimp_list_item_draw (GtkWidget *widget,
GdkRectangle *area);
static void gimp_list_item_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time);
static gboolean gimp_list_item_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static gboolean gimp_list_item_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time);
static void gimp_list_item_name_changed (GimpViewable *viewable,
GtkLabel *label);
static GimpViewable * gimp_list_item_drag_viewable (GtkWidget *widget,
gpointer data);
static guint list_item_signals[LAST_SIGNAL] = { 0 };
static GtkListItemClass *parent_class = NULL;
GtkType
gimp_list_item_get_type (void)
{
static GtkType list_item_type = 0;
if (!list_item_type)
{
static const GtkTypeInfo list_item_info =
{
"GimpListItem",
sizeof (GimpListItem),
sizeof (GimpListItemClass),
(GtkClassInitFunc) gimp_list_item_class_init,
(GtkObjectInitFunc) gimp_list_item_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
list_item_type = gtk_type_unique (GTK_TYPE_LIST_ITEM, &list_item_info);
}
return list_item_type;
}
static void
gimp_list_item_class_init (GimpListItemClass *klass)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass *) klass;
widget_class = (GtkWidgetClass *) klass;
parent_class = gtk_type_class (GTK_TYPE_LIST_ITEM);
list_item_signals[SET_VIEWABLE] =
gtk_signal_new ("set_viewable",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET (GimpListItemClass,
set_viewable),
gtk_marshal_NONE__OBJECT,
GTK_TYPE_NONE, 1,
GIMP_TYPE_VIEWABLE);
widget_class->draw = gimp_list_item_draw;
widget_class->drag_leave = gimp_list_item_drag_leave;
widget_class->drag_motion = gimp_list_item_drag_motion;
widget_class->drag_drop = gimp_list_item_drag_drop;
klass->set_viewable = gimp_list_item_real_set_viewable;
}
static void
gimp_list_item_init (GimpListItem *list_item)
{
removed the layer mask functions. 2001-03-06 Michael Natterer <mitch@gimp.org> * app/gimage.[ch]: removed the layer mask functions. * app/gimpchannel.[ch]: added a boolean "dummy" parameter to gimp_channel_copy() so it has the same signature as gimp_layer_copy() and can be used by the GimpDrawableListView to generically duplicate drawables. * app/gimpcontainerview.c: call "select_item" with a NULL item before changing the underlying GimpContainer so subclasses have a chance to update (e.g. set button sensitivity). * app/gimpdnd.c: folded all the GtkType comparing code into a utility function (much more readable now). * app/gimpdrawablelistview.[ch]: activated the "raise", "lower", "duplicate" and "delete". I'm not really happy with all those function pointers passed to the constructor (and the dummy parameters I've added to some GimpChannel functions) -- OTOH the generic view maybe worth the "gboolean dummy" cruft hanging around in the channel class. * app/gimplayer.[ch]: removed the "apply_mask", "edit_mask" and "show_mask" booleans ... * app/gimplayermask.[ch]: .. and added them here together with proper accessors and "*_changed" signals. This also makes the layer mask undo code much clearer as we don't have to store the booleans separately. * app/gimplayerlistitem.c: badly hacked to acheive the correct indicator being drawn around the active drawable. This needs a new GimpPreview function for setting the border color. * app/gimplistitem.c: smaller horizontal spacing. * app/gimppreview.[ch]: added the "border_width" parameter also to gimp_preview_set_size() so we can modify all previews the same way after creation. * app/layers_dialog.c: no need to push an undo group around the "duplicate layer" code. Was this an artefact or did I miss something here ??? * app/channel_ops.c * app/channels_dialog.c * app/gimage_mask.c * app/gimpcontainergridview.c * app/gimpcontainerlistview.c * app/gimpdrawablelistitem.c * app/gimpimage.[ch] * app/qmask.c * app/test_commands.c * app/undo.c * app/xcf.c * app/pdb/channel_cmds.c * tools/pdbgen/pdb/channel.pdb * app/pdb/selection_cmds.c * tools/pdbgen/pdb/selection.pdb: changed accordingly. * app/pdb/internal_procs.c * app/pdb/layer_cmds.c * libgimp/gimplayer_pdb.[ch] * tools/pdbgen/pdb/layer.pdb: commented out the layer mask accessors from the perl code, so the functions temporarily disappeared all over the place. * plug-ins/Makefile.am: don't build XJT until the layer mask stuff is back. * pixmaps/eye.xpm: cropped it to it's minimal size.
2001-03-06 21:28:39 +08:00
list_item->hbox = gtk_hbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (list_item->hbox), 2);
gtk_container_add (GTK_CONTAINER (list_item), list_item->hbox);
gtk_widget_show (list_item->hbox);
list_item->preview = NULL;
list_item->name_label = NULL;
list_item->preview_size = 0;
list_item->reorderable = FALSE;
list_item->drop_type = GIMP_DROP_NONE;
list_item->container = NULL;
}
static void
gimp_list_item_draw (GtkWidget *widget,
GdkRectangle *area)
{
GimpListItem *list_item;
list_item = GIMP_LIST_ITEM (widget);
if (GTK_WIDGET_CLASS (parent_class)->draw)
GTK_WIDGET_CLASS (parent_class)->draw (widget, area);
if (list_item->drop_type != GIMP_DROP_NONE)
{
gint x, y;
x = list_item->name_label->allocation.x;
y = ((list_item->drop_type == GIMP_DROP_ABOVE) ?
3 : widget->allocation.height - 4);
gdk_gc_set_line_attributes (widget->style->black_gc, 5, GDK_LINE_SOLID,
GDK_CAP_BUTT, GDK_JOIN_MITER);
gdk_draw_line (widget->window, widget->style->black_gc,
x, y,
widget->allocation.width - 3, y);
gdk_gc_set_line_attributes (widget->style->black_gc, 0, GDK_LINE_SOLID,
GDK_CAP_BUTT, GDK_JOIN_MITER);
}
}
static void
gimp_list_item_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time)
{
GimpListItem *list_item;
list_item = GIMP_LIST_ITEM (widget);
list_item->drop_type = GIMP_DROP_NONE;
}
static gboolean
gimp_list_item_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time)
{
GimpListItem *list_item;
GimpViewable *src_viewable;
gint dest_index;
GdkDragAction drag_action;
GimpDropType drop_type;
gboolean return_val;
list_item = GIMP_LIST_ITEM (widget);
return_val = gimp_list_item_check_drag (list_item, context, x, y,
&src_viewable,
&dest_index,
&drag_action,
&drop_type);
gdk_drag_status (context, drag_action, time);
list_item->drop_type = drop_type;
return return_val;
}
static gboolean
gimp_list_item_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time)
{
GimpListItem *list_item;
GimpViewable *src_viewable;
gint dest_index;
GdkDragAction drag_action;
GimpDropType drop_type;
gboolean return_val;
list_item = GIMP_LIST_ITEM (widget);
return_val = gimp_list_item_check_drag (list_item, context, x, y,
&src_viewable,
&dest_index,
&drag_action,
&drop_type);
gtk_drag_finish (context, return_val, FALSE, time);
list_item->drop_type = GIMP_DROP_NONE;
if (return_val)
{
gimp_container_reorder (list_item->container, GIMP_OBJECT (src_viewable),
dest_index);
}
return return_val;
}
GtkWidget *
gimp_list_item_new (GimpViewable *viewable,
gint preview_size)
{
GimpListItem *list_item;
g_return_val_if_fail (viewable != NULL, NULL);
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (preview_size > 0 && preview_size <= 256, NULL);
if (GIMP_IS_LAYER (viewable))
{
list_item = gtk_type_new (GIMP_TYPE_LAYER_LIST_ITEM);
}
else if (GIMP_IS_DRAWABLE (viewable))
{
list_item = gtk_type_new (GIMP_TYPE_DRAWABLE_LIST_ITEM);
}
else
{
list_item = gtk_type_new (GIMP_TYPE_LIST_ITEM);
}
list_item->preview_size = preview_size;
gimp_list_item_set_viewable (list_item, viewable);
return GTK_WIDGET (list_item);
}
void
gimp_list_item_set_viewable (GimpListItem *list_item,
GimpViewable *viewable)
{
gtk_signal_emit (GTK_OBJECT (list_item), list_item_signals[SET_VIEWABLE],
viewable);
}
static void
gimp_list_item_real_set_viewable (GimpListItem *list_item,
GimpViewable *viewable)
{
list_item->preview = gimp_preview_new (viewable, list_item->preview_size,
1, FALSE);
gtk_box_pack_start (GTK_BOX (list_item->hbox), list_item->preview,
FALSE, FALSE, 0);
gtk_widget_show (list_item->preview);
list_item->name_label =
gtk_label_new (gimp_object_get_name (GIMP_OBJECT (viewable)));
gtk_box_pack_start (GTK_BOX (list_item->hbox), list_item->name_label,
FALSE, FALSE, 0);
gtk_widget_show (list_item->name_label);
gtk_signal_connect_while_alive (GTK_OBJECT (viewable), "name_changed",
GTK_SIGNAL_FUNC (gimp_list_item_name_changed),
list_item->name_label,
GTK_OBJECT (list_item->name_label));
gimp_gtk_drag_source_set_by_type (GTK_WIDGET (list_item),
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
GTK_OBJECT (viewable)->klass->type,
GDK_ACTION_MOVE | GDK_ACTION_COPY);
gimp_dnd_viewable_source_set (GTK_WIDGET (list_item),
GTK_OBJECT (viewable)->klass->type,
gimp_list_item_drag_viewable,
NULL);
}
void
gimp_list_item_set_reorderable (GimpListItem *list_item,
gboolean reorderable,
GimpContainer *container)
{
g_return_if_fail (list_item != NULL);
g_return_if_fail (GIMP_IS_LIST_ITEM (list_item));
g_return_if_fail (! reorderable || container != NULL);
g_return_if_fail (! container || GIMP_IS_CONTAINER (container));
list_item->reorderable = reorderable;
if (reorderable)
app/Makefile.am app/apptypes.h new subclass of GimpDrawableListView (the 2001-03-11 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/apptypes.h * app/gimplayerlistview.[ch]: new subclass of GimpDrawableListView (the upcoming replacement of the layers dialog). Connects to the new GimpLayer signals using the layer container as signal proxy (see below). * app/gimpcontainerview.[ch]: made "set_container" a virtual function. This is needed by the GimpLayerListView to connect/disconnect signals. Subclasses implementing this method MUST obey the following order of instructions: 1. disconnect from signals related to GimpContainerView->container 2. chain up (!!!) 3. connect to signals related to GimpContainerView->container And yes, I will add DocBook files for all those new objects :) * app/gimppreview.[ch]: made "border_color" a GimpRGB instead of guchar[3]. Added gimp_preview_set_border_color(). * app/gimpcontainergridview.c * app/gimplayerlistitem.c: use gimp_preview_set_border_color(). * app/gimpcontainerlistview.c * app/gimpdrawablelistview.c: cleanup. * app/gimpdrawablelistitem.c: we can safely asume that our parent widget is a GimpDrawableListView and use it's "reorder_drawable" function pointer (after checking that it's there). * app/gimplistitem.c: connect the correct DND type when changing the container of a list item with "reorderable" enabled. * app/gimplayer.[ch]: added accessors and "*_changed" signals for layer->mode, layer->opacity and layer->preserve_trans. * app/disp_callbacks.c: fixed a FIXME: use the correct bucket fill tool context again. * app/tools/paint_options.[ch]: paint_mode_menu_new(): added a boolean which toggles the "Behind" item on/off to the same constructor can be used for all paint mode menus. * app/tools/gimptoolinfo.c: rect. select is the standard tool again. * app/brush_select.c * app/floating_sel.c * app/gimpimage.c * app/layers_dialog.c * app/pdb/layer_cmds.c * app/tools/gimpeditselectiontool.c * tools/pdbgen/pdb/layer.pdb: use the new layer accessors and the paint_mode_menu constructor. * app/commands.c * app/gdisplay.c * app/menus.c * app/undo.c * app/tools/gimppainttool.c * app/tools/gimptool.c * app/tools/paint_options.c * app/tools/tool_manager.c: put the #warning's back inside #ifdef __GNUC__
2001-03-12 01:24:47 +08:00
{
list_item->container = container;
gimp_gtk_drag_dest_set_by_type (GTK_WIDGET (list_item),
GTK_DEST_DEFAULT_ALL,
container->children_type,
GDK_ACTION_MOVE | GDK_ACTION_COPY);
}
else
app/Makefile.am app/apptypes.h new subclass of GimpDrawableListView (the 2001-03-11 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/apptypes.h * app/gimplayerlistview.[ch]: new subclass of GimpDrawableListView (the upcoming replacement of the layers dialog). Connects to the new GimpLayer signals using the layer container as signal proxy (see below). * app/gimpcontainerview.[ch]: made "set_container" a virtual function. This is needed by the GimpLayerListView to connect/disconnect signals. Subclasses implementing this method MUST obey the following order of instructions: 1. disconnect from signals related to GimpContainerView->container 2. chain up (!!!) 3. connect to signals related to GimpContainerView->container And yes, I will add DocBook files for all those new objects :) * app/gimppreview.[ch]: made "border_color" a GimpRGB instead of guchar[3]. Added gimp_preview_set_border_color(). * app/gimpcontainergridview.c * app/gimplayerlistitem.c: use gimp_preview_set_border_color(). * app/gimpcontainerlistview.c * app/gimpdrawablelistview.c: cleanup. * app/gimpdrawablelistitem.c: we can safely asume that our parent widget is a GimpDrawableListView and use it's "reorder_drawable" function pointer (after checking that it's there). * app/gimplistitem.c: connect the correct DND type when changing the container of a list item with "reorderable" enabled. * app/gimplayer.[ch]: added accessors and "*_changed" signals for layer->mode, layer->opacity and layer->preserve_trans. * app/disp_callbacks.c: fixed a FIXME: use the correct bucket fill tool context again. * app/tools/paint_options.[ch]: paint_mode_menu_new(): added a boolean which toggles the "Behind" item on/off to the same constructor can be used for all paint mode menus. * app/tools/gimptoolinfo.c: rect. select is the standard tool again. * app/brush_select.c * app/floating_sel.c * app/gimpimage.c * app/layers_dialog.c * app/pdb/layer_cmds.c * app/tools/gimpeditselectiontool.c * tools/pdbgen/pdb/layer.pdb: use the new layer accessors and the paint_mode_menu constructor. * app/commands.c * app/gdisplay.c * app/menus.c * app/undo.c * app/tools/gimppainttool.c * app/tools/gimptool.c * app/tools/paint_options.c * app/tools/tool_manager.c: put the #warning's back inside #ifdef __GNUC__
2001-03-12 01:24:47 +08:00
{
list_item->container = NULL;
gtk_drag_dest_unset (GTK_WIDGET (list_item));
}
}
gboolean
gimp_list_item_check_drag (GimpListItem *list_item,
GdkDragContext *context,
gint x,
gint y,
GimpViewable **src_viewable,
gint *dest_index,
GdkDragAction *drag_action,
GimpDropType *drop_type)
{
GtkWidget *src_widget;
GimpViewable *my_src_viewable = NULL;
GimpViewable *my_dest_viewable = NULL;
gint my_src_index = -1;
gint my_dest_index = -1;
GdkDragAction my_drag_action = GDK_ACTION_DEFAULT;
GimpDropType my_drop_type = GIMP_DROP_NONE;
gboolean return_val = FALSE;
if (list_item->reorderable &&
list_item->container &&
(src_widget = gtk_drag_get_source_widget (context)) &&
src_widget != GTK_WIDGET (list_item))
{
my_src_viewable = gimp_dnd_get_drag_data (src_widget);
my_dest_viewable = GIMP_PREVIEW (list_item->preview)->viewable;
if (my_src_viewable && my_dest_viewable)
{
my_src_index =
gimp_container_get_child_index (list_item->container,
GIMP_OBJECT (my_src_viewable));
my_dest_index =
gimp_container_get_child_index (list_item->container,
GIMP_OBJECT (my_dest_viewable));
if (my_src_viewable && my_src_index != -1 &&
my_dest_viewable && my_dest_index != -1)
{
gint difference;
difference = my_dest_index - my_src_index;
if (y < GTK_WIDGET (list_item)->allocation.height / 2)
my_drop_type = GIMP_DROP_ABOVE;
else
my_drop_type = GIMP_DROP_BELOW;
if (difference < 0 && my_drop_type == GIMP_DROP_BELOW)
{
my_dest_index++;
}
else if (difference > 0 && my_drop_type == GIMP_DROP_ABOVE)
{
my_dest_index--;
}
if (my_src_index != my_dest_index)
{
my_drag_action = GDK_ACTION_MOVE;
return_val = TRUE;
}
else
{
my_drop_type = GIMP_DROP_NONE;
}
}
}
}
*src_viewable = my_src_viewable;
*dest_index = my_dest_index;
*drag_action = my_drag_action;
*drop_type = my_drop_type;
return return_val;
}
void
gimp_list_item_button_realize (GtkWidget *widget,
gpointer data)
{
gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
}
void
gimp_list_item_button_state_changed (GtkWidget *widget,
GtkStateType previous_state,
gpointer data)
{
GtkWidget *list_item;
list_item = GTK_WIDGET (data);
if (widget->state != list_item->state)
{
switch (widget->state)
{
case GTK_STATE_NORMAL:
case GTK_STATE_ACTIVE:
/* beware: recursion */
gtk_widget_set_state (widget, list_item->state);
break;
default:
break;
}
}
}
static void
gimp_list_item_name_changed (GimpViewable *viewable,
GtkLabel *label)
{
gtk_label_set_text (label, gimp_object_get_name (GIMP_OBJECT (viewable)));
}
static GimpViewable *
gimp_list_item_drag_viewable (GtkWidget *widget,
gpointer data)
{
return GIMP_PREVIEW (GIMP_LIST_ITEM (widget)->preview)->viewable;
}