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