2001-02-04 22:10:03 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2001-04-22 08:38:56 +08:00
|
|
|
* gimpdatalist.c
|
|
|
|
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2001-02-04 22:10:03 +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 <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2001-02-04 22:10:03 +08:00
|
|
|
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2001-02-04 22:10:03 +08:00
|
|
|
|
2001-02-12 00:14:25 +08:00
|
|
|
#include "gimpdata.h"
|
2001-02-04 22:10:03 +08:00
|
|
|
#include "gimpdatalist.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-02-12 05:08:04 +08:00
|
|
|
|
2001-02-04 22:10:03 +08:00
|
|
|
|
|
|
|
static void gimp_data_list_class_init (GimpDataListClass *klass);
|
|
|
|
static void gimp_data_list_init (GimpDataList *list);
|
|
|
|
static void gimp_data_list_add (GimpContainer *container,
|
|
|
|
GimpObject *object);
|
|
|
|
static void gimp_data_list_remove (GimpContainer *container,
|
|
|
|
GimpObject *object);
|
|
|
|
|
2001-02-18 05:20:10 +08:00
|
|
|
static void gimp_data_list_object_renamed_callback (GimpObject *object,
|
2001-02-04 22:10:03 +08:00
|
|
|
GimpDataList *data_list);
|
|
|
|
static gint gimp_data_list_data_compare_func (gconstpointer first,
|
|
|
|
gconstpointer second);
|
|
|
|
|
|
|
|
|
|
|
|
static GimpListClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
2001-07-25 23:22:55 +08:00
|
|
|
GType
|
2001-02-04 22:10:03 +08:00
|
|
|
gimp_data_list_get_type (void)
|
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
static GType list_type = 0;
|
2001-02-04 22:10:03 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
if (! list_type)
|
2001-02-04 22:10:03 +08:00
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
static const GTypeInfo list_info =
|
2001-02-04 22:10:03 +08:00
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
sizeof (GimpDataListClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_data_list_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2001-02-04 22:10:03 +08:00
|
|
|
sizeof (GimpDataList),
|
2001-08-11 22:39:19 +08:00
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_data_list_init,
|
2001-02-04 22:10:03 +08:00
|
|
|
};
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
list_type = g_type_register_static (GIMP_TYPE_LIST,
|
|
|
|
"GimpDataList",
|
|
|
|
&list_info, 0);
|
2001-02-04 22:10:03 +08:00
|
|
|
}
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
return list_type;
|
2001-02-04 22:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_list_class_init (GimpDataListClass *klass)
|
|
|
|
{
|
|
|
|
GimpContainerClass *container_class;
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
container_class = GIMP_CONTAINER_CLASS (klass);
|
2001-02-04 22:10:03 +08:00
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-04 22:10:03 +08:00
|
|
|
|
|
|
|
container_class->add = gimp_data_list_add;
|
|
|
|
container_class->remove = gimp_data_list_remove;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_list_init (GimpDataList *list)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_list_add (GimpContainer *container,
|
|
|
|
GimpObject *object)
|
|
|
|
{
|
|
|
|
GimpList *list;
|
|
|
|
|
|
|
|
list = GIMP_LIST (container);
|
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
gimp_list_uniquefy_name (GIMP_LIST (container), object, TRUE);
|
2001-02-04 22:10:03 +08:00
|
|
|
|
|
|
|
list->list = g_list_insert_sorted (list->list, object,
|
|
|
|
gimp_data_list_data_compare_func);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_connect (object, "name_changed",
|
2001-07-25 23:22:55 +08:00
|
|
|
G_CALLBACK (gimp_data_list_object_renamed_callback),
|
|
|
|
container);
|
2001-02-04 22:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_list_remove (GimpContainer *container,
|
|
|
|
GimpObject *object)
|
|
|
|
{
|
|
|
|
GimpList *list;
|
|
|
|
|
|
|
|
list = GIMP_LIST (container);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (object,
|
2001-07-25 23:22:55 +08:00
|
|
|
gimp_data_list_object_renamed_callback,
|
|
|
|
container);
|
2001-02-04 22:10:03 +08:00
|
|
|
|
|
|
|
list->list = g_list_remove (list->list, object);
|
|
|
|
}
|
|
|
|
|
2001-02-19 10:17:31 +08:00
|
|
|
GimpContainer *
|
2001-07-25 23:22:55 +08:00
|
|
|
gimp_data_list_new (GType children_type)
|
2001-02-04 22:10:03 +08:00
|
|
|
{
|
|
|
|
GimpDataList *list;
|
|
|
|
|
2001-07-25 23:22:55 +08:00
|
|
|
g_return_val_if_fail (g_type_is_a (children_type, GIMP_TYPE_DATA), NULL);
|
2001-02-04 22:10:03 +08:00
|
|
|
|
2001-10-18 20:43:31 +08:00
|
|
|
list = g_object_new (GIMP_TYPE_DATA_LIST,
|
|
|
|
"children_type", children_type,
|
|
|
|
"policy", GIMP_CONTAINER_POLICY_STRONG,
|
|
|
|
NULL);
|
2001-02-04 22:10:03 +08:00
|
|
|
|
2001-02-19 10:17:31 +08:00
|
|
|
return GIMP_CONTAINER (list);
|
2001-02-04 22:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-04-06 19:21:56 +08:00
|
|
|
gimp_data_list_object_renamed_callback (GimpObject *object,
|
|
|
|
GimpDataList *data_list)
|
2001-02-04 22:10:03 +08:00
|
|
|
{
|
2003-04-06 19:21:56 +08:00
|
|
|
GimpList *gimp_list;
|
|
|
|
GList *list;
|
|
|
|
gint old_index;
|
|
|
|
gint new_index = 0;
|
2001-02-04 22:10:03 +08:00
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
gimp_list = GIMP_LIST (data_list);
|
2001-02-04 22:10:03 +08:00
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
g_signal_handlers_block_by_func (object,
|
|
|
|
gimp_data_list_object_renamed_callback,
|
|
|
|
data_list);
|
2001-02-04 22:10:03 +08:00
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
gimp_list_uniquefy_name (gimp_list, object, TRUE);
|
2001-02-04 22:10:03 +08:00
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
g_signal_handlers_unblock_by_func (object,
|
|
|
|
gimp_data_list_object_renamed_callback,
|
|
|
|
data_list);
|
2001-02-04 22:10:03 +08:00
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
old_index = g_list_index (gimp_list->list, object);
|
2001-02-04 22:10:03 +08:00
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
for (list = gimp_list->list; list; list = g_list_next (list))
|
2001-02-18 05:20:10 +08:00
|
|
|
{
|
2003-04-06 19:21:56 +08:00
|
|
|
GimpObject *object2 = GIMP_OBJECT (list->data);
|
2001-02-18 05:20:10 +08:00
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
if (object == object2)
|
|
|
|
continue;
|
2001-02-18 05:20:10 +08:00
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
if (gimp_data_list_data_compare_func (object, object2) > 0)
|
|
|
|
new_index++;
|
|
|
|
else
|
|
|
|
break;
|
2001-02-18 05:20:10 +08:00
|
|
|
}
|
2001-02-04 22:10:03 +08:00
|
|
|
|
2003-04-06 19:21:56 +08:00
|
|
|
if (new_index != old_index)
|
|
|
|
gimp_container_reorder (GIMP_CONTAINER (data_list), object, new_index);
|
2001-02-04 22:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gimp_data_list_data_compare_func (gconstpointer first,
|
|
|
|
gconstpointer second)
|
|
|
|
{
|
2002-06-12 21:48:47 +08:00
|
|
|
GimpData *first_data = (GimpData *) first;
|
|
|
|
GimpData *second_data = (GimpData *) second;
|
|
|
|
|
|
|
|
/* move the internal objects (like the FG -> BG) gradient) to the top */
|
|
|
|
if (first_data->internal != second_data->internal)
|
|
|
|
return first_data->internal ? -1 : 1;
|
|
|
|
|
2003-03-10 01:40:56 +08:00
|
|
|
return strcmp (((const GimpObject *) first)->name,
|
2001-02-04 22:10:03 +08:00
|
|
|
((const GimpObject *) second)->name);
|
|
|
|
}
|