-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathComboBox.m
More file actions
66 lines (54 loc) · 2.07 KB
/
ComboBox.m
File metadata and controls
66 lines (54 loc) · 2.07 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
#include <Cocoa/Cocoa.h>
@interface Window : NSWindow {
NSComboBox* comboBox1;
NSComboBox* comboBox2;
}
- (instancetype)init;
- (BOOL)windowShouldClose:(id)sender;
@end
@implementation Window
- (instancetype)init {
comboBox1 = [[[NSComboBox alloc] initWithFrame:NSMakeRect(10, 260, 121, 26)] autorelease];
[comboBox1 addItemWithObjectValue:@"item1"];
[comboBox1 addItemWithObjectValue:@"item2"];
[comboBox1 addItemWithObjectValue:@"item3"];
[comboBox1 setTarget:self];
[comboBox1 setAction:@selector(OnComboBox1SelectedItemChange)];
//[[comboBox1 delegate] comboBoxSelectionIsChanging: ];
//[comboBox1 setDelegate:self];
[comboBox1 selectItemAtIndex:1];
comboBox2 = [[[NSComboBox alloc] initWithFrame:NSMakeRect(10, 220, 121, 26)] autorelease];
[comboBox2 setEditable:false];
[comboBox2 addItemWithObjectValue:@"item1"];
[comboBox2 addItemWithObjectValue:@"item2"];
[comboBox2 addItemWithObjectValue:@"item3"];
[comboBox2 setTarget:self];
//[comboBox2 setAction:@selector(OnComboBox2SelectedItemChange)];
[comboBox2 selectItemAtIndex:1];
[super initWithContentRect:NSMakeRect(100, 100, 300, 300) styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable backing:NSBackingStoreBuffered defer:NO];
[self setTitle:@"ComboBox Example"];
[[self contentView] addSubview:comboBox1];
[[self contentView] addSubview:comboBox2];
[self setIsVisible:YES];
return self;
}
- (BOOL)windowShouldClose:(id)sender {
[NSApp terminate:sender];
return YES;
}
- (IBAction) OnComboBox1SelectedItemChange:(id)sender {
[comboBox2 selectItemAtIndex:[comboBox1 indexOfSelectedItem]];
}
- (IBAction) OnComboBox2SelectedItemChange:(id)sender {
[comboBox1 selectItemAtIndex:[comboBox2 indexOfSelectedItem]];
}
- (void)OnComboBox1SelectionIsChanging:(NSNotification *)notification {
}
- (void)comboBoxSelectionIsChanging:(NSNotification *)notification {
}
@end
int main(int argc, char* argv[]) {
[NSApplication sharedApplication];
[[[[Window alloc] init] autorelease] makeMainWindow];
[NSApp run];
}