summaryrefslogtreecommitdiff
path: root/new/darwin/entry.m
blob: 84835f36909489a12ac52f9a741026f2a8f840ee (plain)
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
67
68
69
70
71
72
73
// 9 april 2015
#import "uipriv_darwin.h"

@interface uiNSTextField : NSTextField
@property uiEntry *uiE;
@end

@implementation uiNSTextField

- (void)viewDidMoveToSuperview
{
	if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiE), [self superview])) {
		[self setTarget:nil];
		self.uiE = NULL;
	}
	[super viewDidMoveToSuperview];
}

@end

static char *entryText(uiEntry *e)
{
	uiNSTextField *t;

	t = (uiNSTextField *) uiControlHandle(uiControl(e));
	return uiDarwinNSStringToText([t stringValue]);
}

static void entrySetText(uiEntry *e, const char *text)
{
	uiNSTextField *t;

	t = (uiNSTextField *) uiControlHandle(uiControl(e));
	[t setStringValue:toNSString(text)];
}

// TOOD move elsewhere
// these are based on interface builder defaults; my comments in the old code weren't very good so I don't really know what talked about what, sorry :/
void finishNewTextField(NSTextField *t, BOOL isEntry)
{
	setStandardControlFont((id) t);

	// THE ORDER OF THESE CALLS IS IMPORTANT; CHANGE IT AND THE BORDERS WILL DISAPPEAR
	[t setBordered:NO];
	[t setBezelStyle:NSTextFieldSquareBezel];
	[t setBezeled:isEntry];

	// we don't need to worry about substitutions/autocorrect here; see window_darwin.m for details

	[[t cell] setLineBreakMode:NSLineBreakByClipping];
	[[t cell] setScrollable:YES];
}

uiEntry *uiNewEntry(void)
{
	uiEntry *e;
	uiNSTextField *t;

	e = uiNew(uiEntry);

	uiDarwinNewControl(uiControl(e), [uiNSTextField class], NO, NO);
	t = (uiNSTextField *) uiControlHandle(c);

	[t setSelectable:YES];		// otherwise the setting is masked by the editable default of YES
	finishNewTextField((NSTextField *) t, YES);

	uiEntry(e)->Text = entryText;
	uiEntry(e)->SetText = entrySetText;

	t.uiE = e;

	return t.uiE;
}