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 atk.SelectionT; 26 27 public import atk.ObjectAtk; 28 public import gobject.ObjectG; 29 public import gobject.Signals; 30 public import gtkc.atk; 31 public import gtkc.atktypes; 32 public import std.algorithm; 33 34 35 /** 36 * #AtkSelection should be implemented by UI components with children 37 * which are exposed by #atk_object_ref_child and 38 * #atk_object_get_n_children, if the use of the parent UI component 39 * ordinarily involves selection of one or more of the objects 40 * corresponding to those #AtkObject children - for example, 41 * selectable lists. 42 * 43 * Note that other types of "selection" (for instance text selection) 44 * are accomplished a other ATK interfaces - #AtkSelection is limited 45 * to the selection/deselection of children. 46 */ 47 public template SelectionT(TStruct) 48 { 49 /** Get the main Gtk struct */ 50 public AtkSelection* getSelectionStruct(bool transferOwnership = false) 51 { 52 if (transferOwnership) 53 ownedRef = false; 54 return cast(AtkSelection*)getStruct(); 55 } 56 57 58 /** 59 * Adds the specified accessible child of the object to the 60 * object's selection. 61 * 62 * Params: 63 * i = a #gint specifying the child index. 64 * 65 * Returns: TRUE if success, FALSE otherwise. 66 */ 67 public bool addSelection(int i) 68 { 69 return atk_selection_add_selection(getSelectionStruct(), i) != 0; 70 } 71 72 /** 73 * Clears the selection in the object so that no children in the object 74 * are selected. 75 * 76 * Returns: TRUE if success, FALSE otherwise. 77 */ 78 public bool clearSelection() 79 { 80 return atk_selection_clear_selection(getSelectionStruct()) != 0; 81 } 82 83 /** 84 * Gets the number of accessible children currently selected. 85 * Note: callers should not rely on %NULL or on a zero value for 86 * indication of whether AtkSelectionIface is implemented, they should 87 * use type checking/interface checking macros or the 88 * atk_get_accessible_value() convenience method. 89 * 90 * Returns: a gint representing the number of items selected, or 0 91 * if @selection does not implement this interface. 92 */ 93 public int getSelectionCount() 94 { 95 return atk_selection_get_selection_count(getSelectionStruct()); 96 } 97 98 /** 99 * Determines if the current child of this object is selected 100 * Note: callers should not rely on %NULL or on a zero value for 101 * indication of whether AtkSelectionIface is implemented, they should 102 * use type checking/interface checking macros or the 103 * atk_get_accessible_value() convenience method. 104 * 105 * Params: 106 * i = a #gint specifying the child index. 107 * 108 * Returns: a gboolean representing the specified child is selected, or 0 109 * if @selection does not implement this interface. 110 */ 111 public bool isChildSelected(int i) 112 { 113 return atk_selection_is_child_selected(getSelectionStruct(), i) != 0; 114 } 115 116 /** 117 * Gets a reference to the accessible object representing the specified 118 * selected child of the object. 119 * Note: callers should not rely on %NULL or on a zero value for 120 * indication of whether AtkSelectionIface is implemented, they should 121 * use type checking/interface checking macros or the 122 * atk_get_accessible_value() convenience method. 123 * 124 * Params: 125 * i = a #gint specifying the index in the selection set. (e.g. the 126 * ith selection as opposed to the ith child). 127 * 128 * Returns: an #AtkObject representing the 129 * selected accessible, or %NULL if @selection does not implement this 130 * interface. 131 */ 132 public ObjectAtk refSelection(int i) 133 { 134 auto p = atk_selection_ref_selection(getSelectionStruct(), i); 135 136 if(p is null) 137 { 138 return null; 139 } 140 141 return ObjectG.getDObject!(ObjectAtk)(cast(AtkObject*) p, true); 142 } 143 144 /** 145 * Removes the specified child of the object from the object's selection. 146 * 147 * Params: 148 * i = a #gint specifying the index in the selection set. (e.g. the 149 * ith selection as opposed to the ith child). 150 * 151 * Returns: TRUE if success, FALSE otherwise. 152 */ 153 public bool removeSelection(int i) 154 { 155 return atk_selection_remove_selection(getSelectionStruct(), i) != 0; 156 } 157 158 /** 159 * Causes every child of the object to be selected if the object 160 * supports multiple selections. 161 * 162 * Returns: TRUE if success, FALSE otherwise. 163 */ 164 public bool selectAllSelection() 165 { 166 return atk_selection_select_all_selection(getSelectionStruct()) != 0; 167 } 168 169 protected class OnSelectionChangedDelegateWrapper 170 { 171 static OnSelectionChangedDelegateWrapper[] listeners; 172 void delegate(SelectionIF) dlg; 173 gulong handlerId; 174 175 this(void delegate(SelectionIF) dlg) 176 { 177 this.dlg = dlg; 178 this.listeners ~= this; 179 } 180 181 void remove(OnSelectionChangedDelegateWrapper source) 182 { 183 foreach(index, wrapper; listeners) 184 { 185 if (wrapper.handlerId == source.handlerId) 186 { 187 listeners[index] = null; 188 listeners = std.algorithm.remove(listeners, index); 189 break; 190 } 191 } 192 } 193 } 194 195 /** 196 * The "selection-changed" signal is emitted by an object which 197 * implements AtkSelection interface when the selection changes. 198 */ 199 gulong addOnSelectionChanged(void delegate(SelectionIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 200 { 201 auto wrapper = new OnSelectionChangedDelegateWrapper(dlg); 202 wrapper.handlerId = Signals.connectData( 203 this, 204 "selection-changed", 205 cast(GCallback)&callBackSelectionChanged, 206 cast(void*)wrapper, 207 cast(GClosureNotify)&callBackSelectionChangedDestroy, 208 connectFlags); 209 return wrapper.handlerId; 210 } 211 212 extern(C) static void callBackSelectionChanged(AtkSelection* selectionStruct, OnSelectionChangedDelegateWrapper wrapper) 213 { 214 wrapper.dlg(wrapper.outer); 215 } 216 217 extern(C) static void callBackSelectionChangedDestroy(OnSelectionChangedDelegateWrapper wrapper, GClosure* closure) 218 { 219 wrapper.remove(wrapper); 220 } 221 }