-
Notifications
You must be signed in to change notification settings - Fork 17
/
combobox.m
61 lines (50 loc) · 2.19 KB
/
combobox.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
#import "combobox.h"
#include "_cgo_export.h"
@implementation ComboBoxHandler
-(void) comboBoxSelectionDidChange:(id) sender
{
onSelectionDidChange([self goComboBoxID]);
}
@end
ComboBoxPtr ComboBox_New(int goComboBoxID, int x, int y, int w, int h) {
id nsComboBox = [[[NSComboBox alloc] initWithFrame:NSMakeRect(x, y, w, h)] autorelease];
ComboBoxHandler* handler = [[ComboBoxHandler alloc] init];
[handler setGoComboBoxID:goComboBoxID];
[handler autorelease];
[nsComboBox setDelegate:handler];
[nsComboBox setTarget:handler];
[nsComboBox setAction:@selector(comboBoxSelectionDidChange:)];
return (ComboBoxPtr)nsComboBox;
}
void ComboBox_AddItem(ComboBoxPtr comboBoxPtr, const char* item) {
NSComboBox* comboBox = (NSComboBox*)comboBoxPtr;
[comboBox addItemWithObjectValue:[NSString stringWithUTF8String:item]];
}
void ComboBox_SetEditable(ComboBoxPtr comboBoxPtr, int editable) {
NSComboBox* comboBox = (NSComboBox*)comboBoxPtr;
[comboBox setEditable:editable];
}
int ComboBox_SelectedIndex(ComboBoxPtr comboBoxPtr) {
NSComboBox* comboBox = (NSComboBox*)comboBoxPtr;
return (int)[comboBox indexOfSelectedItem];
}
const char* ComboBox_SelectedText(ComboBoxPtr comboBoxPtr) {
NSComboBox* comboBox = (NSComboBox*)comboBoxPtr;
return [[comboBox itemObjectValueAtIndex:[comboBox indexOfSelectedItem]] cStringUsingEncoding:NSISOLatin1StringEncoding];
}
void ComboBox_SetSelectedIndex(ComboBoxPtr comboBoxPtr, int selectedIndex) {
NSComboBox* comboBox = (NSComboBox*)comboBoxPtr;
[comboBox selectItemAtIndex:selectedIndex];
}
void ComboBox_SetSelectedText(ComboBoxPtr comboBoxPtr, const char* selectedText) {
NSComboBox* comboBox = (NSComboBox*)comboBoxPtr;
[comboBox selectItemWithObjectValue:[NSString stringWithUTF8String:selectedText]];
}
void ComboBox_SetStringValue(ComboBoxPtr comboBoxPtr, const char* stringValue) {
NSComboBox* comboBox = (NSComboBox*)comboBoxPtr;
[comboBox setStringValue:[NSString stringWithUTF8String:stringValue]];
}
const char* ComboBox_StringValue(ComboBoxPtr comboBoxPtr) {
NSComboBox* comboBox = (NSComboBox*)comboBoxPtr;
return [[comboBox stringValue] cStringUsingEncoding:NSISOLatin1StringEncoding];
}