1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * Themes added by The Rasterman <raster@redhat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "gtkthemes.h"
26 #include "gtkselection.h"
27 #include "gtksignal.h"
28 #include "gtkwidget.h"
29 #include "gtkprivate.h"
32 typedef struct _GtkThemeEnginePrivate GtkThemeEnginePrivate;
34 struct _GtkThemeEnginePrivate {
35 GtkThemeEngine engine;
40 void (*init) (GtkThemeEngine *);
46 static GHashTable *engine_hash = NULL;
49 gtk_theme_engine_get (gchar *name)
51 GtkThemeEnginePrivate *result;
54 engine_hash = g_hash_table_new (g_str_hash, g_str_equal);
56 /* get the library name for the theme */
58 result = g_hash_table_lookup (engine_hash, name);
66 g_snprintf (fullname, 1024, "lib%s.so", name);
67 engine_path = gtk_rc_find_module_in_path (fullname);
71 g_warning ("Unable to locate loadable module in module_path: \"%s\",",
79 printf ("Loading Theme %s\n", engine_path);
81 library = g_module_open (engine_path, 0);
84 g_error(g_module_error());
87 result = g_new (GtkThemeEnginePrivate, 1);
90 result->name = g_strdup (name);
91 result->library = library;
93 /* extract symbols from the lib */
94 if (!g_module_symbol (library, "theme_init",
95 (gpointer *)&result->init) ||
96 !g_module_symbol (library, "theme_exit",
97 (gpointer *)&result->exit))
99 g_error (g_module_error());
104 /* call the theme's init (theme_init) function to let it */
105 /* setup anything it needs to set up. */
106 result->init((GtkThemeEngine *)result);
108 g_hash_table_insert (engine_hash, result->name, result);
114 return (GtkThemeEngine *)result;
118 gtk_theme_engine_ref (GtkThemeEngine *engine)
120 g_return_if_fail (engine != NULL);
122 ((GtkThemeEnginePrivate *)engine)->refcount++;
126 gtk_theme_engine_unref (GtkThemeEngine *engine)
128 GtkThemeEnginePrivate *private;
130 g_return_if_fail (engine != NULL);
132 private = (GtkThemeEnginePrivate *)engine;
135 if (private->refcount == 0)
137 g_hash_table_remove (engine_hash, private->name);
139 g_module_close (private->library);
140 g_free (private->name);