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.MapListModel; 26 27 private import gio.ListModelIF; 28 private import gio.ListModelT; 29 private import glib.ConstructionException; 30 private import gobject.ObjectG; 31 private import gtk.c.functions; 32 public import gtk.c.types; 33 34 35 /** 36 * A `GtkMapListModel` maps the items in a list model to different items. 37 * 38 * `GtkMapListModel` uses a [callback@Gtk.MapListModelMapFunc]. 39 * 40 * Example: Create a list of `GtkEventControllers` 41 * ```c 42 * static gpointer 43 * map_to_controllers (gpointer widget, 44 * gpointer data) 45 * { 46 * gpointer result = gtk_widget_observe_controllers (widget); 47 * g_object_unref (widget); 48 * return result; 49 * } 50 * 51 * widgets = gtk_widget_observe_children (widget); 52 * 53 * controllers = gtk_map_list_model_new (G_TYPE_LIST_MODEL, 54 * widgets, 55 * map_to_controllers, 56 * NULL, NULL); 57 * 58 * model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER, 59 * controllers); 60 * ``` 61 * 62 * `GtkMapListModel` will attempt to discard the mapped objects as soon as 63 * they are no longer needed and recreate them if necessary. 64 */ 65 public class MapListModel : ObjectG, ListModelIF 66 { 67 /** the main Gtk struct */ 68 protected GtkMapListModel* gtkMapListModel; 69 70 /** Get the main Gtk struct */ 71 public GtkMapListModel* getMapListModelStruct(bool transferOwnership = false) 72 { 73 if (transferOwnership) 74 ownedRef = false; 75 return gtkMapListModel; 76 } 77 78 /** the main Gtk struct as a void* */ 79 protected override void* getStruct() 80 { 81 return cast(void*)gtkMapListModel; 82 } 83 84 /** 85 * Sets our main struct and passes it to the parent class. 86 */ 87 public this (GtkMapListModel* gtkMapListModel, bool ownedRef = false) 88 { 89 this.gtkMapListModel = gtkMapListModel; 90 super(cast(GObject*)gtkMapListModel, ownedRef); 91 } 92 93 // add the ListModel capabilities 94 mixin ListModelT!(GtkMapListModel); 95 96 97 /** */ 98 public static GType getType() 99 { 100 return gtk_map_list_model_get_type(); 101 } 102 103 /** 104 * Creates a new `GtkMapListModel` for the given arguments. 105 * 106 * Params: 107 * model = The model to map or %NULL for none 108 * mapFunc = map function or %NULL to not map items 109 * userData = user data passed to @map_func 110 * userDestroy = destroy notifier for @user_data 111 * 112 * Returns: a new `GtkMapListModel` 113 * 114 * Throws: ConstructionException GTK+ fails to create the object. 115 */ 116 public this(ListModelIF model, GtkMapListModelMapFunc mapFunc, void* userData, GDestroyNotify userDestroy) 117 { 118 auto __p = gtk_map_list_model_new((model is null) ? null : model.getListModelStruct(), mapFunc, userData, userDestroy); 119 120 if(__p is null) 121 { 122 throw new ConstructionException("null returned by new"); 123 } 124 125 this(cast(GtkMapListModel*) __p, true); 126 } 127 128 /** 129 * Gets the model that is currently being mapped or %NULL if none. 130 * 131 * Returns: The model that gets mapped 132 */ 133 public ListModelIF getModel() 134 { 135 auto __p = gtk_map_list_model_get_model(gtkMapListModel); 136 137 if(__p is null) 138 { 139 return null; 140 } 141 142 return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p); 143 } 144 145 /** 146 * Checks if a map function is currently set on @self. 147 * 148 * Returns: %TRUE if a map function is set 149 */ 150 public bool hasMap() 151 { 152 return gtk_map_list_model_has_map(gtkMapListModel) != 0; 153 } 154 155 /** 156 * Sets the function used to map items. 157 * 158 * The function will be called whenever an item needs to be mapped 159 * and must return the item to use for the given input item. 160 * 161 * Note that `GtkMapListModel` may call this function multiple times 162 * on the same item, because it may delete items it doesn't need anymore. 163 * 164 * GTK makes no effort to ensure that @map_func conforms to the item type 165 * of @self. It assumes that the caller knows what they are doing and the map 166 * function returns items of the appropriate type. 167 * 168 * Params: 169 * mapFunc = map function or %NULL to not map items 170 * userData = user data passed to @map_func 171 * userDestroy = destroy notifier for @user_data 172 */ 173 public void setMapFunc(GtkMapListModelMapFunc mapFunc, void* userData, GDestroyNotify userDestroy) 174 { 175 gtk_map_list_model_set_map_func(gtkMapListModel, mapFunc, userData, userDestroy); 176 } 177 178 /** 179 * Sets the model to be mapped. 180 * 181 * GTK makes no effort to ensure that @model conforms to the item type 182 * expected by the map function. It assumes that the caller knows what 183 * they are doing and have set up an appropriate map function. 184 * 185 * Params: 186 * model = The model to be mapped 187 */ 188 public void setModel(ListModelIF model) 189 { 190 gtk_map_list_model_set_model(gtkMapListModel, (model is null) ? null : model.getListModelStruct()); 191 } 192 }