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