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 gtk.SelectionModelIF; 26 27 private import gobject.ObjectG; 28 private import gobject.Signals; 29 private import gtk.Bitset; 30 private import gtk.c.functions; 31 public import gtk.c.types; 32 private import std.algorithm; 33 34 35 /** 36 * `GtkSelectionModel` is an interface that add support for selection to list models. 37 * 38 * This support is then used by widgets using list models to add the ability 39 * to select and unselect various items. 40 * 41 * GTK provides default implementations of the most common selection modes such 42 * as [class@Gtk.SingleSelection], so you will only need to implement this 43 * interface if you want detailed control about how selections should be handled. 44 * 45 * A `GtkSelectionModel` supports a single boolean per item indicating if an item is 46 * selected or not. This can be queried via [method@Gtk.SelectionModel.is_selected]. 47 * When the selected state of one or more items changes, the model will emit the 48 * [signal@Gtk.SelectionModel::selection-changed] signal by calling the 49 * [method@Gtk.SelectionModel.selection_changed] function. The positions given 50 * in that signal may have their selection state changed, though that is not a 51 * requirement. If new items added to the model via the ::items-changed signal 52 * are selected or not is up to the implementation. 53 * 54 * Note that items added via ::items-changed may already be selected and no 55 * [Gtk.SelectionModel::selection-changed] will be emitted for them. So to 56 * track which items are selected, it is necessary to listen to both signals. 57 * 58 * Additionally, the interface can expose functionality to select and unselect 59 * items. If these functions are implemented, GTK's list widgets will allow users 60 * to select and unselect items. However, `GtkSelectionModel`s are free to only 61 * implement them partially or not at all. In that case the widgets will not 62 * support the unimplemented operations. 63 * 64 * When selecting or unselecting is supported by a model, the return values of 65 * the selection functions do *not* indicate if selection or unselection happened. 66 * They are only meant to indicate complete failure, like when this mode of 67 * selecting is not supported by the model. 68 * 69 * Selections may happen asynchronously, so the only reliable way to find out 70 * when an item was selected is to listen to the signals that indicate selection. 71 */ 72 public interface SelectionModelIF{ 73 /** Get the main Gtk struct */ 74 public GtkSelectionModel* getSelectionModelStruct(bool transferOwnership = false); 75 76 /** the main Gtk struct as a void* */ 77 protected void* getStruct(); 78 79 80 /** */ 81 public static GType getType() 82 { 83 return gtk_selection_model_get_type(); 84 } 85 86 /** 87 * Gets the set containing all currently selected items in the model. 88 * 89 * This function may be slow, so if you are only interested in single item, 90 * consider using [method@Gtk.SelectionModel.is_selected] or if you are only 91 * interested in a few, consider [method@Gtk.SelectionModel.get_selection_in_range]. 92 * 93 * Returns: a `GtkBitset` containing all the values currently 94 * selected in @model. If no items are selected, the bitset is empty. 95 * The bitset must not be modified. 96 */ 97 public Bitset getSelection(); 98 99 /** 100 * Gets the set of selected items in a range. 101 * 102 * This function is an optimization for 103 * [method@Gtk.SelectionModel.get_selection] when you are only 104 * interested in part of the model's selected state. A common use 105 * case is in response to the [signal@Gtk.SelectionModel::selection-changed] 106 * signal. 107 * 108 * Params: 109 * position = start of the queired range 110 * nItems = number of items in the queried range 111 * 112 * Returns: A `GtkBitset` that matches the selection state 113 * for the given range with all other values being undefined. 114 * The bitset must not be modified. 115 */ 116 public Bitset getSelectionInRange(uint position, uint nItems); 117 118 /** 119 * Checks if the given item is selected. 120 * 121 * Params: 122 * position = the position of the item to query 123 * 124 * Returns: %TRUE if the item is selected 125 */ 126 public bool isSelected(uint position); 127 128 /** 129 * Requests to select all items in the model. 130 * 131 * Returns: %TRUE if this action was supported and no fallback should be 132 * tried. This does not mean that all items are now selected. 133 */ 134 public bool selectAll(); 135 136 /** 137 * Requests to select an item in the model. 138 * 139 * Params: 140 * position = the position of the item to select 141 * unselectRest = whether previously selected items should be unselected 142 * 143 * Returns: %TRUE if this action was supported and no fallback should be 144 * tried. This does not mean the item was selected. 145 */ 146 public bool selectItem(uint position, bool unselectRest); 147 148 /** 149 * Requests to select a range of items in the model. 150 * 151 * Params: 152 * position = the first item to select 153 * nItems = the number of items to select 154 * unselectRest = whether previously selected items should be unselected 155 * 156 * Returns: %TRUE if this action was supported and no fallback should be 157 * tried. This does not mean the range was selected. 158 */ 159 public bool selectRange(uint position, uint nItems, bool unselectRest); 160 161 /** 162 * Helper function for implementations of `GtkSelectionModel`. 163 * 164 * Call this when a the selection changes to emit the 165 * [signal@Gtk.SelectionModel::selection-changed] signal. 166 * 167 * Params: 168 * position = the first changed item 169 * nItems = the number of changed items 170 */ 171 public void selectionChanged(uint position, uint nItems); 172 173 /** 174 * Make selection changes. 175 * 176 * This is the most advanced selection updating method that allows 177 * the most fine-grained control over selection changes. If you can, 178 * you should try the simpler versions, as implementations are more 179 * likely to implement support for those. 180 * 181 * Requests that the selection state of all positions set in @mask 182 * be updated to the respective value in the @selected bitmask. 183 * 184 * In pseudocode, it would look something like this: 185 * 186 * ```c 187 * for (i = 0; i < n_items; i++) 188 * { 189 * // don't change values not in the mask 190 * if (!gtk_bitset_contains (mask, i)) 191 * continue; 192 * 193 * if (gtk_bitset_contains (selected, i)) 194 * select_item (i); 195 * else 196 * unselect_item (i); 197 * } 198 * 199 * gtk_selection_model_selection_changed (model, 200 * first_changed_item, 201 * n_changed_items); 202 * ``` 203 * 204 * @mask and @selected must not be modified. They may refer to the 205 * same bitset, which would mean that every item in the set should 206 * be selected. 207 * 208 * Params: 209 * selected = bitmask specifying if items should be selected or 210 * unselected 211 * mask = bitmask specifying which items should be updated 212 * 213 * Returns: %TRUE if this action was supported and no fallback should be 214 * tried. This does not mean that all items were updated according 215 * to the inputs. 216 */ 217 public bool setSelection(Bitset selected, Bitset mask); 218 219 /** 220 * Requests to unselect all items in the model. 221 * 222 * Returns: %TRUE if this action was supported and no fallback should be 223 * tried. This does not mean that all items are now unselected. 224 */ 225 public bool unselectAll(); 226 227 /** 228 * Requests to unselect an item in the model. 229 * 230 * Params: 231 * position = the position of the item to unselect 232 * 233 * Returns: %TRUE if this action was supported and no fallback should be 234 * tried. This does not mean the item was unselected. 235 */ 236 public bool unselectItem(uint position); 237 238 /** 239 * Requests to unselect a range of items in the model. 240 * 241 * Params: 242 * position = the first item to unselect 243 * nItems = the number of items to unselect 244 * 245 * Returns: %TRUE if this action was supported and no fallback should be 246 * tried. This does not mean the range was unselected. 247 */ 248 public bool unselectRange(uint position, uint nItems); 249 250 /** 251 * Emitted when the selection state of some of the items in @model changes. 252 * 253 * Note that this signal does not specify the new selection state of the 254 * items, they need to be queried manually. It is also not necessary for 255 * a model to change the selection state of any of the items in the selection 256 * model, though it would be rather useless to emit such a signal. 257 * 258 * Params: 259 * position = The first item that may have changed 260 * nItems = number of items with changes 261 */ 262 gulong addOnSelectionChanged(void delegate(uint, uint, SelectionModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 263 }