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.InfoBar;
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.Button;
33 private import gtk.HBox;
34 private import gtk.VButtonBox;
35 private import gtk.Widget;
36 public  import gtkc.gdktypes;
37 private import gtkc.gtk;
38 public  import gtkc.gtktypes;
39 
40 
41 /**
42  * #GtkInfoBar is a widget that can be used to show messages to
43  * the user without showing a dialog. It is often temporarily shown
44  * at the top or bottom of a document. In contrast to #GtkDialog, which
45  * has a action area at the bottom, #GtkInfoBar has an action area
46  * at the side.
47  * 
48  * The API of #GtkInfoBar is very similar to #GtkDialog, allowing you
49  * to add buttons to the action area with gtk_info_bar_add_button() or
50  * gtk_info_bar_new_with_buttons(). The sensitivity of action widgets
51  * can be controlled with gtk_info_bar_set_response_sensitive().
52  * To add widgets to the main content area of a #GtkInfoBar, use
53  * gtk_info_bar_get_content_area() and add your widgets to the container.
54  * 
55  * Similar to #GtkMessageDialog, the contents of a #GtkInfoBar can by
56  * classified as error message, warning, informational message, etc,
57  * by using gtk_info_bar_set_message_type(). GTK+ may use the message type
58  * to determine how the message is displayed.
59  * 
60  * A simple example for using a GtkInfoBar:
61  * |[<!-- language="C" -->
62  * // set up info bar
63  * GtkWidget *widget;
64  * GtkInfoBar *bar;
65  * 
66  * widget = gtk_info_bar_new ();
67  * bar = GTK_INFO_BAR (bar);
68  * 
69  * gtk_widget_set_no_show_all (widget, TRUE);
70  * message_label = gtk_label_new ("");
71  * gtk_widget_show (message_label);
72  * content_area = gtk_info_bar_get_content_area (bar);
73  * gtk_container_add (GTK_CONTAINER (content_area),
74  * message_label);
75  * gtk_info_bar_add_button (bar,
76  * _("_OK"),
77  * GTK_RESPONSE_OK);
78  * g_signal_connect (bar,
79  * "response",
80  * G_CALLBACK (gtk_widget_hide),
81  * NULL);
82  * gtk_grid_attach (GTK_GRID (grid),
83  * widget,
84  * 0, 2, 1, 1);
85  * 
86  * ...
87  * 
88  * // show an error message
89  * gtk_label_set_text (GTK_LABEL (message_label), message);
90  * gtk_info_bar_set_message_type (bar,
91  * GTK_MESSAGE_ERROR);
92  * gtk_widget_show (bar);
93  * ]|
94  * 
95  * # GtkInfoBar as GtkBuildable
96  * 
97  * The GtkInfoBar implementation of the GtkBuildable interface exposes
98  * the content area and action area as internal children with the names
99  * “content_area” and “action_area”.
100  * 
101  * GtkInfoBar supports a custom <action-widgets> element, which can contain
102  * multiple <action-widget> elements. The “response” attribute specifies a
103  * numeric response, and the content of the element is the id of widget
104  * (which should be a child of the dialogs @action_area).
105  * 
106  * # CSS nodes
107  * 
108  * GtkInfoBar has a single CSS node with name infobar. The node may get
109  * one of the style classes .info, .warning, .error or .question, depending
110  * on the message type.
111  */
112 public class InfoBar : Box
113 {
114 	/** the main Gtk struct */
115 	protected GtkInfoBar* gtkInfoBar;
116 
117 	/** Get the main Gtk struct */
118 	public GtkInfoBar* getInfoBarStruct()
119 	{
120 		return gtkInfoBar;
121 	}
122 
123 	/** the main Gtk struct as a void* */
124 	protected override void* getStruct()
125 	{
126 		return cast(void*)gtkInfoBar;
127 	}
128 
129 	protected override void setStruct(GObject* obj)
130 	{
131 		gtkInfoBar = cast(GtkInfoBar*)obj;
132 		super.setStruct(obj);
133 	}
134 
135 	/**
136 	 * Sets our main struct and passes it to the parent class.
137 	 */
138 	public this (GtkInfoBar* gtkInfoBar, bool ownedRef = false)
139 	{
140 		this.gtkInfoBar = gtkInfoBar;
141 		super(cast(GtkBox*)gtkInfoBar, ownedRef);
142 	}
143 
144 	/** */
145 	public this(string[] buttonsText, ResponseType[] responses)
146 	{
147 		this();
148 		
149 		for ( int i=0 ; i<buttonsText.length && i<responses.length ; i++)
150 		{
151 			addButton(buttonsText[i], responses[i]);
152 		}
153 	}
154 	
155 	/** */
156 	public this(StockID[] stockIDs, ResponseType[] responses)
157 	{
158 		this();
159 		
160 		for ( int i=0 ; i<stockIDs.length && i<responses.length ; i++)
161 		{
162 			addButton(stockIDs[i], responses[i]);
163 		}
164 	}
165 	
166 	/** */
167 	public Button addButton(StockID stockID, int responseId)
168 	{
169 		auto p = gtk_info_bar_add_button(gtkInfoBar, Str.toStringz(stockID), responseId);
170 		
171 		if ( p is null )
172 		{
173 			return null;
174 		}
175 		
176 		return new Button(cast(GtkButton*)p);
177 	}
178 	
179 	/** */
180 	public void addButtons(string[] buttonsText, ResponseType[] responses)
181 	{
182 		for ( int i=0 ; i<buttonsText.length && i<responses.length ; i++)
183 		{
184 			addButton(buttonsText[i], responses[i]);
185 		}
186 	}
187 	
188 	/** */
189 	public void addButtons(StockID[] stockIDs, ResponseType[] responses)
190 	{
191 		for ( int i=0 ; i<stockIDs.length && i<responses.length ; i++)
192 		{
193 			addButton(stockIDs[i], responses[i]);
194 		}
195 	}
196 	
197 	/**
198 	 * Returns the action area of info_bar.
199 	 * Since 2.18
200 	 * Returns: the action area.
201 	 */
202 	public VButtonBox getActionArea()
203 	{
204 		// GtkWidget * gtk_info_bar_get_action_area (GtkInfoBar *info_bar);
205 		auto p = gtk_info_bar_get_action_area(gtkInfoBar);
206 		if(p is null)
207 		{
208 			return null;
209 		}
210 		return new VButtonBox(cast(GtkVButtonBox*) p);
211 	}
212 	
213 	/**
214 	 * Returns the content area of info_bar.
215 	 * Since 2.18
216 	 * Returns: the content area.
217 	 */
218 	public HBox getContentArea()
219 	{
220 		// GtkWidget * gtk_info_bar_get_content_area (GtkInfoBar *info_bar);
221 		auto p = gtk_info_bar_get_content_area(gtkInfoBar);
222 		if(p is null)
223 		{
224 			return null;
225 		}
226 		return new HBox(cast(GtkHBox*) p);
227 	}
228 
229 	/**
230 	 */
231 
232 	/** */
233 	public static GType getType()
234 	{
235 		return gtk_info_bar_get_type();
236 	}
237 
238 	/**
239 	 * Creates a new #GtkInfoBar object.
240 	 *
241 	 * Return: a new #GtkInfoBar object
242 	 *
243 	 * Since: 2.18
244 	 *
245 	 * Throws: ConstructionException GTK+ fails to create the object.
246 	 */
247 	public this()
248 	{
249 		auto p = gtk_info_bar_new();
250 		
251 		if(p is null)
252 		{
253 			throw new ConstructionException("null returned by new");
254 		}
255 		
256 		this(cast(GtkInfoBar*) p);
257 	}
258 
259 	/**
260 	 * Add an activatable widget to the action area of a #GtkInfoBar,
261 	 * connecting a signal handler that will emit the #GtkInfoBar::response
262 	 * signal on the message area when the widget is activated. The widget
263 	 * is appended to the end of the message areas action area.
264 	 *
265 	 * Params:
266 	 *     child = an activatable widget
267 	 *     responseId = response ID for @child
268 	 *
269 	 * Since: 2.18
270 	 */
271 	public void addActionWidget(Widget child, int responseId)
272 	{
273 		gtk_info_bar_add_action_widget(gtkInfoBar, (child is null) ? null : child.getWidgetStruct(), responseId);
274 	}
275 
276 	/**
277 	 * Adds a button with the given text and sets things up so that
278 	 * clicking the button will emit the “response” signal with the given
279 	 * response_id. The button is appended to the end of the info bars's
280 	 * action area. The button widget is returned, but usually you don't
281 	 * need it.
282 	 *
283 	 * Params:
284 	 *     buttonText = text of button
285 	 *     responseId = response ID for the button
286 	 *
287 	 * Return: the #GtkButton widget
288 	 *     that was added
289 	 *
290 	 * Since: 2.18
291 	 */
292 	public Button addButton(string buttonText, int responseId)
293 	{
294 		auto p = gtk_info_bar_add_button(gtkInfoBar, Str.toStringz(buttonText), responseId);
295 		
296 		if(p is null)
297 		{
298 			return null;
299 		}
300 		
301 		return ObjectG.getDObject!(Button)(cast(GtkButton*) p);
302 	}
303 
304 	/**
305 	 * Returns the message type of the message area.
306 	 *
307 	 * Return: the message type of the message area.
308 	 *
309 	 * Since: 2.18
310 	 */
311 	public GtkMessageType getMessageType()
312 	{
313 		return gtk_info_bar_get_message_type(gtkInfoBar);
314 	}
315 
316 	/**
317 	 * Returns whether the widget will display a standard close button.
318 	 *
319 	 * Return: %TRUE if the widget displays standard close button
320 	 *
321 	 * Since: 3.10
322 	 */
323 	public bool getShowCloseButton()
324 	{
325 		return gtk_info_bar_get_show_close_button(gtkInfoBar) != 0;
326 	}
327 
328 	/**
329 	 * Emits the “response” signal with the given @response_id.
330 	 *
331 	 * Params:
332 	 *     responseId = a response ID
333 	 *
334 	 * Since: 2.18
335 	 */
336 	public void response(int responseId)
337 	{
338 		gtk_info_bar_response(gtkInfoBar, responseId);
339 	}
340 
341 	/**
342 	 * Sets the last widget in the info bar’s action area with
343 	 * the given response_id as the default widget for the dialog.
344 	 * Pressing “Enter” normally activates the default widget.
345 	 *
346 	 * Note that this function currently requires @info_bar to
347 	 * be added to a widget hierarchy.
348 	 *
349 	 * Params:
350 	 *     responseId = a response ID
351 	 *
352 	 * Since: 2.18
353 	 */
354 	public void setDefaultResponse(int responseId)
355 	{
356 		gtk_info_bar_set_default_response(gtkInfoBar, responseId);
357 	}
358 
359 	/**
360 	 * Sets the message type of the message area.
361 	 *
362 	 * GTK+ uses this type to determine how the message is displayed.
363 	 *
364 	 * Params:
365 	 *     messageType = a #GtkMessageType
366 	 *
367 	 * Since: 2.18
368 	 */
369 	public void setMessageType(GtkMessageType messageType)
370 	{
371 		gtk_info_bar_set_message_type(gtkInfoBar, messageType);
372 	}
373 
374 	/**
375 	 * Calls gtk_widget_set_sensitive (widget, setting) for each
376 	 * widget in the info bars’s action area with the given response_id.
377 	 * A convenient way to sensitize/desensitize dialog buttons.
378 	 *
379 	 * Params:
380 	 *     responseId = a response ID
381 	 *     setting = TRUE for sensitive
382 	 *
383 	 * Since: 2.18
384 	 */
385 	public void setResponseSensitive(int responseId, bool setting)
386 	{
387 		gtk_info_bar_set_response_sensitive(gtkInfoBar, responseId, setting);
388 	}
389 
390 	/**
391 	 * If true, a standard close button is shown. When clicked it emits
392 	 * the response %GTK_RESPONSE_CLOSE.
393 	 *
394 	 * Params:
395 	 *     setting = %TRUE to include a close button
396 	 *
397 	 * Since: 3.10
398 	 */
399 	public void setShowCloseButton(bool setting)
400 	{
401 		gtk_info_bar_set_show_close_button(gtkInfoBar, setting);
402 	}
403 
404 	int[string] connectedSignals;
405 
406 	void delegate(InfoBar)[] onCloseListeners;
407 	/**
408 	 * The ::close signal is a
409 	 * [keybinding signal][GtkBindingSignal]
410 	 * which gets emitted when the user uses a keybinding to dismiss
411 	 * the info bar.
412 	 *
413 	 * The default binding for this signal is the Escape key.
414 	 *
415 	 * Since: 2.18
416 	 */
417 	void addOnClose(void delegate(InfoBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
418 	{
419 		if ( "close" !in connectedSignals )
420 		{
421 			Signals.connectData(
422 				this,
423 				"close",
424 				cast(GCallback)&callBackClose,
425 				cast(void*)this,
426 				null,
427 				connectFlags);
428 			connectedSignals["close"] = 1;
429 		}
430 		onCloseListeners ~= dlg;
431 	}
432 	extern(C) static void callBackClose(GtkInfoBar* infobarStruct, InfoBar _infobar)
433 	{
434 		foreach ( void delegate(InfoBar) dlg; _infobar.onCloseListeners )
435 		{
436 			dlg(_infobar);
437 		}
438 	}
439 
440 	void delegate(int, InfoBar)[] onResponseListeners;
441 	/**
442 	 * Emitted when an action widget is clicked or the application programmer
443 	 * calls gtk_dialog_response(). The @response_id depends on which action
444 	 * widget was clicked.
445 	 *
446 	 * Params:
447 	 *     responseId = the response ID
448 	 *
449 	 * Since: 2.18
450 	 */
451 	void addOnResponse(void delegate(int, InfoBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
452 	{
453 		if ( "response" !in connectedSignals )
454 		{
455 			Signals.connectData(
456 				this,
457 				"response",
458 				cast(GCallback)&callBackResponse,
459 				cast(void*)this,
460 				null,
461 				connectFlags);
462 			connectedSignals["response"] = 1;
463 		}
464 		onResponseListeners ~= dlg;
465 	}
466 	extern(C) static void callBackResponse(GtkInfoBar* infobarStruct, int responseId, InfoBar _infobar)
467 	{
468 		foreach ( void delegate(int, InfoBar) dlg; _infobar.onResponseListeners )
469 		{
470 			dlg(responseId, _infobar);
471 		}
472 	}
473 }