From 74f0cb891a356ab5f1a1d173c48b2b670901f504 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 18 Jul 2008 02:06:31 +0000 Subject: [PATCH] Monotone-Parent: 993d2c6913677d2f4479038c7c4a266d4eb3b349 Monotone-Revision: 1cb11e2a0ddee5233e1b78a70804a88e78a13ca1 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2008-07-18T02:06:31 Monotone-Branch: ca.inverse.sogo --- UI/Scheduler/UIxCalMonthView.h | 10 +- UI/Scheduler/UIxCalMonthView.m | 113 ++++++++----------- UI/Templates/SchedulerUI/UIxCalMonthView.wox | 4 +- 3 files changed, 54 insertions(+), 73 deletions(-) diff --git a/UI/Scheduler/UIxCalMonthView.h b/UI/Scheduler/UIxCalMonthView.h index 830c17cac..0d89356fc 100644 --- a/UI/Scheduler/UIxCalMonthView.h +++ b/UI/Scheduler/UIxCalMonthView.h @@ -40,10 +40,9 @@ SOGoAptFormatter *monthAptFormatter; SOGoDateFormatter *dateFormatter; - NSMutableDictionary *sortedAppointments; - NSArray *daysToDisplay; NSCalendarDate *currentTableDay; - NSArray *currentTableColumn; + NSMutableArray *weeksToDisplay; + NSArray *currentWeek; NSArray *dayNames; NSArray *monthNames; @@ -60,11 +59,14 @@ - (NSString *) monthNameOfNextMonth; - (NSString *) monthNameOfTheMonthAfterNextMonth; -- (NSArray *) daysToDisplay; +- (NSArray *) weeksToDisplay; - (NSString *) labelForCurrentDayToDisplay; - (NSString *) dayCellClasses; +- (void) setCurrentWeek: (NSArray *) newCurrentWeek; +- (NSArray *) currentWeek; + - (void) setCurrentTableDay: (NSCalendarDate *) newCurrentTableDay; - (NSCalendarDate *) currentTableDay; - (NSString *) labelForCurrentDayCell; diff --git a/UI/Scheduler/UIxCalMonthView.m b/UI/Scheduler/UIxCalMonthView.m index 127db7e74..bcfb7d10d 100644 --- a/UI/Scheduler/UIxCalMonthView.m +++ b/UI/Scheduler/UIxCalMonthView.m @@ -50,26 +50,21 @@ [dayNames retain]; monthNames = [locale objectForKey: NSMonthNameArray]; [monthNames retain]; - sortedAppointments = [NSMutableDictionary new]; - daysToDisplay = nil; + weeksToDisplay = nil; + currentTableDay = nil; + currentWeek = nil; } return self; } -// - (SOGoAptFormatter *) monthAptFormatter -// { -// return monthAptFormatter; -// } - - (void) dealloc { [monthNames release]; [dayNames release]; - [daysToDisplay release]; -// [monthAptFormatter release]; -// [dateFormatter release]; - [sortedAppointments release]; + [weeksToDisplay release]; + [currentTableDay release]; + [currentWeek release]; [super dealloc]; } @@ -77,45 +72,52 @@ { NSMutableArray *headerDaysToDisplay; unsigned int counter; + NSCalendarDate *currentDate; headerDaysToDisplay = [NSMutableArray arrayWithCapacity: 7]; - currentTableDay = [[self selectedDate] mondayOfWeek]; + currentDate = [[self selectedDate] mondayOfWeek]; for (counter = 0; counter < 7; counter++) { - [headerDaysToDisplay addObject: currentTableDay]; - currentTableDay = [currentTableDay tomorrow]; + [headerDaysToDisplay addObject: currentDate]; + currentDate = [currentDate tomorrow]; } return headerDaysToDisplay; } -- (NSArray *) daysToDisplay +- (NSArray *) weeksToDisplay { - NSMutableArray *days[7]; - unsigned int counter; - NSCalendarDate *firstOfAllDays, *lastDayOfMonth; + NSMutableArray *week; + unsigned int counter, day; + NSCalendarDate *currentDate, *selectedDate, *lastDayOfMonth, *firstOfAllDays; + unsigned int firstToLast, weeks; - if (!daysToDisplay) + if (!weeksToDisplay) { - firstOfAllDays = [[[self selectedDate] firstDayOfMonth] mondayOfWeek]; - lastDayOfMonth = [[self selectedDate] lastDayOfMonth]; - for (counter = 0; counter < 7; counter++) - { - days[counter] = [NSMutableArray new]; - [days[counter] autorelease]; - } - currentTableDay = firstOfAllDays; - while ([currentTableDay earlierDate: lastDayOfMonth] == currentTableDay) - for (counter = 0; counter < 7; counter++) - { - [days[counter] addObject: currentTableDay]; - currentTableDay = [currentTableDay tomorrow]; - } - daysToDisplay = [NSArray arrayWithObjects: days count: 7]; - [daysToDisplay retain]; + selectedDate = [self selectedDate]; + firstOfAllDays = [[selectedDate firstDayOfMonth] mondayOfWeek]; + lastDayOfMonth = [selectedDate lastDayOfMonth]; + firstToLast = ([lastDayOfMonth timeIntervalSinceDate: firstOfAllDays] + / 86400); + weeks = firstToLast / 7; + if ((firstToLast % 7)) + weeks++; + weeksToDisplay = [NSMutableArray arrayWithCapacity: weeks]; + currentDate = firstOfAllDays; + for (counter = 0; counter < weeks; counter++) + { + week = [NSMutableArray arrayWithCapacity: 7]; + for (day = 0; day < 7; day++) + { + [week addObject: currentDate]; + currentDate = [currentDate tomorrow]; + } + [weeksToDisplay addObject: week]; + } + [weeksToDisplay retain]; } - return daysToDisplay; + return weeksToDisplay; } - (NSString *) labelForCurrentDayToDisplay @@ -190,7 +192,7 @@ /* template accessors */ - (void) setCurrentTableDay: (NSCalendarDate *) newCurrentTableDay { - currentTableDay = newCurrentTableDay; + ASSIGN (currentTableDay, newCurrentTableDay); } - (NSCalendarDate *) currentTableDay @@ -198,14 +200,14 @@ return currentTableDay; } -- (void) setCurrentTableColumn: (NSArray *) newCurrentTableColumn +- (void) setCurrentWeek: (NSArray *) newCurrentWeek { - currentTableColumn = newCurrentTableColumn; + ASSIGN (currentWeek, newCurrentWeek); } -- (NSArray *) currentTableColumn +- (NSArray *) currentWeek { - return currentTableColumn; + return currentWeek; } - (NSString *) labelForCurrentDayCell @@ -261,15 +263,14 @@ NSCalendarDate *selectedDate; int dayOfWeek, numberOfWeeks; - classes = [NSMutableString new]; - [classes autorelease]; + classes = [NSMutableString string]; dayOfWeek = [currentTableDay dayOfWeek]; - numberOfWeeks = [currentTableColumn count]; + numberOfWeeks = [weeksToDisplay count]; [classes appendFormat: @"day weekOf%d week%dof%d day%d", numberOfWeeks, - [currentTableColumn indexOfObject: currentTableDay], + [weeksToDisplay indexOfObject: currentWeek], numberOfWeeks, dayOfWeek]; if (dayOfWeek == 0 || dayOfWeek == 6) [classes appendString: @" weekEndDay"]; @@ -285,23 +286,6 @@ return classes; } -- (NSArray *) _rangeOf7DaysForWeekStartingOn: (NSCalendarDate *) weekStart -{ - unsigned int count; - NSMutableArray *range; - NSCalendarDate *currentDate; - - range = [NSMutableArray arrayWithCapacity: 7]; - currentDate = weekStart; - for (count = 0; count < 7; count++) - { - [range addObject: currentDate]; - currentDate = [currentDate dateByAddingYears: 0 months: 0 days: 1]; - } - - return range; -} - - (NSCalendarDate *) startDate { NSCalendarDate *firstDayOfMonth; @@ -320,9 +304,4 @@ return [[lastDayOfMonth mondayOfWeek] dateByAddingYears: 0 months: 0 days: 6]; } -- (NSArray *) aptsForCurrentDate -{ - return [sortedAppointments objectForKey: [currentTableDay shortDateString]]; -} - @end diff --git a/UI/Templates/SchedulerUI/UIxCalMonthView.wox b/UI/Templates/SchedulerUI/UIxCalMonthView.wox index f15c35425..c89f03b51 100644 --- a/UI/Templates/SchedulerUI/UIxCalMonthView.wox +++ b/UI/Templates/SchedulerUI/UIxCalMonthView.wox @@ -47,8 +47,8 @@ >