Migrated OS X uiButton. We're off to a meh start...
This commit is contained in:
parent
71c8bfc539
commit
89f8bd8643
|
@ -1,35 +1,6 @@
|
||||||
// 7 april 2015
|
// 7 april 2015
|
||||||
#import "uipriv_darwin.h"
|
#import "uipriv_darwin.h"
|
||||||
|
|
||||||
@interface buttonDelegate : NSObject {
|
|
||||||
uiButton *b;
|
|
||||||
void (*onClicked)(uiButton *, void *);
|
|
||||||
void *onClickedData;
|
|
||||||
}
|
|
||||||
- (IBAction)buttonClicked:(id)sender;
|
|
||||||
- (void)setButton:(uiButton *)newb;
|
|
||||||
- (void)setOnClicked:(void (*)(uiButton *, void *))f data:(void *)data;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation buttonDelegate
|
|
||||||
|
|
||||||
- (IBAction)buttonClicked:(id)sender
|
|
||||||
{
|
|
||||||
(*(self->onClicked))(self->b, self->onClickedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setButton:(uiButton *)newb
|
|
||||||
{
|
|
||||||
self->b = newb;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setOnClicked:(void (*)(uiButton *, void *))f data:(void *)data
|
|
||||||
{
|
|
||||||
self->onClicked = f;
|
|
||||||
self->onClickedData = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
struct button {
|
struct button {
|
||||||
uiButton b;
|
uiButton b;
|
||||||
|
@ -51,26 +22,6 @@ static void destroy(void *data)
|
||||||
uiFree(b);
|
uiFree(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *buttonText(uiButton *bb)
|
|
||||||
{
|
|
||||||
struct button *b = (struct button *) bb;
|
|
||||||
|
|
||||||
return uiDarwinNSStringToText([b->button title]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void buttonSetText(uiButton *bb, const char *text)
|
|
||||||
{
|
|
||||||
struct button *b = (struct button *) bb;
|
|
||||||
|
|
||||||
[b->button setTitle:toNSString(text)];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
|
|
||||||
{
|
|
||||||
struct button *b = (struct button *) bb;
|
|
||||||
|
|
||||||
[b->delegate setOnClicked:f data:data];
|
|
||||||
}
|
|
||||||
|
|
||||||
uiButton *uiNewButton(const char *text)
|
uiButton *uiNewButton(const char *text)
|
||||||
{
|
{
|
||||||
|
@ -82,18 +33,6 @@ uiButton *uiNewButton(const char *text)
|
||||||
|
|
||||||
b->button = (NSButton *) uiControlHandle(uiControl(b));
|
b->button = (NSButton *) uiControlHandle(uiControl(b));
|
||||||
|
|
||||||
[b->button setTitle:toNSString(text)];
|
|
||||||
[b->button setButtonType:NSMomentaryPushInButton];
|
|
||||||
[b->button setBordered:YES];
|
|
||||||
[b->button setBezelStyle:NSRoundedBezelStyle];
|
|
||||||
setStandardControlFont(b->button);
|
|
||||||
|
|
||||||
b->delegate = [buttonDelegate new];
|
|
||||||
[b->button setTarget:b->delegate];
|
|
||||||
[b->button setAction:@selector(buttonClicked:)];
|
|
||||||
[b->delegate setButton:uiButton(b)];
|
|
||||||
[b->delegate setOnClicked:defaultOnClicked data:NULL];
|
|
||||||
|
|
||||||
uiButton(b)->Text = buttonText;
|
uiButton(b)->Text = buttonText;
|
||||||
uiButton(b)->SetText = buttonSetText;
|
uiButton(b)->SetText = buttonSetText;
|
||||||
uiButton(b)->OnClicked = buttonOnClicked;
|
uiButton(b)->OnClicked = buttonOnClicked;
|
||||||
|
|
|
@ -1,11 +1,40 @@
|
||||||
// 10 june 2015
|
// 10 june 2015
|
||||||
#include "uipriv_darwin.h"
|
#include "uipriv_darwin.h"
|
||||||
|
|
||||||
struct button {
|
@interface buttonDelegate : NSObject {
|
||||||
uiButton b;
|
uiButton *b;
|
||||||
OSTYPE *OSHANDLE;
|
|
||||||
void (*onClicked)(uiButton *, void *);
|
void (*onClicked)(uiButton *, void *);
|
||||||
void *onClickedData;
|
void *onClickedData;
|
||||||
|
}
|
||||||
|
- (IBAction)buttonClicked:(id)sender;
|
||||||
|
- (void)setButton:(uiButton *)newb;
|
||||||
|
- (void)setOnClicked:(void (*)(uiButton *, void *))f data:(void *)data;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation buttonDelegate
|
||||||
|
|
||||||
|
- (IBAction)buttonClicked:(id)sender
|
||||||
|
{
|
||||||
|
(*(self->onClicked))(self->b, self->onClickedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setButton:(uiButton *)newb
|
||||||
|
{
|
||||||
|
self->b = newb;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setOnClicked:(void (*)(uiButton *, void *))f data:(void *)data
|
||||||
|
{
|
||||||
|
self->onClicked = f;
|
||||||
|
self->onClickedData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
struct button {
|
||||||
|
uiButton b;
|
||||||
|
NSButton *button;
|
||||||
|
buttonDelegate *delegate;
|
||||||
};
|
};
|
||||||
|
|
||||||
uiDefineControlType(uiButton, uiTypeButton, struct button)
|
uiDefineControlType(uiButton, uiTypeButton, struct button)
|
||||||
|
@ -14,7 +43,7 @@ static uintptr_t buttonHandle(uiControl *c)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) c;
|
struct button *b = (struct button *) c;
|
||||||
|
|
||||||
return (uintptr_t) (b->OSHANDLE);
|
return (uintptr_t) (b->button);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void defaultOnClicked(uiButton *b, void *data)
|
static void defaultOnClicked(uiButton *b, void *data)
|
||||||
|
@ -26,35 +55,41 @@ static char *buttonText(uiButton *bb)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) bb;
|
struct button *b = (struct button *) bb;
|
||||||
|
|
||||||
return PUT_CODE_HERE;
|
return uiDarwinNSStringToText([b->button title]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buttonSetText(uiButton *bb, const char *text)
|
static void buttonSetText(uiButton *bb, const char *text)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) bb;
|
struct button *b = (struct button *) bb;
|
||||||
|
|
||||||
PUT_CODE_HERE;
|
[b->button setTitle:toNSString(text)];
|
||||||
// changing the text might necessitate a change in the button's size
|
|
||||||
uiControlQueueResize(uiControl(b));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
|
static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) bb;
|
struct button *b = (struct button *) bb;
|
||||||
|
|
||||||
b->onClicked = f;
|
[b->delegate setOnClicked:f data:data];
|
||||||
b->onClickedData = data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uiButton *uiNewButton(const char *text)
|
uiButton *uiNewButton(const char *text)
|
||||||
{
|
{
|
||||||
struct button *b;
|
struct button *b;
|
||||||
|
|
||||||
b = (struct button *) MAKE_CONTROL_INSTANCE(uiTypeButton());
|
b = (struct button *) uiNewControl(uiTypeButton());
|
||||||
|
|
||||||
PUT_CODE_HERE;
|
b->button = [[NSButton alloc] initWithFrame:NSZeroFrame];
|
||||||
|
[b->button setTitle:toNSString(text)];
|
||||||
|
[b->button setButtonType:NSMomentaryPushInButton];
|
||||||
|
[b->button setBordered:YES];
|
||||||
|
[b->button setBezelStyle:NSRoundedBezelStyle];
|
||||||
|
uiDarwinMakeSingleViewControl(uiControl(b), b->button, YES);
|
||||||
|
|
||||||
b->onClicked = defaultOnClicked;
|
b->delegate = [buttonDelegate new];
|
||||||
|
[b->button setTarget:b->delegate];
|
||||||
|
[b->button setAction:@selector(buttonClicked:)];
|
||||||
|
[b->delegate setButton:uiButton(b)];
|
||||||
|
[b->delegate setOnClicked:defaultOnClicked data:NULL];
|
||||||
|
|
||||||
uiControl(b)->Handle = buttonHandle;
|
uiControl(b)->Handle = buttonHandle;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
|
|
||||||
static void singleViewCommitDestroy(uiControl *c)
|
static void singleViewCommitDestroy(uiControl *c)
|
||||||
{
|
{
|
||||||
|
// TODO make this unnecessary?
|
||||||
|
if ([VIEW(c) respondsToSelector:@selector(delegate)])
|
||||||
|
[[VIEW(c) delegate] release];
|
||||||
[VIEW(c) release];
|
[VIEW(c) release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,11 +105,14 @@ static int singleViewHasTabStops(uiControl *c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// called after creating the control's NSView
|
// called after creating the control's NSView
|
||||||
void uiDarwinMakeSingleViewControl(uiControl *c, NSView *view)
|
void uiDarwinMakeSingleViewControl(uiControl *c, NSView *view, BOOL useStandardControlFont)
|
||||||
{
|
{
|
||||||
// we have to retain the view so we can reparent it
|
// we have to retain the view so we can reparent it
|
||||||
[view retain];
|
[view retain];
|
||||||
|
|
||||||
|
if (useStandardControlFont)
|
||||||
|
setStandardControlFont((NSControl *) view);
|
||||||
|
|
||||||
uiControl(c)->CommitDestroy = singleViewCommitDestroy;
|
uiControl(c)->CommitDestroy = singleViewCommitDestroy;
|
||||||
uiControl(c)->CommitSetParent = singleViewCommitSetParent;
|
uiControl(c)->CommitSetParent = singleViewCommitSetParent;
|
||||||
uiControl(c)->PreferredSize = singleViewPreferredSize;
|
uiControl(c)->PreferredSize = singleViewPreferredSize;
|
||||||
|
|
Loading…
Reference in New Issue