diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/darwin/multilineentry.m b/darwin/multilineentry.m index d57284a05..88b35661b 100644 --- a/darwin/multilineentry.m +++ b/darwin/multilineentry.m @@ -1,10 +1,11 @@ // 8 december 2015 #import "uipriv_darwin.h" +#include "util.h" // NSTextView has no intrinsic content size by default, which wreaks havoc on a pure-Auto Layout system // we'll have to take over to get it to work // see also http://stackoverflow.com/questions/24210153/nstextview-not-properly-resizing-with-auto-layout and http://stackoverflow.com/questions/11237622/using-autolayout-with-expanding-nstextviews -@interface intrinsicSizeTextView : NSTextView { +@interface intrinsicSizeTextView : NSTextView { uiMultilineEntry *libui_e; } - (id)initWithFrame:(NSRect)r e:(uiMultilineEntry *)e; @@ -25,11 +26,21 @@ @implementation intrinsicSizeTextView - (id)initWithFrame:(NSRect)r e:(uiMultilineEntry *)e { self = [super initWithFrame:r]; + self.delegate = self; if (self) self->libui_e = e; return self; } +// [e->tv setTextColor:[NSColor textColor]] in finishMultilineentry +// does not work due to an cocoa bug which stops the text +// from changing pre control initialization so we resort +// to changing the text on the delegate method instead +- (void)textDidChange:(NSNotification *)aNotification { + NSTextView *tv = (NSTextView *)[aNotification object]; + [tv setTextColor:[NSColor textColor]]; +} + - (NSSize)intrinsicContentSize { NSTextContainer *textContainer; @@ -130,7 +141,6 @@ void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly) // NSText properties: // this is what Interface Builder sets the background color to - [e->tv setBackgroundColor:[NSColor colorWithCalibratedWhite:1.0 alpha:1.0]]; [e->tv setDrawsBackground:YES]; [e->tv setEditable:YES]; [e->tv setSelectable:YES]; @@ -139,6 +149,13 @@ void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly) [e->tv setImportsGraphics:NO]; [e->tv setUsesFontPanel:NO]; [e->tv setRulerVisible:NO]; + + if (isDarkMode()) { + e->tv.backgroundColor = NSColor.textBackgroundColor; + } else { + [e->tv setBackgroundColor:[NSColor colorWithCalibratedWhite:1.0 alpha:1.0]]; + } + // we'll handle font last // while setAlignment: has been around since 10.0, the named constant "NSTextAlignmentNatural" seems to have only been introduced in 10.11 #define ourNSTextAlignmentNatural 4 @@ -217,6 +234,11 @@ void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly) p.VScroll = YES; e->sv = uiprivMkScrollView(&p, &(e->d)); + if (isDarkMode()) { + e->sv.drawsBackground= YES; + e->sv.backgroundColor = NSColor.textBackgroundColor; + } + uiMultilineEntryOnChanged(e, defaultOnChanged, NULL); return e; diff --git a/darwin/util.h b/darwin/util.h new file mode 100644 index 000000000..1b539370c --- /dev/null +++ b/darwin/util.h @@ -0,0 +1,2 @@ + +bool isDarkMode(); diff --git a/darwin/util.m b/darwin/util.m index 418d958e0..be392731b 100644 --- a/darwin/util.m +++ b/darwin/util.m @@ -14,3 +14,9 @@ void uiprivDisableAutocorrect(NSTextView *tv) [tv setAutomaticLinkDetectionEnabled:NO]; [tv setSmartInsertDeleteEnabled:NO]; } + +bool isDarkMode() +{ + NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; + return [osxMode isEqualToString:@"Dark"]; +}