-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTTextField.extern.c
63 lines (58 loc) · 2.46 KB
/
CTTextField.extern.c
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
#include "CTTextField.extern.h"
#import <Cocoa/Cocoa.h>
// --------- TextField ----------------------------------------------
Int initTextField_CTTextField(World w, Int dummy) {
__block NSTextField *cocoaTextField;
dispatch_sync(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
cocoaTextField = [[NSTextField alloc] initWithFrame: NSMakeRect(0.0, 0.0, 120.0, 20.0)];
[cocoaTextField setBezelStyle:NSRoundedBezelStyle];
[cocoaTextField setStringValue: @"defaultTextFieldString"];
[pool drain];
});
return (Int)cocoaTextField;
}
TUP0 textFieldSetText_CTTextField(Int cocoaRef, LIST str, Int dummy) {
char* buf = listToChars(str);
dispatch_async(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTextField *thisTextField = (NSTextField*) cocoaRef;
[thisTextField setStringValue: [NSString stringWithFormat:@"%s", buf]];
[thisTextField setNeedsDisplay];
[pool drain];
free(buf);
});
}
TUP0 textFieldSetPosition_CTTextField(Int cocoaRef, Position_CocoaDef pos, Int dummy) {
int x = pos->x_CocoaDef;
int y = pos->y_CocoaDef;
dispatch_async(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTextField *thisTextField = (NSTextField*) cocoaRef;
NSPoint p = NSMakePoint(x,y);
[thisTextField setFrameOrigin: p];
[thisTextField setNeedsDisplay];
[pool drain];
});
}
Size_CocoaDef textFieldSetSize_CTTextField(Int cocoaRef, Size_CocoaDef size, Int dummy) {
int width = size->width_CocoaDef;
__block Size_CocoaDef newSize;
dispatch_sync(dispatch_get_main_queue(), ^{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTextField *thisField = (NSTextField*) cocoaRef;
NSRect rr = [thisField frame];
NSSize newS = NSMakeSize(width, rr.size.height);
[thisField setFrameSize: newS];
rr = [thisField frame];
NEW (Size_CocoaDef, newSize, WORDS(sizeof(struct Size_CocoaDef)));
newSize->GCINFO = __GC__Size_CocoaDef;
newSize->width_CocoaDef = rr.size.width -13; // compensate for x-borders
newSize->height_CocoaDef = rr.size.height -11; // compensate for y-borders
[pool drain];
});
return newSize;
}
void _init_external_CTTextField(void) {
// Do nothing
}