forked from mojbro/gocoa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
datepicker.m
63 lines (49 loc) · 2.58 KB
/
datepicker.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
#import "textfield.h"
#include "_cgo_export.h"
@implementation DatePickerHandler
@end
DatePickerPtr DatePicker_New(int goDatePickerId, int x, int y, int w, int h) {
id nsDatePicker = [[[NSDatePicker alloc] initWithFrame:NSMakeRect(x, y, w, h)] autorelease];
return (DatePickerPtr)nsDatePicker;
}
void DatePicker_SetStyle(DatePickerPtr datePickerPtr, int style) {
NSDatePicker* datePicker = (NSDatePicker*)datePickerPtr;
[datePicker setDatePickerStyle:style];
}
void DatePicker_SetMode(DatePickerPtr datePickerPtr, int mode) {
NSDatePicker* datePicker = (NSDatePicker*)datePickerPtr;
[datePicker setDatePickerMode:mode];
}
void DatePicker_SetDate(DatePickerPtr datePickerPtr, const char* date, const char* dateFormat) {
NSDatePicker* datePicker = (NSDatePicker*)datePickerPtr;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = [NSString stringWithUTF8String:dateFormat];
NSDate *formattedDate = [dateFormatter dateFromString: [NSString stringWithUTF8String:date]];
[datePicker setDateValue:formattedDate];
}
void DatePicker_SetMinimumDate(DatePickerPtr datePickerPtr, const char* date, const char* dateFormat) {
NSDatePicker* datePicker = (NSDatePicker*)datePickerPtr;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = [NSString stringWithUTF8String:dateFormat];
NSDate *formattedDate = [dateFormatter dateFromString: [NSString stringWithUTF8String:date]];
[datePicker setMinDate:formattedDate];
}
void DatePicker_SetMaximumDate(DatePickerPtr datePickerPtr, const char* date, const char* dateFormat) {
NSDatePicker* datePicker = (NSDatePicker*)datePickerPtr;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = [NSString stringWithUTF8String:dateFormat];
NSDate *formattedDate = [dateFormatter dateFromString: [NSString stringWithUTF8String:date]];
[datePicker setMaxDate:formattedDate];
}
const char* DatePicker_Date(DatePickerPtr datePickerPtr, const char* dateFormat) {
NSDatePicker* datePicker = (NSDatePicker*)datePickerPtr;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = [NSString stringWithUTF8String:dateFormat];
NSDate *selectedDate = datePicker.dateValue;
NSString *stringFromDate = [dateFormatter stringFromDate:selectedDate];
return [stringFromDate cStringUsingEncoding:NSASCIIStringEncoding];
}
void DatePicker_Remove(DatePickerPtr datePickerPtr) {
NSDatePicker* datePicker = (NSDatePicker*)datePickerPtr;
[datePicker removeFromSuperview];
}