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