package Implements_Gtk_Buildable is new Glib.Types.Implements (Gtk.Buildable.Gtk_Buildable, Gtk_Dialog_Record, Gtk_Dialog);
type Gtk_Dialog_Record is new Gtk_Window_Record with null record;
type Gtk_Dialog is access all Gtk_Dialog_Record'Class;
type Gtk_Response_Type is new Gint;
type Response_Type_Array is array (Natural range <>) of Gtk_Response_Type;
type Cb_Gtk_Dialog_Void is not null access procedure (Self : access Gtk_Dialog_Record'Class);
type Cb_GObject_Void is not null access procedure (Self : access Glib.Object.GObject_Record'Class);
type Cb_Gtk_Dialog_Gtk_Response_Type_Void is not null access procedure (Self : access Gtk_Dialog_Record'Class; Response_Id : Gtk_Response_Type);
type Cb_GObject_Gtk_Response_Type_Void is not null access procedure (Self : access Glib.Object.GObject_Record'Class; Response_Id : Gtk_Response_Type);
Modal : constant Gtk_Dialog_Flags := 2 ** 0;
Destroy_With_Parent : constant Gtk_Dialog_Flags := 2 ** 1;
No_Separator : constant Gtk_Dialog_Flags := 2 ** 2;
Gtk_Response_None : constant Gtk_Response_Type := -1;
Gtk_Response_Reject : constant Gtk_Response_Type := -2;
Gtk_Response_Accept : constant Gtk_Response_Type := -3;
Gtk_Response_Delete_Event : constant Gtk_Response_Type := -4;
Gtk_Response_OK : constant Gtk_Response_Type := -5;
Gtk_Response_Cancel : constant Gtk_Response_Type := -6;
Gtk_Response_Close : constant Gtk_Response_Type := -7;
Gtk_Response_Yes : constant Gtk_Response_Type := -8;
Gtk_Response_No : constant Gtk_Response_Type := -9;
Gtk_Response_Apply : constant Gtk_Response_Type := -10;
Gtk_Response_Help : constant Gtk_Response_Type := -11;
Signal_Close : constant Glib.Signal_Name := "close";
Signal_Response : constant Glib.Signal_Name := "response";
procedure Gtk_New
( | Dialog | : out Gtk_Dialog); |
procedure Initialize
( | Dialog | : not null access Gtk_Dialog_Record'Class); |
function Gtk_Dialog_New return Gtk_Dialog;
function Gtk_Dialog_New
( | Title | : UTF8_String; |
Parent | : Gtk.Window.Gtk_Window := null; | |
Flags | : Gtk_Dialog_Flags) return Gtk_Dialog; |
procedure Gtk_New
( | Dialog | : out Gtk_Dialog; |
Title | : UTF8_String; | |
Parent | : Gtk.Window.Gtk_Window := null; | |
Flags | : Gtk_Dialog_Flags); |
procedure Initialize
( | Dialog | : not null access Gtk_Dialog_Record'Class; |
Title | : UTF8_String; | |
Parent | : Gtk.Window.Gtk_Window := null; | |
Flags | : Gtk_Dialog_Flags); |
function Get_Type return Glib.GType;
procedure Add_Action_Widget
( | Dialog | : not null access Gtk_Dialog_Record; |
Child | : not null access Gtk.Widget.Gtk_Widget_Record'Class; | |
Response_Id | : Gtk_Response_Type); |
function Add_Button
( | Dialog | : not null access Gtk_Dialog_Record; |
Text | : UTF8_String; | |
Response_Id | : Gtk_Response_Type) return Gtk.Widget.Gtk_Widget; |
function Get_Action_Area
( | Dialog | : not null access Gtk_Dialog_Record) return Gtk.Box.Gtk_Box; |
function Get_Content_Area
( | Dialog | : not null access Gtk_Dialog_Record) return Gtk.Box.Gtk_Box; |
function Get_Response_For_Widget
( | Dialog | : not null access Gtk_Dialog_Record; |
Widget | : not null access Gtk.Widget.Gtk_Widget_Record'Class) return Gtk_Response_Type; |
function Get_Widget_For_Response
( | Dialog | : not null access Gtk_Dialog_Record; |
Response_Id | : Gtk_Response_Type) return Gtk.Widget.Gtk_Widget; |
procedure Response
( | Dialog | : not null access Gtk_Dialog_Record; |
Response_Id | : Gtk_Response_Type); |
function Run
( | Dialog | : not null access Gtk_Dialog_Record) return Gtk_Response_Type; |
procedure Set_Default_Response
( | Dialog | : not null access Gtk_Dialog_Record; |
Response_Id | : Gtk_Response_Type); |
procedure Set_Response_Sensitive
( | Dialog | : not null access Gtk_Dialog_Record; |
Response_Id | : Gtk_Response_Type; | |
Setting | : Boolean); |
procedure Set_Alternative_Button_Order_From_Array
( | Dialog | : access Gtk_Dialog_Record; |
New_Order | : Response_Type_Array); |
function Gtk_Alternative_Dialog_Button_Order
( | Screen | : Gdk.Screen.Gdk_Screen := null) return Boolean; |
procedure On_Close
( | Self | : not null access Gtk_Dialog_Record; |
Call | : Cb_Gtk_Dialog_Void; | |
After | : Boolean := False); |
procedure On_Close
( | Self | : not null access Gtk_Dialog_Record; |
Call | : Cb_GObject_Void; | |
Slot | : not null access Glib.Object.GObject_Record'Class; | |
After | : Boolean := False); |
procedure On_Response
( | Self | : not null access Gtk_Dialog_Record; |
Call | : Cb_Gtk_Dialog_Gtk_Response_Type_Void; | |
After | : Boolean := False); |
procedure On_Response
( | Self | : not null access Gtk_Dialog_Record; |
Call | : Cb_GObject_Gtk_Response_Type_Void; | |
Slot | : not null access Glib.Object.GObject_Record'Class; | |
After | : Boolean := False); |
function "+"
( | Widget | : access Gtk_Dialog_Record'Class) return Gtk.Buildable.Gtk_Buildable renames Implements_Gtk_Buildable.To_Interface; |
function "-"
( | Interf | : Gtk.Buildable.Gtk_Buildable) return Gtk_Dialog renames Implements_Gtk_Buildable.To_Object; |
Dialog boxes are a convenient way to prompt the user for a small amount of input, e.g. to display a message, ask a question, or anything else that does not require extensive effort on the user's part.
GTK+ treats a dialog as a window split vertically. The top section is a Gtk.Box.Gtk_Vbox, and is where widgets such as a Gtk.Label.Gtk_Label or a Gtk.GEntry.Gtk_Entry should be packed. The bottom area is known as the <structfield>action_area</structfield>. This is generally used for packing buttons into the dialog which may perform functions such as cancel, ok, or apply.
Gtk.Dialog.Gtk_Dialog boxes are created with a call to Gtk.Dialog.Gtk_New or gtk_dialog_new_with_buttons. gtk_dialog_new_with_buttons is recommended; it allows you to set the dialog title, some convenient flags, and add simple buttons.
If 'dialog' is a newly created dialog, the two primary areas of the window can be accessed through Gtk.Dialog.Get_Content_Area and Gtk.Dialog.Get_Action_Area, as can be seen from the example below.
A 'modal' dialog (that is, one which freezes the rest of the application from user input), can be created by calling Gtk.Window.Set_Modal on the dialog. Use the GTK_WINDOW macro to cast the widget returned from Gtk.Dialog.Gtk_New into a Gtk.Window.Gtk_Window. When using gtk_dialog_new_with_buttons you can also pass the GTK_DIALOG_MODAL flag to make a dialog modal.
If you add buttons to Gtk.Dialog.Gtk_Dialog using gtk_dialog_new_with_buttons, Gtk.Dialog.Add_Button, gtk_dialog_add_buttons, or Gtk.Dialog.Add_Action_Widget, clicking the button will emit a signal called Gtk.Dialog.Gtk_Dialog::response with a response ID that you specified. GTK+ will never assign a meaning to positive response IDs; these are entirely user-defined. But for convenience, you can use the response IDs in the Gtk_Response_Type enumeration (these all have values less than zero). If a dialog receives a delete event, the Gtk.Dialog.Gtk_Dialog::response signal will be emitted with a response ID of GTK_RESPONSE_DELETE_EVENT.
If you want to block waiting for a dialog to return before returning control flow to your code, you can call Gtk.Dialog.Run. This function enters a recursive main loop and waits for the user to respond to the dialog, returning the response ID corresponding to the button the user clicked.
For the simple dialog in the following example, in reality you'd probably use Gtk.Message_Dialog.Gtk_Message_Dialog to save yourself some effort. But you'd need to create the dialog contents manually if you had more than a simple message in the dialog. == Simple GtkDialog usage == /* Function to open a dialog box displaying the message provided. */ void quick_message (gchar *message) { GtkWidget *dialog, *label, *content_area; /* Create the widgets */ dialog = gtk_dialog_new_with_buttons ("Message", main_application_window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_NONE, NULL); content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); label = gtk_label_new (message); /* Ensure that the dialog box is destroyed when the user responds */ g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); /* Add the label, and show everything we've added to the dialog */ gtk_container_add (GTK_CONTAINER (content_area), label); gtk_widget_show_all (dialog); } == GtkDialog as GtkBuildable == The GtkDialog implementation of the Gtk.Buildable.Gtk_Buildable interface exposes the Vbox and Action_Area as internal children with the names "vbox" and "action_area".
GtkDialog supports a custom <action-widgets> element, which can contain multiple <action-widget> elements. The "response" attribute specifies a numeric response, and the content of the element is the id of widget (which should be a child of the dialogs Action_Area). == A <structname>GtkDialog</structname> UI definition fragment. == <object class="GtkDialog" id="dialog1"> <child internal-child="vbox">" <object class="GtkVBox" id="vbox"> <child internal-child="action_area"> <object class="GtkHButtonBox" id="button_box"> <child> <object class="GtkButton" id="button_cancel"/> </child> <child> <object class="GtkButton" id="button_ok"/> </child> </object> </child> </object> </child> <action-widgets> <action-widget response="3">button_ok</action-widget> <action-widget response="-5">button_cancel</action-widget> </action-widgets> </object>