Started the OS X implementation of Textbox.

This commit is contained in:
Pietro Gagliardi 2014-10-24 16:11:53 -04:00
parent cbcf77fb6d
commit d82a6bc36d
4 changed files with 61 additions and 1 deletions

View File

@ -9,6 +9,7 @@
#define toNSView(x) ((NSView *) (x))
#define toNSWindow(x) ((NSWindow *) (x))
#define toNSBox(x) ((NSBox *) (x))
#define toNSTextView(x) ((NSTextView *) (x))
@interface goControlDelegate : NSObject <NSTextFieldDelegate> {
@public
@ -217,3 +218,56 @@ void groupSetText(id group, char *text)
{
[toNSBox(group) setTitle:[NSString stringWithUTF8String:text]];
}
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]];
}

View File

@ -13,4 +13,7 @@ void disableAutocorrect(id onwhat)
// don't worry about automatic data detection; it won't change stringValue (thanks pretty_function in irc.freenode.net/#macdev)
[tv setAutomaticSpellingCorrectionEnabled:NO];
[tv setAutomaticTextReplacementEnabled:NO];
[tv setAutomaticQuoteSubstitutionEnabled:NO];
[tv setAutomaticLinkDetectionEnabled:NO];
[tv setSmartInsertDeleteEnabled:NO];
}

View File

@ -16,7 +16,7 @@ void controlSetHidden(id control, BOOL hidden)
[toNSView(control) setHidden:hidden];
}
// also fine for NSCells
// also fine for NSCells and NSTexts (NSTextViews)
void setStandardControlFont(id control)
{
[toNSControl(control) setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];

View File

@ -79,6 +79,9 @@ extern id newLabel(void);
extern id newGroup(id);
extern const char *groupText(id);
extern void groupSetText(id, char *);
extern id newTextbox(id);
extern char *textboxText(id);
extern void textboxSetText(id, char *);
/* container_darwin.m */
extern id newContainerView(void *);