-
Notifications
You must be signed in to change notification settings - Fork 0
/
MHPopUpButton.j
59 lines (48 loc) · 1.27 KB
/
MHPopUpButton.j
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
@import <AppKit/CPControl.j>
@implementation MHPopUpButton : CPControl
{
DOMElement _DOMSelectElement;
}
- (id)initWithFrame:(CPRect)aFrame
{
if (self = [super initWithFrame:aFrame])
{
//#if PLATFORM(DOM)
_DOMSelectElement = document.createElement("select");
_DOMSelectElement.style.position = "absolute";
_DOMSelectElement.style.left = "0px";
_DOMSelectElement.style.top = "0px";
_DOMElement.appendChild(_DOMSelectElement);
//#endif
}
return self;
}
- (void)removeAllItems
{
var numberOfItems=_DOMSelectElement.options.length;
for (var i=0; i<numberOfItems; i++)
{
_DOMSelectElement.options.remove(_DOMSelectElement.options[0]);
}
}
- (void)addItemsWithTitles:(CPArray)titles
{
for (var i=0; i<[titles count]; i++)
{
var DOMoption = document.createElement("option");
DOMoption.innerHTML = titles[i];
_DOMSelectElement.options.add(DOMoption);
}
}
- (void)selectItemAtIndex:(int)anIndex
{
if (_DOMSelectElement.options.selectedIndex == anIndex)
return;
_DOMSelectElement.options.selectedIndex=anIndex;
[self sendAction:[self action] to:[self target]];
}
- (int)indexOfSelectedItem
{
return _DOMSelectElement.options.selectedIndex;
}
@end