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