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-2009, 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. 
  27. --  It 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 prevent 
  38. --  flicker, using Freeze, and 'thawed' again using Thaw. 
  39. --  </description> 
  40. --  <c_version>2.14</c_version> 
  41. --  <group>Selectors</group> 
  42. --  <testgtk>create_calendar.adb</testgtk> 
  43. --  <screenshot>gtk-calendar</screenshot> 
  44.  
  45. with Glib.Properties; 
  46. with Gtk.Widget; 
  47.  
  48. package Gtk.Calendar is 
  49.  
  50.    type Gtk_Calendar_Display_Options is mod 2 ** 8; 
  51.  
  52.    Show_Heading : constant Gtk_Calendar_Display_Options; 
  53.    --  Specify that the month and year should be displayed. 
  54.  
  55.    Show_Day_Names : constant Gtk_Calendar_Display_Options; 
  56.    --  Specify that three letter day descriptions should be present. 
  57.  
  58.    No_Month_Change : constant Gtk_Calendar_Display_Options; 
  59.    --  Prevent the user from switching months with the calendar. 
  60.  
  61.    Show_Week_Numbers : constant Gtk_Calendar_Display_Options; 
  62.    --  Display each week numbers of the current year, down the left side of 
  63.    --  the calendar. 
  64.  
  65.    Week_Start_Monday : constant Gtk_Calendar_Display_Options; 
  66.    --  Start the calendar week on Monday, instead of the default Sunday. 
  67.  
  68.    type Gtk_Calendar_Record is new Gtk.Widget.Gtk_Widget_Record with private; 
  69.    type Gtk_Calendar is access all Gtk_Calendar_Record'Class; 
  70.  
  71.    procedure Gtk_New (Widget : out Gtk_Calendar); 
  72.    --  Create a new Calendar that points to the current date. 
  73.  
  74.    procedure Initialize (Widget : access Gtk_Calendar_Record'Class); 
  75.    --  Internal initialization function. 
  76.    --  See the section "Creating your own widgets" in the documentation. 
  77.  
  78.    function Get_Type return Gtk.Gtk_Type; 
  79.    --  Return the internal value associated with a Gtk_Calendar. 
  80.  
  81.    function Select_Month 
  82.      (Calendar : access Gtk_Calendar_Record; 
  83.       Month    : Guint; 
  84.       Year     : Guint) return Boolean; 
  85.    --  Shift the calendar to a different month/year. 
  86.    --  Return True if sucessful. 
  87.  
  88.    procedure Select_Day 
  89.      (Calendar : access Gtk_Calendar_Record; 
  90.       Day      : Guint); 
  91.    --  Select a day from the current month. 
  92.    --  Only one day can be selected at a time. 
  93.  
  94.    function Mark_Day 
  95.      (Calendar : access Gtk_Calendar_Record; 
  96.       Day      : Guint) return Boolean; 
  97.    --  Set a specified Day as marked in the Calendar. 
  98.    --  This is shown visually as a painted box around the Day. 
  99.    --  Note that several days can be marked. 
  100.    --  Return True if successful. 
  101.  
  102.    function Unmark_Day 
  103.      (Calendar : access Gtk_Calendar_Record; 
  104.       Day      : Guint) return Boolean; 
  105.    --  Undo the marking of Day. 
  106.    --  Return True if sucessful. 
  107.  
  108.    procedure Clear_Marks (Calendar : access Gtk_Calendar_Record); 
  109.    --  Clear all the marks set by Mark_Day. 
  110.  
  111.    procedure Get_Date 
  112.      (Calendar : access Gtk_Calendar_Record; 
  113.       Year     : out Guint; 
  114.       Month    : out Guint; 
  115.       Day      : out Guint); 
  116.    --  Return the date currently selected. 
  117.  
  118.    procedure Set_Display_Options 
  119.      (Calendar : access Gtk_Calendar_Record; 
  120.       Flags    : Gtk_Calendar_Display_Options); 
  121.    function Get_Display_Options 
  122.      (Calendar : access Gtk_Calendar_Record) 
  123.       return Gtk_Calendar_Display_Options; 
  124.    --  Sets display options (whether to display the heading and the month 
  125.    --  headings). 
  126.  
  127.    function Get_Detail_Height_Rows 
  128.      (Calendar : access Gtk_Calendar_Record) 
  129.       return Gint; 
  130.    procedure Set_Detail_Height_Rows 
  131.      (Calendar : access Gtk_Calendar_Record; 
  132.       Rows     : Gint); 
  133.    --  Queries the height of detail cells, in rows. 
  134.    --  Since: 2.14 
  135.  
  136.    function Get_Detail_Width_Chars 
  137.      (Calendar : access Gtk_Calendar_Record) 
  138.       return Gint; 
  139.    procedure Set_Detail_Width_Chars 
  140.      (Calendar : access Gtk_Calendar_Record; 
  141.       Chars    : Gint); 
  142.    --  Queries the width of detail cells, in characters. 
  143.    --  Since: 2.14 
  144.  
  145.    ------------- 
  146.    -- Details -- 
  147.    ------------- 
  148.  
  149.    type Gtk_Calendar_Detail_Func is access function 
  150.       (Calendar  : access Gtk_Calendar_Record'Class; 
  151.        Year      : Guint; 
  152.        Month     : Guint; 
  153.        Day       : Guint; 
  154.        User_Data : System.Address) return String; 
  155.    --  Return the details for the given day, or the empty string when there 
  156.    --  are no details. 
  157.  
  158.    procedure Set_Detail_Func 
  159.      (Calendar : access Gtk_Calendar_Record; 
  160.       Func     : Gtk_Calendar_Detail_Func; 
  161.       Data     : System.Address; 
  162.       Destroy  : G_Destroy_Notify_Address); 
  163.    --  Installs a function which provides Pango markup with detail information 
  164.    --  for each day. Examples for such details are holidays or appointments. 
  165.    --  That information is shown below each day when the property 
  166.    --  "show-details" is set. 
  167.    --  A tooltip containing with full detail information is provided, if the 
  168.    --  entire text should not fit into the details area, or if show-details 
  169.    --  is not set. 
  170.    -- 
  171.    --  The size of the details area can be restricted by setting the 
  172.    --  "detail-width-chars" and "detail-height-rows" properties. 
  173.    -- 
  174.    --  Since: 2.14 
  175.  
  176.    ----------------- 
  177.    -- Obsolescent -- 
  178.    ----------------- 
  179.    --  All subprograms below are now obsolescent in gtk+. They might be removed 
  180.    --  from future versions of gtk+ (and therefore GtkAda). 
  181.    --  To find out whether your code uses any of these, we recommend compiling 
  182.    --  with the -gnatwj switch 
  183.    --  <doc_ignore> 
  184.  
  185.    procedure Display_Options 
  186.      (Calendar : access Gtk_Calendar_Record; 
  187.       Flags    : Gtk_Calendar_Display_Options); 
  188.    pragma Obsolescent;  --  Display_Options 
  189.    --  Change the display options. 
  190.    --  See individual Display_Option flags for more details. 
  191.  
  192.    procedure Freeze (Calendar : access Gtk_Calendar_Record); 
  193.    pragma Obsolescent;  --  Freeze 
  194.    --  Lock the display of the calendar until it is thawed. 
  195.  
  196.    procedure Thaw (Calendar : access Gtk_Calendar_Record); 
  197.    pragma Obsolescent;  --  Thaw 
  198.    --  Defrost a calendar. 
  199.    --  All the changes made since the last Freeze are displayed. 
  200.  
  201.    --  </doc_ignore> 
  202.  
  203.    ---------------- 
  204.    -- Properties -- 
  205.    ---------------- 
  206.  
  207.    --  <properties> 
  208.    --  The following properties are defined for this widget. See 
  209.    --  Glib.Properties for more information on properties. 
  210.    -- 
  211.    --  Name:  Day_Property 
  212.    --  Type:  Int 
  213.    --  Descr: The selected day (as a number between 1 and 31, or 0 to unselect 
  214.    --         the currently selected day) 
  215.    -- 
  216.    --  Name:  Detail_Height_Rows_Property 
  217.    --  Type:  Int 
  218.    --  Descr: Details height in rows 
  219.    -- 
  220.    --  Name:  Detail_Width_Chars_Property 
  221.    --  Type:  Int 
  222.    --  Descr: Details width in characters 
  223.    -- 
  224.    --  Name:  Month_Property 
  225.    --  Type:  Int 
  226.    --  Descr: The selected month (as a number between 0 and 11) 
  227.    -- 
  228.    --  Name:  No_Month_Change_Property 
  229.    --  Type:  Boolean 
  230.    --  Descr: If TRUE, the selected month cannot be changed 
  231.    -- 
  232.    --  Name:  Show_Day_Names_Property 
  233.    --  Type:  Boolean 
  234.    --  Descr: If TRUE, day names are displayed 
  235.    -- 
  236.    --  Name:  Show_Details_Property 
  237.    --  Type:  Boolean 
  238.    --  Descr: If TRUE, details are shown 
  239.    -- 
  240.    --  Name:  Show_Heading_Property 
  241.    --  Type:  Boolean 
  242.    --  Descr: If TRUE, a heading is displayed 
  243.    -- 
  244.    --  Name:  Show_Week_Numbers_Property 
  245.    --  Type:  Boolean 
  246.    --  Descr: If TRUE, week numbers are displayed 
  247.    -- 
  248.    --  Name:  Year_Property 
  249.    --  Type:  Int 
  250.    --  Descr: The selected year 
  251.    -- 
  252.    --  </properties> 
  253.  
  254.    Day_Property               : constant Glib.Properties.Property_Int; 
  255.    Detail_Height_Rows_Property : constant Glib.Properties.Property_Int; 
  256.    Detail_Width_Chars_Property : constant Glib.Properties.Property_Int; 
  257.    Month_Property             : constant Glib.Properties.Property_Int; 
  258.    No_Month_Change_Property   : constant Glib.Properties.Property_Boolean; 
  259.    Show_Day_Names_Property    : constant Glib.Properties.Property_Boolean; 
  260.    Show_Details_Property      : constant Glib.Properties.Property_Boolean; 
  261.    Show_Heading_Property      : constant Glib.Properties.Property_Boolean; 
  262.    Show_Week_Numbers_Property : constant Glib.Properties.Property_Boolean; 
  263.    Year_Property              : constant Glib.Properties.Property_Int; 
  264.  
  265.    ------------- 
  266.    -- Signals -- 
  267.    ------------- 
  268.  
  269.    --  <signals> 
  270.    --  The following new signals are defined for this widget: 
  271.    --  - "month_changed" 
  272.    --    procedure Handler (Calendar : access Gtk_Calendar_Record'Class); 
  273.    --    Emitted when the user clicks a button to change the selected month on 
  274.    --    calendar. 
  275.    -- 
  276.    --  - "day_selected" 
  277.    --    procedure Handler (Calendar : access Gtk_Calendar_Record'Class); 
  278.    --    Emitted when the user selects a day on a calendar. 
  279.    -- 
  280.    --  - "day_selected_double_click" 
  281.    --    procedure Handler (Calendar : access Gtk_Calendar_Record'Class); 
  282.    --    Emitted when the user double clicks a day on a calendar. 
  283.    -- 
  284.    --  - "prev_month" 
  285.    --    procedure Handler (Calendar : access Gtk_Calendar_Record'Class); 
  286.    --    Emitted when the user selects the previous month on a calendar. 
  287.    -- 
  288.    --  - "next_month" 
  289.    --    procedure Handler (Calendar : access Gtk_Calendar_Record'Class); 
  290.    --    Emitted when the user selects the next month on a calendar. 
  291.    -- 
  292.    --  - "prev_year" 
  293.    --    procedure Handler (Calendar : access Gtk_Calendar_Record'Class); 
  294.    --    Emitted when the user selects the previous year on a calendar. 
  295.    -- 
  296.    --  - "next_year" 
  297.    --    procedure Handler (Calendar : access Gtk_Calendar_Record'Class); 
  298.    --    Emitted when the user selects the next year on a calendar. 
  299.    -- 
  300.    --  </signals> 
  301.  
  302.    Signal_Day_Selected              : constant Glib.Signal_Name := 
  303.                                         "day_selected"; 
  304.    Signal_Day_Selected_Double_Click : constant Glib.Signal_Name := 
  305.                                         "day_selected_double_click"; 
  306.    Signal_Month_Changed             : constant Glib.Signal_Name := 
  307.                                         "month_changed"; 
  308.    Signal_Next_Month                : constant Glib.Signal_Name := 
  309.                                         "next_month"; 
  310.    Signal_Next_Year                 : constant Glib.Signal_Name := 
  311.                                         "next_year"; 
  312.    Signal_Prev_Month                : constant Glib.Signal_Name := 
  313.                                         "prev_month"; 
  314.    Signal_Prev_Year                 : constant Glib.Signal_Name := 
  315.                                         "prev_year"; 
  316.  
  317. private 
  318.    type Gtk_Calendar_Record is new Gtk.Widget.Gtk_Widget_Record 
  319.       with null record; 
  320.  
  321.    Day_Property : constant Glib.Properties.Property_Int := 
  322.      Glib.Properties.Build ("day"); 
  323.    Detail_Height_Rows_Property : constant Glib.Properties.Property_Int := 
  324.      Glib.Properties.Build ("detail-height-rows"); 
  325.    Detail_Width_Chars_Property : constant Glib.Properties.Property_Int := 
  326.      Glib.Properties.Build ("detail-width-chars"); 
  327.    Month_Property : constant Glib.Properties.Property_Int := 
  328.      Glib.Properties.Build ("month"); 
  329.    No_Month_Change_Property : constant Glib.Properties.Property_Boolean := 
  330.      Glib.Properties.Build ("no-month-change"); 
  331.    Show_Day_Names_Property : constant Glib.Properties.Property_Boolean := 
  332.      Glib.Properties.Build ("show-day-names"); 
  333.    Show_Details_Property : constant Glib.Properties.Property_Boolean := 
  334.      Glib.Properties.Build ("show-details"); 
  335.    Show_Heading_Property : constant Glib.Properties.Property_Boolean := 
  336.      Glib.Properties.Build ("show-heading"); 
  337.    Show_Week_Numbers_Property : constant Glib.Properties.Property_Boolean := 
  338.      Glib.Properties.Build ("show-week-numbers"); 
  339.    Year_Property : constant Glib.Properties.Property_Int := 
  340.      Glib.Properties.Build ("year"); 
  341.  
  342.    pragma Import (C, Get_Type, "gtk_calendar_get_type"); 
  343.  
  344.    Show_Heading      : constant Gtk_Calendar_Display_Options := 2 ** 0; 
  345.    Show_Day_Names    : constant Gtk_Calendar_Display_Options := 2 ** 1; 
  346.    No_Month_Change   : constant Gtk_Calendar_Display_Options := 2 ** 2; 
  347.    Show_Week_Numbers : constant Gtk_Calendar_Display_Options := 2 ** 3; 
  348.    Week_Start_Monday : constant Gtk_Calendar_Display_Options := 2 ** 4; 
  349.  
  350. end Gtk.Calendar;