1998-11-06 22:05:02 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* Themes added by The Rasterman <raster@redhat.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
1999-02-24 07:37:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
1998-11-06 22:05:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <gmodule.h>
|
|
|
|
#include "gtkthemes.h"
|
|
|
|
#include "gtkmain.h"
|
|
|
|
#include "gtkrc.h"
|
|
|
|
#include "gtkselection.h"
|
|
|
|
#include "gtksignal.h"
|
|
|
|
#include "gtkwidget.h"
|
|
|
|
#include "config.h"
|
1998-12-18 01:32:33 +00:00
|
|
|
#include "gtkintl.h"
|
1998-11-06 22:05:02 +00:00
|
|
|
|
|
|
|
typedef struct _GtkThemeEnginePrivate GtkThemeEnginePrivate;
|
|
|
|
|
|
|
|
struct _GtkThemeEnginePrivate {
|
|
|
|
GtkThemeEngine engine;
|
|
|
|
|
|
|
|
GModule *library;
|
|
|
|
void *name;
|
|
|
|
|
|
|
|
void (*init) (GtkThemeEngine *);
|
|
|
|
void (*exit) (void);
|
|
|
|
|
|
|
|
guint refcount;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GHashTable *engine_hash = NULL;
|
|
|
|
|
1999-03-07 10:46:34 +00:00
|
|
|
#ifdef __EMX__
|
|
|
|
static void gen_8_3_dll_name(gchar *name, gchar *fullname)
|
|
|
|
{
|
|
|
|
/* 8.3 dll filename restriction */
|
|
|
|
fullname[0] = '_';
|
|
|
|
strncpy (fullname + 1, name, 7);
|
|
|
|
fullname[8] = '\0';
|
|
|
|
strcat (fullname, ".dll");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-11-28 07:42:37 +00:00
|
|
|
GtkThemeEngine*
|
|
|
|
gtk_theme_engine_get (gchar *name)
|
1998-11-06 22:05:02 +00:00
|
|
|
{
|
|
|
|
GtkThemeEnginePrivate *result;
|
|
|
|
|
|
|
|
if (!engine_hash)
|
|
|
|
engine_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
|
|
|
/* get the library name for the theme */
|
|
|
|
|
|
|
|
result = g_hash_table_lookup (engine_hash, name);
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
{
|
This might seem like a large patch, but it isn't that bad, and nothing
should break on Unix/X11.
Win32 merge and general portability stuff:
* acconfig.h,configure.in: Check for <sys/time.h>.
* gdk/win32: New directory (actually, been there for a while).
* gtk/fnmatch.c: Include <glib.h> for G_DIR_SEPARATOR, WIN32 and
NATIVE_WIN32, and use these. Always case fold on Win32. No
backslashed escapes on native Win32.
* gtk/{gtk.def,makefile.msc}: New files.
* gtk/Makefile.am: Add above new files.
* gtk/{gtkaccelgroup,gtkbindings}.c: Include <string.h>
instead of <strings.h>.
* gtk/{gtkcalendar,gtkitemfactory,gtkpreview,gtkrc}.c: Include
config.h. Protect inclusion of <sys/param.h>, <sys/time.h>, and
<unistd.h> appropriately.
* gtk/gtkdnd.c: Merge in Win32 version (which doesn't do much).
Use ABS() (from <glib.h>) instead of abs().
* gtk/gtkfilesel.c: Moved Win32-specific includes after inclusion
of gtk (and thus glib) headers, so that WIN32 will be
defined. With MS C, include <direct.h> for mkdir prototype.
* gtk/gtkitemfactory.c (gtk_item_factory_callback_marshal): Add
some casts, needed by MS C.
* gtk/{gtklayout,gtkplug}.c: Merge in Win32 version (which isn't
implemented).
* gtk/gtkmain.c: Include gdk/gdkx.h for GDK_WINDOWING. Include
<X11/Xlocale.h> only on X11 platform, otherwise <locale.h>. Use
G_SEARCHPATH_SEPARATOR_S and g_module_build_path.
* gtk/gtkmain.h: Mark variables for export/import on Win32.
* gtk/gtkrange.c (gtk_range_motion_notify): Set mods also in case
the event is not a hint, or its window is not the slider. Needed
on Win32, at least.
* gtk/gtkrc.c: Include config.h and gdk/gdkx.h. Use <locale.h>
unless on X11. Skip \r chars, too. Use G_DIR_SEPARATOR and
G_SEARCHPATH_SEPARATOR(_S). Use g_path_is_absolute. On Win32, use
a subdirectory of the Windows directory as gtk system
configuration directory.
* gtk/gtkselection.c: No chunks on Win32.
* gtk/gtksocket.c: Not implemented on Win32.
* gtk/gtkthemes.c (gtk_theme_engine_get): Use g_module_build_path.
* gtk/makeenums.h: Include gdkprivate.h after gdk.h.
* gtk/testrgb.c: Use dynamically allocated buffer. Use GTimers.
1999-03-15 00:03:37 +00:00
|
|
|
gchar *fullname;
|
1998-11-06 22:05:02 +00:00
|
|
|
gchar *engine_path;
|
|
|
|
GModule *library;
|
|
|
|
|
1999-03-07 10:46:34 +00:00
|
|
|
#ifndef __EMX__
|
This might seem like a large patch, but it isn't that bad, and nothing
should break on Unix/X11.
Win32 merge and general portability stuff:
* acconfig.h,configure.in: Check for <sys/time.h>.
* gdk/win32: New directory (actually, been there for a while).
* gtk/fnmatch.c: Include <glib.h> for G_DIR_SEPARATOR, WIN32 and
NATIVE_WIN32, and use these. Always case fold on Win32. No
backslashed escapes on native Win32.
* gtk/{gtk.def,makefile.msc}: New files.
* gtk/Makefile.am: Add above new files.
* gtk/{gtkaccelgroup,gtkbindings}.c: Include <string.h>
instead of <strings.h>.
* gtk/{gtkcalendar,gtkitemfactory,gtkpreview,gtkrc}.c: Include
config.h. Protect inclusion of <sys/param.h>, <sys/time.h>, and
<unistd.h> appropriately.
* gtk/gtkdnd.c: Merge in Win32 version (which doesn't do much).
Use ABS() (from <glib.h>) instead of abs().
* gtk/gtkfilesel.c: Moved Win32-specific includes after inclusion
of gtk (and thus glib) headers, so that WIN32 will be
defined. With MS C, include <direct.h> for mkdir prototype.
* gtk/gtkitemfactory.c (gtk_item_factory_callback_marshal): Add
some casts, needed by MS C.
* gtk/{gtklayout,gtkplug}.c: Merge in Win32 version (which isn't
implemented).
* gtk/gtkmain.c: Include gdk/gdkx.h for GDK_WINDOWING. Include
<X11/Xlocale.h> only on X11 platform, otherwise <locale.h>. Use
G_SEARCHPATH_SEPARATOR_S and g_module_build_path.
* gtk/gtkmain.h: Mark variables for export/import on Win32.
* gtk/gtkrange.c (gtk_range_motion_notify): Set mods also in case
the event is not a hint, or its window is not the slider. Needed
on Win32, at least.
* gtk/gtkrc.c: Include config.h and gdk/gdkx.h. Use <locale.h>
unless on X11. Skip \r chars, too. Use G_DIR_SEPARATOR and
G_SEARCHPATH_SEPARATOR(_S). Use g_path_is_absolute. On Win32, use
a subdirectory of the Windows directory as gtk system
configuration directory.
* gtk/gtkselection.c: No chunks on Win32.
* gtk/gtksocket.c: Not implemented on Win32.
* gtk/gtkthemes.c (gtk_theme_engine_get): Use g_module_build_path.
* gtk/makeenums.h: Include gdkprivate.h after gdk.h.
* gtk/testrgb.c: Use dynamically allocated buffer. Use GTimers.
1999-03-15 00:03:37 +00:00
|
|
|
fullname = g_module_build_path (NULL, name);
|
1999-03-07 10:46:34 +00:00
|
|
|
#else
|
This might seem like a large patch, but it isn't that bad, and nothing
should break on Unix/X11.
Win32 merge and general portability stuff:
* acconfig.h,configure.in: Check for <sys/time.h>.
* gdk/win32: New directory (actually, been there for a while).
* gtk/fnmatch.c: Include <glib.h> for G_DIR_SEPARATOR, WIN32 and
NATIVE_WIN32, and use these. Always case fold on Win32. No
backslashed escapes on native Win32.
* gtk/{gtk.def,makefile.msc}: New files.
* gtk/Makefile.am: Add above new files.
* gtk/{gtkaccelgroup,gtkbindings}.c: Include <string.h>
instead of <strings.h>.
* gtk/{gtkcalendar,gtkitemfactory,gtkpreview,gtkrc}.c: Include
config.h. Protect inclusion of <sys/param.h>, <sys/time.h>, and
<unistd.h> appropriately.
* gtk/gtkdnd.c: Merge in Win32 version (which doesn't do much).
Use ABS() (from <glib.h>) instead of abs().
* gtk/gtkfilesel.c: Moved Win32-specific includes after inclusion
of gtk (and thus glib) headers, so that WIN32 will be
defined. With MS C, include <direct.h> for mkdir prototype.
* gtk/gtkitemfactory.c (gtk_item_factory_callback_marshal): Add
some casts, needed by MS C.
* gtk/{gtklayout,gtkplug}.c: Merge in Win32 version (which isn't
implemented).
* gtk/gtkmain.c: Include gdk/gdkx.h for GDK_WINDOWING. Include
<X11/Xlocale.h> only on X11 platform, otherwise <locale.h>. Use
G_SEARCHPATH_SEPARATOR_S and g_module_build_path.
* gtk/gtkmain.h: Mark variables for export/import on Win32.
* gtk/gtkrange.c (gtk_range_motion_notify): Set mods also in case
the event is not a hint, or its window is not the slider. Needed
on Win32, at least.
* gtk/gtkrc.c: Include config.h and gdk/gdkx.h. Use <locale.h>
unless on X11. Skip \r chars, too. Use G_DIR_SEPARATOR and
G_SEARCHPATH_SEPARATOR(_S). Use g_path_is_absolute. On Win32, use
a subdirectory of the Windows directory as gtk system
configuration directory.
* gtk/gtkselection.c: No chunks on Win32.
* gtk/gtksocket.c: Not implemented on Win32.
* gtk/gtkthemes.c (gtk_theme_engine_get): Use g_module_build_path.
* gtk/makeenums.h: Include gdkprivate.h after gdk.h.
* gtk/testrgb.c: Use dynamically allocated buffer. Use GTimers.
1999-03-15 00:03:37 +00:00
|
|
|
fullname = g_malloc (13);
|
1999-03-07 10:46:34 +00:00
|
|
|
gen_8_3_dll_name(name, fullname);
|
|
|
|
#endif
|
1998-11-28 07:42:37 +00:00
|
|
|
engine_path = gtk_rc_find_module_in_path (fullname);
|
1999-03-07 10:46:34 +00:00
|
|
|
#ifdef __EMX__
|
|
|
|
if (!engine_path)
|
|
|
|
{
|
|
|
|
/* try theme name without prefix '_' */
|
|
|
|
memmove(fullname, fullname + 1, strlen(fullname));
|
|
|
|
engine_path = gtk_rc_find_module_in_path (fullname);
|
|
|
|
}
|
|
|
|
#endif
|
1998-11-06 22:05:02 +00:00
|
|
|
|
|
|
|
if (!engine_path)
|
1998-11-28 07:42:37 +00:00
|
|
|
{
|
1998-12-18 01:32:33 +00:00
|
|
|
g_warning (_("Unable to locate loadable module in module_path: \"%s\","),
|
1998-11-28 07:42:37 +00:00
|
|
|
fullname);
|
|
|
|
|
This might seem like a large patch, but it isn't that bad, and nothing
should break on Unix/X11.
Win32 merge and general portability stuff:
* acconfig.h,configure.in: Check for <sys/time.h>.
* gdk/win32: New directory (actually, been there for a while).
* gtk/fnmatch.c: Include <glib.h> for G_DIR_SEPARATOR, WIN32 and
NATIVE_WIN32, and use these. Always case fold on Win32. No
backslashed escapes on native Win32.
* gtk/{gtk.def,makefile.msc}: New files.
* gtk/Makefile.am: Add above new files.
* gtk/{gtkaccelgroup,gtkbindings}.c: Include <string.h>
instead of <strings.h>.
* gtk/{gtkcalendar,gtkitemfactory,gtkpreview,gtkrc}.c: Include
config.h. Protect inclusion of <sys/param.h>, <sys/time.h>, and
<unistd.h> appropriately.
* gtk/gtkdnd.c: Merge in Win32 version (which doesn't do much).
Use ABS() (from <glib.h>) instead of abs().
* gtk/gtkfilesel.c: Moved Win32-specific includes after inclusion
of gtk (and thus glib) headers, so that WIN32 will be
defined. With MS C, include <direct.h> for mkdir prototype.
* gtk/gtkitemfactory.c (gtk_item_factory_callback_marshal): Add
some casts, needed by MS C.
* gtk/{gtklayout,gtkplug}.c: Merge in Win32 version (which isn't
implemented).
* gtk/gtkmain.c: Include gdk/gdkx.h for GDK_WINDOWING. Include
<X11/Xlocale.h> only on X11 platform, otherwise <locale.h>. Use
G_SEARCHPATH_SEPARATOR_S and g_module_build_path.
* gtk/gtkmain.h: Mark variables for export/import on Win32.
* gtk/gtkrange.c (gtk_range_motion_notify): Set mods also in case
the event is not a hint, or its window is not the slider. Needed
on Win32, at least.
* gtk/gtkrc.c: Include config.h and gdk/gdkx.h. Use <locale.h>
unless on X11. Skip \r chars, too. Use G_DIR_SEPARATOR and
G_SEARCHPATH_SEPARATOR(_S). Use g_path_is_absolute. On Win32, use
a subdirectory of the Windows directory as gtk system
configuration directory.
* gtk/gtkselection.c: No chunks on Win32.
* gtk/gtksocket.c: Not implemented on Win32.
* gtk/gtkthemes.c (gtk_theme_engine_get): Use g_module_build_path.
* gtk/makeenums.h: Include gdkprivate.h after gdk.h.
* gtk/testrgb.c: Use dynamically allocated buffer. Use GTimers.
1999-03-15 00:03:37 +00:00
|
|
|
g_free (fullname);
|
1998-11-28 07:42:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
This might seem like a large patch, but it isn't that bad, and nothing
should break on Unix/X11.
Win32 merge and general portability stuff:
* acconfig.h,configure.in: Check for <sys/time.h>.
* gdk/win32: New directory (actually, been there for a while).
* gtk/fnmatch.c: Include <glib.h> for G_DIR_SEPARATOR, WIN32 and
NATIVE_WIN32, and use these. Always case fold on Win32. No
backslashed escapes on native Win32.
* gtk/{gtk.def,makefile.msc}: New files.
* gtk/Makefile.am: Add above new files.
* gtk/{gtkaccelgroup,gtkbindings}.c: Include <string.h>
instead of <strings.h>.
* gtk/{gtkcalendar,gtkitemfactory,gtkpreview,gtkrc}.c: Include
config.h. Protect inclusion of <sys/param.h>, <sys/time.h>, and
<unistd.h> appropriately.
* gtk/gtkdnd.c: Merge in Win32 version (which doesn't do much).
Use ABS() (from <glib.h>) instead of abs().
* gtk/gtkfilesel.c: Moved Win32-specific includes after inclusion
of gtk (and thus glib) headers, so that WIN32 will be
defined. With MS C, include <direct.h> for mkdir prototype.
* gtk/gtkitemfactory.c (gtk_item_factory_callback_marshal): Add
some casts, needed by MS C.
* gtk/{gtklayout,gtkplug}.c: Merge in Win32 version (which isn't
implemented).
* gtk/gtkmain.c: Include gdk/gdkx.h for GDK_WINDOWING. Include
<X11/Xlocale.h> only on X11 platform, otherwise <locale.h>. Use
G_SEARCHPATH_SEPARATOR_S and g_module_build_path.
* gtk/gtkmain.h: Mark variables for export/import on Win32.
* gtk/gtkrange.c (gtk_range_motion_notify): Set mods also in case
the event is not a hint, or its window is not the slider. Needed
on Win32, at least.
* gtk/gtkrc.c: Include config.h and gdk/gdkx.h. Use <locale.h>
unless on X11. Skip \r chars, too. Use G_DIR_SEPARATOR and
G_SEARCHPATH_SEPARATOR(_S). Use g_path_is_absolute. On Win32, use
a subdirectory of the Windows directory as gtk system
configuration directory.
* gtk/gtkselection.c: No chunks on Win32.
* gtk/gtksocket.c: Not implemented on Win32.
* gtk/gtkthemes.c (gtk_theme_engine_get): Use g_module_build_path.
* gtk/makeenums.h: Include gdkprivate.h after gdk.h.
* gtk/testrgb.c: Use dynamically allocated buffer. Use GTimers.
1999-03-15 00:03:37 +00:00
|
|
|
g_free (fullname);
|
1998-11-06 22:05:02 +00:00
|
|
|
|
|
|
|
/* load the lib */
|
1998-12-18 01:32:33 +00:00
|
|
|
|
|
|
|
GTK_NOTE (MISC, g_message ("Loading Theme %s\n", engine_path));
|
1998-11-06 22:05:02 +00:00
|
|
|
|
|
|
|
library = g_module_open (engine_path, 0);
|
|
|
|
g_free(engine_path);
|
|
|
|
if (!library)
|
1999-01-18 18:48:09 +00:00
|
|
|
{
|
|
|
|
g_warning (g_module_error());
|
|
|
|
return NULL;
|
|
|
|
}
|
1998-11-06 22:05:02 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
result = g_new (GtkThemeEnginePrivate, 1);
|
|
|
|
|
|
|
|
result->refcount = 1;
|
|
|
|
result->name = g_strdup (name);
|
|
|
|
result->library = library;
|
|
|
|
|
|
|
|
/* extract symbols from the lib */
|
|
|
|
if (!g_module_symbol (library, "theme_init",
|
|
|
|
(gpointer *)&result->init) ||
|
|
|
|
!g_module_symbol (library, "theme_exit",
|
|
|
|
(gpointer *)&result->exit))
|
|
|
|
{
|
1999-01-18 18:48:09 +00:00
|
|
|
g_warning (g_module_error());
|
1998-11-06 22:05:02 +00:00
|
|
|
g_free (result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* call the theme's init (theme_init) function to let it */
|
|
|
|
/* setup anything it needs to set up. */
|
|
|
|
result->init((GtkThemeEngine *)result);
|
|
|
|
|
|
|
|
g_hash_table_insert (engine_hash, result->name, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result->refcount++;
|
|
|
|
|
|
|
|
return (GtkThemeEngine *)result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_theme_engine_ref (GtkThemeEngine *engine)
|
|
|
|
{
|
|
|
|
g_return_if_fail (engine != NULL);
|
|
|
|
|
|
|
|
((GtkThemeEnginePrivate *)engine)->refcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_theme_engine_unref (GtkThemeEngine *engine)
|
|
|
|
{
|
|
|
|
GtkThemeEnginePrivate *private;
|
|
|
|
|
|
|
|
g_return_if_fail (engine != NULL);
|
|
|
|
|
|
|
|
private = (GtkThemeEnginePrivate *)engine;
|
|
|
|
private->refcount--;
|
|
|
|
|
|
|
|
if (private->refcount == 0)
|
|
|
|
{
|
|
|
|
g_hash_table_remove (engine_hash, private->name);
|
|
|
|
|
|
|
|
g_module_close (private->library);
|
|
|
|
g_free (private->name);
|
|
|
|
g_free (private);
|
|
|
|
}
|
|
|
|
}
|