2015-04-09 01:35:52 -05:00
|
|
|
// 9 april 2015
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
2015-05-06 19:58:55 -05:00
|
|
|
@interface entryDelegate : NSObject {
|
|
|
|
uiEntry *e;
|
|
|
|
void (*onChanged)(uiEntry *, void *);
|
|
|
|
void *onChangedData;
|
|
|
|
}
|
|
|
|
- (void)controlTextDidChange:(NSNotification *)note;
|
|
|
|
- (void)setEntry:(uiEntry *)e;
|
|
|
|
- (void)setOnChanged:(void (*)(uiEntry *, void *))f data:(void *)data;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation entryDelegate
|
|
|
|
|
|
|
|
- (void)controlTextDidChange:(NSNotification *)note
|
|
|
|
{
|
|
|
|
(*(self->onChanged))(self->e, self->onChangedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setEntry:(uiEntry *)e
|
|
|
|
{
|
|
|
|
self->e = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setOnChanged:(void (*)(uiEntry *, void *))f data:(void *)data
|
|
|
|
{
|
|
|
|
self->onChanged = f;
|
|
|
|
self->onChangedData = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-04-17 17:40:12 -05:00
|
|
|
struct entry {
|
|
|
|
uiEntry e;
|
|
|
|
NSTextField *textfield;
|
2015-05-06 19:58:55 -05:00
|
|
|
entryDelegate *delegate;
|
2015-04-17 17:54:17 -05:00
|
|
|
};
|
2015-04-09 01:35:52 -05:00
|
|
|
|
2015-05-06 19:58:55 -05:00
|
|
|
static void defaultOnChanged(uiEntry *e, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2015-04-17 17:40:12 -05:00
|
|
|
static void destroy(void *data)
|
2015-04-09 01:35:52 -05:00
|
|
|
{
|
2015-04-17 17:40:12 -05:00
|
|
|
struct entry *e = (struct entry *) data;
|
2015-04-09 01:35:52 -05:00
|
|
|
|
2015-05-06 19:58:55 -05:00
|
|
|
[e->textfield setDelegate:nil];
|
|
|
|
[e->delegate release];
|
2015-04-17 17:40:12 -05:00
|
|
|
uiFree(e);
|
|
|
|
}
|
2015-04-09 01:35:52 -05:00
|
|
|
|
2015-04-17 17:40:12 -05:00
|
|
|
static char *entryText(uiEntry *ee)
|
2015-04-16 13:41:24 -05:00
|
|
|
{
|
2015-04-17 17:40:12 -05:00
|
|
|
struct entry *e = (struct entry *) ee;
|
2015-04-16 13:41:24 -05:00
|
|
|
|
2015-04-17 17:40:12 -05:00
|
|
|
return uiDarwinNSStringToText([e->textfield stringValue]);
|
2015-04-16 13:41:24 -05:00
|
|
|
}
|
|
|
|
|
2015-04-17 17:40:12 -05:00
|
|
|
static void entrySetText(uiEntry *ee, const char *text)
|
2015-04-16 13:41:24 -05:00
|
|
|
{
|
2015-04-17 17:40:12 -05:00
|
|
|
struct entry *e = (struct entry *) ee;
|
2015-04-16 13:41:24 -05:00
|
|
|
|
2015-04-17 17:40:12 -05:00
|
|
|
[e->textfield setStringValue:toNSString(text)];
|
2015-04-16 13:41:24 -05:00
|
|
|
}
|
|
|
|
|
2015-05-06 19:58:55 -05:00
|
|
|
static void entryOnChanged(uiEntry *ee, void (*f)(uiEntry *, void *), void *data)
|
|
|
|
{
|
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
|
|
|
|
[e->delegate setOnChanged:f data:data];
|
|
|
|
}
|
|
|
|
|
2015-05-06 23:31:31 -05:00
|
|
|
static int entryReadOnly(uiEntry *ee)
|
|
|
|
{
|
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
|
|
|
|
return [e->textfield isEditable] == NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void entrySetReadOnly(uiEntry *ee, int readonly)
|
|
|
|
{
|
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
BOOL editable;
|
|
|
|
|
|
|
|
editable = YES;
|
|
|
|
if (readonly)
|
|
|
|
editable = NO;
|
|
|
|
[e->textfield setEditable:editable];
|
|
|
|
}
|
2015-05-06 19:58:55 -05:00
|
|
|
|
2015-04-09 01:35:52 -05:00
|
|
|
// 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
|
|
|
{
|
2015-04-17 17:40:12 -05:00
|
|
|
setStandardControlFont(t);
|
2015-04-09 01:35:52 -05:00
|
|
|
|
|
|
|
// 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-17 17:40:12 -05:00
|
|
|
struct entry *e;
|
|
|
|
|
|
|
|
e = uiNew(struct entry);
|
2015-04-09 01:35:52 -05:00
|
|
|
|
2015-05-02 19:51:00 -05:00
|
|
|
uiDarwinMakeControl(uiControl(e), [NSTextField class], NO, NO, destroy, e);
|
2015-04-16 13:41:24 -05:00
|
|
|
|
2015-04-29 09:28:17 -05:00
|
|
|
e->textfield = (NSTextField *) uiControlHandle(uiControl(e));
|
2015-04-09 01:35:52 -05:00
|
|
|
|
2015-04-17 17:40:12 -05:00
|
|
|
[e->textfield setSelectable:YES]; // otherwise the setting is masked by the editable default of YES
|
|
|
|
finishNewTextField(e->textfield, YES);
|
2015-04-09 01:35:52 -05:00
|
|
|
|
2015-05-06 19:58:55 -05:00
|
|
|
e->delegate = [entryDelegate new];
|
|
|
|
[e->textfield setDelegate:e->delegate];
|
|
|
|
[e->delegate setEntry:uiEntry(e)];
|
|
|
|
[e->delegate setOnChanged:defaultOnChanged data:NULL];
|
|
|
|
|
2015-04-16 13:41:24 -05:00
|
|
|
uiEntry(e)->Text = entryText;
|
|
|
|
uiEntry(e)->SetText = entrySetText;
|
2015-05-06 19:58:55 -05:00
|
|
|
uiEntry(e)->OnChanged = entryOnChanged;
|
2015-05-06 23:31:31 -05:00
|
|
|
uiEntry(e)->ReadOnly = entryReadOnly;
|
|
|
|
uiEntry(e)->SetReadOnly = entrySetReadOnly;
|
2015-04-09 10:54:02 -05:00
|
|
|
|
2015-04-17 17:40:12 -05:00
|
|
|
return uiEntry(e);
|
2015-04-09 10:54:02 -05:00
|
|
|
}
|