2 * heavily based on code from Gedit
4 * Copyright (C) 2002-2005 - Paolo Maggi
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA.
22 #ifndef __RB_PLUGIN_H__
23 #define __RB_PLUGIN_H__
25 #include <glib-object.h>
32 * Type checking and casting macros
34 #define RB_TYPE_PLUGIN (rb_plugin_get_type())
35 #define RB_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), RB_TYPE_PLUGIN, RBPlugin))
36 #define RB_PLUGIN_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), RB_TYPE_PLUGIN, RBPlugin const))
37 #define RB_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), RB_TYPE_PLUGIN, RBPluginClass))
38 #define RB_IS_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), RB_TYPE_PLUGIN))
39 #define RB_IS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RB_TYPE_PLUGIN))
40 #define RB_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), RB_TYPE_PLUGIN, RBPluginClass))
43 * Main object structure
50 typedef void (*RBPluginActivationFunc
) (RBPlugin
*plugin
, RBShell
*shell
);
51 typedef GtkWidget
* (*RBPluginWidgetFunc
) (RBPlugin
*plugin
);
52 typedef gboolean (*RBPluginBooleanFunc
) (RBPlugin
*plugin
);
59 GObjectClass parent_class
;
61 /* Virtual public methods */
63 RBPluginActivationFunc activate
;
64 RBPluginActivationFunc deactivate
;
65 RBPluginWidgetFunc create_configure_dialog
;
67 /* Plugins should not override this, it's handled automatically by
69 RBPluginBooleanFunc is_configurable
;
75 GType
rb_plugin_get_type (void) G_GNUC_CONST
;
77 void rb_plugin_activate (RBPlugin
*plugin
,
79 void rb_plugin_deactivate (RBPlugin
*plugin
,
82 gboolean
rb_plugin_is_configurable (RBPlugin
*plugin
);
83 GtkWidget
*rb_plugin_create_configure_dialog
86 char * rb_plugin_find_file (RBPlugin
*plugin
,
89 GList
* rb_get_plugin_paths (void);
92 * Utility macro used to register plugins
94 * use: RBT_PLUGIN_REGISTER(RBSamplePlugin, rb_sample_plugin)
97 #define RB_PLUGIN_REGISTER(PluginName, plugin_name) \
99 static GType plugin_name##_type = 0; \
100 static GTypeModule *plugin_module_type = 0; \
103 plugin_name##_get_type (void) \
105 return plugin_name##_type; \
108 static void plugin_name##_init (PluginName *self); \
109 static void plugin_name##_class_init (PluginName##Class *klass); \
110 static gpointer plugin_name##_parent_class = NULL; \
111 static void plugin_name##_class_intern_init (gpointer klass) \
113 plugin_name##_parent_class = g_type_class_peek_parent (klass); \
114 plugin_name##_class_init ((PluginName##Class *) klass); \
117 G_MODULE_EXPORT GType \
118 register_rb_plugin (GTypeModule *module) \
120 static const GTypeInfo our_info = \
122 sizeof (PluginName##Class), \
123 NULL, /* base_init */ \
124 NULL, /* base_finalize */ \
125 (GClassInitFunc) plugin_name##_class_intern_init, \
127 NULL, /* class_data */ \
128 sizeof (PluginName), \
129 0, /* n_preallocs */ \
130 (GInstanceInitFunc) plugin_name##_init \
133 rb_debug ("Registering plugin %s", #PluginName); \
135 /* Initialise the i18n stuff */ \
136 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); \
137 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); \
139 plugin_module_type = module; \
140 plugin_name##_type = g_type_module_register_type (module, \
145 return plugin_name##_type; \
148 #define RB_PLUGIN_REGISTER_TYPE(type_name) \
149 type_name##_register_type (plugin_module_type)
151 #define RB_PLUGIN_DEFINE_TYPE(TypeName, type_name, TYPE_PARENT) \
152 static void type_name##_init (TypeName *self); \
153 static void type_name##_class_init (TypeName##Class *klass); \
154 static gpointer type_name##_parent_class = ((void *)0); \
155 static GType type_name##_type_id = 0; \
158 type_name##_class_intern_init (gpointer klass) \
160 type_name##_parent_class = g_type_class_peek_parent (klass); \
161 type_name##_class_init ((TypeName##Class*) klass); \
166 type_name##_get_type (void) \
168 g_assert (type_name##_type_id != 0); \
170 return type_name##_type_id; \
174 type_name##_register_type (GTypeModule *module) \
177 if ((type_name##_type_id == 0)) { \
178 static const GTypeInfo g_define_type_info = { \
179 sizeof (TypeName##Class), \
180 (GBaseInitFunc) ((void *)0), \
181 (GBaseFinalizeFunc) ((void *)0), \
182 (GClassInitFunc) type_name##_class_intern_init, \
183 (GClassFinalizeFunc) ((void *)0), \
187 (GInstanceInitFunc) type_name##_init, \
190 type_name##_type_id = \
191 g_type_module_register_type (module, \
194 &g_define_type_info, \
198 return type_name##_type_id; \
203 #endif /* __GEDIT_PLUGIN_H__ */