2
// Copyright (C) 2009 GNOME Do
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
using System.Collections.Generic;
20
using System.Globalization;
28
using Docky.Interface;
29
using Docky.Utilities;
31
namespace Docky.Interface.Painters
35
public class CalendarPainter : AbstractIntegratedPainter
37
const int LineHeight = 16;
38
const double lowlight = .35;
39
const string BoldFormatString = "<b>{0}</b>";
41
ClockDockItem Clock { get; set; }
43
DateTime CalendarStartDate {
45
return DateTime.Today.AddDays (0 - (int) DateTime.Today.DayOfWeek +
46
((int) DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek));
50
public CalendarPainter (ClockDockItem clock) : base (clock as AbstractDockItem)
55
#region IDockPainter implementation
57
protected override int Width {
64
protected override void PaintArea (Cairo.Context cr, Gdk.Rectangle paintArea)
66
int height = paintArea.Height / LineHeight;
67
RenderHeader (cr, paintArea);
68
for (int i = 1; i < height; i++)
69
RenderLine (cr, paintArea, i);
72
protected override void ReceiveClick (Gdk.Rectangle paintArea, Gdk.Point cursor)
79
void RenderHeader (Context cr, Gdk.Rectangle paintArea)
81
int centerLine = paintArea.Y + LineHeight / 2 + ((paintArea.Height % LineHeight) / 2);
82
int offsetSize = paintArea.Width / 9;
84
DateTime day = CalendarStartDate;
85
TextRenderContext textContext = new TextRenderContext (cr, string.Empty, offsetSize);
86
textContext.Alignment = Pango.Alignment.Center;
88
cr.Color = new Cairo.Color (1, 1, 1, .5);
89
for (int i = 1; i < 8; i++) {
90
textContext.Text = string.Format (BoldFormatString, day.ToString ("ddd").ToUpper ());
91
textContext.LeftCenteredPoint = new Gdk.Point (paintArea.X + offsetSize * i, centerLine);
92
DockServices.DrawingService.TextPathAtPoint (textContext);
94
day = day.AddDays (1);
98
void RenderLine (Context cr, Gdk.Rectangle paintArea, int line)
100
DateTime lineStart = CalendarStartDate.AddDays ((line - 1) * 7);
101
int offsetSize = paintArea.Width / 9;
102
int centerLine = paintArea.Y + LineHeight / 2 + LineHeight * line + ((paintArea.Height % LineHeight) / 2);
105
TextRenderContext textContext = new TextRenderContext (cr, string.Empty, offsetSize);
106
for (int i = 0; i < 9; i++) {
108
cr.Color = new Cairo.Color (1, 1, 1, lowlight);
109
textContext.Text = string.Format (BoldFormatString, lineStart.AddDays (6).ToString ("MMM").ToUpper ());
110
textContext.Alignment = Pango.Alignment.Left;
112
cr.Color = new Cairo.Color (1, 1, 1, lowlight);
113
int woy = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear (lineStart,
114
DateTimeFormatInfo.CurrentInfo.CalendarWeekRule,
115
DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);
116
textContext.Text = string.Format ("<b>W{0:00}</b>", woy);
117
textContext.Alignment = Pango.Alignment.Right;
119
DateTime day = lineStart.AddDays (dayOffset);
120
textContext.Alignment = Pango.Alignment.Center;
122
if (day.Month == CalendarStartDate.Month)
123
cr.Color = new Cairo.Color (1, 1, 1);
125
cr.Color = new Cairo.Color (1, 1, 1, .8);
127
textContext.Text = string.Format ("{0:00}", day.Day);
128
if (day.Date == DateTime.Today)
129
textContext.Text = string.Format (BoldFormatString, textContext.Text);
132
textContext.LeftCenteredPoint = new Gdk.Point (paintArea.X + offsetSize * i, centerLine);
133
DockServices.DrawingService.TextPathAtPoint (textContext);
139
public void Summon ()
146
OnPaintNeeded (new PaintNeededArgs ());