Ported module loading to GTypeModule, getting rid of all own module

2002-10-20  Michael Natterer  <mitch@gimp.org>

	Ported module loading to GTypeModule, getting rid of all own
	module registering/bookkeeping stuff for color selectors and
	display filters. The modules now simply register GimpColorSelector
	and GimpColorDisplay subclasses, the list of registered subclasses
	can then be obtained calling g_type_children() on the abstract
	base classes.

	This is work in progress and just the first working state after I
	started breaking everything...

	* app/gui/color-select.[ch]
	* libgimp/gimpcolordisplay.h
	* libgimp/gimpcolorselector.h: removed.

	* app/gui/Makefile.am
	* libgimp/Makefile.am: changed accordingly.

	* libgimp/gimpmodule.h: massively simplified. All voodoo is gone.

	* libgimpwidgets/gimpcolordisplay.[ch]
	* libgimpwidgets/gimpcolorselector.[ch]: new abstract base classes
	which need to be subclassed by modules.

	* libgimpwidgets/gimpcolorselect.[ch]: the built-in color selector
	from app/gui/color-select.* ported to be a GimpColorSelector
	subclass.

	* libgimpwidgets/Makefile.am
	* libgimpwidgets/gimpwidgets.h
	* libgimpwidgets/gimpwidgetsmarshal.list
	* libgimpwidgets/gimpwidgetstypes.h: changed accordingly.

	* app/core/gimpmoduleinfo.[ch]: made it a GTypeModule subclass

	* app/core/gimpmodules.c: changed accordingly.

	* app/core/gimpcontainer.c
	* app/core/gimplist.c: HACKED around to allow GimpLists of
	GObjects (not GimpObjects). This is EEKy, so I will either make
	gimp->modules a simple GList and revert this bit of change, or
	allow GObjects all over the place in GimpContainer land...

	* app/display/gimpdisplayshell-filter.[ch]
	* app/gui/color-notebook.c: removed all module stuff and use
	g_type_children() to get the list of available color_selectors
	and display_filters.

	* app/display/gimpdisplayshell-filter-dialog.c
	* app/display/gimpdisplayshell-render.c
	* app/gui/module-browser.c: changed accordingly.

	* app/gui/gui.c: ref the built-in color selector's class before
	the modules are queried so it appears first in the list of
	GimpColorSelector's children.

	* modules/Makefile.am: build the water color selector again.

	* modules/cdisplay_gamma.c
	* modules/cdisplay_highcontrast.c
	* modules/colorsel_triangle.c
	* modules/colorsel_water.c: ported them all to the new API.

	* modules/gimpmodregister.[ch]: removed the old EMX module hack.
This commit is contained in:
Michael Natterer 2002-10-20 10:14:17 +00:00 committed by Michael Natterer
parent 921d265270
commit d7055a3351
47 changed files with 2813 additions and 5410 deletions

View File

@ -1,3 +1,69 @@
2002-10-20 Michael Natterer <mitch@gimp.org>
Ported module loading to GTypeModule, getting rid of all own
module registering/bookkeeping stuff for color selectors and
display filters. The modules now simply register GimpColorSelector
and GimpColorDisplay subclasses, the list of registered subclasses
can then be obtained calling g_type_children() on the abstract
base classes.
This is work in progress and just the first working state after I
started breaking everything...
* app/gui/color-select.[ch]
* libgimp/gimpcolordisplay.h
* libgimp/gimpcolorselector.h: removed.
* app/gui/Makefile.am
* libgimp/Makefile.am: changed accordingly.
* libgimp/gimpmodule.h: massively simplified. All voodoo is gone.
* libgimpwidgets/gimpcolordisplay.[ch]
* libgimpwidgets/gimpcolorselector.[ch]: new abstract base classes
which need to be subclassed by modules.
* libgimpwidgets/gimpcolorselect.[ch]: the built-in color selector
from app/gui/color-select.* ported to be a GimpColorSelector
subclass.
* libgimpwidgets/Makefile.am
* libgimpwidgets/gimpwidgets.h
* libgimpwidgets/gimpwidgetsmarshal.list
* libgimpwidgets/gimpwidgetstypes.h: changed accordingly.
* app/core/gimpmoduleinfo.[ch]: made it a GTypeModule subclass
* app/core/gimpmodules.c: changed accordingly.
* app/core/gimpcontainer.c
* app/core/gimplist.c: HACKED around to allow GimpLists of
GObjects (not GimpObjects). This is EEKy, so I will either make
gimp->modules a simple GList and revert this bit of change, or
allow GObjects all over the place in GimpContainer land...
* app/display/gimpdisplayshell-filter.[ch]
* app/gui/color-notebook.c: removed all module stuff and use
g_type_children() to get the list of available color_selectors
and display_filters.
* app/display/gimpdisplayshell-filter-dialog.c
* app/display/gimpdisplayshell-render.c
* app/gui/module-browser.c: changed accordingly.
* app/gui/gui.c: ref the built-in color selector's class before
the modules are queried so it appears first in the list of
GimpColorSelector's children.
* modules/Makefile.am: build the water color selector again.
* modules/cdisplay_gamma.c
* modules/cdisplay_highcontrast.c
* modules/colorsel_triangle.c
* modules/colorsel_water.c: ported them all to the new API.
* modules/gimpmodregister.[ch]: removed the old EMX module hack.
2002-10-18 Sven Neumann <sven@gimp.org>
* app/core/gimpimage-mask.c (gimp_image_mask_extract): changed an

View File

@ -47,6 +47,9 @@
#include "libgimp/gimpintl.h"
#define DUMP_DB 1
static void gimp_modules_module_initialize (const gchar *filename,
gpointer loader_data);
@ -60,8 +63,6 @@ static void print_module_info (gpointer data,
static gboolean gimp_modules_write_modulerc (Gimp *gimp);
static void gimp_modules_module_free_func (gpointer data,
gpointer user_data);
static void gimp_modules_module_on_disk_func (gpointer data,
gpointer user_data);
static void gimp_modules_module_remove_func (gpointer data,
@ -74,7 +75,7 @@ gimp_modules_init (Gimp *gimp)
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp->modules = gimp_list_new (GIMP_TYPE_MODULE_INFO,
GIMP_CONTAINER_POLICY_WEAK);
GIMP_CONTAINER_POLICY_STRONG);
gimp_object_set_name (GIMP_OBJECT (gimp->modules), "modules");
gimp->write_modulerc = FALSE;
@ -110,7 +111,7 @@ gimp_modules_load (Gimp *gimp)
gimp);
#ifdef DUMP_DB
gimp_container_foreach (modules, print_module_info, NULL);
gimp_container_foreach (gimp->modules, print_module_info, NULL);
#endif
}
@ -126,8 +127,6 @@ gimp_modules_unload (Gimp *gimp)
gimp->write_modulerc = FALSE;
}
}
gimp_container_foreach (gimp->modules, gimp_modules_module_free_func, NULL);
}
void
@ -153,20 +152,6 @@ gimp_modules_refresh (Gimp *gimp)
gimp);
}
static void
gimp_modules_module_free_func (gpointer data,
gpointer user_data)
{
GimpModuleInfoObj *module_info = data;
if (module_info->module &&
module_info->unload &&
module_info->state == GIMP_MODULE_STATE_LOADED_OK)
{
gimp_module_info_module_unload (module_info, FALSE);
}
}
static void
add_to_inhibit_string (gpointer data,
gpointer user_data)
@ -177,7 +162,7 @@ add_to_inhibit_string (gpointer data,
if (module_info->load_inhibit)
{
str = g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
str = g_string_append (str, module_info->fullpath);
str = g_string_append (str, module_info->filename);
}
}
@ -266,62 +251,29 @@ gimp_modules_module_initialize (const gchar *filename,
if (gimp_modules_module_find_by_path (gimp, filename))
return;
module_info = gimp_module_info_new (filename);
module_info = gimp_module_info_new (filename,
gimp->config->module_db_load_inhibit,
gimp->be_verbose);
gimp_module_info_set_load_inhibit (module_info,
gimp->config->module_db_load_inhibit);
if (! module_info->load_inhibit)
{
if (gimp->be_verbose)
g_print (_("loading module: '%s'\n"), filename);
gimp_module_info_module_load (module_info, TRUE);
}
else
{
if (gimp->be_verbose)
g_print (_("skipping module: '%s'\n"), filename);
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
}
gimp_container_add (gimp->modules, GIMP_OBJECT (module_info));
}
typedef struct
{
const gchar *search_key;
GimpModuleInfoObj *found;
} find_by_path_closure;
static void
gimp_modules_module_path_cmp_func (gpointer data,
gpointer user_data)
{
GimpModuleInfoObj *module_info;
find_by_path_closure *closure;
module_info = (GimpModuleInfoObj *) data;
closure = (find_by_path_closure *) user_data;
if (! strcmp (module_info->fullpath, closure->search_key))
closure->found = module_info;
gimp_container_add (gimp->modules, (GimpObject *) module_info);
}
static GimpModuleInfoObj *
gimp_modules_module_find_by_path (Gimp *gimp,
const char *fullpath)
{
find_by_path_closure cl;
GimpModuleInfoObj *module_info;
GList *list;
cl.found = NULL;
cl.search_key = fullpath;
for (list = GIMP_LIST (gimp->modules)->list; list; list = g_list_next (list))
{
module_info = (GimpModuleInfoObj *) list->data;
gimp_container_foreach (gimp->modules,
gimp_modules_module_path_cmp_func, &cl);
if (! strcmp (module_info->filename, fullpath))
return module_info;
}
return cl.found;
return NULL;
}
#ifdef DUMP_DB
@ -331,22 +283,25 @@ print_module_info (gpointer data,
{
GimpModuleInfoObj *i = data;
g_print ("\n%s: %s\n",
i->fullpath, statename[i->state]);
g_print (" module:%p lasterr:%s init:%p unload:%p\n",
i->module, i->last_module_error? i->last_module_error : "NONE",
i->init, i->unload);
g_print ("\n%s: %i\n",
i->filename,
i->state /* statename[i->state] */);
g_print (" module:%p lasterr:%s register:%p\n",
i->module,
i->last_module_error? i->last_module_error : "NONE",
i->register_module);
if (i->info)
{
g_print (" shutdown_data: %p\n"
" purpose: %s\n"
g_print (" purpose: %s\n"
" author: %s\n"
" version: %s\n"
" copyright: %s\n"
" date: %s\n",
i->info->shutdown_data,
i->info->purpose, i->info->author, i->info->version,
i->info->copyright, i->info->date);
i->info->purpose,
i->info->author,
i->info->version,
i->info->copyright,
i->info->date);
}
}
#endif
@ -364,7 +319,7 @@ gimp_modules_module_on_disk_func (gpointer data,
old_on_disk = module_info->on_disk;
module_info->on_disk = g_file_test (module_info->fullpath,
module_info->on_disk = g_file_test (module_info->filename,
G_FILE_TEST_IS_REGULAR);
/* if it's not on the disk, and it isn't in memory, mark it to be
@ -390,7 +345,5 @@ gimp_modules_module_remove_func (gpointer data,
module_info = (GimpModuleInfoObj *) data;
gimp = (Gimp *) user_data;
gimp_container_remove (gimp->modules, GIMP_OBJECT (module_info));
g_object_unref (G_OBJECT (module_info));
gimp_container_remove (gimp->modules, (GimpObject *) module_info);
}

View File

@ -195,7 +195,7 @@ gimp_container_class_init (GimpContainerClass *klass)
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_OBJECT);
G_TYPE_OBJECT);
container_signals[REMOVE] =
g_signal_new ("remove",
@ -205,7 +205,7 @@ gimp_container_class_init (GimpContainerClass *klass)
NULL, NULL,
gimp_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
GIMP_TYPE_OBJECT);
G_TYPE_OBJECT);
container_signals[REORDER] =
g_signal_new ("reorder",
@ -215,7 +215,7 @@ gimp_container_class_init (GimpContainerClass *klass)
NULL, NULL,
gimp_marshal_VOID__OBJECT_INT,
G_TYPE_NONE, 2,
GIMP_TYPE_OBJECT,
G_TYPE_OBJECT,
G_TYPE_INT);
container_signals[FREEZE] =
@ -396,7 +396,7 @@ gimp_container_serialize_foreach (GObject *object,
{
GimpConfigInterface *config_iface;
GString *str;
const gchar *name;
const gchar *name = NULL;
config_iface = GIMP_GET_CONFIG_INTERFACE (object);
@ -413,7 +413,8 @@ gimp_container_serialize_foreach (GObject *object,
g_string_append_printf (str, "(%s ",
g_type_name (G_TYPE_FROM_INSTANCE (object)));
name = gimp_object_get_name (GIMP_OBJECT (object));
if (GIMP_IS_OBJECT (object))
name = gimp_object_get_name (GIMP_OBJECT (object));
if (name)
{

View File

@ -131,7 +131,7 @@ gimp_list_dispose (GObject *object)
while (list->list)
{
gimp_container_remove (GIMP_CONTAINER (list),
GIMP_OBJECT (list->list->data));
(GimpObject *) list->list->data);
}
G_OBJECT_CLASS (parent_class)->dispose (object);
@ -155,7 +155,8 @@ gimp_list_get_memsize (GimpObject *object)
for (list = gimp_list->list; list; list = g_list_next (list))
{
memsize += gimp_object_get_memsize (GIMP_OBJECT (list->data));
if (GIMP_IS_OBJECT (list->data))
memsize += gimp_object_get_memsize (GIMP_OBJECT (list->data));
}
}
@ -279,7 +280,7 @@ gimp_list_new (GType children_type,
{
GimpList *list;
g_return_val_if_fail (g_type_is_a (children_type, GIMP_TYPE_OBJECT), NULL);
g_return_val_if_fail (g_type_is_a (children_type, G_TYPE_OBJECT), NULL);
g_return_val_if_fail (policy == GIMP_CONTAINER_POLICY_STRONG ||
policy == GIMP_CONTAINER_POLICY_WEAK, NULL);

View File

@ -42,17 +42,21 @@ enum
};
static void gimp_module_info_class_init (GimpModuleInfoObjClass *klass);
static void gimp_module_info_init (GimpModuleInfoObj *mod);
static void gimp_module_info_class_init (GimpModuleInfoObjClass *klass);
static void gimp_module_info_init (GimpModuleInfoObj *mod);
static void gimp_module_info_finalize (GObject *object);
static void gimp_module_info_finalize (GObject *object);
static gsize gimp_module_info_get_memsize (GimpObject *object);
static gboolean gimp_module_info_load (GTypeModule *module);
static void gimp_module_info_unload (GTypeModule *module);
static void gimp_module_info_set_last_error (GimpModuleInfoObj *module_info,
const gchar *error_str);
static guint module_info_signals[LAST_SIGNAL];
static GimpObjectClass *parent_class = NULL;
static GTypeModuleClass *parent_class = NULL;
GType
@ -75,7 +79,7 @@ gimp_module_info_get_type (void)
(GInstanceInitFunc) gimp_module_info_init,
};
module_info_type = g_type_register_static (GIMP_TYPE_OBJECT,
module_info_type = g_type_register_static (G_TYPE_TYPE_MODULE,
"GimpModuleInfoObj",
&module_info_info, 0);
}
@ -86,11 +90,11 @@ gimp_module_info_get_type (void)
static void
gimp_module_info_class_init (GimpModuleInfoObjClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GObjectClass *object_class;
GTypeModuleClass *module_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
object_class = G_OBJECT_CLASS (klass);
module_class = G_TYPE_MODULE_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@ -103,27 +107,28 @@ gimp_module_info_class_init (GimpModuleInfoObjClass *klass)
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->finalize = gimp_module_info_finalize;
object_class->finalize = gimp_module_info_finalize;
gimp_object_class->get_memsize = gimp_module_info_get_memsize;
module_class->load = gimp_module_info_load;
module_class->unload = gimp_module_info_unload;
klass->modified = NULL;
klass->modified = NULL;
}
static void
gimp_module_info_init (GimpModuleInfoObj *module_info)
{
module_info->fullpath = NULL;
module_info->filename = NULL;
module_info->verbose = FALSE;
module_info->state = GIMP_MODULE_STATE_ERROR;
module_info->on_disk = FALSE;
module_info->load_inhibit = FALSE;
module_info->refs = 0;
module_info->info = NULL;
module_info->module = NULL;
module_info->info = NULL;
module_info->last_module_error = NULL;
module_info->init = NULL;
module_info->unload = NULL;
module_info->register_module = NULL;
}
static void
@ -133,40 +138,103 @@ gimp_module_info_finalize (GObject *object)
mod = GIMP_MODULE_INFO (object);
/* if this trips, then we're onto some serious lossage in a moment */
g_return_if_fail (mod->refs == 0);
if (mod->last_module_error)
{
g_free (mod->last_module_error);
mod->last_module_error = NULL;
}
if (mod->fullpath)
if (mod->filename)
{
g_free (mod->fullpath);
mod->fullpath = NULL;
g_free (mod->filename);
mod->filename = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gsize
gimp_module_info_get_memsize (GimpObject *object)
static gboolean
gimp_module_info_load (GTypeModule *module)
{
GimpModuleInfoObj *module_info;
gsize memsize = 0;
gpointer symbol;
gboolean retval;
module_info = GIMP_MODULE_INFO (object);
g_return_val_if_fail (GIMP_IS_MODULE_INFO (module), FALSE);
if (module_info->fullpath)
memsize += strlen (module_info->fullpath) + 1;
module_info = GIMP_MODULE_INFO (module);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
g_return_val_if_fail (module_info->filename != NULL, FALSE);
g_return_val_if_fail (module_info->module == NULL, FALSE);
if (module_info->verbose)
g_print (_("loading module: '%s'\n"), module_info->filename);
module_info->module = g_module_open (module_info->filename,
G_MODULE_BIND_LAZY);
if (! module_info->module)
{
module_info->state = GIMP_MODULE_STATE_ERROR;
gimp_module_info_set_last_error (module_info, g_module_error ());
if (module_info->verbose)
g_message (_("Module '%s' load error:\n%s"),
module_info->filename, module_info->last_module_error);
return FALSE;
}
/* find the module_init symbol */
if (! g_module_symbol (module_info->module, "gimp_module_register", &symbol))
{
module_info->state = GIMP_MODULE_STATE_ERROR;
gimp_module_info_set_last_error (module_info,
_("Missing gimp_module_register() symbol"));
if (module_info->verbose)
g_message (_("Module '%s' load error:\n%s"),
module_info->filename, module_info->last_module_error);
g_module_close (module_info->module);
module_info->module = NULL;
return FALSE;
}
module_info->register_module = symbol;
retval = module_info->register_module (module, &module_info->info);
if (retval)
module_info->state = GIMP_MODULE_STATE_LOADED_OK;
else
module_info->state = GIMP_MODULE_STATE_LOAD_FAILED;
return retval;
}
static void
gimp_module_info_unload (GTypeModule *module)
{
GimpModuleInfoObj *module_info;
g_return_if_fail (GIMP_IS_MODULE_INFO (module));
module_info = GIMP_MODULE_INFO (module);
g_return_if_fail (module_info->module != NULL);
g_module_close (module_info->module); /* FIXME: error handling */
module_info->module = NULL;
module_info->info = NULL;
module_info->register_module = NULL;
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
}
GimpModuleInfoObj *
gimp_module_info_new (const gchar *filename)
gimp_module_info_new (const gchar *filename,
const gchar *inhibit_list,
gboolean verbose)
{
GimpModuleInfoObj *module_info;
@ -174,9 +242,25 @@ gimp_module_info_new (const gchar *filename)
module_info = g_object_new (GIMP_TYPE_MODULE_INFO, NULL);
module_info->fullpath = g_strdup (filename);
module_info->filename = g_strdup (filename);
module_info->verbose = verbose ? TRUE : FALSE;
module_info->on_disk = TRUE;
gimp_module_info_set_load_inhibit (module_info, inhibit_list);
if (! module_info->load_inhibit)
{
if (gimp_module_info_load (G_TYPE_MODULE (module_info)))
gimp_module_info_unload (G_TYPE_MODULE (module_info));
}
else
{
if (verbose)
g_print (_("skipping module: '%s'\n"), filename);
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
}
return module_info;
}
@ -198,14 +282,14 @@ gimp_module_info_set_load_inhibit (GimpModuleInfoObj *module_info,
const gchar *end;
g_return_if_fail (GIMP_IS_MODULE_INFO (module_info));
g_return_if_fail (module_info->fullpath != NULL);
g_return_if_fail (module_info->filename != NULL);
module_info->load_inhibit = FALSE;
if (! inhibit_list || ! strlen (inhibit_list))
return;
p = strstr (inhibit_list, module_info->fullpath);
p = strstr (inhibit_list, module_info->filename);
if (!p)
return;
@ -221,7 +305,7 @@ gimp_module_info_set_load_inhibit (GimpModuleInfoObj *module_info,
if (! end)
end = inhibit_list + strlen (inhibit_list);
pathlen = strlen (module_info->fullpath);
pathlen = strlen (module_info->filename);
if ((end - start) == pathlen)
module_info->load_inhibit = TRUE;
@ -236,185 +320,3 @@ gimp_module_info_set_last_error (GimpModuleInfoObj *module_info,
module_info->last_module_error = g_strdup (error_str);
}
/*
* FIXME: currently this will fail badly on EMX
*/
#ifdef __EMX__
extern void gimp_color_selector_register (void);
extern void gimp_color_selector_unregister (void);
extern void dialog_register (void);
extern void dialog_unregister (void);
static struct main_funcs_struc
{
gchar *name;
void (* func) (void);
}
gimp_main_funcs[] =
{
{ "gimp_color_selector_register", gimp_color_selector_register },
{ "gimp_color_selector_unregister", gimp_color_selector_unregister },
{ "dialog_register", dialog_register },
{ "dialog_unregister", dialog_unregister },
{ NULL, NULL }
};
#endif
void
gimp_module_info_module_load (GimpModuleInfoObj *module_info,
gboolean verbose)
{
gpointer symbol;
g_return_if_fail (GIMP_IS_MODULE_INFO (module_info));
g_return_if_fail (module_info->fullpath != NULL);
g_return_if_fail (module_info->module == NULL);
module_info->module = g_module_open (module_info->fullpath,
G_MODULE_BIND_LAZY);
if (! module_info->module)
{
module_info->state = GIMP_MODULE_STATE_ERROR;
gimp_module_info_set_last_error (module_info, g_module_error ());
if (verbose)
g_message (_("Module '%s' load error:\n%s"),
module_info->fullpath, module_info->last_module_error);
return;
}
#ifdef __EMX__
if (g_module_symbol (module_info->module, "gimp_main_funcs", &symbol))
{
*(struct main_funcs_struc **) symbol = gimp_main_funcs;
}
#endif
/* find the module_init symbol */
if (! g_module_symbol (module_info->module, "module_init", &symbol))
{
module_info->state = GIMP_MODULE_STATE_ERROR;
gimp_module_info_set_last_error (module_info,
_("Missing module_init() symbol"));
if (verbose)
g_message (_("Module '%s' load error:\n%s"),
module_info->fullpath, module_info->last_module_error);
g_module_close (module_info->module);
module_info->module = NULL;
return;
}
module_info->init = symbol;
/* loaded modules are assumed to have a ref of 1 */
gimp_module_info_module_ref (module_info);
/* run module's initialisation */
if (module_info->init (&module_info->info) == GIMP_MODULE_UNLOAD)
{
module_info->state = GIMP_MODULE_STATE_LOAD_FAILED;
gimp_module_info_module_unref (module_info);
module_info->info = NULL;
return;
}
/* module is now happy */
module_info->state = GIMP_MODULE_STATE_LOADED_OK;
/* do we have an unload function? */
if (g_module_symbol (module_info->module, "module_unload", &symbol))
{
module_info->unload = symbol;
}
}
static void
gimp_module_info_module_unload_completed_callback (gpointer data)
{
GimpModuleInfoObj *module_info;
module_info = (GimpModuleInfoObj *) data;
g_return_if_fail (module_info->state == GIMP_MODULE_STATE_UNLOAD_REQUESTED);
/* lose the ref we gave this module when we loaded it,
* since the module's now happy to be unloaded.
*/
gimp_module_info_module_unref (module_info);
module_info->info = NULL;
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
gimp_module_info_modified (module_info);
}
static gboolean
gimp_module_info_module_idle_unref (gpointer data)
{
GimpModuleInfoObj *module_info;
module_info = (GimpModuleInfoObj *) data;
gimp_module_info_module_unref (module_info);
return FALSE;
}
void
gimp_module_info_module_unload (GimpModuleInfoObj *module_info,
gboolean verbose)
{
g_return_if_fail (GIMP_IS_MODULE_INFO (module_info));
g_return_if_fail (module_info->module != NULL);
g_return_if_fail (module_info->unload != NULL);
if (module_info->state == GIMP_MODULE_STATE_UNLOAD_REQUESTED)
return;
module_info->state = GIMP_MODULE_STATE_UNLOAD_REQUESTED;
/* Send the unload request. Need to ref the module so we don't
* accidentally unload it while this call is in progress (eg if the
* callback is called before the unload function returns).
*/
gimp_module_info_module_ref (module_info);
module_info->unload (module_info->info->shutdown_data,
gimp_module_info_module_unload_completed_callback,
module_info);
g_idle_add (gimp_module_info_module_idle_unref, module_info);
}
void
gimp_module_info_module_ref (GimpModuleInfoObj *module_info)
{
g_return_if_fail (GIMP_IS_MODULE_INFO (module_info));
g_return_if_fail (module_info->refs >= 0);
g_return_if_fail (module_info->module != NULL);
module_info->refs++;
}
void
gimp_module_info_module_unref (GimpModuleInfoObj *module_info)
{
g_return_if_fail (GIMP_IS_MODULE_INFO (module_info));
g_return_if_fail (module_info->refs > 0);
g_return_if_fail (module_info->module != NULL);
module_info->refs--;
if (module_info->refs == 0)
{
g_module_close (module_info->module);
module_info->module = NULL;
}
}

View File

@ -25,8 +25,6 @@
#include "libgimp/gimpmodule.h"
#include "gimpobject.h"
typedef enum
{
@ -50,34 +48,26 @@ typedef struct _GimpModuleInfoObjClass GimpModuleInfoObjClass;
struct _GimpModuleInfoObj
{
GimpObject parent_instance;
GTypeModule parent_instance;
gchar *fullpath; /* path to the module */
gchar *filename; /* path to the module */
gboolean verbose; /* verbose error reporting */
GimpModuleState state; /* what's happened to the module */
gboolean on_disk; /* TRUE if file still exists */
gboolean load_inhibit; /* user requests not to load at boot time */
/* Count of times main gimp is within the module. Normally, this
* will be 1, and we assume that the module won't call its
* unload callback until it is satisfied that it's not in use any
* more. refs can be 2 temporarily while we're running the module's
* unload function, to stop the module attempting to unload
* itself.
*/
gint refs;
/* stuff from now on may be NULL depending on the state the module is in */
GimpModuleInfo *info; /* returned values from module_init */
/* stuff from now on may be NULL depending on the state the module is in */
GModule *module; /* handle on the module */
GimpModuleInfo *info; /* returned values from module_register */
gchar *last_module_error;
GimpModuleInitFunc init;
GimpModuleUnloadFunc unload;
gboolean (* register_module) (GTypeModule *module,
GimpModuleInfo **module_info);
};
struct _GimpModuleInfoObjClass
{
GimpObjectClass parent_class;
GTypeModuleClass parent_class;
void (* modified) (GimpModuleInfoObj *module_info);
};
@ -85,18 +75,13 @@ struct _GimpModuleInfoObjClass
GType gimp_module_info_get_type (void) G_GNUC_CONST;
GimpModuleInfoObj * gimp_module_info_new (const gchar *filename);
GimpModuleInfoObj * gimp_module_info_new (const gchar *filename,
const gchar *inhibit_str,
gboolean verbose);
void gimp_module_info_modified (GimpModuleInfoObj *module);
void gimp_module_info_set_load_inhibit (GimpModuleInfoObj *module,
const gchar *inhibit_list);
void gimp_module_info_module_load (GimpModuleInfoObj *module_info,
gboolean verbose);
void gimp_module_info_module_unload (GimpModuleInfoObj *module_info,
gboolean verbose);
void gimp_module_info_module_ref (GimpModuleInfoObj *module_info);
void gimp_module_info_module_unref (GimpModuleInfoObj *module_info);
#endif /* __GIMP_MODULE_INFO_H__ */

View File

@ -47,6 +47,9 @@
#include "libgimp/gimpintl.h"
#define DUMP_DB 1
static void gimp_modules_module_initialize (const gchar *filename,
gpointer loader_data);
@ -60,8 +63,6 @@ static void print_module_info (gpointer data,
static gboolean gimp_modules_write_modulerc (Gimp *gimp);
static void gimp_modules_module_free_func (gpointer data,
gpointer user_data);
static void gimp_modules_module_on_disk_func (gpointer data,
gpointer user_data);
static void gimp_modules_module_remove_func (gpointer data,
@ -74,7 +75,7 @@ gimp_modules_init (Gimp *gimp)
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp->modules = gimp_list_new (GIMP_TYPE_MODULE_INFO,
GIMP_CONTAINER_POLICY_WEAK);
GIMP_CONTAINER_POLICY_STRONG);
gimp_object_set_name (GIMP_OBJECT (gimp->modules), "modules");
gimp->write_modulerc = FALSE;
@ -110,7 +111,7 @@ gimp_modules_load (Gimp *gimp)
gimp);
#ifdef DUMP_DB
gimp_container_foreach (modules, print_module_info, NULL);
gimp_container_foreach (gimp->modules, print_module_info, NULL);
#endif
}
@ -126,8 +127,6 @@ gimp_modules_unload (Gimp *gimp)
gimp->write_modulerc = FALSE;
}
}
gimp_container_foreach (gimp->modules, gimp_modules_module_free_func, NULL);
}
void
@ -153,20 +152,6 @@ gimp_modules_refresh (Gimp *gimp)
gimp);
}
static void
gimp_modules_module_free_func (gpointer data,
gpointer user_data)
{
GimpModuleInfoObj *module_info = data;
if (module_info->module &&
module_info->unload &&
module_info->state == GIMP_MODULE_STATE_LOADED_OK)
{
gimp_module_info_module_unload (module_info, FALSE);
}
}
static void
add_to_inhibit_string (gpointer data,
gpointer user_data)
@ -177,7 +162,7 @@ add_to_inhibit_string (gpointer data,
if (module_info->load_inhibit)
{
str = g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
str = g_string_append (str, module_info->fullpath);
str = g_string_append (str, module_info->filename);
}
}
@ -266,62 +251,29 @@ gimp_modules_module_initialize (const gchar *filename,
if (gimp_modules_module_find_by_path (gimp, filename))
return;
module_info = gimp_module_info_new (filename);
module_info = gimp_module_info_new (filename,
gimp->config->module_db_load_inhibit,
gimp->be_verbose);
gimp_module_info_set_load_inhibit (module_info,
gimp->config->module_db_load_inhibit);
if (! module_info->load_inhibit)
{
if (gimp->be_verbose)
g_print (_("loading module: '%s'\n"), filename);
gimp_module_info_module_load (module_info, TRUE);
}
else
{
if (gimp->be_verbose)
g_print (_("skipping module: '%s'\n"), filename);
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
}
gimp_container_add (gimp->modules, GIMP_OBJECT (module_info));
}
typedef struct
{
const gchar *search_key;
GimpModuleInfoObj *found;
} find_by_path_closure;
static void
gimp_modules_module_path_cmp_func (gpointer data,
gpointer user_data)
{
GimpModuleInfoObj *module_info;
find_by_path_closure *closure;
module_info = (GimpModuleInfoObj *) data;
closure = (find_by_path_closure *) user_data;
if (! strcmp (module_info->fullpath, closure->search_key))
closure->found = module_info;
gimp_container_add (gimp->modules, (GimpObject *) module_info);
}
static GimpModuleInfoObj *
gimp_modules_module_find_by_path (Gimp *gimp,
const char *fullpath)
{
find_by_path_closure cl;
GimpModuleInfoObj *module_info;
GList *list;
cl.found = NULL;
cl.search_key = fullpath;
for (list = GIMP_LIST (gimp->modules)->list; list; list = g_list_next (list))
{
module_info = (GimpModuleInfoObj *) list->data;
gimp_container_foreach (gimp->modules,
gimp_modules_module_path_cmp_func, &cl);
if (! strcmp (module_info->filename, fullpath))
return module_info;
}
return cl.found;
return NULL;
}
#ifdef DUMP_DB
@ -331,22 +283,25 @@ print_module_info (gpointer data,
{
GimpModuleInfoObj *i = data;
g_print ("\n%s: %s\n",
i->fullpath, statename[i->state]);
g_print (" module:%p lasterr:%s init:%p unload:%p\n",
i->module, i->last_module_error? i->last_module_error : "NONE",
i->init, i->unload);
g_print ("\n%s: %i\n",
i->filename,
i->state /* statename[i->state] */);
g_print (" module:%p lasterr:%s register:%p\n",
i->module,
i->last_module_error? i->last_module_error : "NONE",
i->register_module);
if (i->info)
{
g_print (" shutdown_data: %p\n"
" purpose: %s\n"
g_print (" purpose: %s\n"
" author: %s\n"
" version: %s\n"
" copyright: %s\n"
" date: %s\n",
i->info->shutdown_data,
i->info->purpose, i->info->author, i->info->version,
i->info->copyright, i->info->date);
i->info->purpose,
i->info->author,
i->info->version,
i->info->copyright,
i->info->date);
}
}
#endif
@ -364,7 +319,7 @@ gimp_modules_module_on_disk_func (gpointer data,
old_on_disk = module_info->on_disk;
module_info->on_disk = g_file_test (module_info->fullpath,
module_info->on_disk = g_file_test (module_info->filename,
G_FILE_TEST_IS_REGULAR);
/* if it's not on the disk, and it isn't in memory, mark it to be
@ -390,7 +345,5 @@ gimp_modules_module_remove_func (gpointer data,
module_info = (GimpModuleInfoObj *) data;
gimp = (Gimp *) user_data;
gimp_container_remove (gimp->modules, GIMP_OBJECT (module_info));
g_object_unref (G_OBJECT (module_info));
gimp_container_remove (gimp->modules, (GimpObject *) module_info);
}

View File

@ -24,13 +24,11 @@
#include <stdlib.h>
#include <string.h>
#include <gmodule.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "libgimp/gimpcolorselector.h"
#include "gui-types.h"
@ -54,39 +52,6 @@ typedef enum
} ColorNotebookUpdateType;
/* "class" information we keep on each registered color selector */
typedef struct _ColorSelectorInfo ColorSelectorInfo;
struct _ColorSelectorInfo
{
gchar *name; /* label used in notebook tab */
gchar *help_page;
GimpColorSelectorMethods methods;
gint refs; /* number of instances around */
gboolean active;
GimpColorSelectorFinishedCB death_callback;
gpointer death_data;
ColorSelectorInfo *next;
};
/* "instance" information we keep on each notebook tab */
typedef struct _ColorSelectorInstance ColorSelectorInstance;
struct _ColorSelectorInstance
{
ColorNotebook *color_notebook;
ColorSelectorInfo *info;
GtkWidget *frame; /* main widget */
gpointer selector_data;
ColorSelectorInstance *next;
};
struct _ColorNotebook
{
GtkWidget *shell;
@ -105,7 +70,7 @@ struct _ColorNotebook
GimpRGB orig_rgb;
GimpColorSelectorChannelType active_channel;
GimpColorSelectorChannel active_channel;
ColorNotebookCallback callback;
gpointer client_data;
@ -113,8 +78,8 @@ struct _ColorNotebook
gboolean wants_updates;
gboolean show_alpha;
ColorSelectorInstance *selectors;
ColorSelectorInstance *cur_page;
GList *selectors;
GimpColorSelector *cur_page;
};
@ -131,22 +96,21 @@ static ColorNotebook *
gboolean show_alpha);
static void color_notebook_ok_callback (GtkWidget *widget,
gpointer data);
ColorNotebook *cnp);
static void color_notebook_cancel_callback (GtkWidget *widget,
gpointer data);
ColorNotebook *cnp);
static void color_notebook_reset_callback (GtkWidget *widget,
gpointer data);
static void color_notebook_update_callback (gpointer data,
ColorNotebook *cnp);
static void color_notebook_update_callback (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv,
const GimpRGB *rgb);
ColorNotebook *cnp);
static void color_notebook_page_switch (GtkWidget *widget,
GtkNotebookPage *page,
guint page_num,
gpointer data);
ColorNotebook *cnp);
static void color_notebook_help_func (const gchar *help_data);
static void color_notebook_selector_death (ColorSelectorInfo *info);
static void color_notebook_set_white (ColorNotebook *cnp);
static void color_notebook_set_black (ColorNotebook *cnp);
static void color_notebook_color_changed (GtkWidget *widget,
@ -180,10 +144,7 @@ static void color_history_add_clicked (GtkWidget *widget,
gpointer data);
/* master list of all registered colour selectors */
static ColorSelectorInfo *selector_info = NULL;
static GList *color_notebooks = NULL;
static GList *color_notebooks = NULL;
static GimpRGB color_history[COLOR_HISTORY_SIZE];
static gboolean color_history_initialized = FALSE;
@ -278,8 +239,8 @@ color_notebook_new_internal (GimpViewable *viewable,
GSList *group;
guchar r, g, b;
gchar buffer[8];
ColorSelectorInfo *info;
ColorSelectorInstance *csel;
GType *selector_types;
gint n_selector_types;
gint i;
static gchar *toggle_titles[] =
@ -313,7 +274,6 @@ color_notebook_new_internal (GimpViewable *viewable,
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 100 };
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 10 };
g_return_val_if_fail (selector_info != NULL, NULL);
g_return_val_if_fail (color != NULL, NULL);
if (! color_history_initialized)
@ -401,8 +361,10 @@ color_notebook_new_internal (GimpViewable *viewable,
gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0);
gtk_widget_show (right_vbox);
selector_types = g_type_children (GIMP_TYPE_COLOR_SELECTOR, &n_selector_types);
/* do we actually need a notebook? */
if (selector_info->next)
if (n_selector_types > 1)
{
cnp->notebook = gtk_notebook_new ();
gtk_box_pack_start (GTK_BOX (left_vbox), cnp->notebook,
@ -415,53 +377,43 @@ color_notebook_new_internal (GimpViewable *viewable,
}
/* create each registered color selector */
info = selector_info;
while (info)
for (i = 0; i < n_selector_types; i++)
{
if (info->active)
{
csel = g_new (ColorSelectorInstance, 1);
csel->color_notebook = cnp;
csel->info = info;
info->refs++;
csel->frame =
info->methods.new (&cnp->hsv,
&cnp->rgb,
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
g_object_set_data (G_OBJECT (csel->frame), "gimp_color_notebook",
csel);
GtkWidget *selector;
if (cnp->notebook)
{
label = gtk_label_new (info->name);
gtk_widget_show (label);
/* hide the frame, so it doesn't get selected by mistake */
gtk_widget_hide (csel->frame);
gtk_notebook_append_page (GTK_NOTEBOOK (cnp->notebook),
csel->frame,
label);
}
else
{
gtk_box_pack_start (GTK_BOX (left_vbox), csel->frame,
TRUE, TRUE, 0);
}
selector = gimp_color_selector_new (selector_types[i],
&cnp->rgb,
&cnp->hsv);
gtk_widget_show (csel->frame);
if (! selector)
continue;
if (!cnp->cur_page)
cnp->cur_page = csel;
if (cnp->notebook)
{
label = gtk_label_new (GIMP_COLOR_SELECTOR_GET_CLASS (selector)->name);
/* link into list of all selectors hanging off the new notebook */
csel->next = cnp->selectors;
cnp->selectors = csel;
}
gtk_notebook_append_page (GTK_NOTEBOOK (cnp->notebook),
selector, label);
}
else
{
gtk_box_pack_start (GTK_BOX (left_vbox), selector, TRUE, TRUE, 0);
}
info = info->next;
if (! cnp->cur_page)
cnp->cur_page = GIMP_COLOR_SELECTOR (selector);
cnp->selectors = g_list_append (cnp->selectors, selector);
gtk_widget_show (selector);
g_signal_connect (G_OBJECT (selector), "color_changed",
G_CALLBACK (color_notebook_update_callback),
cnp);
}
g_free (selector_types);
/* The table for the color_areas */
table = gtk_table_new (2, 4, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 1);
@ -712,45 +664,27 @@ color_notebook_show (ColorNotebook *cnp)
{
g_return_if_fail (cnp != NULL);
if (! GTK_WIDGET_VISIBLE (cnp->shell))
gtk_widget_show (cnp->shell);
else
gdk_window_raise (cnp->shell->window);
gtk_window_present (GTK_WINDOW (cnp->shell));
}
void
color_notebook_hide (ColorNotebook *cnp)
{
g_return_if_fail (cnp != NULL);
gtk_widget_hide (cnp->shell);
}
void
color_notebook_free (ColorNotebook *cnp)
{
ColorSelectorInstance *csel, *next;
g_return_if_fail (cnp != NULL);
color_notebooks = g_list_remove (color_notebooks, cnp);
gtk_widget_destroy (cnp->shell);
/* call the free functions for all the color selectors */
csel = cnp->selectors;
while (csel)
{
next = csel->next;
csel->info->methods.free (csel->selector_data);
csel->info->refs--;
if (csel->info->refs == 0 && !csel->info->active)
color_notebook_selector_death (csel->info);
g_free (csel);
csel = next;
}
g_list_free (cnp->selectors);
g_free (cnp);
}
@ -835,20 +769,11 @@ color_notebook_color_changed (GtkWidget *widget,
* Called by a color selector on user selection of a color
*/
static void
color_notebook_update_callback (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
color_notebook_update_callback (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv,
ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
ColorNotebook *cnp;
g_return_if_fail (data != NULL);
g_return_if_fail (hsv != NULL);
g_return_if_fail (rgb != NULL);
csel = (ColorSelectorInstance *) data;
cnp = csel->color_notebook;
cnp->hsv = *hsv;
cnp->rgb = *rgb;
@ -860,13 +785,9 @@ color_notebook_update_callback (gpointer data,
}
static void
color_notebook_ok_callback (GtkWidget *widget,
gpointer data)
color_notebook_ok_callback (GtkWidget *widget,
ColorNotebook *cnp)
{
ColorNotebook *cnp;
cnp = (ColorNotebook *) data;
color_history_add_clicked (NULL, cnp);
if (cnp->callback)
@ -879,13 +800,9 @@ color_notebook_ok_callback (GtkWidget *widget,
}
static void
color_notebook_cancel_callback (GtkWidget *widget,
gpointer data)
color_notebook_cancel_callback (GtkWidget *widget,
ColorNotebook *cnp)
{
ColorNotebook *cnp;
cnp = (ColorNotebook *) data;
if (cnp->callback)
{
(* cnp->callback) (cnp,
@ -896,13 +813,9 @@ color_notebook_cancel_callback (GtkWidget *widget,
}
static void
color_notebook_reset_callback (GtkWidget *widget,
gpointer data)
color_notebook_reset_callback (GtkWidget *widget,
ColorNotebook *cnp)
{
ColorNotebook *cnp;
cnp = (ColorNotebook *) data;
cnp->rgb = cnp->orig_rgb;
color_notebook_update_hsv_values (cnp);
@ -918,28 +831,21 @@ static void
color_notebook_page_switch (GtkWidget *widget,
GtkNotebookPage *page,
guint page_num,
gpointer data)
ColorNotebook *cnp)
{
GtkWidget *page_widget;
ColorNotebook *cnp;
ColorSelectorInstance *csel;
gint i;
cnp = (ColorNotebook *) data;
GtkWidget *page_widget;
gboolean set_channel;
gint i;
page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (widget), page_num);
csel = g_object_get_data (G_OBJECT (page_widget), "gimp_color_notebook");
cnp->cur_page = GIMP_COLOR_SELECTOR (page_widget);
g_return_if_fail (cnp != NULL && csel != NULL);
cnp->cur_page = csel;
set_channel =
(GIMP_COLOR_SELECTOR_GET_CLASS (page_widget)->set_channel != NULL);
for (i = 0; i < 6; i++)
{
gtk_widget_set_sensitive (cnp->toggles[i],
csel->info->methods.set_channel != NULL);
}
gtk_widget_set_sensitive (cnp->toggles[i], set_channel);
color_notebook_update (cnp, UPDATE_CHANNEL | UPDATE_NOTEBOOK);
}
@ -953,106 +859,12 @@ color_notebook_help_func (const gchar *data)
cnp = (ColorNotebook *) data;
help_path = g_strconcat ("dialogs/color_selectors/",
cnp->cur_page->info->help_page,
GIMP_COLOR_SELECTOR_GET_CLASS (cnp->cur_page)->help_page,
NULL);
gimp_standard_help_func (help_path);
g_free (help_path);
}
/**************************/
/* Registration functions */
G_MODULE_EXPORT
GimpColorSelectorID
gimp_color_selector_register (const gchar *name,
const gchar *help_page,
GimpColorSelectorMethods *methods)
{
ColorSelectorInfo *info;
/* check the name is unique */
info = selector_info;
while (info)
{
if (!strcmp (info->name, name))
return NULL;
info = info->next;
}
info = g_new (ColorSelectorInfo, 1);
info->name = g_strdup (name);
info->help_page = g_strdup (help_page);
info->methods = *methods;
info->refs = 0;
info->active = TRUE;
info->next = selector_info;
selector_info = info;
return info;
}
G_MODULE_EXPORT
gboolean
gimp_color_selector_unregister (GimpColorSelectorID id,
GimpColorSelectorFinishedCB callback,
gpointer data)
{
ColorSelectorInfo *info;
info = selector_info;
while (info)
{
if (info == id)
{
info->active = FALSE;
info->death_callback = callback;
info->death_data = data;
if (info->refs == 0)
color_notebook_selector_death (info);
return TRUE;
}
info = info->next;
}
g_warning ("%s: unknown color selector ID %p", G_STRLOC, id);
return FALSE;
}
static void
color_notebook_selector_death (ColorSelectorInfo *info)
{
ColorSelectorInfo *here, *prev;
here = selector_info;
prev = NULL;
while (here)
{
if (here == info)
{
if (prev)
prev->next = info->next;
else
selector_info = info->next;
if (info->death_callback)
(*info->death_callback) (info->death_data);
g_free (info->name);
g_free (info);
return;
}
prev = here;
here = here->next;
}
g_warning ("%s: color selector %p not found.", G_STRLOC, info);
}
static void
color_notebook_update (ColorNotebook *cnp,
ColorNotebookUpdateType update)
@ -1079,30 +891,16 @@ color_notebook_update (ColorNotebook *cnp,
static void
color_notebook_update_notebook (ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
if (csel->info->methods.set_color)
csel->info->methods.set_color (csel->selector_data,
&cnp->hsv,
&cnp->rgb);
gimp_color_selector_set_color (cnp->cur_page,
&cnp->rgb,
&cnp->hsv);
}
static void
color_notebook_update_channel (ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
if (csel->info->methods.set_channel)
csel->info->methods.set_channel (csel->selector_data,
cnp->active_channel);
gimp_color_selector_set_channel (cnp->cur_page,
cnp->active_channel);
}
static void
@ -1237,7 +1035,7 @@ color_notebook_toggle_update (GtkWidget *widget,
for (i = 0; i < 6; i++)
if (widget == cnp->toggles[i])
cnp->active_channel = (GimpColorSelectorChannelType) i;
cnp->active_channel = (GimpColorSelectorChannel) i;
color_notebook_update (cnp, UPDATE_CHANNEL);
}

View File

@ -280,10 +280,11 @@ browser_load_unload_callback (GtkWidget *widget,
{
BrowserState *st = data;
if (st->last_update->state == GIMP_MODULE_STATE_LOADED_OK)
gimp_module_info_module_unload (st->last_update, FALSE);
else
gimp_module_info_module_load (st->last_update, FALSE);
if (st->last_update->state != GIMP_MODULE_STATE_LOADED_OK)
{
if (g_type_module_use (G_TYPE_MODULE (st->last_update)))
g_type_module_unuse (G_TYPE_MODULE (st->last_update));
}
gimp_module_info_modified (st->last_update);
}
@ -310,7 +311,7 @@ make_list_item (gpointer data,
gtk_list_store_append (st->list, &iter);
gtk_list_store_set (st->list, &iter,
PATH_COLUMN, info->fullpath,
PATH_COLUMN, info->filename,
INFO_COLUMN, info,
-1);
}
@ -444,8 +445,7 @@ browser_info_update (GimpModuleInfoObj *mod,
case GIMP_MODULE_STATE_LOADED_OK:
gtk_label_set_text (GTK_LABEL(st->button_label), _("Unload"));
gtk_widget_set_sensitive (GTK_WIDGET (st->button),
mod->unload ? TRUE : FALSE);
gtk_widget_set_sensitive (GTK_WIDGET (st->button), FALSE);
break;
}
}

View File

@ -91,8 +91,6 @@ static void color_display_down_callback (GtkWidget *widget,
static void color_display_configure_callback (GtkWidget *widget,
ColorDisplayDialog *cdd);
static void src_list_populate (const char *name,
GtkTreeStore *src);
static void dest_list_populate (GList *node_list,
GtkTreeStore *dest);
@ -142,7 +140,7 @@ make_dialog (ColorDisplayDialog *cdd)
gtk_box_pack_start (GTK_BOX (hbox), scrolled_win, TRUE, TRUE, 0);
gtk_widget_show (scrolled_win);
cdd->src = gtk_tree_store_new (1, G_TYPE_STRING);
cdd->src = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (cdd->src));
g_object_unref (G_OBJECT (cdd->src));
@ -357,10 +355,10 @@ color_display_add_callback (GtkWidget *widget,
ColorDisplayNode *node;
GValue val = { 0, };
gtk_tree_model_get_value (model, &iter, 0, &val);
gtk_tree_model_get_value (model, &iter, 1, &val);
node = gimp_display_shell_filter_attach (cdd->shell,
g_value_get_string (&val));
(GType) g_value_get_pointer (&val));
g_value_unset (&val);
@ -527,12 +525,34 @@ void
gimp_display_shell_filter_dialog_new (GimpDisplayShell *shell)
{
ColorDisplayDialog *cdd;
GType *filter_types;
gint n_filter_types;
gint i;
cdd = g_new0 (ColorDisplayDialog, 1);
make_dialog (cdd);
color_display_foreach ((GimpCDFunc) src_list_populate, cdd->src);
filter_types = g_type_children (GIMP_TYPE_COLOR_DISPLAY, &n_filter_types);
for (i = 0; i < n_filter_types; i++)
{
GimpColorDisplayClass *filter_class;
GtkTreeIter iter;
filter_class = g_type_class_ref (filter_types[i]);
gtk_tree_store_append (cdd->src, &iter, NULL);
gtk_tree_store_set (cdd->src, &iter,
0, filter_class->name,
1, filter_types[i],
-1);
g_type_class_unref (filter_class);
}
g_free (filter_types);
cdd->old_nodes = shell->filters;
dest_list_populate (shell->filters, cdd->dest);
@ -543,19 +563,6 @@ gimp_display_shell_filter_dialog_new (GimpDisplayShell *shell)
shell->filters_dialog = cdd->dialog;
}
static void
src_list_populate (const char *name,
GtkTreeStore *src)
{
GtkTreeIter iter;
gtk_tree_store_append (src, &iter, NULL);
gtk_tree_store_set (src, &iter,
0, name,
-1);
}
static void
dest_list_populate (GList *node_list,
GtkTreeStore *dest)

View File

@ -24,6 +24,7 @@
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "display-types.h"
@ -34,152 +35,28 @@
#include "gimpdisplayshell-filter.h"
typedef struct _ColorDisplayInfo ColorDisplayInfo;
struct _ColorDisplayInfo
{
gchar *name;
GimpColorDisplayMethods methods;
GSList *refs;
};
static void color_display_foreach_real (gpointer key,
gpointer value,
gpointer user_data);
static void gimp_display_shell_filter_detach_real (GimpDisplayShell *shell,
ColorDisplayNode *node,
gboolean unref);
static gint node_name_compare (ColorDisplayNode *node,
const gchar *name);
ColorDisplayNode *node);
static GHashTable *color_display_table = NULL;
void
color_display_init (void)
{
}
G_MODULE_EXPORT gboolean
gimp_color_display_register (const gchar *name,
GimpColorDisplayMethods *methods)
{
ColorDisplayInfo *info;
info = g_new (ColorDisplayInfo, 1);
info->name = g_strdup (name);
info->methods = *methods;
info->refs = NULL;
if (!color_display_table)
color_display_table = g_hash_table_new (g_str_hash, g_str_equal);
if (g_hash_table_lookup (color_display_table, name))
return FALSE;
if (!methods->convert)
return FALSE;
g_hash_table_insert (color_display_table, info->name, info);
return TRUE;
}
G_MODULE_EXPORT gboolean
gimp_color_display_unregister (const gchar *name)
{
ColorDisplayInfo *info;
GimpDisplayShell *shell;
GList *node;
if ((info = g_hash_table_lookup (color_display_table, name)))
{
GSList *refs;
for (refs = info->refs; refs; refs = g_slist_next (refs))
{
shell = GIMP_DISPLAY_SHELL (refs->data);
node = g_list_find_custom (shell->filters, (gpointer) name,
(GCompareFunc) node_name_compare);
shell->filters = g_list_remove_link (shell->filters, node);
gimp_display_shell_filter_detach_real (shell, node->data, FALSE);
g_list_free_1 (node);
}
g_slist_free (info->refs);
g_hash_table_remove (color_display_table, name);
g_free (info->name);
g_free (info);
}
return TRUE;
}
typedef struct _DisplayForeachData DisplayForeachData;
struct _DisplayForeachData
{
GimpCDFunc func;
gpointer user_data;
};
void
color_display_foreach (GimpCDFunc func,
gpointer user_data)
{
DisplayForeachData data;
data.func = func;
data.user_data = user_data;
g_hash_table_foreach (color_display_table, color_display_foreach_real, &data);
}
static void
color_display_foreach_real (gpointer key,
gpointer value,
gpointer user_data)
{
DisplayForeachData *data;
data = (DisplayForeachData *) user_data;
data->func (key, data->user_data);
}
ColorDisplayNode *
gimp_display_shell_filter_attach (GimpDisplayShell *shell,
const gchar *name)
GType type)
{
ColorDisplayInfo *info;
GimpColorDisplay *color_display;
ColorDisplayNode *node;
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);
g_return_val_if_fail (g_type_is_a (type, GIMP_TYPE_COLOR_DISPLAY), NULL);
if ((info = g_hash_table_lookup (color_display_table, name)))
color_display = gimp_color_display_new (type);
if (color_display)
{
node = g_new (ColorDisplayNode, 1);
node->cd_name = g_strdup (name);
node->cd_ID = NULL;
if (!info->refs && info->methods.init)
info->methods.init ();
info->refs = g_slist_append (info->refs, shell);
if (info->methods.new)
node->cd_ID = info->methods.new (shell->gdisp->gimage->base_type);
node->cd_convert = info->methods.convert;
node->cd_name = g_strdup (GIMP_COLOR_DISPLAY_GET_CLASS (color_display)->name);
node->color_display = color_display;
shell->filters = g_list_append (shell->filters, node);
@ -195,25 +72,20 @@ ColorDisplayNode *
gimp_display_shell_filter_attach_clone (GimpDisplayShell *shell,
ColorDisplayNode *node)
{
ColorDisplayInfo *info;
GimpColorDisplay *color_display;
ColorDisplayNode *clone;
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);
g_return_val_if_fail (node != NULL, NULL);
if ((info = g_hash_table_lookup (color_display_table, node->cd_name)))
color_display = gimp_color_display_clone (node->color_display);
if (color_display)
{
clone = g_new (ColorDisplayNode, 1);
clone->cd_name = g_strdup (node->cd_name);
clone->cd_ID = NULL;
info->refs = g_slist_append (info->refs, shell);
if (info->methods.clone)
node->cd_ID = info->methods.clone (node->cd_ID);
node->cd_convert = info->methods.convert;
clone->cd_name = g_strdup (node->cd_name);
clone->color_display = color_display;
shell->filters = g_list_append (shell->filters, node);
@ -240,7 +112,7 @@ gimp_display_shell_filter_detach_destroy (GimpDisplayShell *shell,
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
gimp_display_shell_filter_detach_real (shell, node, TRUE);
gimp_display_shell_filter_detach_real (shell, node);
shell->filters = g_list_remove (shell->filters, node);
}
@ -254,7 +126,7 @@ gimp_display_shell_filter_detach_all (GimpDisplayShell *shell)
for (list = shell->filters; list; list = g_list_next (list))
{
gimp_display_shell_filter_detach_real (shell, list->data, TRUE);
gimp_display_shell_filter_detach_real (shell, list->data);
}
g_list_free (shell->filters);
@ -263,26 +135,12 @@ gimp_display_shell_filter_detach_all (GimpDisplayShell *shell)
static void
gimp_display_shell_filter_detach_real (GimpDisplayShell *shell,
ColorDisplayNode *node,
gboolean unref)
ColorDisplayNode *node)
{
ColorDisplayInfo *info;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_return_if_fail (node != NULL);
if ((info = g_hash_table_lookup (color_display_table, node->cd_name)))
{
if (info->methods.destroy)
info->methods.destroy (node->cd_ID);
if (unref)
info->refs = g_slist_remove (info->refs, shell);
if (!info->refs && info->methods.finalize)
info->methods.finalize ();
}
g_return_if_fail (node != NULL);
g_object_unref (node->color_display);
g_free (node->cd_name);
g_free (node);
}
@ -323,13 +181,6 @@ gimp_display_shell_filter_reorder_down (GimpDisplayShell *shell,
}
}
static gint
node_name_compare (ColorDisplayNode *node,
const char *name)
{
return strcmp (node->cd_name, name);
}
void
gimp_display_shell_filter_configure (ColorDisplayNode *node,
GFunc ok_func,
@ -337,37 +188,17 @@ gimp_display_shell_filter_configure (ColorDisplayNode *node,
GFunc cancel_func,
gpointer cancel_data)
{
ColorDisplayInfo *info;
g_return_if_fail (node != NULL);
if ((info = g_hash_table_lookup (color_display_table, node->cd_name)))
{
if (info->methods.configure)
info->methods.configure (node->cd_ID,
ok_func, ok_data,
cancel_func, cancel_data);
}
else
g_warning ("Tried to configure a nonexistant color display");
return;
gimp_color_display_configure (node->color_display,
ok_func, ok_data,
cancel_func, cancel_data);
}
void
gimp_display_shell_filter_configure_cancel (ColorDisplayNode *node)
{
ColorDisplayInfo *info;
g_return_if_fail (node != NULL);
if ((info = g_hash_table_lookup (color_display_table, node->cd_name)))
{
if (info->methods.cancel)
info->methods.cancel (node->cd_ID);
}
else
g_warning ("Tried to configure cancel a nonexistant color display");
return;
gimp_color_display_configure_cancel (node->color_display);
}

View File

@ -20,27 +20,18 @@
#define __GIMP_DISPLAY_SHELL_FILTER_H__
#include "libgimp/gimpcolordisplay.h"
typedef struct _ColorDisplayNode ColorDisplayNode;
struct _ColorDisplayNode {
gpointer cd_ID;
gchar *cd_name;
GimpColorDisplayConvert cd_convert;
struct _ColorDisplayNode
{
GimpColorDisplay *color_display;
gchar *cd_name;
};
typedef void (*GimpCDFunc) (const gchar *name,
gpointer user_data);
void color_display_init (void);
void color_display_foreach (GimpCDFunc func,
gpointer user_data);
ColorDisplayNode *
gimp_display_shell_filter_attach (GimpDisplayShell *shell,
const gchar *name);
GType type);
ColorDisplayNode *
gimp_display_shell_filter_attach_clone (GimpDisplayShell *shell,
ColorDisplayNode *node);

View File

@ -23,6 +23,8 @@
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "display-types.h"
#include "base/tile-manager.h"
@ -271,11 +273,11 @@ gimp_display_shell_render (GimpDisplayShell *shell,
node = (ColorDisplayNode *) list->data;
node->cd_convert (node->cd_ID,
shell->render_buf,
w, h,
3,
3 * GIMP_DISPLAY_SHELL_RENDER_BUF_WIDTH);
gimp_color_display_convert (node->color_display,
shell->render_buf,
w, h,
3,
3 * GIMP_DISPLAY_SHELL_RENDER_BUF_WIDTH);
}
/* put it to the screen */

View File

@ -16,8 +16,6 @@ libappgui_a_SOURCES = \
channels-commands.h \
color-notebook.c \
color-notebook.h \
color-select.c \
color-select.h \
colormap-editor-commands.c \
colormap-editor-commands.h \
convert-dialog.c \

View File

@ -24,13 +24,11 @@
#include <stdlib.h>
#include <string.h>
#include <gmodule.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "libgimp/gimpcolorselector.h"
#include "gui-types.h"
@ -54,39 +52,6 @@ typedef enum
} ColorNotebookUpdateType;
/* "class" information we keep on each registered color selector */
typedef struct _ColorSelectorInfo ColorSelectorInfo;
struct _ColorSelectorInfo
{
gchar *name; /* label used in notebook tab */
gchar *help_page;
GimpColorSelectorMethods methods;
gint refs; /* number of instances around */
gboolean active;
GimpColorSelectorFinishedCB death_callback;
gpointer death_data;
ColorSelectorInfo *next;
};
/* "instance" information we keep on each notebook tab */
typedef struct _ColorSelectorInstance ColorSelectorInstance;
struct _ColorSelectorInstance
{
ColorNotebook *color_notebook;
ColorSelectorInfo *info;
GtkWidget *frame; /* main widget */
gpointer selector_data;
ColorSelectorInstance *next;
};
struct _ColorNotebook
{
GtkWidget *shell;
@ -105,7 +70,7 @@ struct _ColorNotebook
GimpRGB orig_rgb;
GimpColorSelectorChannelType active_channel;
GimpColorSelectorChannel active_channel;
ColorNotebookCallback callback;
gpointer client_data;
@ -113,8 +78,8 @@ struct _ColorNotebook
gboolean wants_updates;
gboolean show_alpha;
ColorSelectorInstance *selectors;
ColorSelectorInstance *cur_page;
GList *selectors;
GimpColorSelector *cur_page;
};
@ -131,22 +96,21 @@ static ColorNotebook *
gboolean show_alpha);
static void color_notebook_ok_callback (GtkWidget *widget,
gpointer data);
ColorNotebook *cnp);
static void color_notebook_cancel_callback (GtkWidget *widget,
gpointer data);
ColorNotebook *cnp);
static void color_notebook_reset_callback (GtkWidget *widget,
gpointer data);
static void color_notebook_update_callback (gpointer data,
ColorNotebook *cnp);
static void color_notebook_update_callback (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv,
const GimpRGB *rgb);
ColorNotebook *cnp);
static void color_notebook_page_switch (GtkWidget *widget,
GtkNotebookPage *page,
guint page_num,
gpointer data);
ColorNotebook *cnp);
static void color_notebook_help_func (const gchar *help_data);
static void color_notebook_selector_death (ColorSelectorInfo *info);
static void color_notebook_set_white (ColorNotebook *cnp);
static void color_notebook_set_black (ColorNotebook *cnp);
static void color_notebook_color_changed (GtkWidget *widget,
@ -180,10 +144,7 @@ static void color_history_add_clicked (GtkWidget *widget,
gpointer data);
/* master list of all registered colour selectors */
static ColorSelectorInfo *selector_info = NULL;
static GList *color_notebooks = NULL;
static GList *color_notebooks = NULL;
static GimpRGB color_history[COLOR_HISTORY_SIZE];
static gboolean color_history_initialized = FALSE;
@ -278,8 +239,8 @@ color_notebook_new_internal (GimpViewable *viewable,
GSList *group;
guchar r, g, b;
gchar buffer[8];
ColorSelectorInfo *info;
ColorSelectorInstance *csel;
GType *selector_types;
gint n_selector_types;
gint i;
static gchar *toggle_titles[] =
@ -313,7 +274,6 @@ color_notebook_new_internal (GimpViewable *viewable,
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 100 };
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 10 };
g_return_val_if_fail (selector_info != NULL, NULL);
g_return_val_if_fail (color != NULL, NULL);
if (! color_history_initialized)
@ -401,8 +361,10 @@ color_notebook_new_internal (GimpViewable *viewable,
gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0);
gtk_widget_show (right_vbox);
selector_types = g_type_children (GIMP_TYPE_COLOR_SELECTOR, &n_selector_types);
/* do we actually need a notebook? */
if (selector_info->next)
if (n_selector_types > 1)
{
cnp->notebook = gtk_notebook_new ();
gtk_box_pack_start (GTK_BOX (left_vbox), cnp->notebook,
@ -415,53 +377,43 @@ color_notebook_new_internal (GimpViewable *viewable,
}
/* create each registered color selector */
info = selector_info;
while (info)
for (i = 0; i < n_selector_types; i++)
{
if (info->active)
{
csel = g_new (ColorSelectorInstance, 1);
csel->color_notebook = cnp;
csel->info = info;
info->refs++;
csel->frame =
info->methods.new (&cnp->hsv,
&cnp->rgb,
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
g_object_set_data (G_OBJECT (csel->frame), "gimp_color_notebook",
csel);
GtkWidget *selector;
if (cnp->notebook)
{
label = gtk_label_new (info->name);
gtk_widget_show (label);
/* hide the frame, so it doesn't get selected by mistake */
gtk_widget_hide (csel->frame);
gtk_notebook_append_page (GTK_NOTEBOOK (cnp->notebook),
csel->frame,
label);
}
else
{
gtk_box_pack_start (GTK_BOX (left_vbox), csel->frame,
TRUE, TRUE, 0);
}
selector = gimp_color_selector_new (selector_types[i],
&cnp->rgb,
&cnp->hsv);
gtk_widget_show (csel->frame);
if (! selector)
continue;
if (!cnp->cur_page)
cnp->cur_page = csel;
if (cnp->notebook)
{
label = gtk_label_new (GIMP_COLOR_SELECTOR_GET_CLASS (selector)->name);
/* link into list of all selectors hanging off the new notebook */
csel->next = cnp->selectors;
cnp->selectors = csel;
}
gtk_notebook_append_page (GTK_NOTEBOOK (cnp->notebook),
selector, label);
}
else
{
gtk_box_pack_start (GTK_BOX (left_vbox), selector, TRUE, TRUE, 0);
}
info = info->next;
if (! cnp->cur_page)
cnp->cur_page = GIMP_COLOR_SELECTOR (selector);
cnp->selectors = g_list_append (cnp->selectors, selector);
gtk_widget_show (selector);
g_signal_connect (G_OBJECT (selector), "color_changed",
G_CALLBACK (color_notebook_update_callback),
cnp);
}
g_free (selector_types);
/* The table for the color_areas */
table = gtk_table_new (2, 4, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 1);
@ -712,45 +664,27 @@ color_notebook_show (ColorNotebook *cnp)
{
g_return_if_fail (cnp != NULL);
if (! GTK_WIDGET_VISIBLE (cnp->shell))
gtk_widget_show (cnp->shell);
else
gdk_window_raise (cnp->shell->window);
gtk_window_present (GTK_WINDOW (cnp->shell));
}
void
color_notebook_hide (ColorNotebook *cnp)
{
g_return_if_fail (cnp != NULL);
gtk_widget_hide (cnp->shell);
}
void
color_notebook_free (ColorNotebook *cnp)
{
ColorSelectorInstance *csel, *next;
g_return_if_fail (cnp != NULL);
color_notebooks = g_list_remove (color_notebooks, cnp);
gtk_widget_destroy (cnp->shell);
/* call the free functions for all the color selectors */
csel = cnp->selectors;
while (csel)
{
next = csel->next;
csel->info->methods.free (csel->selector_data);
csel->info->refs--;
if (csel->info->refs == 0 && !csel->info->active)
color_notebook_selector_death (csel->info);
g_free (csel);
csel = next;
}
g_list_free (cnp->selectors);
g_free (cnp);
}
@ -835,20 +769,11 @@ color_notebook_color_changed (GtkWidget *widget,
* Called by a color selector on user selection of a color
*/
static void
color_notebook_update_callback (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
color_notebook_update_callback (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv,
ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
ColorNotebook *cnp;
g_return_if_fail (data != NULL);
g_return_if_fail (hsv != NULL);
g_return_if_fail (rgb != NULL);
csel = (ColorSelectorInstance *) data;
cnp = csel->color_notebook;
cnp->hsv = *hsv;
cnp->rgb = *rgb;
@ -860,13 +785,9 @@ color_notebook_update_callback (gpointer data,
}
static void
color_notebook_ok_callback (GtkWidget *widget,
gpointer data)
color_notebook_ok_callback (GtkWidget *widget,
ColorNotebook *cnp)
{
ColorNotebook *cnp;
cnp = (ColorNotebook *) data;
color_history_add_clicked (NULL, cnp);
if (cnp->callback)
@ -879,13 +800,9 @@ color_notebook_ok_callback (GtkWidget *widget,
}
static void
color_notebook_cancel_callback (GtkWidget *widget,
gpointer data)
color_notebook_cancel_callback (GtkWidget *widget,
ColorNotebook *cnp)
{
ColorNotebook *cnp;
cnp = (ColorNotebook *) data;
if (cnp->callback)
{
(* cnp->callback) (cnp,
@ -896,13 +813,9 @@ color_notebook_cancel_callback (GtkWidget *widget,
}
static void
color_notebook_reset_callback (GtkWidget *widget,
gpointer data)
color_notebook_reset_callback (GtkWidget *widget,
ColorNotebook *cnp)
{
ColorNotebook *cnp;
cnp = (ColorNotebook *) data;
cnp->rgb = cnp->orig_rgb;
color_notebook_update_hsv_values (cnp);
@ -918,28 +831,21 @@ static void
color_notebook_page_switch (GtkWidget *widget,
GtkNotebookPage *page,
guint page_num,
gpointer data)
ColorNotebook *cnp)
{
GtkWidget *page_widget;
ColorNotebook *cnp;
ColorSelectorInstance *csel;
gint i;
cnp = (ColorNotebook *) data;
GtkWidget *page_widget;
gboolean set_channel;
gint i;
page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (widget), page_num);
csel = g_object_get_data (G_OBJECT (page_widget), "gimp_color_notebook");
cnp->cur_page = GIMP_COLOR_SELECTOR (page_widget);
g_return_if_fail (cnp != NULL && csel != NULL);
cnp->cur_page = csel;
set_channel =
(GIMP_COLOR_SELECTOR_GET_CLASS (page_widget)->set_channel != NULL);
for (i = 0; i < 6; i++)
{
gtk_widget_set_sensitive (cnp->toggles[i],
csel->info->methods.set_channel != NULL);
}
gtk_widget_set_sensitive (cnp->toggles[i], set_channel);
color_notebook_update (cnp, UPDATE_CHANNEL | UPDATE_NOTEBOOK);
}
@ -953,106 +859,12 @@ color_notebook_help_func (const gchar *data)
cnp = (ColorNotebook *) data;
help_path = g_strconcat ("dialogs/color_selectors/",
cnp->cur_page->info->help_page,
GIMP_COLOR_SELECTOR_GET_CLASS (cnp->cur_page)->help_page,
NULL);
gimp_standard_help_func (help_path);
g_free (help_path);
}
/**************************/
/* Registration functions */
G_MODULE_EXPORT
GimpColorSelectorID
gimp_color_selector_register (const gchar *name,
const gchar *help_page,
GimpColorSelectorMethods *methods)
{
ColorSelectorInfo *info;
/* check the name is unique */
info = selector_info;
while (info)
{
if (!strcmp (info->name, name))
return NULL;
info = info->next;
}
info = g_new (ColorSelectorInfo, 1);
info->name = g_strdup (name);
info->help_page = g_strdup (help_page);
info->methods = *methods;
info->refs = 0;
info->active = TRUE;
info->next = selector_info;
selector_info = info;
return info;
}
G_MODULE_EXPORT
gboolean
gimp_color_selector_unregister (GimpColorSelectorID id,
GimpColorSelectorFinishedCB callback,
gpointer data)
{
ColorSelectorInfo *info;
info = selector_info;
while (info)
{
if (info == id)
{
info->active = FALSE;
info->death_callback = callback;
info->death_data = data;
if (info->refs == 0)
color_notebook_selector_death (info);
return TRUE;
}
info = info->next;
}
g_warning ("%s: unknown color selector ID %p", G_STRLOC, id);
return FALSE;
}
static void
color_notebook_selector_death (ColorSelectorInfo *info)
{
ColorSelectorInfo *here, *prev;
here = selector_info;
prev = NULL;
while (here)
{
if (here == info)
{
if (prev)
prev->next = info->next;
else
selector_info = info->next;
if (info->death_callback)
(*info->death_callback) (info->death_data);
g_free (info->name);
g_free (info);
return;
}
prev = here;
here = here->next;
}
g_warning ("%s: color selector %p not found.", G_STRLOC, info);
}
static void
color_notebook_update (ColorNotebook *cnp,
ColorNotebookUpdateType update)
@ -1079,30 +891,16 @@ color_notebook_update (ColorNotebook *cnp,
static void
color_notebook_update_notebook (ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
if (csel->info->methods.set_color)
csel->info->methods.set_color (csel->selector_data,
&cnp->hsv,
&cnp->rgb);
gimp_color_selector_set_color (cnp->cur_page,
&cnp->rgb,
&cnp->hsv);
}
static void
color_notebook_update_channel (ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
if (csel->info->methods.set_channel)
csel->info->methods.set_channel (csel->selector_data,
cnp->active_channel);
gimp_color_selector_set_channel (cnp->cur_page,
cnp->active_channel);
}
static void
@ -1237,7 +1035,7 @@ color_notebook_toggle_update (GtkWidget *widget,
for (i = 0; i < 6; i++)
if (widget == cnp->toggles[i])
cnp->active_channel = (GimpColorSelectorChannelType) i;
cnp->active_channel = (GimpColorSelectorChannel) i;
color_notebook_update (cnp, UPDATE_CHANNEL);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +0,0 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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.
*/
#ifndef __COLOR_SELECT_H__
#define __COLOR_SELECT_H__
void color_select_init (void);
#endif /* __COLOR_SELECT_H__ */

View File

@ -37,7 +37,6 @@
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-filter.h"
#include "display/gimpdisplayshell-render.h"
#include "widgets/gimpdevices.h"
@ -45,7 +44,6 @@
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpwidgets-utils.h"
#include "color-select.h"
#include "device-status-dialog.h"
#include "dialogs.h"
#include "dialogs-commands.h"
@ -118,6 +116,8 @@ gui_libs_init (gint *argc,
#endif
gimp_widgets_init ();
g_type_class_ref (GIMP_TYPE_COLOR_SELECT);
}
void
@ -226,8 +226,6 @@ gui_init (Gimp *gimp)
menus_init (gimp);
color_display_init ();
render_setup (gimprc.transparency_type, gimprc.transparency_size);
dialogs_init (gimp);
@ -249,8 +247,6 @@ gui_restore (Gimp *gimp,
menus_restore (gimp);
color_select_init ();
gimp_devices_restore (gimp);
if (gimprc.always_restore_session || restore_session)
@ -308,6 +304,8 @@ gui_exit (Gimp *gimp)
g_hash_table_destroy (themes_hash);
themes_hash = NULL;
}
g_type_class_unref (g_type_class_peek (GIMP_TYPE_COLOR_SELECT));
}
void

View File

@ -280,10 +280,11 @@ browser_load_unload_callback (GtkWidget *widget,
{
BrowserState *st = data;
if (st->last_update->state == GIMP_MODULE_STATE_LOADED_OK)
gimp_module_info_module_unload (st->last_update, FALSE);
else
gimp_module_info_module_load (st->last_update, FALSE);
if (st->last_update->state != GIMP_MODULE_STATE_LOADED_OK)
{
if (g_type_module_use (G_TYPE_MODULE (st->last_update)))
g_type_module_unuse (G_TYPE_MODULE (st->last_update));
}
gimp_module_info_modified (st->last_update);
}
@ -310,7 +311,7 @@ make_list_item (gpointer data,
gtk_list_store_append (st->list, &iter);
gtk_list_store_set (st->list, &iter,
PATH_COLUMN, info->fullpath,
PATH_COLUMN, info->filename,
INFO_COLUMN, info,
-1);
}
@ -444,8 +445,7 @@ browser_info_update (GimpModuleInfoObj *mod,
case GIMP_MODULE_STATE_LOADED_OK:
gtk_label_set_text (GTK_LABEL(st->button_label), _("Unload"));
gtk_widget_set_sensitive (GTK_WIDGET (st->button),
mod->unload ? TRUE : FALSE);
gtk_widget_set_sensitive (GTK_WIDGET (st->button), FALSE);
break;
}
}

View File

@ -24,13 +24,11 @@
#include <stdlib.h>
#include <string.h>
#include <gmodule.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "libgimp/gimpcolorselector.h"
#include "gui-types.h"
@ -54,39 +52,6 @@ typedef enum
} ColorNotebookUpdateType;
/* "class" information we keep on each registered color selector */
typedef struct _ColorSelectorInfo ColorSelectorInfo;
struct _ColorSelectorInfo
{
gchar *name; /* label used in notebook tab */
gchar *help_page;
GimpColorSelectorMethods methods;
gint refs; /* number of instances around */
gboolean active;
GimpColorSelectorFinishedCB death_callback;
gpointer death_data;
ColorSelectorInfo *next;
};
/* "instance" information we keep on each notebook tab */
typedef struct _ColorSelectorInstance ColorSelectorInstance;
struct _ColorSelectorInstance
{
ColorNotebook *color_notebook;
ColorSelectorInfo *info;
GtkWidget *frame; /* main widget */
gpointer selector_data;
ColorSelectorInstance *next;
};
struct _ColorNotebook
{
GtkWidget *shell;
@ -105,7 +70,7 @@ struct _ColorNotebook
GimpRGB orig_rgb;
GimpColorSelectorChannelType active_channel;
GimpColorSelectorChannel active_channel;
ColorNotebookCallback callback;
gpointer client_data;
@ -113,8 +78,8 @@ struct _ColorNotebook
gboolean wants_updates;
gboolean show_alpha;
ColorSelectorInstance *selectors;
ColorSelectorInstance *cur_page;
GList *selectors;
GimpColorSelector *cur_page;
};
@ -131,22 +96,21 @@ static ColorNotebook *
gboolean show_alpha);
static void color_notebook_ok_callback (GtkWidget *widget,
gpointer data);
ColorNotebook *cnp);
static void color_notebook_cancel_callback (GtkWidget *widget,
gpointer data);
ColorNotebook *cnp);
static void color_notebook_reset_callback (GtkWidget *widget,
gpointer data);
static void color_notebook_update_callback (gpointer data,
ColorNotebook *cnp);
static void color_notebook_update_callback (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv,
const GimpRGB *rgb);
ColorNotebook *cnp);
static void color_notebook_page_switch (GtkWidget *widget,
GtkNotebookPage *page,
guint page_num,
gpointer data);
ColorNotebook *cnp);
static void color_notebook_help_func (const gchar *help_data);
static void color_notebook_selector_death (ColorSelectorInfo *info);
static void color_notebook_set_white (ColorNotebook *cnp);
static void color_notebook_set_black (ColorNotebook *cnp);
static void color_notebook_color_changed (GtkWidget *widget,
@ -180,10 +144,7 @@ static void color_history_add_clicked (GtkWidget *widget,
gpointer data);
/* master list of all registered colour selectors */
static ColorSelectorInfo *selector_info = NULL;
static GList *color_notebooks = NULL;
static GList *color_notebooks = NULL;
static GimpRGB color_history[COLOR_HISTORY_SIZE];
static gboolean color_history_initialized = FALSE;
@ -278,8 +239,8 @@ color_notebook_new_internal (GimpViewable *viewable,
GSList *group;
guchar r, g, b;
gchar buffer[8];
ColorSelectorInfo *info;
ColorSelectorInstance *csel;
GType *selector_types;
gint n_selector_types;
gint i;
static gchar *toggle_titles[] =
@ -313,7 +274,6 @@ color_notebook_new_internal (GimpViewable *viewable,
static gdouble slider_max_vals[] = { 360, 100, 100, 255, 255, 255, 100 };
static gdouble slider_incs[] = { 30, 10, 10, 16, 16, 16, 10 };
g_return_val_if_fail (selector_info != NULL, NULL);
g_return_val_if_fail (color != NULL, NULL);
if (! color_history_initialized)
@ -401,8 +361,10 @@ color_notebook_new_internal (GimpViewable *viewable,
gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0);
gtk_widget_show (right_vbox);
selector_types = g_type_children (GIMP_TYPE_COLOR_SELECTOR, &n_selector_types);
/* do we actually need a notebook? */
if (selector_info->next)
if (n_selector_types > 1)
{
cnp->notebook = gtk_notebook_new ();
gtk_box_pack_start (GTK_BOX (left_vbox), cnp->notebook,
@ -415,53 +377,43 @@ color_notebook_new_internal (GimpViewable *viewable,
}
/* create each registered color selector */
info = selector_info;
while (info)
for (i = 0; i < n_selector_types; i++)
{
if (info->active)
{
csel = g_new (ColorSelectorInstance, 1);
csel->color_notebook = cnp;
csel->info = info;
info->refs++;
csel->frame =
info->methods.new (&cnp->hsv,
&cnp->rgb,
show_alpha,
color_notebook_update_callback, csel,
&csel->selector_data);
g_object_set_data (G_OBJECT (csel->frame), "gimp_color_notebook",
csel);
GtkWidget *selector;
if (cnp->notebook)
{
label = gtk_label_new (info->name);
gtk_widget_show (label);
/* hide the frame, so it doesn't get selected by mistake */
gtk_widget_hide (csel->frame);
gtk_notebook_append_page (GTK_NOTEBOOK (cnp->notebook),
csel->frame,
label);
}
else
{
gtk_box_pack_start (GTK_BOX (left_vbox), csel->frame,
TRUE, TRUE, 0);
}
selector = gimp_color_selector_new (selector_types[i],
&cnp->rgb,
&cnp->hsv);
gtk_widget_show (csel->frame);
if (! selector)
continue;
if (!cnp->cur_page)
cnp->cur_page = csel;
if (cnp->notebook)
{
label = gtk_label_new (GIMP_COLOR_SELECTOR_GET_CLASS (selector)->name);
/* link into list of all selectors hanging off the new notebook */
csel->next = cnp->selectors;
cnp->selectors = csel;
}
gtk_notebook_append_page (GTK_NOTEBOOK (cnp->notebook),
selector, label);
}
else
{
gtk_box_pack_start (GTK_BOX (left_vbox), selector, TRUE, TRUE, 0);
}
info = info->next;
if (! cnp->cur_page)
cnp->cur_page = GIMP_COLOR_SELECTOR (selector);
cnp->selectors = g_list_append (cnp->selectors, selector);
gtk_widget_show (selector);
g_signal_connect (G_OBJECT (selector), "color_changed",
G_CALLBACK (color_notebook_update_callback),
cnp);
}
g_free (selector_types);
/* The table for the color_areas */
table = gtk_table_new (2, 4, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 1);
@ -712,45 +664,27 @@ color_notebook_show (ColorNotebook *cnp)
{
g_return_if_fail (cnp != NULL);
if (! GTK_WIDGET_VISIBLE (cnp->shell))
gtk_widget_show (cnp->shell);
else
gdk_window_raise (cnp->shell->window);
gtk_window_present (GTK_WINDOW (cnp->shell));
}
void
color_notebook_hide (ColorNotebook *cnp)
{
g_return_if_fail (cnp != NULL);
gtk_widget_hide (cnp->shell);
}
void
color_notebook_free (ColorNotebook *cnp)
{
ColorSelectorInstance *csel, *next;
g_return_if_fail (cnp != NULL);
color_notebooks = g_list_remove (color_notebooks, cnp);
gtk_widget_destroy (cnp->shell);
/* call the free functions for all the color selectors */
csel = cnp->selectors;
while (csel)
{
next = csel->next;
csel->info->methods.free (csel->selector_data);
csel->info->refs--;
if (csel->info->refs == 0 && !csel->info->active)
color_notebook_selector_death (csel->info);
g_free (csel);
csel = next;
}
g_list_free (cnp->selectors);
g_free (cnp);
}
@ -835,20 +769,11 @@ color_notebook_color_changed (GtkWidget *widget,
* Called by a color selector on user selection of a color
*/
static void
color_notebook_update_callback (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
color_notebook_update_callback (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv,
ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
ColorNotebook *cnp;
g_return_if_fail (data != NULL);
g_return_if_fail (hsv != NULL);
g_return_if_fail (rgb != NULL);
csel = (ColorSelectorInstance *) data;
cnp = csel->color_notebook;
cnp->hsv = *hsv;
cnp->rgb = *rgb;
@ -860,13 +785,9 @@ color_notebook_update_callback (gpointer data,
}
static void
color_notebook_ok_callback (GtkWidget *widget,
gpointer data)
color_notebook_ok_callback (GtkWidget *widget,
ColorNotebook *cnp)
{
ColorNotebook *cnp;
cnp = (ColorNotebook *) data;
color_history_add_clicked (NULL, cnp);
if (cnp->callback)
@ -879,13 +800,9 @@ color_notebook_ok_callback (GtkWidget *widget,
}
static void
color_notebook_cancel_callback (GtkWidget *widget,
gpointer data)
color_notebook_cancel_callback (GtkWidget *widget,
ColorNotebook *cnp)
{
ColorNotebook *cnp;
cnp = (ColorNotebook *) data;
if (cnp->callback)
{
(* cnp->callback) (cnp,
@ -896,13 +813,9 @@ color_notebook_cancel_callback (GtkWidget *widget,
}
static void
color_notebook_reset_callback (GtkWidget *widget,
gpointer data)
color_notebook_reset_callback (GtkWidget *widget,
ColorNotebook *cnp)
{
ColorNotebook *cnp;
cnp = (ColorNotebook *) data;
cnp->rgb = cnp->orig_rgb;
color_notebook_update_hsv_values (cnp);
@ -918,28 +831,21 @@ static void
color_notebook_page_switch (GtkWidget *widget,
GtkNotebookPage *page,
guint page_num,
gpointer data)
ColorNotebook *cnp)
{
GtkWidget *page_widget;
ColorNotebook *cnp;
ColorSelectorInstance *csel;
gint i;
cnp = (ColorNotebook *) data;
GtkWidget *page_widget;
gboolean set_channel;
gint i;
page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (widget), page_num);
csel = g_object_get_data (G_OBJECT (page_widget), "gimp_color_notebook");
cnp->cur_page = GIMP_COLOR_SELECTOR (page_widget);
g_return_if_fail (cnp != NULL && csel != NULL);
cnp->cur_page = csel;
set_channel =
(GIMP_COLOR_SELECTOR_GET_CLASS (page_widget)->set_channel != NULL);
for (i = 0; i < 6; i++)
{
gtk_widget_set_sensitive (cnp->toggles[i],
csel->info->methods.set_channel != NULL);
}
gtk_widget_set_sensitive (cnp->toggles[i], set_channel);
color_notebook_update (cnp, UPDATE_CHANNEL | UPDATE_NOTEBOOK);
}
@ -953,106 +859,12 @@ color_notebook_help_func (const gchar *data)
cnp = (ColorNotebook *) data;
help_path = g_strconcat ("dialogs/color_selectors/",
cnp->cur_page->info->help_page,
GIMP_COLOR_SELECTOR_GET_CLASS (cnp->cur_page)->help_page,
NULL);
gimp_standard_help_func (help_path);
g_free (help_path);
}
/**************************/
/* Registration functions */
G_MODULE_EXPORT
GimpColorSelectorID
gimp_color_selector_register (const gchar *name,
const gchar *help_page,
GimpColorSelectorMethods *methods)
{
ColorSelectorInfo *info;
/* check the name is unique */
info = selector_info;
while (info)
{
if (!strcmp (info->name, name))
return NULL;
info = info->next;
}
info = g_new (ColorSelectorInfo, 1);
info->name = g_strdup (name);
info->help_page = g_strdup (help_page);
info->methods = *methods;
info->refs = 0;
info->active = TRUE;
info->next = selector_info;
selector_info = info;
return info;
}
G_MODULE_EXPORT
gboolean
gimp_color_selector_unregister (GimpColorSelectorID id,
GimpColorSelectorFinishedCB callback,
gpointer data)
{
ColorSelectorInfo *info;
info = selector_info;
while (info)
{
if (info == id)
{
info->active = FALSE;
info->death_callback = callback;
info->death_data = data;
if (info->refs == 0)
color_notebook_selector_death (info);
return TRUE;
}
info = info->next;
}
g_warning ("%s: unknown color selector ID %p", G_STRLOC, id);
return FALSE;
}
static void
color_notebook_selector_death (ColorSelectorInfo *info)
{
ColorSelectorInfo *here, *prev;
here = selector_info;
prev = NULL;
while (here)
{
if (here == info)
{
if (prev)
prev->next = info->next;
else
selector_info = info->next;
if (info->death_callback)
(*info->death_callback) (info->death_data);
g_free (info->name);
g_free (info);
return;
}
prev = here;
here = here->next;
}
g_warning ("%s: color selector %p not found.", G_STRLOC, info);
}
static void
color_notebook_update (ColorNotebook *cnp,
ColorNotebookUpdateType update)
@ -1079,30 +891,16 @@ color_notebook_update (ColorNotebook *cnp,
static void
color_notebook_update_notebook (ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
if (csel->info->methods.set_color)
csel->info->methods.set_color (csel->selector_data,
&cnp->hsv,
&cnp->rgb);
gimp_color_selector_set_color (cnp->cur_page,
&cnp->rgb,
&cnp->hsv);
}
static void
color_notebook_update_channel (ColorNotebook *cnp)
{
ColorSelectorInstance *csel;
g_return_if_fail (cnp != NULL);
csel = cnp->cur_page;
if (csel->info->methods.set_channel)
csel->info->methods.set_channel (csel->selector_data,
cnp->active_channel);
gimp_color_selector_set_channel (cnp->cur_page,
cnp->active_channel);
}
static void
@ -1237,7 +1035,7 @@ color_notebook_toggle_update (GtkWidget *widget,
for (i = 0; i < 6; i++)
if (widget == cnp->toggles[i])
cnp->active_channel = (GimpColorSelectorChannelType) i;
cnp->active_channel = (GimpColorSelectorChannel) i;
color_notebook_update (cnp, UPDATE_CHANNEL);
}

View File

@ -91,8 +91,6 @@ static void color_display_down_callback (GtkWidget *widget,
static void color_display_configure_callback (GtkWidget *widget,
ColorDisplayDialog *cdd);
static void src_list_populate (const char *name,
GtkTreeStore *src);
static void dest_list_populate (GList *node_list,
GtkTreeStore *dest);
@ -142,7 +140,7 @@ make_dialog (ColorDisplayDialog *cdd)
gtk_box_pack_start (GTK_BOX (hbox), scrolled_win, TRUE, TRUE, 0);
gtk_widget_show (scrolled_win);
cdd->src = gtk_tree_store_new (1, G_TYPE_STRING);
cdd->src = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (cdd->src));
g_object_unref (G_OBJECT (cdd->src));
@ -357,10 +355,10 @@ color_display_add_callback (GtkWidget *widget,
ColorDisplayNode *node;
GValue val = { 0, };
gtk_tree_model_get_value (model, &iter, 0, &val);
gtk_tree_model_get_value (model, &iter, 1, &val);
node = gimp_display_shell_filter_attach (cdd->shell,
g_value_get_string (&val));
(GType) g_value_get_pointer (&val));
g_value_unset (&val);
@ -527,12 +525,34 @@ void
gimp_display_shell_filter_dialog_new (GimpDisplayShell *shell)
{
ColorDisplayDialog *cdd;
GType *filter_types;
gint n_filter_types;
gint i;
cdd = g_new0 (ColorDisplayDialog, 1);
make_dialog (cdd);
color_display_foreach ((GimpCDFunc) src_list_populate, cdd->src);
filter_types = g_type_children (GIMP_TYPE_COLOR_DISPLAY, &n_filter_types);
for (i = 0; i < n_filter_types; i++)
{
GimpColorDisplayClass *filter_class;
GtkTreeIter iter;
filter_class = g_type_class_ref (filter_types[i]);
gtk_tree_store_append (cdd->src, &iter, NULL);
gtk_tree_store_set (cdd->src, &iter,
0, filter_class->name,
1, filter_types[i],
-1);
g_type_class_unref (filter_class);
}
g_free (filter_types);
cdd->old_nodes = shell->filters;
dest_list_populate (shell->filters, cdd->dest);
@ -543,19 +563,6 @@ gimp_display_shell_filter_dialog_new (GimpDisplayShell *shell)
shell->filters_dialog = cdd->dialog;
}
static void
src_list_populate (const char *name,
GtkTreeStore *src)
{
GtkTreeIter iter;
gtk_tree_store_append (src, &iter, NULL);
gtk_tree_store_set (src, &iter,
0, name,
-1);
}
static void
dest_list_populate (GList *node_list,
GtkTreeStore *dest)

View File

@ -20,138 +20,3 @@ color selector module.
#libgimp-gimpmodule
</para>
<!-- ##### USER_FUNCTION GimpColorSelectorCallback ##### -->
<para>
</para>
@data:
@hsv:
@rgb:
<!-- ##### USER_FUNCTION GimpColorSelectorNewFunc ##### -->
<para>
</para>
@hsv:
@rgb:
@show_alpha:
@cb:
@data:
@selector_data:
@Returns:
<!-- ##### USER_FUNCTION GimpColorSelectorFreeFunc ##### -->
<para>
</para>
@selector_data:
<!-- ##### USER_FUNCTION GimpColorSelectorSetColorFunc ##### -->
<para>
</para>
@selector_data:
@hsv:
@rgb:
<!-- ##### USER_FUNCTION GimpColorSelectorSetChannelFunc ##### -->
<para>
</para>
@selector_data:
@type:
<!-- ##### STRUCT GimpColorSelectorMethods ##### -->
<para>
</para>
@new:
@free:
@set_color:
@set_channel:
<!-- ##### TYPEDEF GimpColorSelectorID ##### -->
<para>
</para>
<!-- ##### ENUM GimpColorSelectorChannelType ##### -->
<para>
</para>
@GIMP_COLOR_SELECTOR_HUE:
@GIMP_COLOR_SELECTOR_SATURATION:
@GIMP_COLOR_SELECTOR_VALUE:
@GIMP_COLOR_SELECTOR_RED:
@GIMP_COLOR_SELECTOR_GREEN:
@GIMP_COLOR_SELECTOR_BLUE:
@GIMP_COLOR_SELECTOR_ALPHA:
<!-- ##### USER_FUNCTION GimpColorSelectorFinishedCB ##### -->
<para>
A function of this type will be called once all instances of a color
selector have finished after the selector module called
gimp_color_selector_unregister().
</para>
@finished_data: The @finished_data as specified in gimp_color_selector_register().
<!-- ##### MACRO GIMP_COLOR_SELECTOR_SIZE ##### -->
<para>
</para>
<!-- ##### MACRO GIMP_COLOR_SELECTOR_BAR_SIZE ##### -->
<para>
</para>
<!-- ##### FUNCTION gimp_color_selector_register ##### -->
<para>
Register a color selector. Returns an identifier for the color
selector on success, or #NULL if the name is already in use. Both
the @name and @methods table are internalised, so may be g_free()'d after
this call.
</para>
@name: The color selector's name.
@help_page: The help page.
@methods: The color selector's methods.
@Returns: The #GimpColorSelectorID of the new color selector.
<!-- ##### FUNCTION gimp_color_selector_unregister ##### -->
<para>
Remove the selector @id from active service. New instances of the
selector will not be created, but existing ones are allowed to
continue. If @finished_cb is non-#NULL, it will be called once all
instances have finished. The callback could be used to unload
dynamiclly loaded code, for example.
</para>
@selector_id:
@finished_cb: Optional callback which will be called once all instances have finished.
@finished_data: The @finished_data which will be passed to @finished_cb.
@Returns: #TRUE on success, #FALSE if @id was not found.
<!-- # Unused Parameters # -->
@id: The @id as returned by gimp_color_selector_register().

View File

@ -15,77 +15,14 @@ Common definitions for creating a pluggable GIMP module.
#GModule
</para>
<!-- ##### ENUM GimpModuleStatus ##### -->
<para>
</para>
@GIMP_MODULE_OK:
@GIMP_MODULE_UNLOAD:
<!-- ##### STRUCT GimpModuleInfo ##### -->
<para>
</para>
@shutdown_data:
@purpose:
@author:
@version:
@copyright:
@date:
<!-- ##### USER_FUNCTION GimpModuleInitFunc ##### -->
<para>
GIMP modules should #G_MODULE_EXPORT a function named "module_init"
of this type.
</para>
<para>
The "module_init" function is called by the GIMP at startup,
and should return either #GIMP_MODULE_OK if it sucessfully initialised or
#GIMP_MODULE_UNLOAD if the module failed to hook whatever functions
it wanted. #GIMP_MODULE_UNLOAD causes the module to be closed, so
the module must not have registered any internal functions or given
out pointers to its data to anyone.
</para>
<para>
If the module returns #GIMP_MODULE_OK, it should also return a
#GimpModuleInfo structure describing itself.
</para>
@module_info: Returns the #GimpModuleInfo desribing the module.
@Returns: A #GimpModuleStatus value indicating success.
<!-- ##### USER_FUNCTION GimpModuleCompletedCB ##### -->
<para>
The type of the @completed_cb passed to the "module_unload" function
(see below).
</para>
@completed_data: Must be the @completed_data pointer provided by the
"module_unload" function.
<!-- ##### USER_FUNCTION GimpModuleUnloadFunc ##### -->
<para>
If GIMP modules want to allow themselves to be unloaded, they
should #G_MODULE_EXPORT a function named "module_unload" of
this type.
</para>
<para>
GIMP calls the "module_unload" unload request function to ask
a module to prepare itself to be unloaded. It is called with the
value of @shutdown_data supplied in the #GimpModuleInfo struct.
The module should ensure that none of its code or data are being
used, and then call the supplied @completed_cb callback function with
the @completed_data provided. Typically the shutdown request function
will queue de-registration activities then return. Only when the
de-registration has finished should the @completed_cb be invoked.
</para>
@shutdown_data: The @shutdown_data supplied in the #GimpModuleInfo struct.
@completed_cb: The function to call after successful unload.
@completed_data: Has to be passed to the @completed_cb.

View File

@ -139,8 +139,6 @@ libgimpui_1_3_la_SOURCES = \
gimpexport.h
gimpinclude_HEADERS = \
gimpcolordisplay.h \
gimpcolorselector.h \
gimp.h \
gimpcompat.h \
gimptypes.h \

View File

@ -1,83 +0,0 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1999 Manish Singh <yosh@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser 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.
*/
#ifndef __GIMP_COLOR_DISPLAY_H__
#define __GIMP_COLOR_DISPLAY_H__
#include <glib.h>
#include <gmodule.h>
#include <libgimpbase/gimpparasite.h>
G_BEGIN_DECLS
/* For information look at the html documentation */
typedef void (* GimpColorDisplayInit) (void);
typedef gpointer (* GimpColorDisplayNew) (gint type);
typedef gpointer (* GimpColorDisplayClone) (gpointer cd_ID);
typedef void (* GimpColorDisplayConvert) (gpointer cd_ID,
guchar *buf,
gint width,
gint height,
gint bpp,
gint bpl);
typedef void (* GimpColorDisplayDestroy) (gpointer cd_ID);
typedef void (* GimpColorDisplayFinalize) (void);
typedef void (* GimpColorDisplayLoadState) (gpointer cd_ID,
GimpParasite *state);
typedef GimpParasite * (* GimpColorDisplaySaveState) (gpointer cd_ID);
typedef void (* GimpColorDisplayConfigure) (gpointer cd_ID,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data);
typedef void (* GimpColorDisplayConfigureCancel) (gpointer cd_ID);
typedef struct _GimpColorDisplayMethods GimpColorDisplayMethods;
struct _GimpColorDisplayMethods
{
GimpColorDisplayInit init;
GimpColorDisplayNew new;
GimpColorDisplayClone clone;
GimpColorDisplayConvert convert;
GimpColorDisplayDestroy destroy;
GimpColorDisplayFinalize finalize;
GimpColorDisplayLoadState load;
GimpColorDisplaySaveState save;
GimpColorDisplayConfigure configure;
GimpColorDisplayConfigureCancel cancel;
};
/* The following two functions are implemted and exported by gimp/app
* but need to be marked for it here too ...
*/
G_MODULE_EXPORT
gboolean gimp_color_display_register (const gchar *name,
GimpColorDisplayMethods *methods);
G_MODULE_EXPORT
gboolean gimp_color_display_unregister (const gchar *name);
G_END_DECLS
#endif /* __GIMP_COLOR_DISPLAY_H__ */

View File

@ -1,99 +0,0 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* Colour selector module (C) 1999 Austin Donnelly <austin@greenend.org.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser 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.
*/
#ifndef __COLOR_SELECTOR_H__
#define __COLOR_SELECTOR_H__
G_BEGIN_DECLS
/* For information look at the html documentation */
#define GIMP_COLOR_SELECTOR_SIZE 150
#define GIMP_COLOR_SELECTOR_BAR_SIZE 15
typedef enum
{
GIMP_COLOR_SELECTOR_HUE,
GIMP_COLOR_SELECTOR_SATURATION,
GIMP_COLOR_SELECTOR_VALUE,
GIMP_COLOR_SELECTOR_RED,
GIMP_COLOR_SELECTOR_GREEN,
GIMP_COLOR_SELECTOR_BLUE,
GIMP_COLOR_SELECTOR_ALPHA
} GimpColorSelectorChannelType;
typedef void (* GimpColorSelectorCallback) (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb);
typedef GtkWidget * (* GimpColorSelectorNewFunc) (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback cb,
gpointer data,
gpointer *selector_data);
typedef void (* GimpColorSelectorFreeFunc) (gpointer selector_data);
typedef void (* GimpColorSelectorSetColorFunc) (gpointer selector_data,
const GimpHSV *hsv,
const GimpRGB *rgb);
typedef void (* GimpColorSelectorSetChannelFunc) (gpointer selector_data,
GimpColorSelectorChannelType type);
typedef void (* GimpColorSelectorFinishedCB) (gpointer finished_data);
typedef struct _GimpColorSelectorMethods GimpColorSelectorMethods;
struct _GimpColorSelectorMethods
{
GimpColorSelectorNewFunc new;
GimpColorSelectorFreeFunc free;
GimpColorSelectorSetColorFunc set_color;
GimpColorSelectorSetChannelFunc set_channel;
};
typedef gpointer GimpColorSelectorID;
#include <gmodule.h>
G_MODULE_EXPORT
GimpColorSelectorID
gimp_color_selector_register (const gchar *name,
const gchar *help_page,
GimpColorSelectorMethods *methods);
G_MODULE_EXPORT
gboolean
gimp_color_selector_unregister (GimpColorSelectorID selector_id,
GimpColorSelectorFinishedCB finished_cb,
gpointer finished_data);
G_END_DECLS
#endif /* __COLOR_SELECTOR_H__ */

View File

@ -18,8 +18,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMPMODULE_H__
#define __GIMPMODULE_H__
#ifndef __GIMP_MODULE_H__
#define __GIMP_MODULE_H__
#include <gmodule.h>
@ -28,19 +28,10 @@ G_BEGIN_DECLS
/* For information look at the html documentation */
typedef enum
{
GIMP_MODULE_OK,
GIMP_MODULE_UNLOAD
} GimpModuleStatus;
typedef struct _GimpModuleInfo GimpModuleInfo;
struct _GimpModuleInfo
{
gpointer shutdown_data;
const gchar *purpose;
const gchar *author;
const gchar *version;
@ -49,40 +40,10 @@ struct _GimpModuleInfo
};
/* Module initialization */
typedef GimpModuleStatus (* GimpModuleInitFunc) (GimpModuleInfo **module_info);
#ifndef MODULE_COMPILATION
/* On Win32 this declaration clashes with the definition
* (which uses G_MODULE_EXPORT) and thus should be bypassed
* when compiling the module itself.
*/
GimpModuleInitFunc module_init;
#endif /* ! MODULE_COMPILATION */
/* Module unload */
typedef void (* GimpModuleCompletedCB) (gpointer completed_data);
typedef void (* GimpModuleUnloadFunc) (gpointer shutdown_data,
GimpModuleCompletedCB completed_cb,
gpointer completed_data);
#ifndef MODULE_COMPILATION
/* The same as for module_init.
*/
GimpModuleUnloadFunc module_unload;
#endif /* ! MODULE_COMPILATION */
typedef gboolean (* GimpModuleRegisterFunc) (GTypeModule *module,
GimpModuleInfo **module_info);
G_END_DECLS
#endif /* __GIMPMODULE_H__ */
#endif /* __GIMP_MODULE_H__ */

View File

@ -42,17 +42,21 @@ enum
};
static void gimp_module_info_class_init (GimpModuleInfoObjClass *klass);
static void gimp_module_info_init (GimpModuleInfoObj *mod);
static void gimp_module_info_class_init (GimpModuleInfoObjClass *klass);
static void gimp_module_info_init (GimpModuleInfoObj *mod);
static void gimp_module_info_finalize (GObject *object);
static void gimp_module_info_finalize (GObject *object);
static gsize gimp_module_info_get_memsize (GimpObject *object);
static gboolean gimp_module_info_load (GTypeModule *module);
static void gimp_module_info_unload (GTypeModule *module);
static void gimp_module_info_set_last_error (GimpModuleInfoObj *module_info,
const gchar *error_str);
static guint module_info_signals[LAST_SIGNAL];
static GimpObjectClass *parent_class = NULL;
static GTypeModuleClass *parent_class = NULL;
GType
@ -75,7 +79,7 @@ gimp_module_info_get_type (void)
(GInstanceInitFunc) gimp_module_info_init,
};
module_info_type = g_type_register_static (GIMP_TYPE_OBJECT,
module_info_type = g_type_register_static (G_TYPE_TYPE_MODULE,
"GimpModuleInfoObj",
&module_info_info, 0);
}
@ -86,11 +90,11 @@ gimp_module_info_get_type (void)
static void
gimp_module_info_class_init (GimpModuleInfoObjClass *klass)
{
GObjectClass *object_class;
GimpObjectClass *gimp_object_class;
GObjectClass *object_class;
GTypeModuleClass *module_class;
object_class = G_OBJECT_CLASS (klass);
gimp_object_class = GIMP_OBJECT_CLASS (klass);
object_class = G_OBJECT_CLASS (klass);
module_class = G_TYPE_MODULE_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
@ -103,27 +107,28 @@ gimp_module_info_class_init (GimpModuleInfoObjClass *klass)
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->finalize = gimp_module_info_finalize;
object_class->finalize = gimp_module_info_finalize;
gimp_object_class->get_memsize = gimp_module_info_get_memsize;
module_class->load = gimp_module_info_load;
module_class->unload = gimp_module_info_unload;
klass->modified = NULL;
klass->modified = NULL;
}
static void
gimp_module_info_init (GimpModuleInfoObj *module_info)
{
module_info->fullpath = NULL;
module_info->filename = NULL;
module_info->verbose = FALSE;
module_info->state = GIMP_MODULE_STATE_ERROR;
module_info->on_disk = FALSE;
module_info->load_inhibit = FALSE;
module_info->refs = 0;
module_info->info = NULL;
module_info->module = NULL;
module_info->info = NULL;
module_info->last_module_error = NULL;
module_info->init = NULL;
module_info->unload = NULL;
module_info->register_module = NULL;
}
static void
@ -133,40 +138,103 @@ gimp_module_info_finalize (GObject *object)
mod = GIMP_MODULE_INFO (object);
/* if this trips, then we're onto some serious lossage in a moment */
g_return_if_fail (mod->refs == 0);
if (mod->last_module_error)
{
g_free (mod->last_module_error);
mod->last_module_error = NULL;
}
if (mod->fullpath)
if (mod->filename)
{
g_free (mod->fullpath);
mod->fullpath = NULL;
g_free (mod->filename);
mod->filename = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gsize
gimp_module_info_get_memsize (GimpObject *object)
static gboolean
gimp_module_info_load (GTypeModule *module)
{
GimpModuleInfoObj *module_info;
gsize memsize = 0;
gpointer symbol;
gboolean retval;
module_info = GIMP_MODULE_INFO (object);
g_return_val_if_fail (GIMP_IS_MODULE_INFO (module), FALSE);
if (module_info->fullpath)
memsize += strlen (module_info->fullpath) + 1;
module_info = GIMP_MODULE_INFO (module);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
g_return_val_if_fail (module_info->filename != NULL, FALSE);
g_return_val_if_fail (module_info->module == NULL, FALSE);
if (module_info->verbose)
g_print (_("loading module: '%s'\n"), module_info->filename);
module_info->module = g_module_open (module_info->filename,
G_MODULE_BIND_LAZY);
if (! module_info->module)
{
module_info->state = GIMP_MODULE_STATE_ERROR;
gimp_module_info_set_last_error (module_info, g_module_error ());
if (module_info->verbose)
g_message (_("Module '%s' load error:\n%s"),
module_info->filename, module_info->last_module_error);
return FALSE;
}
/* find the module_init symbol */
if (! g_module_symbol (module_info->module, "gimp_module_register", &symbol))
{
module_info->state = GIMP_MODULE_STATE_ERROR;
gimp_module_info_set_last_error (module_info,
_("Missing gimp_module_register() symbol"));
if (module_info->verbose)
g_message (_("Module '%s' load error:\n%s"),
module_info->filename, module_info->last_module_error);
g_module_close (module_info->module);
module_info->module = NULL;
return FALSE;
}
module_info->register_module = symbol;
retval = module_info->register_module (module, &module_info->info);
if (retval)
module_info->state = GIMP_MODULE_STATE_LOADED_OK;
else
module_info->state = GIMP_MODULE_STATE_LOAD_FAILED;
return retval;
}
static void
gimp_module_info_unload (GTypeModule *module)
{
GimpModuleInfoObj *module_info;
g_return_if_fail (GIMP_IS_MODULE_INFO (module));
module_info = GIMP_MODULE_INFO (module);
g_return_if_fail (module_info->module != NULL);
g_module_close (module_info->module); /* FIXME: error handling */
module_info->module = NULL;
module_info->info = NULL;
module_info->register_module = NULL;
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
}
GimpModuleInfoObj *
gimp_module_info_new (const gchar *filename)
gimp_module_info_new (const gchar *filename,
const gchar *inhibit_list,
gboolean verbose)
{
GimpModuleInfoObj *module_info;
@ -174,9 +242,25 @@ gimp_module_info_new (const gchar *filename)
module_info = g_object_new (GIMP_TYPE_MODULE_INFO, NULL);
module_info->fullpath = g_strdup (filename);
module_info->filename = g_strdup (filename);
module_info->verbose = verbose ? TRUE : FALSE;
module_info->on_disk = TRUE;
gimp_module_info_set_load_inhibit (module_info, inhibit_list);
if (! module_info->load_inhibit)
{
if (gimp_module_info_load (G_TYPE_MODULE (module_info)))
gimp_module_info_unload (G_TYPE_MODULE (module_info));
}
else
{
if (verbose)
g_print (_("skipping module: '%s'\n"), filename);
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
}
return module_info;
}
@ -198,14 +282,14 @@ gimp_module_info_set_load_inhibit (GimpModuleInfoObj *module_info,
const gchar *end;
g_return_if_fail (GIMP_IS_MODULE_INFO (module_info));
g_return_if_fail (module_info->fullpath != NULL);
g_return_if_fail (module_info->filename != NULL);
module_info->load_inhibit = FALSE;
if (! inhibit_list || ! strlen (inhibit_list))
return;
p = strstr (inhibit_list, module_info->fullpath);
p = strstr (inhibit_list, module_info->filename);
if (!p)
return;
@ -221,7 +305,7 @@ gimp_module_info_set_load_inhibit (GimpModuleInfoObj *module_info,
if (! end)
end = inhibit_list + strlen (inhibit_list);
pathlen = strlen (module_info->fullpath);
pathlen = strlen (module_info->filename);
if ((end - start) == pathlen)
module_info->load_inhibit = TRUE;
@ -236,185 +320,3 @@ gimp_module_info_set_last_error (GimpModuleInfoObj *module_info,
module_info->last_module_error = g_strdup (error_str);
}
/*
* FIXME: currently this will fail badly on EMX
*/
#ifdef __EMX__
extern void gimp_color_selector_register (void);
extern void gimp_color_selector_unregister (void);
extern void dialog_register (void);
extern void dialog_unregister (void);
static struct main_funcs_struc
{
gchar *name;
void (* func) (void);
}
gimp_main_funcs[] =
{
{ "gimp_color_selector_register", gimp_color_selector_register },
{ "gimp_color_selector_unregister", gimp_color_selector_unregister },
{ "dialog_register", dialog_register },
{ "dialog_unregister", dialog_unregister },
{ NULL, NULL }
};
#endif
void
gimp_module_info_module_load (GimpModuleInfoObj *module_info,
gboolean verbose)
{
gpointer symbol;
g_return_if_fail (GIMP_IS_MODULE_INFO (module_info));
g_return_if_fail (module_info->fullpath != NULL);
g_return_if_fail (module_info->module == NULL);
module_info->module = g_module_open (module_info->fullpath,
G_MODULE_BIND_LAZY);
if (! module_info->module)
{
module_info->state = GIMP_MODULE_STATE_ERROR;
gimp_module_info_set_last_error (module_info, g_module_error ());
if (verbose)
g_message (_("Module '%s' load error:\n%s"),
module_info->fullpath, module_info->last_module_error);
return;
}
#ifdef __EMX__
if (g_module_symbol (module_info->module, "gimp_main_funcs", &symbol))
{
*(struct main_funcs_struc **) symbol = gimp_main_funcs;
}
#endif
/* find the module_init symbol */
if (! g_module_symbol (module_info->module, "module_init", &symbol))
{
module_info->state = GIMP_MODULE_STATE_ERROR;
gimp_module_info_set_last_error (module_info,
_("Missing module_init() symbol"));
if (verbose)
g_message (_("Module '%s' load error:\n%s"),
module_info->fullpath, module_info->last_module_error);
g_module_close (module_info->module);
module_info->module = NULL;
return;
}
module_info->init = symbol;
/* loaded modules are assumed to have a ref of 1 */
gimp_module_info_module_ref (module_info);
/* run module's initialisation */
if (module_info->init (&module_info->info) == GIMP_MODULE_UNLOAD)
{
module_info->state = GIMP_MODULE_STATE_LOAD_FAILED;
gimp_module_info_module_unref (module_info);
module_info->info = NULL;
return;
}
/* module is now happy */
module_info->state = GIMP_MODULE_STATE_LOADED_OK;
/* do we have an unload function? */
if (g_module_symbol (module_info->module, "module_unload", &symbol))
{
module_info->unload = symbol;
}
}
static void
gimp_module_info_module_unload_completed_callback (gpointer data)
{
GimpModuleInfoObj *module_info;
module_info = (GimpModuleInfoObj *) data;
g_return_if_fail (module_info->state == GIMP_MODULE_STATE_UNLOAD_REQUESTED);
/* lose the ref we gave this module when we loaded it,
* since the module's now happy to be unloaded.
*/
gimp_module_info_module_unref (module_info);
module_info->info = NULL;
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
gimp_module_info_modified (module_info);
}
static gboolean
gimp_module_info_module_idle_unref (gpointer data)
{
GimpModuleInfoObj *module_info;
module_info = (GimpModuleInfoObj *) data;
gimp_module_info_module_unref (module_info);
return FALSE;
}
void
gimp_module_info_module_unload (GimpModuleInfoObj *module_info,
gboolean verbose)
{
g_return_if_fail (GIMP_IS_MODULE_INFO (module_info));
g_return_if_fail (module_info->module != NULL);
g_return_if_fail (module_info->unload != NULL);
if (module_info->state == GIMP_MODULE_STATE_UNLOAD_REQUESTED)
return;
module_info->state = GIMP_MODULE_STATE_UNLOAD_REQUESTED;
/* Send the unload request. Need to ref the module so we don't
* accidentally unload it while this call is in progress (eg if the
* callback is called before the unload function returns).
*/
gimp_module_info_module_ref (module_info);
module_info->unload (module_info->info->shutdown_data,
gimp_module_info_module_unload_completed_callback,
module_info);
g_idle_add (gimp_module_info_module_idle_unref, module_info);
}
void
gimp_module_info_module_ref (GimpModuleInfoObj *module_info)
{
g_return_if_fail (GIMP_IS_MODULE_INFO (module_info));
g_return_if_fail (module_info->refs >= 0);
g_return_if_fail (module_info->module != NULL);
module_info->refs++;
}
void
gimp_module_info_module_unref (GimpModuleInfoObj *module_info)
{
g_return_if_fail (GIMP_IS_MODULE_INFO (module_info));
g_return_if_fail (module_info->refs > 0);
g_return_if_fail (module_info->module != NULL);
module_info->refs--;
if (module_info->refs == 0)
{
g_module_close (module_info->module);
module_info->module = NULL;
}
}

View File

@ -25,8 +25,6 @@
#include "libgimp/gimpmodule.h"
#include "gimpobject.h"
typedef enum
{
@ -50,34 +48,26 @@ typedef struct _GimpModuleInfoObjClass GimpModuleInfoObjClass;
struct _GimpModuleInfoObj
{
GimpObject parent_instance;
GTypeModule parent_instance;
gchar *fullpath; /* path to the module */
gchar *filename; /* path to the module */
gboolean verbose; /* verbose error reporting */
GimpModuleState state; /* what's happened to the module */
gboolean on_disk; /* TRUE if file still exists */
gboolean load_inhibit; /* user requests not to load at boot time */
/* Count of times main gimp is within the module. Normally, this
* will be 1, and we assume that the module won't call its
* unload callback until it is satisfied that it's not in use any
* more. refs can be 2 temporarily while we're running the module's
* unload function, to stop the module attempting to unload
* itself.
*/
gint refs;
/* stuff from now on may be NULL depending on the state the module is in */
GimpModuleInfo *info; /* returned values from module_init */
/* stuff from now on may be NULL depending on the state the module is in */
GModule *module; /* handle on the module */
GimpModuleInfo *info; /* returned values from module_register */
gchar *last_module_error;
GimpModuleInitFunc init;
GimpModuleUnloadFunc unload;
gboolean (* register_module) (GTypeModule *module,
GimpModuleInfo **module_info);
};
struct _GimpModuleInfoObjClass
{
GimpObjectClass parent_class;
GTypeModuleClass parent_class;
void (* modified) (GimpModuleInfoObj *module_info);
};
@ -85,18 +75,13 @@ struct _GimpModuleInfoObjClass
GType gimp_module_info_get_type (void) G_GNUC_CONST;
GimpModuleInfoObj * gimp_module_info_new (const gchar *filename);
GimpModuleInfoObj * gimp_module_info_new (const gchar *filename,
const gchar *inhibit_str,
gboolean verbose);
void gimp_module_info_modified (GimpModuleInfoObj *module);
void gimp_module_info_set_load_inhibit (GimpModuleInfoObj *module,
const gchar *inhibit_list);
void gimp_module_info_module_load (GimpModuleInfoObj *module_info,
gboolean verbose);
void gimp_module_info_module_unload (GimpModuleInfoObj *module_info,
gboolean verbose);
void gimp_module_info_module_ref (GimpModuleInfoObj *module_info);
void gimp_module_info_module_unref (GimpModuleInfoObj *module_info);
#endif /* __GIMP_MODULE_INFO_H__ */

View File

@ -47,6 +47,9 @@
#include "libgimp/gimpintl.h"
#define DUMP_DB 1
static void gimp_modules_module_initialize (const gchar *filename,
gpointer loader_data);
@ -60,8 +63,6 @@ static void print_module_info (gpointer data,
static gboolean gimp_modules_write_modulerc (Gimp *gimp);
static void gimp_modules_module_free_func (gpointer data,
gpointer user_data);
static void gimp_modules_module_on_disk_func (gpointer data,
gpointer user_data);
static void gimp_modules_module_remove_func (gpointer data,
@ -74,7 +75,7 @@ gimp_modules_init (Gimp *gimp)
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp->modules = gimp_list_new (GIMP_TYPE_MODULE_INFO,
GIMP_CONTAINER_POLICY_WEAK);
GIMP_CONTAINER_POLICY_STRONG);
gimp_object_set_name (GIMP_OBJECT (gimp->modules), "modules");
gimp->write_modulerc = FALSE;
@ -110,7 +111,7 @@ gimp_modules_load (Gimp *gimp)
gimp);
#ifdef DUMP_DB
gimp_container_foreach (modules, print_module_info, NULL);
gimp_container_foreach (gimp->modules, print_module_info, NULL);
#endif
}
@ -126,8 +127,6 @@ gimp_modules_unload (Gimp *gimp)
gimp->write_modulerc = FALSE;
}
}
gimp_container_foreach (gimp->modules, gimp_modules_module_free_func, NULL);
}
void
@ -153,20 +152,6 @@ gimp_modules_refresh (Gimp *gimp)
gimp);
}
static void
gimp_modules_module_free_func (gpointer data,
gpointer user_data)
{
GimpModuleInfoObj *module_info = data;
if (module_info->module &&
module_info->unload &&
module_info->state == GIMP_MODULE_STATE_LOADED_OK)
{
gimp_module_info_module_unload (module_info, FALSE);
}
}
static void
add_to_inhibit_string (gpointer data,
gpointer user_data)
@ -177,7 +162,7 @@ add_to_inhibit_string (gpointer data,
if (module_info->load_inhibit)
{
str = g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
str = g_string_append (str, module_info->fullpath);
str = g_string_append (str, module_info->filename);
}
}
@ -266,62 +251,29 @@ gimp_modules_module_initialize (const gchar *filename,
if (gimp_modules_module_find_by_path (gimp, filename))
return;
module_info = gimp_module_info_new (filename);
module_info = gimp_module_info_new (filename,
gimp->config->module_db_load_inhibit,
gimp->be_verbose);
gimp_module_info_set_load_inhibit (module_info,
gimp->config->module_db_load_inhibit);
if (! module_info->load_inhibit)
{
if (gimp->be_verbose)
g_print (_("loading module: '%s'\n"), filename);
gimp_module_info_module_load (module_info, TRUE);
}
else
{
if (gimp->be_verbose)
g_print (_("skipping module: '%s'\n"), filename);
module_info->state = GIMP_MODULE_STATE_UNLOADED_OK;
}
gimp_container_add (gimp->modules, GIMP_OBJECT (module_info));
}
typedef struct
{
const gchar *search_key;
GimpModuleInfoObj *found;
} find_by_path_closure;
static void
gimp_modules_module_path_cmp_func (gpointer data,
gpointer user_data)
{
GimpModuleInfoObj *module_info;
find_by_path_closure *closure;
module_info = (GimpModuleInfoObj *) data;
closure = (find_by_path_closure *) user_data;
if (! strcmp (module_info->fullpath, closure->search_key))
closure->found = module_info;
gimp_container_add (gimp->modules, (GimpObject *) module_info);
}
static GimpModuleInfoObj *
gimp_modules_module_find_by_path (Gimp *gimp,
const char *fullpath)
{
find_by_path_closure cl;
GimpModuleInfoObj *module_info;
GList *list;
cl.found = NULL;
cl.search_key = fullpath;
for (list = GIMP_LIST (gimp->modules)->list; list; list = g_list_next (list))
{
module_info = (GimpModuleInfoObj *) list->data;
gimp_container_foreach (gimp->modules,
gimp_modules_module_path_cmp_func, &cl);
if (! strcmp (module_info->filename, fullpath))
return module_info;
}
return cl.found;
return NULL;
}
#ifdef DUMP_DB
@ -331,22 +283,25 @@ print_module_info (gpointer data,
{
GimpModuleInfoObj *i = data;
g_print ("\n%s: %s\n",
i->fullpath, statename[i->state]);
g_print (" module:%p lasterr:%s init:%p unload:%p\n",
i->module, i->last_module_error? i->last_module_error : "NONE",
i->init, i->unload);
g_print ("\n%s: %i\n",
i->filename,
i->state /* statename[i->state] */);
g_print (" module:%p lasterr:%s register:%p\n",
i->module,
i->last_module_error? i->last_module_error : "NONE",
i->register_module);
if (i->info)
{
g_print (" shutdown_data: %p\n"
" purpose: %s\n"
g_print (" purpose: %s\n"
" author: %s\n"
" version: %s\n"
" copyright: %s\n"
" date: %s\n",
i->info->shutdown_data,
i->info->purpose, i->info->author, i->info->version,
i->info->copyright, i->info->date);
i->info->purpose,
i->info->author,
i->info->version,
i->info->copyright,
i->info->date);
}
}
#endif
@ -364,7 +319,7 @@ gimp_modules_module_on_disk_func (gpointer data,
old_on_disk = module_info->on_disk;
module_info->on_disk = g_file_test (module_info->fullpath,
module_info->on_disk = g_file_test (module_info->filename,
G_FILE_TEST_IS_REGULAR);
/* if it's not on the disk, and it isn't in memory, mark it to be
@ -390,7 +345,5 @@ gimp_modules_module_remove_func (gpointer data,
module_info = (GimpModuleInfoObj *) data;
gimp = (Gimp *) user_data;
gimp_container_remove (gimp->modules, GIMP_OBJECT (module_info));
g_object_unref (G_OBJECT (module_info));
gimp_container_remove (gimp->modules, (GimpObject *) module_info);
}

View File

@ -25,6 +25,12 @@ libgimpwidgets_1_3_la_sources = \
gimpcolorarea.h \
gimpcolorbutton.c \
gimpcolorbutton.h \
gimpcolordisplay.c \
gimpcolordisplay.h \
gimpcolorselector.c \
gimpcolorselector.h \
gimpcolorselect.c \
gimpcolorselect.h \
gimpdialog.c \
gimpdialog.h \
gimpfileselection.c \
@ -70,6 +76,9 @@ libgimpwidgetsinclude_HEADERS = \
gimpchainbutton.h \
gimpcolorarea.h \
gimpcolorbutton.h \
gimpcolordisplay.h \
gimpcolorselector.h \
gimpcolorselect.h \
gimpdialog.h \
gimpfileselection.h \
gimphelpui.h \

View File

@ -0,0 +1,170 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcolordisplay.c
* Copyright (C) 2002 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser 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 "libgimpcolor/gimpcolor.h"
#include "gimpwidgetstypes.h"
#include "gimpcolordisplay.h"
static void gimp_color_display_class_init (GimpColorDisplayClass *klass);
static void gimp_color_display_init (GimpColorDisplay *display);
static GObjectClass *parent_class = NULL;
GType
gimp_color_display_get_type (void)
{
static GType display_type = 0;
if (! display_type)
{
static const GTypeInfo display_info =
{
sizeof (GimpColorDisplayClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_color_display_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpColorDisplay),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_color_display_init,
};
display_type = g_type_register_static (G_TYPE_OBJECT,
"GimpColorDisplay",
&display_info, 0);
}
return display_type;
}
static void
gimp_color_display_class_init (GimpColorDisplayClass *klass)
{
parent_class = g_type_class_peek_parent (klass);
klass->clone = NULL;
klass->convert = NULL;
klass->load_state = NULL;
klass->save_state = NULL;
klass->configure = NULL;
klass->configure_cancel = NULL;
}
static void
gimp_color_display_init (GimpColorDisplay *display)
{
}
GimpColorDisplay *
gimp_color_display_new (GType display_type)
{
GimpColorDisplay *display;
g_return_val_if_fail (g_type_is_a (display_type, GIMP_TYPE_COLOR_DISPLAY),
NULL);
display = g_object_new (display_type, NULL);
return display;
}
GimpColorDisplay *
gimp_color_display_clone (GimpColorDisplay *display)
{
g_return_val_if_fail (GIMP_IS_COLOR_DISPLAY (display), NULL);
if (GIMP_COLOR_DISPLAY_GET_CLASS (display)->clone)
return GIMP_COLOR_DISPLAY_GET_CLASS (display)->clone (display);
return NULL;
}
void
gimp_color_display_convert (GimpColorDisplay *display,
guchar *buf,
gint width,
gint height,
gint bpp,
gint bpl)
{
g_return_if_fail (GIMP_IS_COLOR_DISPLAY (display));
if (GIMP_COLOR_DISPLAY_GET_CLASS (display)->convert)
GIMP_COLOR_DISPLAY_GET_CLASS (display)->convert (display, buf,
width, height,
bpp, bpl);
}
void
gimp_color_display_load_state (GimpColorDisplay *display,
GimpParasite *state)
{
g_return_if_fail (GIMP_IS_COLOR_DISPLAY (display));
g_return_if_fail (state != NULL);
if (GIMP_COLOR_DISPLAY_GET_CLASS (display)->load_state)
GIMP_COLOR_DISPLAY_GET_CLASS (display)->load_state (display, state);
}
GimpParasite *
gimp_color_display_save_state (GimpColorDisplay *display)
{
g_return_val_if_fail (GIMP_IS_COLOR_DISPLAY (display), NULL);
if (GIMP_COLOR_DISPLAY_GET_CLASS (display)->save_state)
return GIMP_COLOR_DISPLAY_GET_CLASS (display)->save_state (display);
return NULL;
}
void
gimp_color_display_configure (GimpColorDisplay *display,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data)
{
g_return_if_fail (GIMP_IS_COLOR_DISPLAY (display));
if (GIMP_COLOR_DISPLAY_GET_CLASS (display)->configure)
GIMP_COLOR_DISPLAY_GET_CLASS (display)->configure (display,
ok_func, ok_data,
cancel_func, cancel_data);
}
void
gimp_color_display_configure_cancel (GimpColorDisplay *display)
{
g_return_if_fail (GIMP_IS_COLOR_DISPLAY (display));
if (GIMP_COLOR_DISPLAY_GET_CLASS (display)->configure_cancel)
GIMP_COLOR_DISPLAY_GET_CLASS (display)->configure_cancel (display);
}

View File

@ -0,0 +1,94 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1999 Manish Singh <yosh@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser 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.
*/
#ifndef __GIMP_COLOR_DISPLAY_H__
#define __GIMP_COLOR_DISPLAY_H__
G_BEGIN_DECLS
/* For information look at the html documentation */
#define GIMP_TYPE_COLOR_DISPLAY (gimp_color_display_get_type ())
#define GIMP_COLOR_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_COLOR_DISPLAY, GimpColorDisplay))
#define GIMP_COLOR_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_COLOR_DISPLAY, GimpColorDisplayClass))
#define GIMP_IS_COLOR_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_COLOR_DISPLAY))
#define GIMP_IS_COLOR_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_COLOR_DISPLAY))
#define GIMP_COLOR_DISPLAY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_DISPLAY, GimpColorDisplayClass))
typedef struct _GimpColorDisplayClass GimpColorDisplayClass;
struct _GimpColorDisplay
{
GObject parent_instance;
};
struct _GimpColorDisplayClass
{
GObjectClass parent_class;
const gchar *name;
const gchar *help_page;
/* virtual functions */
GimpColorDisplay * (* clone) (GimpColorDisplay *display);
void (* convert) (GimpColorDisplay *display,
guchar *buf,
gint width,
gint height,
gint bpp,
gint bpl);
void (* load_state) (GimpColorDisplay *display,
GimpParasite *state);
GimpParasite * (* save_state) (GimpColorDisplay *display);
void (* configure) (GimpColorDisplay *display,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data);
void (* configure_cancel) (GimpColorDisplay *display);
};
GType gimp_color_display_get_type (void) G_GNUC_CONST;
GimpColorDisplay * gimp_color_display_new (GType display_type);
GimpColorDisplay * gimp_color_display_clone (GimpColorDisplay *display);
void gimp_color_display_convert (GimpColorDisplay *display,
guchar *buf,
gint width,
gint height,
gint bpp,
gint bpl);
void gimp_color_display_load_state (GimpColorDisplay *display,
GimpParasite *state);
GimpParasite * gimp_color_display_save_state (GimpColorDisplay *display);
void gimp_color_display_configure (GimpColorDisplay *display,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data);
void gimp_color_display_configure_cancel (GimpColorDisplay *display);
G_END_DECLS
#endif /* __GIMP_COLOR_DISPLAY_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,41 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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.
*/
#ifndef __GIMP_COLOR_SELECT_H__
#define __GIMP_COLOR_SELECT_H__
G_BEGIN_DECLS
#define GIMP_TYPE_COLOR_SELECT (gimp_color_select_get_type ())
#define GIMP_COLOR_SELECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_COLOR_SELECT, GimpColorSelect))
#define GIMP_COLOR_SELECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_COLOR_SELECT, GimpColorSelectClass))
#define GIMP_IS_COLOR_SELECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_COLOR_SELECT))
#define GIMP_IS_COLOR_SELECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_COLOR_SELECT))
#define GIMP_COLOR_SELECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_SELECT, GimpColorSelectClass))
typedef struct _GimpColorSelectClass GimpColorSelectClass;
GType gimp_color_select_get_type (void) G_GNUC_CONST;
G_END_DECLS
#endif /* __GIMP_COLOR_SELECT_H__ */

View File

@ -0,0 +1,161 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcolorselector.c
* Copyright (C) 2002 Michael Natterer <mitch@gimp.org>
*
* based on:
* Colour selector module
* Copyright (C) 1999 Austin Donnelly <austin@greenend.org.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser 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 "libgimpcolor/gimpcolor.h"
#include "gimpwidgetstypes.h"
#include "gimpcolorselector.h"
#include "gimpwidgetsmarshal.h"
enum
{
COLOR_CHANGED,
LAST_SIGNAL
};
static void gimp_color_selector_class_init (GimpColorSelectorClass *klass);
static void gimp_color_selector_init (GimpColorSelector *selector);
static GtkVBoxClass *parent_class = NULL;
static guint selector_signals[LAST_SIGNAL] = { 0 };
GType
gimp_color_selector_get_type (void)
{
static GType selector_type = 0;
if (! selector_type)
{
static const GTypeInfo selector_info =
{
sizeof (GimpColorSelectorClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_color_selector_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpColorSelector),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_color_selector_init,
};
selector_type = g_type_register_static (GTK_TYPE_VBOX,
"GimpColorSelector",
&selector_info, 0);
}
return selector_type;
}
static void
gimp_color_selector_class_init (GimpColorSelectorClass *klass)
{
parent_class = g_type_class_peek_parent (klass);
selector_signals[COLOR_CHANGED] =
g_signal_new ("color_changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpColorSelectorClass, color_changed),
NULL, NULL,
_gimp_widgets_marshal_VOID__POINTER_POINTER,
G_TYPE_NONE, 2,
G_TYPE_POINTER,
G_TYPE_POINTER);
klass->set_color = NULL;
klass->set_channel = NULL;
klass->color_changed = NULL;
}
static void
gimp_color_selector_init (GimpColorSelector *selector)
{
}
GtkWidget *
gimp_color_selector_new (GType selector_type,
const GimpRGB *rgb,
const GimpHSV *hsv)
{
GimpColorSelector *selector;
g_return_val_if_fail (g_type_is_a (selector_type, GIMP_TYPE_COLOR_SELECTOR),
NULL);
g_return_val_if_fail (rgb != NULL, NULL);
g_return_val_if_fail (hsv != NULL, NULL);
selector = g_object_new (selector_type, NULL);
gimp_color_selector_set_color (selector, rgb, hsv);
return GTK_WIDGET (selector);
}
void
gimp_color_selector_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv)
{
g_return_if_fail (GIMP_IS_COLOR_SELECTOR (selector));
g_return_if_fail (rgb != NULL);
g_return_if_fail (hsv != NULL);
if (GIMP_COLOR_SELECTOR_GET_CLASS (selector)->set_color)
GIMP_COLOR_SELECTOR_GET_CLASS (selector)->set_color (selector, rgb, hsv);
}
void
gimp_color_selector_set_channel (GimpColorSelector *selector,
GimpColorSelectorChannel channel)
{
g_return_if_fail (GIMP_IS_COLOR_SELECTOR (selector));
if (GIMP_COLOR_SELECTOR_GET_CLASS (selector)->set_channel)
GIMP_COLOR_SELECTOR_GET_CLASS (selector)->set_channel (selector, channel);
}
void
gimp_color_selector_color_changed (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv)
{
g_return_if_fail (GIMP_IS_COLOR_SELECTOR (selector));
g_return_if_fail (rgb != NULL);
g_return_if_fail (hsv != NULL);
g_signal_emit (G_OBJECT (selector), selector_signals[COLOR_CHANGED], 0,
rgb, hsv);
}

View File

@ -0,0 +1,104 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpcolorselector.h
* Copyright (C) 2002 Michael Natterer <mitch@gimp.org>
*
* based on:
* Colour selector module
* Copyright (C) 1999 Austin Donnelly <austin@greenend.org.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser 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.
*/
#ifndef __GIMP_COLOR_SELECTOR_H__
#define __GIMP_COLOR_SELECTOR_H__
G_BEGIN_DECLS
/* For information look at the html documentation */
#define GIMP_COLOR_SELECTOR_SIZE 150
#define GIMP_COLOR_SELECTOR_BAR_SIZE 15
typedef enum
{
GIMP_COLOR_SELECTOR_HUE,
GIMP_COLOR_SELECTOR_SATURATION,
GIMP_COLOR_SELECTOR_VALUE,
GIMP_COLOR_SELECTOR_RED,
GIMP_COLOR_SELECTOR_GREEN,
GIMP_COLOR_SELECTOR_BLUE,
GIMP_COLOR_SELECTOR_ALPHA
} GimpColorSelectorChannel;
#define GIMP_TYPE_COLOR_SELECTOR (gimp_color_selector_get_type ())
#define GIMP_COLOR_SELECTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_COLOR_SELECTOR, GimpColorSelector))
#define GIMP_COLOR_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_COLOR_SELECTOR, GimpColorSelectorClass))
#define GIMP_IS_COLOR_SELECTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_COLOR_SELECTOR))
#define GIMP_IS_COLOR_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_COLOR_SELECTOR))
#define GIMP_COLOR_SELECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_SELECTOR, GimpColorSelectorClass))
typedef struct _GimpColorSelectorClass GimpColorSelectorClass;
struct _GimpColorSelector
{
GtkVBox parent_instance;
};
struct _GimpColorSelectorClass
{
GtkVBoxClass parent_class;
const gchar *name;
const gchar *help_page;
/* virtual functions */
void (* set_color) (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv);
void (* set_channel) (GimpColorSelector *selector,
GimpColorSelectorChannel channel);
/* signals */
void (* color_changed) (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv);
};
GType gimp_color_selector_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_color_selector_new (GType selector_type,
const GimpRGB *rgb,
const GimpHSV *hsv);
void gimp_color_selector_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv);
void gimp_color_selector_set_channel (GimpColorSelector *selector,
GimpColorSelectorChannel channel);
void gimp_color_selector_color_changed (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv);
G_END_DECLS
#endif /* __GIMP_COLOR_SELECTOR_H__ */

View File

@ -30,6 +30,9 @@
#include <libgimpwidgets/gimpchainbutton.h>
#include <libgimpwidgets/gimpcolorarea.h>
#include <libgimpwidgets/gimpcolorbutton.h>
#include <libgimpwidgets/gimpcolordisplay.h>
#include <libgimpwidgets/gimpcolorselector.h>
#include <libgimpwidgets/gimpcolorselect.h>
#include <libgimpwidgets/gimpdialog.h>
#include <libgimpwidgets/gimpfileselection.h>
#include <libgimpwidgets/gimphelpui.h>

View File

@ -1 +1,2 @@
NONE:INT,INT
NONE:POINTER,POINTER

View File

@ -48,6 +48,9 @@ typedef struct _GimpButton GimpButton;
typedef struct _GimpChainButton GimpChainButton;
typedef struct _GimpColorArea GimpColorArea;
typedef struct _GimpColorButton GimpColorButton;
typedef struct _GimpColorDisplay GimpColorDisplay;
typedef struct _GimpColorSelector GimpColorSelector;
typedef struct _GimpColorSelect GimpColorSelect;
typedef struct _GimpDialog GimpDialog;
typedef struct _GimpFileSelection GimpFileSelection;
typedef struct _GimpOffsetArea GimpOffsetArea;

View File

@ -2,8 +2,6 @@
libdir = $(gimpplugindir)/modules
AM_CPPFLAGS = -DMODULE_COMPILATION
INCLUDES = \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
@ -14,17 +12,15 @@ EXTRA_DIST = \
makefile.mingw.in \
makefile.msc \
module.def \
gimpmodregister.c \
gimpmodregister.h \
colorsel_water.c
lib_LTLIBRARIES = \
libcolorsel_triangle.la \
libcdisplay_gamma.la \
libcdisplay_highcontrast.la
libcdisplay_highcontrast.la \
libcolorsel_water.la
## libcolorsel_gtk.la \
## libcolorsel_water.la \
EXTRA_LTLIBRARIES =
@ -36,9 +32,9 @@ libcolorsel_triangle_la_SOURCES = colorsel_triangle.c
libcolorsel_triangle_la_LDFLAGS = -avoid-version -module
libcolorsel_triangle_la_LIBADD = $(GTK_LIBS)
## libcolorsel_water_la_SOURCES = colorsel_water.c
## libcolorsel_water_la_LDFLAGS = -avoid-version -module
## libcolorsel_water_la_LIBADD = $(GTK_LIBS)
libcolorsel_water_la_SOURCES = colorsel_water.c
libcolorsel_water_la_LDFLAGS = -avoid-version -module
libcolorsel_water_la_LIBADD = $(GTK_LIBS)
libcdisplay_gamma_la_SOURCES = cdisplay_gamma.c
libcdisplay_gamma_la_LDFLAGS = -avoid-version -module

View File

@ -15,6 +15,7 @@
* 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 <string.h>
@ -23,74 +24,77 @@
#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
#include "libgimp/gimpmodule.h"
#include "libgimp/gimpcolordisplay.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "gimpmodregister.h"
#include "libgimp/gimpmodule.h"
#include "libgimp/gimpintl.h"
#define COLOR_DISPLAY_NAME _("Gamma")
#define CDISPLAY_TYPE_GAMMA (cdisplay_gamma_type)
#define CDISPLAY_GAMMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_GAMMA, CdisplayGamma))
#define CDISPLAY_GAMMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_GAMMA, CdisplayGammaClass))
#define CDISPLAY_IS_GAMMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_GAMMA))
#define CDISPLAY_IS_GAMMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_GAMMA))
typedef struct _GammaContext GammaContext;
struct _GammaContext
typedef struct _CdisplayGamma CdisplayGamma;
typedef struct _CdisplayGammaClass CdisplayGammaClass;
struct _CdisplayGamma
{
GFunc ok_func;
gpointer ok_data;
GFunc cancel_func;
gpointer cancel_data;
GimpColorDisplay parent_instance;
gdouble gamma;
guchar *lookup;
GFunc ok_func;
gpointer ok_data;
GFunc cancel_func;
gpointer cancel_data;
GtkWidget *shell;
GtkWidget *spinner;
gdouble gamma;
guchar *lookup;
GtkWidget *shell;
GtkWidget *spinner;
};
static gpointer gamma_new (int type);
static gpointer gamma_clone (gpointer cd_ID);
static void gamma_create_lookup_table (GammaContext *context);
static void gamma_destroy (gpointer cd_ID);
static void gamma_convert (gpointer cd_ID,
guchar *buf,
int w,
int h,
int bpp,
int bpl);
static void gamma_load (gpointer cd_ID,
GimpParasite *state);
static GimpParasite * gamma_save (gpointer cd_ID);
static void gamma_configure_ok_callback (GtkWidget *widget,
gpointer data);
static void gamma_configure_cancel_callback (GtkWidget *widget,
gpointer data);
static void gamma_configure (gpointer cd_ID,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data);
static void gamma_configure_cancel (gpointer cd_ID);
static GimpColorDisplayMethods methods =
struct _CdisplayGammaClass
{
NULL,
gamma_new,
gamma_clone,
gamma_convert,
gamma_destroy,
NULL,
gamma_load,
gamma_save,
gamma_configure,
gamma_configure_cancel
GimpColorDisplayClass parent_instance;
};
static GimpModuleInfo info =
static GType cdisplay_gamma_get_type (GTypeModule *module);
static void cdisplay_gamma_class_init (CdisplayGammaClass *klass);
static void cdisplay_gamma_init (CdisplayGamma *gamma);
static void cdisplay_gamma_finalize (GObject *object);
static GimpColorDisplay * cdisplay_gamma_clone (GimpColorDisplay *display);
static void cdisplay_gamma_convert (GimpColorDisplay *display,
guchar *buf,
gint w,
gint h,
gint bpp,
gint bpl);
static void cdisplay_gamma_load_state (GimpColorDisplay *display,
GimpParasite *state);
static GimpParasite * cdisplay_gamma_save_state (GimpColorDisplay *display);
static void cdisplay_gamma_configure (GimpColorDisplay *display,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data);
static void cdisplay_gamma_configure_cancel (GimpColorDisplay *display);
static void gamma_create_lookup_table (CdisplayGamma *gamma);
static void gamma_configure_ok_callback (GtkWidget *widget,
CdisplayGamma *gamma);
static void gamma_configure_cancel_callback (GtkWidget *widget,
CdisplayGamma *gamma);
static GimpModuleInfo cdisplay_gamma_info =
{
NULL,
N_("Gamma color display filter"),
"Manish Singh <yosh@gimp.org>",
"v0.2",
@ -98,111 +102,137 @@ static GimpModuleInfo info =
"October 14, 2000"
};
G_MODULE_EXPORT GimpModuleStatus
module_init (GimpModuleInfo **inforet)
static GType cdisplay_gamma_type = 0;
static GimpColorDisplayClass *parent_class = NULL;
G_MODULE_EXPORT gboolean
gimp_module_register (GTypeModule *module,
GimpModuleInfo **inforet)
{
#ifndef __EMX__
if (gimp_color_display_register (COLOR_DISPLAY_NAME, &methods))
#else
if (mod_color_display_register (COLOR_DISPLAY_NAME, &methods))
#endif
cdisplay_gamma_get_type (module);
if (inforet)
*inforet = &cdisplay_gamma_info;
return TRUE;
}
static GType
cdisplay_gamma_get_type (GTypeModule *module)
{
if (! cdisplay_gamma_type)
{
*inforet = &info;
return GIMP_MODULE_OK;
static const GTypeInfo select_info =
{
sizeof (CdisplayGammaClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) cdisplay_gamma_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (CdisplayGamma),
0, /* n_preallocs */
(GInstanceInitFunc) cdisplay_gamma_init,
};
cdisplay_gamma_type =
g_type_module_register_type (module,
GIMP_TYPE_COLOR_DISPLAY,
"CdisplayGamma",
&select_info, 0);
}
else
return GIMP_MODULE_UNLOAD;
return cdisplay_gamma_type;
}
G_MODULE_EXPORT void
module_unload (void *shutdown_data,
void (*completed_cb) (void *),
void *completed_data)
static void
cdisplay_gamma_class_init (CdisplayGammaClass *klass)
{
#ifndef __EMX__
gimp_color_display_unregister (COLOR_DISPLAY_NAME);
#else
mod_color_display_unregister (COLOR_DISPLAY_NAME);
#endif
GObjectClass *object_class;
GimpColorDisplayClass *display_class;
object_class = G_OBJECT_CLASS (klass);
display_class = GIMP_COLOR_DISPLAY_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = cdisplay_gamma_finalize;
display_class->name = _("Gamma");
display_class->help_page = "modules/gamma.html";
display_class->clone = cdisplay_gamma_clone;
display_class->convert = cdisplay_gamma_convert;
display_class->load_state = cdisplay_gamma_load_state;
display_class->save_state = cdisplay_gamma_save_state;
display_class->configure = cdisplay_gamma_configure;
display_class->configure_cancel = cdisplay_gamma_configure_cancel;
}
static gpointer
gamma_new (int type)
static void
cdisplay_gamma_init (CdisplayGamma *gamma)
{
int i;
GammaContext *context;
gint i;
context = g_new0 (GammaContext, 1);
context->gamma = 1.0;
context->lookup = g_new (guchar, 256);
gamma->gamma = 1.0;
gamma->lookup = g_new (guchar, 256);
for (i = 0; i < 256; i++)
context->lookup[i] = i;
return context;
gamma->lookup[i] = i;
}
static gpointer
gamma_clone (gpointer cd_ID)
static void
cdisplay_gamma_finalize (GObject *object)
{
GammaContext *src_context = cd_ID;
GammaContext *context;
CdisplayGamma *gamma;
context = gamma_new (0);
context->gamma = src_context->gamma;
gamma = CDISPLAY_GAMMA (object);
if (gamma->shell)
{
gtk_widget_destroy (gamma->shell);
gamma->shell = NULL;
}
if (gamma->lookup)
{
g_free (gamma->lookup);
gamma->lookup = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static GimpColorDisplay *
cdisplay_gamma_clone (GimpColorDisplay *display)
{
CdisplayGamma *gamma;
CdisplayGamma *copy;
gamma = CDISPLAY_GAMMA (display);
copy = CDISPLAY_GAMMA (gimp_color_display_new (G_TYPE_FROM_INSTANCE (gamma)));
copy->gamma = gamma->gamma;
memcpy (context->lookup, src_context->lookup, sizeof (guchar) * 256);
memcpy (copy->lookup, gamma->lookup, sizeof (guchar) * 256);
return context;
return GIMP_COLOR_DISPLAY (copy);
}
static void
gamma_create_lookup_table (GammaContext *context)
cdisplay_gamma_convert (GimpColorDisplay *display,
guchar *buf,
gint width,
gint height,
gint bpp,
gint bpl)
{
gdouble one_over_gamma;
gdouble ind;
gint i;
CdisplayGamma *gamma;
gint i, j = height;
if (context->gamma == 0.0)
context->gamma = 1.0;
one_over_gamma = 1.0 / context->gamma;
for (i = 0; i < 256; i++)
{
ind = (double) i / 255.0;
context->lookup[i] = (guchar) (gint) (255 * pow (ind, one_over_gamma));
}
}
static void
gamma_destroy (gpointer cd_ID)
{
GammaContext *context = cd_ID;
if (context->shell)
{
#if 0
dialog_unregister (context->shell);
#endif
gtk_widget_destroy (context->shell);
}
g_free (context->lookup);
g_free (context);
}
static void
gamma_convert (gpointer cd_ID,
guchar *buf,
gint width,
gint height,
gint bpp,
gint bpl)
{
guchar *lookup = ((GammaContext *) cd_ID)->lookup;
gint i, j = height;
gamma = CDISPLAY_GAMMA (display);
/* You will not be using the entire buffer most of the time.
* Hence, the simplistic code for this is as follows:
@ -223,7 +253,7 @@ gamma_convert (gpointer cd_ID,
i = width;
while (i--)
{
*buf = lookup[*buf];
*buf = gamma->lookup[*buf];
buf++;
}
buf += bpl;
@ -231,36 +261,44 @@ gamma_convert (gpointer cd_ID,
}
static void
gamma_load (gpointer cd_ID,
GimpParasite *state)
cdisplay_gamma_load_state (GimpColorDisplay *display,
GimpParasite *state)
{
GammaContext *context = cd_ID;
CdisplayGamma *gamma;
gamma = CDISPLAY_GAMMA (display);
#if G_BYTE_ORDER == G_BIG_ENDIAN
memcpy (&context->gamma, gimp_parasite_data (state), sizeof (gdouble));
memcpy (&gamma->gamma, gimp_parasite_data (state), sizeof (gdouble));
#else
guint32 buf[2], *data = gimp_parasite_data (state);
{
guint32 buf[2], *data = gimp_parasite_data (state);
buf[0] = g_ntohl (data[1]);
buf[1] = g_ntohl (data[0]);
buf[0] = g_ntohl (data[1]);
buf[1] = g_ntohl (data[0]);
memcpy (&context->gamma, buf, sizeof (gdouble));
memcpy (&gamma->gamma, buf, sizeof (gdouble));
}
#endif
gamma_create_lookup_table (context);
gamma_create_lookup_table (gamma);
}
static GimpParasite *
gamma_save (gpointer cd_ID)
cdisplay_gamma_save_state (GimpColorDisplay *display)
{
GammaContext *context = cd_ID;
guint32 buf[2];
CdisplayGamma *gamma;
guint32 buf[2];
memcpy (buf, &context->gamma, sizeof (double));
gamma = CDISPLAY_GAMMA (display);
memcpy (buf, &gamma->gamma, sizeof (double));
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
{
guint32 tmp = g_htonl (buf[0]);
guint32 tmp;
tmp = g_htonl (buf[0]);
buf[0] = g_htonl (buf[1]);
buf[1] = tmp;
}
@ -271,113 +309,113 @@ gamma_save (gpointer cd_ID)
}
static void
gamma_configure_ok_callback (GtkWidget *widget,
gpointer data)
cdisplay_gamma_configure (GimpColorDisplay *display,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data)
{
GammaContext *context = data;
CdisplayGamma *gamma;
GtkWidget *hbox;
GtkWidget *label;
GtkObject *adjustment;
context->gamma =
gtk_spin_button_get_value (GTK_SPIN_BUTTON (context->spinner));
gamma_create_lookup_table (context);
gamma = CDISPLAY_GAMMA (display);
#if 0
dialog_unregister (context->shell);
#endif
gtk_widget_destroy (GTK_WIDGET (context->shell));
context->shell = NULL;
if (context->ok_func)
context->ok_func (context, context->ok_data);
}
static void
gamma_configure_cancel_callback (GtkWidget *widget,
gpointer data)
{
GammaContext *context = data;
#if 0
dialog_unregister (context->shell);
#endif
gtk_widget_destroy (GTK_WIDGET (context->shell));
context->shell = NULL;
if (context->cancel_func)
context->cancel_func (context, context->cancel_data);
}
static void
gamma_configure (gpointer cd_ID,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data)
{
GammaContext *context = cd_ID;
GtkWidget *hbox;
GtkWidget *label;
GtkObject *adjustment;
if (!context->shell)
if (!gamma->shell)
{
context->ok_func = ok_func;
context->ok_data = ok_data;
context->cancel_func = cancel_func;
context->cancel_data = cancel_data;
gamma->ok_func = ok_func;
gamma->ok_data = ok_data;
gamma->cancel_func = cancel_func;
gamma->cancel_data = cancel_data;
context->shell =
gamma->shell =
gimp_dialog_new (_("Gamma"), "gamma",
gimp_standard_help_func, "modules/gamma.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
GTK_STOCK_CANCEL, gamma_configure_cancel_callback,
cd_ID, NULL, NULL, FALSE, TRUE,
gamma, NULL, NULL, FALSE, TRUE,
GTK_STOCK_OK, gamma_configure_ok_callback,
cd_ID, NULL, NULL, TRUE, FALSE,
gamma, NULL, NULL, TRUE, FALSE,
NULL);
#if 0
dialog_register (context->shell);
#endif
hbox = gtk_hbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (context->shell)->vbox),
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (gamma->shell)->vbox),
hbox, FALSE, FALSE, 0);
label = gtk_label_new ( _("Gamma:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
adjustment = gtk_adjustment_new (context->gamma, 0.01, 10.0, 0.01, 0.1, 0.0);
context->spinner = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment),
adjustment = gtk_adjustment_new (gamma->gamma, 0.01, 10.0, 0.01, 0.1, 0.0);
gamma->spinner = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment),
0.1, 3);
gtk_widget_set_size_request (context->spinner, 100, -1);
gtk_box_pack_start (GTK_BOX (hbox), context->spinner, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), gamma->spinner, FALSE, FALSE, 0);
}
gtk_widget_show_all (context->shell);
gtk_widget_show_all (gamma->shell);
}
static void
gamma_configure_cancel (gpointer cd_ID)
cdisplay_gamma_configure_cancel (GimpColorDisplay *display)
{
GammaContext *context = cd_ID;
CdisplayGamma *gamma;
if (context->shell)
gamma = CDISPLAY_GAMMA (display);
if (gamma->shell)
{
#if 0
dialog_unregister (context->shell);
#endif
gtk_widget_destroy (context->shell);
context->shell = NULL;
gtk_widget_destroy (gamma->shell);
gamma->shell = NULL;
}
if (context->cancel_func)
context->cancel_func (context, context->cancel_data);
if (gamma->cancel_func)
gamma->cancel_func (gamma, gamma->cancel_data);
}
static void
gamma_create_lookup_table (CdisplayGamma *gamma)
{
gdouble one_over_gamma;
gdouble ind;
gint i;
if (gamma->gamma == 0.0)
gamma->gamma = 1.0;
one_over_gamma = 1.0 / gamma->gamma;
for (i = 0; i < 256; i++)
{
ind = (gdouble) i / 255.0;
gamma->lookup[i] = (guchar) (gint) (255 * pow (ind, one_over_gamma));
}
}
static void
gamma_configure_ok_callback (GtkWidget *widget,
CdisplayGamma *gamma)
{
gamma->gamma =
gtk_spin_button_get_value (GTK_SPIN_BUTTON (gamma->spinner));
gamma_create_lookup_table (gamma);
gtk_widget_destroy (GTK_WIDGET (gamma->shell));
gamma->shell = NULL;
if (gamma->ok_func)
gamma->ok_func (gamma, gamma->ok_data);
}
static void
gamma_configure_cancel_callback (GtkWidget *widget,
CdisplayGamma *gamma)
{
gimp_color_display_configure_cancel (GIMP_COLOR_DISPLAY (gamma));
}

View File

@ -24,74 +24,77 @@
#include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h"
#include "libgimp/gimpmodule.h"
#include "libgimp/gimpcolordisplay.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "gimpmodregister.h"
#include "libgimp/gimpmodule.h"
#include "libgimp/gimpintl.h"
#define COLOR_DISPLAY_NAME _("High Contrast")
#define CDISPLAY_TYPE_CONTRAST (cdisplay_contrast_type)
#define CDISPLAY_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CDISPLAY_TYPE_CONTRAST, CdisplayContrast))
#define CDISPLAY_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CDISPLAY_TYPE_CONTRAST, CdisplayContrastClass))
#define CDISPLAY_IS_CONTRAST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CDISPLAY_TYPE_CONTRAST))
#define CDISPLAY_IS_CONTRAST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CDISPLAY_TYPE_CONTRAST))
typedef struct _ContrastContext ContrastContext;
struct _ContrastContext
typedef struct _CdisplayContrast CdisplayContrast;
typedef struct _CdisplayContrastClass CdisplayContrastClass;
struct _CdisplayContrast
{
GFunc ok_func;
gpointer ok_data;
GFunc cancel_func;
gpointer cancel_data;
GimpColorDisplay parent_instance;
gdouble contrast;
guchar *lookup;
GFunc ok_func;
gpointer ok_data;
GFunc cancel_func;
gpointer cancel_data;
GtkWidget *shell;
GtkWidget *spinner;
gdouble contrast;
guchar *lookup;
GtkWidget *shell;
GtkWidget *spinner;
};
static gpointer contrast_new (gint type);
static gpointer contrast_clone (gpointer cd_ID);
static void contrast_create_lookup_table (ContrastContext *context);
static void contrast_destroy (gpointer cd_ID);
static void contrast_convert (gpointer cd_ID,
guchar *buf,
gint w,
gint h,
gint bpp,
gint bpl);
static void contrast_load (gpointer cd_ID,
GimpParasite *state);
static GimpParasite * contrast_save (gpointer cd_ID);
static void contrast_configure_ok_callback (GtkWidget *widget,
gpointer data);
static void contrast_configure_cancel_callback (GtkWidget *widget,
gpointer data);
static void contrast_configure (gpointer cd_ID,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data);
static void contrast_configure_cancel (gpointer cd_ID);
static GimpColorDisplayMethods methods =
struct _CdisplayContrastClass
{
NULL,
contrast_new,
contrast_clone,
contrast_convert,
contrast_destroy,
NULL,
contrast_load,
contrast_save,
contrast_configure,
contrast_configure_cancel
GimpColorDisplayClass parent_instance;
};
static GimpModuleInfo info =
static GType cdisplay_contrast_get_type (GTypeModule *module);
static void cdisplay_contrast_class_init (CdisplayContrastClass *klass);
static void cdisplay_contrast_init (CdisplayContrast *contrast);
static void cdisplay_contrast_finalize (GObject *object);
static GimpColorDisplay * cdisplay_contrast_clone (GimpColorDisplay *display);
static void cdisplay_contrast_convert (GimpColorDisplay *display,
guchar *buf,
gint w,
gint h,
gint bpp,
gint bpl);
static void cdisplay_contrast_load_state (GimpColorDisplay *display,
GimpParasite *state);
static GimpParasite * cdisplay_contrast_save_state (GimpColorDisplay *display);
static void cdisplay_contrast_configure (GimpColorDisplay *display,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data);
static void cdisplay_contrast_configure_cancel (GimpColorDisplay *display);
static void contrast_create_lookup_table (CdisplayContrast *contrast);
static void contrast_configure_ok_callback (GtkWidget *widget,
CdisplayContrast *contrast);
static void contrast_configure_cancel_callback (GtkWidget *widget,
CdisplayContrast *contrast);
static GimpModuleInfo cdisplay_contrast_info =
{
NULL,
N_("High Contrast color display filter"),
"Jay Cox <jaycox@earthlink.net>",
"v0.2",
@ -99,105 +102,134 @@ static GimpModuleInfo info =
"October 14, 2000"
};
G_MODULE_EXPORT GimpModuleStatus
module_init (GimpModuleInfo **inforet)
static GType cdisplay_contrast_type = 0;
static GimpColorDisplayClass *parent_class = NULL;
G_MODULE_EXPORT gboolean
gimp_module_register (GTypeModule *module,
GimpModuleInfo **inforet)
{
#ifndef __EMX__
if (gimp_color_display_register (COLOR_DISPLAY_NAME, &methods))
#else
if (mod_color_display_register (COLOR_DISPLAY_NAME, &methods))
#endif
cdisplay_contrast_get_type (module);
if (inforet)
*inforet = &cdisplay_contrast_info;
return TRUE;
}
static GType
cdisplay_contrast_get_type (GTypeModule *module)
{
if (! cdisplay_contrast_type)
{
*inforet = &info;
return GIMP_MODULE_OK;
static const GTypeInfo select_info =
{
sizeof (CdisplayContrastClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) cdisplay_contrast_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (CdisplayContrast),
0, /* n_preallocs */
(GInstanceInitFunc) cdisplay_contrast_init,
};
cdisplay_contrast_type =
g_type_module_register_type (module,
GIMP_TYPE_COLOR_DISPLAY,
"CdisplayContrast",
&select_info, 0);
}
else
return GIMP_MODULE_UNLOAD;
return cdisplay_contrast_type;
}
G_MODULE_EXPORT void
module_unload (void *shutdown_data,
void (*completed_cb) (void *),
void *completed_data)
static void
cdisplay_contrast_class_init (CdisplayContrastClass *klass)
{
#ifndef __EMX__
gimp_color_display_unregister (COLOR_DISPLAY_NAME);
#else
mod_color_display_unregister (COLOR_DISPLAY_NAME);
#endif
GObjectClass *object_class;
GimpColorDisplayClass *display_class;
object_class = G_OBJECT_CLASS (klass);
display_class = GIMP_COLOR_DISPLAY_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = cdisplay_contrast_finalize;
display_class->name = _("Contrast");
display_class->help_page = "modules/contrast.html";
display_class->clone = cdisplay_contrast_clone;
display_class->convert = cdisplay_contrast_convert;
display_class->load_state = cdisplay_contrast_load_state;
display_class->save_state = cdisplay_contrast_save_state;
display_class->configure = cdisplay_contrast_configure;
display_class->configure_cancel = cdisplay_contrast_configure_cancel;
}
static void
cdisplay_contrast_init (CdisplayContrast *contrast)
{
contrast->contrast = 4.0;
contrast->lookup = g_new (guchar, 256);
contrast_create_lookup_table (contrast);
}
static void
cdisplay_contrast_finalize (GObject *object)
{
CdisplayContrast *contrast;
contrast = CDISPLAY_CONTRAST (object);
if (contrast->shell)
{
gtk_widget_destroy (contrast->shell);
contrast->shell = NULL;
}
if (contrast->lookup)
{
g_free (contrast->lookup);
contrast->lookup = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gpointer
contrast_new (gint type)
static GimpColorDisplay *
cdisplay_contrast_clone (GimpColorDisplay *display)
{
ContrastContext *context;
CdisplayContrast *contrast;
CdisplayContrast *copy;
context = g_new0 (ContrastContext, 1);
context->contrast = 4.0;
context->lookup = g_new (guchar, 256);
contrast = CDISPLAY_CONTRAST (display);
contrast_create_lookup_table (context);
copy = CDISPLAY_CONTRAST (gimp_color_display_new (G_TYPE_FROM_INSTANCE (contrast)));
return context;
}
static gpointer
contrast_clone (gpointer cd_ID)
{
ContrastContext *src_context = cd_ID;
ContrastContext *context;
context = contrast_new (0);
context->contrast = src_context->contrast;
copy->contrast = contrast->contrast;
memcpy (context->lookup, src_context->lookup, sizeof (guchar) * 256);
memcpy (copy->lookup, contrast->lookup, sizeof (guchar) * 256);
return context;
return GIMP_COLOR_DISPLAY (copy);
}
static void
contrast_create_lookup_table (ContrastContext *context)
cdisplay_contrast_convert (GimpColorDisplay *display,
guchar *buf,
gint width,
gint height,
gint bpp,
gint bpl)
{
gint i;
CdisplayContrast *contrast;
gint i, j = height;
if (context->contrast == 0.0)
context->contrast = 1.0;
for (i = 0; i < 256; i++)
{
context->lookup[i]
= (guchar) (int)(255 * .5 * (1 + sin(context->contrast*2*G_PI*i/255.0)));
}
}
static void
contrast_destroy (gpointer cd_ID)
{
ContrastContext *context = cd_ID;
if (context->shell)
{
#if 0
dialog_unregister (context->shell);
#endif
gtk_widget_destroy (context->shell);
}
g_free (context->lookup);
g_free (context);
}
static void
contrast_convert (gpointer cd_ID,
guchar *buf,
gint width,
gint height,
gint bpp,
gint bpl)
{
guchar *lookup = ((ContrastContext *) cd_ID)->lookup;
gint i, j = height;
contrast = CDISPLAY_CONTRAST (display);
/* You will not be using the entire buffer most of the time.
* Hence, the simplistic code for this is as follows:
@ -218,7 +250,7 @@ contrast_convert (gpointer cd_ID,
i = width;
while (i--)
{
*buf = lookup[*buf];
*buf = contrast->lookup[*buf];
buf++;
}
buf += bpl;
@ -226,151 +258,157 @@ contrast_convert (gpointer cd_ID,
}
static void
contrast_load (gpointer cd_ID,
GimpParasite *state)
cdisplay_contrast_load_state (GimpColorDisplay *display,
GimpParasite *state)
{
ContrastContext *context = cd_ID;
CdisplayContrast *contrast;
contrast = CDISPLAY_CONTRAST (display);
#if G_BYTE_ORDER == G_BIG_ENDIAN
memcpy (&context->contrast, gimp_parasite_data (state), sizeof (gdouble));
memcpy (&contrast->contrast, gimp_parasite_data (state), sizeof (gdouble));
#else
guint32 buf[2], *data = gimp_parasite_data (state);
{
guint32 buf[2], *data = gimp_parasite_data (state);
buf[0] = g_ntohl (data[1]);
buf[1] = g_ntohl (data[0]);
buf[0] = g_ntohl (data[1]);
buf[1] = g_ntohl (data[0]);
memcpy (&context->contrast, buf, sizeof (gdouble));
memcpy (&contrast->contrast, buf, sizeof (gdouble));
}
#endif
contrast_create_lookup_table (context);
contrast_create_lookup_table (contrast);
}
static GimpParasite *
contrast_save (gpointer cd_ID)
cdisplay_contrast_save_state (GimpColorDisplay *display)
{
ContrastContext *context = cd_ID;
guint32 buf[2];
CdisplayContrast *contrast;
guint32 buf[2];
memcpy (buf, &context->contrast, sizeof (gdouble));
contrast = CDISPLAY_CONTRAST (display);
memcpy (buf, &contrast->contrast, sizeof (double));
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
{
guint32 tmp = g_htonl (buf[0]);
guint32 tmp;
tmp = g_htonl (buf[0]);
buf[0] = g_htonl (buf[1]);
buf[1] = tmp;
}
#endif
return gimp_parasite_new ("Display/Contrast", GIMP_PARASITE_PERSISTENT,
sizeof (gdouble), &buf);
sizeof (double), &buf);
}
static void
contrast_configure_ok_callback (GtkWidget *widget,
gpointer data)
cdisplay_contrast_configure (GimpColorDisplay *display,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data)
{
ContrastContext *context = data;
CdisplayContrast *contrast;
GtkWidget *hbox;
GtkWidget *label;
GtkObject *adjustment;
context->contrast =
gtk_spin_button_get_value (GTK_SPIN_BUTTON (context->spinner));
contrast_create_lookup_table (context);
contrast = CDISPLAY_CONTRAST (display);
#if 0
dialog_unregister (context->shell);
#endif
gtk_widget_destroy (GTK_WIDGET (context->shell));
context->shell = NULL;
if (context->ok_func)
context->ok_func (context, context->ok_data);
}
static void
contrast_configure_cancel_callback (GtkWidget *widget,
gpointer data)
{
ContrastContext *context = data;
#if 0
dialog_unregister (context->shell);
#endif
gtk_widget_destroy (GTK_WIDGET (context->shell));
context->shell = NULL;
if (context->cancel_func)
context->cancel_func (context, context->cancel_data);
}
static void
contrast_configure (gpointer cd_ID,
GFunc ok_func,
gpointer ok_data,
GFunc cancel_func,
gpointer cancel_data)
{
ContrastContext *context = cd_ID;
GtkWidget *hbox;
GtkWidget *label;
GtkObject *adjustment;
if (!context->shell)
if (!contrast->shell)
{
context->ok_func = ok_func;
context->ok_data = ok_data;
context->cancel_func = cancel_func;
context->cancel_data = cancel_data;
contrast->ok_func = ok_func;
contrast->ok_data = ok_data;
contrast->cancel_func = cancel_func;
contrast->cancel_data = cancel_data;
context->shell =
gimp_dialog_new (_("High Contrast"), "high contrast",
contrast->shell =
gimp_dialog_new (_("High Contrast"), "high_contrast",
gimp_standard_help_func, "modules/highcontrast.html",
GTK_WIN_POS_MOUSE,
FALSE, TRUE, FALSE,
GTK_STOCK_CANCEL, contrast_configure_cancel_callback,
cd_ID, NULL, NULL, FALSE, TRUE,
contrast, NULL, NULL, FALSE, TRUE,
GTK_STOCK_OK, contrast_configure_ok_callback,
cd_ID, NULL, NULL, TRUE, FALSE,
contrast, NULL, NULL, TRUE, FALSE,
NULL);
#if 0
dialog_register (context->shell);
#endif
hbox = gtk_hbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (context->shell)->vbox),
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (contrast->shell)->vbox),
hbox, FALSE, FALSE, 0);
label = gtk_label_new ( _("Contrast Cycles:"));
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
adjustment = gtk_adjustment_new (context->contrast, 1.0, 20.0, 0.5, 1.0, 0.0);
context->spinner = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment),
adjustment = gtk_adjustment_new (contrast->contrast, 0.01, 10.0, 0.01, 0.1, 0.0);
contrast->spinner = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment),
0.1, 3);
gtk_widget_set_size_request (context->spinner, 100, -1);
gtk_box_pack_start (GTK_BOX (hbox), context->spinner, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), contrast->spinner, FALSE, FALSE, 0);
}
gtk_widget_show_all (context->shell);
gtk_widget_show_all (contrast->shell);
}
static void
contrast_configure_cancel (gpointer cd_ID)
cdisplay_contrast_configure_cancel (GimpColorDisplay *display)
{
ContrastContext *context = cd_ID;
CdisplayContrast *contrast;
if (context->shell)
contrast = CDISPLAY_CONTRAST (display);
if (contrast->shell)
{
#if 0
dialog_unregister (context->shell);
#endif
gtk_widget_destroy (context->shell);
context->shell = NULL;
gtk_widget_destroy (contrast->shell);
contrast->shell = NULL;
}
if (context->cancel_func)
context->cancel_func (context, context->cancel_data);
if (contrast->cancel_func)
contrast->cancel_func (contrast, contrast->cancel_data);
}
static void
contrast_create_lookup_table (CdisplayContrast *contrast)
{
gint i;
if (contrast->contrast == 0.0)
contrast->contrast = 1.0;
for (i = 0; i < 256; i++)
{
contrast->lookup[i] = (guchar) (gint)
(255 * .5 * (1 + sin (contrast->contrast * 2 * G_PI * i / 255.0)));
}
}
static void
contrast_configure_ok_callback (GtkWidget *widget,
CdisplayContrast *contrast)
{
contrast->contrast =
gtk_spin_button_get_value (GTK_SPIN_BUTTON (contrast->spinner));
contrast_create_lookup_table (contrast);
gtk_widget_destroy (GTK_WIDGET (contrast->shell));
contrast->shell = NULL;
if (contrast->ok_func)
contrast->ok_func (contrast, contrast->ok_data);
}
static void
contrast_configure_cancel_callback (GtkWidget *widget,
CdisplayContrast *contrast)
{
gimp_color_display_configure_cancel (GIMP_COLOR_DISPLAY (contrast));
}

View File

@ -22,65 +22,92 @@
#include "config.h"
#include <stdlib.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "gimpmodregister.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimpmodule.h"
#include "libgimp/gimpintl.h"
/* prototypes */
static GtkWidget * colorsel_triangle_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer callback_data,
gpointer *selector_data);
static void colorsel_triangle_free (gpointer selector_data);
static void colorsel_triangle_set_color (gpointer selector_data,
const GimpHSV *hsv,
const GimpRGB *rgb);
static void colorsel_xy_to_triangle_buf (const gint x,
const gint y,
const gdouble hue,
guchar *buf,
const gint sx,
const gint sy,
const gint vx,
const gint vy,
const gint hx,
const gint hy);
#define COLORWHEELRADIUS (GIMP_COLOR_SELECTOR_SIZE / 2)
#define COLORTRIANGLERADIUS (COLORWHEELRADIUS - GIMP_COLOR_SELECTOR_BAR_SIZE)
#define PREVIEWSIZE (2 * COLORWHEELRADIUS + 1)
#define BGCOLOR 180
#define PREVIEW_MASK (GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON_MOTION_MASK )
/* local methods */
static GimpColorSelectorMethods methods =
#define COLORSEL_TYPE_TRIANGLE (colorsel_triangle_type)
#define COLORSEL_TRIANGLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COLORSEL_TYPE_TRIANGLE, ColorselTriangle))
#define COLORSEL_TRIANGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COLORSEL_TYPE_TRIANGLE, ColorselTriangleClass))
#define COLORSEL_IS_TRIANGLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COLORSEL_TYPE_TRIANGLE))
#define COLORSEL_IS_TRIANGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COLORSEL_TYPE_TRIANGLE))
typedef struct _ColorselTriangle ColorselTriangle;
typedef struct _ColorselTriangleClass ColorselTriangleClass;
struct _ColorselTriangle
{
colorsel_triangle_new,
colorsel_triangle_free,
colorsel_triangle_set_color,
NULL /* set_channel */
GimpColorSelector parent_instance;
GimpHSV hsv;
GimpRGB rgb;
gdouble oldsat;
gdouble oldval;
gint mode;
GtkWidget *preview;
};
struct _ColorselTriangleClass
{
GimpColorSelectorClass parent_class;
};
static GimpModuleInfo info =
static GType colorsel_triangle_get_type (GTypeModule *module);
static void colorsel_triangle_class_init (ColorselTriangleClass *klass);
static void colorsel_triangle_init (ColorselTriangle *triangle);
static void colorsel_triangle_finalize (GObject *object);
static void colorsel_triangle_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv);
static void colorsel_xy_to_triangle_buf (gint x,
gint y,
gdouble hue,
guchar *buf,
gint sx,
gint sy,
gint vx,
gint vy,
gint hx,
gint hy);
static GtkWidget *colorsel_triangle_create_preview (ColorselTriangle *triangle);
static void colorsel_triangle_update_previews (ColorselTriangle *triangle,
gboolean hue_changed);
static gboolean colorsel_triangle_event (GtkWidget *widget,
GdkEvent *event,
ColorselTriangle *triangle);
static GimpModuleInfo colorsel_triangle_info =
{
NULL,
N_("Painter-style color selector as a pluggable color selector"),
"Simon Budig <Simon.Budig@unix-ag.org>",
"v0.03",
@ -94,178 +121,163 @@ static const GtkTargetEntry targets[] =
};
#define COLORWHEELRADIUS (GIMP_COLOR_SELECTOR_SIZE / 2)
#define COLORTRIANGLERADIUS (COLORWHEELRADIUS - GIMP_COLOR_SELECTOR_BAR_SIZE)
#define PREVIEWSIZE (2 * COLORWHEELRADIUS + 1)
static GType colorsel_triangle_type = 0;
static GimpColorSelectorClass *parent_class = NULL;
#define BGCOLOR 180
#define PREVIEW_MASK GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON_MOTION_MASK
typedef enum
G_MODULE_EXPORT gboolean
gimp_module_register (GTypeModule *module,
GimpModuleInfo **info_return)
{
HUE = 0,
SATURATION,
VALUE,
RED,
GREEN,
BLUE,
ALPHA
} ColorSelectFillType;
colorsel_triangle_get_type (module);
struct _ColorSelect
{
GimpHSV hsv;
GimpRGB rgb;
if (info_return)
*info_return = &colorsel_triangle_info;
gdouble oldsat;
gdouble oldval;
gint mode;
GtkWidget *preview;
GimpColorSelectorCallback callback;
gpointer data;
};
typedef struct _ColorSelect ColorSelect;
static GtkWidget * create_preview (ColorSelect *coldata);
static void update_previews (ColorSelect *coldata,
gboolean hue_changed);
/*************************************************************/
/* globaly exported init function */
G_MODULE_EXPORT GimpModuleStatus
module_init (GimpModuleInfo **inforet)
{
GimpColorSelectorID id;
#ifndef __EMX__
id = gimp_color_selector_register (_("Triangle"), "triangle.html", &methods);
#else
id = mod_color_selector_register (_("Triangle"), "triangle.html", &methods);
#endif
if (id)
{
info.shutdown_data = id;
*inforet = &info;
return GIMP_MODULE_OK;
}
else
{
return GIMP_MODULE_UNLOAD;
}
return TRUE;
}
G_MODULE_EXPORT void
module_unload (gpointer shutdown_data,
GimpColorSelectorFinishedCB completed_cb,
gpointer completed_data)
static GType
colorsel_triangle_get_type (GTypeModule *module)
{
#ifndef __EMX__
gimp_color_selector_unregister (shutdown_data, completed_cb, completed_data);
#else
mod_color_selector_unregister (shutdown_data, completed_cb, completed_data);
#endif
if (! colorsel_triangle_type)
{
static const GTypeInfo select_info =
{
sizeof (ColorselTriangleClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) colorsel_triangle_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (ColorselTriangle),
0, /* n_preallocs */
(GInstanceInitFunc) colorsel_triangle_init,
};
colorsel_triangle_type =
g_type_module_register_type (module,
GIMP_TYPE_COLOR_SELECTOR,
"ColorselTriangle",
&select_info, 0);
}
return colorsel_triangle_type;
}
/*************************************************************/
/* methods */
static GtkWidget *
colorsel_triangle_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer callback_data,
/* RETURNS: */
gpointer *selector_data)
static void
colorsel_triangle_class_init (ColorselTriangleClass *klass)
{
ColorSelect *coldata;
GtkWidget *preview;
GtkWidget *frame;
GtkWidget *hbox;
GtkWidget *vbox;
GObjectClass *object_class;
GimpColorSelectorClass *selector_class;
coldata = g_new (ColorSelect, 1);
object_class = G_OBJECT_CLASS (klass);
selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
coldata->hsv = *hsv;
coldata->rgb = *rgb;
parent_class = g_type_class_peek_parent (klass);
coldata->oldsat = 0;
coldata->oldval = 0;
object_class->finalize = colorsel_triangle_finalize;
coldata->mode = 0;
selector_class->name = _("Triangle");
selector_class->help_page = "triangle.html";
selector_class->set_color = colorsel_triangle_set_color;
}
coldata->callback = callback;
coldata->data = callback_data;
static void
colorsel_triangle_init (ColorselTriangle *triangle)
{
GtkWidget *frame;
GtkWidget *hbox;
preview = create_preview (coldata);
coldata->preview = preview;
gimp_rgba_set (&triangle->rgb, 1.0, 1.0, 1.0, 1.0);
gimp_rgb_to_hsv (&triangle->rgb, &triangle->hsv);
update_previews (coldata, TRUE);
*selector_data = coldata;
vbox = gtk_vbox_new (FALSE, 0);
triangle->oldsat = 0;
triangle->oldval = 0;
triangle->mode = 0;
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (triangle), hbox, TRUE, FALSE, 0);
gtk_widget_show (hbox);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (frame), preview);
gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, FALSE, 0);
gtk_widget_show_all (vbox);
gtk_widget_show (frame);
return vbox;
triangle->preview = colorsel_triangle_create_preview (triangle);
gtk_container_add (GTK_CONTAINER (frame), triangle->preview);
gtk_widget_show (triangle->preview);
colorsel_triangle_update_previews (triangle, TRUE);
}
static void
colorsel_triangle_free (gpointer selector_data)
colorsel_triangle_finalize (GObject *object)
{
/* anything else needed to go? */
g_free (selector_data);
ColorselTriangle *triangle;
triangle = COLORSEL_TRIANGLE (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
colorsel_triangle_set_color (gpointer selector_data,
const GimpHSV *hsv,
const GimpRGB *rgb)
colorsel_triangle_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv)
{
ColorSelect *coldata;
ColorselTriangle *triangle;
coldata = selector_data;
triangle = COLORSEL_TRIANGLE (selector);
coldata->hsv = *hsv;
coldata->rgb = *rgb;
triangle->rgb = *rgb;
triangle->hsv = *hsv;
update_previews (coldata, TRUE);
colorsel_triangle_update_previews (triangle, TRUE);
}
/*************************************************************/
/* helper functions */
static void
update_previews (ColorSelect *coldata,
gint hue_changed)
static GtkWidget *
colorsel_triangle_create_preview (ColorselTriangle *triangle)
{
GtkWidget *preview;
guchar buf[3 * PREVIEWSIZE];
gint x, y, k, r2, dx, col;
gint x0, y0;
gdouble hue, sat, val, atn;
gint hx,hy, sx,sy, vx,vy;
gint i;
hue = (gdouble) coldata->hsv.h * 2 * G_PI;
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_preview_set_dither (GTK_PREVIEW (preview), GDK_RGB_DITHER_MAX);
gtk_widget_set_events (GTK_WIDGET (preview), PREVIEW_MASK );
gtk_preview_size (GTK_PREVIEW (preview), PREVIEWSIZE, PREVIEWSIZE);
g_signal_connect (G_OBJECT (preview), "motion_notify_event",
G_CALLBACK (colorsel_triangle_event),
triangle);
g_signal_connect (G_OBJECT (preview), "button_press_event",
G_CALLBACK (colorsel_triangle_event),
triangle);
g_signal_connect (G_OBJECT (preview), "button_release_event",
G_CALLBACK (colorsel_triangle_event),
triangle);
for (i=0; i < 3 * PREVIEWSIZE; i += 3)
buf[i] = buf[i+1] = buf[i+2] = BGCOLOR;
for (i=0; i < PREVIEWSIZE; i++)
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, PREVIEWSIZE);
return preview;
}
static void
colorsel_triangle_update_previews (ColorselTriangle *triangle,
gboolean hue_changed)
{
guchar buf[3 * PREVIEWSIZE];
gint x, y, k, r2, dx, col;
gint x0, y0;
gdouble hue, sat, val, atn;
gint hx,hy, sx,sy, vx,vy;
hue = (gdouble) triangle->hsv.h * 2 * G_PI;
/* Colored point (value = 1, saturation = 1) */
hx = RINT (sin (hue) * COLORTRIANGLERADIUS);
@ -279,8 +291,7 @@ update_previews (ColorSelect *coldata,
vx = RINT (sin (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS);
vy = RINT (cos (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS);
hue = coldata->hsv.h * 360.0;
preview = coldata->preview;
hue = triangle->hsv.h * 360.0;
if (hue_changed)
{
@ -310,7 +321,7 @@ update_previews (ColorSelect *coldata,
k += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
gtk_preview_draw_row (GTK_PREVIEW (triangle->preview), buf,
COLORWHEELRADIUS - dx,
COLORWHEELRADIUS - y, 2 * dx + 1);
}
@ -352,7 +363,7 @@ update_previews (ColorSelect *coldata,
k += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
gtk_preview_draw_row (GTK_PREVIEW (triangle->preview), buf,
COLORWHEELRADIUS + x0 - 4,
COLORWHEELRADIUS - y, 9);
}
@ -361,8 +372,8 @@ update_previews (ColorSelect *coldata,
{
/* delete marker in triangle */
sat = coldata->oldsat;
val = coldata->oldval;
sat = triangle->oldsat;
val = triangle->oldval;
x0 = RINT (sx + (vx - sx) * val + (hx - vx) * sat * val);
y0 = RINT (sy + (vy - sy) * val + (hy - vy) * sat * val);
@ -388,7 +399,7 @@ update_previews (ColorSelect *coldata,
k += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
gtk_preview_draw_row (GTK_PREVIEW (triangle->preview), buf,
COLORWHEELRADIUS + x0 - 4,
COLORWHEELRADIUS - y, 9);
}
@ -396,10 +407,10 @@ update_previews (ColorSelect *coldata,
/* marker in triangle */
col = gimp_rgb_intensity (&coldata->rgb) > 0.5 ? 0 : 255;
col = gimp_rgb_intensity (&triangle->rgb) > 0.5 ? 0 : 255;
sat = coldata->oldsat = coldata->hsv.s;
val = coldata->oldval = coldata->hsv.v;
sat = triangle->oldsat = triangle->hsv.s;
val = triangle->oldval = triangle->hsv.v;
x0 = RINT (sx + (vx - sx) * val + (hx - vx) * sat * val);
y0 = RINT (sy + (vy - sy) * val + (hy - vy) * sat * val);
@ -433,20 +444,25 @@ update_previews (ColorSelect *coldata,
k += 3;
}
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
gtk_preview_draw_row (GTK_PREVIEW (triangle->preview), buf,
COLORWHEELRADIUS + x0 - 4,
COLORWHEELRADIUS - y, 9);
}
gtk_widget_draw (preview, NULL);
gtk_widget_queue_draw (triangle->preview);
}
static void
colorsel_xy_to_triangle_buf (const gint x, const gint y,
const gdouble hue, guchar *buf,
const gint hx, const gint hy, /* colored point */
const gint sx, const gint sy, /* black point */
const gint vx, const gint vy) /* white point */
colorsel_xy_to_triangle_buf (gint x,
gint y,
gdouble hue,
guchar *buf,
gint hx,
gint hy, /* colored point */
gint sx,
gint sy, /* black point */
gint vx,
gint vy) /* white point */
{
gdouble sat, val;
@ -476,21 +492,15 @@ colorsel_xy_to_triangle_buf (const gint x, const gint y,
}
}
/*
* Color Preview
*/
static gint
color_selection_callback (GtkWidget *widget,
GdkEvent *event)
static gboolean
colorsel_triangle_event (GtkWidget *widget,
GdkEvent *event,
ColorselTriangle *triangle)
{
ColorSelect *coldata;
gint x,y, angle, mousex, mousey;
gdouble r;
gdouble hue, sat, val;
gint hx,hy, sx,sy, vx,vy;
coldata = g_object_get_data (G_OBJECT (widget), "colorselect");
gint x,y, angle, mousex, mousey;
gdouble r;
gdouble hue, sat, val;
gint hx,hy, sx,sy, vx,vy;
switch (event->type)
{
@ -501,9 +511,9 @@ color_selection_callback (GtkWidget *widget,
r = sqrt ((gdouble) (x * x + y * y));
angle = ((gint) RINT (atan2 (x, y) / G_PI * 180) + 360 ) % 360;
if ( /* r <= COLORWHEELRADIUS && */ r > COLORTRIANGLERADIUS)
coldata->mode = 1; /* Dragging in the Ring */
triangle->mode = 1; /* Dragging in the Ring */
else
coldata->mode = 2; /* Dragging in the Triangle */
triangle->mode = 2; /* Dragging in the Triangle */
break;
case GDK_MOTION_NOTIFY:
@ -514,13 +524,13 @@ color_selection_callback (GtkWidget *widget,
break;
case GDK_BUTTON_RELEASE:
coldata->mode = 0;
triangle->mode = 0;
gtk_grab_remove (widget);
/* callback the user */
(* coldata->callback) (coldata->data,
&coldata->hsv,
&coldata->rgb);
gimp_color_selector_color_changed (GIMP_COLOR_SELECTOR (triangle),
&triangle->rgb,
&triangle->hsv);
return FALSE;
break;
@ -539,25 +549,25 @@ color_selection_callback (GtkWidget *widget,
(mousex != event->motion.x || mousey != event->motion.y)))
return FALSE;
if (coldata->mode == 1 ||
if (triangle->mode == 1 ||
(r > COLORWHEELRADIUS &&
(abs (angle - coldata->hsv.h * 360.0) < 30 ||
abs (abs (angle - coldata->hsv.h * 360.0) - 360) < 30)))
(abs (angle - triangle->hsv.h * 360.0) < 30 ||
abs (abs (angle - triangle->hsv.h * 360.0) - 360) < 30)))
{
coldata->hsv.h = angle / 360.0;
gimp_hsv_to_rgb (&coldata->hsv, &coldata->rgb);
update_previews (coldata, TRUE);
triangle->hsv.h = angle / 360.0;
gimp_hsv_to_rgb (&triangle->hsv, &triangle->rgb);
colorsel_triangle_update_previews (triangle, TRUE);
}
else
{
hue = coldata->hsv.h * 2 * G_PI;
hue = triangle->hsv.h * 2 * G_PI;
hx = sin (hue) * COLORTRIANGLERADIUS;
hy = cos (hue) * COLORTRIANGLERADIUS;
sx = sin (hue - 2 * G_PI / 3) * COLORTRIANGLERADIUS;
sy = cos (hue - 2 * G_PI / 3) * COLORTRIANGLERADIUS;
vx = sin (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS;
vy = cos (hue + 2 * G_PI / 3) * COLORTRIANGLERADIUS;
hue = coldata->hsv.h * 360.0;
hue = triangle->hsv.h * 360.0;
if ((x - sx) * vx + (y - sy) * vy < 0)
{
@ -613,50 +623,16 @@ color_selection_callback (GtkWidget *widget,
}
}
coldata->hsv.s = sat;
coldata->hsv.v = val;
gimp_hsv_to_rgb (&coldata->hsv, &coldata->rgb);
update_previews (coldata, FALSE);
triangle->hsv.s = sat;
triangle->hsv.v = val;
gimp_hsv_to_rgb (&triangle->hsv, &triangle->rgb);
colorsel_triangle_update_previews (triangle, FALSE);
}
/* callback the user */
(* coldata->callback) (coldata->data,
&coldata->hsv,
&coldata->rgb);
gimp_color_selector_color_changed (GIMP_COLOR_SELECTOR (triangle),
&triangle->rgb,
&triangle->hsv);
return FALSE;
}
static GtkWidget *
create_preview (ColorSelect *coldata)
{
GtkWidget *preview;
guchar buf[3 * PREVIEWSIZE];
gint i;
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_preview_set_dither (GTK_PREVIEW (preview), GDK_RGB_DITHER_MAX);
gtk_widget_set_events (GTK_WIDGET (preview), PREVIEW_MASK );
gtk_preview_size (GTK_PREVIEW (preview), PREVIEWSIZE, PREVIEWSIZE);
g_object_set_data (G_OBJECT (preview), "colorselect", coldata);
g_signal_connect (G_OBJECT (preview), "motion_notify_event",
G_CALLBACK (color_selection_callback),
NULL);
g_signal_connect (G_OBJECT (preview), "button_press_event",
G_CALLBACK (color_selection_callback),
NULL);
g_signal_connect (G_OBJECT (preview), "button_release_event",
G_CALLBACK (color_selection_callback),
NULL);
for (i=0; i < 3 * PREVIEWSIZE; i += 3)
buf[i] = buf[i+1] = buf[i+2] = BGCOLOR;
for (i=0; i < PREVIEWSIZE; i++)
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, i, PREVIEWSIZE);
gtk_widget_draw (preview, NULL);
return preview;
}

View File

@ -22,19 +22,19 @@
#include <stdlib.h>
#include <stdio.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "libgimp/gimpuitypes.h"
#include "libgimp/gimpcolorselector.h"
#include "libgimp/gimpmodule.h"
#include "gimpmodregister.h"
#include "libgimp/gimpintl.h"
@ -42,49 +42,69 @@
#define IMAGE_SIZE GIMP_COLOR_SELECTOR_SIZE
typedef struct
#define COLORSEL_TYPE_WATER (colorsel_water_type)
#define COLORSEL_WATER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COLORSEL_TYPE_WATER, ColorselWater))
#define COLORSEL_WATER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COLORSEL_TYPE_WATER, ColorselWaterClass))
#define COLORSEL_IS_WATER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COLORSEL_TYPE_WATER))
#define COLORSEL_IS_WATER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COLORSEL_TYPE_WATER))
typedef struct _ColorselWater ColorselWater;
typedef struct _ColorselWaterClass ColorselWaterClass;
struct _ColorselWater
{
GimpRGB rgb;
gdouble last_x;
gdouble last_y;
gdouble last_pressure;
GimpColorSelector parent_instance;
gfloat pressure_adjust;
guint32 motion_time;
gint button_state;
GimpRGB rgb;
GimpColorSelectorCallback callback;
gpointer data;
} ColorselWater;
gdouble last_x;
gdouble last_y;
gdouble last_pressure;
gfloat pressure_adjust;
guint32 motion_time;
gint button_state;
};
/* prototypes */
static GtkWidget * colorsel_water_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback,
gpointer ,
gpointer *);
static void colorsel_water_free (gpointer data);
static void colorsel_water_set_color (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb);
static void colorsel_water_update (ColorselWater *colorsel);
/* local methods */
static GimpColorSelectorMethods methods =
struct _ColorselWaterClass
{
colorsel_water_new,
colorsel_water_free,
colorsel_water_set_color,
NULL /* set_channel */
GimpColorSelectorClass parent_class;
};
static GimpModuleInfo info =
static GType colorsel_water_get_type (GTypeModule *module);
static void colorsel_water_class_init (ColorselWaterClass *klass);
static void colorsel_water_init (ColorselWater *water);
static void colorsel_water_finalize (GObject *object);
static void colorsel_water_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv);
static void colorsel_water_update (ColorselWater *water);
static void select_area_draw (GtkWidget *preview);
static gboolean button_press_event (GtkWidget *widget,
GdkEventButton *event,
ColorselWater *water);
static gboolean button_release_event (GtkWidget *widget,
GdkEventButton *event,
ColorselWater *water);
static gboolean motion_notify_event (GtkWidget *widget,
GdkEventMotion *event,
ColorselWater *water);
static gboolean proximity_out_event (GtkWidget *widget,
GdkEventProximity *event,
ColorselWater *water);
static void pressure_adjust_update (GtkAdjustment *adj,
ColorselWater *water);
static GimpModuleInfo colorsel_water_info =
{
NULL,
N_("Watercolor style color selector as a pluggable module"),
"Raph Levien <raph@acm.org>, Sven Neumann <sven@gimp.org>",
"v0.3",
@ -92,52 +112,196 @@ static GimpModuleInfo info =
"May, 10 1999"
};
static const GtkTargetEntry targets[] =
{
{ "application/x-color", 0 }
};
/*************************************************************/
/* globaly exported init function */
G_MODULE_EXPORT GimpModuleStatus
module_init (GimpModuleInfo **inforet)
static GType colorsel_water_type = 0;
static GimpColorSelectorClass *parent_class = NULL;
G_MODULE_EXPORT gboolean
gimp_module_register (GTypeModule *module,
GimpModuleInfo **info_return)
{
GimpColorSelectorID id;
colorsel_water_get_type (module);
#ifndef __EMX__
id = gimp_color_selector_register (_("Watercolor"), "watercolor.html",
&methods);
#else
id = mod_color_selector_register (_("Watercolor"), "watercolor.html",
&methods);
#endif
if (info_return)
*info_return = &colorsel_water_info;
if (id)
return TRUE;
}
static GType
colorsel_water_get_type (GTypeModule *module)
{
if (! colorsel_water_type)
{
info.shutdown_data = id;
*inforet = &info;
return GIMP_MODULE_OK;
}
else
{
return GIMP_MODULE_UNLOAD;
static const GTypeInfo select_info =
{
sizeof (ColorselWaterClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) colorsel_water_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (ColorselWater),
0, /* n_preallocs */
(GInstanceInitFunc) colorsel_water_init,
};
colorsel_water_type =
g_type_module_register_type (module,
GIMP_TYPE_COLOR_SELECTOR,
"ColorselWater",
&select_info, 0);
}
return colorsel_water_type;
}
static void
colorsel_water_class_init (ColorselWaterClass *klass)
{
GObjectClass *object_class;
GimpColorSelectorClass *selector_class;
object_class = G_OBJECT_CLASS (klass);
selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = colorsel_water_finalize;
selector_class->name = _("Watercolor");
selector_class->help_page = "watercolor.html";
selector_class->set_color = colorsel_water_set_color;
}
static void
colorsel_water_init (ColorselWater *water)
{
GtkWidget *preview;
GtkWidget *event_box;
GtkWidget *frame;
GtkWidget *hbox;
GtkWidget *hbox2;
GtkObject *adj;
GtkWidget *scale;
water->pressure_adjust = 1.0;
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (water), hbox, TRUE, FALSE, 0);
hbox2 = gtk_hbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (hbox), hbox2, TRUE, FALSE, 0);
/* the event box */
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (hbox2), frame, FALSE, FALSE, 0);
event_box = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (frame), event_box);
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_preview_size (GTK_PREVIEW (preview), IMAGE_SIZE, IMAGE_SIZE);
gtk_container_add (GTK_CONTAINER (event_box), preview);
select_area_draw (preview);
/* Event signals */
g_signal_connect (G_OBJECT (event_box), "motion_notify_event",
G_CALLBACK (motion_notify_event),
water);
g_signal_connect (G_OBJECT (event_box), "button_press_event",
G_CALLBACK (button_press_event),
water);
g_signal_connect (G_OBJECT (event_box), "button_release_event",
G_CALLBACK (button_release_event),
water);
g_signal_connect (G_OBJECT (event_box), "proximity_out_event",
G_CALLBACK (proximity_out_event),
water);
gtk_widget_set_events (event_box,
GDK_EXPOSURE_MASK |
GDK_LEAVE_NOTIFY_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_KEY_PRESS_MASK |
GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK |
GDK_PROXIMITY_OUT_MASK);
/* The following call enables tracking and processing of extension
* events for the drawing area
*/
gtk_widget_set_extension_events (event_box, GDK_EXTENSION_EVENTS_ALL);
gtk_widget_grab_focus (event_box);
adj = gtk_adjustment_new (200.0 - water->pressure_adjust * 100.0,
0.0, 200.0, 1.0, 1.0, 0.0);
g_signal_connect (G_OBJECT (adj), "value_changed",
G_CALLBACK (pressure_adjust_update),
water);
scale = gtk_vscale_new (GTK_ADJUSTMENT (adj));
gtk_scale_set_digits (GTK_SCALE (scale), 0);
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
gimp_help_set_help_data (scale, _("Pressure"), NULL);
gtk_box_pack_start (GTK_BOX (hbox2), scale, FALSE, FALSE, 0);
gtk_widget_show_all (hbox);
}
static void
colorsel_water_finalize (GObject *object)
{
ColorselWater *water;
water = COLORSEL_WATER (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
colorsel_water_set_color (GimpColorSelector *selector,
const GimpRGB *rgb,
const GimpHSV *hsv)
{
ColorselWater *water;
water = COLORSEL_WATER (selector);
water->rgb = *rgb;
}
static void
colorsel_water_update (ColorselWater *water)
{
GimpHSV hsv;
gimp_rgb_to_hsv (&water->rgb, &hsv);
gimp_color_selector_color_changed (GIMP_COLOR_SELECTOR (water),
&water->rgb, &hsv);
}
G_MODULE_EXPORT void
module_unload (gpointer shutdown_data,
GimpColorSelectorFinishedCB completed_cb,
gpointer completed_data)
{
#ifndef __EMX__
gimp_color_selector_unregister (shutdown_data, completed_cb, completed_data);
#else
mod_color_selector_unregister (shutdown_data, completed_cb, completed_data);
#endif
}
static gdouble
@ -250,260 +414,121 @@ draw_brush (ColorselWater *colorsel,
add_pigment (colorsel, erase, x, y, much);
colorsel->last_x = x;
colorsel->last_y = y;
colorsel->last_x = x;
colorsel->last_y = y;
colorsel->last_pressure = pressure;
}
static gint
static gboolean
button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer data)
ColorselWater *water)
{
ColorselWater *colorsel;
gboolean erase;
gboolean erase = FALSE;
colorsel = (ColorselWater *) data;
water->last_x = event->x;
water->last_y = event->y;
water->last_pressure = 1.0; /* FIXME: event->pressure */
colorsel->last_x = event->x;
colorsel->last_y = event->y;
colorsel->last_pressure = event->pressure;
water->button_state |= 1 << event->button;
colorsel->button_state |= 1 << event->button;
erase = (event->button != 1) || FALSE;
/* FIXME: (event->source == GDK_SOURCE_ERASER) */
erase = (event->button != 1) ||
(event->source == GDK_SOURCE_ERASER);
add_pigment (colorsel, erase, event->x, event->y, 0.05);
colorsel->motion_time = event->time;
add_pigment (water, erase, event->x, event->y, 0.05);
water->motion_time = event->time;
return FALSE;
}
static gint
static gboolean
button_release_event (GtkWidget *widget,
GdkEventButton *event,
gpointer data)
ColorselWater *water)
{
ColorselWater *colorsel;
colorsel = (ColorselWater *) data;
colorsel->button_state &= ~(1 << event->button);
water->button_state &= ~(1 << event->button);
return TRUE;
}
static gint
static gboolean
motion_notify_event (GtkWidget *widget,
GdkEventMotion *event,
gpointer data)
ColorselWater *water)
{
ColorselWater *colorsel;
GdkTimeCoord *coords;
GdkTimeCoord **coords;
gint nevents;
gint i;
gboolean erase;
colorsel = (ColorselWater *) data;
if (event->state & (GDK_BUTTON1_MASK |
GDK_BUTTON2_MASK |
GDK_BUTTON3_MASK |
GDK_BUTTON4_MASK))
{
coords = gdk_input_motion_events (event->window, event->deviceid,
colorsel->motion_time, event->time,
&nevents);
erase = (event->state &
(GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK)) ||
(event->source == GDK_SOURCE_ERASER);
guint32 last_motion_time;
colorsel->motion_time = event->time;
last_motion_time = event->time;
if (coords)
{
for (i=0; i<nevents; i++)
draw_brush (colorsel, widget,
erase,
coords[i].x,
coords[i].y,
coords[i].pressure);
erase = ((event->state &
(GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK)) ||
FALSE);
/* FIXME: (event->source == GDK_SOURCE_ERASER) */
water->motion_time = event->time;
if (gdk_device_get_history (event->device,
event->window,
last_motion_time,
event->time,
&coords,
&nevents))
{
for (i = 0; i < nevents; i++)
{
gdouble x = 0.0;
gdouble y = 0.0;
gdouble pressure = 0.5;
gdk_device_get_axis (event->device, coords[i]->axes,
GDK_AXIS_X, &x);
gdk_device_get_axis (event->device, coords[i]->axes,
GDK_AXIS_Y, &y);
gdk_device_get_axis (event->device, coords[i]->axes,
GDK_AXIS_PRESSURE, &pressure);
draw_brush (water, widget, erase, x, y, pressure);
}
g_free (coords);
}
else
{
if (event->is_hint)
gdk_input_window_get_pointer (event->window, event->deviceid,
NULL, NULL, NULL, NULL, NULL, NULL);
gdouble pressure = 0.5;
draw_brush (colorsel, widget,
erase,
event->x,
event->y,
event->pressure);
gdk_event_get_axis ((GdkEvent *) event, GDK_AXIS_PRESSURE, &pressure);
draw_brush (water, widget, erase, event->x, event->y, pressure);
}
}
else
{
gdk_input_window_get_pointer (event->window, event->deviceid,
&event->x, &event->y,
NULL, NULL, NULL, NULL);
}
if (event->is_hint)
gdk_device_get_state (event->device, event->window, NULL, NULL);
return TRUE;
}
static gint
static gboolean
proximity_out_event (GtkWidget *widget,
GdkEventProximity *event,
gpointer data)
ColorselWater *water)
{
ColorselWater *colorsel;
colorsel = (ColorselWater *) data;
return TRUE;
}
static void
pressure_adjust_update (GtkAdjustment *adj,
gpointer data)
ColorselWater *water)
{
ColorselWater *colorsel;
colorsel = (ColorselWater *) data;
colorsel->pressure_adjust = (adj->upper - adj->value) / 100.0;
}
/***********/
/* methods */
static GtkWidget*
colorsel_water_new (const GimpHSV *hsv,
const GimpRGB *rgb,
gboolean show_alpha,
GimpColorSelectorCallback callback,
gpointer callback_data,
/* RETURNS: */
gpointer *selector_data)
{
ColorselWater *coldata;
GtkWidget *preview;
GtkWidget *event_box;
GtkWidget *frame;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *hbox2;
GtkObject *adj;
GtkWidget *scale;
coldata = g_new (ColorselWater, 1);
coldata->pressure_adjust = 1.0;
coldata->callback = callback;
coldata->data = callback_data;
*selector_data = coldata;
vbox = gtk_vbox_new (FALSE, 0);
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
hbox2 = gtk_hbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (hbox), hbox2, TRUE, FALSE, 0);
/* the event box */
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (hbox2), frame, FALSE, FALSE, 0);
event_box = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (frame), event_box);
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_preview_size (GTK_PREVIEW (preview), IMAGE_SIZE, IMAGE_SIZE);
gtk_container_add (GTK_CONTAINER (event_box), preview);
select_area_draw (preview);
/* Event signals */
g_signal_connect (G_OBJECT (event_box), "motion_notify_event",
G_CALLBACK (motion_notify_event),
coldata);
g_signal_connect (G_OBJECT (event_box), "button_press_event",
G_CALLBACK (button_press_event),
coldata);
g_signal_connect (G_OBJECT (event_box), "button_release_event",
G_CALLBACK (button_release_event),
coldata);
g_signal_connect (G_OBJECT (event_box), "proximity_out_event",
G_CALLBACK (proximity_out_event),
coldata);
gtk_widget_set_events (event_box,
GDK_EXPOSURE_MASK |
GDK_LEAVE_NOTIFY_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_KEY_PRESS_MASK |
GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK |
GDK_PROXIMITY_OUT_MASK);
/* The following call enables tracking and processing of extension
* events for the drawing area
*/
gtk_widget_set_extension_events (event_box, GDK_EXTENSION_EVENTS_ALL);
gtk_widget_grab_focus (event_box);
adj = gtk_adjustment_new (200.0 - coldata->pressure_adjust * 100.0,
0.0, 200.0, 1.0, 1.0, 0.0);
g_signal_connect (G_OBJECT (adj), "value_changed",
G_CALLBACK (pressure_adjust_update),
coldata);
scale = gtk_vscale_new (GTK_ADJUSTMENT (adj));
gtk_scale_set_digits (GTK_SCALE (scale), 0);
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
gimp_help_set_help_data (scale, _("Pressure"), NULL);
gtk_box_pack_start (GTK_BOX (hbox2), scale, FALSE, FALSE, 0);
gtk_widget_show_all (vbox);
colorsel_water_set_color (coldata, hsv, rgb);
return vbox;
}
static void
colorsel_water_free (gpointer selector_data)
{
g_free (selector_data);
}
static void
colorsel_water_set_color (gpointer data,
const GimpHSV *hsv,
const GimpRGB *rgb)
{
ColorselWater *colorsel;
colorsel = (ColorselWater *) data;
colorsel->rgb = *rgb;
}
static void
colorsel_water_update (ColorselWater *colorsel)
{
GimpHSV hsv;
gimp_rgb_to_hsv (&colorsel->rgb, &hsv);
colorsel->callback (colorsel->data, &hsv, &colorsel->rgb);
water->pressure_adjust = (adj->upper - adj->value) / 100.0;
}

View File

@ -1,127 +0,0 @@
/*
* 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.
*
*
*/
#ifdef __EMX__
#include "config.h"
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <libgimp/gimpmodule.h>
#include <math.h>
#include "gimpmodregister.h"
struct main_funcs_struc *gimp_main_funcs = NULL;
gpointer get_main_func(gchar *name)
{
struct main_funcs_struc *x;
if (gimp_main_funcs == NULL)
return NULL;
for (x = gimp_main_funcs; x->name; x++)
{
if (!strcmp(x->name, name))
return (gpointer) x->func;
}
}
GimpColorSelectorID
mod_color_selector_register (const char *name,
const char *help_page,
GimpColorSelectorMethods *methods)
{
GimpColorSelectorID id;
color_reg_func reg_func;
reg_func = (color_reg_func) get_main_func("gimp_color_selector_register");
if (!reg_func)
return 0;
id = (*reg_func) (name, help_page, methods);
return (id);
}
G_MODULE_EXPORT gboolean
mod_color_display_register (const char *name,
GimpColorDisplayMethods *methods)
{
gboolean retval;
display_reg_func reg_func;
reg_func = (display_reg_func) get_main_func("gimp_color_display_register");
if (!reg_func)
return 0;
retval = (*reg_func) (name, methods);
return (retval);
}
gboolean
mod_color_selector_unregister (GimpColorSelectorID id,
void (*callback)(void *data),
void *data)
{
color_unreg_func unreg_func;
gboolean status;
unreg_func = (color_unreg_func) get_main_func("gimp_color_selector_unregister");
if (unreg_func)
{
status = (*unreg_func) (id, callback, data);
}
else
status = FALSE;
return (status);
}
G_MODULE_EXPORT gboolean
mod_color_display_unregister (const char *name)
{
display_unreg_func unreg_func;
gboolean status;
unreg_func = (display_unreg_func) get_main_func("gimp_color_display_unregister");
if (unreg_func)
{
status = (*unreg_func) (name);
}
else
status = FALSE;
return (status);
}
void mod_dialog_register (GtkWidget *dialog)
{
dialog_reg_func reg_func;
reg_func = (dialog_reg_func) get_main_func("dialog_register");
if (!reg_func)
return;
(*reg_func) (dialog);
}
void mod_dialog_unregister (GtkWidget *dialog)
{
dialog_reg_func reg_func;
reg_func = (dialog_reg_func) get_main_func("dialog_unregister");
if (!reg_func)
return;
(*reg_func) (dialog);
}
#endif

View File

@ -1,70 +0,0 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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.
*/
#ifndef __MODREGISTER_H__
#define __MODREGISTER_H__
#ifdef __EMX__
#include <libgimp/gimptypes.h>
#include <libgimp/gimpcolordisplay.h>
#include <libgimp/gimpcolorselector.h>
struct main_funcs_struc {
gchar *name;
void (*func)();
};
typedef GimpColorSelectorID (*color_reg_func)(const char *,
const char *,
GimpColorSelectorMethods *);
typedef G_MODULE_EXPORT gboolean (*display_reg_func)
(const char *,GimpColorDisplayMethods *);
typedef gboolean (*color_unreg_func) (GimpColorSelectorID,
void (*)(void *),
void *);
typedef G_MODULE_EXPORT gboolean (*display_unreg_func) (const char *name);
typedef void (*dialog_reg_func) (GtkWidget *dialog);
void mod_dialog_register (GtkWidget *dialog);
void mod_dialog_unregister (GtkWidget *dialog);
#define dialog_register mod_dialog_register
#define dialog_unregister mod_dialog_unregister
GimpColorSelectorID
mod_color_selector_register (const char *name,
const char *help_page,
GimpColorSelectorMethods *methods);
gboolean
mod_color_selector_unregister (GimpColorSelectorID id,
void (*callback)(void *data),
void *data);
G_MODULE_EXPORT gboolean
mod_color_display_register (const char *name,
GimpColorDisplayMethods *methods);
G_MODULE_EXPORT gboolean
mod_color_display_unregister (const char *name);
#endif
#endif /* __MODREGISTER_H__ */