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-2011, 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. -- -- -- -- -- -- -- -- -- -- -- --
  23. ----------------------------------------------------------------------- 
  24.  
  25. --  <description> 
  26. --  Gtk_Calendar is a widget that displays a calendar, one month at a time. It 
  27. --  can be created with Gtk_New. 
  28. -- 
  29. --  The month and year currently displayed can be altered with Select_Month. 
  30. --  The exact day can be selected from the displayed month using Select_Day. 
  31. -- 
  32. --  The way in which the calendar itself is displayed can be altered using 
  33. --  Display_Options. 
  34. -- 
  35. --  The selected date can be retrieved from a Gtk_Calendar using Get_Date. 
  36. -- 
  37. --  If performing many 'mark' operations, the calendar can be frozen to 
  38. --  prevent flicker, using Freeze, and 'thawed' again using Thaw. 
  39. -- 
  40. --  </description> 
  41. --  <screenshot>gtk-calendar</screenshot> 
  42. --  <group>Selectors</group> 
  43. --  <testgtk>create_calendar.adb</testgtk> 
  44.  
  45. pragma Warnings (Off, "*is already use-visible*"); 
  46. with Glib;            use Glib; 
  47. with Glib.Properties; use Glib.Properties; 
  48. with Glib.Types;      use Glib.Types; 
  49. with Gtk.Buildable;   use Gtk.Buildable; 
  50. with Gtk.Widget;      use Gtk.Widget; 
  51.  
  52. package Gtk.Calendar is 
  53.  
  54.    type Gtk_Calendar_Record is new Gtk_Widget_Record with null record; 
  55.    type Gtk_Calendar is access all Gtk_Calendar_Record'Class; 
  56.  
  57.    type Gtk_Calendar_Display_Options is mod 2 ** 8; 
  58.  
  59.    Show_Heading : constant Gtk_Calendar_Display_Options := 2 ** 0; 
  60.    --  Specify that the month and year should be displayed. 
  61.  
  62.    Show_Day_Names : constant Gtk_Calendar_Display_Options := 2 ** 1; 
  63.    --  Specify that three letter day descriptions should be present. 
  64.  
  65.    No_Month_Change : constant Gtk_Calendar_Display_Options := 2 ** 2; 
  66.    --  Prevent the user from switching months with the calendar. 
  67.  
  68.    Show_Week_Numbers : constant Gtk_Calendar_Display_Options := 2 ** 3; 
  69.    --  Display each week numbers of the current year, down the left side of 
  70.    --  the calendar. 
  71.  
  72.    Week_Start_Monday : constant Gtk_Calendar_Display_Options := 2 ** 4; 
  73.    --  Start the calendar week on Monday, instead of the default Sunday. 
  74.  
  75.    type Gtk_Calendar_Detail_Func is access function 
  76.      (Calendar  : access Gtk_Calendar_Record'Class; 
  77.       Year      : Guint; 
  78.       Month     : Guint; 
  79.       Day       : Guint; 
  80.       User_Data : System.Address) return String; 
  81.    --  Return the details for the given day, or the empty string when there 
  82.    --  are no details. 
  83.  
  84.    ------------------ 
  85.    -- Constructors -- 
  86.    ------------------ 
  87.  
  88.    procedure Gtk_New (Calendar : out Gtk_Calendar); 
  89.    procedure Initialize (Calendar : access Gtk_Calendar_Record'Class); 
  90.    --  Creates a new calendar, with the current date being selected. 
  91.  
  92.    function Get_Type return Glib.GType; 
  93.    pragma Import (C, Get_Type, "gtk_calendar_get_type"); 
  94.  
  95.    ------------- 
  96.    -- Methods -- 
  97.    ------------- 
  98.  
  99.    procedure Clear_Marks (Calendar : access Gtk_Calendar_Record); 
  100.    --  Remove all visual markers. 
  101.  
  102.    procedure Display_Options 
  103.       (Calendar : access Gtk_Calendar_Record; 
  104.        Flags    : Gtk_Calendar_Display_Options); 
  105.    pragma Obsolescent (Display_Options); 
  106.    function Get_Display_Options 
  107.       (Calendar : access Gtk_Calendar_Record) 
  108.        return Gtk_Calendar_Display_Options; 
  109.    procedure Set_Display_Options 
  110.       (Calendar : access Gtk_Calendar_Record; 
  111.        Flags    : Gtk_Calendar_Display_Options); 
  112.    --  Sets display options (whether to display the heading and the month 
  113.    --  headings). 
  114.    --  Since: gtk+ 2.4 
  115.    --  "flags": the display options to set 
  116.  
  117.    procedure Freeze (Calendar : access Gtk_Calendar_Record); 
  118.    pragma Obsolescent (Freeze); 
  119.    --  Does nothing. Previously locked the display of the calendar until it 
  120.    --  was thawed with Gtk.Calendar.Thaw. 
  121.    --  Deprecated 
  122.  
  123.    procedure Get_Date 
  124.       (Calendar : access Gtk_Calendar_Record; 
  125.        Year     : out Guint; 
  126.        Month    : out Guint; 
  127.        Day      : out Guint); 
  128.    --  Obtains the selected date from a Gtk.Calendar.Gtk_Calendar. 
  129.    --  "year": location to store the year as a decimal number (e.g. 2011), or 
  130.    --  null 
  131.    --  "month": location to store the month number (between 0 and 11), or null 
  132.    --  "day": location to store the day number (between 1 and 31), or null 
  133.  
  134.    function Get_Detail_Height_Rows 
  135.       (Calendar : access Gtk_Calendar_Record) return Gint; 
  136.    procedure Set_Detail_Height_Rows 
  137.       (Calendar : access Gtk_Calendar_Record; 
  138.        Rows     : Gint); 
  139.    --  Updates the height of detail cells. See 
  140.    --  Gtk.Calendar.Gtk_Calendar:detail-height-rows. 
  141.    --  Since: gtk+ 2.14 
  142.    --  "rows": detail height in rows. 
  143.  
  144.    function Get_Detail_Width_Chars 
  145.       (Calendar : access Gtk_Calendar_Record) return Gint; 
  146.    procedure Set_Detail_Width_Chars 
  147.       (Calendar : access Gtk_Calendar_Record; 
  148.        Chars    : Gint); 
  149.    --  Updates the width of detail cells. See 
  150.    --  Gtk.Calendar.Gtk_Calendar:detail-width-chars. 
  151.    --  Since: gtk+ 2.14 
  152.    --  "chars": detail width in characters. 
  153.  
  154.    function Mark_Day 
  155.       (Calendar : access Gtk_Calendar_Record; 
  156.        Day      : Guint) return Boolean; 
  157.    --  Places a visual marker on a particular day. Note that this function 
  158.    --  always returns True, and you should ignore the return value. In GTK+ 3, 
  159.    --  this function will not return a value. 
  160.    --  Returns True, always 
  161.    --  "day": the day number to mark between 1 and 31. 
  162.  
  163.    procedure Select_Day (Calendar : access Gtk_Calendar_Record; Day : Guint); 
  164.    --  Selects a day from the current month. 
  165.    --  "day": the day number between 1 and 31, or 0 to unselect the currently 
  166.    --  selected day. 
  167.  
  168.    function Select_Month 
  169.       (Calendar : access Gtk_Calendar_Record; 
  170.        Month    : Guint; 
  171.        Year     : Guint) return Boolean; 
  172.    --  Shifts the calendar to a different month. Note that this function 
  173.    --  always returns True, and you should ignore the return value. In GTK+ 3, 
  174.    --  this function will not return a value. 
  175.    --  Returns True, always 
  176.    --  "month": a month number between 0 and 11. 
  177.    --  "year": the year the month is in. 
  178.  
  179.    procedure Set_Detail_Func 
  180.       (Calendar : access Gtk_Calendar_Record; 
  181.        Func     : Gtk_Calendar_Detail_Func; 
  182.        Data     : System.Address; 
  183.        Destroy  : Glib.G_Destroy_Notify_Address); 
  184.    --  Installs a function which provides Pango markup with detail information 
  185.    --  for each day. Examples for such details are holidays or appointments. 
  186.    --  That information is shown below each day when 
  187.    --  Gtk.Calendar.Gtk_Calendar:show-details is set. A tooltip containing with 
  188.    --  full detail information is provided, if the entire text should not fit 
  189.    --  into the details area, or if Gtk.Calendar.Gtk_Calendar:show-details is 
  190.    --  not set. The size of the details area can be restricted by setting the 
  191.    --  Gtk.Calendar.Gtk_Calendar:detail-width-chars and 
  192.    --  Gtk.Calendar.Gtk_Calendar:detail-height-rows properties. 
  193.    --  Since: gtk+ 2.14 
  194.    --  "func": a function providing details for each day. 
  195.    --  "data": data to pass to Func invokations. 
  196.    --  "destroy": a function for releasing Data. 
  197.  
  198.    procedure Thaw (Calendar : access Gtk_Calendar_Record); 
  199.    pragma Obsolescent (Thaw); 
  200.    --  Does nothing. Previously defrosted a calendar; all the changes made 
  201.    --  since the last Gtk.Calendar.Freeze were displayed. 
  202.    --  Deprecated 
  203.  
  204.    function Unmark_Day 
  205.       (Calendar : access Gtk_Calendar_Record; 
  206.        Day      : Guint) return Boolean; 
  207.    --  Removes the visual marker from a particular day. Note that this 
  208.    --  function always returns True, and you should ignore the return value. In 
  209.    --  GTK+ 3, this function will not return a value. 
  210.    --  Returns True, always 
  211.    --  "day": the day number to unmark between 1 and 31. 
  212.  
  213.    ---------------- 
  214.    -- Interfaces -- 
  215.    ---------------- 
  216.    --  This class implements several interfaces. See Glib.Types 
  217.    -- 
  218.    --  - "Buildable" 
  219.  
  220.    package Implements_Buildable is new Glib.Types.Implements 
  221.      (Gtk.Buildable.Gtk_Buildable, Gtk_Calendar_Record, Gtk_Calendar); 
  222.    function "+" 
  223.      (Widget : access Gtk_Calendar_Record'Class) 
  224.    return Gtk.Buildable.Gtk_Buildable 
  225.    renames Implements_Buildable.To_Interface; 
  226.    function "-" 
  227.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  228.    return Gtk_Calendar 
  229.    renames Implements_Buildable.To_Object; 
  230.  
  231.    ---------------- 
  232.    -- Properties -- 
  233.    ---------------- 
  234.    --  The following properties are defined for this widget. See 
  235.    --  Glib.Properties for more information on properties) 
  236.    -- 
  237.    --  Name: Day_Property 
  238.    --  Type: Gint 
  239.    --  Flags: read-write 
  240.    --  The selected day (as a number between 1 and 31, or 0 to unselect the 
  241.    --  currently selected day). This property gets initially set to the current 
  242.    --  day. 
  243.    -- 
  244.    --  Name: Detail_Height_Rows_Property 
  245.    --  Type: Gint 
  246.    --  Flags: read-write 
  247.    --  Height of a detail cell, in rows. A value of 0 allows any width. See 
  248.    --  Gtk.Calendar.Set_Detail_Func. 
  249.    -- 
  250.    --  Name: Detail_Width_Chars_Property 
  251.    --  Type: Gint 
  252.    --  Flags: read-write 
  253.    --  Width of a detail cell, in characters. A value of 0 allows any width. 
  254.    --  See Gtk.Calendar.Set_Detail_Func. 
  255.    -- 
  256.    --  Name: Month_Property 
  257.    --  Type: Gint 
  258.    --  Flags: read-write 
  259.    --  The selected month (as a number between 0 and 11). This property gets 
  260.    --  initially set to the current month. 
  261.    -- 
  262.    --  Name: No_Month_Change_Property 
  263.    --  Type: Boolean 
  264.    --  Flags: read-write 
  265.    --  Determines whether the selected month can be changed. 
  266.    -- 
  267.    --  Name: Show_Day_Names_Property 
  268.    --  Type: Boolean 
  269.    --  Flags: read-write 
  270.    --  Determines whether day names are displayed. 
  271.    -- 
  272.    --  Name: Show_Details_Property 
  273.    --  Type: Boolean 
  274.    --  Flags: read-write 
  275.    --  Determines whether details are shown directly in the widget, or if they 
  276.    --  are available only as tooltip. When this property is set days with 
  277.    --  details are marked. 
  278.    -- 
  279.    --  Name: Show_Heading_Property 
  280.    --  Type: Boolean 
  281.    --  Flags: read-write 
  282.    --  Determines whether a heading is displayed. 
  283.    -- 
  284.    --  Name: Show_Week_Numbers_Property 
  285.    --  Type: Boolean 
  286.    --  Flags: read-write 
  287.    --  Determines whether week numbers are displayed. 
  288.    -- 
  289.    --  Name: Year_Property 
  290.    --  Type: Gint 
  291.    --  Flags: read-write 
  292.    --  The selected year. This property gets initially set to the current 
  293.    --  year. 
  294.  
  295.    Day_Property : constant Glib.Properties.Property_Int; 
  296.    Detail_Height_Rows_Property : constant Glib.Properties.Property_Int; 
  297.    Detail_Width_Chars_Property : constant Glib.Properties.Property_Int; 
  298.    Month_Property : constant Glib.Properties.Property_Int; 
  299.    No_Month_Change_Property : constant Glib.Properties.Property_Boolean; 
  300.    Show_Day_Names_Property : constant Glib.Properties.Property_Boolean; 
  301.    Show_Details_Property : constant Glib.Properties.Property_Boolean; 
  302.    Show_Heading_Property : constant Glib.Properties.Property_Boolean; 
  303.    Show_Week_Numbers_Property : constant Glib.Properties.Property_Boolean; 
  304.    Year_Property : constant Glib.Properties.Property_Int; 
  305.  
  306.    ------------- 
  307.    -- Signals -- 
  308.    ------------- 
  309.    --  The following new signals are defined for this widget: 
  310.    -- 
  311.    --  "day-selected" 
  312.    --     procedure Handler (Self : access Gtk_Calendar_Record'Class); 
  313.    -- 
  314.    --  "day-selected-double-click" 
  315.    --     procedure Handler (Self : access Gtk_Calendar_Record'Class); 
  316.    -- 
  317.    --  "month-changed" 
  318.    --     procedure Handler (Self : access Gtk_Calendar_Record'Class); 
  319.    --  Emitted when the user clicks a button to change the selected month on a 
  320.    --  calendar. 
  321.    -- 
  322.    --  "next-month" 
  323.    --     procedure Handler (Self : access Gtk_Calendar_Record'Class); 
  324.    -- 
  325.    --  "next-year" 
  326.    --     procedure Handler (Self : access Gtk_Calendar_Record'Class); 
  327.    -- 
  328.    --  "prev-month" 
  329.    --     procedure Handler (Self : access Gtk_Calendar_Record'Class); 
  330.    -- 
  331.    --  "prev-year" 
  332.    --     procedure Handler (Self : access Gtk_Calendar_Record'Class); 
  333.  
  334.    Signal_Day_Selected : constant Glib.Signal_Name := "day-selected"; 
  335.    Signal_Day_Selected_Double_Click : constant Glib.Signal_Name := "day-selected-double-click"; 
  336.    Signal_Month_Changed : constant Glib.Signal_Name := "month-changed"; 
  337.    Signal_Next_Month : constant Glib.Signal_Name := "next-month"; 
  338.    Signal_Next_Year : constant Glib.Signal_Name := "next-year"; 
  339.    Signal_Prev_Month : constant Glib.Signal_Name := "prev-month"; 
  340.    Signal_Prev_Year : constant Glib.Signal_Name := "prev-year"; 
  341.  
  342. private 
  343.    Day_Property : constant Glib.Properties.Property_Int := 
  344.      Glib.Properties.Build ("day"); 
  345.    Detail_Height_Rows_Property : constant Glib.Properties.Property_Int := 
  346.      Glib.Properties.Build ("detail-height-rows"); 
  347.    Detail_Width_Chars_Property : constant Glib.Properties.Property_Int := 
  348.      Glib.Properties.Build ("detail-width-chars"); 
  349.    Month_Property : constant Glib.Properties.Property_Int := 
  350.      Glib.Properties.Build ("month"); 
  351.    No_Month_Change_Property : constant Glib.Properties.Property_Boolean := 
  352.      Glib.Properties.Build ("no-month-change"); 
  353.    Show_Day_Names_Property : constant Glib.Properties.Property_Boolean := 
  354.      Glib.Properties.Build ("show-day-names"); 
  355.    Show_Details_Property : constant Glib.Properties.Property_Boolean := 
  356.      Glib.Properties.Build ("show-details"); 
  357.    Show_Heading_Property : constant Glib.Properties.Property_Boolean := 
  358.      Glib.Properties.Build ("show-heading"); 
  359.    Show_Week_Numbers_Property : constant Glib.Properties.Property_Boolean := 
  360.      Glib.Properties.Build ("show-week-numbers"); 
  361.    Year_Property : constant Glib.Properties.Property_Int := 
  362.      Glib.Properties.Build ("year"); 
  363. end Gtk.Calendar;