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