2014-07-16 12:25:09 -05:00
|
|
|
// 16 july 2014
|
|
|
|
|
|
|
|
#import "objc_darwin.h"
|
|
|
|
#import "_cgo_export.h"
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#define toNSButton(x) ((NSButton *) (x))
|
2014-07-26 08:20:33 -05:00
|
|
|
#define toNSTextField(x) ((NSTextField *) (x))
|
2014-08-15 23:37:38 -05:00
|
|
|
#define toNSView(x) ((NSView *) (x))
|
2014-08-27 11:11:55 -05:00
|
|
|
#define toNSWindow(x) ((NSWindow *) (x))
|
2014-08-15 23:37:38 -05:00
|
|
|
#define toNSBox(x) ((NSBox *) (x))
|
2014-10-24 15:11:53 -05:00
|
|
|
#define toNSTextView(x) ((NSTextView *) (x))
|
2014-11-04 10:41:38 -06:00
|
|
|
#define toNSProgressIndicator(x) ((NSProgressIndicator *) (x))
|
2014-07-16 12:25:09 -05:00
|
|
|
|
2014-08-20 14:26:48 -05:00
|
|
|
@interface goControlDelegate : NSObject <NSTextFieldDelegate> {
|
2014-07-17 11:02:39 -05:00
|
|
|
@public
|
|
|
|
void *gocontrol;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation goControlDelegate
|
|
|
|
|
|
|
|
- (IBAction)buttonClicked:(id)sender
|
|
|
|
{
|
|
|
|
buttonClicked(self->gocontrol);
|
|
|
|
}
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
- (IBAction)checkboxToggled:(id)sender
|
|
|
|
{
|
2014-08-04 12:44:48 -05:00
|
|
|
checkboxToggled(self->gocontrol);
|
2014-08-03 19:08:25 -05:00
|
|
|
}
|
|
|
|
|
2014-08-20 14:26:48 -05:00
|
|
|
- (void)controlTextDidChange:(NSNotification *)note
|
|
|
|
{
|
|
|
|
textfieldChanged(self->gocontrol);
|
|
|
|
}
|
|
|
|
|
2014-07-17 11:02:39 -05:00
|
|
|
@end
|
|
|
|
|
2014-07-22 22:32:32 -05:00
|
|
|
id newButton(void)
|
2014-07-16 12:25:09 -05:00
|
|
|
{
|
|
|
|
NSButton *b;
|
|
|
|
|
2014-08-05 21:02:57 -05:00
|
|
|
b = [[NSButton alloc] initWithFrame:NSZeroRect];
|
2014-07-26 09:05:18 -05:00
|
|
|
[b setButtonType:NSMomentaryPushInButton];
|
2014-07-16 12:25:09 -05:00
|
|
|
[b setBordered:YES];
|
|
|
|
[b setBezelStyle:NSRoundedBezelStyle];
|
2014-07-26 09:05:18 -05:00
|
|
|
setStandardControlFont((id) b);
|
2014-07-22 22:32:32 -05:00
|
|
|
return (id) b;
|
2014-07-16 12:25:09 -05:00
|
|
|
}
|
|
|
|
|
2014-07-17 11:02:39 -05:00
|
|
|
void buttonSetDelegate(id button, void *b)
|
|
|
|
{
|
|
|
|
goControlDelegate *d;
|
|
|
|
|
|
|
|
d = [goControlDelegate new];
|
|
|
|
d->gocontrol = b;
|
|
|
|
[toNSButton(button) setTarget:d];
|
|
|
|
[toNSButton(button) setAction:@selector(buttonClicked:)];
|
|
|
|
}
|
|
|
|
|
2014-07-16 12:25:09 -05:00
|
|
|
const char *buttonText(id button)
|
|
|
|
{
|
|
|
|
return [[toNSButton(button) title] UTF8String];
|
|
|
|
}
|
|
|
|
|
|
|
|
void buttonSetText(id button, char *text)
|
|
|
|
{
|
|
|
|
[toNSButton(button) setTitle:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|
2014-07-22 22:32:32 -05:00
|
|
|
|
|
|
|
id newCheckbox(void)
|
|
|
|
{
|
|
|
|
NSButton *c;
|
|
|
|
|
2014-08-05 21:02:57 -05:00
|
|
|
c = [[NSButton alloc] initWithFrame:NSZeroRect];
|
2014-07-22 22:32:32 -05:00
|
|
|
[c setButtonType:NSSwitchButton];
|
|
|
|
[c setBordered:NO];
|
2014-07-26 09:05:18 -05:00
|
|
|
setStandardControlFont((id) c);
|
2014-07-22 22:32:32 -05:00
|
|
|
return (id) c;
|
|
|
|
}
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
void checkboxSetDelegate(id checkbox, void *b)
|
|
|
|
{
|
|
|
|
goControlDelegate *d;
|
|
|
|
|
|
|
|
d = [goControlDelegate new];
|
|
|
|
d->gocontrol = b;
|
|
|
|
[toNSButton(checkbox) setTarget:d];
|
|
|
|
[toNSButton(checkbox) setAction:@selector(checkboxToggled:)];
|
|
|
|
}
|
|
|
|
|
2014-07-22 22:32:32 -05:00
|
|
|
BOOL checkboxChecked(id c)
|
|
|
|
{
|
|
|
|
if ([toNSButton(c) state] == NSOnState)
|
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkboxSetChecked(id c, BOOL checked)
|
|
|
|
{
|
|
|
|
NSInteger state;
|
|
|
|
|
|
|
|
state = NSOnState;
|
|
|
|
if (checked == NO)
|
|
|
|
state = NSOffState;
|
|
|
|
[toNSButton(c) setState:state];
|
|
|
|
}
|
2014-07-26 08:20:33 -05:00
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
// also good for labels
|
2014-08-22 21:32:31 -05:00
|
|
|
// not static because area_darwin.m uses it
|
|
|
|
id finishNewTextField(id _t, BOOL bordered)
|
2014-07-26 08:20:33 -05:00
|
|
|
{
|
2014-08-22 21:32:31 -05:00
|
|
|
NSTextField *t = toNSTextField(_t);
|
|
|
|
|
2014-07-29 12:48:31 -05:00
|
|
|
// same for text fields, password fields, and labels
|
2014-07-26 09:05:18 -05:00
|
|
|
setStandardControlFont((id) t);
|
2014-08-10 12:55:46 -05:00
|
|
|
// these three are the same across text fields, password fields, and labels; the only difference is the setBezeled: value, and it's only different on labels
|
2014-08-10 13:15:59 -05:00
|
|
|
// THE ORDER OF THESE CALLS IS IMPORTANT; CHANGE IT AND THE BORDERS WILL DISAPPEAR
|
|
|
|
[t setBordered:NO];
|
2014-08-10 12:55:46 -05:00
|
|
|
[t setBezelStyle:NSTextFieldSquareBezel];
|
|
|
|
[t setBezeled:bordered];
|
2014-07-26 10:18:34 -05:00
|
|
|
// smart quotes and other autocorrect features are handled by the window; see newWindow() in window_darwin.m for details
|
2014-07-26 08:20:33 -05:00
|
|
|
// Interface Builder does this to make the text box behave properly
|
|
|
|
// this disables both word wrap AND ellipsizing in one fell swoop
|
|
|
|
// however, we need to send it to the control's cell, not to the control directly
|
|
|
|
[[t cell] setLineBreakMode:NSLineBreakByClipping];
|
|
|
|
// Interface Builder also sets this to allow horizontal scrolling
|
2014-07-29 12:48:31 -05:00
|
|
|
// it also sets this for labels, despite those not being scrollable
|
2014-07-26 08:20:33 -05:00
|
|
|
[[t cell] setScrollable:YES];
|
|
|
|
return (id) t;
|
|
|
|
}
|
|
|
|
|
|
|
|
id newTextField(void)
|
|
|
|
{
|
|
|
|
NSTextField *t;
|
|
|
|
|
2014-08-05 21:02:57 -05:00
|
|
|
t = [[NSTextField alloc] initWithFrame:NSZeroRect];
|
2014-11-05 12:35:39 -06:00
|
|
|
[t setSelectable:YES]; // otherwise the setting is masked by the editable default of YES
|
2014-08-22 21:32:31 -05:00
|
|
|
return finishNewTextField((id) t, YES);
|
2014-07-26 08:20:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
id newPasswordField(void)
|
|
|
|
{
|
|
|
|
NSSecureTextField *t;
|
|
|
|
|
2014-08-05 21:02:57 -05:00
|
|
|
t = [[NSSecureTextField alloc] initWithFrame:NSZeroRect];
|
2014-11-05 12:35:39 -06:00
|
|
|
[t setSelectable:YES]; // otherwise the setting is masked by the editable default of YES
|
2014-08-22 21:32:31 -05:00
|
|
|
return finishNewTextField((id) t, YES);
|
2014-07-26 08:20:33 -05:00
|
|
|
}
|
|
|
|
|
2014-08-20 14:26:48 -05:00
|
|
|
void textfieldSetDelegate(id textfield, void *t)
|
|
|
|
{
|
|
|
|
goControlDelegate *d;
|
|
|
|
|
|
|
|
d = [goControlDelegate new];
|
|
|
|
d->gocontrol = t;
|
|
|
|
[toNSTextField(textfield) setDelegate:d];
|
|
|
|
}
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
// also good for labels
|
2014-08-27 12:17:31 -05:00
|
|
|
const char *textfieldText(id t)
|
2014-07-26 08:20:33 -05:00
|
|
|
{
|
|
|
|
return [[toNSTextField(t) stringValue] UTF8String];
|
|
|
|
}
|
|
|
|
|
2014-08-03 19:08:25 -05:00
|
|
|
// also good for labels
|
2014-08-27 12:17:31 -05:00
|
|
|
void textfieldSetText(id t, char *text)
|
2014-07-26 08:20:33 -05:00
|
|
|
{
|
|
|
|
[toNSTextField(t) setStringValue:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|
2014-07-29 12:48:31 -05:00
|
|
|
|
2014-08-20 16:08:47 -05:00
|
|
|
id textfieldOpenInvalidPopover(id textfield, char *reason)
|
|
|
|
{
|
2014-08-27 11:11:55 -05:00
|
|
|
id popover;
|
2014-08-20 16:08:47 -05:00
|
|
|
|
2014-08-27 11:11:55 -05:00
|
|
|
popover = newWarningPopover(reason);
|
|
|
|
warningPopoverShow(popover, textfield);
|
2014-08-24 14:27:58 -05:00
|
|
|
NSBeep();
|
2014-08-20 16:08:47 -05:00
|
|
|
return (id) popover;
|
|
|
|
}
|
|
|
|
|
|
|
|
void textfieldCloseInvalidPopover(id popover)
|
|
|
|
{
|
2014-08-27 15:01:47 -05:00
|
|
|
[toNSWindow(popover) close];
|
|
|
|
// don't release; close does that already
|
2014-08-20 16:08:47 -05:00
|
|
|
}
|
|
|
|
|
2014-11-05 12:35:39 -06:00
|
|
|
BOOL textfieldEditable(id textfield)
|
|
|
|
{
|
|
|
|
return [toNSTextField(textfield) isEditable];
|
|
|
|
}
|
|
|
|
|
|
|
|
void textfieldSetEditable(id textfield, BOOL editable)
|
|
|
|
{
|
|
|
|
[toNSTextField(textfield) setEditable:editable];
|
|
|
|
}
|
|
|
|
|
2014-07-29 12:48:31 -05:00
|
|
|
id newLabel(void)
|
|
|
|
{
|
|
|
|
NSTextField *l;
|
|
|
|
|
2014-08-05 21:02:57 -05:00
|
|
|
l = [[NSTextField alloc] initWithFrame:NSZeroRect];
|
2014-07-29 12:48:31 -05:00
|
|
|
[l setEditable:NO];
|
|
|
|
[l setSelectable:NO];
|
|
|
|
[l setDrawsBackground:NO];
|
2014-08-22 21:32:31 -05:00
|
|
|
return finishNewTextField((id) l, NO);
|
2014-07-29 12:48:31 -05:00
|
|
|
}
|
2014-08-15 23:37:38 -05:00
|
|
|
|
|
|
|
id newGroup(id container)
|
|
|
|
{
|
|
|
|
NSBox *group;
|
|
|
|
|
|
|
|
group = [[NSBox alloc] initWithFrame:NSZeroRect];
|
|
|
|
[group setBorderType:NSLineBorder];
|
|
|
|
[group setBoxType:NSBoxPrimary];
|
|
|
|
[group setTransparent:NO];
|
|
|
|
// can't use setSmallControlFont() here because the selector is different
|
|
|
|
[group setTitleFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
|
|
|
|
[group setTitlePosition:NSAtTop];
|
|
|
|
[group setContentView:toNSView(container)];
|
|
|
|
return (id) group;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *groupText(id group)
|
|
|
|
{
|
|
|
|
return [[toNSBox(group) title] UTF8String];
|
|
|
|
}
|
|
|
|
|
|
|
|
void groupSetText(id group, char *text)
|
|
|
|
{
|
|
|
|
[toNSBox(group) setTitle:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|
2014-10-24 15:11:53 -05:00
|
|
|
|
|
|
|
id newTextbox(void)
|
|
|
|
{
|
|
|
|
NSTextView *tv;
|
|
|
|
|
|
|
|
tv = [[NSTextView alloc] initWithFrame:NSZeroRect];
|
|
|
|
// verified against Interface Builder, except for rich text options
|
|
|
|
[tv setAllowsDocumentBackgroundColorChange:NO];
|
|
|
|
[tv setBackgroundColor:[NSColor textBackgroundColor]];
|
|
|
|
[tv setTextColor:[NSColor textColor]];
|
|
|
|
[tv setAllowsUndo:YES];
|
|
|
|
[tv setEditable:YES];
|
|
|
|
[tv setSelectable:YES];
|
|
|
|
[tv setRichText:NO];
|
|
|
|
[tv setImportsGraphics:NO];
|
|
|
|
[tv setBaseWritingDirection:NSWritingDirectionNatural];
|
|
|
|
// TODO default paragraph format
|
|
|
|
[tv setAllowsImageEditing:NO];
|
|
|
|
[tv setAutomaticQuoteSubstitutionEnabled:NO];
|
|
|
|
[tv setAutomaticLinkDetectionEnabled:NO];
|
|
|
|
[tv setUsesRuler:NO];
|
|
|
|
[tv setRulerVisible:NO];
|
|
|
|
[tv setUsesInspectorBar:NO];
|
|
|
|
[tv setSelectionGranularity:NSSelectByCharacter];
|
|
|
|
//TODO [tv setInsertionPointColor:[NSColor insertionColor]];
|
|
|
|
[tv setContinuousSpellCheckingEnabled:NO];
|
|
|
|
[tv setGrammarCheckingEnabled:NO];
|
|
|
|
[tv setUsesFontPanel:NO];
|
|
|
|
[tv setEnabledTextCheckingTypes:0];
|
|
|
|
[tv setAutomaticDashSubstitutionEnabled:NO];
|
|
|
|
[tv setAutomaticSpellingCorrectionEnabled:NO];
|
|
|
|
[tv setAutomaticTextReplacementEnabled:NO];
|
|
|
|
[tv setSmartInsertDeleteEnabled:NO];
|
|
|
|
[tv setLayoutOrientation:NSTextLayoutOrientationHorizontal];
|
|
|
|
// TODO default find panel behavior
|
|
|
|
// now just to be safe; this will do some of the above but whatever
|
|
|
|
disableAutocorrect((id) tv);
|
|
|
|
// this option is complex; just set it to the Interface Builder default
|
|
|
|
[[tv layoutManager] setAllowsNonContiguousLayout:YES];
|
|
|
|
// this will work because it's the same selector
|
|
|
|
setStandardControlFont((id) tv);
|
|
|
|
return (id) tv;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *textboxText(id tv)
|
|
|
|
{
|
|
|
|
return [[toNSTextView(tv) string] UTF8String];
|
|
|
|
}
|
|
|
|
|
|
|
|
void textboxSetText(id tv, char *text)
|
|
|
|
{
|
|
|
|
[toNSTextView(tv) setString:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|
2014-11-04 10:41:38 -06:00
|
|
|
|
|
|
|
id newProgressBar(void)
|
|
|
|
{
|
|
|
|
NSProgressIndicator *pi;
|
|
|
|
|
|
|
|
pi = [[NSProgressIndicator alloc] initWithFrame:NSZeroRect];
|
|
|
|
[pi setStyle:NSProgressIndicatorBarStyle];
|
|
|
|
[pi setControlSize:NSRegularControlSize];
|
|
|
|
[pi setControlTint:NSDefaultControlTint];
|
|
|
|
[pi setBezeled:YES];
|
|
|
|
[pi setDisplayedWhenStopped:YES];
|
|
|
|
[pi setUsesThreadedAnimation:YES];
|
|
|
|
[pi setIndeterminate:NO];
|
|
|
|
[pi setMinValue:0];
|
|
|
|
[pi setMaxValue:100];
|
|
|
|
[pi setDoubleValue:0];
|
|
|
|
return (id) pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
intmax_t progressbarPercent(id pbar)
|
|
|
|
{
|
|
|
|
return (intmax_t) [toNSProgressIndicator(pbar) doubleValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
void progressbarSetPercent(id pbar, intmax_t percent)
|
|
|
|
{
|
|
|
|
[toNSProgressIndicator(pbar) setDoubleValue:((double) percent)];
|
|
|
|
}
|