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  * Conversion parameters:
26  * inFile  = gtk3-Accelerator-Maps.html
27  * outPack = gtk
28  * outFile = AccelMap
29  * strct   = GtkAccelMap
30  * realStrct=
31  * ctorStrct=
32  * clss    = AccelMap
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_accel_map_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ScannerG
48  * structWrap:
49  * 	- GScanner* -> ScannerG
50  * 	- GtkAccelMap* -> AccelMap
51  * module aliases:
52  * local aliases:
53  * overrides:
54  */
55 
56 module gtk.AccelMap;
57 
58 public  import gtkc.gtktypes;
59 
60 private import gtkc.gtk;
61 private import glib.ConstructionException;
62 private import gobject.ObjectG;
63 
64 private import gobject.Signals;
65 public  import gtkc.gdktypes;
66 private import glib.Str;
67 private import glib.ScannerG;
68 
69 
70 private import gobject.ObjectG;
71 
72 /**
73  * Accelerator maps are used to define runtime configurable accelerators.
74  * Functions for manipulating them are are usually used by higher level
75  * convenience mechanisms like GtkUIManager and are thus considered
76  * "low-level". You'll want to use them if you're manually creating menus that
77  * should have user-configurable accelerators.
78  *
79  * Accelerator is uniquely defined by:
80  *
81  * accelerator path
82  *
83  * accelerator key
84  *
85  * accelerator modifiers
86  *
87  * The accelerator path must consist of
88  * "<WINDOWTYPE>/Category1/Category2/.../Action", where WINDOWTYPE
89  * should be a unique application-specific identifier that corresponds to the
90  * kind of window the accelerator is being used in, e.g. "Gimp-Image",
91  * "Abiword-Document" or "Gnumeric-Settings".
92  * The "Category1/.../Action" portion is most appropriately chosen by the action
93  * the accelerator triggers, i.e. for accelerators on menu items, choose the
94  * item's menu path, e.g. "File/Save As", "Image/View/Zoom" or
95  * "Edit/Select All". So a full valid accelerator path may look like:
96  * "<Gimp-Toolbox>/File/Dialogs/Tool Options...".
97  *
98  * All accelerators are stored inside one global GtkAccelMap that can be
99  * obtained using gtk_accel_map_get(). See Monitoring changes for additional
100  * details.
101  *
102  * Manipulating accelerators
103  *
104  * New accelerators can be added using gtk_accel_map_add_entry(). To search for
105  * specific accelerator, use gtk_accel_map_lookup_entry(). Modifications of
106  * existing accelerators should be done using gtk_accel_map_change_entry().
107  *
108  * In order to avoid having some accelerators changed, they can be locked using
109  * gtk_accel_map_lock_path(). Unlocking is done using
110  * gtk_accel_map_unlock_path().
111  *
112  * <hr>
113  *
114  * Saving and loading accelerator maps
115  *
116  * Accelerator maps can be saved to and loaded from some external resource. For
117  * simple saving and loading from file, gtk_accel_map_save() and
118  * gtk_accel_map_load() are provided. Saving and loading can also be done by
119  * providing file descriptor to gtk_accel_map_save_fd() and
120  * gtk_accel_map_load_fd().
121  *
122  * <hr>
123  *
124  * Monitoring changes
125  *
126  * GtkAccelMap object is only useful for monitoring changes of accelerators. By
127  * connecting to "changed" signal, one can monitor changes of all
128  * accelerators. It is also possible to monitor only single accelerator path by
129  * using it as a detail of the "changed" signal.
130  */
131 public class AccelMap : ObjectG
132 {
133 	
134 	/** the main Gtk struct */
135 	protected GtkAccelMap* gtkAccelMap;
136 	
137 	
138 	/** Get the main Gtk struct */
139 	public GtkAccelMap* getAccelMapStruct()
140 	{
141 		return gtkAccelMap;
142 	}
143 	
144 	
145 	/** the main Gtk struct as a void* */
146 	protected override void* getStruct()
147 	{
148 		return cast(void*)gtkAccelMap;
149 	}
150 	
151 	/**
152 	 * Sets our main struct and passes it to the parent class
153 	 */
154 	public this (GtkAccelMap* gtkAccelMap)
155 	{
156 		super(cast(GObject*)gtkAccelMap);
157 		this.gtkAccelMap = gtkAccelMap;
158 	}
159 	
160 	protected override void setStruct(GObject* obj)
161 	{
162 		super.setStruct(obj);
163 		gtkAccelMap = cast(GtkAccelMap*)obj;
164 	}
165 	
166 	/**
167 	 */
168 	int[string] connectedSignals;
169 	
170 	void delegate(string, guint, GdkModifierType, AccelMap)[] onChangedListeners;
171 	/**
172 	 * Notifies of a change in the global accelerator map.
173 	 * The path is also used as the detail for the signal,
174 	 * so it is possible to connect to
175 	 * changed::accel_path.
176 	 * Since 2.4
177 	 * See Also
178 	 * GtkAccelGroup, GtkAccelKey, GtkUIManager, gtk_widget_set_accel_path(), gtk_menu_item_set_accel_path()
179 	 */
180 	void addOnChanged(void delegate(string, guint, GdkModifierType, AccelMap) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
181 	{
182 		if ( !("changed" in connectedSignals) )
183 		{
184 			Signals.connectData(
185 			getStruct(),
186 			"changed",
187 			cast(GCallback)&callBackChanged,
188 			cast(void*)this,
189 			null,
190 			connectFlags);
191 			connectedSignals["changed"] = 1;
192 		}
193 		onChangedListeners ~= dlg;
194 	}
195 	extern(C) static void callBackChanged(GtkAccelMap* objectStruct, gchar* accelPath, guint accelKey, GdkModifierType accelMods, AccelMap _accelMap)
196 	{
197 		foreach ( void delegate(string, guint, GdkModifierType, AccelMap) dlg ; _accelMap.onChangedListeners )
198 		{
199 			dlg(Str.toString(accelPath), accelKey, accelMods, _accelMap);
200 		}
201 	}
202 	
203 	
204 	/**
205 	 * Registers a new accelerator with the global accelerator map.
206 	 * This function should only be called once per accel_path
207 	 * with the canonical accel_key and accel_mods for this path.
208 	 * To change the accelerator during runtime programatically, use
209 	 * gtk_accel_map_change_entry().
210 	 * Set accel_key and accel_mods to 0 to request a removal of
211 	 * the accelerator.
212 	 * Note that accel_path string will be stored in a GQuark. Therefore, if you
213 	 * pass a static string, you can save some memory by interning it first with
214 	 * g_intern_static_string().
215 	 * Params:
216 	 * accelPath = valid accelerator path
217 	 * accelKey = the accelerator key
218 	 * accelMods = the accelerator modifiers
219 	 */
220 	public static void addEntry(string accelPath, uint accelKey, GdkModifierType accelMods)
221 	{
222 		// void gtk_accel_map_add_entry (const gchar *accel_path,  guint accel_key,  GdkModifierType accel_mods);
223 		gtk_accel_map_add_entry(Str.toStringz(accelPath), accelKey, accelMods);
224 	}
225 	
226 	/**
227 	 * Looks up the accelerator entry for accel_path and fills in key.
228 	 * Params:
229 	 * accelPath = a valid accelerator path
230 	 * key = the accelerator key to be filled in (optional). [allow-none][out]
231 	 * Returns: TRUE if accel_path is known, FALSE otherwise
232 	 */
233 	public static int lookupEntry(string accelPath, out GtkAccelKey key)
234 	{
235 		// gboolean gtk_accel_map_lookup_entry (const gchar *accel_path,  GtkAccelKey *key);
236 		return gtk_accel_map_lookup_entry(Str.toStringz(accelPath), &key);
237 	}
238 	
239 	/**
240 	 * Changes the accel_key and accel_mods currently associated with accel_path.
241 	 * Due to conflicts with other accelerators, a change may not always be possible,
242 	 * replace indicates whether other accelerators may be deleted to resolve such
243 	 * conflicts. A change will only occur if all conflicts could be resolved (which
244 	 * might not be the case if conflicting accelerators are locked). Successful
245 	 * changes are indicated by a TRUE return value.
246 	 * Note that accel_path string will be stored in a GQuark. Therefore, if you
247 	 * pass a static string, you can save some memory by interning it first with
248 	 * g_intern_static_string().
249 	 * Params:
250 	 * accelPath = a valid accelerator path
251 	 * accelKey = the new accelerator key
252 	 * accelMods = the new accelerator modifiers
253 	 * replace = TRUE if other accelerators may be deleted upon conflicts
254 	 * Returns: TRUE if the accelerator could be changed, FALSE otherwise
255 	 */
256 	public static int changeEntry(string accelPath, uint accelKey, GdkModifierType accelMods, int replace)
257 	{
258 		// gboolean gtk_accel_map_change_entry (const gchar *accel_path,  guint accel_key,  GdkModifierType accel_mods,  gboolean replace);
259 		return gtk_accel_map_change_entry(Str.toStringz(accelPath), accelKey, accelMods, replace);
260 	}
261 	
262 	/**
263 	 * Parses a file previously saved with gtk_accel_map_save() for
264 	 * accelerator specifications, and propagates them accordingly.
265 	 * Params:
266 	 * fileName = a file containing accelerator specifications,
267 	 * in the GLib file name encoding. [type filename]
268 	 */
269 	public static void load(string fileName)
270 	{
271 		// void gtk_accel_map_load (const gchar *file_name);
272 		gtk_accel_map_load(Str.toStringz(fileName));
273 	}
274 	
275 	/**
276 	 * Saves current accelerator specifications (accelerator path, key
277 	 * and modifiers) to file_name.
278 	 * The file is written in a format suitable to be read back in by
279 	 * gtk_accel_map_load().
280 	 * Params:
281 	 * fileName = the name of the file to contain
282 	 * accelerator specifications, in the GLib file name encoding. [type filename]
283 	 */
284 	public static void save(string fileName)
285 	{
286 		// void gtk_accel_map_save (const gchar *file_name);
287 		gtk_accel_map_save(Str.toStringz(fileName));
288 	}
289 	
290 	/**
291 	 * Loops over the entries in the accelerator map whose accel path
292 	 * doesn't match any of the filters added with gtk_accel_map_add_filter(),
293 	 * and execute foreach_func on each. The signature of foreach_func is
294 	 * that of GtkAccelMapForeach, the changed parameter indicates whether
295 	 * this accelerator was changed during runtime (thus, would need
296 	 * saving during an accelerator map dump).
297 	 * Params:
298 	 * data = data to be passed into foreach_func. [allow-none]
299 	 * foreachFunc = function to be executed for each accel
300 	 * map entry which is not filtered out. [scope call]
301 	 */
302 	public static void foreac(void* data, GtkAccelMapForeach foreachFunc)
303 	{
304 		// void gtk_accel_map_foreach (gpointer data,  GtkAccelMapForeach foreach_func);
305 		gtk_accel_map_foreach(data, foreachFunc);
306 	}
307 	
308 	/**
309 	 * Filedescriptor variant of gtk_accel_map_load().
310 	 * Note that the file descriptor will not be closed by this function.
311 	 * Params:
312 	 * fd = a valid readable file descriptor
313 	 */
314 	public static void loadFd(int fd)
315 	{
316 		// void gtk_accel_map_load_fd (gint fd);
317 		gtk_accel_map_load_fd(fd);
318 	}
319 	
320 	/**
321 	 * Filedescriptor variant of gtk_accel_map_save().
322 	 * Note that the file descriptor will not be closed by this function.
323 	 * Params:
324 	 * fd = a valid writable file descriptor
325 	 */
326 	public static void saveFd(int fd)
327 	{
328 		// void gtk_accel_map_save_fd (gint fd);
329 		gtk_accel_map_save_fd(fd);
330 	}
331 	
332 	/**
333 	 * GScanner variant of gtk_accel_map_load().
334 	 * Params:
335 	 * scanner = a GScanner which has already been provided with an input file
336 	 */
337 	public static void loadScanner(ScannerG scanner)
338 	{
339 		// void gtk_accel_map_load_scanner (GScanner *scanner);
340 		gtk_accel_map_load_scanner((scanner is null) ? null : scanner.getScannerGStruct());
341 	}
342 	
343 	/**
344 	 * Adds a filter to the global list of accel path filters.
345 	 * Accel map entries whose accel path matches one of the filters
346 	 * are skipped by gtk_accel_map_foreach().
347 	 * This function is intended for GTK+ modules that create their own
348 	 * menus, but don't want them to be saved into the applications accelerator
349 	 * map dump.
350 	 * Params:
351 	 * filterPattern = a pattern (see GPatternSpec)
352 	 */
353 	public static void addFilter(string filterPattern)
354 	{
355 		// void gtk_accel_map_add_filter (const gchar *filter_pattern);
356 		gtk_accel_map_add_filter(Str.toStringz(filterPattern));
357 	}
358 	
359 	/**
360 	 * Loops over all entries in the accelerator map, and execute
361 	 * foreach_func on each. The signature of foreach_func is that of
362 	 * GtkAccelMapForeach, the changed parameter indicates whether
363 	 * this accelerator was changed during runtime (thus, would need
364 	 * saving during an accelerator map dump).
365 	 * Params:
366 	 * data = data to be passed into foreach_func
367 	 * foreachFunc = function to be executed for each accel
368 	 * map entry. [scope call]
369 	 */
370 	public static void foreachUnfiltered(void* data, GtkAccelMapForeach foreachFunc)
371 	{
372 		// void gtk_accel_map_foreach_unfiltered (gpointer data,  GtkAccelMapForeach foreach_func);
373 		gtk_accel_map_foreach_unfiltered(data, foreachFunc);
374 	}
375 	
376 	/**
377 	 * Gets the singleton global GtkAccelMap object. This object
378 	 * is useful only for notification of changes to the accelerator
379 	 * map via the ::changed signal; it isn't a parameter to the
380 	 * other accelerator map functions.
381 	 * Since 2.4
382 	 * Returns: the global GtkAccelMap object. [transfer none]
383 	 */
384 	public static AccelMap get()
385 	{
386 		// GtkAccelMap * gtk_accel_map_get (void);
387 		auto p = gtk_accel_map_get();
388 		
389 		if(p is null)
390 		{
391 			return null;
392 		}
393 		
394 		return ObjectG.getDObject!(AccelMap)(cast(GtkAccelMap*) p);
395 	}
396 	
397 	/**
398 	 * Locks the given accelerator path. If the accelerator map doesn't yet contain
399 	 * an entry for accel_path, a new one is created.
400 	 * Locking an accelerator path prevents its accelerator from being changed
401 	 * during runtime. A locked accelerator path can be unlocked by
402 	 * gtk_accel_map_unlock_path(). Refer to gtk_accel_map_change_entry()
403 	 * for information about runtime accelerator changes.
404 	 * If called more than once, accel_path remains locked until
405 	 * gtk_accel_map_unlock_path() has been called an equivalent number
406 	 * of times.
407 	 * Note that locking of individual accelerator paths is independent from
408 	 * locking the GtkAccelGroup containing them. For runtime accelerator
409 	 * changes to be possible, both the accelerator path and its GtkAccelGroup
410 	 * have to be unlocked.
411 	 * Since 2.4
412 	 * Params:
413 	 * accelPath = a valid accelerator path
414 	 */
415 	public static void lockPath(string accelPath)
416 	{
417 		// void gtk_accel_map_lock_path (const gchar *accel_path);
418 		gtk_accel_map_lock_path(Str.toStringz(accelPath));
419 	}
420 	
421 	/**
422 	 * Undoes the last call to gtk_accel_map_lock_path() on this accel_path.
423 	 * Refer to gtk_accel_map_lock_path() for information about accelerator path locking.
424 	 * Since 2.4
425 	 * Signal Details
426 	 * The "changed" signal
427 	 * void user_function (GtkAccelMap *object,
428 	 *  gchar *accel_path,
429 	 *  guint accel_key,
430 	 *  GdkModifierType accel_mods,
431 	 *  gpointer user_data) : Has Details
432 	 * Notifies of a change in the global accelerator map.
433 	 * The path is also used as the detail for the signal,
434 	 * so it is possible to connect to
435 	 * changed::accel_path.
436 	 * Since 2.4
437 	 * Params:
438 	 * accelPath = a valid accelerator path
439 	 * accelPath = the path of the accelerator that changed
440 	 */
441 	public static void unlockPath(string accelPath)
442 	{
443 		// void gtk_accel_map_unlock_path (const gchar *accel_path);
444 		gtk_accel_map_unlock_path(Str.toStringz(accelPath));
445 	}
446 }