gimp/app/widgets/gimpcontainereditor.c
Michael Natterer bba8413773 app/core/Makefile.am new files: the QMask stuff stripped from GUI code.
2001-11-30  Michael Natterer  <mitch@gimp.org>

	* app/core/Makefile.am
	* app/core/gimpimage-qmask.[ch]: new files: the QMask stuff
	stripped from GUI code. Added gimp_image_qmask_invert().

	* app/core/gimpimage.[ch]: removed the QMask functions.

	* app/display/Makefile.am
	* app/display/gimpdisplayshell-qmask.[ch]: removed.

	* app/gui/Makefile.am
	* app/gui/qmask-commands.[ch]: new files for the new QMask item
	factory callbacks and the qmask query dialog.

	* app/gui/menus.c: added a context menu for the QMask button.

	* app/display/gimpdisplayshell.c
	* app/display/gimpdisplayshell-handlers.c: don't include the qmask
	stuff.

	* app/display/gimpdisplayshell-callbacks.[ch]: Moved the 2 qmask
	callbacks here. Don't popup the dialog on double_click. Show
	the contect menu on right-click.

	* app/display/gimpdisplayshell-callbacks.[ch]:
	gimp_display_shell_canvas_events(): removed the hack of
	conntecting "key_press_event" to gtk_true() while a tool is
	active. Instead, check for (event & GDK_BUTTON1_MASK) in the
	key_press and key_release handlers and stop signal emission. Save
	the modifier state on "button_press" and restore it after
	"button_release".

	Changed the way context menus are updated/shown:

	- removed GimpContainerContextFunc.
	- pass around item factory identifiers (e.g. "<Brushes>")
	- added voodoo to update the menus before showing them.

	* app/widgets/gimpitemfactory.[ch]: gimp_item_factory_new(): take
	a GimpItemFactoryUpdateFunc parameter, attach it as data to the
	factory and use it to update the menu in
	gimp_item_factory_popup_with_date().

	* app/widgets/gimpwidgets-utils.[ch]: removed
	gimp_item_factory_popup_with_data() here.

	* app/widgets/gimpbrushfactoryview.[ch]
	* app/widgets/gimpbufferview.[ch]
	* app/widgets/gimpcontainereditor.[ch]
	* app/widgets/gimpdatafactoryview.[ch]
	* app/widgets/gimpdocumentview.[ch]
	* app/widgets/gimpdrawablelistview.[ch]: use item_factory
	identifier strings all over the place.

	* app/widgets/gimpdockbook.c: removed the menu update code, it's
	now in gui/dialogs-commands.c.

	* app/gui/brushes-commands.[ch]
	* app/gui/buffers-commands.[c]
	* app/gui/channels-commands.[ch]
	* app/gui/dialogs-commands.[ch]
	* app/gui/documents-commands.[ch]
	* app/gui/gradient-editor-commands.[ch]
	* app/gui/gradients-commands.[ch]
	* app/gui/layers-commands.[ch]
	* app/gui/palettes-commands.[ch]
	* app/gui/patterns-commands.[ch]: removed all show_context_menu()
	functions and made the update functions public. Changed all
	update functions to use the gimp_item_factory_set_foo() methods
	instead of gimp_menu_item_set_foo().

	* app/gui/menus.c: pass the update functions to the
	gimp_item_factory_new().

	* app/gui/dialogs-constructors.c: pass item factory identifiers to
	all view constructors.

	* app/gui/gradient-editor.c: show the context menu using the new
	method.

	* app/gui/toolbox.c: no need to include "dialogs-commands.h".
2001-11-30 14:41:56 +00:00

263 lines
7.5 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpcontainereditor.c
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "core/gimpcontext.h"
#include "core/gimpcontainer.h"
#include "gimpcontainereditor.h"
#include "gimpcontainergridview.h"
#include "gimpcontainerlistview.h"
#include "gimpdnd.h"
#include "gimpitemfactory.h"
static void gimp_container_editor_class_init (GimpContainerEditorClass *klass);
static void gimp_container_editor_init (GimpContainerEditor *view);
static void gimp_container_editor_finalize (GObject *object);
static void gimp_container_editor_select_item (GtkWidget *widget,
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);
static void gimp_container_editor_real_context_item(GimpContainerEditor *editor,
GimpViewable *viewable);
static GtkVBoxClass *parent_class = NULL;
GType
gimp_container_editor_get_type (void)
{
static GType view_type = 0;
if (! view_type)
{
static const GTypeInfo view_info =
{
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,
};
view_type = g_type_register_static (GTK_TYPE_VBOX,
"GimpContainerEditor",
&view_info, 0);
}
return view_type;
}
static void
gimp_container_editor_class_init (GimpContainerEditorClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_container_editor_finalize;
klass->select_item = NULL;
klass->activate_item = NULL;
klass->context_item = gimp_container_editor_real_context_item;
}
static void
gimp_container_editor_init (GimpContainerEditor *view)
{
view->item_factory = NULL;
view->view = NULL;
}
static void
gimp_container_editor_finalize (GObject *object)
{
GimpContainerEditor *editor;
editor = GIMP_CONTAINER_EDITOR (object);
g_free (editor->item_factory);
editor->item_factory = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object);
}
gboolean
gimp_container_editor_construct (GimpContainerEditor *editor,
GimpViewType view_type,
GimpContainer *container,
GimpContext *context,
gint preview_size,
gboolean reorderable,
gint min_items_x,
gint min_items_y,
const gchar *item_factory)
{
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);
g_return_val_if_fail (preview_size > 0 && preview_size <= 64, FALSE);
g_return_val_if_fail (min_items_x > 0 && min_items_x <= 64, FALSE);
g_return_val_if_fail (min_items_y > 0 && min_items_y <= 64, FALSE);
editor->item_factory = g_strdup (item_factory);
switch (view_type)
{
case GIMP_VIEW_TYPE_GRID:
editor->view =
GIMP_CONTAINER_VIEW (gimp_container_grid_view_new (container,
context,
preview_size,
reorderable,
min_items_x,
min_items_y));
break;
case GIMP_VIEW_TYPE_LIST:
editor->view =
GIMP_CONTAINER_VIEW (gimp_container_list_view_new (container,
context,
preview_size,
reorderable,
min_items_x,
min_items_y));
break;
default:
g_warning ("%s(): unknown GimpViewType passed", G_GNUC_FUNCTION);
return FALSE;
}
gtk_container_add (GTK_CONTAINER (editor),
GTK_WIDGET (editor->view));
gtk_widget_show (GTK_WIDGET (editor->view));
g_signal_connect_object (G_OBJECT (editor->view), "select_item",
G_CALLBACK (gimp_container_editor_select_item),
G_OBJECT (editor),
0);
g_signal_connect_object (G_OBJECT (editor->view), "activate_item",
G_CALLBACK (gimp_container_editor_activate_item),
G_OBJECT (editor),
0);
g_signal_connect_object (G_OBJECT (editor->view), "context_item",
G_CALLBACK (gimp_container_editor_context_item),
G_OBJECT (editor),
0);
return TRUE;
}
/* private functions */
static void
gimp_container_editor_select_item (GtkWidget *widget,
GimpViewable *viewable,
gpointer insert_data,
GimpContainerEditor *editor)
{
GimpContainerEditorClass *klass;
klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
if (klass->select_item)
klass->select_item (editor, viewable);
}
static void
gimp_container_editor_activate_item (GtkWidget *widget,
GimpViewable *viewable,
gpointer insert_data,
GimpContainerEditor *editor)
{
GimpContainerEditorClass *klass;
klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
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)
{
GimpContainerEditorClass *klass;
klass = GIMP_CONTAINER_EDITOR_GET_CLASS (editor);
if (klass->context_item)
klass->context_item (editor, viewable);
}
static void
gimp_container_editor_real_context_item (GimpContainerEditor *editor,
GimpViewable *viewable)
{
if (viewable && gimp_container_have (editor->view->container,
GIMP_OBJECT (viewable)))
{
if (editor->item_factory)
{
GtkItemFactory *factory;
factory = gtk_item_factory_from_path (editor->item_factory);
if (factory)
{
gimp_item_factory_popup_with_data (factory, editor, NULL);
}
}
}
}