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. --  The Gtk.Font_Button.Gtk_Font_Button is a button which displays the 
  26. --  currently selected font an allows to open a font chooser dialog to change 
  27. --  the font. It is suitable widget for selecting a font in a preference 
  28. --  dialog. 
  29. -- 
  30. --  </description> 
  31. pragma Ada_2005; 
  32.  
  33. pragma Warnings (Off, "*is already use-visible*"); 
  34. with Glib;              use Glib; 
  35. with Glib.Object;       use Glib.Object; 
  36. with Glib.Properties;   use Glib.Properties; 
  37. with Glib.Types;        use Glib.Types; 
  38. with Glib.Variant;      use Glib.Variant; 
  39. with Gtk.Action;        use Gtk.Action; 
  40. with Gtk.Actionable;    use Gtk.Actionable; 
  41. with Gtk.Activatable;   use Gtk.Activatable; 
  42. with Gtk.Buildable;     use Gtk.Buildable; 
  43. with Gtk.Button;        use Gtk.Button; 
  44. with Gtk.Font_Chooser;  use Gtk.Font_Chooser; 
  45. with Pango.Font;        use Pango.Font; 
  46. with Pango.Font_Face;   use Pango.Font_Face; 
  47. with Pango.Font_Family; use Pango.Font_Family; 
  48.  
  49. package Gtk.Font_Button is 
  50.  
  51.    type Gtk_Font_Button_Record is new Gtk_Button_Record with null record; 
  52.    type Gtk_Font_Button is access all Gtk_Font_Button_Record'Class; 
  53.  
  54.    --------------- 
  55.    -- Callbacks -- 
  56.    --------------- 
  57.  
  58.    type Gtk_Font_Filter_Func is access function 
  59.      (Family : not null access Pango.Font_Family.Pango_Font_Family_Record'Class; 
  60.       Face   : not null access Pango.Font_Face.Pango_Font_Face_Record'Class) 
  61.    return Boolean; 
  62.    --  The type of function that is used for deciding what fonts get shown in 
  63.    --  a Gtk.Font_Chooser.Gtk_Font_Chooser. See 
  64.    --  Gtk.Font_Chooser.Set_Filter_Func. 
  65.    --  "family": a Pango.Font_Family.Pango_Font_Family 
  66.    --  "face": a Pango.Font_Face.Pango_Font_Face belonging to Family 
  67.  
  68.    ------------------ 
  69.    -- Constructors -- 
  70.    ------------------ 
  71.  
  72.    procedure Gtk_New (Font_Button : out Gtk_Font_Button); 
  73.    procedure Initialize 
  74.       (Font_Button : not null access Gtk_Font_Button_Record'Class); 
  75.    --  Creates a new font picker widget. 
  76.    --  Since: gtk+ 2.4 
  77.  
  78.    function Gtk_Font_Button_New return Gtk_Font_Button; 
  79.    --  Creates a new font picker widget. 
  80.    --  Since: gtk+ 2.4 
  81.  
  82.    procedure Gtk_New_With_Font 
  83.       (Font_Button : out Gtk_Font_Button; 
  84.        Fontname    : UTF8_String); 
  85.    procedure Initialize_With_Font 
  86.       (Font_Button : not null access Gtk_Font_Button_Record'Class; 
  87.        Fontname    : UTF8_String); 
  88.    --  Creates a new font picker widget. 
  89.    --  Since: gtk+ 2.4 
  90.    --  "fontname": Name of font to display in font chooser dialog 
  91.  
  92.    function Gtk_Font_Button_New_With_Font 
  93.       (Fontname : UTF8_String) return Gtk_Font_Button; 
  94.    --  Creates a new font picker widget. 
  95.    --  Since: gtk+ 2.4 
  96.    --  "fontname": Name of font to display in font chooser dialog 
  97.  
  98.    function Get_Type return Glib.GType; 
  99.    pragma Import (C, Get_Type, "gtk_font_button_get_type"); 
  100.  
  101.    ------------- 
  102.    -- Methods -- 
  103.    ------------- 
  104.  
  105.    function Get_Font_Name 
  106.       (Font_Button : not null access Gtk_Font_Button_Record) 
  107.        return UTF8_String; 
  108.    --  Retrieves the name of the currently selected font. This name includes 
  109.    --  style and size information as well. If you want to render something with 
  110.    --  the font, use this string with Pango.Font.From_String . If you're 
  111.    --  interested in peeking certain values (family name, style, size, weight) 
  112.    --  just query these properties from the Pango.Font.Pango_Font_Description 
  113.    --  object. 
  114.    --  Since: gtk+ 2.4 
  115.  
  116.    function Set_Font_Name 
  117.       (Font_Button : not null access Gtk_Font_Button_Record; 
  118.        Fontname    : UTF8_String) return Boolean; 
  119.    --  Sets or updates the currently-displayed font in font picker dialog. 
  120.    --  Since: gtk+ 2.4 
  121.    --  "fontname": Name of font to display in font chooser dialog 
  122.  
  123.    function Get_Show_Size 
  124.       (Font_Button : not null access Gtk_Font_Button_Record) return Boolean; 
  125.    --  Returns whether the font size will be shown in the label. 
  126.    --  Since: gtk+ 2.4 
  127.  
  128.    procedure Set_Show_Size 
  129.       (Font_Button : not null access Gtk_Font_Button_Record; 
  130.        Show_Size   : Boolean); 
  131.    --  If Show_Size is True, the font size will be displayed along with the 
  132.    --  name of the selected font. 
  133.    --  Since: gtk+ 2.4 
  134.    --  "show_size": True if font size should be displayed in dialog. 
  135.  
  136.    function Get_Show_Style 
  137.       (Font_Button : not null access Gtk_Font_Button_Record) return Boolean; 
  138.    --  Returns whether the name of the font style will be shown in the label. 
  139.    --  Since: gtk+ 2.4 
  140.  
  141.    procedure Set_Show_Style 
  142.       (Font_Button : not null access Gtk_Font_Button_Record; 
  143.        Show_Style  : Boolean); 
  144.    --  If Show_Style is True, the font style will be displayed along with name 
  145.    --  of the selected font. 
  146.    --  Since: gtk+ 2.4 
  147.    --  "show_style": True if font style should be displayed in label. 
  148.  
  149.    function Get_Title 
  150.       (Font_Button : not null access Gtk_Font_Button_Record) 
  151.        return UTF8_String; 
  152.    --  Retrieves the title of the font chooser dialog. 
  153.    --  Since: gtk+ 2.4 
  154.  
  155.    procedure Set_Title 
  156.       (Font_Button : not null access Gtk_Font_Button_Record; 
  157.        Title       : UTF8_String); 
  158.    --  Sets the title for the font chooser dialog. 
  159.    --  Since: gtk+ 2.4 
  160.    --  "title": a string containing the font chooser dialog title 
  161.  
  162.    function Get_Use_Font 
  163.       (Font_Button : not null access Gtk_Font_Button_Record) return Boolean; 
  164.    --  Returns whether the selected font is used in the label. 
  165.    --  Since: gtk+ 2.4 
  166.  
  167.    procedure Set_Use_Font 
  168.       (Font_Button : not null access Gtk_Font_Button_Record; 
  169.        Use_Font    : Boolean); 
  170.    --  If Use_Font is True, the font name will be written using the selected 
  171.    --  font. 
  172.    --  Since: gtk+ 2.4 
  173.    --  "use_font": If True, font name will be written using font chosen. 
  174.  
  175.    function Get_Use_Size 
  176.       (Font_Button : not null access Gtk_Font_Button_Record) return Boolean; 
  177.    --  Returns whether the selected size is used in the label. 
  178.    --  Since: gtk+ 2.4 
  179.  
  180.    procedure Set_Use_Size 
  181.       (Font_Button : not null access Gtk_Font_Button_Record; 
  182.        Use_Size    : Boolean); 
  183.    --  If Use_Size is True, the font name will be written using the selected 
  184.    --  size. 
  185.    --  Since: gtk+ 2.4 
  186.    --  "use_size": If True, font name will be written using the selected size. 
  187.  
  188.    procedure Set_Filter_Func 
  189.       (Self   : not null access Gtk_Font_Button_Record; 
  190.        Filter : Gtk_Font_Filter_Func); 
  191.    --  Adds a filter function that decides which fonts to display in the font 
  192.    --  chooser. 
  193.    --  Since: gtk+ 3.2 
  194.    --  "filter": a Gtk_Font_Filter_Func, or null 
  195.  
  196.    generic 
  197.       type User_Data_Type (<>) is private; 
  198.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  199.    package Set_Filter_Func_User_Data is 
  200.  
  201.       type Gtk_Font_Filter_Func is access function 
  202.         (Family : not null access Pango.Font_Family.Pango_Font_Family_Record'Class; 
  203.          Face   : not null access Pango.Font_Face.Pango_Font_Face_Record'Class; 
  204.          Data   : User_Data_Type) return Boolean; 
  205.       --  The type of function that is used for deciding what fonts get shown in 
  206.       --  a Gtk.Font_Chooser.Gtk_Font_Chooser. See 
  207.       --  Gtk.Font_Chooser.Set_Filter_Func. 
  208.       --  "family": a Pango.Font_Family.Pango_Font_Family 
  209.       --  "face": a Pango.Font_Face.Pango_Font_Face belonging to Family 
  210.       --  "data": user data passed to Gtk.Font_Chooser.Set_Filter_Func 
  211.  
  212.       procedure Set_Filter_Func 
  213.          (Self      : not null access Gtk.Font_Button.Gtk_Font_Button_Record'Class; 
  214.           Filter    : Gtk_Font_Filter_Func; 
  215.           User_Data : User_Data_Type); 
  216.       --  Adds a filter function that decides which fonts to display in the 
  217.       --  font chooser. 
  218.       --  Since: gtk+ 3.2 
  219.       --  "filter": a Gtk_Font_Filter_Func, or null 
  220.       --  "user_data": data to pass to Filter 
  221.  
  222.    end Set_Filter_Func_User_Data; 
  223.  
  224.    --------------------------------------------- 
  225.    -- Inherited subprograms (from interfaces) -- 
  226.    --------------------------------------------- 
  227.    --  Methods inherited from the Buildable interface are not duplicated here 
  228.    --  since they are meant to be used by tools, mostly. If you need to call 
  229.    --  them, use an explicit cast through the "-" operator below. 
  230.  
  231.    function Get_Action_Name 
  232.       (Self : not null access Gtk_Font_Button_Record) return UTF8_String; 
  233.  
  234.    procedure Set_Action_Name 
  235.       (Self        : not null access Gtk_Font_Button_Record; 
  236.        Action_Name : UTF8_String); 
  237.  
  238.    function Get_Action_Target_Value 
  239.       (Self : not null access Gtk_Font_Button_Record) 
  240.        return Glib.Variant.Gvariant; 
  241.  
  242.    procedure Set_Action_Target_Value 
  243.       (Self         : not null access Gtk_Font_Button_Record; 
  244.        Target_Value : Glib.Variant.Gvariant); 
  245.  
  246.    procedure Set_Detailed_Action_Name 
  247.       (Self                 : not null access Gtk_Font_Button_Record; 
  248.        Detailed_Action_Name : UTF8_String); 
  249.  
  250.    procedure Do_Set_Related_Action 
  251.       (Self   : not null access Gtk_Font_Button_Record; 
  252.        Action : not null access Gtk.Action.Gtk_Action_Record'Class); 
  253.  
  254.    function Get_Related_Action 
  255.       (Self : not null access Gtk_Font_Button_Record) 
  256.        return Gtk.Action.Gtk_Action; 
  257.  
  258.    procedure Set_Related_Action 
  259.       (Self   : not null access Gtk_Font_Button_Record; 
  260.        Action : not null access Gtk.Action.Gtk_Action_Record'Class); 
  261.  
  262.    function Get_Use_Action_Appearance 
  263.       (Self : not null access Gtk_Font_Button_Record) return Boolean; 
  264.  
  265.    procedure Set_Use_Action_Appearance 
  266.       (Self           : not null access Gtk_Font_Button_Record; 
  267.        Use_Appearance : Boolean); 
  268.  
  269.    procedure Sync_Action_Properties 
  270.       (Self   : not null access Gtk_Font_Button_Record; 
  271.        Action : access Gtk.Action.Gtk_Action_Record'Class); 
  272.  
  273.    function Get_Font 
  274.       (Self : not null access Gtk_Font_Button_Record) return UTF8_String; 
  275.  
  276.    procedure Set_Font 
  277.       (Self     : not null access Gtk_Font_Button_Record; 
  278.        Fontname : UTF8_String); 
  279.  
  280.    function Get_Font_Desc 
  281.       (Self : not null access Gtk_Font_Button_Record) 
  282.        return Pango.Font.Pango_Font_Description; 
  283.  
  284.    procedure Set_Font_Desc 
  285.       (Self      : not null access Gtk_Font_Button_Record; 
  286.        Font_Desc : Pango.Font.Pango_Font_Description); 
  287.  
  288.    function Get_Font_Face 
  289.       (Self : not null access Gtk_Font_Button_Record) 
  290.        return Pango.Font_Face.Pango_Font_Face; 
  291.  
  292.    function Get_Font_Family 
  293.       (Self : not null access Gtk_Font_Button_Record) 
  294.        return Pango.Font_Family.Pango_Font_Family; 
  295.  
  296.    function Get_Font_Size 
  297.       (Self : not null access Gtk_Font_Button_Record) return Gint; 
  298.  
  299.    function Get_Preview_Text 
  300.       (Self : not null access Gtk_Font_Button_Record) return UTF8_String; 
  301.  
  302.    procedure Set_Preview_Text 
  303.       (Self : not null access Gtk_Font_Button_Record; 
  304.        Text : UTF8_String); 
  305.  
  306.    function Get_Show_Preview_Entry 
  307.       (Self : not null access Gtk_Font_Button_Record) return Boolean; 
  308.  
  309.    procedure Set_Show_Preview_Entry 
  310.       (Self               : not null access Gtk_Font_Button_Record; 
  311.        Show_Preview_Entry : Boolean); 
  312.  
  313.    ---------------- 
  314.    -- Properties -- 
  315.    ---------------- 
  316.    --  The following properties are defined for this widget. See 
  317.    --  Glib.Properties for more information on properties) 
  318.  
  319.    Font_Name_Property : constant Glib.Properties.Property_String; 
  320.    --  The name of the currently selected font. 
  321.  
  322.    Show_Size_Property : constant Glib.Properties.Property_Boolean; 
  323.    --  If this property is set to True, the selected font size will be shown 
  324.    --  in the label. For a more WYSIWYG way to show the selected size, see the 
  325.    --  ::use-size property. 
  326.  
  327.    Show_Style_Property : constant Glib.Properties.Property_Boolean; 
  328.    --  If this property is set to True, the name of the selected font style 
  329.    --  will be shown in the label. For a more WYSIWYG way to show the selected 
  330.    --  style, see the ::use-font property. 
  331.  
  332.    Title_Property : constant Glib.Properties.Property_String; 
  333.    --  The title of the font chooser dialog. 
  334.  
  335.    Use_Font_Property : constant Glib.Properties.Property_Boolean; 
  336.    --  If this property is set to True, the label will be drawn in the 
  337.    --  selected font. 
  338.  
  339.    Use_Size_Property : constant Glib.Properties.Property_Boolean; 
  340.    --  If this property is set to True, the label will be drawn with the 
  341.    --  selected font size. 
  342.  
  343.    ------------- 
  344.    -- Signals -- 
  345.    ------------- 
  346.  
  347.    type Cb_Gtk_Font_Button_Void is not null access procedure 
  348.      (Self : access Gtk_Font_Button_Record'Class); 
  349.  
  350.    type Cb_GObject_Void is not null access procedure 
  351.      (Self : access Glib.Object.GObject_Record'Class); 
  352.  
  353.    Signal_Font_Set : constant Glib.Signal_Name := "font-set"; 
  354.    procedure On_Font_Set 
  355.       (Self  : not null access Gtk_Font_Button_Record; 
  356.        Call  : Cb_Gtk_Font_Button_Void; 
  357.        After : Boolean := False); 
  358.    procedure On_Font_Set 
  359.       (Self  : not null access Gtk_Font_Button_Record; 
  360.        Call  : Cb_GObject_Void; 
  361.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  362.        After : Boolean := False); 
  363.    --  The ::font-set signal is emitted when the user selects a font. When 
  364.    --  handling this signal, use Gtk.Font_Button.Get_Font_Name to find out 
  365.    --  which font was just selected. 
  366.    -- 
  367.    --  Note that this signal is only emitted when the *user* changes the font. 
  368.    --  If you need to react to programmatic font changes as well, use the 
  369.    --  notify::font-name signal. 
  370.  
  371.    ---------------- 
  372.    -- Interfaces -- 
  373.    ---------------- 
  374.    --  This class implements several interfaces. See Glib.Types 
  375.    -- 
  376.    --  - "Actionable" 
  377.    -- 
  378.    --  - "Activatable" 
  379.    -- 
  380.    --  - "Buildable" 
  381.    -- 
  382.    --  - "FontChooser" 
  383.  
  384.    package Implements_Gtk_Actionable is new Glib.Types.Implements 
  385.      (Gtk.Actionable.Gtk_Actionable, Gtk_Font_Button_Record, Gtk_Font_Button); 
  386.    function "+" 
  387.      (Widget : access Gtk_Font_Button_Record'Class) 
  388.    return Gtk.Actionable.Gtk_Actionable 
  389.    renames Implements_Gtk_Actionable.To_Interface; 
  390.    function "-" 
  391.      (Interf : Gtk.Actionable.Gtk_Actionable) 
  392.    return Gtk_Font_Button 
  393.    renames Implements_Gtk_Actionable.To_Object; 
  394.  
  395.    package Implements_Gtk_Activatable is new Glib.Types.Implements 
  396.      (Gtk.Activatable.Gtk_Activatable, Gtk_Font_Button_Record, Gtk_Font_Button); 
  397.    function "+" 
  398.      (Widget : access Gtk_Font_Button_Record'Class) 
  399.    return Gtk.Activatable.Gtk_Activatable 
  400.    renames Implements_Gtk_Activatable.To_Interface; 
  401.    function "-" 
  402.      (Interf : Gtk.Activatable.Gtk_Activatable) 
  403.    return Gtk_Font_Button 
  404.    renames Implements_Gtk_Activatable.To_Object; 
  405.  
  406.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  407.      (Gtk.Buildable.Gtk_Buildable, Gtk_Font_Button_Record, Gtk_Font_Button); 
  408.    function "+" 
  409.      (Widget : access Gtk_Font_Button_Record'Class) 
  410.    return Gtk.Buildable.Gtk_Buildable 
  411.    renames Implements_Gtk_Buildable.To_Interface; 
  412.    function "-" 
  413.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  414.    return Gtk_Font_Button 
  415.    renames Implements_Gtk_Buildable.To_Object; 
  416.  
  417.    package Implements_Gtk_Font_Chooser is new Glib.Types.Implements 
  418.      (Gtk.Font_Chooser.Gtk_Font_Chooser, Gtk_Font_Button_Record, Gtk_Font_Button); 
  419.    function "+" 
  420.      (Widget : access Gtk_Font_Button_Record'Class) 
  421.    return Gtk.Font_Chooser.Gtk_Font_Chooser 
  422.    renames Implements_Gtk_Font_Chooser.To_Interface; 
  423.    function "-" 
  424.      (Interf : Gtk.Font_Chooser.Gtk_Font_Chooser) 
  425.    return Gtk_Font_Button 
  426.    renames Implements_Gtk_Font_Chooser.To_Object; 
  427.  
  428. private 
  429.    Use_Size_Property : constant Glib.Properties.Property_Boolean := 
  430.      Glib.Properties.Build ("use-size"); 
  431.    Use_Font_Property : constant Glib.Properties.Property_Boolean := 
  432.      Glib.Properties.Build ("use-font"); 
  433.    Title_Property : constant Glib.Properties.Property_String := 
  434.      Glib.Properties.Build ("title"); 
  435.    Show_Style_Property : constant Glib.Properties.Property_Boolean := 
  436.      Glib.Properties.Build ("show-style"); 
  437.    Show_Size_Property : constant Glib.Properties.Property_Boolean := 
  438.      Glib.Properties.Build ("show-size"); 
  439.    Font_Name_Property : constant Glib.Properties.Property_String := 
  440.      Glib.Properties.Build ("font-name"); 
  441. end Gtk.Font_Button;