🎨 Minor formatting tweaks

This commit is contained in:
Kevin Sawicki 2017-06-05 11:08:05 -07:00
parent 96251e55de
commit 2880cfdc9c

View file

@ -56,81 +56,91 @@ bool ScopedDisableResize::disable_resize_ = false;
BOOL mouseInside = NO; BOOL mouseInside = NO;
- (id)initWithFrame:(NSRect)frame { - (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
if (self) {
// create buttons if (self) {
NSButton *closeButton = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:NSTitledWindowMask]; // create buttons
NSButton *minitButton = [NSWindow standardWindowButton:NSWindowMiniaturizeButton forStyleMask:NSTitledWindowMask]; NSButton* closeButton = [NSWindow standardWindowButton:NSWindowCloseButton
NSButton *fullScreenButton = [NSWindow standardWindowButton:NSWindowZoomButton forStyleMask:NSTitledWindowMask]; forStyleMask:NSTitledWindowMask];
NSButton* minitButton = [NSWindow standardWindowButton:NSWindowMiniaturizeButton
forStyleMask:NSTitledWindowMask];
NSButton* fullScreenButton = [NSWindow standardWindowButton:NSWindowZoomButton
forStyleMask:NSTitledWindowMask];
// size view for buttons // size view for buttons
const int top = 3; const int top = 3;
const int bottom = 3; const int bottom = 3;
const int left = 7; const int left = 7;
const int between = 6; const int between = 6;
const int right = 6; const int right = 6;
auto buttonsSize = NSMakeRect(0,
0,
left + closeButton.frame.size.width + between + minitButton.frame.size.width + between + fullScreenButton.frame.size.width + right,
top + closeButton.frame.size.height + bottom);
// NSView* buttons = [[SemaphoreView alloc] initWithFrame:buttonsSize];
[self setFrame:buttonsSize];
//set their location auto buttonsSize = NSMakeRect(0,
[closeButton setFrame:NSMakeRect(7, 0,
buttonsSize.size.height - closeButton.frame.size.height - 3, left + closeButton.frame.size.width + between + minitButton.frame.size.width + between + fullScreenButton.frame.size.width + right,
closeButton.frame.size.width, top + closeButton.frame.size.height + bottom);
closeButton.frame.size.height)]; [self setFrame:buttonsSize];
[minitButton setFrame:NSMakeRect(7 + closeButton.frame.size.width + 6,
buttonsSize.size.height - minitButton.frame.size.height - 3,
minitButton.frame.size.width,
minitButton.frame.size.height)];
[fullScreenButton setFrame:NSMakeRect(7 + closeButton.frame.size.width + 6 + minitButton.frame.size.width + 6,
buttonsSize.size.height - fullScreenButton.frame.size.height - 3,
fullScreenButton.frame.size.width,
fullScreenButton.frame.size.height)];
//add buttons to the window //set their location
[self addSubview:closeButton]; [closeButton setFrame:NSMakeRect(left,
[self addSubview:minitButton]; buttonsSize.size.height - closeButton.frame.size.height - top,
[self addSubview:fullScreenButton]; closeButton.frame.size.width,
closeButton.frame.size.height)];
[minitButton setFrame:NSMakeRect(
left + closeButton.frame.size.width + between,
buttonsSize.size.height - minitButton.frame.size.height - top,
minitButton.frame.size.width,
minitButton.frame.size.height)];
[fullScreenButton setFrame:NSMakeRect(
left + closeButton.frame.size.width + between + minitButton.frame.size.width + between,
buttonsSize.size.height - fullScreenButton.frame.size.height - top,
fullScreenButton.frame.size.width,
fullScreenButton.frame.size.height)];
// stay in upper left corner //add buttons to the window
[self setAutoresizingMask: NSViewMaxXMargin | NSViewMinYMargin]; [self addSubview:closeButton];
[self addSubview:minitButton];
[self addSubview:fullScreenButton];
// refresh for initial conditions // stay in upper left corner
[self setNeedsDisplayForButtons]; [self setAutoresizingMask: NSViewMaxXMargin | NSViewMinYMargin];
}
return self; // refresh for initial conditions
[self setNeedsDisplayForButtons];
}
return self;
} }
- (BOOL)_mouseInGroup:(NSButton *)button { - (BOOL)_mouseInGroup:(NSButton*)button {
return mouseInside; return mouseInside;
} }
- (void)updateTrackingAreas { - (void)updateTrackingAreas {
NSTrackingArea *const trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect) owner:self userInfo:nil]; NSTrackingArea* const trackingArea =
[self addTrackingArea:trackingArea]; [[NSTrackingArea alloc] initWithRect:NSZeroRect
options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect
owner:self
userInfo:nil];
[self addTrackingArea:trackingArea];
} }
- (void)mouseEntered:(NSEvent *)event { - (void)mouseEntered:(NSEvent*)event {
[super mouseEntered:event]; [super mouseEntered:event];
mouseInside = YES; mouseInside = YES;
[self setNeedsDisplayForButtons]; [self setNeedsDisplayForButtons];
} }
- (void)mouseExited:(NSEvent *)event { - (void)mouseExited:(NSEvent*)event {
[super mouseExited:event]; [super mouseExited:event];
mouseInside = NO; mouseInside = NO;
[self setNeedsDisplayForButtons]; [self setNeedsDisplayForButtons];
} }
- (void)setNeedsDisplayForButtons { - (void)setNeedsDisplayForButtons {
for (NSView *subview in self.subviews) { for (NSView* subview in self.subviews) {
[subview setHidden:!mouseInside]; [subview setHidden:!mouseInside];
[subview setNeedsDisplay:YES]; [subview setNeedsDisplay:YES];
} }
} }
@end @end
@ -685,26 +695,27 @@ enum {
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil]; [[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront:nil];
} }
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem { // Custom window button methods
return ([menuItem action] == @selector(performClose:) || [menuItem action] == @selector(performMiniaturize:)) ? YES : [super validateMenuItem:menuItem];
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
return ([menuItem action] == @selector(performClose:) || [menuItem action] == @selector(performMiniaturize:)) ? YES : [super validateMenuItem:menuItem];
} }
- (BOOL)windowShouldClose:(id)sender { - (BOOL)windowShouldClose:(id)sender {
return YES; return YES;
} }
- (void)performClose:(id)sender { - (void)performClose:(id)sender {
if([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) { if ([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) {
if(![[self delegate] windowShouldClose:self]) return; if (![[self delegate] windowShouldClose:self]) return;
} } else if ([self respondsToSelector:@selector(windowShouldClose:)]) {
else if([self respondsToSelector:@selector(windowShouldClose:)]) { if (![self windowShouldClose:self]) return;
if(![self windowShouldClose:self]) return; }
} [self close];
[self close];
} }
- (void)performMiniaturize:(id)sender { - (void)performMiniaturize:(id)sender {
[self miniaturize:self]; [self miniaturize:self];
} }
@end @end