2015-04-09 01:35:52 -05:00
|
|
|
// 9 april 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
|
|
|
@interface uiNSTextField : NSTextField
|
2015-04-16 13:41:24 -05:00
|
|
|
@property uiEntry *uiE;
|
2015-04-09 01:35:52 -05:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation uiNSTextField
|
|
|
|
|
|
|
|
- (void)viewDidMoveToSuperview
|
|
|
|
{
|
2015-04-16 13:41:24 -05:00
|
|
|
if (uiDarwinControlFreeWhenAppropriate(uiControl(self.uiE), [self superview])) {
|
2015-04-09 01:35:52 -05:00
|
|
|
[self setTarget:nil];
|
2015-04-16 13:41:24 -05:00
|
|
|
self.uiE = NULL;
|
2015-04-09 01:35:52 -05:00
|
|
|
}
|
|
|
|
[super viewDidMoveToSuperview];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-04-16 13:41:24 -05:00
|
|
|
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)];
|
|
|
|
}
|
|
|
|
|
2015-04-09 01:35:52 -05:00
|
|
|
// 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 :/
|
2015-04-09 10:54:02 -05:00
|
|
|
void finishNewTextField(NSTextField *t, BOOL isEntry)
|
2015-04-09 01:35:52 -05:00
|
|
|
{
|
|
|
|
setStandardControlFont((id) t);
|
|
|
|
|
|
|
|
// THE ORDER OF THESE CALLS IS IMPORTANT; CHANGE IT AND THE BORDERS WILL DISAPPEAR
|
|
|
|
[t setBordered:NO];
|
|
|
|
[t setBezelStyle:NSTextFieldSquareBezel];
|
2015-04-09 10:54:02 -05:00
|
|
|
[t setBezeled:isEntry];
|
2015-04-09 01:35:52 -05:00
|
|
|
|
2015-04-10 16:06:59 -05:00
|
|
|
// we don't need to worry about substitutions/autocorrect here; see window_darwin.m for details
|
2015-04-09 01:35:52 -05:00
|
|
|
|
|
|
|
[[t cell] setLineBreakMode:NSLineBreakByClipping];
|
|
|
|
[[t cell] setScrollable:YES];
|
|
|
|
}
|
|
|
|
|
2015-04-16 13:41:24 -05:00
|
|
|
uiEntry *uiNewEntry(void)
|
2015-04-09 01:35:52 -05:00
|
|
|
{
|
2015-04-16 13:41:24 -05:00
|
|
|
uiEntry *e;
|
2015-04-09 01:35:52 -05:00
|
|
|
uiNSTextField *t;
|
|
|
|
|
2015-04-16 13:41:24 -05:00
|
|
|
e = uiNew(uiEntry);
|
|
|
|
|
|
|
|
uiDarwinNewControl(uiControl(e), [uiNSTextField class], NO, NO);
|
2015-04-16 14:08:49 -05:00
|
|
|
t = (uiNSTextField *) uiControlHandle(uiControl(e));
|
2015-04-09 01:35:52 -05:00
|
|
|
|
|
|
|
[t setSelectable:YES]; // otherwise the setting is masked by the editable default of YES
|
|
|
|
finishNewTextField((NSTextField *) t, YES);
|
|
|
|
|
2015-04-16 13:41:24 -05:00
|
|
|
uiEntry(e)->Text = entryText;
|
|
|
|
uiEntry(e)->SetText = entrySetText;
|
2015-04-09 10:54:02 -05:00
|
|
|
|
2015-04-16 13:41:24 -05:00
|
|
|
t.uiE = e;
|
2015-04-09 10:54:02 -05:00
|
|
|
|
2015-04-16 13:41:24 -05:00
|
|
|
return t.uiE;
|
2015-04-09 10:54:02 -05:00
|
|
|
}
|