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.Statusbar;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.Box;
32 private import gtk.Widget;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 public  import gtkc.gtktypes;
36 private import std.algorithm;
37 
38 
39 /**
40  * A #GtkStatusbar is usually placed along the bottom of an application's
41  * main #GtkWindow. It may provide a regular commentary of the application's
42  * status (as is usually the case in a web browser, for example), or may be
43  * used to simply output a message when the status changes, (when an upload
44  * is complete in an FTP client, for example).
45  * 
46  * Status bars in GTK+ maintain a stack of messages. The message at
47  * the top of the each bar’s stack is the one that will currently be displayed.
48  * 
49  * Any messages added to a statusbar’s stack must specify a
50  * context id that is used to uniquely identify
51  * the source of a message. This context id can be generated by
52  * gtk_statusbar_get_context_id(), given a message and the statusbar that
53  * it will be added to. Note that messages are stored in a stack, and when
54  * choosing which message to display, the stack structure is adhered to,
55  * regardless of the context identifier of a message.
56  * 
57  * One could say that a statusbar maintains one stack of messages for
58  * display purposes, but allows multiple message producers to maintain
59  * sub-stacks of the messages they produced (via context ids).
60  * 
61  * Status bars are created using gtk_statusbar_new().
62  * 
63  * Messages are added to the bar’s stack with gtk_statusbar_push().
64  * 
65  * The message at the top of the stack can be removed using
66  * gtk_statusbar_pop(). A message can be removed from anywhere in the
67  * stack if its message id was recorded at the time it was added. This
68  * is done using gtk_statusbar_remove().
69  * 
70  * # CSS node
71  * 
72  * GtkStatusbar has a single CSS node with name statusbar.
73  */
74 public class Statusbar : Box
75 {
76 	/** the main Gtk struct */
77 	protected GtkStatusbar* gtkStatusbar;
78 
79 	/** Get the main Gtk struct */
80 	public GtkStatusbar* getStatusbarStruct(bool transferOwnership = false)
81 	{
82 		if (transferOwnership)
83 			ownedRef = false;
84 		return gtkStatusbar;
85 	}
86 
87 	/** the main Gtk struct as a void* */
88 	protected override void* getStruct()
89 	{
90 		return cast(void*)gtkStatusbar;
91 	}
92 
93 	protected override void setStruct(GObject* obj)
94 	{
95 		gtkStatusbar = cast(GtkStatusbar*)obj;
96 		super.setStruct(obj);
97 	}
98 
99 	/**
100 	 * Sets our main struct and passes it to the parent class.
101 	 */
102 	public this (GtkStatusbar* gtkStatusbar, bool ownedRef = false)
103 	{
104 		this.gtkStatusbar = gtkStatusbar;
105 		super(cast(GtkBox*)gtkStatusbar, ownedRef);
106 	}
107 
108 	/**
109 	 * Retrieves the box containing the label widget.
110 	 * Since 2.20
111 	 * Returns: a GtkBox. [transfer none]
112 	 */
113 	public Box getMessageArea()
114 	{
115 		auto p = gtk_statusbar_get_message_area(gtkStatusbar);
116 		if(p is null)
117 		{
118 			return null;
119 		}
120 		return ObjectG.getDObject!(Box)(cast(GtkBox*) p);
121 	}
122 
123 	/**
124 	 */
125 
126 	/** */
127 	public static GType getType()
128 	{
129 		return gtk_statusbar_get_type();
130 	}
131 
132 	/**
133 	 * Creates a new #GtkStatusbar ready for messages.
134 	 *
135 	 * Returns: the new #GtkStatusbar
136 	 *
137 	 * Throws: ConstructionException GTK+ fails to create the object.
138 	 */
139 	public this()
140 	{
141 		auto p = gtk_statusbar_new();
142 
143 		if(p is null)
144 		{
145 			throw new ConstructionException("null returned by new");
146 		}
147 
148 		this(cast(GtkStatusbar*) p);
149 	}
150 
151 	/**
152 	 * Returns a new context identifier, given a description
153 	 * of the actual context. Note that the description is
154 	 * not shown in the UI.
155 	 *
156 	 * Params:
157 	 *     contextDescription = textual description of what context
158 	 *         the new message is being used in
159 	 *
160 	 * Returns: an integer id
161 	 */
162 	public uint getContextId(string contextDescription)
163 	{
164 		return gtk_statusbar_get_context_id(gtkStatusbar, Str.toStringz(contextDescription));
165 	}
166 
167 	/**
168 	 * Removes the first message in the #GtkStatusbar’s stack
169 	 * with the given context id.
170 	 *
171 	 * Note that this may not change the displayed message, if
172 	 * the message at the top of the stack has a different
173 	 * context id.
174 	 *
175 	 * Params:
176 	 *     contextId = a context identifier
177 	 */
178 	public void pop(uint contextId)
179 	{
180 		gtk_statusbar_pop(gtkStatusbar, contextId);
181 	}
182 
183 	/**
184 	 * Pushes a new message onto a statusbar’s stack.
185 	 *
186 	 * Params:
187 	 *     contextId = the message’s context id, as returned by
188 	 *         gtk_statusbar_get_context_id()
189 	 *     text = the message to add to the statusbar
190 	 *
191 	 * Returns: a message id that can be used with
192 	 *     gtk_statusbar_remove().
193 	 */
194 	public uint push(uint contextId, string text)
195 	{
196 		return gtk_statusbar_push(gtkStatusbar, contextId, Str.toStringz(text));
197 	}
198 
199 	/**
200 	 * Forces the removal of a message from a statusbar’s stack.
201 	 * The exact @context_id and @message_id must be specified.
202 	 *
203 	 * Params:
204 	 *     contextId = a context identifier
205 	 *     messageId = a message identifier, as returned by gtk_statusbar_push()
206 	 */
207 	public void remove(uint contextId, uint messageId)
208 	{
209 		gtk_statusbar_remove(gtkStatusbar, contextId, messageId);
210 	}
211 
212 	/**
213 	 * Forces the removal of all messages from a statusbar's
214 	 * stack with the exact @context_id.
215 	 *
216 	 * Params:
217 	 *     contextId = a context identifier
218 	 *
219 	 * Since: 2.22
220 	 */
221 	public void removeAll(uint contextId)
222 	{
223 		gtk_statusbar_remove_all(gtkStatusbar, contextId);
224 	}
225 
226 	protected class OnTextPoppedDelegateWrapper
227 	{
228 		void delegate(uint, string, Statusbar) dlg;
229 		gulong handlerId;
230 
231 		this(void delegate(uint, string, Statusbar) dlg)
232 		{
233 			this.dlg = dlg;
234 			onTextPoppedListeners ~= this;
235 		}
236 
237 		void remove(OnTextPoppedDelegateWrapper source)
238 		{
239 			foreach(index, wrapper; onTextPoppedListeners)
240 			{
241 				if (wrapper.handlerId == source.handlerId)
242 				{
243 					onTextPoppedListeners[index] = null;
244 					onTextPoppedListeners = std.algorithm.remove(onTextPoppedListeners, index);
245 					break;
246 				}
247 			}
248 		}
249 	}
250 	OnTextPoppedDelegateWrapper[] onTextPoppedListeners;
251 
252 	/**
253 	 * Is emitted whenever a new message is popped off a statusbar's stack.
254 	 *
255 	 * Params:
256 	 *     contextId = the context id of the relevant message/statusbar
257 	 *     text = the message that was just popped
258 	 */
259 	gulong addOnTextPopped(void delegate(uint, string, Statusbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
260 	{
261 		auto wrapper = new OnTextPoppedDelegateWrapper(dlg);
262 		wrapper.handlerId = Signals.connectData(
263 			this,
264 			"text-popped",
265 			cast(GCallback)&callBackTextPopped,
266 			cast(void*)wrapper,
267 			cast(GClosureNotify)&callBackTextPoppedDestroy,
268 			connectFlags);
269 		return wrapper.handlerId;
270 	}
271 
272 	extern(C) static void callBackTextPopped(GtkStatusbar* statusbarStruct, uint contextId, char* text, OnTextPoppedDelegateWrapper wrapper)
273 	{
274 		wrapper.dlg(contextId, Str.toString(text), wrapper.outer);
275 	}
276 
277 	extern(C) static void callBackTextPoppedDestroy(OnTextPoppedDelegateWrapper wrapper, GClosure* closure)
278 	{
279 		wrapper.remove(wrapper);
280 	}
281 
282 	protected class OnTextPushedDelegateWrapper
283 	{
284 		void delegate(uint, string, Statusbar) dlg;
285 		gulong handlerId;
286 
287 		this(void delegate(uint, string, Statusbar) dlg)
288 		{
289 			this.dlg = dlg;
290 			onTextPushedListeners ~= this;
291 		}
292 
293 		void remove(OnTextPushedDelegateWrapper source)
294 		{
295 			foreach(index, wrapper; onTextPushedListeners)
296 			{
297 				if (wrapper.handlerId == source.handlerId)
298 				{
299 					onTextPushedListeners[index] = null;
300 					onTextPushedListeners = std.algorithm.remove(onTextPushedListeners, index);
301 					break;
302 				}
303 			}
304 		}
305 	}
306 	OnTextPushedDelegateWrapper[] onTextPushedListeners;
307 
308 	/**
309 	 * Is emitted whenever a new message gets pushed onto a statusbar's stack.
310 	 *
311 	 * Params:
312 	 *     contextId = the context id of the relevant message/statusbar
313 	 *     text = the message that was pushed
314 	 */
315 	gulong addOnTextPushed(void delegate(uint, string, Statusbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
316 	{
317 		auto wrapper = new OnTextPushedDelegateWrapper(dlg);
318 		wrapper.handlerId = Signals.connectData(
319 			this,
320 			"text-pushed",
321 			cast(GCallback)&callBackTextPushed,
322 			cast(void*)wrapper,
323 			cast(GClosureNotify)&callBackTextPushedDestroy,
324 			connectFlags);
325 		return wrapper.handlerId;
326 	}
327 
328 	extern(C) static void callBackTextPushed(GtkStatusbar* statusbarStruct, uint contextId, char* text, OnTextPushedDelegateWrapper wrapper)
329 	{
330 		wrapper.dlg(contextId, Str.toString(text), wrapper.outer);
331 	}
332 
333 	extern(C) static void callBackTextPushedDestroy(OnTextPushedDelegateWrapper wrapper, GClosure* closure)
334 	{
335 		wrapper.remove(wrapper);
336 	}
337 }