2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "UIxCalWeekView.h"
26 @interface UIxCalWeekChartview : UIxCalWeekView
33 - (NSCalendarDate *)currentDate;
37 #include <NGExtensions/NGCalendarDateRange.h>
38 #include <sys/param.h> // MIN, MAX
39 #include <SOGoUI/SOGoAptFormatter.h>
41 @implementation UIxCalWeekChartview
44 [self->hours release];
48 - (void)setDay:(int)_day {
53 date = [[self startDate] dateByAddingYears:0 months:0 days:_day];
54 [self setCurrentDay:date];
60 - (void)setHour:(int)_hour {
67 - (NSCalendarDate *)currentDate {
70 date = [[self startDate] beginOfDay];
71 date = [date dateByAddingYears:0 months:0 days:[self day]
72 hours:[self hour] minutes:0 seconds:0];
78 - (NSArray *)columns {
79 static NSMutableArray *columns = nil;
84 count = [self shouldDisplayWeekend] ? 7 : 5;
85 columns = [[NSMutableArray alloc] initWithCapacity:count];
86 for(i = 0; i < count; i++) {
87 [columns addObject:[NSNumber numberWithInt:i]];
95 /* row is active, if apt intersects hour range */
97 NSCalendarDate *aptStart, *aptEnd, *date;
98 int aptStartHour, aptEndHour;
99 BOOL isStartOnSameDay, isEndOnSameDay;
101 aptStart = [self->appointment valueForKey:@"startDate"];
102 aptEnd = [self->appointment valueForKey:@"endDate"];
103 date = [self currentDay];
104 isStartOnSameDay = [aptStart isDateOnSameDay:date];
105 isEndOnSameDay = [aptEnd isDateOnSameDay:date];
107 if (!isStartOnSameDay && !isEndOnSameDay)
109 aptStartHour = [aptStart hourOfDay];
110 aptEndHour = [aptEnd hourOfDay];
111 if (isStartOnSameDay && isEndOnSameDay)
112 return (([self hour] >= aptStartHour) &&
113 ([self hour] <= aptEndHour));
114 if (!isStartOnSameDay)
115 return [self hour] <= aptEndHour;
116 return [self hour] >= aptStartHour;
119 /* item is active, if apt's dateRange intersects the range
120 of the current column (currentDay is set to be this date) */
121 - (BOOL)isItemActive {
122 NSCalendarDate *dateStart, *dateEnd, *aptStart, *aptEnd;
123 NGCalendarDateRange *dateRange, *aptRange;
125 dateStart = [self currentDate];
126 dateEnd = [dateStart dateByAddingYears:0 months:0 days:0
127 hours:1 minutes:0 seconds:0];
128 dateRange = [NGCalendarDateRange calendarDateRangeWithStartDate:dateStart
130 aptStart = [self->appointment valueForKey:@"startDate"];
131 aptEnd = [self->appointment valueForKey:@"endDate"];
132 aptRange = [NGCalendarDateRange calendarDateRangeWithStartDate:aptStart
134 return [dateRange doesIntersectWithDateRange:aptRange];
141 NSMutableArray *result;
146 min = [self dayStartHour];
147 max = [self dayEndHour];
149 apts = [self appointments];
150 count = [apts count];
151 for(i = 0; i < count; i++) {
153 NSCalendarDate *aptStart, *aptEnd;
154 apt = [apts objectAtIndex:i];
155 aptStart = [apt valueForKey:@"startDate"];
157 min = MIN(min, [aptStart hourOfDay]);
159 aptEnd = [apt valueForKey:@"endDate"];
161 max = MAX(max, [aptEnd hourOfDay]);
164 result = [[NSMutableArray alloc] initWithCapacity:max - min];
165 for(i = min; i <= max; i++) {
166 [result addObject:[NSNumber numberWithInt:i]];
168 self->hours = result;
175 - (void)configureFormatters {
176 [super configureFormatters];
177 [self->aptFormatter setTitleOnly];
178 [self->privateAptFormatter setPrivateTitleOnly];
184 - (NSString *)titleStyle {
185 if([self->currentDay isToday])
186 return @"weekoverview_title_hilite";
187 return @"weekoverview_title";
190 @end /* UIxCalWeekChartview */