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/.
33 #include "gtkthemes.h"
39 typedef struct _GtkThemeEngineClass GtkThemeEngineClass;
41 struct _GtkThemeEngine
43 GTypeModule parent_instance;
47 void (*init) (GTypeModule *);
49 GtkRcStyle *(*create_rc_style) ();
54 struct _GtkThemeEngineClass
56 GTypeModuleClass parent_class;
59 static GHashTable *engine_hash = NULL;
62 gtk_theme_engine_load (GTypeModule *module)
64 GtkThemeEngine *engine = GTK_THEME_ENGINE (module);
68 engine_path = gtk_rc_find_module_in_path (engine->name);
72 g_warning (_("Unable to locate theme engine in module_path: \"%s\","),
79 GTK_NOTE (MISC, g_message ("Loading Theme %s\n", engine_path));
81 engine->library = g_module_open (engine_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
85 g_warning ("%s", g_module_error());
89 /* extract symbols from the lib */
90 if (!g_module_symbol (engine->library, "theme_init",
91 (gpointer *)&engine->init) ||
92 !g_module_symbol (engine->library, "theme_exit",
93 (gpointer *)&engine->exit) ||
94 !g_module_symbol (engine->library, "theme_create_rc_style",
95 (gpointer *)&engine->create_rc_style))
97 g_warning ("%s", g_module_error());
98 g_module_close (engine->library);
103 /* call the theme's init (theme_init) function to let it */
104 /* setup anything it needs to set up. */
105 engine->init (module);
111 gtk_theme_engine_unload (GTypeModule *module)
113 GtkThemeEngine *engine = GTK_THEME_ENGINE (module);
117 g_module_close (engine->library);
118 engine->library = NULL;
122 engine->create_rc_style = NULL;
126 gtk_theme_engine_class_init (GtkThemeEngineClass *class)
128 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class);
130 module_class->load = gtk_theme_engine_load;
131 module_class->unload = gtk_theme_engine_unload;
135 gtk_theme_engine_get_type (void)
137 static GType theme_engine_type = 0;
139 if (!theme_engine_type)
141 const GTypeInfo theme_engine_info = {
142 sizeof (GtkThemeEngineClass),
143 NULL, /* base_init */
144 NULL, /* base_finalize */
145 (GClassInitFunc) gtk_theme_engine_class_init,
146 NULL, /* class_finalize */
147 NULL, /* class_data */
148 sizeof (GtkThemeEngine),
150 NULL, /* instance_init */
154 g_type_register_static (G_TYPE_TYPE_MODULE, I_("GtkThemeEngine"),
155 &theme_engine_info, 0);
158 return theme_engine_type;
162 gtk_theme_engine_get (const gchar *name)
164 GtkThemeEngine *result;
167 engine_hash = g_hash_table_new (g_str_hash, g_str_equal);
169 /* get the library name for the theme
171 result = g_hash_table_lookup (engine_hash, name);
175 result = g_object_new (GTK_TYPE_THEME_ENGINE, NULL);
176 g_type_module_set_name (G_TYPE_MODULE (result), name);
177 result->name = g_strdup (name);
179 g_hash_table_insert (engine_hash, result->name, result);
182 if (!g_type_module_use (G_TYPE_MODULE (result)))
189 gtk_theme_engine_create_rc_style (GtkThemeEngine *engine)
191 g_return_val_if_fail (engine != NULL, NULL);
193 return engine->create_rc_style ();