-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPWeekViewController.mm
More file actions
144 lines (112 loc) · 2.98 KB
/
Copy pathCPWeekViewController.mm
File metadata and controls
144 lines (112 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//#define TESTING
#import "common.h"
#import "defines.h"
#import "classes.h"
#import "CPSelectionItem.h"
#import "CPDaysSelectionItem.h"
#import "CPWeekViewController.h"
NSString *wkSet1[] =
{
@"Every Day",
@"Weekdays",
@"Clear All"
};
NSString *wkSet2[] =
{
@"Monday",
@"Tuesday",
@"Wednesday",
@"Thursday",
@"Friday",
@"Saturday",
@"Sunday"
};
@implementation CPWeekViewController
- (void) loadView
{
[super loadView];
[self setTitle: RPLOC(@"Days")];
}
- (void) dealloc
{
[selection release];
[super dealloc];
}
- (NSArray*) tableItems
{
SRPINIT();
if(_tableItems==nil)
{
CPSelectionItem* item0 = [CPSelectionItem new];
{
[item0 setDelegate: self];
NSArray* vals = [NSArray arrayWithObjects:
SRPLOC(wkSet1[0]),
SRPLOC(wkSet1[1]),
SRPLOC(wkSet1[2]),
nil];
NSArray* keys = [NSArray arrayWithObjects:
[NSNumber numberWithInt: 0x7f],
[NSNumber numberWithInt: 0x1f],
[NSNumber numberWithInt: 0x0],
nil];
[item0 setIdentifier: @"weekdays"];
[item0 setKeys: keys vals: vals selection: selection];
[item0 autorelease];
}
CPDaysSelectionItem* item1 = [CPDaysSelectionItem new];
{
[item1 setDelegate: self];
uint dayoffs = ((uint)([[NSCalendar currentCalendar] firstWeekday])+5);
NSArray* vals = [NSArray arrayWithObjects:
SRPLOC(wkSet2[(0+dayoffs)%7]),
SRPLOC(wkSet2[(1+dayoffs)%7]),
SRPLOC(wkSet2[(2+dayoffs)%7]),
SRPLOC(wkSet2[(3+dayoffs)%7]),
SRPLOC(wkSet2[(4+dayoffs)%7]),
SRPLOC(wkSet2[(5+dayoffs)%7]),
SRPLOC(wkSet2[(6+dayoffs)%7]),
nil];
NSArray* keys = [NSArray arrayWithObjects:
[NSNumber numberWithInt: 1<<((0+dayoffs)%7)],
[NSNumber numberWithInt: 1<<((1+dayoffs)%7)],
[NSNumber numberWithInt: 1<<((2+dayoffs)%7)],
[NSNumber numberWithInt: 1<<((3+dayoffs)%7)],
[NSNumber numberWithInt: 1<<((4+dayoffs)%7)],
[NSNumber numberWithInt: 1<<((5+dayoffs)%7)],
[NSNumber numberWithInt: 1<<((6+dayoffs)%7)],
nil];
[item1 setIdentifier: @"weekdays"];
[item1 setKeys: keys vals: vals selection: selection];
[item1 autorelease];
}
_tableItems = [[NSArray alloc] initWithObjects:
item0, item1,
nil];
}
return _tableItems;
}
- (void) setSelection: (NSNumber*) newSelection
{
[selection release];
selection = [newSelection retain];
}
- (void) updateSelection
{
CPSelectionItem* item0 = (CPSelectionItem*)[[self tableItems] objectAtIndex: 0];
CPSelectionItem* item1 = (CPSelectionItem*)[[self tableItems] objectAtIndex: 1];
[item0 setSelection: selection];
[item1 setSelection: selection];
[_table reloadData];
}
- (void) setSelection: (NSObject*) newSelection forIdentifier: (NSString*) identifier
{
[self setSelection: (NSNumber*) newSelection];
if(itemDelegate)
{
[itemDelegate setSelection: (NSObject*) newSelection forIdentifier: (NSString*) identifier];
}
[self updateSelection];
[_table reloadData];
}
@end