diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-16 13:25:09 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-16 13:25:09 -0400 |
| commit | 1953f2d748a097e7a0e6ecfd2a2db2acf5fbca10 (patch) | |
| tree | 006a71c97602608a54b11baa14b5948e6ca8321d /redo/controls_darwin.m | |
| parent | d154a2d74d01be34561b2959864ce9302043c27f (diff) | |
Added Button and control adding to the Mac OS X backend.
Diffstat (limited to 'redo/controls_darwin.m')
| -rw-r--r-- | redo/controls_darwin.m | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/redo/controls_darwin.m b/redo/controls_darwin.m new file mode 100644 index 0000000..a21ac0f --- /dev/null +++ b/redo/controls_darwin.m @@ -0,0 +1,47 @@ +// 16 july 2014 + +#import "objc_darwin.h" +#import "_cgo_export.h" +#import <Cocoa/Cocoa.h> + +#define toNSView(x) ((NSView *) (x)) +#define toNSWindow(x) ((NSWindow *) (x)) +#define toNSButton(x) ((NSButton *) (x)) + +void unparent(id control) +{ + [toNSView(control) retain]; // save from being freed when released by the removal selector below + // TODO removeFromSuperviewWithoutNeedingDisplay? + [toNSView(control) removeFromSuperview]; +} + +void parent(id control, id parentid, BOOL floating) +{ + [[toNSWindow(parentid) contentView] addSubview:toNSView(control)]; + if (floating) // previously unparented + [toNSView(control) release]; +} + +id newButton(char *text) +{ + NSButton *b; + + // TODO cache the initial rect? + b = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; + // TODO verify all of these against Interface Builder + [b setButtonType:NSMomentaryLightButton]; + [b setTitle:[NSString stringWithUTF8String:text]]; + [b setBordered:YES]; + [b setBezelStyle:NSRoundedBezelStyle]; + return b; +} + +const char *buttonText(id button) +{ + return [[toNSButton(button) title] UTF8String]; +} + +void buttonSetText(id button, char *text) +{ + [toNSButton(button) setTitle:[NSString stringWithUTF8String:text]]; +} |
