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.LayoutManager;
26 
27 private import gobject.ObjectG;
28 private import gtk.LayoutChild;
29 private import gtk.Widget;
30 private import gtk.c.functions;
31 public  import gtk.c.types;
32 
33 
34 /**
35  * Layout managers are delegate classes that handle the preferred size
36  * and the allocation of a widget.
37  * 
38  * You typically subclass `GtkLayoutManager` if you want to implement a
39  * layout policy for the children of a widget, or if you want to determine
40  * the size of a widget depending on its contents.
41  * 
42  * Each `GtkWidget` can only have a `GtkLayoutManager` instance associated
43  * to it at any given time; it is possible, though, to replace the layout
44  * manager instance using [method@Gtk.Widget.set_layout_manager].
45  * 
46  * ## Layout properties
47  * 
48  * A layout manager can expose properties for controlling the layout of
49  * each child, by creating an object type derived from [class@Gtk.LayoutChild]
50  * and installing the properties on it as normal `GObject` properties.
51  * 
52  * Each `GtkLayoutChild` instance storing the layout properties for a
53  * specific child is created through the [method@Gtk.LayoutManager.get_layout_child]
54  * method; a `GtkLayoutManager` controls the creation of its `GtkLayoutChild`
55  * instances by overriding the GtkLayoutManagerClass.create_layout_child()
56  * virtual function. The typical implementation should look like:
57  * 
58  * ```c
59  * static GtkLayoutChild *
60  * create_layout_child (GtkLayoutManager *manager,
61  * GtkWidget        *container,
62  * GtkWidget        *child)
63  * {
64  * return g_object_new (your_layout_child_get_type (),
65  * "layout-manager", manager,
66  * "child-widget", child,
67  * NULL);
68  * }
69  * ```
70  * 
71  * The [property@Gtk.LayoutChild:layout-manager] and
72  * [property@Gtk.LayoutChild:child-widget] properties
73  * on the newly created `GtkLayoutChild` instance are mandatory. The
74  * `GtkLayoutManager` will cache the newly created `GtkLayoutChild` instance
75  * until the widget is removed from its parent, or the parent removes the
76  * layout manager.
77  * 
78  * Each `GtkLayoutManager` instance creating a `GtkLayoutChild` should use
79  * [method@Gtk.LayoutManager.get_layout_child] every time it needs to query
80  * the layout properties; each `GtkLayoutChild` instance should call
81  * [method@Gtk.LayoutManager.layout_changed] every time a property is
82  * updated, in order to queue a new size measuring and allocation.
83  */
84 public class LayoutManager : ObjectG
85 {
86 	/** the main Gtk struct */
87 	protected GtkLayoutManager* gtkLayoutManager;
88 
89 	/** Get the main Gtk struct */
90 	public GtkLayoutManager* getLayoutManagerStruct(bool transferOwnership = false)
91 	{
92 		if (transferOwnership)
93 			ownedRef = false;
94 		return gtkLayoutManager;
95 	}
96 
97 	/** the main Gtk struct as a void* */
98 	protected override void* getStruct()
99 	{
100 		return cast(void*)gtkLayoutManager;
101 	}
102 
103 	/**
104 	 * Sets our main struct and passes it to the parent class.
105 	 */
106 	public this (GtkLayoutManager* gtkLayoutManager, bool ownedRef = false)
107 	{
108 		this.gtkLayoutManager = gtkLayoutManager;
109 		super(cast(GObject*)gtkLayoutManager, ownedRef);
110 	}
111 
112 
113 	/** */
114 	public static GType getType()
115 	{
116 		return gtk_layout_manager_get_type();
117 	}
118 
119 	/**
120 	 * Assigns the given @width, @height, and @baseline to
121 	 * a @widget, and computes the position and sizes of the children of
122 	 * the @widget using the layout management policy of @manager.
123 	 *
124 	 * Params:
125 	 *     widget = the `GtkWidget` using @manager
126 	 *     width = the new width of the @widget
127 	 *     height = the new height of the @widget
128 	 *     baseline = the baseline position of the @widget, or -1
129 	 */
130 	public void allocate(Widget widget, int width, int height, int baseline)
131 	{
132 		gtk_layout_manager_allocate(gtkLayoutManager, (widget is null) ? null : widget.getWidgetStruct(), width, height, baseline);
133 	}
134 
135 	/**
136 	 * Retrieves a `GtkLayoutChild` instance for the `GtkLayoutManager`,
137 	 * creating one if necessary.
138 	 *
139 	 * The @child widget must be a child of the widget using @manager.
140 	 *
141 	 * The `GtkLayoutChild` instance is owned by the `GtkLayoutManager`,
142 	 * and is guaranteed to exist as long as @child is a child of the
143 	 * `GtkWidget` using the given `GtkLayoutManager`.
144 	 *
145 	 * Params:
146 	 *     child = a `GtkWidget`
147 	 *
148 	 * Returns: a `GtkLayoutChild`
149 	 */
150 	public LayoutChild getLayoutChild(Widget child)
151 	{
152 		auto __p = gtk_layout_manager_get_layout_child(gtkLayoutManager, (child is null) ? null : child.getWidgetStruct());
153 
154 		if(__p is null)
155 		{
156 			return null;
157 		}
158 
159 		return ObjectG.getDObject!(LayoutChild)(cast(GtkLayoutChild*) __p);
160 	}
161 
162 	/**
163 	 * Retrieves the request mode of @manager.
164 	 *
165 	 * Returns: a `GtkSizeRequestMode`
166 	 */
167 	public GtkSizeRequestMode getRequestMode()
168 	{
169 		return gtk_layout_manager_get_request_mode(gtkLayoutManager);
170 	}
171 
172 	/**
173 	 * Retrieves the `GtkWidget` using the given `GtkLayoutManager`.
174 	 *
175 	 * Returns: a `GtkWidget`
176 	 */
177 	public Widget getWidget()
178 	{
179 		auto __p = gtk_layout_manager_get_widget(gtkLayoutManager);
180 
181 		if(__p is null)
182 		{
183 			return null;
184 		}
185 
186 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p);
187 	}
188 
189 	/**
190 	 * Queues a resize on the `GtkWidget` using @manager, if any.
191 	 *
192 	 * This function should be called by subclasses of `GtkLayoutManager`
193 	 * in response to changes to their layout management policies.
194 	 */
195 	public void layoutChanged()
196 	{
197 		gtk_layout_manager_layout_changed(gtkLayoutManager);
198 	}
199 
200 	/**
201 	 * Measures the size of the @widget using @manager, for the
202 	 * given @orientation and size.
203 	 *
204 	 * See the [class@Gtk.Widget] documentation on layout management for
205 	 * more details.
206 	 *
207 	 * Params:
208 	 *     widget = the `GtkWidget` using @manager
209 	 *     orientation = the orientation to measure
210 	 *     forSize = Size for the opposite of @orientation; for instance, if
211 	 *         the @orientation is %GTK_ORIENTATION_HORIZONTAL, this is the height
212 	 *         of the widget; if the @orientation is %GTK_ORIENTATION_VERTICAL, this
213 	 *         is the width of the widget. This allows to measure the height for the
214 	 *         given width, and the width for the given height. Use -1 if the size
215 	 *         is not known
216 	 *     minimum = the minimum size for the given size and
217 	 *         orientation
218 	 *     natural = the natural, or preferred size for the
219 	 *         given size and orientation
220 	 *     minimumBaseline = the baseline position for the
221 	 *         minimum size
222 	 *     naturalBaseline = the baseline position for the
223 	 *         natural size
224 	 */
225 	public void measure(Widget widget, GtkOrientation orientation, int forSize, out int minimum, out int natural, out int minimumBaseline, out int naturalBaseline)
226 	{
227 		gtk_layout_manager_measure(gtkLayoutManager, (widget is null) ? null : widget.getWidgetStruct(), orientation, forSize, &minimum, &natural, &minimumBaseline, &naturalBaseline);
228 	}
229 }