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