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.Button; 32 private import gtk.Widget; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 private import std.algorithm; 36 37 38 /** 39 * `GtkInfoBar` can be show messages to the user without a dialog. 40 * 41 * ![An example GtkInfoBar](info-bar.png) 42 * 43 * It is often temporarily shown at the top or bottom of a document. 44 * In contrast to [class@Gtk.Dialog], which has an action area at the 45 * bottom, `GtkInfoBar` has an action area at the side. 46 * 47 * The API of `GtkInfoBar` is very similar to `GtkDialog`, allowing you 48 * to add buttons to the action area with [method@Gtk.InfoBar.add_button] 49 * or [ctor@Gtk.InfoBar.new_with_buttons]. The sensitivity of action widgets 50 * can be controlled with [method@Gtk.InfoBar.set_response_sensitive]. 51 * 52 * To add widgets to the main content area of a `GtkInfoBar`, use 53 * [method@Gtk.InfoBar.add_child]. 54 * 55 * Similar to [class@Gtk.MessageDialog], the contents of a `GtkInfoBar` 56 * can by classified as error message, warning, informational message, etc, 57 * by using [method@Gtk.InfoBar.set_message_type]. GTK may use the message 58 * type to determine how the message is displayed. 59 * 60 * A simple example for using a `GtkInfoBar`: 61 * ```c 62 * GtkWidget *message_label; 63 * GtkWidget *widget; 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 * message_label = gtk_label_new (""); 73 * gtk_info_bar_add_child (bar, message_label); 74 * gtk_info_bar_add_button (bar, 75 * _("_OK"), 76 * GTK_RESPONSE_OK); 77 * g_signal_connect (bar, 78 * "response", 79 * G_CALLBACK (gtk_widget_hide), 80 * NULL); 81 * gtk_grid_attach (GTK_GRID (grid), 82 * widget, 83 * 0, 2, 1, 1); 84 * 85 * // ... 86 * 87 * // show an error message 88 * gtk_label_set_text (GTK_LABEL (message_label), "An error occurred!"); 89 * gtk_info_bar_set_message_type (bar, GTK_MESSAGE_ERROR); 90 * gtk_widget_show (bar); 91 * ``` 92 * 93 * # GtkInfoBar as GtkBuildable 94 * 95 * The `GtkInfoBar` implementation of the `GtkBuildable` interface exposes 96 * the content area and action area as internal children with the names 97 * “content_area” and “action_area”. 98 * 99 * `GtkInfoBar` supports a custom <action-widgets> element, which can contain 100 * multiple <action-widget> elements. The “response” attribute specifies a 101 * numeric response, and the content of the element is the id of widget 102 * (which should be a child of the dialogs @action_area). 103 * 104 * # CSS nodes 105 * 106 * `GtkInfoBar` has a single CSS node with name infobar. The node may get 107 * one of the style classes .info, .warning, .error or .question, depending 108 * on the message type. 109 * If the info bar shows a close button, that button will have the .close 110 * style class applied. 111 */ 112 public class InfoBar : Widget 113 { 114 /** the main Gtk struct */ 115 protected GtkInfoBar* gtkInfoBar; 116 117 /** Get the main Gtk struct */ 118 public GtkInfoBar* getInfoBarStruct(bool transferOwnership = false) 119 { 120 if (transferOwnership) 121 ownedRef = false; 122 return gtkInfoBar; 123 } 124 125 /** the main Gtk struct as a void* */ 126 protected override void* getStruct() 127 { 128 return cast(void*)gtkInfoBar; 129 } 130 131 /** 132 * Sets our main struct and passes it to the parent class. 133 */ 134 public this (GtkInfoBar* gtkInfoBar, bool ownedRef = false) 135 { 136 this.gtkInfoBar = gtkInfoBar; 137 super(cast(GtkWidget*)gtkInfoBar, ownedRef); 138 } 139 140 141 /** */ 142 public static GType getType() 143 { 144 return gtk_info_bar_get_type(); 145 } 146 147 /** 148 * Creates a new `GtkInfoBar` object. 149 * 150 * Returns: a new `GtkInfoBar` object 151 * 152 * Throws: ConstructionException GTK+ fails to create the object. 153 */ 154 public this() 155 { 156 auto __p = gtk_info_bar_new(); 157 158 if(__p is null) 159 { 160 throw new ConstructionException("null returned by new"); 161 } 162 163 this(cast(GtkInfoBar*) __p); 164 } 165 166 /** 167 * Add an activatable widget to the action area of a `GtkInfoBar`. 168 * 169 * This also connects a signal handler that will emit the 170 * [signal@Gtk.InfoBar::response] signal on the message area 171 * when the widget is activated. The widget is appended to the 172 * end of the message areas action area. 173 * 174 * Params: 175 * child = an activatable widget 176 * responseId = response ID for @child 177 */ 178 public void addActionWidget(Widget child, int responseId) 179 { 180 gtk_info_bar_add_action_widget(gtkInfoBar, (child is null) ? null : child.getWidgetStruct(), responseId); 181 } 182 183 /** 184 * Adds a button with the given text. 185 * 186 * Clicking the button will emit the [signal@Gtk.InfoBar::response] 187 * signal with the given response_id. The button is appended to the 188 * end of the info bars's action area. The button widget is returned, 189 * but usually you don't need it. 190 * 191 * Params: 192 * buttonText = text of button 193 * responseId = response ID for the button 194 * 195 * Returns: the `GtkButton` widget 196 * that was added 197 */ 198 public Button addButton(string buttonText, int responseId) 199 { 200 auto __p = gtk_info_bar_add_button(gtkInfoBar, Str.toStringz(buttonText), responseId); 201 202 if(__p is null) 203 { 204 return null; 205 } 206 207 return ObjectG.getDObject!(Button)(cast(GtkButton*) __p); 208 } 209 210 /** 211 * Adds a widget to the content area of the info bar. 212 * 213 * Params: 214 * widget = the child to be added 215 */ 216 public void addChild(Widget widget) 217 { 218 gtk_info_bar_add_child(gtkInfoBar, (widget is null) ? null : widget.getWidgetStruct()); 219 } 220 221 /** 222 * Returns the message type of the message area. 223 * 224 * Returns: the message type of the message area. 225 */ 226 public GtkMessageType getMessageType() 227 { 228 return gtk_info_bar_get_message_type(gtkInfoBar); 229 } 230 231 /** 232 * Returns whether the info bar is currently revealed. 233 * 234 * Returns: the current value of the [property@Gtk.InfoBar:revealed] property 235 */ 236 public bool getRevealed() 237 { 238 return gtk_info_bar_get_revealed(gtkInfoBar) != 0; 239 } 240 241 /** 242 * Returns whether the widget will display a standard close button. 243 * 244 * Returns: %TRUE if the widget displays standard close button 245 */ 246 public bool getShowCloseButton() 247 { 248 return gtk_info_bar_get_show_close_button(gtkInfoBar) != 0; 249 } 250 251 /** 252 * Removes a widget from the action area of @info_bar. 253 * 254 * The widget must have been put there by a call to 255 * [method@Gtk.InfoBar.add_action_widget] or [method@Gtk.InfoBar.add_button]. 256 * 257 * Params: 258 * widget = an action widget to remove 259 */ 260 public void removeActionWidget(Widget widget) 261 { 262 gtk_info_bar_remove_action_widget(gtkInfoBar, (widget is null) ? null : widget.getWidgetStruct()); 263 } 264 265 /** 266 * Removes a widget from the content area of the info bar. 267 * 268 * Params: 269 * widget = a child that has been added to the content area 270 */ 271 public void removeChild(Widget widget) 272 { 273 gtk_info_bar_remove_child(gtkInfoBar, (widget is null) ? null : widget.getWidgetStruct()); 274 } 275 276 /** 277 * Emits the “response” signal with the given @response_id. 278 * 279 * Params: 280 * responseId = a response ID 281 */ 282 public void response(int responseId) 283 { 284 gtk_info_bar_response(gtkInfoBar, responseId); 285 } 286 287 /** 288 * Sets the last widget in the info bar’s action area with 289 * the given response_id as the default widget for the dialog. 290 * 291 * Pressing “Enter” normally activates the default widget. 292 * 293 * Note that this function currently requires @info_bar to 294 * be added to a widget hierarchy. 295 * 296 * Params: 297 * responseId = a response ID 298 */ 299 public void setDefaultResponse(int responseId) 300 { 301 gtk_info_bar_set_default_response(gtkInfoBar, responseId); 302 } 303 304 /** 305 * Sets the message type of the message area. 306 * 307 * GTK uses this type to determine how the message is displayed. 308 * 309 * Params: 310 * messageType = a #GtkMessageType 311 */ 312 public void setMessageType(GtkMessageType messageType) 313 { 314 gtk_info_bar_set_message_type(gtkInfoBar, messageType); 315 } 316 317 /** 318 * Sets the sensitivity of action widgets for @response_id. 319 * 320 * Calls `gtk_widget_set_sensitive (widget, setting)` for each 321 * widget in the info bars’s action area with the given @response_id. 322 * A convenient way to sensitize/desensitize buttons. 323 * 324 * Params: 325 * responseId = a response ID 326 * setting = TRUE for sensitive 327 */ 328 public void setResponseSensitive(int responseId, bool setting) 329 { 330 gtk_info_bar_set_response_sensitive(gtkInfoBar, responseId, setting); 331 } 332 333 /** 334 * Sets whether the `GtkInfoBar` is revealed. 335 * 336 * Changing this will make @info_bar reveal or conceal 337 * itself via a sliding transition. 338 * 339 * Note: this does not show or hide @info_bar in the 340 * [property@Gtk.Widget:visible] sense, so revealing has no effect 341 * if [property@Gtk.Widget:visible] is %FALSE. 342 * 343 * Params: 344 * revealed = The new value of the property 345 */ 346 public void setRevealed(bool revealed) 347 { 348 gtk_info_bar_set_revealed(gtkInfoBar, revealed); 349 } 350 351 /** 352 * If true, a standard close button is shown. 353 * 354 * When clicked it emits the response %GTK_RESPONSE_CLOSE. 355 * 356 * Params: 357 * setting = %TRUE to include a close button 358 */ 359 public void setShowCloseButton(bool setting) 360 { 361 gtk_info_bar_set_show_close_button(gtkInfoBar, setting); 362 } 363 364 /** 365 * Gets emitted when the user uses a keybinding to dismiss the info bar. 366 * 367 * The ::close signal is a [keybinding signal](class.SignalAction.html). 368 * 369 * The default binding for this signal is the Escape key. 370 */ 371 gulong addOnClose(void delegate(InfoBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 372 { 373 return Signals.connect(this, "close", dlg, connectFlags ^ ConnectFlags.SWAPPED); 374 } 375 376 /** 377 * Emitted when an action widget is clicked. 378 * 379 * The signal is also emitted when the application programmer 380 * calls [method@Gtk.InfoBar.response]. The @response_id depends 381 * on which action widget was clicked. 382 * 383 * Params: 384 * responseId = the response ID 385 */ 386 gulong addOnResponse(void delegate(int, InfoBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 387 { 388 return Signals.connect(this, "response", dlg, connectFlags ^ ConnectFlags.SWAPPED); 389 } 390 }