1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gobject.TypeModule; 26 27 private import glib.Str; 28 private import gobject.ObjectG; 29 private import gobject.TypePluginIF; 30 private import gobject.TypePluginT; 31 private import gtkc.gobject; 32 public import gtkc.gobjecttypes; 33 34 35 /** 36 * #GTypeModule provides a simple implementation of the #GTypePlugin 37 * interface. The model of #GTypeModule is a dynamically loaded module 38 * which implements some number of types and interface implementations. 39 * When the module is loaded, it registers its types and interfaces 40 * using g_type_module_register_type() and g_type_module_add_interface(). 41 * As long as any instances of these types and interface implementations 42 * are in use, the module is kept loaded. When the types and interfaces 43 * are gone, the module may be unloaded. If the types and interfaces 44 * become used again, the module will be reloaded. Note that the last 45 * unref cannot happen in module code, since that would lead to the 46 * caller's code being unloaded before g_object_unref() returns to it. 47 * 48 * Keeping track of whether the module should be loaded or not is done by 49 * using a use count - it starts at zero, and whenever it is greater than 50 * zero, the module is loaded. The use count is maintained internally by 51 * the type system, but also can be explicitly controlled by 52 * g_type_module_use() and g_type_module_unuse(). Typically, when loading 53 * a module for the first type, g_type_module_use() will be used to load 54 * it so that it can initialize its types. At some later point, when the 55 * module no longer needs to be loaded except for the type 56 * implementations it contains, g_type_module_unuse() is called. 57 * 58 * #GTypeModule does not actually provide any implementation of module 59 * loading and unloading. To create a particular module type you must 60 * derive from #GTypeModule and implement the load and unload functions 61 * in #GTypeModuleClass. 62 */ 63 public class TypeModule : ObjectG, TypePluginIF 64 { 65 /** the main Gtk struct */ 66 protected GTypeModule* gTypeModule; 67 68 /** Get the main Gtk struct */ 69 public GTypeModule* getTypeModuleStruct() 70 { 71 return gTypeModule; 72 } 73 74 /** the main Gtk struct as a void* */ 75 protected override void* getStruct() 76 { 77 return cast(void*)gTypeModule; 78 } 79 80 protected override void setStruct(GObject* obj) 81 { 82 gTypeModule = cast(GTypeModule*)obj; 83 super.setStruct(obj); 84 } 85 86 /** 87 * Sets our main struct and passes it to the parent class. 88 */ 89 public this (GTypeModule* gTypeModule, bool ownedRef = false) 90 { 91 this.gTypeModule = gTypeModule; 92 super(cast(GObject*)gTypeModule, ownedRef); 93 } 94 95 // add the TypePlugin capabilities 96 mixin TypePluginT!(GTypeModule); 97 98 99 /** */ 100 public static GType getType() 101 { 102 return g_type_module_get_type(); 103 } 104 105 /** 106 * Registers an additional interface for a type, whose interface lives 107 * in the given type plugin. If the interface was already registered 108 * for the type in this plugin, nothing will be done. 109 * 110 * As long as any instances of the type exist, the type plugin will 111 * not be unloaded. 112 * 113 * Params: 114 * instanceType = type to which to add the interface. 115 * interfaceType = interface type to add 116 * interfaceInfo = type information structure 117 */ 118 public void addInterface(GType instanceType, GType interfaceType, GInterfaceInfo* interfaceInfo) 119 { 120 g_type_module_add_interface(gTypeModule, instanceType, interfaceType, interfaceInfo); 121 } 122 123 /** 124 * Looks up or registers an enumeration that is implemented with a particular 125 * type plugin. If a type with name @type_name was previously registered, 126 * the #GType identifier for the type is returned, otherwise the type 127 * is newly registered, and the resulting #GType identifier returned. 128 * 129 * As long as any instances of the type exist, the type plugin will 130 * not be unloaded. 131 * 132 * Params: 133 * name = name for the type 134 * constStaticValues = an array of #GEnumValue structs for the 135 * possible enumeration values. The array is 136 * terminated by a struct with all members being 137 * 0. 138 * 139 * Return: the new or existing type ID 140 * 141 * Since: 2.6 142 */ 143 public GType registerEnum(string name, GEnumValue* constStaticValues) 144 { 145 return g_type_module_register_enum(gTypeModule, Str.toStringz(name), constStaticValues); 146 } 147 148 /** 149 * Looks up or registers a flags type that is implemented with a particular 150 * type plugin. If a type with name @type_name was previously registered, 151 * the #GType identifier for the type is returned, otherwise the type 152 * is newly registered, and the resulting #GType identifier returned. 153 * 154 * As long as any instances of the type exist, the type plugin will 155 * not be unloaded. 156 * 157 * Params: 158 * name = name for the type 159 * constStaticValues = an array of #GFlagsValue structs for the 160 * possible flags values. The array is 161 * terminated by a struct with all members being 162 * 0. 163 * 164 * Return: the new or existing type ID 165 * 166 * Since: 2.6 167 */ 168 public GType registerFlags(string name, GFlagsValue* constStaticValues) 169 { 170 return g_type_module_register_flags(gTypeModule, Str.toStringz(name), constStaticValues); 171 } 172 173 /** 174 * Looks up or registers a type that is implemented with a particular 175 * type plugin. If a type with name @type_name was previously registered, 176 * the #GType identifier for the type is returned, otherwise the type 177 * is newly registered, and the resulting #GType identifier returned. 178 * 179 * When reregistering a type (typically because a module is unloaded 180 * then reloaded, and reinitialized), @module and @parent_type must 181 * be the same as they were previously. 182 * 183 * As long as any instances of the type exist, the type plugin will 184 * not be unloaded. 185 * 186 * Params: 187 * parentType = the type for the parent class 188 * typeName = name for the type 189 * typeInfo = type information structure 190 * flags = flags field providing details about the type 191 * 192 * Return: the new or existing type ID 193 */ 194 public GType registerType(GType parentType, string typeName, GTypeInfo* typeInfo, GTypeFlags flags) 195 { 196 return g_type_module_register_type(gTypeModule, parentType, Str.toStringz(typeName), typeInfo, flags); 197 } 198 199 /** 200 * Sets the name for a #GTypeModule 201 * 202 * Params: 203 * name = a human-readable name to use in error messages. 204 */ 205 public void setName(string name) 206 { 207 g_type_module_set_name(gTypeModule, Str.toStringz(name)); 208 } 209 210 /** 211 * Decreases the use count of a #GTypeModule by one. If the 212 * result is zero, the module will be unloaded. (However, the 213 * #GTypeModule will not be freed, and types associated with the 214 * #GTypeModule are not unregistered. Once a #GTypeModule is 215 * initialized, it must exist forever.) 216 */ 217 public void unuse() 218 { 219 g_type_module_unuse(gTypeModule); 220 } 221 222 /** 223 * Increases the use count of a #GTypeModule by one. If the 224 * use count was zero before, the plugin will be loaded. 225 * If loading the plugin fails, the use count is reset to 226 * its prior value. 227 * 228 * Return: %FALSE if the plugin needed to be loaded and 229 * loading the plugin failed. 230 */ 231 public bool use() 232 { 233 return g_type_module_use(gTypeModule) != 0; 234 } 235 }