1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --   Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet   -- 
  5. --                Copyright (C) 2000-2010 AdaCore                    -- 
  6. --                                                                   -- 
  7. -- This library is free software; you can redistribute it and/or     -- 
  8. -- modify it under the terms of the GNU General Public               -- 
  9. -- License as published by the Free Software Foundation; either      -- 
  10. -- version 2 of the License, or (at your option) any later version.  -- 
  11. --                                                                   -- 
  12. -- This library is distributed in the hope that it will be useful,   -- 
  13. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  14. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  15. -- General Public License for more details.                          -- 
  16. --                                                                   -- 
  17. -- You should have received a copy of the GNU General Public         -- 
  18. -- License along with this library; if not, write to the             -- 
  19. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  20. -- Boston, MA 02111-1307, USA.                                       -- 
  21. --                                                                   -- 
  22. -- -- -- -- -- -- -- -- -- -- -- --
  23. ----------------------------------------------------------------------- 
  24.  
  25. --  <description> 
  26. --  Dialog boxes are a convenient way to prompt the user for a small amount of 
  27. --  input, eg. to display a message, ask a question, or anything else that does 
  28. --  not require extensive effort on the user's part. 
  29. -- 
  30. --  Gtkada treats a dialog as a window split horizontally. The top section is a 
  31. --  Gtk_Vbox, and is where widgets such as a Gtk_Label or a Gtk_Entry should be 
  32. --  packed. The second area is known as the action_area. This is generally used 
  33. --  for packing buttons into the dialog which may perform functions such as 
  34. --  cancel, ok, or apply. The two areas are separated by a Gtk_Hseparator. 
  35. -- 
  36. --  If 'dialog' is a newly created dialog, the two primary areas of the window 
  37. --  can be accessed using Get_Vbox and Get_Action_Area as can be seen from the 
  38. --  example, below. 
  39. -- 
  40. --  A 'modal' dialog (that is, one which freezes the rest of the application 
  41. --  from user input), can be created by calling Set_Modal on the dialog. 
  42. -- 
  43. --  See Gtkada.Dialogs for a higher level dialog interface. 
  44. --  </description> 
  45. --  <c_version>2.16.6</c_version> 
  46. --  <group>Windows</group> 
  47. --  <testgtk>create_dialog.adb</testgtk> 
  48. --  <screenshot>gtk-dialog</screenshot> 
  49.  
  50. with Glib.Properties; 
  51. with Gtk.Box; 
  52. with Gtk.Widget; 
  53. with Gtk.Window; 
  54.  
  55. package Gtk.Dialog is 
  56.  
  57.    type Gtk_Dialog_Record is new Gtk.Window.Gtk_Window_Record with private; 
  58.    type Gtk_Dialog is access all Gtk_Dialog_Record'Class; 
  59.  
  60.    ----------------------- 
  61.    -- Enumeration types -- 
  62.    ----------------------- 
  63.  
  64.    type Gtk_Dialog_Flags is mod 8; 
  65.    pragma Convention (C, Gtk_Dialog_Flags); 
  66.    Modal               : constant Gtk_Dialog_Flags := 2 ** 0; 
  67.    Destroy_With_Parent : constant Gtk_Dialog_Flags := 2 ** 1; 
  68.    No_Separator        : constant Gtk_Dialog_Flags := 2 ** 2; 
  69.    --  Various flags that can be set for the dialog, with the following 
  70.    --  implications: 
  71.    --     - Modal : the dialog is modal, see Gtk.Window.Set_Modal 
  72.    --     - Destroy_With_Parent: The dialog is destroyed if its parent is 
  73.    --       destroyed. See Gtk.Window.Set_Destroy_With_Parent 
  74.    --     - No_Separator: No separator bar above the buttons. 
  75.  
  76.    type Gtk_Response_Type is new Gint; 
  77.    --  Type used for Response_Id's. 
  78.    --  Positive values are totally user-interpreted. 
  79.    --  GtkAda will sometimes return Gtk_Response_None if no Response_Id is 
  80.    --  available. 
  81.    -- 
  82.    --  Typical usage is: 
  83.    --    if Gtk.Dialog.Run (Dialog) = Gtk_Response_Accept then 
  84.    --       blah; 
  85.    --    end if; 
  86.  
  87.    Gtk_Response_None : constant Gtk_Response_Type := -1; 
  88.    --  GtkAda returns this if a response widget has no Response_Id, 
  89.    --  or if the dialog gets programmatically hidden or destroyed. 
  90.  
  91.    Gtk_Response_Reject : constant Gtk_Response_Type := -2; 
  92.    Gtk_Response_Accept : constant Gtk_Response_Type := -3; 
  93.    --  GtkAda won't return these unless you pass them in 
  94.    --  as the response for an action widget. They are 
  95.    --  for your convenience. 
  96.  
  97.    Gtk_Response_Delete_Event : constant Gtk_Response_Type := -4; 
  98.    --  If the dialog is deleted through the button in the titlebar 
  99.  
  100.    Gtk_Response_OK     : constant Gtk_Response_Type := -5; 
  101.    Gtk_Response_Cancel : constant Gtk_Response_Type := -6; 
  102.    Gtk_Response_Close  : constant Gtk_Response_Type := -7; 
  103.    Gtk_Response_Yes    : constant Gtk_Response_Type := -8; 
  104.    Gtk_Response_No     : constant Gtk_Response_Type := -9; 
  105.    Gtk_Response_Apply  : constant Gtk_Response_Type := -10; 
  106.    Gtk_Response_Help   : constant Gtk_Response_Type := -11; 
  107.    --  These are returned from dialogs, and you can also use them 
  108.    --  yourself if you like. 
  109.  
  110.    type Response_Type_Array is array (Natural range <>) of Gtk_Response_Type; 
  111.  
  112.    ----------------- 
  113.    -- Subprograms -- 
  114.    ----------------- 
  115.  
  116.    procedure Gtk_New (Dialog : out Gtk_Dialog); 
  117.    --  Create a new dialog. 
  118.    --  Widgets should not be packed into this widget directly, but into the 
  119.    --  vbox and action_area, as described above. 
  120.  
  121.    procedure Gtk_New 
  122.      (Dialog : out Gtk_Dialog; 
  123.       Title  : UTF8_String; 
  124.       Parent : Gtk.Window.Gtk_Window; 
  125.       Flags  : Gtk_Dialog_Flags); 
  126.    --  Create a new dialog with a specific title, and specific attributes. 
  127.    --  Parent is the transient parent for the dialog (ie the one that is 
  128.    --  used for reference for the flag Destroy_With_Parent, or to compute the 
  129.    --  initial position of the dialog). 
  130.  
  131.    procedure Initialize (Dialog : access Gtk_Dialog_Record'Class); 
  132.    --  Internal initialization function. 
  133.    --  See the section "Creating your own widgets" in the documentation. 
  134.  
  135.    procedure Initialize 
  136.      (Dialog : access Gtk_Dialog_Record'Class; 
  137.       Title  : UTF8_String; 
  138.       Parent : Gtk.Window.Gtk_Window; 
  139.       Flags  : Gtk_Dialog_Flags); 
  140.    --  Internal initialization function. 
  141.    --  See the section "Creating your own widgets" in the documentation. 
  142.  
  143.    function Get_Type return Gtk.Gtk_Type; 
  144.    --  Return the internal value associated with a Gtk_Dialog. 
  145.  
  146.    function Get_Action_Area 
  147.      (Dialog : access Gtk_Dialog_Record) return Gtk.Box.Gtk_Box; 
  148.    --  Return the action area box associated with a Dialog. 
  149.  
  150.    function Get_Content_Area 
  151.      (Dialog : access Gtk_Dialog_Record) return Gtk.Box.Gtk_Box; 
  152.    --  Return the content area of the Dialog. 
  153.  
  154.    function Get_Vbox 
  155.      (Dialog : access Gtk_Dialog_Record) return Gtk.Box.Gtk_Box; 
  156.    --  Return the vertical box associated with a Dialog. 
  157.  
  158.    procedure Add_Action_Widget 
  159.      (Dialog      : access Gtk_Dialog_Record; 
  160.       Child       : access Gtk.Widget.Gtk_Widget_Record'Class; 
  161.       Response_Id : Gtk_Response_Type); 
  162.    --  Add an activatable widget to the action area of Dialog. 
  163.    --  When the widget is activated (ie emits the "activate" signal), Dialog 
  164.    --  will emit the "response" signal with Response_Id. 
  165.  
  166.    function Add_Button 
  167.      (Dialog      : access Gtk_Dialog_Record; 
  168.       Text        : UTF8_String; 
  169.       Response_Id : Gtk_Response_Type) return Gtk.Widget.Gtk_Widget; 
  170.    --  Add a button with the given text to the dialog. Note that you can also 
  171.    --  pass one of the constants defined in Gtk.Stock for the predefined 
  172.    --  buttons. 
  173.    --  When the button is clicked, Dialog will emit the "response" signal. 
  174.    --  The button widget is returned. 
  175.  
  176.    function Get_Response_For_Widget 
  177.      (Dialog : access Gtk_Dialog_Record; 
  178.       Widget : access Gtk.Widget.Gtk_Widget_Record'Class) return Gint; 
  179.    --  Gets the response id of a widget in the action area of a dialog, or 
  180.    --  Gtk_Response_None if Widget doesn't have a response Id set 
  181.  
  182.    procedure Set_Alternative_Button_Order_From_Array 
  183.      (Dialog    : access Gtk_Dialog_Record; 
  184.       New_Order : Response_Type_Array); 
  185.    --  Sets an alternative button order. If the gtk-alternative-button-order 
  186.    --  setting is set to %TRUE, the dialog buttons are reordered according to 
  187.    --  the order of the response ids passed to this function. 
  188.    -- 
  189.    --  By default, GTK+ dialogs use the button order advocated by the Gnome 
  190.    --  Human Interface Guidelines with the affirmative button at the far right, 
  191.    --  and the cancel button left of it. But the builtin GTK+ dialogs and 
  192.    --  message dialogs' do provide an alternative button order, which is more 
  193.    --  suitable on some platforms, e.g. Windows. 
  194.    -- 
  195.    --  Use this function after adding all the buttons to your dialog. 
  196.  
  197.    function Gtk_Alternative_Dialog_Button_Order 
  198.      (Screen : Gdk.Gdk_Screen := null)  return Boolean; 
  199.    --  Returns True if dialogs are expected to use an alternative button order 
  200.    --  on the given screen (or current screen if null) . See 
  201.    --  Set_Alternative_Button_Order_From_Array for more details about 
  202.    --  alternative button order. 
  203.    -- 
  204.    --  If you need to use this function, you should probably connect to the 
  205.    --  ::notify:gtk-alternative-button-order signal on the Gtk_Settings object 
  206.    --  associated to Screen, in order to be notified if the button order 
  207.    --  setting changes. 
  208.    -- 
  209.    --  Returns: Whether the alternative button order should be used 
  210.  
  211.    procedure Set_Response_Sensitive 
  212.      (Dialog      : access Gtk_Dialog_Record; 
  213.       Response_Id : Gtk_Response_Type; 
  214.       Setting     : Boolean); 
  215.    --  Call Gtk.Widget.Set_Sensitive for all the buttons in the dialog 
  216.    --  associated with Response_Id. 
  217.  
  218.    procedure Set_Default_Response 
  219.      (Dialog : access Gtk_Dialog_Record; Response_Id : Gtk_Response_Type); 
  220.    --  Set the last widget in the dialog's action area with the given 
  221.    --  Response_Id as the default widget for Dialog. 
  222.    --  Pressing Enter will activate this default widget. 
  223.  
  224.    procedure Set_Has_Separator 
  225.      (Dialog : access Gtk_Dialog_Record; Setting : Boolean); 
  226.    function Get_Has_Separator (Dialog : access Gtk_Dialog_Record) 
  227.       return Boolean; 
  228.    --  Set whether the dialog has a separator above the buttons. 
  229.  
  230.    function Run (Dialog : access Gtk_Dialog_Record) return Gtk_Response_Type; 
  231.    --  Block in a recursive main loop until Dialog emits the "response" 
  232.    --  signal, or is destroyed. If the dialog is destroyed, Gtk_Response_None 
  233.    --  is returned. Otherwise, the response_id from the "response" signal is 
  234.    --  returned. 
  235.    --  Run will call Show on the dialog automatically. However, it is your 
  236.    --  responsability to call Show for any child you have inserted in the 
  237.    --  dialog. 
  238.    --  The dialog is automatically set to modal when this function is 
  239.    --  called. You can exit at any time from this function by emitting the 
  240.    --  "response" signal directly. 
  241.    --  When Run returns, you are responsible for hiding or destroying the 
  242.    --  dialog if necessary. 
  243.  
  244.    ---------------- 
  245.    -- Properties -- 
  246.    ---------------- 
  247.    --  The following properties are defined for this widget. See 
  248.    --  Glib.Properties for more information on properties. 
  249.  
  250.    --  <properties> 
  251.    --  - Name:  Has_Separator_Property 
  252.    --    Type:  Boolean 
  253.    --    Flags: read-write 
  254.    --    Descr: The dialog has a separator bar above its buttons 
  255.    --  </properties> 
  256.  
  257.    Has_Separator_Property : constant Glib.Properties.Property_Boolean; 
  258.  
  259.    ---------------------- 
  260.    -- Style Properties -- 
  261.    ---------------------- 
  262.    --  The following properties can be changed through the gtk theme and 
  263.    --  configuration files, and retrieved through Gtk.Widget.Style_Get_Property 
  264.  
  265.    --  <style_properties> 
  266.    --  Name:  Action_Area_Border_Property 
  267.    --  Type:  Int 
  268.    --  Descr: Width of border around the button area at the bottom of the 
  269.    --         dialog 
  270.    -- 
  271.    --  Name:  Button_Spacing_Property 
  272.    --  Type:  Int 
  273.    --  Descr: Spacing between buttons 
  274.    -- 
  275.    --  Name:  Content_Area_Border_Property 
  276.    --  Type:  Int 
  277.    --  Descr: Width of border around the main dialog area 
  278.    -- 
  279.    --  Name:  Content_Area_Spacing_Property 
  280.    --  Type:  Int 
  281.    --  Descr: Spacing between elements of the main dialog area 
  282.    --  </style_properties> 
  283.  
  284.    Action_Area_Border_Property  : constant Glib.Properties.Property_Int; 
  285.    Button_Spacing_Property      : constant Glib.Properties.Property_Int; 
  286.    Content_Area_Border_Property : constant Glib.Properties.Property_Int; 
  287.    Content_Area_Spacing_Property : constant Glib.Properties.Property_Int; 
  288.  
  289.    ------------- 
  290.    -- Signals -- 
  291.    ------------- 
  292.  
  293.    --  <signals> 
  294.    --  The following new signals are defined for this widget: 
  295.    -- 
  296.    --  - "response" 
  297.    --    procedure Handler 
  298.    --      (Dialog      : access Gtk_Dialog_Record'Class; 
  299.    --       Response_Id : Gint); 
  300.    --    Emitted when an action widget is clicked, the dialog receives a delete 
  301.    --    event, or the application programmer calls Response. On delete event, 
  302.    --    the response ID is GTK_RESPONSE_NONE. Otherwise, it depends on which 
  303.    --    action widget was clicked. 
  304.    -- 
  305.    --  - "close" 
  306.    --    procedure Handler (Dialog : access Gtk_Dialog_Record'Class); 
  307.    --    Emit this signal to force a closing of the dialog. 
  308.    --  </signals> 
  309.  
  310.    Signal_Close    : constant Glib.Signal_Name := "close"; 
  311.    Signal_Response : constant Glib.Signal_Name := "response"; 
  312.  
  313.    procedure Response 
  314.      (Dialog      : access Gtk_Dialog_Record; 
  315.       Response_Id : Gtk_Response_Type); 
  316.    --  Emit the "response" signal 
  317.  
  318. private 
  319.    type Gtk_Dialog_Record is new Gtk.Window.Gtk_Window_Record with null record; 
  320.  
  321.    Has_Separator_Property : constant Glib.Properties.Property_Boolean := 
  322.      Glib.Properties.Build ("has_separator"); 
  323.  
  324.    Action_Area_Border_Property : constant Glib.Properties.Property_Int := 
  325.      Glib.Properties.Build ("action-area-border"); 
  326.    Button_Spacing_Property : constant Glib.Properties.Property_Int := 
  327.      Glib.Properties.Build ("button-spacing"); 
  328.    Content_Area_Border_Property : constant Glib.Properties.Property_Int := 
  329.      Glib.Properties.Build ("content-area-border"); 
  330.    Content_Area_Spacing_Property : constant Glib.Properties.Property_Int := 
  331.      Glib.Properties.Build ("content-area-spacing"); 
  332.  
  333.    pragma Import (C, Get_Type, "gtk_dialog_get_type"); 
  334. end Gtk.Dialog; 
  335.  
  336. --  No binding: gtk_dialog_set_alternative_button_order 
  337. --  No binding: gtk_dialog_new_with_buttons 
  338. --  No binding: gtk_dialog_add_buttons 
  339. --  No binding: gtk_dialog_get_action_area