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.Calendar.Gtk_Calendar is a widget that displays a Gregorian calendar, 
  26. --  one month at a time. It can be created with Gtk.Calendar.Gtk_New. 
  27. -- 
  28. --  The month and year currently displayed can be altered with 
  29. --  Gtk.Calendar.Select_Month. The exact day can be selected from the displayed 
  30. --  month using Gtk.Calendar.Select_Day. 
  31. -- 
  32. --  To place a visual marker on a particular day, use Gtk.Calendar.Mark_Day 
  33. --  and to remove the marker, Gtk.Calendar.Unmark_Day. Alternative, all marks 
  34. --  can be cleared with Gtk.Calendar.Clear_Marks. 
  35. -- 
  36. --  The way in which the calendar itself is displayed can be altered using 
  37. --  Gtk.Calendar.Set_Display_Options. 
  38. -- 
  39. --  The selected date can be retrieved from a Gtk.Calendar.Gtk_Calendar using 
  40. --  Gtk.Calendar.Get_Date. 
  41. -- 
  42. --  Users should be aware that, although the Gregorian calendar is the legal 
  43. --  calendar in most countries, it was adopted progressively between 1582 and 
  44. --  1929. Display before these dates is likely to be historically incorrect. 
  45. -- 
  46. --  </description> 
  47. --  <screenshot>gtk-calendar</screenshot> 
  48. --  <group>Selectors</group> 
  49. --  <testgtk>create_calendar.adb</testgtk> 
  50. pragma Ada_2005; 
  51.  
  52. pragma Warnings (Off, "*is already use-visible*"); 
  53. with Glib;                    use Glib; 
  54. with Glib.Generic_Properties; use Glib.Generic_Properties; 
  55. with Glib.Object;             use Glib.Object; 
  56. with Glib.Properties;         use Glib.Properties; 
  57. with Glib.Types;              use Glib.Types; 
  58. with Gtk.Buildable;           use Gtk.Buildable; 
  59. with Gtk.Widget;              use Gtk.Widget; 
  60.  
  61. package Gtk.Calendar is 
  62.  
  63.    type Gtk_Calendar_Record is new Gtk_Widget_Record with null record; 
  64.    type Gtk_Calendar is access all Gtk_Calendar_Record'Class; 
  65.  
  66.    type Gtk_Calendar_Display_Options is mod 2 ** Integer'Size; 
  67.    pragma Convention (C, Gtk_Calendar_Display_Options); 
  68.    --  These options can be used to influence the display and behaviour of a 
  69.    --  Gtk.Calendar.Gtk_Calendar. 
  70.  
  71.    Show_Heading : constant Gtk_Calendar_Display_Options := 1; 
  72.    Show_Day_Names : constant Gtk_Calendar_Display_Options := 2; 
  73.    No_Month_Change : constant Gtk_Calendar_Display_Options := 4; 
  74.    Show_Week_Numbers : constant Gtk_Calendar_Display_Options := 8; 
  75.    Show_Details : constant Gtk_Calendar_Display_Options := 32; 
  76.  
  77.    --------------- 
  78.    -- Callbacks -- 
  79.    --------------- 
  80.  
  81.    type Gtk_Calendar_Detail_Func is access function 
  82.      (Calendar : not null access Gtk_Calendar_Record'Class; 
  83.       Year     : Guint; 
  84.       Month    : Guint; 
  85.       Day      : Guint) return UTF8_String; 
  86.    --  This kind of functions provide Pango markup with detail information for 
  87.    --  the specified day. Examples for such details are holidays or 
  88.    --  appointments. The function returns null when no information is 
  89.    --  available. 
  90.    --  Since: gtk+ 2.14 
  91.    --  "calendar": a Gtk.Calendar.Gtk_Calendar. 
  92.    --  "year": the year for which details are needed. 
  93.    --  "month": the month for which details are needed. 
  94.    --  "day": the day of Month for which details are needed. 
  95.  
  96.    ---------------------------- 
  97.    -- Enumeration Properties -- 
  98.    ---------------------------- 
  99.  
  100.    package Gtk_Calendar_Display_Options_Properties is 
  101.       new Generic_Internal_Discrete_Property (Gtk_Calendar_Display_Options); 
  102.    type Property_Gtk_Calendar_Display_Options is new Gtk_Calendar_Display_Options_Properties.Property; 
  103.  
  104.    ------------------ 
  105.    -- Constructors -- 
  106.    ------------------ 
  107.  
  108.    procedure Gtk_New (Calendar : out Gtk_Calendar); 
  109.    procedure Initialize 
  110.       (Calendar : not null access Gtk_Calendar_Record'Class); 
  111.    --  Creates a new calendar, with the current date being selected. 
  112.  
  113.    function Gtk_Calendar_New return Gtk_Calendar; 
  114.    --  Creates a new calendar, with the current date being selected. 
  115.  
  116.    function Get_Type return Glib.GType; 
  117.    pragma Import (C, Get_Type, "gtk_calendar_get_type"); 
  118.  
  119.    ------------- 
  120.    -- Methods -- 
  121.    ------------- 
  122.  
  123.    procedure Clear_Marks (Calendar : not null access Gtk_Calendar_Record); 
  124.    --  Remove all visual markers. 
  125.  
  126.    procedure Get_Date 
  127.       (Calendar : not null access Gtk_Calendar_Record; 
  128.        Year     : out Guint; 
  129.        Month    : out Guint; 
  130.        Day      : out Guint); 
  131.    --  Obtains the selected date from a Gtk.Calendar.Gtk_Calendar. 
  132.    --  "year": location to store the year as a decimal number (e.g. 2011), or 
  133.    --  null 
  134.    --  "month": location to store the month number (between 0 and 11), or null 
  135.    --  "day": location to store the day number (between 1 and 31), or null 
  136.  
  137.    function Get_Day_Is_Marked 
  138.       (Calendar : not null access Gtk_Calendar_Record; 
  139.        Day      : Guint) return Boolean; 
  140.    --  Returns if the Day of the Calendar is already marked. 
  141.    --  Since: gtk+ 3.0 
  142.    --  "day": the day number between 1 and 31. 
  143.  
  144.    function Get_Detail_Height_Rows 
  145.       (Calendar : not null access Gtk_Calendar_Record) return Gint; 
  146.    --  Queries the height of detail cells, in rows. See 
  147.    --  Gtk.Calendar.Gtk_Calendar:detail-width-chars. 
  148.    --  Since: gtk+ 2.14 
  149.  
  150.    procedure Set_Detail_Height_Rows 
  151.       (Calendar : not null access Gtk_Calendar_Record; 
  152.        Rows     : Gint); 
  153.    --  Updates the height of detail cells. See 
  154.    --  Gtk.Calendar.Gtk_Calendar:detail-height-rows. 
  155.    --  Since: gtk+ 2.14 
  156.    --  "rows": detail height in rows. 
  157.  
  158.    function Get_Detail_Width_Chars 
  159.       (Calendar : not null access Gtk_Calendar_Record) return Gint; 
  160.    --  Queries the width of detail cells, in characters. See 
  161.    --  Gtk.Calendar.Gtk_Calendar:detail-width-chars. 
  162.    --  Since: gtk+ 2.14 
  163.  
  164.    procedure Set_Detail_Width_Chars 
  165.       (Calendar : not null access Gtk_Calendar_Record; 
  166.        Chars    : Gint); 
  167.    --  Updates the width of detail cells. See 
  168.    --  Gtk.Calendar.Gtk_Calendar:detail-width-chars. 
  169.    --  Since: gtk+ 2.14 
  170.    --  "chars": detail width in characters. 
  171.  
  172.    function Get_Display_Options 
  173.       (Calendar : not null access Gtk_Calendar_Record) 
  174.        return Gtk_Calendar_Display_Options; 
  175.    --  Returns the current display options of Calendar. 
  176.    --  Since: gtk+ 2.4 
  177.  
  178.    procedure Set_Display_Options 
  179.       (Calendar : not null access Gtk_Calendar_Record; 
  180.        Flags    : Gtk_Calendar_Display_Options); 
  181.    --  Sets display options (whether to display the heading and the month 
  182.    --  headings). 
  183.    --  Since: gtk+ 2.4 
  184.    --  "flags": the display options to set 
  185.  
  186.    procedure Mark_Day 
  187.       (Calendar : not null access Gtk_Calendar_Record; 
  188.        Day      : Guint); 
  189.    --  Places a visual marker on a particular day. 
  190.    --  "day": the day number to mark between 1 and 31. 
  191.  
  192.    procedure Select_Day 
  193.       (Calendar : not null access Gtk_Calendar_Record; 
  194.        Day      : Guint); 
  195.    --  Selects a day from the current month. 
  196.    --  "day": the day number between 1 and 31, or 0 to unselect the currently 
  197.    --  selected day. 
  198.  
  199.    procedure Select_Month 
  200.       (Calendar : not null access Gtk_Calendar_Record; 
  201.        Month    : Guint; 
  202.        Year     : Guint); 
  203.    --  Shifts the calendar to a different month. 
  204.    --  "month": a month number between 0 and 11. 
  205.    --  "year": the year the month is in. 
  206.  
  207.    procedure Set_Detail_Func 
  208.       (Calendar : not null access Gtk_Calendar_Record; 
  209.        Func     : Gtk_Calendar_Detail_Func); 
  210.    --  Installs a function which provides Pango markup with detail information 
  211.    --  for each day. Examples for such details are holidays or appointments. 
  212.    --  That information is shown below each day when 
  213.    --  Gtk.Calendar.Gtk_Calendar:show-details is set. A tooltip containing with 
  214.    --  full detail information is provided, if the entire text should not fit 
  215.    --  into the details area, or if Gtk.Calendar.Gtk_Calendar:show-details is 
  216.    --  not set. 
  217.    --  The size of the details area can be restricted by setting the 
  218.    --  Gtk.Calendar.Gtk_Calendar:detail-width-chars and 
  219.    --  Gtk.Calendar.Gtk_Calendar:detail-height-rows properties. 
  220.    --  Since: gtk+ 2.14 
  221.    --  "func": a function providing details for each day. 
  222.  
  223.    generic 
  224.       type User_Data_Type (<>) is private; 
  225.       with procedure Destroy (Data : in out User_Data_Type) is null; 
  226.    package Set_Detail_Func_User_Data is 
  227.  
  228.       type Gtk_Calendar_Detail_Func is access function 
  229.         (Calendar  : not null access Gtk.Calendar.Gtk_Calendar_Record'Class; 
  230.          Year      : Guint; 
  231.          Month     : Guint; 
  232.          Day       : Guint; 
  233.          User_Data : User_Data_Type) return UTF8_String; 
  234.       --  This kind of functions provide Pango markup with detail information for 
  235.       --  the specified day. Examples for such details are holidays or 
  236.       --  appointments. The function returns null when no information is 
  237.       --  available. 
  238.       --  Since: gtk+ 2.14 
  239.       --  "calendar": a Gtk.Calendar.Gtk_Calendar. 
  240.       --  "year": the year for which details are needed. 
  241.       --  "month": the month for which details are needed. 
  242.       --  "day": the day of Month for which details are needed. 
  243.       --  "user_data": the data passed with Gtk.Calendar.Set_Detail_Func. 
  244.  
  245.       procedure Set_Detail_Func 
  246.          (Calendar : not null access Gtk.Calendar.Gtk_Calendar_Record'Class; 
  247.           Func     : Gtk_Calendar_Detail_Func; 
  248.           Data     : User_Data_Type); 
  249.       --  Installs a function which provides Pango markup with detail 
  250.       --  information for each day. Examples for such details are holidays or 
  251.       --  appointments. That information is shown below each day when 
  252.       --  Gtk.Calendar.Gtk_Calendar:show-details is set. A tooltip containing 
  253.       --  with full detail information is provided, if the entire text should 
  254.       --  not fit into the details area, or if 
  255.       --  Gtk.Calendar.Gtk_Calendar:show-details is not set. 
  256.       --  The size of the details area can be restricted by setting the 
  257.       --  Gtk.Calendar.Gtk_Calendar:detail-width-chars and 
  258.       --  Gtk.Calendar.Gtk_Calendar:detail-height-rows properties. 
  259.       --  Since: gtk+ 2.14 
  260.       --  "func": a function providing details for each day. 
  261.       --  "data": data to pass to Func invokations. 
  262.  
  263.    end Set_Detail_Func_User_Data; 
  264.  
  265.    procedure Unmark_Day 
  266.       (Calendar : not null access Gtk_Calendar_Record; 
  267.        Day      : Guint); 
  268.    --  Removes the visual marker from a particular day. 
  269.    --  "day": the day number to unmark between 1 and 31. 
  270.  
  271.    ---------------- 
  272.    -- Properties -- 
  273.    ---------------- 
  274.    --  The following properties are defined for this widget. See 
  275.    --  Glib.Properties for more information on properties) 
  276.  
  277.    Day_Property : constant Glib.Properties.Property_Int; 
  278.    --  The selected day (as a number between 1 and 31, or 0 to unselect the 
  279.    --  currently selected day). This property gets initially set to the current 
  280.    --  day. 
  281.  
  282.    Detail_Height_Rows_Property : constant Glib.Properties.Property_Int; 
  283.    --  Height of a detail cell, in rows. A value of 0 allows any width. See 
  284.    --  Gtk.Calendar.Set_Detail_Func. 
  285.  
  286.    Detail_Width_Chars_Property : constant Glib.Properties.Property_Int; 
  287.    --  Width of a detail cell, in characters. A value of 0 allows any width. 
  288.    --  See Gtk.Calendar.Set_Detail_Func. 
  289.  
  290.    Month_Property : constant Glib.Properties.Property_Int; 
  291.    --  The selected month (as a number between 0 and 11). This property gets 
  292.    --  initially set to the current month. 
  293.  
  294.    No_Month_Change_Property : constant Glib.Properties.Property_Boolean; 
  295.    --  Determines whether the selected month can be changed. 
  296.  
  297.    Show_Day_Names_Property : constant Glib.Properties.Property_Boolean; 
  298.    --  Determines whether day names are displayed. 
  299.  
  300.    Show_Details_Property : constant Glib.Properties.Property_Boolean; 
  301.    --  Determines whether details are shown directly in the widget, or if they 
  302.    --  are available only as tooltip. When this property is set days with 
  303.    --  details are marked. 
  304.  
  305.    Show_Heading_Property : constant Glib.Properties.Property_Boolean; 
  306.    --  Determines whether a heading is displayed. 
  307.  
  308.    Show_Week_Numbers_Property : constant Glib.Properties.Property_Boolean; 
  309.    --  Determines whether week numbers are displayed. 
  310.  
  311.    Year_Property : constant Glib.Properties.Property_Int; 
  312.    --  The selected year. This property gets initially set to the current 
  313.    --  year. 
  314.  
  315.    ------------- 
  316.    -- Signals -- 
  317.    ------------- 
  318.  
  319.    type Cb_Gtk_Calendar_Void is not null access procedure (Self : access Gtk_Calendar_Record'Class); 
  320.  
  321.    type Cb_GObject_Void is not null access procedure 
  322.      (Self : access Glib.Object.GObject_Record'Class); 
  323.  
  324.    Signal_Day_Selected : constant Glib.Signal_Name := "day-selected"; 
  325.    procedure On_Day_Selected 
  326.       (Self  : not null access Gtk_Calendar_Record; 
  327.        Call  : Cb_Gtk_Calendar_Void; 
  328.        After : Boolean := False); 
  329.    procedure On_Day_Selected 
  330.       (Self  : not null access Gtk_Calendar_Record; 
  331.        Call  : Cb_GObject_Void; 
  332.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  333.        After : Boolean := False); 
  334.    --  Emitted when the user selects a day. 
  335.  
  336.    Signal_Day_Selected_Double_Click : constant Glib.Signal_Name := "day-selected-double-click"; 
  337.    procedure On_Day_Selected_Double_Click 
  338.       (Self  : not null access Gtk_Calendar_Record; 
  339.        Call  : Cb_Gtk_Calendar_Void; 
  340.        After : Boolean := False); 
  341.    procedure On_Day_Selected_Double_Click 
  342.       (Self  : not null access Gtk_Calendar_Record; 
  343.        Call  : Cb_GObject_Void; 
  344.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  345.        After : Boolean := False); 
  346.    --  Emitted when the user double-clicks a day. 
  347.  
  348.    Signal_Month_Changed : constant Glib.Signal_Name := "month-changed"; 
  349.    procedure On_Month_Changed 
  350.       (Self  : not null access Gtk_Calendar_Record; 
  351.        Call  : Cb_Gtk_Calendar_Void; 
  352.        After : Boolean := False); 
  353.    procedure On_Month_Changed 
  354.       (Self  : not null access Gtk_Calendar_Record; 
  355.        Call  : Cb_GObject_Void; 
  356.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  357.        After : Boolean := False); 
  358.    --  Emitted when the user clicks a button to change the selected month on a 
  359.    --  calendar. 
  360.  
  361.    Signal_Next_Month : constant Glib.Signal_Name := "next-month"; 
  362.    procedure On_Next_Month 
  363.       (Self  : not null access Gtk_Calendar_Record; 
  364.        Call  : Cb_Gtk_Calendar_Void; 
  365.        After : Boolean := False); 
  366.    procedure On_Next_Month 
  367.       (Self  : not null access Gtk_Calendar_Record; 
  368.        Call  : Cb_GObject_Void; 
  369.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  370.        After : Boolean := False); 
  371.    --  Emitted when the user switched to the next month. 
  372.  
  373.    Signal_Next_Year : constant Glib.Signal_Name := "next-year"; 
  374.    procedure On_Next_Year 
  375.       (Self  : not null access Gtk_Calendar_Record; 
  376.        Call  : Cb_Gtk_Calendar_Void; 
  377.        After : Boolean := False); 
  378.    procedure On_Next_Year 
  379.       (Self  : not null access Gtk_Calendar_Record; 
  380.        Call  : Cb_GObject_Void; 
  381.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  382.        After : Boolean := False); 
  383.    --  Emitted when user switched to the next year. 
  384.  
  385.    Signal_Prev_Month : constant Glib.Signal_Name := "prev-month"; 
  386.    procedure On_Prev_Month 
  387.       (Self  : not null access Gtk_Calendar_Record; 
  388.        Call  : Cb_Gtk_Calendar_Void; 
  389.        After : Boolean := False); 
  390.    procedure On_Prev_Month 
  391.       (Self  : not null access Gtk_Calendar_Record; 
  392.        Call  : Cb_GObject_Void; 
  393.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  394.        After : Boolean := False); 
  395.    --  Emitted when the user switched to the previous month. 
  396.  
  397.    Signal_Prev_Year : constant Glib.Signal_Name := "prev-year"; 
  398.    procedure On_Prev_Year 
  399.       (Self  : not null access Gtk_Calendar_Record; 
  400.        Call  : Cb_Gtk_Calendar_Void; 
  401.        After : Boolean := False); 
  402.    procedure On_Prev_Year 
  403.       (Self  : not null access Gtk_Calendar_Record; 
  404.        Call  : Cb_GObject_Void; 
  405.        Slot  : not null access Glib.Object.GObject_Record'Class; 
  406.        After : Boolean := False); 
  407.    --  Emitted when user switched to the previous year. 
  408.  
  409.    ---------------- 
  410.    -- Interfaces -- 
  411.    ---------------- 
  412.    --  This class implements several interfaces. See Glib.Types 
  413.    -- 
  414.    --  - "Buildable" 
  415.  
  416.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  417.      (Gtk.Buildable.Gtk_Buildable, Gtk_Calendar_Record, Gtk_Calendar); 
  418.    function "+" 
  419.      (Widget : access Gtk_Calendar_Record'Class) 
  420.    return Gtk.Buildable.Gtk_Buildable 
  421.    renames Implements_Gtk_Buildable.To_Interface; 
  422.    function "-" 
  423.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  424.    return Gtk_Calendar 
  425.    renames Implements_Gtk_Buildable.To_Object; 
  426.  
  427. private 
  428.    Year_Property : constant Glib.Properties.Property_Int := 
  429.      Glib.Properties.Build ("year"); 
  430.    Show_Week_Numbers_Property : constant Glib.Properties.Property_Boolean := 
  431.      Glib.Properties.Build ("show-week-numbers"); 
  432.    Show_Heading_Property : constant Glib.Properties.Property_Boolean := 
  433.      Glib.Properties.Build ("show-heading"); 
  434.    Show_Details_Property : constant Glib.Properties.Property_Boolean := 
  435.      Glib.Properties.Build ("show-details"); 
  436.    Show_Day_Names_Property : constant Glib.Properties.Property_Boolean := 
  437.      Glib.Properties.Build ("show-day-names"); 
  438.    No_Month_Change_Property : constant Glib.Properties.Property_Boolean := 
  439.      Glib.Properties.Build ("no-month-change"); 
  440.    Month_Property : constant Glib.Properties.Property_Int := 
  441.      Glib.Properties.Build ("month"); 
  442.    Detail_Width_Chars_Property : constant Glib.Properties.Property_Int := 
  443.      Glib.Properties.Build ("detail-width-chars"); 
  444.    Detail_Height_Rows_Property : constant Glib.Properties.Property_Int := 
  445.      Glib.Properties.Build ("detail-height-rows"); 
  446.    Day_Property : constant Glib.Properties.Property_Int := 
  447.      Glib.Properties.Build ("day"); 
  448. end Gtk.Calendar;