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