1 /* 2 * This file is part of d-dazzle. 3 * 4 * d-dazzle 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 * d-dazzle 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 d-dazzle; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 module dazzle.ShortcutChordTable; 20 21 private import dazzle.ShortcutChord; 22 private import dazzle.c.functions; 23 public import dazzle.c.types; 24 private import glib.ConstructionException; 25 private import gobject.ObjectG; 26 private import gtkd.Loader; 27 28 29 /** */ 30 public class ShortcutChordTable 31 { 32 /** the main Gtk struct */ 33 protected DzlShortcutChordTable* dzlShortcutChordTable; 34 protected bool ownedRef; 35 36 /** Get the main Gtk struct */ 37 public DzlShortcutChordTable* getShortcutChordTableStruct(bool transferOwnership = false) 38 { 39 if (transferOwnership) 40 ownedRef = false; 41 return dzlShortcutChordTable; 42 } 43 44 /** the main Gtk struct as a void* */ 45 protected void* getStruct() 46 { 47 return cast(void*)dzlShortcutChordTable; 48 } 49 50 /** 51 * Sets our main struct and passes it to the parent class. 52 */ 53 public this (DzlShortcutChordTable* dzlShortcutChordTable, bool ownedRef = false) 54 { 55 this.dzlShortcutChordTable = dzlShortcutChordTable; 56 this.ownedRef = ownedRef; 57 } 58 59 ~this () 60 { 61 if ( Linker.isLoaded(LIBRARY_DAZZLE) && ownedRef ) 62 dzl_shortcut_chord_table_free(dzlShortcutChordTable); 63 } 64 65 66 /** */ 67 public void add(ShortcutChord chord, void* data) 68 { 69 dzl_shortcut_chord_table_add(dzlShortcutChordTable, (chord is null) ? null : chord.getShortcutChordStruct(), data); 70 } 71 72 alias foreac = foreach_; 73 /** 74 * This function will call @foreach_func for each chord in the table. 75 * 76 * Params: 77 * foreachFunc = A callback for each chord 78 * foreachData = user data for @foreach_func 79 */ 80 public void foreach_(DzlShortcutChordTableForeach foreachFunc, void* foreachData) 81 { 82 dzl_shortcut_chord_table_foreach(dzlShortcutChordTable, foreachFunc, foreachData); 83 } 84 85 /** */ 86 public void free() 87 { 88 dzl_shortcut_chord_table_free(dzlShortcutChordTable); 89 ownedRef = false; 90 } 91 92 /** */ 93 public DzlShortcutMatch lookup(ShortcutChord chord, void** data) 94 { 95 return dzl_shortcut_chord_table_lookup(dzlShortcutChordTable, (chord is null) ? null : chord.getShortcutChordStruct(), data); 96 } 97 98 /** */ 99 public ShortcutChord lookupData(void* data) 100 { 101 auto p = dzl_shortcut_chord_table_lookup_data(dzlShortcutChordTable, data); 102 103 if(p is null) 104 { 105 return null; 106 } 107 108 return ObjectG.getDObject!(ShortcutChord)(cast(DzlShortcutChord*) p); 109 } 110 111 /** */ 112 public void printf() 113 { 114 dzl_shortcut_chord_table_printf(dzlShortcutChordTable); 115 } 116 117 /** */ 118 public bool remove(ShortcutChord chord) 119 { 120 return dzl_shortcut_chord_table_remove(dzlShortcutChordTable, (chord is null) ? null : chord.getShortcutChordStruct()) != 0; 121 } 122 123 /** */ 124 public bool removeData(void* data) 125 { 126 return dzl_shortcut_chord_table_remove_data(dzlShortcutChordTable, data) != 0; 127 } 128 129 /** */ 130 public void setFreeFunc(GDestroyNotify notify) 131 { 132 dzl_shortcut_chord_table_set_free_func(dzlShortcutChordTable, notify); 133 } 134 135 /** */ 136 public uint size() 137 { 138 return dzl_shortcut_chord_table_size(dzlShortcutChordTable); 139 } 140 141 /** */ 142 public this() 143 { 144 auto p = dzl_shortcut_chord_table_new(); 145 146 if(p is null) 147 { 148 throw new ConstructionException("null returned by new"); 149 } 150 151 this(cast(DzlShortcutChordTable*) p); 152 } 153 }