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 * Conversion parameters: 26 * inFile = GtkDialog.html 27 * outPack = gtk 28 * outFile = Dialog 29 * strct = GtkDialog 30 * realStrct= 31 * ctorStrct= 32 * clss = Dialog 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gtk_dialog_ 41 * - gtk_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * - gtk_dialog_get_action_area 46 * - gtk_dialog_get_content_area 47 * omit signals: 48 * imports: 49 * - glib.Str 50 * - gtk.Window 51 * - gtk.Widget 52 * - gdk.Screen 53 * - gtk.HButtonBox 54 * - gtk.VBox 55 * structWrap: 56 * - GdkScreen* -> Screen 57 * - GtkWidget* -> Widget 58 * - GtkWindow* -> Window 59 * module aliases: 60 * local aliases: 61 * overrides: 62 */ 63 64 module gtk.Dialog; 65 66 public import gtkc.gtktypes; 67 68 private import gtkc.gtk; 69 private import glib.ConstructionException; 70 private import gobject.ObjectG; 71 72 private import gobject.Signals; 73 public import gtkc.gdktypes; 74 75 private import glib.Str; 76 private import gtk.Window; 77 private import gtk.Widget; 78 private import gdk.Screen; 79 private import gtk.HButtonBox; 80 private import gtk.VBox; 81 82 83 84 private import gtk.Window; 85 86 /** 87 * Description 88 * Dialog boxes are a convenient way to prompt the user for a small amount of 89 * input, e.g. to display a message, ask a question, or anything else that does 90 * not require extensive effort on the user's part. 91 * GTK+ treats a dialog as a window split vertically. The top section is a 92 * GtkVBox, and is where widgets such as a GtkLabel or a GtkEntry should 93 * be packed. The bottom area is known as the 94 * action_area. This is generally used for 95 * packing buttons into the dialog which may perform functions such as 96 * cancel, ok, or apply. The two areas are separated by a GtkHSeparator. 97 * GtkDialog boxes are created with a call to gtk_dialog_new() or 98 * gtk_dialog_new_with_buttons(). gtk_dialog_new_with_buttons() is recommended; it 99 * allows you to set the dialog title, some convenient flags, and add simple 100 * buttons. 101 * If 'dialog' is a newly created dialog, the two primary areas of the window 102 * can be accessed through gtk_dialog_get_content_area() and 103 * gtk_dialog_get_action_area(), as can be seen from the example, below. 104 * A 'modal' dialog (that is, one which freezes the rest of the application from 105 * user input), can be created by calling gtk_window_set_modal() on the dialog. Use 106 * the GTK_WINDOW() macro to cast the widget returned from gtk_dialog_new() into a 107 * GtkWindow. When using gtk_dialog_new_with_buttons() you can also pass the 108 * GTK_DIALOG_MODAL flag to make a dialog modal. 109 * If you add buttons to GtkDialog using gtk_dialog_new_with_buttons(), 110 * gtk_dialog_add_button(), gtk_dialog_add_buttons(), or 111 * gtk_dialog_add_action_widget(), clicking the button will emit a signal called 112 * "response" with a response ID that you specified. GTK+ will never assign a 113 * meaning to positive response IDs; these are entirely user-defined. But for 114 * convenience, you can use the response IDs in the GtkResponseType enumeration 115 * (these all have values less than zero). If a dialog receives a delete event, 116 * the "response" signal will be emitted with a response ID of GTK_RESPONSE_DELETE_EVENT. 117 * If you want to block waiting for a dialog to return before returning control 118 * flow to your code, you can call gtk_dialog_run(). This function enters a 119 * recursive main loop and waits for the user to respond to the dialog, returning the 120 * response ID corresponding to the button the user clicked. 121 * For the simple dialog in the following example, in reality you'd probably use 122 * GtkMessageDialog to save yourself some effort. But you'd need to create the 123 * dialog contents manually if you had more than a simple message in the dialog. 124 * $(DDOC_COMMENT example) 125 * GtkDialog as GtkBuildable 126 * The GtkDialog implementation of the GtkBuildable interface exposes the 127 * vbox and action_area as internal children with the names "vbox" and 128 * "action_area". 129 * GtkDialog supports a custom <action-widgets> element, which 130 * can contain multiple <action-widget> elements. The "response" 131 * attribute specifies a numeric response, and the content of the element 132 * is the id of widget (which should be a child of the dialogs action_area). 133 * $(DDOC_COMMENT example) 134 */ 135 public class Dialog : Window 136 { 137 138 /** the main Gtk struct */ 139 protected GtkDialog* gtkDialog; 140 141 142 public GtkDialog* getDialogStruct() 143 { 144 return gtkDialog; 145 } 146 147 148 /** the main Gtk struct as a void* */ 149 protected override void* getStruct() 150 { 151 return cast(void*)gtkDialog; 152 } 153 154 /** 155 * Sets our main struct and passes it to the parent class 156 */ 157 public this (GtkDialog* gtkDialog) 158 { 159 super(cast(GtkWindow*)gtkDialog); 160 this.gtkDialog = gtkDialog; 161 } 162 163 protected override void setStruct(GObject* obj) 164 { 165 super.setStruct(obj); 166 gtkDialog = cast(GtkDialog*)obj; 167 } 168 169 /** 170 * Both title and parent can be null. 171 */ 172 this(string title, Window parent, GtkDialogFlags flags, string[] buttonsText, ResponseType[] responses) 173 { 174 auto p = gtk_dialog_new_with_buttons(Str.toStringz(title), (parent is null) ? null : parent.getWindowStruct(), flags, Str.toStringz(buttonsText[0]), responses[0], null); 175 if(p is null) 176 { 177 throw new ConstructionException("null returned by gtk_dialog_new_with_buttons"); 178 } 179 180 this(cast(GtkDialog*)p); 181 182 addButtons(buttonsText[1 .. $], responses[1 .. $]); 183 } 184 185 /** ditto */ 186 this(string title, Window parent, GtkDialogFlags flags, StockID[] stockIDs, ResponseType[] responses) 187 { 188 auto p = gtk_dialog_new_with_buttons(Str.toStringz(title), (parent is null) ? null : parent.getWindowStruct(), flags, Str.toStringz(StockDesc[stockIDs[0]]), responses[0], null); 189 if(p is null) 190 { 191 throw new ConstructionException("null returned by gtk_dialog_new_with_buttons"); 192 } 193 194 this(cast(GtkDialog*)p); 195 196 addButtons(stockIDs[1 .. $], responses[1 .. $]); 197 } 198 199 /** */ 200 public Widget addButton(StockID stockID, int responseId) 201 { 202 return addButton(StockDesc[stockID], responseId); 203 } 204 205 /** */ 206 public void addButtons(string[] buttonsText, ResponseType[] responses) 207 { 208 for ( int i=0 ; i<buttonsText.length && i<responses.length ; i++) 209 { 210 addButton(buttonsText[i], responses[i]); 211 } 212 } 213 214 /** */ 215 public void addButtons(StockID[] stockIDs, ResponseType[] responses) 216 { 217 for ( int i=0 ; i<stockIDs.length && i<responses.length ; i++) 218 { 219 addButton(stockIDs[i], responses[i]); 220 } 221 } 222 223 //Return the corect class instead of Widget 224 /** 225 * Returns the action area of dialog. 226 * Since 2.14 227 * Returns: the action area. 228 */ 229 public HButtonBox getActionArea() 230 { 231 // GtkWidget* gtk_dialog_get_action_area (GtkDialog *dialog); 232 auto p = gtk_dialog_get_action_area(gtkDialog); 233 if(p is null) 234 { 235 return null; 236 } 237 return new HButtonBox(cast(GtkHButtonBox*) p); 238 } 239 240 //Return the corect class instead of Widget 241 /** 242 * Returns the content area of dialog. 243 * Since 2.14 244 * Returns: the content area GtkVBox. 245 */ 246 public VBox getContentArea() 247 { 248 // GtkWidget* gtk_dialog_get_content_area (GtkDialog *dialog); 249 auto p = gtk_dialog_get_content_area(gtkDialog); 250 if(p is null) 251 { 252 return null; 253 } 254 return new VBox(cast(GtkVBox*) p); 255 } 256 257 /** 258 */ 259 int[string] connectedSignals; 260 261 void delegate(Dialog)[] onCloseListeners; 262 /** 263 * The ::close signal is a 264 * keybinding signal 265 * which gets emitted when the user uses a keybinding to close 266 * the dialog. 267 * The default binding for this signal is the Escape key. 268 */ 269 void addOnClose(void delegate(Dialog) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 270 { 271 if ( !("close" in connectedSignals) ) 272 { 273 Signals.connectData( 274 getStruct(), 275 "close", 276 cast(GCallback)&callBackClose, 277 cast(void*)this, 278 null, 279 connectFlags); 280 connectedSignals["close"] = 1; 281 } 282 onCloseListeners ~= dlg; 283 } 284 extern(C) static void callBackClose(GtkDialog* arg0Struct, Dialog _dialog) 285 { 286 foreach ( void delegate(Dialog) dlg ; _dialog.onCloseListeners ) 287 { 288 dlg(_dialog); 289 } 290 } 291 292 void delegate(gint, Dialog)[] onResponseListeners; 293 /** 294 * Emitted when an action widget is clicked, the dialog receives a 295 * delete event, or the application programmer calls gtk_dialog_response(). 296 * On a delete event, the response ID is GTK_RESPONSE_DELETE_EVENT. 297 * Otherwise, it depends on which action widget was clicked. 298 * See Also 299 * GtkVBox 300 * Pack widgets vertically. 301 * GtkWindow 302 * Alter the properties of your dialog box. 303 * GtkButton 304 * Add them to the action_area to get a 305 * response from the user. 306 */ 307 void addOnResponse(void delegate(gint, Dialog) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 308 { 309 if ( !("response" in connectedSignals) ) 310 { 311 Signals.connectData( 312 getStruct(), 313 "response", 314 cast(GCallback)&callBackResponse, 315 cast(void*)this, 316 null, 317 connectFlags); 318 connectedSignals["response"] = 1; 319 } 320 onResponseListeners ~= dlg; 321 } 322 extern(C) static void callBackResponse(GtkDialog* dialogStruct, gint responseId, Dialog _dialog) 323 { 324 foreach ( void delegate(gint, Dialog) dlg ; _dialog.onResponseListeners ) 325 { 326 dlg(responseId, _dialog); 327 } 328 } 329 330 331 /** 332 * Creates a new dialog box. Widgets should not be packed into this GtkWindow 333 * directly, but into the vbox and action_area, as described above. 334 * Throws: ConstructionException GTK+ fails to create the object. 335 */ 336 public this () 337 { 338 // GtkWidget * gtk_dialog_new (void); 339 auto p = gtk_dialog_new(); 340 if(p is null) 341 { 342 throw new ConstructionException("null returned by gtk_dialog_new()"); 343 } 344 this(cast(GtkDialog*) p); 345 } 346 347 /** 348 * Blocks in a recursive main loop until the dialog either emits the 349 * "response" signal, or is destroyed. If the dialog is 350 * destroyed during the call to gtk_dialog_run(), gtk_dialog_run() returns 351 * GTK_RESPONSE_NONE. Otherwise, it returns the response ID from the 352 * ::response signal emission. 353 * Before entering the recursive main loop, gtk_dialog_run() calls 354 * gtk_widget_show() on the dialog for you. Note that you still 355 * need to show any children of the dialog yourself. 356 * During gtk_dialog_run(), the default behavior of "delete-event" 357 * is disabled; if the dialog receives ::delete_event, it will not be 358 * destroyed as windows usually are, and gtk_dialog_run() will return 359 * GTK_RESPONSE_DELETE_EVENT. Also, during gtk_dialog_run() the dialog 360 * will be modal. You can force gtk_dialog_run() to return at any time by 361 * calling gtk_dialog_response() to emit the ::response signal. Destroying 362 * the dialog during gtk_dialog_run() is a very bad idea, because your 363 * post-run code won't know whether the dialog was destroyed or not. 364 * After gtk_dialog_run() returns, you are responsible for hiding or 365 * destroying the dialog if you wish to do so. 366 * Returns: response ID 367 */ 368 public int run() 369 { 370 // gint gtk_dialog_run (GtkDialog *dialog); 371 return gtk_dialog_run(gtkDialog); 372 } 373 374 /** 375 * Emits the "response" signal with the given response ID. 376 * Used to indicate that the user has responded to the dialog in some way; 377 * typically either you or gtk_dialog_run() will be monitoring the 378 * ::response signal and take appropriate action. 379 * Params: 380 * responseId = response ID 381 */ 382 public void response(int responseId) 383 { 384 // void gtk_dialog_response (GtkDialog *dialog, gint response_id); 385 gtk_dialog_response(gtkDialog, responseId); 386 } 387 388 /** 389 * Adds a button with the given text (or a stock button, if button_text is a 390 * stock ID) and sets things up so that clicking the button will emit the 391 * "response" signal with the given response_id. The button is 392 * appended to the end of the dialog's action area. The button widget is 393 * returned, but usually you don't need it. 394 * Params: 395 * buttonText = text of button, or stock ID 396 * responseId = response ID for the button 397 * Returns: the button widget that was added. [transfer none] 398 */ 399 public Widget addButton(string buttonText, int responseId) 400 { 401 // GtkWidget * gtk_dialog_add_button (GtkDialog *dialog, const gchar *button_text, gint response_id); 402 auto p = gtk_dialog_add_button(gtkDialog, Str.toStringz(buttonText), responseId); 403 404 if(p is null) 405 { 406 return null; 407 } 408 409 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 410 } 411 412 /** 413 * Adds an activatable widget to the action area of a GtkDialog, 414 * connecting a signal handler that will emit the "response" 415 * signal on the dialog when the widget is activated. The widget is 416 * appended to the end of the dialog's action area. If you want to add a 417 * non-activatable widget, simply pack it into the action_area field 418 * of the GtkDialog struct. 419 * Params: 420 * child = an activatable widget 421 * responseId = response ID for child 422 */ 423 public void addActionWidget(Widget child, int responseId) 424 { 425 // void gtk_dialog_add_action_widget (GtkDialog *dialog, GtkWidget *child, gint response_id); 426 gtk_dialog_add_action_widget(gtkDialog, (child is null) ? null : child.getWidgetStruct(), responseId); 427 } 428 429 /** 430 * Warning 431 * gtk_dialog_get_has_separator has been deprecated since version 2.22 and should not be used in newly-written code. This function will be removed in GTK+ 3 432 * Accessor for whether the dialog has a separator. 433 * Returns: TRUE if the dialog has a separator 434 */ 435 public int getHasSeparator() 436 { 437 // gboolean gtk_dialog_get_has_separator (GtkDialog *dialog); 438 return gtk_dialog_get_has_separator(gtkDialog); 439 } 440 441 /** 442 * Sets the last widget in the dialog's action area with the given response_id 443 * as the default widget for the dialog. Pressing "Enter" normally activates 444 * the default widget. 445 * Params: 446 * responseId = a response ID 447 */ 448 public void setDefaultResponse(int responseId) 449 { 450 // void gtk_dialog_set_default_response (GtkDialog *dialog, gint response_id); 451 gtk_dialog_set_default_response(gtkDialog, responseId); 452 } 453 454 /** 455 * Warning 456 * gtk_dialog_set_has_separator has been deprecated since version 2.22 and should not be used in newly-written code. This function will be removed in GTK+ 3 457 * Sets whether the dialog has a separator above the buttons. 458 * Params: 459 * setting = TRUE to have a separator 460 */ 461 public void setHasSeparator(int setting) 462 { 463 // void gtk_dialog_set_has_separator (GtkDialog *dialog, gboolean setting); 464 gtk_dialog_set_has_separator(gtkDialog, setting); 465 } 466 467 /** 468 * Calls gtk_widget_set_sensitive (widget, setting) 469 * for each widget in the dialog's action area with the given response_id. 470 * A convenient way to sensitize/desensitize dialog buttons. 471 * Params: 472 * responseId = a response ID 473 * setting = TRUE for sensitive 474 */ 475 public void setResponseSensitive(int responseId, int setting) 476 { 477 // void gtk_dialog_set_response_sensitive (GtkDialog *dialog, gint response_id, gboolean setting); 478 gtk_dialog_set_response_sensitive(gtkDialog, responseId, setting); 479 } 480 481 /** 482 * Gets the response id of a widget in the action area 483 * of a dialog. 484 * Since 2.8 485 * Params: 486 * widget = a widget in the action area of dialog 487 * Returns: the response id of widget, or GTK_RESPONSE_NONE if widget doesn't have a response id set. 488 */ 489 public int getResponseForWidget(Widget widget) 490 { 491 // gint gtk_dialog_get_response_for_widget (GtkDialog *dialog, GtkWidget *widget); 492 return gtk_dialog_get_response_for_widget(gtkDialog, (widget is null) ? null : widget.getWidgetStruct()); 493 } 494 495 /** 496 * Gets the widget button that uses the given response ID in the action area 497 * of a dialog. 498 * Since 2.20 499 * Params: 500 * responseId = the response ID used by the dialog widget 501 * Returns: the widget button that uses the given response_id, or NULL. [transfer none] 502 */ 503 public Widget getWidgetForResponse(int responseId) 504 { 505 // GtkWidget * gtk_dialog_get_widget_for_response (GtkDialog *dialog, gint response_id); 506 auto p = gtk_dialog_get_widget_for_response(gtkDialog, responseId); 507 508 if(p is null) 509 { 510 return null; 511 } 512 513 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 514 } 515 516 /** 517 * Returns TRUE if dialogs are expected to use an alternative 518 * button order on the screen screen. See 519 * gtk_dialog_set_alternative_button_order() for more details 520 * about alternative button order. 521 * If you need to use this function, you should probably connect 522 * to the ::notify:gtk-alternative-button-order signal on the 523 * GtkSettings object associated to screen, in order to be 524 * notified if the button order setting changes. 525 * Since 2.6 526 * Params: 527 * screen = a GdkScreen, or NULL to use the default screen. [allow-none] 528 * Returns: Whether the alternative button order should be used 529 */ 530 public static int alternativeDialogButtonOrder(Screen screen) 531 { 532 // gboolean gtk_alternative_dialog_button_order (GdkScreen *screen); 533 return gtk_alternative_dialog_button_order((screen is null) ? null : screen.getScreenStruct()); 534 } 535 536 /** 537 * Sets an alternative button order. If the 538 * "gtk-alternative-button-order" setting is set to TRUE, 539 * the dialog buttons are reordered according to the order of the 540 * response ids in new_order. 541 * See gtk_dialog_set_alternative_button_order() for more information. 542 * This function is for use by language bindings. 543 * Since 2.6 544 * Params: 545 * newOrder = an array of response ids of 546 * dialog's buttons. [array length=n_params] 547 */ 548 public void setAlternativeButtonOrderFromArray(int[] newOrder) 549 { 550 // void gtk_dialog_set_alternative_button_order_from_array (GtkDialog *dialog, gint n_params, gint *new_order); 551 gtk_dialog_set_alternative_button_order_from_array(gtkDialog, cast(int) newOrder.length, newOrder.ptr); 552 } 553 }