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