1 | #import <Foundation/Foundation.h>
|
---|
2 |
|
---|
3 | #import <UIKit/CDStructures.h>
|
---|
4 | #import <UIKit/UINavigationBar.h>
|
---|
5 | #import <UIKit/UIWindow.h>
|
---|
6 | #import <UIKit/UIView-Hierarchy.h>
|
---|
7 | #import <UIKit/UIHardware.h>
|
---|
8 | #import <UIKit/UITable.h>
|
---|
9 | #import <UIKit/UITableCell.h>
|
---|
10 | #import <UIKit/UITableColumn.h>
|
---|
11 |
|
---|
12 | #import "GreenstoneApplication.h"
|
---|
13 | #import "GSResultItem.h"
|
---|
14 |
|
---|
15 | #import "MenuCascadeView.h"
|
---|
16 |
|
---|
17 |
|
---|
18 | // ***** think about coding for orientation of iPod!!!!
|
---|
19 |
|
---|
20 | @implementation MenuCascadeView
|
---|
21 |
|
---|
22 | -(id) init
|
---|
23 | {
|
---|
24 | CGRect rect = [GreenstoneApplication workAreaRect];
|
---|
25 | return [self initWithFrame:rect];
|
---|
26 | }
|
---|
27 |
|
---|
28 | -(id) initWithFrame:(CGRect)rect
|
---|
29 | {
|
---|
30 | return [self initWithFrame:rect withParent:nil withCollection:nil withTitle:nil withGID:nil];
|
---|
31 | }
|
---|
32 |
|
---|
33 | -(id) initWithFrame:(CGRect)rect withTitle:(NSString*)title
|
---|
34 | {
|
---|
35 | return [self initWithFrame:rect withParent:nil withCollection:nil withTitle:title withGID:nil];
|
---|
36 | }
|
---|
37 |
|
---|
38 | -(id) initWithFrame:(CGRect)rect withParent:(UIView*)parent
|
---|
39 | withCollection:(NSString*)collection withTitle:(NSString*)title withGID:(NSString*)gid
|
---|
40 | {
|
---|
41 | self = [super initWithFrame:rect];
|
---|
42 |
|
---|
43 | _parent = parent;
|
---|
44 | _collection = collection;
|
---|
45 | _gid = gid;
|
---|
46 | _childMenu = nil;
|
---|
47 |
|
---|
48 | _tabrow = [[NSMutableArray alloc] initWithCapacity:MCInitCapacity];
|
---|
49 | _oidItem = [[NSMutableArray alloc] initWithCapacity:MCInitCapacity];
|
---|
50 |
|
---|
51 | int frame_x_dim = CGRectGetMaxX(rect)+1;
|
---|
52 | int frame_y_dim = CGRectGetMaxY(rect)+1;
|
---|
53 |
|
---|
54 | int tab_x_org = 0.0f;
|
---|
55 | int tab_y_org = TOP_NAVBAR_HEIGHT;
|
---|
56 | int tab_x_dim = frame_x_dim;
|
---|
57 | int tab_y_dim = frame_y_dim -TOP_NAVBAR_HEIGHT;
|
---|
58 |
|
---|
59 | CGRect tablerect = CGRectMake(tab_x_org,tab_y_org,tab_x_dim,tab_y_dim);
|
---|
60 |
|
---|
61 | _table = [[UITable alloc] initWithFrame:tablerect];
|
---|
62 |
|
---|
63 | UITableColumn *col = [[UITableColumn alloc] initWithTitle: @"MenuCascadeApp"
|
---|
64 | identifier: @"menucascade" width: frame_x_dim];
|
---|
65 |
|
---|
66 | [_table addTableColumn: col];
|
---|
67 | [_table setDataSource: self];
|
---|
68 | [_table setDelegate: self];
|
---|
69 | [_table reloadData];
|
---|
70 |
|
---|
71 | int nav_x_org = 0.0f;
|
---|
72 | int nav_y_org = 0.0f;
|
---|
73 | int nav_x_dim = frame_x_dim;
|
---|
74 | int nav_y_dim = TOP_NAVBAR_HEIGHT;
|
---|
75 |
|
---|
76 | CGRect navrect = CGRectMake(nav_x_org,nav_y_org,nav_x_dim,nav_y_dim);
|
---|
77 | _navbar = [[UINavigationBar alloc] initWithFrame: navrect];
|
---|
78 |
|
---|
79 | NSString* back = (parent) ? @"Back" : nil;
|
---|
80 | [_navbar showButtonsWithLeftTitle:back rightTitle:nil leftBack:YES];
|
---|
81 | [_navbar enableAnimation];
|
---|
82 | [_navbar setBarStyle: 0];
|
---|
83 | [_navbar setDelegate: self];
|
---|
84 |
|
---|
85 | if (title != nil) {
|
---|
86 | [self setTitle:title];
|
---|
87 | }
|
---|
88 |
|
---|
89 | [self addSubview: _navbar];
|
---|
90 | [self addSubview: _table];
|
---|
91 |
|
---|
92 | return self;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | -(void) setTitle: (NSString*)title
|
---|
97 | {
|
---|
98 | UINavigationItem* navtitle = [UINavigationItem alloc];
|
---|
99 | [_navbar pushNavigationItem: [navtitle initWithTitle: title]];
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | -(void) appendMenuItem: (NSObject*) app withItem:(NSString*)itemLabel withGID:(NSString*)childGID
|
---|
104 | {
|
---|
105 | UIImageAndTextTableCell* itcell = [[UIImageAndTextTableCell alloc] init];
|
---|
106 | [itcell setTitle: itemLabel];
|
---|
107 |
|
---|
108 | if ([childGID hasPrefix:@"CL"]==YES) {
|
---|
109 | [itcell setShowDisclosure: YES];
|
---|
110 | [itcell setDisclosureStyle: 2];
|
---|
111 | }
|
---|
112 | else if (_parent == nil) {
|
---|
113 | // Root menu => Make disclosures look a bit different
|
---|
114 | [itcell setShowDisclosure: YES];
|
---|
115 | [itcell setDisclosureStyle: 1];
|
---|
116 | }
|
---|
117 |
|
---|
118 | [_tabrow addObject:itcell];
|
---|
119 | [itcell retain];
|
---|
120 |
|
---|
121 | if (itemLabel == nil) {
|
---|
122 | itemLabel = [[NSString alloc] initWithString:@"Unknown Title"];
|
---|
123 | }
|
---|
124 |
|
---|
125 | GSResultItem* oidItem = [[GSResultItem alloc] initWithOID:childGID withTitle:itemLabel]; // *****
|
---|
126 | [_oidItem addObject:oidItem];
|
---|
127 |
|
---|
128 | // needed to force table view to update
|
---|
129 | [_table reloadData];
|
---|
130 |
|
---|
131 | }
|
---|
132 |
|
---|
133 | // ************
|
---|
134 | // * Delegates
|
---|
135 | // ************
|
---|
136 |
|
---|
137 | - (int) numberOfRowsInTable: (UITable *)table
|
---|
138 | {
|
---|
139 | return [_tabrow count];
|
---|
140 | }
|
---|
141 |
|
---|
142 | - (UITableCell *) table: (UITable *)table cellForRow: (int)row column: (int)col
|
---|
143 | {
|
---|
144 |
|
---|
145 |
|
---|
146 | return [_tabrow objectAtIndex:row];
|
---|
147 | }
|
---|
148 |
|
---|
149 | - (UITableCell *) table: (UITable *)table cellForRow: (int)row column: (int)col
|
---|
150 | reusing: (BOOL) reusing
|
---|
151 | {
|
---|
152 | return [_tabrow objectAtIndex:row];
|
---|
153 | }
|
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|
157 | -(void) navigationBar:(UINavigationBar*)navbar buttonClicked:(int)button
|
---|
158 | {
|
---|
159 | switch (button)
|
---|
160 | {
|
---|
161 | case 1: // left
|
---|
162 | // cerr << "***** Need to set collection to nil if going to top page" << endl; // ****
|
---|
163 | // [GreenstoneApplication setInCollection:_parent._collectcion];
|
---|
164 | [GreenstoneApplication transitionView:UITransitionBothShiftRight
|
---|
165 | fromView:self toView:_parent];
|
---|
166 |
|
---|
167 | if (_childMenu != nil) {
|
---|
168 | [_childMenu release];
|
---|
169 | _childMenu = nil;
|
---|
170 | }
|
---|
171 | break;
|
---|
172 |
|
---|
173 | default:
|
---|
174 | NSLog(@"Unrecognised navbar button = %d",button);
|
---|
175 | break;
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | -(void) dealloc
|
---|
181 | {
|
---|
182 | [_childMenu release];
|
---|
183 |
|
---|
184 | [_gid release]; // **** is this ever used???
|
---|
185 | [_collection release];
|
---|
186 |
|
---|
187 | [_tabrow release];
|
---|
188 | [_oidItem release];
|
---|
189 |
|
---|
190 | [ super dealloc ];
|
---|
191 | }
|
---|
192 |
|
---|
193 | @end
|
---|