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