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 public static GType getType() 227 { 228 return gtk_info_bar_get_type(); 229 } 230 231 /** 232 * Creates a new #GtkInfoBar object. 233 * 234 * Return: a new #GtkInfoBar object 235 * 236 * Since: 2.18 237 * 238 * Throws: ConstructionException GTK+ fails to create the object. 239 */ 240 public this() 241 { 242 auto p = gtk_info_bar_new(); 243 244 if(p is null) 245 { 246 throw new ConstructionException("null returned by new"); 247 } 248 249 this(cast(GtkInfoBar*) p); 250 } 251 252 /** 253 * Add an activatable widget to the action area of a #GtkInfoBar, 254 * connecting a signal handler that will emit the #GtkInfoBar::response 255 * signal on the message area when the widget is activated. The widget 256 * is appended to the end of the message areas action area. 257 * 258 * Params: 259 * child = an activatable widget 260 * responseId = response ID for @child 261 * 262 * Since: 2.18 263 */ 264 public void addActionWidget(Widget child, int responseId) 265 { 266 gtk_info_bar_add_action_widget(gtkInfoBar, (child is null) ? null : child.getWidgetStruct(), responseId); 267 } 268 269 /** 270 * Adds a button with the given text and sets things up so that 271 * clicking the button will emit the “response” signal with the given 272 * response_id. The button is appended to the end of the info bars's 273 * action area. The button widget is returned, but usually you don't 274 * need it. 275 * 276 * Params: 277 * buttonText = text of button 278 * responseId = response ID for the button 279 * 280 * Return: the #GtkButton widget 281 * that was added 282 * 283 * Since: 2.18 284 */ 285 public Button addButton(string buttonText, int responseId) 286 { 287 auto p = gtk_info_bar_add_button(gtkInfoBar, Str.toStringz(buttonText), responseId); 288 289 if(p is null) 290 { 291 return null; 292 } 293 294 return ObjectG.getDObject!(Button)(cast(GtkButton*) p); 295 } 296 297 /** 298 * Returns the message type of the message area. 299 * 300 * Return: the message type of the message area. 301 * 302 * Since: 2.18 303 */ 304 public GtkMessageType getMessageType() 305 { 306 return gtk_info_bar_get_message_type(gtkInfoBar); 307 } 308 309 /** 310 * Returns whether the widget will display a standard close button. 311 * 312 * Return: %TRUE if the widget displays standard close button 313 * 314 * Since: 3.10 315 */ 316 public bool getShowCloseButton() 317 { 318 return gtk_info_bar_get_show_close_button(gtkInfoBar) != 0; 319 } 320 321 /** 322 * Emits the “response” signal with the given @response_id. 323 * 324 * Params: 325 * responseId = a response ID 326 * 327 * Since: 2.18 328 */ 329 public void response(int responseId) 330 { 331 gtk_info_bar_response(gtkInfoBar, responseId); 332 } 333 334 /** 335 * Sets the last widget in the info bar’s action area with 336 * the given response_id as the default widget for the dialog. 337 * Pressing “Enter” normally activates the default widget. 338 * 339 * Note that this function currently requires @info_bar to 340 * be added to a widget hierarchy. 341 * 342 * Params: 343 * responseId = a response ID 344 * 345 * Since: 2.18 346 */ 347 public void setDefaultResponse(int responseId) 348 { 349 gtk_info_bar_set_default_response(gtkInfoBar, responseId); 350 } 351 352 /** 353 * Sets the message type of the message area. 354 * GTK+ uses this type to determine what color to use 355 * when drawing the message area. 356 * 357 * Params: 358 * messageType = a #GtkMessageType 359 * 360 * Since: 2.18 361 */ 362 public void setMessageType(GtkMessageType messageType) 363 { 364 gtk_info_bar_set_message_type(gtkInfoBar, messageType); 365 } 366 367 /** 368 * Calls gtk_widget_set_sensitive (widget, setting) for each 369 * widget in the info bars’s action area with the given response_id. 370 * A convenient way to sensitize/desensitize dialog buttons. 371 * 372 * Params: 373 * responseId = a response ID 374 * setting = TRUE for sensitive 375 * 376 * Since: 2.18 377 */ 378 public void setResponseSensitive(int responseId, bool setting) 379 { 380 gtk_info_bar_set_response_sensitive(gtkInfoBar, responseId, setting); 381 } 382 383 /** 384 * If true, a standard close button is shown. When clicked it emits 385 * the response %GTK_RESPONSE_CLOSE. 386 * 387 * Params: 388 * setting = %TRUE to include a close button 389 * 390 * Since: 3.10 391 */ 392 public void setShowCloseButton(bool setting) 393 { 394 gtk_info_bar_set_show_close_button(gtkInfoBar, setting); 395 } 396 397 int[string] connectedSignals; 398 399 void delegate(InfoBar)[] onCloseListeners; 400 /** 401 * The ::close signal is a 402 * [keybinding signal][GtkBindingSignal] 403 * which gets emitted when the user uses a keybinding to dismiss 404 * the info bar. 405 * 406 * The default binding for this signal is the Escape key. 407 * 408 * Since: 2.18 409 */ 410 void addOnClose(void delegate(InfoBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 411 { 412 if ( "close" !in connectedSignals ) 413 { 414 Signals.connectData( 415 this, 416 "close", 417 cast(GCallback)&callBackClose, 418 cast(void*)this, 419 null, 420 connectFlags); 421 connectedSignals["close"] = 1; 422 } 423 onCloseListeners ~= dlg; 424 } 425 extern(C) static void callBackClose(GtkInfoBar* infobarStruct, InfoBar _infobar) 426 { 427 foreach ( void delegate(InfoBar) dlg; _infobar.onCloseListeners ) 428 { 429 dlg(_infobar); 430 } 431 } 432 433 void delegate(int, InfoBar)[] onResponseListeners; 434 /** 435 * Emitted when an action widget is clicked or the application programmer 436 * calls gtk_dialog_response(). The @response_id depends on which action 437 * widget was clicked. 438 * 439 * Params: 440 * responseId = the response ID 441 * 442 * Since: 2.18 443 */ 444 void addOnResponse(void delegate(int, InfoBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 445 { 446 if ( "response" !in connectedSignals ) 447 { 448 Signals.connectData( 449 this, 450 "response", 451 cast(GCallback)&callBackResponse, 452 cast(void*)this, 453 null, 454 connectFlags); 455 connectedSignals["response"] = 1; 456 } 457 onResponseListeners ~= dlg; 458 } 459 extern(C) static void callBackResponse(GtkInfoBar* infobarStruct, int responseId, InfoBar _infobar) 460 { 461 foreach ( void delegate(int, InfoBar) dlg; _infobar.onResponseListeners ) 462 { 463 dlg(responseId, _infobar); 464 } 465 } 466 }