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);
65 engine_path = gtk_rc_find_module_in_path (engine->name);
69 g_warning (_("Unable to locate theme engine in module_path: \"%s\","),
76 GTK_NOTE (MISC, g_message ("Loading Theme %s\n", engine_path));
78 engine->library = g_module_open (engine_path, 0);
82 g_warning (g_module_error());
86 /* extract symbols from the lib */
87 if (!g_module_symbol (engine->library, "theme_init",
88 (gpointer *)&engine->init) ||
89 !g_module_symbol (engine->library, "theme_exit",
90 (gpointer *)&engine->exit) ||
91 !g_module_symbol (engine->library, "theme_create_rc_style",
92 (gpointer *)&engine->create_rc_style))
94 g_warning (g_module_error());
95 g_module_close (engine->library);
100 /* call the theme's init (theme_init) function to let it */
101 /* setup anything it needs to set up. */
102 engine->init (module);
108 gtk_theme_engine_unload (GTypeModule *module)
110 GtkThemeEngine *engine = GTK_THEME_ENGINE (module);
114 g_module_close (engine->library);
115 engine->library = NULL;
119 engine->create_rc_style = NULL;
123 gtk_theme_engine_class_init (GtkThemeEngineClass *class)
125 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class);
127 module_class->load = gtk_theme_engine_load;
128 module_class->unload = gtk_theme_engine_unload;
132 gtk_theme_engine_get_type (void)
134 static GType theme_engine_type = 0;
136 if (!theme_engine_type)
138 static const GTypeInfo theme_engine_info = {
139 sizeof (GtkThemeEngineClass),
140 NULL, /* base_init */
141 NULL, /* base_finalize */
142 (GClassInitFunc) gtk_theme_engine_class_init,
143 NULL, /* class_finalize */
144 NULL, /* class_data */
145 sizeof (GtkThemeEngine),
147 NULL, /* instance_init */
151 g_type_register_static (G_TYPE_TYPE_MODULE, "GtkThemeEngine",
152 &theme_engine_info, 0);
155 return theme_engine_type;
159 gtk_theme_engine_get (const gchar *name)
161 GtkThemeEngine *result;
164 engine_hash = g_hash_table_new (g_str_hash, g_str_equal);
166 /* get the library name for the theme
168 result = g_hash_table_lookup (engine_hash, name);
172 result = g_object_new (GTK_TYPE_THEME_ENGINE, NULL);
173 g_type_module_set_name (G_TYPE_MODULE (result), name);
174 result->name = g_strdup (name);
176 g_hash_table_insert (engine_hash, result->name, result);
179 if (!g_type_module_use (G_TYPE_MODULE (result)))
186 gtk_theme_engine_create_rc_style (GtkThemeEngine *engine)
188 g_return_val_if_fail (engine != NULL, NULL);
190 return engine->create_rc_style ();