Merge 0316998e1c
into fea45b2d5b
This commit is contained in:
commit
26157cdfee
|
@ -0,0 +1 @@
|
||||||
|
/build
|
|
@ -1,10 +1,11 @@
|
||||||
// 8 december 2015
|
// 8 december 2015
|
||||||
#import "uipriv_darwin.h"
|
#import "uipriv_darwin.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
// NSTextView has no intrinsic content size by default, which wreaks havoc on a pure-Auto Layout system
|
// 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
|
// 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
|
// 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<NSTextViewDelegate> {
|
||||||
uiMultilineEntry *libui_e;
|
uiMultilineEntry *libui_e;
|
||||||
}
|
}
|
||||||
- (id)initWithFrame:(NSRect)r e:(uiMultilineEntry *)e;
|
- (id)initWithFrame:(NSRect)r e:(uiMultilineEntry *)e;
|
||||||
|
@ -25,11 +26,21 @@ struct uiMultilineEntry {
|
||||||
- (id)initWithFrame:(NSRect)r e:(uiMultilineEntry *)e
|
- (id)initWithFrame:(NSRect)r e:(uiMultilineEntry *)e
|
||||||
{
|
{
|
||||||
self = [super initWithFrame:r];
|
self = [super initWithFrame:r];
|
||||||
|
self.delegate = self;
|
||||||
if (self)
|
if (self)
|
||||||
self->libui_e = e;
|
self->libui_e = e;
|
||||||
return self;
|
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
|
- (NSSize)intrinsicContentSize
|
||||||
{
|
{
|
||||||
NSTextContainer *textContainer;
|
NSTextContainer *textContainer;
|
||||||
|
@ -130,7 +141,6 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll)
|
||||||
|
|
||||||
// NSText properties:
|
// NSText properties:
|
||||||
// this is what Interface Builder sets the background color to
|
// 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 setDrawsBackground:YES];
|
||||||
[e->tv setEditable:YES];
|
[e->tv setEditable:YES];
|
||||||
[e->tv setSelectable:YES];
|
[e->tv setSelectable:YES];
|
||||||
|
@ -139,6 +149,13 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll)
|
||||||
[e->tv setImportsGraphics:NO];
|
[e->tv setImportsGraphics:NO];
|
||||||
[e->tv setUsesFontPanel:NO];
|
[e->tv setUsesFontPanel:NO];
|
||||||
[e->tv setRulerVisible: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
|
// 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
|
// while setAlignment: has been around since 10.0, the named constant "NSTextAlignmentNatural" seems to have only been introduced in 10.11
|
||||||
#define ourNSTextAlignmentNatural 4
|
#define ourNSTextAlignmentNatural 4
|
||||||
|
@ -217,6 +234,11 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll)
|
||||||
p.VScroll = YES;
|
p.VScroll = YES;
|
||||||
e->sv = uiprivMkScrollView(&p, &(e->d));
|
e->sv = uiprivMkScrollView(&p, &(e->d));
|
||||||
|
|
||||||
|
if (isDarkMode()) {
|
||||||
|
e->sv.drawsBackground= YES;
|
||||||
|
e->sv.backgroundColor = NSColor.textBackgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
uiMultilineEntryOnChanged(e, defaultOnChanged, NULL);
|
uiMultilineEntryOnChanged(e, defaultOnChanged, NULL);
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
bool isDarkMode();
|
|
@ -14,3 +14,9 @@ void uiprivDisableAutocorrect(NSTextView *tv)
|
||||||
[tv setAutomaticLinkDetectionEnabled:NO];
|
[tv setAutomaticLinkDetectionEnabled:NO];
|
||||||
[tv setSmartInsertDeleteEnabled:NO];
|
[tv setSmartInsertDeleteEnabled:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isDarkMode()
|
||||||
|
{
|
||||||
|
NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
|
||||||
|
return [osxMode isEqualToString:@"Dark"];
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue