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"
38 typedef struct _GtkThemeEngineClass GtkThemeEngineClass;
40 struct _GtkThemeEngine
42 GTypeModule parent_instance;
46 void (*init) (GTypeModule *);
48 GtkRcStyle *(*create_rc_style) ();
53 struct _GtkThemeEngineClass
55 GTypeModuleClass parent_class;
58 static GHashTable *engine_hash = NULL;
61 gtk_theme_engine_load (GTypeModule *module)
63 GtkThemeEngine *engine = GTK_THEME_ENGINE (module);
67 engine_path = gtk_rc_find_module_in_path (engine->name);
71 g_warning (_("Unable to locate theme engine in module_path: \"%s\","),
78 GTK_NOTE (MISC, g_message ("Loading Theme %s\n", engine_path));
80 engine->library = g_module_open (engine_path, G_MODULE_BIND_LAZY);
84 g_warning (g_module_error());
88 /* extract symbols from the lib */
89 if (!g_module_symbol (engine->library, "theme_init",
90 (gpointer *)&engine->init) ||
91 !g_module_symbol (engine->library, "theme_exit",
92 (gpointer *)&engine->exit) ||
93 !g_module_symbol (engine->library, "theme_create_rc_style",
94 (gpointer *)&engine->create_rc_style))
96 g_warning (g_module_error());
97 g_module_close (engine->library);
102 /* call the theme's init (theme_init) function to let it */
103 /* setup anything it needs to set up. */
104 engine->init (module);
110 gtk_theme_engine_unload (GTypeModule *module)
112 GtkThemeEngine *engine = GTK_THEME_ENGINE (module);
116 g_module_close (engine->library);
117 engine->library = NULL;
121 engine->create_rc_style = NULL;
125 gtk_theme_engine_class_init (GtkThemeEngineClass *class)
127 GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class);
129 module_class->load = gtk_theme_engine_load;
130 module_class->unload = gtk_theme_engine_unload;
134 gtk_theme_engine_get_type (void)
136 static GType theme_engine_type = 0;
138 if (!theme_engine_type)
140 static const GTypeInfo theme_engine_info = {
141 sizeof (GtkThemeEngineClass),
142 NULL, /* base_init */
143 NULL, /* base_finalize */
144 (GClassInitFunc) gtk_theme_engine_class_init,
145 NULL, /* class_finalize */
146 NULL, /* class_data */
147 sizeof (GtkThemeEngine),
149 NULL, /* instance_init */
153 g_type_register_static (G_TYPE_TYPE_MODULE, I_("GtkThemeEngine"),
154 &theme_engine_info, 0);
157 return theme_engine_type;
161 gtk_theme_engine_get (const gchar *name)
163 GtkThemeEngine *result;
166 engine_hash = g_hash_table_new (g_str_hash, g_str_equal);
168 /* get the library name for the theme
170 result = g_hash_table_lookup (engine_hash, name);
174 result = g_object_new (GTK_TYPE_THEME_ENGINE, NULL);
175 g_type_module_set_name (G_TYPE_MODULE (result), name);
176 result->name = g_strdup (name);
178 g_hash_table_insert (engine_hash, result->name, result);
181 if (!g_type_module_use (G_TYPE_MODULE (result)))
188 gtk_theme_engine_create_rc_style (GtkThemeEngine *engine)
190 g_return_val_if_fail (engine != NULL, NULL);
192 return engine->create_rc_style ();
195 #define __GTK_THEMES_C__
196 #include "gtkaliasdef.c"