1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --                    Copyright (C) 2010, AdaCore                    -- 
  5. --                                                                   -- 
  6. -- This library is free software; you can redistribute it and/or     -- 
  7. -- modify it under the terms of the GNU General Public               -- 
  8. -- License as published by the Free Software Foundation; either      -- 
  9. -- version 2 of the License, or (at your option) any later version.  -- 
  10. --                                                                   -- 
  11. -- This library is distributed in the hope that it will be useful,   -- 
  12. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  13. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  14. -- General Public License for more details.                          -- 
  15. --                                                                   -- 
  16. -- You should have received a copy of the GNU General Public         -- 
  17. -- License along with this library; if not, write to the             -- 
  18. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  19. -- Boston, MA 02111-1307, USA.                                       -- 
  20. --                                                                   -- 
  21. -- -- -- -- -- -- -- -- -- -- -- --
  22. ----------------------------------------------------------------------- 
  23.  
  24. --  <description> 
  25. --  A Gtk_Link_Button is like a regular button with contents that 
  26. --  appear like a web browser hyperlink.  It is associated with a 
  27. --  URI.  The URI is passed to a callback procedure that is invoked 
  28. --  when the user clicks the button.  This widget also keeps track of 
  29. --  whether it has been clicked, and changes color after it has been 
  30. --  visited. 
  31. --  </description> 
  32. --  <c_version>2.16.6</c_version> 
  33. --  <group>Buttons and Toggles</group> 
  34. --  <testgtk>create_link_buttons.adb</testgtk> 
  35.  
  36. with Interfaces.C.Strings; 
  37.  
  38. with Glib.Properties; 
  39. with Gtk.Button; 
  40. with Gtk.Widget;      use Gtk.Widget; 
  41.  
  42. package Gtk.Link_Button is 
  43.  
  44.    type Gtk_Link_Button_Record is new 
  45.      Gtk.Button.Gtk_Button_Record with private; 
  46.    type Gtk_Link_Button is access all Gtk_Link_Button_Record'Class; 
  47.  
  48.    function Get_Type return GType; 
  49.    --  Return the internal value associated with a Gtk_Link_Button. 
  50.  
  51.    function Get_Uri 
  52.      (Link_Button : access Gtk_Link_Button_Record) return String; 
  53.    --  Retrieves the URI set using Set_Uri. 
  54.    --  Return value: a valid URI.  The returned string is owned by the 
  55.    --  link button and should not be modified or freed. 
  56.  
  57.    function Get_Visited 
  58.      (Link_Button : access Gtk_Link_Button_Record) return Boolean; 
  59.    --  Retrieves the 'visited' state of the URI where the Link_Button 
  60.    --  points. The button becomes visited when it is clicked. If the URI 
  61.    --  is changed on the button, the 'visited' state is unset again. 
  62.    -- 
  63.    --  The state may also be changed using Set_Visited. 
  64.    -- 
  65.    --  Return value: True if the link has been visited, False otherwise 
  66.  
  67.    procedure Gtk_New (Widget : out Gtk_Link_Button; Uri : String); 
  68.    --  Creates a new Gtk_Link_Button_Record with the URI as its text. 
  69.  
  70.    procedure Initialize 
  71.      (Widget : access Gtk_Link_Button_Record'Class; Uri : String); 
  72.    --  Creates a new Gtk_Link_Button_Record with the URI as its text. 
  73.  
  74.    procedure Gtk_New_With_Label 
  75.      (Widget : out Gtk_Link_Button; 
  76.       Uri    : String; 
  77.       Label  : String); 
  78.    --  Creates a new Gtk_Link_Button_Record containing a label. 
  79.  
  80.    procedure Initialize_With_Label 
  81.      (Widget : access Gtk_Link_Button_Record'Class; 
  82.       Uri    : String; 
  83.       Label  : String); 
  84.    --  Creates a new Gtk_Link_Button containing a label. 
  85.  
  86.    procedure Set_Uri 
  87.      (Link_Button : access Gtk_Link_Button_Record; 
  88.       Uri         : String); 
  89.    --  Sets Uri as the URI where the Gtk_Link_Button points. As a side-effect 
  90.    --  this unsets the 'visited' state of the button. 
  91.  
  92.    type Uri_Func is access procedure 
  93.      (Button : System.Address; 
  94.       Link   : Interfaces.C.Strings.chars_ptr; 
  95.       Data   : System.Address); 
  96.    pragma Convention (C, Uri_Func); 
  97.    --  This is a low-level callback function to be used with Set_Uri_Hook. 
  98.    --  See package Generic_Uri_Hook below for a higher-level interface. 
  99.    -- 
  100.    --  You could convert the parameters to Ada types with the following 
  101.    --  declarations: 
  102.    -- 
  103.    --     Stub        : Gtk_Link_Button_Record; 
  104.    --     Link_Button : constant Gtk_Link_Button := 
  105.    --                     Gtk_Link_Button (Get_User_Data (Button, Stub)); 
  106.    --     Link_String : constant String := Interfaces.C.Strings.Value (Link); 
  107.    -- 
  108.    --  You'd also perform an appropriate conversion on Data using 
  109.    --  Ada.Unchecked_Conversion. 
  110.  
  111.    function Set_Uri_Hook 
  112.      (Func    : Uri_Func; 
  113.       Data    : System.Address; 
  114.       Destroy : G_Destroy_Notify) 
  115.       return Uri_Func; 
  116.    --  Func: a function called each time a Gtk_Link_Button is clicked, or null 
  117.    --  Data: user data to be passed to Func, or null 
  118.    --  Destroy: called when Data is no longer needed, or null 
  119.    -- 
  120.    --  Sets Func as the subprogram that should be invoked every time a user 
  121.    --  clicks a Gtk_Link_Button. This function is called before every 
  122.    --  callback registered for the "clicked" signal. 
  123.    -- 
  124.    --  Returns the previously set hook function. 
  125.  
  126.    generic 
  127.       type Data_Type (<>) is private; 
  128.    package Generic_Uri_Hook is 
  129.       type Uri_Handler is access procedure 
  130.         (Button    : access Gtk_Link_Button_Record'Class; 
  131.          Link      : UTF8_String; 
  132.          User_Data : Data_Type); 
  133.       --  A callback that is invoked when the user presses a hyperlink. 
  134.  
  135.       type Destroy_Notify is access procedure (User_Data : in out Data_Type); 
  136.       --  Destroy_Notify is called just prior to the destruction of 
  137.       --  User_Data. 
  138.  
  139.       procedure Set_Uri_Hook 
  140.         (Handler   : Uri_Handler; 
  141.          User_Data : Data_Type; 
  142.          Destroy   : Destroy_Notify); 
  143.       --  Sets Handler as the subprogram that should be invoked every time 
  144.       --  a user clicks a Gtk_Link_Button. This subprogram is called before 
  145.       --  every callback registered for the "clicked" signal. 
  146.       -- 
  147.       --  If no uri hook has been set, GTK+ defaults to calling gtk_show_uri(). 
  148.    end Generic_Uri_Hook; 
  149.  
  150.    procedure Set_Visited 
  151.      (Link_Button : access Gtk_Link_Button_Record; 
  152.       Visited     : Boolean); 
  153.    --  Sets the 'visited' state of the URI where the #GtkLinkButton 
  154.    --  points.  See Get_Visited for more details. 
  155.  
  156.    Uri_Property : constant Glib.Properties.Property_String; 
  157.    Visited_Property : constant Glib.Properties.Property_Boolean; 
  158.  
  159. private 
  160.  
  161.    type Gtk_Link_Button_Record is new 
  162.      Gtk.Button.Gtk_Button_Record with null record; 
  163.  
  164.    Uri_Property : constant Glib.Properties.Property_String := 
  165.      Glib.Properties.Build ("uri"); 
  166.    Visited_Property : constant Glib.Properties.Property_Boolean := 
  167.      Glib.Properties.Build ("visited"); 
  168.  
  169.    pragma Import (C, Get_Type, "gtk_link_button_get_type"); 
  170.  
  171. end Gtk.Link_Button;