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 public class InfoBar : Box
107 {
108 	/** the main Gtk struct */
109 	protected GtkInfoBar* gtkInfoBar;
110 
111 	/** Get the main Gtk struct */
112 	public GtkInfoBar* getInfoBarStruct()
113 	{
114 		return gtkInfoBar;
115 	}
116 
117 	/** the main Gtk struct as a void* */
118 	protected override void* getStruct()
119 	{
120 		return cast(void*)gtkInfoBar;
121 	}
122 
123 	protected override void setStruct(GObject* obj)
124 	{
125 		gtkInfoBar = cast(GtkInfoBar*)obj;
126 		super.setStruct(obj);
127 	}
128 
129 	/**
130 	 * Sets our main struct and passes it to the parent class.
131 	 */
132 	public this (GtkInfoBar* gtkInfoBar, bool ownedRef = false)
133 	{
134 		this.gtkInfoBar = gtkInfoBar;
135 		super(cast(GtkBox*)gtkInfoBar, ownedRef);
136 	}
137 
138 	/** */
139 	public this(string[] buttonsText, ResponseType[] responses)
140 	{
141 		this();
142 		
143 		for ( int i=0 ; i<buttonsText.length && i<responses.length ; i++)
144 		{
145 			addButton(buttonsText[i], responses[i]);
146 		}
147 	}
148 	
149 	/** */
150 	public this(StockID[] stockIDs, ResponseType[] responses)
151 	{
152 		this();
153 		
154 		for ( int i=0 ; i<stockIDs.length && i<responses.length ; i++)
155 		{
156 			addButton(stockIDs[i], responses[i]);
157 		}
158 	}
159 	
160 	/** */
161 	public Button addButton(StockID stockID, int responseId)
162 	{
163 		auto p = gtk_info_bar_add_button(gtkInfoBar, Str.toStringz(stockID), responseId);
164 		
165 		if ( p is null )
166 		{
167 			return null;
168 		}
169 		
170 		return new Button(cast(GtkButton*)p);
171 	}
172 	
173 	/** */
174 	public void addButtons(string[] buttonsText, ResponseType[] responses)
175 	{
176 		for ( int i=0 ; i<buttonsText.length && i<responses.length ; i++)
177 		{
178 			addButton(buttonsText[i], responses[i]);
179 		}
180 	}
181 	
182 	/** */
183 	public void addButtons(StockID[] stockIDs, ResponseType[] responses)
184 	{
185 		for ( int i=0 ; i<stockIDs.length && i<responses.length ; i++)
186 		{
187 			addButton(stockIDs[i], responses[i]);
188 		}
189 	}
190 	
191 	/**
192 	 * Returns the action area of info_bar.
193 	 * Since 2.18
194 	 * Returns: the action area.
195 	 */
196 	public VButtonBox getActionArea()
197 	{
198 		// GtkWidget * gtk_info_bar_get_action_area (GtkInfoBar *info_bar);
199 		auto p = gtk_info_bar_get_action_area(gtkInfoBar);
200 		if(p is null)
201 		{
202 			return null;
203 		}
204 		return new VButtonBox(cast(GtkVButtonBox*) p);
205 	}
206 	
207 	/**
208 	 * Returns the content area of info_bar.
209 	 * Since 2.18
210 	 * Returns: the content area.
211 	 */
212 	public HBox getContentArea()
213 	{
214 		// GtkWidget * gtk_info_bar_get_content_area (GtkInfoBar *info_bar);
215 		auto p = gtk_info_bar_get_content_area(gtkInfoBar);
216 		if(p is null)
217 		{
218 			return null;
219 		}
220 		return new HBox(cast(GtkHBox*) p);
221 	}
222 
223 	/**
224 	 */
225 
226 	/** */
227 	public static GType getType()
228 	{
229 		return gtk_info_bar_get_type();
230 	}
231 
232 	/**
233 	 * Creates a new #GtkInfoBar object.
234 	 *
235 	 * Return: a new #GtkInfoBar object
236 	 *
237 	 * Since: 2.18
238 	 *
239 	 * Throws: ConstructionException GTK+ fails to create the object.
240 	 */
241 	public this()
242 	{
243 		auto p = gtk_info_bar_new();
244 		
245 		if(p is null)
246 		{
247 			throw new ConstructionException("null returned by new");
248 		}
249 		
250 		this(cast(GtkInfoBar*) p);
251 	}
252 
253 	/**
254 	 * Add an activatable widget to the action area of a #GtkInfoBar,
255 	 * connecting a signal handler that will emit the #GtkInfoBar::response
256 	 * signal on the message area when the widget is activated. The widget
257 	 * is appended to the end of the message areas action area.
258 	 *
259 	 * Params:
260 	 *     child = an activatable widget
261 	 *     responseId = response ID for @child
262 	 *
263 	 * Since: 2.18
264 	 */
265 	public void addActionWidget(Widget child, int responseId)
266 	{
267 		gtk_info_bar_add_action_widget(gtkInfoBar, (child is null) ? null : child.getWidgetStruct(), responseId);
268 	}
269 
270 	/**
271 	 * Adds a button with the given text and sets things up so that
272 	 * clicking the button will emit the “response” signal with the given
273 	 * response_id. The button is appended to the end of the info bars's
274 	 * action area. The button widget is returned, but usually you don't
275 	 * need it.
276 	 *
277 	 * Params:
278 	 *     buttonText = text of button
279 	 *     responseId = response ID for the button
280 	 *
281 	 * Return: the #GtkButton widget
282 	 *     that was added
283 	 *
284 	 * Since: 2.18
285 	 */
286 	public Button addButton(string buttonText, int responseId)
287 	{
288 		auto p = gtk_info_bar_add_button(gtkInfoBar, Str.toStringz(buttonText), responseId);
289 		
290 		if(p is null)
291 		{
292 			return null;
293 		}
294 		
295 		return ObjectG.getDObject!(Button)(cast(GtkButton*) p);
296 	}
297 
298 	/**
299 	 * Returns the message type of the message area.
300 	 *
301 	 * Return: the message type of the message area.
302 	 *
303 	 * Since: 2.18
304 	 */
305 	public GtkMessageType getMessageType()
306 	{
307 		return gtk_info_bar_get_message_type(gtkInfoBar);
308 	}
309 
310 	/**
311 	 * Returns whether the widget will display a standard close button.
312 	 *
313 	 * Return: %TRUE if the widget displays standard close button
314 	 *
315 	 * Since: 3.10
316 	 */
317 	public bool getShowCloseButton()
318 	{
319 		return gtk_info_bar_get_show_close_button(gtkInfoBar) != 0;
320 	}
321 
322 	/**
323 	 * Emits the “response” signal with the given @response_id.
324 	 *
325 	 * Params:
326 	 *     responseId = a response ID
327 	 *
328 	 * Since: 2.18
329 	 */
330 	public void response(int responseId)
331 	{
332 		gtk_info_bar_response(gtkInfoBar, responseId);
333 	}
334 
335 	/**
336 	 * Sets the last widget in the info bar’s action area with
337 	 * the given response_id as the default widget for the dialog.
338 	 * Pressing “Enter” normally activates the default widget.
339 	 *
340 	 * Note that this function currently requires @info_bar to
341 	 * be added to a widget hierarchy.
342 	 *
343 	 * Params:
344 	 *     responseId = a response ID
345 	 *
346 	 * Since: 2.18
347 	 */
348 	public void setDefaultResponse(int responseId)
349 	{
350 		gtk_info_bar_set_default_response(gtkInfoBar, responseId);
351 	}
352 
353 	/**
354 	 * Sets the message type of the message area.
355 	 * GTK+ uses this type to determine what color to use
356 	 * when drawing the message area.
357 	 *
358 	 * Params:
359 	 *     messageType = a #GtkMessageType
360 	 *
361 	 * Since: 2.18
362 	 */
363 	public void setMessageType(GtkMessageType messageType)
364 	{
365 		gtk_info_bar_set_message_type(gtkInfoBar, messageType);
366 	}
367 
368 	/**
369 	 * Calls gtk_widget_set_sensitive (widget, setting) for each
370 	 * widget in the info bars’s action area with the given response_id.
371 	 * A convenient way to sensitize/desensitize dialog buttons.
372 	 *
373 	 * Params:
374 	 *     responseId = a response ID
375 	 *     setting = TRUE for sensitive
376 	 *
377 	 * Since: 2.18
378 	 */
379 	public void setResponseSensitive(int responseId, bool setting)
380 	{
381 		gtk_info_bar_set_response_sensitive(gtkInfoBar, responseId, setting);
382 	}
383 
384 	/**
385 	 * If true, a standard close button is shown. When clicked it emits
386 	 * the response %GTK_RESPONSE_CLOSE.
387 	 *
388 	 * Params:
389 	 *     setting = %TRUE to include a close button
390 	 *
391 	 * Since: 3.10
392 	 */
393 	public void setShowCloseButton(bool setting)
394 	{
395 		gtk_info_bar_set_show_close_button(gtkInfoBar, setting);
396 	}
397 
398 	int[string] connectedSignals;
399 
400 	void delegate(InfoBar)[] onCloseListeners;
401 	/**
402 	 * The ::close signal is a
403 	 * [keybinding signal][GtkBindingSignal]
404 	 * which gets emitted when the user uses a keybinding to dismiss
405 	 * the info bar.
406 	 *
407 	 * The default binding for this signal is the Escape key.
408 	 *
409 	 * Since: 2.18
410 	 */
411 	void addOnClose(void delegate(InfoBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
412 	{
413 		if ( "close" !in connectedSignals )
414 		{
415 			Signals.connectData(
416 				this,
417 				"close",
418 				cast(GCallback)&callBackClose,
419 				cast(void*)this,
420 				null,
421 				connectFlags);
422 			connectedSignals["close"] = 1;
423 		}
424 		onCloseListeners ~= dlg;
425 	}
426 	extern(C) static void callBackClose(GtkInfoBar* infobarStruct, InfoBar _infobar)
427 	{
428 		foreach ( void delegate(InfoBar) dlg; _infobar.onCloseListeners )
429 		{
430 			dlg(_infobar);
431 		}
432 	}
433 
434 	void delegate(int, InfoBar)[] onResponseListeners;
435 	/**
436 	 * Emitted when an action widget is clicked or the application programmer
437 	 * calls gtk_dialog_response(). The @response_id depends on which action
438 	 * widget was clicked.
439 	 *
440 	 * Params:
441 	 *     responseId = the response ID
442 	 *
443 	 * Since: 2.18
444 	 */
445 	void addOnResponse(void delegate(int, InfoBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
446 	{
447 		if ( "response" !in connectedSignals )
448 		{
449 			Signals.connectData(
450 				this,
451 				"response",
452 				cast(GCallback)&callBackResponse,
453 				cast(void*)this,
454 				null,
455 				connectFlags);
456 			connectedSignals["response"] = 1;
457 		}
458 		onResponseListeners ~= dlg;
459 	}
460 	extern(C) static void callBackResponse(GtkInfoBar* infobarStruct, int responseId, InfoBar _infobar)
461 	{
462 		foreach ( void delegate(int, InfoBar) dlg; _infobar.onResponseListeners )
463 		{
464 			dlg(responseId, _infobar);
465 		}
466 	}
467 }