1
/***************************************************************************
4
* Copyright (C) 2005 Novell
5
* Written by Aaron Bockover (aaron@aaronbock.net)
6
****************************************************************************/
8
/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW:
10
* Permission is hereby granted, free of charge, to any person obtaining a
11
* copy of this software and associated documentation files (the "Software"),
12
* to deal in the Software without restriction, including without limitation
13
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
14
* and/or sell copies of the Software, and to permit persons to whom the
15
* Software is furnished to do so, subject to the following conditions:
17
* The above copyright notice and this permission notice shall be included in
18
* all copies or substantial portions of the Software.
20
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26
* DEALINGS IN THE SOFTWARE.
35
public class DateButton : ToggleButton
38
private DateTime date;
40
private bool show_time;
42
private const uint CURRENT_TIME = 0;
44
// FIXME: If this is ever moved to its own library
45
// this reference to Tomboy will obviously have to
47
public DateButton(DateTime date_time, bool show_time)
48
: base(Tomboy.GuiUtils.GetPrettyPrintDate (date_time, show_time))
53
this.show_time = show_time;
56
private void ShowCalendar()
58
popup = new Window(WindowType.Popup);
59
popup.Screen = this.Screen;
61
Frame frame = new Frame();
62
frame.Shadow = ShadowType.Out;
67
VBox box = new VBox(false, 0);
72
cal.DisplayOptions = CalendarDisplayOptions.ShowHeading
73
| CalendarDisplayOptions.ShowDayNames
74
| CalendarDisplayOptions.ShowWeekNumbers;
76
cal.KeyPressEvent += OnCalendarKeyPressed;
77
popup.ButtonPressEvent += OnButtonPressed;
81
Alignment calAlignment = new Alignment(0.0f, 0.0f, 1.0f, 1.0f);
83
calAlignment.SetPadding(4, 4, 4, 4);
84
calAlignment.Add(cal);
86
box.PackStart(calAlignment, false, false, 0);
88
Requisition req = SizeRequest();
90
GdkWindow.GetOrigin(out x, out y);
91
popup.Move(x + Allocation.X, y + Allocation.Y + req.Height + 3);
97
Gdk.GrabStatus grabbed = Gdk.Pointer.Grab(popup.GdkWindow, true,
98
Gdk.EventMask.ButtonPressMask
99
| Gdk.EventMask.ButtonReleaseMask
100
| Gdk.EventMask.PointerMotionMask, null, null, CURRENT_TIME);
102
if(grabbed == Gdk.GrabStatus.Success) {
103
grabbed = Gdk.Keyboard.Grab(popup.GdkWindow,
106
if(grabbed != Gdk.GrabStatus.Success) {
117
cal.DaySelectedDoubleClick += OnCalendarDaySelected;
118
cal.ButtonPressEvent += OnCalendarButtonPressed;
123
public void HideCalendar(bool update)
127
Gdk.Pointer.Ungrab(CURRENT_TIME);
128
Gdk.Keyboard.Ungrab(CURRENT_TIME);
135
date = cal.GetDate();
136
// FIXME: If this is ever moved to its own library
137
// this reference to Tomboy will obviously have to
139
Label = Tomboy.GuiUtils.GetPrettyPrintDate (date, show_time);
145
private void OnToggled(object o, EventArgs args)
154
private void OnButtonPressed(object o, ButtonPressEventArgs args)
160
private void OnCalendarDaySelected(object o, EventArgs args)
165
private void OnCalendarButtonPressed(object o,
166
ButtonPressEventArgs args)
171
private void OnCalendarKeyPressed(object o, KeyPressEventArgs args)
173
switch(args.Event.Key) {
177
case Gdk.Key.KP_Enter:
178
case Gdk.Key.ISO_Enter:
179
case Gdk.Key.Key_3270_Enter:
182
case Gdk.Key.KP_Space:
195
Label = Tomboy.GuiUtils.GetPrettyPrintDate (date, show_time);
200
/// If true, both the date and time will be shown. If false, the time
205
get { return show_time; }
206
set { show_time = value; }