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.
22 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkthemes.h"
34 #include "gtkselection.h"
35 #include "gtksignal.h"
36 #include "gtkwidget.h"
40 typedef struct _GtkThemeEnginePrivate GtkThemeEnginePrivate;
42 struct _GtkThemeEnginePrivate {
43 GtkThemeEngine engine;
48 void (*init) (GtkThemeEngine *);
54 static GHashTable *engine_hash = NULL;
57 static void gen_8_3_dll_name(gchar *name, gchar *fullname)
59 /* 8.3 dll filename restriction */
61 strncpy (fullname + 1, name, 7);
63 strcat (fullname, ".dll");
68 gtk_theme_engine_get (gchar *name)
70 GtkThemeEnginePrivate *result;
73 engine_hash = g_hash_table_new (g_str_hash, g_str_equal);
75 /* get the library name for the theme */
77 result = g_hash_table_lookup (engine_hash, name);
86 fullname = g_module_build_path (NULL, name);
88 fullname = g_malloc (13);
89 gen_8_3_dll_name(name, fullname);
91 engine_path = gtk_rc_find_module_in_path (fullname);
95 /* try theme name without prefix '_' */
96 memmove(fullname, fullname + 1, strlen(fullname));
97 engine_path = gtk_rc_find_module_in_path (fullname);
103 g_warning (_("Unable to locate loadable module in module_path: \"%s\","),
113 GTK_NOTE (MISC, g_message ("Loading Theme %s\n", engine_path));
115 library = g_module_open (engine_path, 0);
119 g_warning (g_module_error());
124 result = g_new (GtkThemeEnginePrivate, 1);
126 result->refcount = 1;
127 result->name = g_strdup (name);
128 result->library = library;
130 /* extract symbols from the lib */
131 if (!g_module_symbol (library, "theme_init",
132 (gpointer *)&result->init) ||
133 !g_module_symbol (library, "theme_exit",
134 (gpointer *)&result->exit))
136 g_warning (g_module_error());
141 /* call the theme's init (theme_init) function to let it */
142 /* setup anything it needs to set up. */
143 result->init((GtkThemeEngine *)result);
145 g_hash_table_insert (engine_hash, result->name, result);
151 return (GtkThemeEngine *)result;
155 gtk_theme_engine_ref (GtkThemeEngine *engine)
157 g_return_if_fail (engine != NULL);
159 ((GtkThemeEnginePrivate *)engine)->refcount++;
163 gtk_theme_engine_unref (GtkThemeEngine *engine)
165 GtkThemeEnginePrivate *private;
166 private = (GtkThemeEnginePrivate *)engine;
168 g_return_if_fail (engine != NULL);
169 g_return_if_fail (private->refcount > 0);
173 if (private->refcount == 0)
177 g_hash_table_remove (engine_hash, private->name);
179 g_module_close (private->library);
180 g_free (private->name);