-
Notifications
You must be signed in to change notification settings - Fork 3
/
DropDownList.m
executable file
·238 lines (200 loc) · 5.99 KB
/
DropDownList.m
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//
// DropDownList.m
// DropDownList1
//
// Created by Nick Marchenko on 30.09.10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "DropDownList.h"
#import "TransparentOverlay+Private.h"
#import "BaseItemObject.h"
#import "Configuration.h"
@implementation DropDownList
@synthesize button;
@synthesize theTransparentOverlay;
@synthesize name;
@synthesize type;
@synthesize buttonInstructionLabelFrame;
@synthesize activeImage;
@synthesize inActiveImage;
@synthesize objects;
@synthesize cellDispAmount;
@synthesize delegate;
@synthesize parentViewController;
- (void) setCellBGImage:(UIImage *) _cellBGImage setCellBGHoverImage:(UIImage *) _cellBGHoverImage;
{
[cellBGImage release];
cellBGImage=[_cellBGImage retain];
[cellBGHoverImage release];
cellBGHoverImage=[_cellBGHoverImage retain];
}
- (void) setTopMainBG:(UIImage *) _topMainBG setMiddleBG:(UIImage *) _middleMainBG setBottom:(UIImage *) _bottomMainBG
{
[topMainBG release];
topMainBG=[_topMainBG retain];
[middleMainBG release];
middleMainBG=[_middleMainBG retain];
[bottomMainBG release];
bottomMainBG=[_bottomMainBG retain];
}
- (void) setBGXMargin:(CGFloat) x BGYMargin:(CGFloat) y BGUnderTableHeight:(CGFloat) h
{
xBGMargin = x;
yBGMargin = y;
bgUnderTableHeight = h;
}
-(void)setObjects:(NSMutableArray *) objs
{
if (objs) {
objects = objs;
[objs retain];
}
}
- (void) setTableXMargin:(CGFloat) x TableYMargin:(CGFloat) y
{
tableXMargin = x;
tableYMargin = y;
}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
}
return self;
}
- (id) initWithOrigin:(CGPoint)_origin
ActiveImage:(UIImage*)_activeImage
WithInactiveImage:(UIImage*)_inactiveImage
{
self.activeImage=_activeImage;
self.inActiveImage=_inactiveImage;
CGRect frame=CGRectMake(_origin.x, _origin.y, _activeImage.size.width, _activeImage.size.height);
if (self=[super initWithFrame:frame])
{
button=[[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, inActiveImage.size.width, inActiveImage.size.height)];
[button setBackgroundImage:inActiveImage forState:UIControlStateNormal];
[button setUserInteractionEnabled:NO];
[button addTarget:self action:@selector(showDropDownList:) forControlEvents:UIControlEventTouchDown];
[self addSubview:button];
// Assign default value
previouslySelectedCell=-1;
}
return self;
}
- (void) closeDropDownList
{
[theTransparentOverlay closeOpenDropdownList];
}
- (void) showDropDownList: (id) sender
{
if (theTransparentOverlay == nil)
{
theTransparentOverlay=[[TransparentOverlay alloc] initWithButtonOrigin:self.frame.origin];
theTransparentOverlay.type = type;
theTransparentOverlay.tableXMargin = tableXMargin;
theTransparentOverlay.tableYMargin = tableYMargin;
theTransparentOverlay.topMainBG=topMainBG;
theTransparentOverlay.middleMainBG=middleMainBG;
theTransparentOverlay.bottomMainBG=bottomMainBG;
theTransparentOverlay.xBGMargin = xBGMargin;
theTransparentOverlay.yBGMargin = yBGMargin;
theTransparentOverlay.bgUnderTableHeight = bgUnderTableHeight;
theTransparentOverlay.cellBGImage=cellBGImage;
theTransparentOverlay.cellBGHoverImage=cellBGHoverImage;
theTransparentOverlay.cellDispAmount=cellDispAmount;
theTransparentOverlay.delegate=self;
}
// Paste doObjects
theTransparentOverlay.objects = objects;
[parentViewController.view addSubview:theTransparentOverlay];
theTransparentOverlay.previouslySelectedCell=previouslySelectedCell;
[theTransparentOverlay showOpenDropDownList];
// Set delegate method dropDownListDidShow
[delegate dropDownListDidShown:self];
}
- (void) setUserInteractionEnabled:(BOOL)_value
{
[button setUserInteractionEnabled:_value];
for (UIView *v in [button subviews])
if ([v tag]==1)
[v removeFromSuperview];
UILabel *buttonLabel=[[UILabel alloc] initWithFrame:buttonInstructionLabelFrame];
if (_value)
{
[button setBackgroundImage:activeImage forState:UIControlStateNormal];
[button setBackgroundImage:activeImage forState:UIControlStateHighlighted];
[buttonLabel setTextColor:BUTTON_LABEL_ACTIVE_COLOR];
// Assign default value
previouslySelectedCell=-1;
}
else
{
[button setBackgroundImage:inActiveImage forState:UIControlStateNormal];
[buttonLabel setTextColor:BUTTON_LABEL_INACTIVE_COLOR];
// Assign default value
previouslySelectedCell=-1;
}
[buttonLabel setText:name];
buttonLabel.tag=1;
[buttonLabel setFont:BUTTON_LABEL_FONT];
[buttonLabel setBackgroundColor:[UIColor clearColor]];
[button addSubview:buttonLabel];
[buttonLabel release];
}
- (BaseItemObject*) getSelectedCell
{
for (BaseItemObject *cell in objects)
if (cell.isCurrentlySelected)
return cell;
return nil;
}
- (void) clearSelectedCell
{
for (BaseItemObject *cell in objects)
cell.isCurrentlySelected=NO;
}
- (void) updateButtonImage
{
if (previouslySelectedCell != -1)
{
// Remove subview from button
for (UIView *v in [button subviews])
if ([v tag]==1)
[v removeFromSuperview];
// Paste data to button
BaseItemObject *tempBaseItemObject=[objects objectAtIndex:previouslySelectedCell];
[TransparentOverlay _pasteData:tempBaseItemObject To:button WithType:type];
}
}
#pragma mark -
#pragma mark DropDownList table delegate
- (void) cellDidSelected:(int) row
{
// Set the delegate
[delegate dropDownListItemDidSelected:self WithNumber:row];
previouslySelectedCell=row;
// Remove subview from button
for (UIView *v in [button subviews])
if ([v tag]==1)
[v removeFromSuperview];
// Paste data to button
BaseItemObject *tempBaseItemObject=[objects objectAtIndex:row];
[TransparentOverlay _pasteData:tempBaseItemObject To:button WithType:type];
}
#pragma mark -
#pragma mark Memory manegament
- (void)dealloc {
[button release];
[name release];
[type release];
[theTransparentOverlay release];
[activeImage release];
[inActiveImage release];
[cellBGImage release];
[cellBGHoverImage release];
[topMainBG release];
[bottomMainBG release];
[middleMainBG release];
[objects release];
[super dealloc];
}
@end