1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ 2 /* 3 * Anjuta 4 * Copyright (C) 2000 Dave Camp, Naba Kumar <naba@gnome.org> 5 * 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. 10 * 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. 15 * 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 Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef ANJUTA_PLUGIN_H 23 #define ANJUTA_PLUGIN_H 24 25 #include <glib.h> 26 #include <glib-object.h> 27 28 #include <string.h> 29 #include <libanjuta/anjuta-shell.h> 30 #include <libanjuta/anjuta-ui.h> 31 #include <libanjuta/anjuta-preferences.h> 32 #include <libanjuta/anjuta-utils.h> 33 34 G_BEGIN_DECLS 35 36 /* Add this alias in case some plugin outside Anjuta tree still uses it */ 37 typedef GTypeModule AnjutaGluePlugin; 38 39 typedef struct _AnjutaPlugin AnjutaPlugin; 40 typedef struct _AnjutaPluginClass AnjutaPluginClass; 41 typedef struct _AnjutaPluginPrivate AnjutaPluginPrivate; 42 43 /** 44 * AnjutaPluginValueAdded: 45 * @plugin: The #AnjutaPlugin based plugin 46 * @name: name of value being added. 47 * @value: value of value being added. 48 * @user_data: User data set during anjuta_plugin_add_watch() 49 * 50 * The callback to pass to anjuta_plugin_add_watch(). When a @name value 51 * is added to shell by another plugin, this callback will be called. 52 */ 53 typedef void (*AnjutaPluginValueAdded) (AnjutaPlugin *plugin, 54 const char *name, 55 const GValue *value, 56 gpointer user_data); 57 58 /** 59 * AnjutaPluginValueRemoved: 60 * @plugin: The #AnjutaPlugin based plugin 61 * @name: name of value being added. 62 * @user_data: User data set during anjuta_plugin_add_watch() 63 * 64 * The callback to pass to anjuta_plugin_add_watch(). When the @name value 65 * is removed from the shell (by the plugin exporting this value), this 66 * callback will be called. 67 */ 68 typedef void (*AnjutaPluginValueRemoved) (AnjutaPlugin *plugin, 69 const char *name, 70 gpointer user_data); 71 72 73 #define ANJUTA_TYPE_PLUGIN (anjuta_plugin_get_type ()) 74 #define ANJUTA_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), ANJUTA_TYPE_PLUGIN, AnjutaPlugin)) 75 #define ANJUTA_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), ANJUTA_TYPE_PLUGIN, AnjutaPluginClass)) 76 #define ANJUTA_IS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), ANJUTA_TYPE_PLUGIN)) 77 #define ANJUTA_IS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), ANJUTA_TYPE_PLUGIN)) 78 #define ANJUTA_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), ANJUTA_TYPE_PLUGIN, AnjutaPluginClass)) 79 80 struct _AnjutaPlugin { 81 GObject parent; 82 83 /* The shell in which the plugin has been added */ 84 AnjutaShell *shell; 85 86 /*< private >*/ 87 AnjutaPluginPrivate *priv; 88 }; 89 90 struct _AnjutaPluginClass { 91 GObjectClass parent_class; 92 93 /* Signals */ 94 void (*activated) (AnjutaPlugin *plugin); 95 void (*deactivated) (AnjutaPlugin *plugin); 96 97 /* Virtual functions */ 98 gboolean (*activate) (AnjutaPlugin *plugin); 99 gboolean (*deactivate) (AnjutaPlugin *plugin); 100 }; 101 102 GType anjuta_plugin_get_type (void); 103 104 gboolean anjuta_plugin_activate (AnjutaPlugin *plugin); 105 106 gboolean anjuta_plugin_deactivate (AnjutaPlugin *plugin); 107 108 gboolean anjuta_plugin_is_active (AnjutaPlugin *plugin); 109 110 guint anjuta_plugin_add_watch (AnjutaPlugin *plugin, 111 const gchar *name, 112 AnjutaPluginValueAdded added, 113 AnjutaPluginValueRemoved removed, 114 gpointer user_data); 115 116 void anjuta_plugin_remove_watch (AnjutaPlugin *plugin, guint id, 117 gboolean send_remove); 118 119 AnjutaShell *anjuta_plugin_get_shell (AnjutaPlugin* plugin); 120 121 /** 122 * ANJUTA_PLUGIN_BEGIN: 123 * @class_name: Name of the class. e.g. EditorPlugin 124 * @prefix: prefix of member function names. e.g. editor_plugin 125 * 126 * This is a convienient macro defined to make it easy to write plugin 127 * classes . This macro begins the class type definition. member function 128 * @prefix _class_init and @prefix _instance_init should be statically defined 129 * before using this macro. 130 * 131 * The class type definition is finished with ANJUTA_PLUGIN_END() macro. In 132 * between which any number of interface definitions could be added with 133 * ANJUTA_PLUGIN_ADD_INTERFACE() macro. 134 */ 135 #define ANJUTA_PLUGIN_BEGIN(class_name, prefix) \ 136 extern GType \ 137 prefix##_get_type (GTypeModule *module) \ 138 { \ 139 static GType type = 0; \ 140 if (G_UNLIKELY (!type)) { \ 141 static const GTypeInfo type_info = { \ 142 sizeof (class_name##Class), \ 143 NULL, \ 144 NULL, \ 145 (GClassInitFunc)prefix##_class_init, \ 146 NULL, \ 147 NULL, \ 148 sizeof (class_name), \ 149 0, \ 150 (GInstanceInitFunc)prefix##_instance_init \ 151 }; \ 152 g_return_val_if_fail (module != NULL, 0); \ 153 type = g_type_module_register_type (module, \ 154 ANJUTA_TYPE_PLUGIN, \ 155 #class_name, \ 156 &type_info, \ 157 (GTypeFlags) 0); 158 /** 159 * ANJUTA_PLUGIN_END: 160 * 161 * Ends the plugin class type definition started with ANJUTA_PLUGIN_BEGIN() 162 */ 163 #define ANJUTA_PLUGIN_END \ 164 } \ 165 return type; \ 166 } 167 168 /** 169 * ANJUTA_PLUGIN_ADD_INTERFACE: 170 * @interface_type: Interface type. e.g. IANJUTA_TYPE_EDITOR 171 * @prefix: prefix of member function names. 172 * 173 * This is a convienient macro defined to make it easy to add interfaces 174 * to a plugin type. @prefix _iface_init should be statically defined 175 * before using this macro. This macro should be called between 176 * ANJUTA_PLUGIN_BEGIN() and ANJUTA_PLUGIN_END() macros. 177 */ 178 #define ANJUTA_PLUGIN_ADD_INTERFACE(prefix,interface_type) \ 179 { \ 180 GInterfaceInfo iface_info = { \ 181 (GInterfaceInitFunc)prefix##_iface_init, \ 182 NULL, \ 183 NULL \ 184 }; \ 185 g_type_module_add_interface (module, \ 186 type, interface_type, \ 187 &iface_info); \ 188 } 189 190 /** 191 * ANJUTA_PLUGIN_BOILERPLATE: 192 * @class_name: Name of the class. e.g EditorPlugin 193 * @prefix: prefix of member function names. e.g. editor_plugin 194 * 195 * This macro is similar to using ANJUTA_PLUGIN_BEGIN() and then immediately 196 * using ANJUTA_PLUGIN_END(). It is basically a plugin type definition macro 197 * that does not have any interface implementation. 198 */ 199 #define ANJUTA_PLUGIN_BOILERPLATE(class_name, prefix) \ 200 ANJUTA_PLUGIN_BEGIN(class_name, prefix); \ 201 ANJUTA_PLUGIN_END 202 203 /** 204 * ANJUTA_SIMPLE_PLUGIN: 205 * @class_name: Name of the class. e.g. EditorPlugin 206 * @prefix: prefix of member function names. e.g. editor_plugin 207 * 208 * Sets up necessary codes for the plugin factory to know the class type of 209 * of the plugin. This macro is generally used at the end of plugin class 210 * and member functions definitions. 211 */ 212 #define ANJUTA_SIMPLE_PLUGIN(class_name, prefix) \ 213 G_MODULE_EXPORT void anjuta_glue_register_components (GTypeModule *module); \ 214 G_MODULE_EXPORT void \ 215 anjuta_glue_register_components (GTypeModule *module) \ 216 { \ 217 prefix##_get_type (module); \ 218 } \ 219 220 G_END_DECLS 221 222 #endif 223