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 Lesser 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 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser 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-2000. 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"
36 typedef struct _GtkThemeEngineClass GtkThemeEngineClass;
38 struct _GtkThemeEngine
40 GTypeModule parent_instance;
44 void (*init) (GTypeModule *);
46 GtkRcStyle *(*create_rc_style) ();
51 struct _GtkThemeEngineClass
53 GTypeModuleClass parent_class;
56 static GHashTable *engine_hash = NULL;
59 gtk_theme_engine_load (GTypeModule *module)
61 GtkThemeEngine *engine = GTK_THEME_ENGINE (module);
66 fullname = g_module_build_path (NULL, engine->name);
67 engine_path = gtk_rc_find_module_in_path (fullname);
71 g_warning (_("Unable to locate theme engine in module_path: \"%s\","),
82 GTK_NOTE (MISC, g_message ("Loading Theme %s\n", engine_path));
84 engine->library = g_module_open (engine_path, 0);
88 g_warning (g_module_error());
92 /* extract symbols from the lib */
93 if (!g_module_symbol (engine->library, "theme_init",
94 (gpointer *)&engine->init) ||
95 !g_module_symbol (engine->library, "theme_exit",
96 (gpointer *)&engine->exit) ||
97 !g_module_symbol (engine->library, "theme_create_rc_style",
98 (gpointer *)&engine->create_rc_style))
100 g_warning (g_module_error());
101 g_module_close (engine->library);
106 /* call the theme's init (theme_init) function to let it */
107 /* setup anything it needs to set up. */
108 engine->init (module);
114 gtk_theme_engine_unload (GTypeModule *module)
116 GtkThemeEngine *engine = GTK_THEME_ENGINE (module);
120 g_module_close (engine->library);
121 engine->library = NULL;
125 engine->create_rc_style = NULL;
129 gtk_theme_engine_class_init (GtkThemeEngineClass *class)
131 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class);
133 module_class->load = gtk_theme_engine_load;
134 module_class->unload = gtk_theme_engine_unload;
138 gtk_theme_engine_get_type (void)
140 static GType theme_engine_type = 0;
142 if (!theme_engine_type)
144 static const GTypeInfo theme_engine_info = {
145 sizeof (GtkThemeEngineClass),
146 NULL, /* base_init */
147 NULL, /* base_finalize */
148 (GClassInitFunc) gtk_theme_engine_class_init,
149 NULL, /* class_finalize */
150 NULL, /* class_data */
151 sizeof (GtkThemeEngine),
153 NULL, /* instance_init */
156 theme_engine_type = g_type_register_static (G_TYPE_TYPE_MODULE, "GtkThemeEngine", &theme_engine_info, 0);
159 return theme_engine_type;
163 gtk_theme_engine_get (const gchar *name)
165 GtkThemeEngine *result;
168 engine_hash = g_hash_table_new (g_str_hash, g_str_equal);
170 /* get the library name for the theme
172 result = g_hash_table_lookup (engine_hash, name);
176 result = GTK_THEME_ENGINE (g_object_new (GTK_TYPE_THEME_ENGINE, NULL));
177 g_type_module_set_name (G_TYPE_MODULE (result), name);
178 result->name = g_strdup (name);
180 g_hash_table_insert (engine_hash, result->name, result);
183 if (!g_type_module_use (G_TYPE_MODULE (result)))
190 gtk_theme_engine_create_rc_style (GtkThemeEngine *engine)
192 g_return_val_if_fail (engine != NULL, NULL);
194 return engine->create_rc_style ();