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