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.SliceListModel;
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  * `GtkSliceListModel` is a list model that presents a slice of another model.
37  * 
38  * This is useful when implementing paging by setting the size to the number
39  * of elements per page and updating the offset whenever a different page is
40  * opened.
41  */
42 public class SliceListModel : ObjectG, ListModelIF
43 {
44 	/** the main Gtk struct */
45 	protected GtkSliceListModel* gtkSliceListModel;
46 
47 	/** Get the main Gtk struct */
48 	public GtkSliceListModel* getSliceListModelStruct(bool transferOwnership = false)
49 	{
50 		if (transferOwnership)
51 			ownedRef = false;
52 		return gtkSliceListModel;
53 	}
54 
55 	/** the main Gtk struct as a void* */
56 	protected override void* getStruct()
57 	{
58 		return cast(void*)gtkSliceListModel;
59 	}
60 
61 	/**
62 	 * Sets our main struct and passes it to the parent class.
63 	 */
64 	public this (GtkSliceListModel* gtkSliceListModel, bool ownedRef = false)
65 	{
66 		this.gtkSliceListModel = gtkSliceListModel;
67 		super(cast(GObject*)gtkSliceListModel, ownedRef);
68 	}
69 
70 	// add the ListModel capabilities
71 	mixin ListModelT!(GtkSliceListModel);
72 
73 
74 	/** */
75 	public static GType getType()
76 	{
77 		return gtk_slice_list_model_get_type();
78 	}
79 
80 	/**
81 	 * Creates a new slice model.
82 	 *
83 	 * It presents the slice from @offset to offset + @size
84 	 * of the given @model.
85 	 *
86 	 * Params:
87 	 *     model = The model to use, or %NULL
88 	 *     offset = the offset of the slice
89 	 *     size = maximum size of the slice
90 	 *
91 	 * Returns: A new `GtkSliceListModel`
92 	 *
93 	 * Throws: ConstructionException GTK+ fails to create the object.
94 	 */
95 	public this(ListModelIF model, uint offset, uint size)
96 	{
97 		auto __p = gtk_slice_list_model_new((model is null) ? null : model.getListModelStruct(), offset, size);
98 
99 		if(__p is null)
100 		{
101 			throw new ConstructionException("null returned by new");
102 		}
103 
104 		this(cast(GtkSliceListModel*) __p, true);
105 	}
106 
107 	/**
108 	 * Gets the model that is currently being used or %NULL if none.
109 	 *
110 	 * Returns: The model in use
111 	 */
112 	public ListModelIF getModel()
113 	{
114 		auto __p = gtk_slice_list_model_get_model(gtkSliceListModel);
115 
116 		if(__p is null)
117 		{
118 			return null;
119 		}
120 
121 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p);
122 	}
123 
124 	/**
125 	 * Gets the offset set via gtk_slice_list_model_set_offset().
126 	 *
127 	 * Returns: The offset
128 	 */
129 	public uint getOffset()
130 	{
131 		return gtk_slice_list_model_get_offset(gtkSliceListModel);
132 	}
133 
134 	/**
135 	 * Gets the size set via gtk_slice_list_model_set_size().
136 	 *
137 	 * Returns: The size
138 	 */
139 	public uint getSize()
140 	{
141 		return gtk_slice_list_model_get_size(gtkSliceListModel);
142 	}
143 
144 	/**
145 	 * Sets the model to show a slice of.
146 	 *
147 	 * The model's item type must conform to @self's item type.
148 	 *
149 	 * Params:
150 	 *     model = The model to be sliced
151 	 */
152 	public void setModel(ListModelIF model)
153 	{
154 		gtk_slice_list_model_set_model(gtkSliceListModel, (model is null) ? null : model.getListModelStruct());
155 	}
156 
157 	/**
158 	 * Sets the offset into the original model for this slice.
159 	 *
160 	 * If the offset is too large for the sliced model,
161 	 * @self will end up empty.
162 	 *
163 	 * Params:
164 	 *     offset = the new offset to use
165 	 */
166 	public void setOffset(uint offset)
167 	{
168 		gtk_slice_list_model_set_offset(gtkSliceListModel, offset);
169 	}
170 
171 	/**
172 	 * Sets the maximum size. @self will never have more items
173 	 * than @size.
174 	 *
175 	 * It can however have fewer items if the offset is too large
176 	 * or the model sliced from doesn't have enough items.
177 	 *
178 	 * Params:
179 	 *     size = the maximum size
180 	 */
181 	public void setSize(uint size)
182 	{
183 		gtk_slice_list_model_set_size(gtkSliceListModel, size);
184 	}
185 }