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
|
||||
#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 {
|
||||
uiButton b;
|
||||
|
@ -51,26 +22,6 @@ static void destroy(void *data)
|
|||
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)
|
||||
{
|
||||
|
@ -82,18 +33,6 @@ uiButton *uiNewButton(const char *text)
|
|||
|
||||
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)->SetText = buttonSetText;
|
||||
uiButton(b)->OnClicked = buttonOnClicked;
|
||||
|
|
|
@ -1,11 +1,40 @@
|
|||
// 10 june 2015
|
||||
#include "uipriv_darwin.h"
|
||||
|
||||
struct button {
|
||||
uiButton b;
|
||||
OSTYPE *OSHANDLE;
|
||||
@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 {
|
||||
uiButton b;
|
||||
NSButton *button;
|
||||
buttonDelegate *delegate;
|
||||
};
|
||||
|
||||
uiDefineControlType(uiButton, uiTypeButton, struct button)
|
||||
|
@ -14,7 +43,7 @@ static uintptr_t buttonHandle(uiControl *c)
|
|||
{
|
||||
struct button *b = (struct button *) c;
|
||||
|
||||
return (uintptr_t) (b->OSHANDLE);
|
||||
return (uintptr_t) (b->button);
|
||||
}
|
||||
|
||||
static void defaultOnClicked(uiButton *b, void *data)
|
||||
|
@ -26,35 +55,41 @@ static char *buttonText(uiButton *bb)
|
|||
{
|
||||
struct button *b = (struct button *) bb;
|
||||
|
||||
return PUT_CODE_HERE;
|
||||
return uiDarwinNSStringToText([b->button title]);
|
||||
}
|
||||
|
||||
static void buttonSetText(uiButton *bb, const char *text)
|
||||
{
|
||||
struct button *b = (struct button *) bb;
|
||||
|
||||
PUT_CODE_HERE;
|
||||
// changing the text might necessitate a change in the button's size
|
||||
uiControlQueueResize(uiControl(b));
|
||||
[b->button setTitle:toNSString(text)];
|
||||
}
|
||||
|
||||
static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
|
||||
{
|
||||
struct button *b = (struct button *) bb;
|
||||
|
||||
b->onClicked = f;
|
||||
b->onClickedData = data;
|
||||
[b->delegate setOnClicked:f data:data];
|
||||
}
|
||||
|
||||
uiButton *uiNewButton(const char *text)
|
||||
{
|
||||
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;
|
||||
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
static void singleViewCommitDestroy(uiControl *c)
|
||||
{
|
||||
// TODO make this unnecessary?
|
||||
if ([VIEW(c) respondsToSelector:@selector(delegate)])
|
||||
[[VIEW(c) delegate] release];
|
||||
[VIEW(c) release];
|
||||
}
|
||||
|
||||
|
@ -102,11 +105,14 @@ static int singleViewHasTabStops(uiControl *c)
|
|||
}
|
||||
|
||||
// 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
|
||||
[view retain];
|
||||
|
||||
if (useStandardControlFont)
|
||||
setStandardControlFont((NSControl *) view);
|
||||
|
||||
uiControl(c)->CommitDestroy = singleViewCommitDestroy;
|
||||
uiControl(c)->CommitSetParent = singleViewCommitSetParent;
|
||||
uiControl(c)->PreferredSize = singleViewPreferredSize;
|
||||
|
|
Loading…
Reference in New Issue