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