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 public  import gtkc.gdktypes;
34 private import gtkc.gtk;
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()
81 	{
82 		return gtkStatusbar;
83 	}
84 
85 	/** the main Gtk struct as a void* */
86 	protected override void* getStruct()
87 	{
88 		return cast(void*)gtkStatusbar;
89 	}
90 
91 	protected override void setStruct(GObject* obj)
92 	{
93 		gtkStatusbar = cast(GtkStatusbar*)obj;
94 		super.setStruct(obj);
95 	}
96 
97 	/**
98 	 * Sets our main struct and passes it to the parent class.
99 	 */
100 	public this (GtkStatusbar* gtkStatusbar, bool ownedRef = false)
101 	{
102 		this.gtkStatusbar = gtkStatusbar;
103 		super(cast(GtkBox*)gtkStatusbar, ownedRef);
104 	}
105 
106 	/**
107 	 * Retrieves the box containing the label widget.
108 	 * Since 2.20
109 	 * Returns: a GtkBox. [transfer none]
110 	 */
111 	public Box getMessageArea()
112 	{
113 		auto p = gtk_statusbar_get_message_area(gtkStatusbar);
114 		if(p is null)
115 		{
116 			return null;
117 		}
118 		return new Box(cast(GtkBox*) p);
119 	}
120 
121 	/**
122 	 */
123 
124 	/** */
125 	public static GType getType()
126 	{
127 		return gtk_statusbar_get_type();
128 	}
129 
130 	/**
131 	 * Creates a new #GtkStatusbar ready for messages.
132 	 *
133 	 * Return: the new #GtkStatusbar
134 	 *
135 	 * Throws: ConstructionException GTK+ fails to create the object.
136 	 */
137 	public this()
138 	{
139 		auto p = gtk_statusbar_new();
140 		
141 		if(p is null)
142 		{
143 			throw new ConstructionException("null returned by new");
144 		}
145 		
146 		this(cast(GtkStatusbar*) p);
147 	}
148 
149 	/**
150 	 * Returns a new context identifier, given a description
151 	 * of the actual context. Note that the description is
152 	 * not shown in the UI.
153 	 *
154 	 * Params:
155 	 *     contextDescription = textual description of what context
156 	 *         the new message is being used in
157 	 *
158 	 * Return: an integer id
159 	 */
160 	public uint getContextId(string contextDescription)
161 	{
162 		return gtk_statusbar_get_context_id(gtkStatusbar, Str.toStringz(contextDescription));
163 	}
164 
165 	/**
166 	 * Removes the first message in the #GtkStatusbar’s stack
167 	 * with the given context id.
168 	 *
169 	 * Note that this may not change the displayed message, if
170 	 * the message at the top of the stack has a different
171 	 * context id.
172 	 *
173 	 * Params:
174 	 *     contextId = a context identifier
175 	 */
176 	public void pop(uint contextId)
177 	{
178 		gtk_statusbar_pop(gtkStatusbar, contextId);
179 	}
180 
181 	/**
182 	 * Pushes a new message onto a statusbar’s stack.
183 	 *
184 	 * Params:
185 	 *     contextId = the message’s context id, as returned by
186 	 *         gtk_statusbar_get_context_id()
187 	 *     text = the message to add to the statusbar
188 	 *
189 	 * Return: a message id that can be used with
190 	 *     gtk_statusbar_remove().
191 	 */
192 	public uint push(uint contextId, string text)
193 	{
194 		return gtk_statusbar_push(gtkStatusbar, contextId, Str.toStringz(text));
195 	}
196 
197 	/**
198 	 * Forces the removal of a message from a statusbar’s stack.
199 	 * The exact @context_id and @message_id must be specified.
200 	 *
201 	 * Params:
202 	 *     contextId = a context identifier
203 	 *     messageId = a message identifier, as returned by gtk_statusbar_push()
204 	 */
205 	public void remove(uint contextId, uint messageId)
206 	{
207 		gtk_statusbar_remove(gtkStatusbar, contextId, messageId);
208 	}
209 
210 	/**
211 	 * Forces the removal of all messages from a statusbar's
212 	 * stack with the exact @context_id.
213 	 *
214 	 * Params:
215 	 *     contextId = a context identifier
216 	 *
217 	 * Since: 2.22
218 	 */
219 	public void removeAll(uint contextId)
220 	{
221 		gtk_statusbar_remove_all(gtkStatusbar, contextId);
222 	}
223 
224 	protected class OnTextPoppedDelegateWrapper
225 	{
226 		void delegate(uint, string, Statusbar) dlg;
227 		gulong handlerId;
228 		ConnectFlags flags;
229 		this(void delegate(uint, string, Statusbar) dlg, gulong handlerId, ConnectFlags flags)
230 		{
231 			this.dlg = dlg;
232 			this.handlerId = handlerId;
233 			this.flags = flags;
234 		}
235 	}
236 	protected OnTextPoppedDelegateWrapper[] onTextPoppedListeners;
237 
238 	/**
239 	 * Is emitted whenever a new message is popped off a statusbar's stack.
240 	 *
241 	 * Params:
242 	 *     contextId = the context id of the relevant message/statusbar
243 	 *     text = the message that was just popped
244 	 */
245 	gulong addOnTextPopped(void delegate(uint, string, Statusbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
246 	{
247 		onTextPoppedListeners ~= new OnTextPoppedDelegateWrapper(dlg, 0, connectFlags);
248 		onTextPoppedListeners[onTextPoppedListeners.length - 1].handlerId = Signals.connectData(
249 			this,
250 			"text-popped",
251 			cast(GCallback)&callBackTextPopped,
252 			cast(void*)onTextPoppedListeners[onTextPoppedListeners.length - 1],
253 			cast(GClosureNotify)&callBackTextPoppedDestroy,
254 			connectFlags);
255 		return onTextPoppedListeners[onTextPoppedListeners.length - 1].handlerId;
256 	}
257 	
258 	extern(C) static void callBackTextPopped(GtkStatusbar* statusbarStruct, uint contextId, char* text,OnTextPoppedDelegateWrapper wrapper)
259 	{
260 		wrapper.dlg(contextId, Str.toString(text), wrapper.outer);
261 	}
262 	
263 	extern(C) static void callBackTextPoppedDestroy(OnTextPoppedDelegateWrapper wrapper, GClosure* closure)
264 	{
265 		wrapper.outer.internalRemoveOnTextPopped(wrapper);
266 	}
267 
268 	protected void internalRemoveOnTextPopped(OnTextPoppedDelegateWrapper source)
269 	{
270 		foreach(index, wrapper; onTextPoppedListeners)
271 		{
272 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
273 			{
274 				onTextPoppedListeners[index] = null;
275 				onTextPoppedListeners = std.algorithm.remove(onTextPoppedListeners, index);
276 				break;
277 			}
278 		}
279 	}
280 	
281 
282 	protected class OnTextPushedDelegateWrapper
283 	{
284 		void delegate(uint, string, Statusbar) dlg;
285 		gulong handlerId;
286 		ConnectFlags flags;
287 		this(void delegate(uint, string, Statusbar) dlg, gulong handlerId, ConnectFlags flags)
288 		{
289 			this.dlg = dlg;
290 			this.handlerId = handlerId;
291 			this.flags = flags;
292 		}
293 	}
294 	protected OnTextPushedDelegateWrapper[] onTextPushedListeners;
295 
296 	/**
297 	 * Is emitted whenever a new message gets pushed onto a statusbar's stack.
298 	 *
299 	 * Params:
300 	 *     contextId = the context id of the relevant message/statusbar
301 	 *     text = the message that was pushed
302 	 */
303 	gulong addOnTextPushed(void delegate(uint, string, Statusbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
304 	{
305 		onTextPushedListeners ~= new OnTextPushedDelegateWrapper(dlg, 0, connectFlags);
306 		onTextPushedListeners[onTextPushedListeners.length - 1].handlerId = Signals.connectData(
307 			this,
308 			"text-pushed",
309 			cast(GCallback)&callBackTextPushed,
310 			cast(void*)onTextPushedListeners[onTextPushedListeners.length - 1],
311 			cast(GClosureNotify)&callBackTextPushedDestroy,
312 			connectFlags);
313 		return onTextPushedListeners[onTextPushedListeners.length - 1].handlerId;
314 	}
315 	
316 	extern(C) static void callBackTextPushed(GtkStatusbar* statusbarStruct, uint contextId, char* text,OnTextPushedDelegateWrapper wrapper)
317 	{
318 		wrapper.dlg(contextId, Str.toString(text), wrapper.outer);
319 	}
320 	
321 	extern(C) static void callBackTextPushedDestroy(OnTextPushedDelegateWrapper wrapper, GClosure* closure)
322 	{
323 		wrapper.outer.internalRemoveOnTextPushed(wrapper);
324 	}
325 
326 	protected void internalRemoveOnTextPushed(OnTextPushedDelegateWrapper source)
327 	{
328 		foreach(index, wrapper; onTextPushedListeners)
329 		{
330 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
331 			{
332 				onTextPushedListeners[index] = null;
333 				onTextPushedListeners = std.algorithm.remove(onTextPushedListeners, index);
334 				break;
335 			}
336 		}
337 	}
338 	
339 }