1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  Gtk.Message_Dialog.Gtk_Message_Dialog presents a dialog with an image 
  26. --  representing the type of message (Error, Question, etc.) alongside some 
  27. --  message text. It's simply a convenience widget; you could construct the 
  28. --  equivalent of Gtk.Message_Dialog.Gtk_Message_Dialog from 
  29. --  Gtk.Dialog.Gtk_Dialog without too much effort, but 
  30. --  Gtk.Message_Dialog.Gtk_Message_Dialog saves typing. 
  31. -- 
  32. --  One difference from Gtk.Dialog.Gtk_Dialog is that 
  33. --  Gtk.Message_Dialog.Gtk_Message_Dialog sets the 
  34. --  Gtk.Window.Gtk_Window:skip-taskbar-hint property to True, so that the 
  35. --  dialog is hidden from the taskbar by default. 
  36. -- 
  37. --  The easiest way to do a modal message dialog is to use Gtk.Dialog.Run, 
  38. --  though you can also pass in the GTK_DIALOG_MODAL flag, Gtk.Dialog.Run 
  39. --  automatically makes the dialog modal and waits for the user to respond to 
  40. --  it. Gtk.Dialog.Run returns when any dialog button is clicked. 
  41. -- 
  42. --  == A modal dialog. == 
  43. -- 
  44. --    dialog = gtk_message_dialog_new (main_application_window, 
  45. --       GTK_DIALOG_DESTROY_WITH_PARENT, 
  46. --       GTK_MESSAGE_ERROR, 
  47. --       GTK_BUTTONS_CLOSE, 
  48. --       "Error loading file '%s': %s", 
  49. --       filename, g_strerror (errno)); 
  50. --    gtk_dialog_run (GTK_DIALOG (dialog)); 
  51. --    gtk_widget_destroy (dialog); 
  52. -- 
  53. --  You might do a non-modal Gtk.Message_Dialog.Gtk_Message_Dialog as follows: 
  54. -- 
  55. --  == A non-modal dialog. == 
  56. -- 
  57. --    dialog = gtk_message_dialog_new (main_application_window, 
  58. --       GTK_DIALOG_DESTROY_WITH_PARENT, 
  59. --       GTK_MESSAGE_ERROR, 
  60. --       GTK_BUTTONS_CLOSE, 
  61. --       "Error loading file '%s': %s", 
  62. --       filename, g_strerror (errno)); 
  63. --    /* Destroy the dialog when the user responds to it (e.g. clicks a button) */ 
  64. --    g_signal_connect_swapped (dialog, "response", 
  65. --       G_CALLBACK (gtk_widget_destroy), 
  66. --       dialog); 
  67. -- 
  68. --  == GtkMessageDialog as GtkBuildable == 
  69. -- 
  70. --  The GtkMessageDialog implementation of the GtkBuildable interface exposes 
  71. --  the message area as an internal child with the name "message_area". 
  72. -- 
  73. -- 
  74. --  </description> 
  75. pragma Ada_2005; 
  76.  
  77. pragma Warnings (Off, "*is already use-visible*"); 
  78. with Glib;                    use Glib; 
  79. with Glib.Generic_Properties; use Glib.Generic_Properties; 
  80. with Glib.Properties;         use Glib.Properties; 
  81. with Glib.Types;              use Glib.Types; 
  82. with Gtk.Buildable;           use Gtk.Buildable; 
  83. with Gtk.Dialog;              use Gtk.Dialog; 
  84. with Gtk.Widget;              use Gtk.Widget; 
  85. with Gtk.Window;              use Gtk.Window; 
  86.  
  87. package Gtk.Message_Dialog is 
  88.  
  89.    type Gtk_Message_Dialog_Record is new Gtk_Dialog_Record with null record; 
  90.    type Gtk_Message_Dialog is access all Gtk_Message_Dialog_Record'Class; 
  91.  
  92.    type Gtk_Message_Type is ( 
  93.       Message_Info, 
  94.       Message_Warning, 
  95.       Message_Question, 
  96.       Message_Error, 
  97.       Message_Other); 
  98.    pragma Convention (C, Gtk_Message_Type); 
  99.    --  The type of message being displayed in the dialog. 
  100.  
  101.    type Gtk_Buttons_Type is ( 
  102.       Buttons_None, 
  103.       Buttons_Ok, 
  104.       Buttons_Close, 
  105.       Buttons_Cancel, 
  106.       Buttons_Yes_No, 
  107.       Buttons_Ok_Cancel); 
  108.    pragma Convention (C, Gtk_Buttons_Type); 
  109.    --  Prebuilt sets of buttons for the dialog. If none of these choices are 
  110.    --  appropriate, simply use Gtk.Message_Dialog.Buttons_None then call 
  111.    --  gtk_dialog_add_buttons. 
  112.    -- 
  113.    --  Note: Please note that Gtk.Message_Dialog.Buttons_Ok, 
  114.    --  Gtk.Message_Dialog.Buttons_Yes_No and 
  115.    --  Gtk.Message_Dialog.Buttons_Ok_Cancel are discouraged by the <ulink 
  116.    --  url="http://library.gnome.org/devel/hig-book/stable/">GNOME HIG</ulink>. 
  117.  
  118.    ---------------------------- 
  119.    -- Enumeration Properties -- 
  120.    ---------------------------- 
  121.  
  122.    package Gtk_Message_Type_Properties is 
  123.       new Generic_Internal_Discrete_Property (Gtk_Message_Type); 
  124.    type Property_Gtk_Message_Type is new Gtk_Message_Type_Properties.Property; 
  125.  
  126.    package Gtk_Buttons_Type_Properties is 
  127.       new Generic_Internal_Discrete_Property (Gtk_Buttons_Type); 
  128.    type Property_Gtk_Buttons_Type is new Gtk_Buttons_Type_Properties.Property; 
  129.  
  130.    ------------------ 
  131.    -- Constructors -- 
  132.    ------------------ 
  133.  
  134.    procedure Gtk_New 
  135.       (Dialog   : out Gtk_Message_Dialog; 
  136.        Parent   : access Gtk.Window.Gtk_Window_Record'Class; 
  137.        Flags    : Gtk_Dialog_Flags; 
  138.        The_Type : Gtk_Message_Type; 
  139.        Buttons  : Gtk_Buttons_Type; 
  140.        Message  : UTF8_String := ""; 
  141.        Arg5     : System.Address); 
  142.    procedure Initialize 
  143.       (Dialog   : not null access Gtk_Message_Dialog_Record'Class; 
  144.        Parent   : access Gtk.Window.Gtk_Window_Record'Class; 
  145.        Flags    : Gtk_Dialog_Flags; 
  146.        The_Type : Gtk_Message_Type; 
  147.        Buttons  : Gtk_Buttons_Type; 
  148.        Message  : UTF8_String := ""; 
  149.        Arg5     : System.Address); 
  150.    --  Creates a new message dialog, which is a simple dialog with an icon 
  151.    --  indicating the dialog type (error, warning, etc.) and some text the user 
  152.    --  may want to see. When the user clicks a button a "response" signal is 
  153.    --  emitted with response IDs from Gtk_Response_Type. See 
  154.    --  Gtk.Dialog.Gtk_Dialog for more details. 
  155.    --  "parent": transient parent, or null for none 
  156.    --  "flags": flags 
  157.    --  "type": type of message 
  158.    --  "buttons": set of buttons to use 
  159.    --  "message": printf-style format string, or null 
  160.  
  161.    function Gtk_Message_Dialog_New 
  162.       (Parent   : access Gtk.Window.Gtk_Window_Record'Class; 
  163.        Flags    : Gtk_Dialog_Flags; 
  164.        The_Type : Gtk_Message_Type; 
  165.        Buttons  : Gtk_Buttons_Type; 
  166.        Message  : UTF8_String := ""; 
  167.        Arg5     : System.Address) return Gtk_Message_Dialog; 
  168.    --  Creates a new message dialog, which is a simple dialog with an icon 
  169.    --  indicating the dialog type (error, warning, etc.) and some text the user 
  170.    --  may want to see. When the user clicks a button a "response" signal is 
  171.    --  emitted with response IDs from Gtk_Response_Type. See 
  172.    --  Gtk.Dialog.Gtk_Dialog for more details. 
  173.    --  "parent": transient parent, or null for none 
  174.    --  "flags": flags 
  175.    --  "type": type of message 
  176.    --  "buttons": set of buttons to use 
  177.    --  "message": printf-style format string, or null 
  178.  
  179.    procedure Gtk_New_With_Markup 
  180.       (Dialog   : out Gtk_Message_Dialog; 
  181.        Parent   : access Gtk.Window.Gtk_Window_Record'Class; 
  182.        Flags    : Gtk_Dialog_Flags; 
  183.        The_Type : Gtk_Message_Type; 
  184.        Buttons  : Gtk_Buttons_Type; 
  185.        Message  : UTF8_String := ""; 
  186.        Arg5     : System.Address); 
  187.    procedure Initialize_With_Markup 
  188.       (Dialog   : not null access Gtk_Message_Dialog_Record'Class; 
  189.        Parent   : access Gtk.Window.Gtk_Window_Record'Class; 
  190.        Flags    : Gtk_Dialog_Flags; 
  191.        The_Type : Gtk_Message_Type; 
  192.        Buttons  : Gtk_Buttons_Type; 
  193.        Message  : UTF8_String := ""; 
  194.        Arg5     : System.Address); 
  195.    --  Creates a new message dialog, which is a simple dialog with an icon 
  196.    --  indicating the dialog type (error, warning, etc.) and some text which is 
  197.    --  marked up with the <link linkend="PangoMarkupFormat">Pango text markup 
  198.    --  language</link>. When the user clicks a button a "response" signal is 
  199.    --  emitted with response IDs from Gtk_Response_Type. See 
  200.    --  Gtk.Dialog.Gtk_Dialog for more details. 
  201.    --  Special XML characters in the printf arguments passed to this function 
  202.    --  will automatically be escaped as necessary. (See g_markup_printf_escaped 
  203.    --  for how this is implemented.) Usually this is what you want, but if you 
  204.    --  have an existing Pango markup string that you want to use literally as 
  205.    --  the label, then you need to use Gtk.Message_Dialog.Set_Markup instead, 
  206.    --  since you can't pass the markup string either as the format (it might 
  207.    --  contain '%' characters) or as a string argument. |[ GtkWidget *dialog; 
  208.    --  dialog = gtk_message_dialog_new (main_application_window, 
  209.    --  GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, 
  210.    --  NULL); gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), 
  211.    --  markup); ]| 
  212.    --  Since: gtk+ 2.4 
  213.    --  "parent": transient parent, or null for none 
  214.    --  "flags": flags 
  215.    --  "type": type of message 
  216.    --  "buttons": set of buttons to use 
  217.    --  "message": printf-style format string, or null 
  218.  
  219.    function Gtk_Message_Dialog_New_With_Markup 
  220.       (Parent   : access Gtk.Window.Gtk_Window_Record'Class; 
  221.        Flags    : Gtk_Dialog_Flags; 
  222.        The_Type : Gtk_Message_Type; 
  223.        Buttons  : Gtk_Buttons_Type; 
  224.        Message  : UTF8_String := ""; 
  225.        Arg5     : System.Address) return Gtk_Message_Dialog; 
  226.    --  Creates a new message dialog, which is a simple dialog with an icon 
  227.    --  indicating the dialog type (error, warning, etc.) and some text which is 
  228.    --  marked up with the <link linkend="PangoMarkupFormat">Pango text markup 
  229.    --  language</link>. When the user clicks a button a "response" signal is 
  230.    --  emitted with response IDs from Gtk_Response_Type. See 
  231.    --  Gtk.Dialog.Gtk_Dialog for more details. 
  232.    --  Special XML characters in the printf arguments passed to this function 
  233.    --  will automatically be escaped as necessary. (See g_markup_printf_escaped 
  234.    --  for how this is implemented.) Usually this is what you want, but if you 
  235.    --  have an existing Pango markup string that you want to use literally as 
  236.    --  the label, then you need to use Gtk.Message_Dialog.Set_Markup instead, 
  237.    --  since you can't pass the markup string either as the format (it might 
  238.    --  contain '%' characters) or as a string argument. |[ GtkWidget *dialog; 
  239.    --  dialog = gtk_message_dialog_new (main_application_window, 
  240.    --  GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, 
  241.    --  NULL); gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), 
  242.    --  markup); ]| 
  243.    --  Since: gtk+ 2.4 
  244.    --  "parent": transient parent, or null for none 
  245.    --  "flags": flags 
  246.    --  "type": type of message 
  247.    --  "buttons": set of buttons to use 
  248.    --  "message": printf-style format string, or null 
  249.  
  250.    function Get_Type return Glib.GType; 
  251.    pragma Import (C, Get_Type, "gtk_message_dialog_get_type"); 
  252.  
  253.    ------------- 
  254.    -- Methods -- 
  255.    ------------- 
  256.  
  257.    procedure Format_Secondary_Markup 
  258.       (Dialog  : not null access Gtk_Message_Dialog_Record; 
  259.        Message : UTF8_String := ""; 
  260.        Arg2    : System.Address); 
  261.    --  Sets the secondary text of the message dialog to be Message_Format 
  262.    --  (with printf-style), which is marked up with the <link 
  263.    --  linkend="PangoMarkupFormat">Pango text markup language</link>. 
  264.    --  Due to an oversight, this function does not escape special XML 
  265.    --  characters like Gtk.Message_Dialog.Gtk_New_With_Markup does. Thus, if 
  266.    --  the arguments may contain special XML characters, you should use 
  267.    --  g_markup_printf_escaped to escape it. 
  268.    --    gchar *msg; 
  269.    --    msg = g_markup_printf_escaped (message_format, ...); 
  270.    --    gtk_message_dialog_format_secondary_markup (message_dialog, "%s", msg); 
  271.    --    g_free (msg); 
  272.    --  Since: gtk+ 2.6 
  273.    --  "message": printf-style markup string (see <link 
  274.    --  linkend="PangoMarkupFormat">Pango markup format</link>), or null 
  275.  
  276.    function Get_Image 
  277.       (Dialog : not null access Gtk_Message_Dialog_Record) 
  278.        return Gtk.Widget.Gtk_Widget; 
  279.    --  Gets the dialog's image. 
  280.    --  Since: gtk+ 2.14 
  281.  
  282.    procedure Set_Image 
  283.       (Dialog : not null access Gtk_Message_Dialog_Record; 
  284.        Image  : not null access Gtk.Widget.Gtk_Widget_Record'Class); 
  285.    --  Sets the dialog's image to Image. 
  286.    --  Since: gtk+ 2.10 
  287.    --  "image": the image 
  288.  
  289.    function Get_Message_Area 
  290.       (Dialog : not null access Gtk_Message_Dialog_Record) 
  291.        return Gtk.Widget.Gtk_Widget; 
  292.    --  Returns the message area of the dialog. This is the box where the 
  293.    --  dialog's primary and secondary labels are packed. You can add your own 
  294.    --  extra content to that box and it will appear below those labels, on the 
  295.    --  right side of the dialog's image (or on the left for right-to-left 
  296.    --  languages). See Gtk.Dialog.Get_Content_Area for the corresponding 
  297.    --  function in the parent Gtk.Dialog.Gtk_Dialog. 
  298.    --  Since: gtk+ 2.22 
  299.  
  300.    procedure Set_Markup 
  301.       (Dialog : not null access Gtk_Message_Dialog_Record; 
  302.        Str    : UTF8_String); 
  303.    --  Sets the text of the message dialog to be Str, which is marked up with 
  304.    --  the <link linkend="PangoMarkupFormat">Pango text markup language</link>. 
  305.    --  Since: gtk+ 2.4 
  306.    --  "str": markup string (see <link linkend="PangoMarkupFormat">Pango 
  307.    --  markup format</link>) 
  308.  
  309.    ---------------- 
  310.    -- Properties -- 
  311.    ---------------- 
  312.    --  The following properties are defined for this widget. See 
  313.    --  Glib.Properties for more information on properties) 
  314.  
  315.    Buttons_Property : constant Gtk.Message_Dialog.Property_Gtk_Buttons_Type; 
  316.    --  Type: Gtk_Buttons_Type 
  317.    --  Flags: write 
  318.  
  319.    Image_Property : constant Glib.Properties.Property_Object; 
  320.    --  Type: Gtk.Widget.Gtk_Widget 
  321.    --  The image for this dialog. 
  322.  
  323.    Message_Area_Property : constant Glib.Properties.Property_Object; 
  324.    --  Type: Gtk.Widget.Gtk_Widget 
  325.    --  The Gtk.Box.Gtk_Vbox that corresponds to the message area of this 
  326.    --  dialog. See Gtk.Message_Dialog.Get_Message_Area for a detailed 
  327.    --  description of this area. 
  328.  
  329.    Message_Type_Property : constant Gtk.Message_Dialog.Property_Gtk_Message_Type; 
  330.    --  Type: Gtk_Message_Type 
  331.    --  The type of the message. The type is used to determine the image that 
  332.    --  is shown in the dialog, unless the image is explicitly set by the 
  333.    --  ::image property. 
  334.  
  335.    Secondary_Text_Property : constant Glib.Properties.Property_String; 
  336.    --  The secondary text of the message dialog. 
  337.  
  338.    Secondary_Use_Markup_Property : constant Glib.Properties.Property_Boolean; 
  339.    --  True if the secondary text of the dialog includes Pango markup. See 
  340.    --  pango_parse_markup. 
  341.  
  342.    Text_Property : constant Glib.Properties.Property_String; 
  343.    --  The primary text of the message dialog. If the dialog has a secondary 
  344.    --  text, this will appear as the title. 
  345.  
  346.    Use_Markup_Property : constant Glib.Properties.Property_Boolean; 
  347.    --  True if the primary text of the dialog includes Pango markup. See 
  348.    --  pango_parse_markup. 
  349.  
  350.    ---------------- 
  351.    -- Interfaces -- 
  352.    ---------------- 
  353.    --  This class implements several interfaces. See Glib.Types 
  354.    -- 
  355.    --  - "Buildable" 
  356.  
  357.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  358.      (Gtk.Buildable.Gtk_Buildable, Gtk_Message_Dialog_Record, Gtk_Message_Dialog); 
  359.    function "+" 
  360.      (Widget : access Gtk_Message_Dialog_Record'Class) 
  361.    return Gtk.Buildable.Gtk_Buildable 
  362.    renames Implements_Gtk_Buildable.To_Interface; 
  363.    function "-" 
  364.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  365.    return Gtk_Message_Dialog 
  366.    renames Implements_Gtk_Buildable.To_Object; 
  367.  
  368. private 
  369.    Use_Markup_Property : constant Glib.Properties.Property_Boolean := 
  370.      Glib.Properties.Build ("use-markup"); 
  371.    Text_Property : constant Glib.Properties.Property_String := 
  372.      Glib.Properties.Build ("text"); 
  373.    Secondary_Use_Markup_Property : constant Glib.Properties.Property_Boolean := 
  374.      Glib.Properties.Build ("secondary-use-markup"); 
  375.    Secondary_Text_Property : constant Glib.Properties.Property_String := 
  376.      Glib.Properties.Build ("secondary-text"); 
  377.    Message_Type_Property : constant Gtk.Message_Dialog.Property_Gtk_Message_Type := 
  378.      Gtk.Message_Dialog.Build ("message-type"); 
  379.    Message_Area_Property : constant Glib.Properties.Property_Object := 
  380.      Glib.Properties.Build ("message-area"); 
  381.    Image_Property : constant Glib.Properties.Property_Object := 
  382.      Glib.Properties.Build ("image"); 
  383.    Buttons_Property : constant Gtk.Message_Dialog.Property_Gtk_Buttons_Type := 
  384.      Gtk.Message_Dialog.Build ("buttons"); 
  385. end Gtk.Message_Dialog;