More OS X uiControl work.

This commit is contained in:
Pietro Gagliardi 2015-07-22 23:20:01 -04:00
parent d5744df476
commit 62b5365577
3 changed files with 13 additions and 57 deletions

View File

@ -1,50 +0,0 @@
// 9 april 2015
#import "uipriv_darwin.h"
struct label {
uiLabel l;
NSTextField *label;
};
static void destroy(void *data)
{
struct label *l = (struct label *) data;
uiFree(l);
}
static char *labelText(uiLabel *ll)
{
struct label *l = (struct label *) ll;
return uiDarwinNSStringToText([l->label stringValue]);
}
static void labelSetText(uiLabel *ll, const char *text)
{
struct label *l = (struct label *) ll;
[l->label setStringValue:toNSString(text)];
}
uiLabel *uiNewLabel(const char *text)
{
struct label *l;
l = uiNew(struct label);
uiDarwinMakeControl(uiControl(l), [NSTextField class], NO, NO, destroy, l);
l->label = (NSTextField *) uiControlHandle(uiControl(l));
[l->label setStringValue:toNSString(text)];
[l->label setEditable:NO];
[l->label setSelectable:NO];
[l->label setDrawsBackground:NO];
finishNewTextField(l->label, NO);
uiLabel(l)->Text = labelText;
uiLabel(l)->SetText = labelSetText;
return uiLabel(l);
}

View File

@ -3,7 +3,7 @@
struct label {
uiLabel l;
OSTYPE *OSHANDLE;
NSTextField *label;
};
uiDefineControlType(uiLabel, uiTypeLabel, struct label)
@ -12,21 +12,21 @@ static uintptr_t labelHandle(uiControl *c)
{
struct label *l = (struct label *) c;
return (uintptr_t) (l->OSHANDLE);
return (uintptr_t) (l->label);
}
static char *labelText(uiLabel *ll)
{
struct label *l = (struct label *) ll;
return PUT_CODE_HERE;
return uiDarwinNSStringToText([l->label stringValue]);
}
static void labelSetText(uiLabel *ll, const char *text)
{
struct label *l = (struct label *) ll;
PUT_CODE_HERE;
[l->label setStringValue:toNSString(text)];
// changing the text might necessitate a change in the label's size
uiControlQueueResize(uiControl(l));
}
@ -35,9 +35,15 @@ uiLabel *uiNewLabel(const char *text)
{
struct label *l;
l = (struct label *) MAKE_CONTROL_INSTANCE(uiTypeLabel());
l = (struct label *) uiNewControl(uiTypeLabel());
PUT_CODE_HERE;
l->label = [[NSTextField alloc] initWithFrame:NSZeroRect];
[l->label setStringValue:toNSString(text)];
[l->label setEditable:NO];
[l->label setSelectable:NO];
[l->label setDrawsBackground:NO];
finishNewTextField(uiControl(l), l->label, NO);
uiControl(l)->Handle = labelHandle;

View File

@ -47,7 +47,7 @@ extern void setStandardControlFont(NSControl *);
extern void disableAutocorrect(NSTextView *);
// entry.m
extern void finishNewTextField(NSTextField *, BOOL);
extern void finishNewTextField(uiControl *, NSTextField *, BOOL);
// window.m
extern uiWindow *windowFromNSWindow(NSWindow *);