Delete MAAttachedWindow, it's not required anymore on 10.7.
This commit is contained in:
1 parent
bb166e846a
commit
475efae14c
5 files changed
+9
-1174
No files matched your search
@@ -14,7 +14,7 @@
|
|||||||
@private
|
@private
|
||||||
IBOutlet NSView *generalView, *advancedView, *setsView;
|
IBOutlet NSView *generalView, *advancedView, *setsView;
|
||||||
|
|
||||||
id _popover;
|
NSPopover *_popover;
|
||||||
SBMovieViewController *_controller;
|
SBMovieViewController *_controller;
|
||||||
NSInteger _currentRow;
|
NSInteger _currentRow;
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,6 @@
|
|||||||
#import "SBTableView.h"
|
#import "SBTableView.h"
|
||||||
#import "SBMovieViewController.h"
|
#import "SBMovieViewController.h"
|
||||||
|
|
||||||
#import "MAAttachedWindow.h"
|
|
||||||
|
|
||||||
#define TOOLBAR_GENERAL @"TOOLBAR_GENERAL"
|
#define TOOLBAR_GENERAL @"TOOLBAR_GENERAL"
|
||||||
#define TOOLBAR_ADVANCED @"TOOLBAR_ADVANCED"
|
#define TOOLBAR_ADVANCED @"TOOLBAR_ADVANCED"
|
||||||
#define TOOLBAR_SETS @"TOOLBAR_SETS"
|
#define TOOLBAR_SETS @"TOOLBAR_SETS"
|
||||||
@@ -150,13 +148,8 @@
|
|||||||
|
|
||||||
- (IBAction)closePopOver:(id)sender
|
- (IBAction)closePopOver:(id)sender
|
||||||
{
|
{
|
||||||
if(_popover) {
|
if (_popover) {
|
||||||
if (!NSClassFromString(@"NSPopover")) {
|
[_popover close];
|
||||||
[[self window] removeChildWindow:_popover];
|
|
||||||
[_popover orderOut:self];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
[_popover close];
|
|
||||||
|
|
||||||
[_popover release];
|
[_popover release];
|
||||||
_popover = nil;
|
_popover = nil;
|
||||||
@@ -177,41 +170,11 @@
|
|||||||
_controller = [[SBMovieViewController alloc] initWithNibName:@"MovieView" bundle:nil];
|
_controller = [[SBMovieViewController alloc] initWithNibName:@"MovieView" bundle:nil];
|
||||||
[_controller setMetadata:[[presetManager presets] objectAtIndex:_currentRow]];
|
[_controller setMetadata:[[presetManager presets] objectAtIndex:_currentRow]];
|
||||||
|
|
||||||
if (NSClassFromString(@"NSPopover")) {
|
_popover = [[NSPopover alloc] init];
|
||||||
_popover = [[NSPopover alloc] init];
|
_popover.contentViewController = _controller;
|
||||||
((NSPopover *)_popover).contentViewController = _controller;
|
_popover.contentSize = NSMakeSize(480.0f, 500.0f);
|
||||||
((NSPopover *)_popover).contentSize = NSMakeSize(480.0f, 500.0f);
|
|
||||||
|
|
||||||
[_popover showRelativeToRect:[tableView frameOfCellAtColumn:1 row:_currentRow] ofView:tableView preferredEdge:NSMaxYEdge];
|
[_popover showRelativeToRect:[tableView frameOfCellAtColumn:1 row:_currentRow] ofView:tableView preferredEdge:NSMaxYEdge];
|
||||||
} else {
|
|
||||||
NSInteger row = [tableView selectedRow];
|
|
||||||
|
|
||||||
NSRect cellFrame = [tableView frameOfCellAtColumn:1 row:row];
|
|
||||||
NSRect tableFrame = [[[tableView superview] superview]frame];
|
|
||||||
|
|
||||||
NSPoint windowPoint = NSMakePoint(NSMidX(cellFrame) + 20,
|
|
||||||
NSHeight(tableFrame) + tableFrame.origin.y - cellFrame.origin.y - (cellFrame.size.height / 2) - 8);
|
|
||||||
|
|
||||||
_popover = [[MAAttachedWindow alloc] initWithView:[_controller view]
|
|
||||||
attachedToPoint:windowPoint
|
|
||||||
inWindow:[self window]
|
|
||||||
onSide:MAPositionBottom
|
|
||||||
atDistance:0];
|
|
||||||
|
|
||||||
[_popover setBackgroundColor:[NSColor colorWithCalibratedRed:0.98f green:0.98f blue:1.0f alpha:0.9f]];
|
|
||||||
[(MAAttachedWindow *)_popover setDelegate:self];
|
|
||||||
[(MAAttachedWindow *)_popover setCornerRadius:6];
|
|
||||||
|
|
||||||
[[self window] addChildWindow:_popover ordered:NSWindowAbove];
|
|
||||||
|
|
||||||
[_popover setAlphaValue:0.0];
|
|
||||||
|
|
||||||
[NSAnimationContext beginGrouping];
|
|
||||||
[[NSAnimationContext currentContext] setDuration:0.2];
|
|
||||||
[_popover makeKeyAndOrderFront:self];
|
|
||||||
[[_popover animator] setAlphaValue:1.0];
|
|
||||||
[NSAnimationContext endGrouping];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,183 +0,0 @@
|
|||||||
//
|
|
||||||
// MAAttachedWindow.h
|
|
||||||
//
|
|
||||||
// Created by Matt Gemmell on 27/09/2007.
|
|
||||||
// Copyright 2007 Magic Aubergine.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
Below are the positions the attached window can be displayed at.
|
|
||||||
|
|
||||||
Note that these positions are relative to the point passed to the constructor,
|
|
||||||
e.g. MAPositionBottomRight will put the window below the point and towards the right,
|
|
||||||
MAPositionTop will horizontally center the window above the point,
|
|
||||||
MAPositionRightTop will put the window to the right and above the point,
|
|
||||||
and so on.
|
|
||||||
|
|
||||||
You can also pass MAPositionAutomatic (or use an initializer which omits the 'onSide:'
|
|
||||||
argument) and the attached window will try to position itself sensibly, based on
|
|
||||||
available screen-space.
|
|
||||||
|
|
||||||
Notes regarding automatically-positioned attached windows:
|
|
||||||
|
|
||||||
(a) The window prefers to position itself horizontally centered below the specified point.
|
|
||||||
This gives a certain enhanced visual sense of an attachment/relationship.
|
|
||||||
|
|
||||||
(b) The window will try to align itself with its parent window (if any); i.e. it will
|
|
||||||
attempt to stay within its parent window's frame if it can.
|
|
||||||
|
|
||||||
(c) The algorithm isn't perfect. :) If in doubt, do your own calculations and then
|
|
||||||
explicitly request that the window attach itself to a particular side.
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef enum _MAWindowPosition {
|
|
||||||
// The four primary sides are compatible with the preferredEdge of NSDrawer.
|
|
||||||
MAPositionLeft = NSMinXEdge, // 0
|
|
||||||
MAPositionRight = NSMaxXEdge, // 2
|
|
||||||
MAPositionTop = NSMaxYEdge, // 3
|
|
||||||
MAPositionBottom = NSMinYEdge, // 1
|
|
||||||
MAPositionLeftTop = 4,
|
|
||||||
MAPositionLeftBottom = 5,
|
|
||||||
MAPositionRightTop = 6,
|
|
||||||
MAPositionRightBottom = 7,
|
|
||||||
MAPositionTopLeft = 8,
|
|
||||||
MAPositionTopRight = 9,
|
|
||||||
MAPositionBottomLeft = 10,
|
|
||||||
MAPositionBottomRight = 11,
|
|
||||||
MAPositionAutomatic = 12
|
|
||||||
} MAWindowPosition;
|
|
||||||
|
|
||||||
@interface MAAttachedWindow : NSWindow {
|
|
||||||
NSColor *borderColor;
|
|
||||||
CGFloat borderWidth;
|
|
||||||
CGFloat viewMargin;
|
|
||||||
CGFloat arrowBaseWidth;
|
|
||||||
CGFloat arrowHeight;
|
|
||||||
BOOL hasArrow;
|
|
||||||
CGFloat cornerRadius;
|
|
||||||
BOOL drawsRoundCornerBesideArrow;
|
|
||||||
|
|
||||||
@private
|
|
||||||
NSColor *_MABackgroundColor;
|
|
||||||
__weak NSView *_view;
|
|
||||||
__weak NSWindow *_window;
|
|
||||||
NSPoint _point;
|
|
||||||
MAWindowPosition _side;
|
|
||||||
CGFloat _distance;
|
|
||||||
NSRect _viewFrame;
|
|
||||||
BOOL _resizing;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Initialization methods
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
|
|
||||||
view The view to display in the attached window. Must not be nil.
|
|
||||||
|
|
||||||
point The point to which the attached window should be attached. If you
|
|
||||||
are also specifying a parent window, the point should be in the
|
|
||||||
coordinate system of that parent window. If you are not specifying
|
|
||||||
a window, the point should be in the screen's coordinate space.
|
|
||||||
This value is required.
|
|
||||||
|
|
||||||
window The parent window to attach this one to. Note that no actual
|
|
||||||
relationship is created (particularly, this window is not made
|
|
||||||
a childWindow of the parent window).
|
|
||||||
Default: nil.
|
|
||||||
|
|
||||||
side The side of the specified point on which to attach this window.
|
|
||||||
Default: MAPositionAutomatic.
|
|
||||||
|
|
||||||
distance How far from the specified point this window should be.
|
|
||||||
Default: 0.
|
|
||||||
*/
|
|
||||||
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view // designated initializer
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
inWindow:(NSWindow *)window
|
|
||||||
onSide:(MAWindowPosition)side
|
|
||||||
atDistance:(float)distance;
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
inWindow:(NSWindow *)window
|
|
||||||
atDistance:(float)distance;
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
onSide:(MAWindowPosition)side
|
|
||||||
atDistance:(float)distance;
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
atDistance:(float)distance;
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
inWindow:(NSWindow *)window;
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
onSide:(MAWindowPosition)side;
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point;
|
|
||||||
|
|
||||||
// Accessor methods
|
|
||||||
- (NSColor *)borderColor;
|
|
||||||
- (void)setBorderColor:(NSColor *)value;
|
|
||||||
- (CGFloat)borderWidth;
|
|
||||||
- (void)setBorderWidth:(CGFloat)value; // See note 1 below.
|
|
||||||
- (CGFloat)viewMargin;
|
|
||||||
- (void)setViewMargin:(CGFloat)value; // See note 2 below.
|
|
||||||
- (CGFloat)arrowBaseWidth;
|
|
||||||
- (void)setArrowBaseWidth:(CGFloat)value; // See note 2 below.
|
|
||||||
- (CGFloat)arrowHeight;
|
|
||||||
- (void)setArrowHeight:(CGFloat)value; // See note 2 below.
|
|
||||||
- (CGFloat)hasArrow;
|
|
||||||
- (void)setHasArrow:(CGFloat)value;
|
|
||||||
- (CGFloat)cornerRadius;
|
|
||||||
- (void)setCornerRadius:(CGFloat)value; // See note 2 below.
|
|
||||||
- (CGFloat)drawsRoundCornerBesideArrow; // See note 3 below.
|
|
||||||
- (void)setDrawsRoundCornerBesideArrow:(CGFloat)value; // See note 2 below.
|
|
||||||
- (void)setBackgroundImage:(NSImage *)value;
|
|
||||||
- (NSColor *)windowBackgroundColor; // See note 4 below.
|
|
||||||
- (void)setBackgroundColor:(NSColor *)value;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Notes regarding accessor methods:
|
|
||||||
|
|
||||||
1. The border is drawn inside the viewMargin area, expanding inwards; it does not
|
|
||||||
increase the width/height of the window. You can use the -setBorderWidth: and
|
|
||||||
-setViewMargin: methods together to achieve the exact look/geometry you want.
|
|
||||||
(viewMargin is the distance between the edge of the view and the window edge.)
|
|
||||||
|
|
||||||
2. The specified setter methods are primarily intended to be used _before_ the window
|
|
||||||
is first shown. If you use them while the window is already visible, be aware
|
|
||||||
that they may cause the window to move and/or resize, in order to stay anchored
|
|
||||||
to the point specified in the initializer. They may also cause the view to move
|
|
||||||
within the window, in order to remain centered there.
|
|
||||||
|
|
||||||
Note that the -setHasArrow: method can safely be used at any time, and will not
|
|
||||||
cause moving/resizing of the window. This is for convenience, in case you want
|
|
||||||
to add or remove the arrow in response to user interaction. For example, you
|
|
||||||
could make the attached window movable by its background, and if the user dragged
|
|
||||||
it away from its initial point, the arrow could be removed. This would duplicate
|
|
||||||
how Aperture's attached windows behave.
|
|
||||||
|
|
||||||
3. drawsRoundCornerBesideArrow takes effect when the arrow is being drawn at a corner,
|
|
||||||
i.e. when it's not at one of the four primary compass directions. In this situation,
|
|
||||||
if drawsRoundCornerBesideArrow is YES (the default), then that corner of the window
|
|
||||||
will be rounded just like the other three corners, thus the arrow will be inset
|
|
||||||
slightly from the edge of the window to allow room for the rounded corner. If this
|
|
||||||
value is NO, the corner beside the arrow will be a square corner, and the other
|
|
||||||
three corners will be rounded.
|
|
||||||
|
|
||||||
This is useful when you want to attach a window very near the edge of another window,
|
|
||||||
and don't want the attached window's edge to be visually outside the frame of the
|
|
||||||
parent window.
|
|
||||||
|
|
||||||
4. Note that to retrieve the background color of the window, you should use the
|
|
||||||
-windowBackgroundColor method, instead of -backgroundColor. This is because we draw
|
|
||||||
the entire background of the window (rounded path, arrow, etc) in an NSColor pattern
|
|
||||||
image, and set it as the backgroundColor of the window.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@end
|
|
||||||
@@ -1,939 +0,0 @@
|
|||||||
//
|
|
||||||
// MAAttachedWindow.m
|
|
||||||
//
|
|
||||||
// Created by Matt Gemmell on 27/09/2007.
|
|
||||||
// Copyright 2007 Magic Aubergine.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "MAAttachedWindow.h"
|
|
||||||
|
|
||||||
#define MAATTACHEDWINDOW_DEFAULT_BACKGROUND_COLOR [NSColor colorWithCalibratedWhite:0.1 alpha:0.75]
|
|
||||||
#define MAATTACHEDWINDOW_DEFAULT_BORDER_COLOR [NSColor whiteColor]
|
|
||||||
#define MAATTACHEDWINDOW_SCALE_FACTOR [[NSScreen mainScreen] userSpaceScaleFactor]
|
|
||||||
|
|
||||||
@interface MAAttachedWindow (MAPrivateMethods)
|
|
||||||
|
|
||||||
// Geometry
|
|
||||||
- (void)_updateGeometry;
|
|
||||||
- (MAWindowPosition)_bestSideForAutomaticPosition;
|
|
||||||
- (CGFloat)_arrowInset;
|
|
||||||
|
|
||||||
// Drawing
|
|
||||||
- (void)_updateBackground;
|
|
||||||
- (NSColor *)_backgroundColorPatternImage;
|
|
||||||
- (NSBezierPath *)_backgroundPath;
|
|
||||||
- (void)_appendArrowToPath:(NSBezierPath *)path;
|
|
||||||
- (void)_redisplay;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation MAAttachedWindow
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark Initializers
|
|
||||||
|
|
||||||
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
inWindow:(NSWindow *)window
|
|
||||||
onSide:(MAWindowPosition)side
|
|
||||||
atDistance:(float)distance
|
|
||||||
{
|
|
||||||
// Insist on having a valid view.
|
|
||||||
if (!view) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create dummy initial contentRect for window.
|
|
||||||
NSRect contentRect = NSZeroRect;
|
|
||||||
contentRect.size = [view frame].size;
|
|
||||||
|
|
||||||
if ((self = [super initWithContentRect:contentRect
|
|
||||||
styleMask:NSBorderlessWindowMask
|
|
||||||
backing:NSBackingStoreBuffered
|
|
||||||
defer:NO])) {
|
|
||||||
_view = view;
|
|
||||||
_window = window;
|
|
||||||
_point = point;
|
|
||||||
_side = side;
|
|
||||||
_distance = distance;
|
|
||||||
|
|
||||||
// Configure window characteristics.
|
|
||||||
[super setBackgroundColor:[NSColor clearColor]];
|
|
||||||
[self setMovableByWindowBackground:NO];
|
|
||||||
[self setExcludedFromWindowsMenu:YES];
|
|
||||||
[self setAlphaValue:1.0];
|
|
||||||
[self setOpaque:NO];
|
|
||||||
[self setHasShadow:YES];
|
|
||||||
[self useOptimizedDrawing:YES];
|
|
||||||
|
|
||||||
// Set up some sensible defaults for display.
|
|
||||||
_MABackgroundColor = [MAATTACHEDWINDOW_DEFAULT_BACKGROUND_COLOR copy];
|
|
||||||
borderColor = [MAATTACHEDWINDOW_DEFAULT_BORDER_COLOR copy];
|
|
||||||
borderWidth = 2.0;
|
|
||||||
viewMargin = 2.0;
|
|
||||||
arrowBaseWidth = 20.0;
|
|
||||||
arrowHeight = 16.0;
|
|
||||||
hasArrow = YES;
|
|
||||||
cornerRadius = 8.0;
|
|
||||||
drawsRoundCornerBesideArrow = YES;
|
|
||||||
_resizing = NO;
|
|
||||||
|
|
||||||
// Work out what side to put the window on if it's "automatic".
|
|
||||||
if (_side == MAPositionAutomatic) {
|
|
||||||
_side = [self _bestSideForAutomaticPosition];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure our initial geometry.
|
|
||||||
[self _updateGeometry];
|
|
||||||
|
|
||||||
// Update the background.
|
|
||||||
[self _updateBackground];
|
|
||||||
|
|
||||||
// Add view as subview of our contentView.
|
|
||||||
[[self contentView] addSubview:_view];
|
|
||||||
|
|
||||||
// Subscribe to notifications for when we change size.
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
||||||
selector:@selector(windowDidResize:)
|
|
||||||
name:NSWindowDidResizeNotification
|
|
||||||
object:self];
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
inWindow:(NSWindow *)window
|
|
||||||
atDistance:(float)distance
|
|
||||||
{
|
|
||||||
return [self initWithView:view attachedToPoint:point
|
|
||||||
inWindow:window onSide:MAPositionAutomatic
|
|
||||||
atDistance:distance];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
onSide:(MAWindowPosition)side
|
|
||||||
atDistance:(float)distance
|
|
||||||
{
|
|
||||||
return [self initWithView:view attachedToPoint:point
|
|
||||||
inWindow:nil onSide:side
|
|
||||||
atDistance:distance];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
atDistance:(float)distance
|
|
||||||
{
|
|
||||||
return [self initWithView:view attachedToPoint:point
|
|
||||||
inWindow:nil onSide:MAPositionAutomatic
|
|
||||||
atDistance:distance];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
inWindow:(NSWindow *)window
|
|
||||||
{
|
|
||||||
return [self initWithView:view attachedToPoint:point
|
|
||||||
inWindow:window onSide:MAPositionAutomatic
|
|
||||||
atDistance:0];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
onSide:(MAWindowPosition)side
|
|
||||||
{
|
|
||||||
return [self initWithView:view attachedToPoint:point
|
|
||||||
inWindow:nil onSide:side
|
|
||||||
atDistance:0];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (MAAttachedWindow *)initWithView:(NSView *)view
|
|
||||||
attachedToPoint:(NSPoint)point
|
|
||||||
{
|
|
||||||
return [self initWithView:view attachedToPoint:point
|
|
||||||
inWindow:nil onSide:MAPositionAutomatic
|
|
||||||
atDistance:0];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)dealloc
|
|
||||||
{
|
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
||||||
[borderColor release];
|
|
||||||
[_MABackgroundColor release];
|
|
||||||
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark Geometry
|
|
||||||
|
|
||||||
|
|
||||||
- (void)_updateGeometry
|
|
||||||
{
|
|
||||||
NSRect contentRect = NSZeroRect;
|
|
||||||
contentRect.size = [_view frame].size;
|
|
||||||
|
|
||||||
// Account for viewMargin.
|
|
||||||
_viewFrame = NSMakeRect(viewMargin * MAATTACHEDWINDOW_SCALE_FACTOR,
|
|
||||||
viewMargin * MAATTACHEDWINDOW_SCALE_FACTOR,
|
|
||||||
[_view frame].size.width, [_view frame].size.height);
|
|
||||||
contentRect = NSInsetRect(contentRect,
|
|
||||||
-viewMargin * MAATTACHEDWINDOW_SCALE_FACTOR,
|
|
||||||
-viewMargin * MAATTACHEDWINDOW_SCALE_FACTOR);
|
|
||||||
|
|
||||||
// Account for arrowHeight in new window frame.
|
|
||||||
// Note: we always leave room for the arrow, even if it currently set to
|
|
||||||
// not be shown. This is so it can easily be toggled whilst the window
|
|
||||||
// is visible, without altering the window's frame origin point.
|
|
||||||
CGFloat scaledArrowHeight = arrowHeight * MAATTACHEDWINDOW_SCALE_FACTOR;
|
|
||||||
switch (_side) {
|
|
||||||
case MAPositionLeft:
|
|
||||||
case MAPositionLeftTop:
|
|
||||||
case MAPositionLeftBottom:
|
|
||||||
contentRect.size.width += scaledArrowHeight;
|
|
||||||
break;
|
|
||||||
case MAPositionRight:
|
|
||||||
case MAPositionRightTop:
|
|
||||||
case MAPositionRightBottom:
|
|
||||||
_viewFrame.origin.x += scaledArrowHeight;
|
|
||||||
contentRect.size.width += scaledArrowHeight;
|
|
||||||
break;
|
|
||||||
case MAPositionTop:
|
|
||||||
case MAPositionTopLeft:
|
|
||||||
case MAPositionTopRight:
|
|
||||||
_viewFrame.origin.y += scaledArrowHeight;
|
|
||||||
contentRect.size.height += scaledArrowHeight;
|
|
||||||
break;
|
|
||||||
case MAPositionBottom:
|
|
||||||
case MAPositionBottomLeft:
|
|
||||||
case MAPositionBottomRight:
|
|
||||||
contentRect.size.height += scaledArrowHeight;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break; // won't happen, but this satisfies gcc with -Wall
|
|
||||||
}
|
|
||||||
|
|
||||||
// Position frame origin appropriately for _side, accounting for arrow-inset.
|
|
||||||
contentRect.origin = (_window) ? [_window convertBaseToScreen:_point] : _point;
|
|
||||||
CGFloat arrowInset = [self _arrowInset];
|
|
||||||
CGFloat halfWidth = contentRect.size.width / 2.0;
|
|
||||||
CGFloat halfHeight = contentRect.size.height / 2.0;
|
|
||||||
switch (_side) {
|
|
||||||
case MAPositionTopLeft:
|
|
||||||
contentRect.origin.x -= contentRect.size.width - arrowInset;
|
|
||||||
break;
|
|
||||||
case MAPositionTop:
|
|
||||||
contentRect.origin.x -= halfWidth;
|
|
||||||
break;
|
|
||||||
case MAPositionTopRight:
|
|
||||||
contentRect.origin.x -= arrowInset;
|
|
||||||
break;
|
|
||||||
case MAPositionBottomLeft:
|
|
||||||
contentRect.origin.y -= contentRect.size.height;
|
|
||||||
contentRect.origin.x -= contentRect.size.width - arrowInset;
|
|
||||||
break;
|
|
||||||
case MAPositionBottom:
|
|
||||||
contentRect.origin.y -= contentRect.size.height;
|
|
||||||
contentRect.origin.x -= halfWidth;
|
|
||||||
break;
|
|
||||||
case MAPositionBottomRight:
|
|
||||||
contentRect.origin.x -= arrowInset;
|
|
||||||
contentRect.origin.y -= contentRect.size.height;
|
|
||||||
break;
|
|
||||||
case MAPositionLeftTop:
|
|
||||||
contentRect.origin.x -= contentRect.size.width;
|
|
||||||
contentRect.origin.y -= arrowInset;
|
|
||||||
break;
|
|
||||||
case MAPositionLeft:
|
|
||||||
contentRect.origin.x -= contentRect.size.width;
|
|
||||||
contentRect.origin.y -= halfHeight;
|
|
||||||
break;
|
|
||||||
case MAPositionLeftBottom:
|
|
||||||
contentRect.origin.x -= contentRect.size.width;
|
|
||||||
contentRect.origin.y -= contentRect.size.height - arrowInset;
|
|
||||||
break;
|
|
||||||
case MAPositionRightTop:
|
|
||||||
contentRect.origin.y -= arrowInset;
|
|
||||||
break;
|
|
||||||
case MAPositionRight:
|
|
||||||
contentRect.origin.y -= halfHeight;
|
|
||||||
break;
|
|
||||||
case MAPositionRightBottom:
|
|
||||||
contentRect.origin.y -= contentRect.size.height - arrowInset;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break; // won't happen, but this satisfies gcc with -Wall
|
|
||||||
}
|
|
||||||
|
|
||||||
// Account for _distance in new window frame.
|
|
||||||
switch (_side) {
|
|
||||||
case MAPositionLeft:
|
|
||||||
case MAPositionLeftTop:
|
|
||||||
case MAPositionLeftBottom:
|
|
||||||
contentRect.origin.x -= _distance;
|
|
||||||
break;
|
|
||||||
case MAPositionRight:
|
|
||||||
case MAPositionRightTop:
|
|
||||||
case MAPositionRightBottom:
|
|
||||||
contentRect.origin.x += _distance;
|
|
||||||
break;
|
|
||||||
case MAPositionTop:
|
|
||||||
case MAPositionTopLeft:
|
|
||||||
case MAPositionTopRight:
|
|
||||||
contentRect.origin.y += _distance;
|
|
||||||
break;
|
|
||||||
case MAPositionBottom:
|
|
||||||
case MAPositionBottomLeft:
|
|
||||||
case MAPositionBottomRight:
|
|
||||||
contentRect.origin.y -= _distance;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break; // won't happen, but this satisfies gcc with -Wall
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reconfigure window and view frames appropriately.
|
|
||||||
[self setFrame:contentRect display:NO];
|
|
||||||
[_view setFrame:_viewFrame];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (MAWindowPosition)_bestSideForAutomaticPosition
|
|
||||||
{
|
|
||||||
// Get all relevant geometry in screen coordinates.
|
|
||||||
NSRect screenFrame;
|
|
||||||
if (_window && [_window screen]) {
|
|
||||||
screenFrame = [[_window screen] visibleFrame];
|
|
||||||
} else {
|
|
||||||
screenFrame = [[NSScreen mainScreen] visibleFrame];
|
|
||||||
}
|
|
||||||
NSPoint pointOnScreen = (_window) ? [_window convertBaseToScreen:_point] : _point;
|
|
||||||
NSSize viewSize = [_view frame].size;
|
|
||||||
viewSize.width += (viewMargin * MAATTACHEDWINDOW_SCALE_FACTOR) * 2.0;
|
|
||||||
viewSize.height += (viewMargin * MAATTACHEDWINDOW_SCALE_FACTOR) * 2.0;
|
|
||||||
MAWindowPosition side = MAPositionBottom; // By default, position us centered below.
|
|
||||||
CGFloat scaledArrowHeight = (arrowHeight * MAATTACHEDWINDOW_SCALE_FACTOR) + _distance;
|
|
||||||
|
|
||||||
// We'd like to display directly below the specified point, since this gives a
|
|
||||||
// sense of a relationship between the point and this window. Check there's room.
|
|
||||||
if (pointOnScreen.y - viewSize.height - scaledArrowHeight < NSMinY(screenFrame)) {
|
|
||||||
// We'd go off the bottom of the screen. Try the right.
|
|
||||||
if (pointOnScreen.x + viewSize.width + scaledArrowHeight >= NSMaxX(screenFrame)) {
|
|
||||||
// We'd go off the right of the screen. Try the left.
|
|
||||||
if (pointOnScreen.x - viewSize.width - scaledArrowHeight < NSMinX(screenFrame)) {
|
|
||||||
// We'd go off the left of the screen. Try the top.
|
|
||||||
if (pointOnScreen.y + viewSize.height + scaledArrowHeight < NSMaxY(screenFrame)) {
|
|
||||||
side = MAPositionTop;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
side = MAPositionLeft;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
side = MAPositionRight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CGFloat halfWidth = viewSize.width / 2.0;
|
|
||||||
CGFloat halfHeight = viewSize.height / 2.0;
|
|
||||||
|
|
||||||
NSRect parentFrame = (_window) ? [_window frame] : screenFrame;
|
|
||||||
CGFloat arrowInset = [self _arrowInset];
|
|
||||||
|
|
||||||
// We're currently at a primary side.
|
|
||||||
// Try to avoid going outwith the parent area in the secondary dimension,
|
|
||||||
// by checking to see if an appropriate corner side would be better.
|
|
||||||
switch (side) {
|
|
||||||
case MAPositionBottom:
|
|
||||||
case MAPositionTop:
|
|
||||||
// Check to see if we go beyond the left edge of the parent area.
|
|
||||||
if (pointOnScreen.x - halfWidth < NSMinX(parentFrame)) {
|
|
||||||
// We go beyond the left edge. Try using right position.
|
|
||||||
if (pointOnScreen.x + viewSize.width - arrowInset < NSMaxX(screenFrame)) {
|
|
||||||
// We'd still be on-screen using right, so use it.
|
|
||||||
if (side == MAPositionBottom) {
|
|
||||||
side = MAPositionBottomRight;
|
|
||||||
} else {
|
|
||||||
side = MAPositionTopRight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (pointOnScreen.x + halfWidth >= NSMaxX(parentFrame)) {
|
|
||||||
// We go beyond the right edge. Try using left position.
|
|
||||||
if (pointOnScreen.x - viewSize.width + arrowInset >= NSMinX(screenFrame)) {
|
|
||||||
// We'd still be on-screen using left, so use it.
|
|
||||||
if (side == MAPositionBottom) {
|
|
||||||
side = MAPositionBottomLeft;
|
|
||||||
} else {
|
|
||||||
side = MAPositionTopLeft;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MAPositionRight:
|
|
||||||
case MAPositionLeft:
|
|
||||||
// Check to see if we go beyond the bottom edge of the parent area.
|
|
||||||
if (pointOnScreen.y - halfHeight < NSMinY(parentFrame)) {
|
|
||||||
// We go beyond the bottom edge. Try using top position.
|
|
||||||
if (pointOnScreen.y + viewSize.height - arrowInset < NSMaxY(screenFrame)) {
|
|
||||||
// We'd still be on-screen using top, so use it.
|
|
||||||
if (side == MAPositionRight) {
|
|
||||||
side = MAPositionRightTop;
|
|
||||||
} else {
|
|
||||||
side = MAPositionLeftTop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (pointOnScreen.y + halfHeight >= NSMaxY(parentFrame)) {
|
|
||||||
// We go beyond the top edge. Try using bottom position.
|
|
||||||
if (pointOnScreen.y - viewSize.height + arrowInset >= NSMinY(screenFrame)) {
|
|
||||||
// We'd still be on-screen using bottom, so use it.
|
|
||||||
if (side == MAPositionRight) {
|
|
||||||
side = MAPositionRightBottom;
|
|
||||||
} else {
|
|
||||||
side = MAPositionLeftBottom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break; // won't happen, but this satisfies gcc with -Wall
|
|
||||||
}
|
|
||||||
|
|
||||||
return side;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (CGFloat)_arrowInset
|
|
||||||
{
|
|
||||||
CGFloat cornerInset = (drawsRoundCornerBesideArrow) ? cornerRadius : 0;
|
|
||||||
return (cornerInset + (arrowBaseWidth / 2.0)) * MAATTACHEDWINDOW_SCALE_FACTOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark Drawing
|
|
||||||
|
|
||||||
|
|
||||||
- (void)_updateBackground
|
|
||||||
{
|
|
||||||
// Call NSWindow's implementation of -setBackgroundColor: because we override
|
|
||||||
// it in this class to let us set the entire background image of the window
|
|
||||||
// as an NSColor patternImage.
|
|
||||||
NSDisableScreenUpdates();
|
|
||||||
[super setBackgroundColor:[self _backgroundColorPatternImage]];
|
|
||||||
if ([self isVisible]) {
|
|
||||||
[self display];
|
|
||||||
[self invalidateShadow];
|
|
||||||
}
|
|
||||||
NSEnableScreenUpdates();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (NSColor *)_backgroundColorPatternImage
|
|
||||||
{
|
|
||||||
NSImage *bg = [[NSImage alloc] initWithSize:[self frame].size];
|
|
||||||
NSRect bgRect = NSZeroRect;
|
|
||||||
bgRect.size = [bg size];
|
|
||||||
|
|
||||||
[bg lockFocus];
|
|
||||||
NSBezierPath *bgPath = [self _backgroundPath];
|
|
||||||
[NSGraphicsContext saveGraphicsState];
|
|
||||||
[bgPath addClip];
|
|
||||||
|
|
||||||
// Draw background.
|
|
||||||
[_MABackgroundColor set];
|
|
||||||
[bgPath fill];
|
|
||||||
|
|
||||||
// Draw border if appropriate.
|
|
||||||
if (borderWidth > 0) {
|
|
||||||
// Double the borderWidth since we're drawing inside the path.
|
|
||||||
[bgPath setLineWidth:(borderWidth * 2.0) * MAATTACHEDWINDOW_SCALE_FACTOR];
|
|
||||||
[borderColor set];
|
|
||||||
[bgPath stroke];
|
|
||||||
}
|
|
||||||
|
|
||||||
[NSGraphicsContext restoreGraphicsState];
|
|
||||||
[bg unlockFocus];
|
|
||||||
|
|
||||||
return [NSColor colorWithPatternImage:[bg autorelease]];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (NSBezierPath *)_backgroundPath
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
Construct path for window background, taking account of:
|
|
||||||
1. hasArrow
|
|
||||||
2. _side
|
|
||||||
3. drawsRoundCornerBesideArrow
|
|
||||||
4. arrowBaseWidth
|
|
||||||
5. arrowHeight
|
|
||||||
6. cornerRadius
|
|
||||||
*/
|
|
||||||
|
|
||||||
CGFloat scaleFactor = MAATTACHEDWINDOW_SCALE_FACTOR;
|
|
||||||
CGFloat scaledRadius = cornerRadius * scaleFactor;
|
|
||||||
CGFloat scaledArrowWidth = arrowBaseWidth * scaleFactor;
|
|
||||||
CGFloat halfArrowWidth = scaledArrowWidth / 2.0;
|
|
||||||
NSRect contentArea = NSInsetRect(_viewFrame,
|
|
||||||
-viewMargin * scaleFactor,
|
|
||||||
-viewMargin * scaleFactor);
|
|
||||||
CGFloat minX = NSMinX(contentArea) * scaleFactor;
|
|
||||||
CGFloat midX = NSMidX(contentArea) * scaleFactor;
|
|
||||||
CGFloat maxX = NSMaxX(contentArea) * scaleFactor;
|
|
||||||
CGFloat minY = NSMinY(contentArea) * scaleFactor;
|
|
||||||
CGFloat midY = NSMidY(contentArea) * scaleFactor;
|
|
||||||
CGFloat maxY = NSMaxY(contentArea) * scaleFactor;
|
|
||||||
|
|
||||||
NSBezierPath *path = [NSBezierPath bezierPath];
|
|
||||||
[path setLineJoinStyle:NSRoundLineJoinStyle];
|
|
||||||
|
|
||||||
// Begin at top-left. This will be either after the rounded corner, or
|
|
||||||
// at the top-left point if cornerRadius is zero and/or we're drawing
|
|
||||||
// the arrow at the top-left or left-top without a rounded corner.
|
|
||||||
NSPoint currPt = NSMakePoint(minX, maxY);
|
|
||||||
if (scaledRadius > 0 &&
|
|
||||||
(drawsRoundCornerBesideArrow ||
|
|
||||||
(_side != MAPositionBottomRight && _side != MAPositionRightBottom))
|
|
||||||
) {
|
|
||||||
currPt.x += scaledRadius;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSPoint endOfLine = NSMakePoint(maxX, maxY);
|
|
||||||
BOOL shouldDrawNextCorner = NO;
|
|
||||||
if (scaledRadius > 0 &&
|
|
||||||
(drawsRoundCornerBesideArrow ||
|
|
||||||
(_side != MAPositionBottomLeft && _side != MAPositionLeftBottom))
|
|
||||||
) {
|
|
||||||
endOfLine.x -= scaledRadius;
|
|
||||||
shouldDrawNextCorner = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
[path moveToPoint:currPt];
|
|
||||||
|
|
||||||
// If arrow should be drawn at top-left point, draw it.
|
|
||||||
if (_side == MAPositionBottomRight) {
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
} else if (_side == MAPositionBottom) {
|
|
||||||
// Line to relevant point before arrow.
|
|
||||||
[path lineToPoint:NSMakePoint(midX - halfArrowWidth, maxY)];
|
|
||||||
// Draw arrow.
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
} else if (_side == MAPositionBottomLeft) {
|
|
||||||
// Line to relevant point before arrow.
|
|
||||||
[path lineToPoint:NSMakePoint(endOfLine.x - scaledArrowWidth, maxY)];
|
|
||||||
// Draw arrow.
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line to end of this side.
|
|
||||||
[path lineToPoint:endOfLine];
|
|
||||||
|
|
||||||
// Rounded corner on top-right.
|
|
||||||
if (shouldDrawNextCorner) {
|
|
||||||
[path appendBezierPathWithArcFromPoint:NSMakePoint(maxX, maxY)
|
|
||||||
toPoint:NSMakePoint(maxX, maxY - scaledRadius)
|
|
||||||
radius:scaledRadius];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Draw the right side, beginning at the top-right.
|
|
||||||
endOfLine = NSMakePoint(maxX, minY);
|
|
||||||
shouldDrawNextCorner = NO;
|
|
||||||
if (scaledRadius > 0 &&
|
|
||||||
(drawsRoundCornerBesideArrow ||
|
|
||||||
(_side != MAPositionTopLeft && _side != MAPositionLeftTop))
|
|
||||||
) {
|
|
||||||
endOfLine.y += scaledRadius;
|
|
||||||
shouldDrawNextCorner = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If arrow should be drawn at right-top point, draw it.
|
|
||||||
if (_side == MAPositionLeftBottom) {
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
} else if (_side == MAPositionLeft) {
|
|
||||||
// Line to relevant point before arrow.
|
|
||||||
[path lineToPoint:NSMakePoint(maxX, midY + halfArrowWidth)];
|
|
||||||
// Draw arrow.
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
} else if (_side == MAPositionLeftTop) {
|
|
||||||
// Line to relevant point before arrow.
|
|
||||||
[path lineToPoint:NSMakePoint(maxX, endOfLine.y + scaledArrowWidth)];
|
|
||||||
// Draw arrow.
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line to end of this side.
|
|
||||||
[path lineToPoint:endOfLine];
|
|
||||||
|
|
||||||
// Rounded corner on bottom-right.
|
|
||||||
if (shouldDrawNextCorner) {
|
|
||||||
[path appendBezierPathWithArcFromPoint:NSMakePoint(maxX, minY)
|
|
||||||
toPoint:NSMakePoint(maxX - scaledRadius, minY)
|
|
||||||
radius:scaledRadius];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Draw the bottom side, beginning at the bottom-right.
|
|
||||||
endOfLine = NSMakePoint(minX, minY);
|
|
||||||
shouldDrawNextCorner = NO;
|
|
||||||
if (scaledRadius > 0 &&
|
|
||||||
(drawsRoundCornerBesideArrow ||
|
|
||||||
(_side != MAPositionTopRight && _side != MAPositionRightTop))
|
|
||||||
) {
|
|
||||||
endOfLine.x += scaledRadius;
|
|
||||||
shouldDrawNextCorner = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If arrow should be drawn at bottom-right point, draw it.
|
|
||||||
if (_side == MAPositionTopLeft) {
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
} else if (_side == MAPositionTop) {
|
|
||||||
// Line to relevant point before arrow.
|
|
||||||
[path lineToPoint:NSMakePoint(midX + halfArrowWidth, minY)];
|
|
||||||
// Draw arrow.
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
} else if (_side == MAPositionTopRight) {
|
|
||||||
// Line to relevant point before arrow.
|
|
||||||
[path lineToPoint:NSMakePoint(endOfLine.x + scaledArrowWidth, minY)];
|
|
||||||
// Draw arrow.
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line to end of this side.
|
|
||||||
[path lineToPoint:endOfLine];
|
|
||||||
|
|
||||||
// Rounded corner on bottom-left.
|
|
||||||
if (shouldDrawNextCorner) {
|
|
||||||
[path appendBezierPathWithArcFromPoint:NSMakePoint(minX, minY)
|
|
||||||
toPoint:NSMakePoint(minX, minY + scaledRadius)
|
|
||||||
radius:scaledRadius];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Draw the left side, beginning at the bottom-left.
|
|
||||||
endOfLine = NSMakePoint(minX, maxY);
|
|
||||||
shouldDrawNextCorner = NO;
|
|
||||||
if (scaledRadius > 0 &&
|
|
||||||
(drawsRoundCornerBesideArrow ||
|
|
||||||
(_side != MAPositionRightBottom && _side != MAPositionBottomRight))
|
|
||||||
) {
|
|
||||||
endOfLine.y -= scaledRadius;
|
|
||||||
shouldDrawNextCorner = YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If arrow should be drawn at left-bottom point, draw it.
|
|
||||||
if (_side == MAPositionRightTop) {
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
} else if (_side == MAPositionRight) {
|
|
||||||
// Line to relevant point before arrow.
|
|
||||||
[path lineToPoint:NSMakePoint(minX, midY - halfArrowWidth)];
|
|
||||||
// Draw arrow.
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
} else if (_side == MAPositionRightBottom) {
|
|
||||||
// Line to relevant point before arrow.
|
|
||||||
[path lineToPoint:NSMakePoint(minX, endOfLine.y - scaledArrowWidth)];
|
|
||||||
// Draw arrow.
|
|
||||||
[self _appendArrowToPath:path];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line to end of this side.
|
|
||||||
[path lineToPoint:endOfLine];
|
|
||||||
|
|
||||||
// Rounded corner on top-left.
|
|
||||||
if (shouldDrawNextCorner) {
|
|
||||||
[path appendBezierPathWithArcFromPoint:NSMakePoint(minX, maxY)
|
|
||||||
toPoint:NSMakePoint(minX + scaledRadius, maxY)
|
|
||||||
radius:scaledRadius];
|
|
||||||
}
|
|
||||||
|
|
||||||
[path closePath];
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)_appendArrowToPath:(NSBezierPath *)path
|
|
||||||
{
|
|
||||||
if (!hasArrow) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CGFloat scaleFactor = MAATTACHEDWINDOW_SCALE_FACTOR;
|
|
||||||
CGFloat scaledArrowWidth = arrowBaseWidth * scaleFactor;
|
|
||||||
CGFloat halfArrowWidth = scaledArrowWidth / 2.0;
|
|
||||||
CGFloat scaledArrowHeight = arrowHeight * scaleFactor;
|
|
||||||
NSPoint currPt = [path currentPoint];
|
|
||||||
NSPoint tipPt = currPt;
|
|
||||||
NSPoint endPt = currPt;
|
|
||||||
|
|
||||||
// Note: we always build the arrow path in a clockwise direction.
|
|
||||||
switch (_side) {
|
|
||||||
case MAPositionLeft:
|
|
||||||
case MAPositionLeftTop:
|
|
||||||
case MAPositionLeftBottom:
|
|
||||||
// Arrow points towards right. We're starting from the top.
|
|
||||||
tipPt.x += scaledArrowHeight;
|
|
||||||
tipPt.y -= halfArrowWidth;
|
|
||||||
endPt.y -= scaledArrowWidth;
|
|
||||||
break;
|
|
||||||
case MAPositionRight:
|
|
||||||
case MAPositionRightTop:
|
|
||||||
case MAPositionRightBottom:
|
|
||||||
// Arrow points towards left. We're starting from the bottom.
|
|
||||||
tipPt.x -= scaledArrowHeight;
|
|
||||||
tipPt.y += halfArrowWidth;
|
|
||||||
endPt.y += scaledArrowWidth;
|
|
||||||
break;
|
|
||||||
case MAPositionTop:
|
|
||||||
case MAPositionTopLeft:
|
|
||||||
case MAPositionTopRight:
|
|
||||||
// Arrow points towards bottom. We're starting from the right.
|
|
||||||
tipPt.y -= scaledArrowHeight;
|
|
||||||
tipPt.x -= halfArrowWidth;
|
|
||||||
endPt.x -= scaledArrowWidth;
|
|
||||||
break;
|
|
||||||
case MAPositionBottom:
|
|
||||||
case MAPositionBottomLeft:
|
|
||||||
case MAPositionBottomRight:
|
|
||||||
// Arrow points towards top. We're starting from the left.
|
|
||||||
tipPt.y += scaledArrowHeight;
|
|
||||||
tipPt.x += halfArrowWidth;
|
|
||||||
endPt.x += scaledArrowWidth;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break; // won't happen, but this satisfies gcc with -Wall
|
|
||||||
}
|
|
||||||
|
|
||||||
[path lineToPoint:tipPt];
|
|
||||||
[path lineToPoint:endPt];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)_redisplay
|
|
||||||
{
|
|
||||||
if (_resizing) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_resizing = YES;
|
|
||||||
NSDisableScreenUpdates();
|
|
||||||
[self _updateGeometry];
|
|
||||||
[self _updateBackground];
|
|
||||||
NSEnableScreenUpdates();
|
|
||||||
_resizing = NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# pragma mark Window Behaviour
|
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)canBecomeMainWindow
|
|
||||||
{
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)canBecomeKeyWindow
|
|
||||||
{
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)isExcludedFromWindowsMenu
|
|
||||||
{
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)validateMenuItem:(NSMenuItem *)item
|
|
||||||
{
|
|
||||||
if (_window) {
|
|
||||||
return [_window validateMenuItem:item];
|
|
||||||
}
|
|
||||||
return [super validateMenuItem:item];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (IBAction)performClose:(id)sender
|
|
||||||
{
|
|
||||||
if (_window) {
|
|
||||||
[_window performClose:sender];
|
|
||||||
} else {
|
|
||||||
[super performClose:sender];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# pragma mark Notification handlers
|
|
||||||
|
|
||||||
|
|
||||||
- (void)windowDidResize:(NSNotification *)note
|
|
||||||
{
|
|
||||||
[self _redisplay];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark Accessors
|
|
||||||
|
|
||||||
|
|
||||||
- (NSColor *)windowBackgroundColor {
|
|
||||||
return [[_MABackgroundColor retain] autorelease];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setBackgroundColor:(NSColor *)value {
|
|
||||||
if (_MABackgroundColor != value) {
|
|
||||||
[_MABackgroundColor release];
|
|
||||||
_MABackgroundColor = [value copy];
|
|
||||||
|
|
||||||
[self _updateBackground];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (NSColor *)borderColor {
|
|
||||||
return [[borderColor retain] autorelease];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setBorderColor:(NSColor *)value {
|
|
||||||
if (borderColor != value) {
|
|
||||||
[borderColor release];
|
|
||||||
borderColor = [value copy];
|
|
||||||
|
|
||||||
[self _updateBackground];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (CGFloat)borderWidth {
|
|
||||||
return borderWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setBorderWidth:(CGFloat)value {
|
|
||||||
if (borderWidth != value) {
|
|
||||||
CGFloat maxBorderWidth = viewMargin;
|
|
||||||
if (value <= maxBorderWidth) {
|
|
||||||
borderWidth = value;
|
|
||||||
} else {
|
|
||||||
borderWidth = maxBorderWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
[self _updateBackground];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (CGFloat)viewMargin {
|
|
||||||
return viewMargin;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setViewMargin:(CGFloat)value {
|
|
||||||
if (viewMargin != value) {
|
|
||||||
viewMargin = MAX(value, 0.0);
|
|
||||||
|
|
||||||
// Adjust cornerRadius appropriately (which will also adjust arrowBaseWidth).
|
|
||||||
[self setCornerRadius:cornerRadius];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (CGFloat)arrowBaseWidth {
|
|
||||||
return arrowBaseWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setArrowBaseWidth:(CGFloat)value {
|
|
||||||
CGFloat maxWidth = (MIN(_viewFrame.size.width, _viewFrame.size.height) +
|
|
||||||
(viewMargin * 2.0)) - cornerRadius;
|
|
||||||
if (drawsRoundCornerBesideArrow) {
|
|
||||||
maxWidth -= cornerRadius;
|
|
||||||
}
|
|
||||||
if (value <= maxWidth) {
|
|
||||||
arrowBaseWidth = value;
|
|
||||||
} else {
|
|
||||||
arrowBaseWidth = maxWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
[self _redisplay];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (CGFloat)arrowHeight {
|
|
||||||
return arrowHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setArrowHeight:(CGFloat)value {
|
|
||||||
if (arrowHeight != value) {
|
|
||||||
arrowHeight = value;
|
|
||||||
|
|
||||||
[self _redisplay];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (CGFloat)hasArrow {
|
|
||||||
return hasArrow;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setHasArrow:(CGFloat)value {
|
|
||||||
if (hasArrow != value) {
|
|
||||||
hasArrow = value;
|
|
||||||
|
|
||||||
[self _updateBackground];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (CGFloat)cornerRadius {
|
|
||||||
return cornerRadius;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setCornerRadius:(CGFloat)value {
|
|
||||||
CGFloat maxRadius = ((MIN(_viewFrame.size.width, _viewFrame.size.height) +
|
|
||||||
(viewMargin * 2.0)) - arrowBaseWidth) / 2.0;
|
|
||||||
if (value <= maxRadius) {
|
|
||||||
cornerRadius = value;
|
|
||||||
} else {
|
|
||||||
cornerRadius = maxRadius;
|
|
||||||
}
|
|
||||||
cornerRadius = MAX(cornerRadius, 0.0);
|
|
||||||
|
|
||||||
// Adjust arrowBaseWidth appropriately.
|
|
||||||
[self setArrowBaseWidth:arrowBaseWidth];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (CGFloat)drawsRoundCornerBesideArrow {
|
|
||||||
return drawsRoundCornerBesideArrow;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setDrawsRoundCornerBesideArrow:(CGFloat)value {
|
|
||||||
if (drawsRoundCornerBesideArrow != value) {
|
|
||||||
drawsRoundCornerBesideArrow = value;
|
|
||||||
|
|
||||||
[self _redisplay];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)setBackgroundImage:(NSImage *)value
|
|
||||||
{
|
|
||||||
if (value) {
|
|
||||||
[self setBackgroundColor:[NSColor colorWithPatternImage:value]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
A91F622D0FB0A56F00B96B33 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A91F622C0FB0A56F00B96B33 /* libicucore.dylib */; };
|
A91F622D0FB0A56F00B96B33 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A91F622C0FB0A56F00B96B33 /* libicucore.dylib */; };
|
||||||
A925AA8518378D8A00BE84D4 /* MP42Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A925AA8218378D7900BE84D4 /* MP42Foundation.framework */; };
|
A925AA8518378D8A00BE84D4 /* MP42Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A925AA8218378D7900BE84D4 /* MP42Foundation.framework */; };
|
||||||
A925AA8818378DD000BE84D4 /* MP42Foundation.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = A925AA8218378D7900BE84D4 /* MP42Foundation.framework */; };
|
A925AA8818378DD000BE84D4 /* MP42Foundation.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = A925AA8218378D7900BE84D4 /* MP42Foundation.framework */; };
|
||||||
A936E03E130BE10200CA5527 /* MAAttachedWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = A936E03D130BE10200CA5527 /* MAAttachedWindow.m */; };
|
|
||||||
A95C881D0F827BFB00F51A22 /* ToolbarRemoveTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = A95C881C0F827BFB00F51A22 /* ToolbarRemoveTemplate.png */; };
|
A95C881D0F827BFB00F51A22 /* ToolbarRemoveTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = A95C881C0F827BFB00F51A22 /* ToolbarRemoveTemplate.png */; };
|
||||||
A960E96317D4B00900FC6ED9 /* SBImageBrowserView.m in Sources */ = {isa = PBXBuildFile; fileRef = A960E96217D4B00900FC6ED9 /* SBImageBrowserView.m */; };
|
A960E96317D4B00900FC6ED9 /* SBImageBrowserView.m in Sources */ = {isa = PBXBuildFile; fileRef = A960E96217D4B00900FC6ED9 /* SBImageBrowserView.m */; };
|
||||||
A961476313F567E10068F161 /* SBQueueController.m in Sources */ = {isa = PBXBuildFile; fileRef = A961476013F567E10068F161 /* SBQueueController.m */; };
|
A961476313F567E10068F161 /* SBQueueController.m in Sources */ = {isa = PBXBuildFile; fileRef = A961476013F567E10068F161 /* SBQueueController.m */; };
|
||||||
@@ -158,8 +157,6 @@
|
|||||||
A917286419FD289F00348DF8 /* SBLogger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SBLogger.h; path = Classes/SBLogger.h; sourceTree = "<group>"; };
|
A917286419FD289F00348DF8 /* SBLogger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SBLogger.h; path = Classes/SBLogger.h; sourceTree = "<group>"; };
|
||||||
A91F622C0FB0A56F00B96B33 /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = /usr/lib/libicucore.dylib; sourceTree = "<absolute>"; };
|
A91F622C0FB0A56F00B96B33 /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = /usr/lib/libicucore.dylib; sourceTree = "<absolute>"; };
|
||||||
A925AA7B18378D7800BE84D4 /* MP42Foundation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = MP42Foundation.xcodeproj; path = MP42Foundation/MP42Foundation.xcodeproj; sourceTree = "<group>"; };
|
A925AA7B18378D7800BE84D4 /* MP42Foundation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = MP42Foundation.xcodeproj; path = MP42Foundation/MP42Foundation.xcodeproj; sourceTree = "<group>"; };
|
||||||
A936E03C130BE10200CA5527 /* MAAttachedWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MAAttachedWindow.h; path = Others/MAAttachedWindow.h; sourceTree = "<group>"; };
|
|
||||||
A936E03D130BE10200CA5527 /* MAAttachedWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MAAttachedWindow.m; path = Others/MAAttachedWindow.m; sourceTree = "<group>"; };
|
|
||||||
A95C881C0F827BFB00F51A22 /* ToolbarRemoveTemplate.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ToolbarRemoveTemplate.png; path = images/ToolbarRemoveTemplate.png; sourceTree = "<group>"; };
|
A95C881C0F827BFB00F51A22 /* ToolbarRemoveTemplate.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ToolbarRemoveTemplate.png; path = images/ToolbarRemoveTemplate.png; sourceTree = "<group>"; };
|
||||||
A960E96117D4B00900FC6ED9 /* SBImageBrowserView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBImageBrowserView.h; path = Classes/SBImageBrowserView.h; sourceTree = "<group>"; };
|
A960E96117D4B00900FC6ED9 /* SBImageBrowserView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBImageBrowserView.h; path = Classes/SBImageBrowserView.h; sourceTree = "<group>"; };
|
||||||
A960E96217D4B00900FC6ED9 /* SBImageBrowserView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SBImageBrowserView.m; path = Classes/SBImageBrowserView.m; sourceTree = "<group>"; };
|
A960E96217D4B00900FC6ED9 /* SBImageBrowserView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SBImageBrowserView.m; path = Classes/SBImageBrowserView.m; sourceTree = "<group>"; };
|
||||||
@@ -373,8 +370,6 @@
|
|||||||
32DBCF750370BD2300C91783 /* Subler_Prefix.pch */,
|
32DBCF750370BD2300C91783 /* Subler_Prefix.pch */,
|
||||||
A9B46A9312B79B990040517A /* ButtonToolbarItem.h */,
|
A9B46A9312B79B990040517A /* ButtonToolbarItem.h */,
|
||||||
A9B46A9412B79B990040517A /* ButtonToolbarItem.m */,
|
A9B46A9412B79B990040517A /* ButtonToolbarItem.m */,
|
||||||
A936E03C130BE10200CA5527 /* MAAttachedWindow.h */,
|
|
||||||
A936E03D130BE10200CA5527 /* MAAttachedWindow.m */,
|
|
||||||
2A37F4B0FDCFA73011CA2CEA /* main.m */,
|
2A37F4B0FDCFA73011CA2CEA /* main.m */,
|
||||||
);
|
);
|
||||||
name = "Other Sources";
|
name = "Other Sources";
|
||||||
@@ -727,7 +722,6 @@
|
|||||||
A9AB485717F0AEAC000AA72E /* SBSoundViewController.m in Sources */,
|
A9AB485717F0AEAC000AA72E /* SBSoundViewController.m in Sources */,
|
||||||
A9C828F5195950C3004C4718 /* SBQueuePreferences.m in Sources */,
|
A9C828F5195950C3004C4718 /* SBQueuePreferences.m in Sources */,
|
||||||
CD56963212FAAD680029FADB /* SBArtworkSelector.m in Sources */,
|
CD56963212FAAD680029FADB /* SBArtworkSelector.m in Sources */,
|
||||||
A936E03E130BE10200CA5527 /* MAAttachedWindow.m in Sources */,
|
|
||||||
A961476313F567E10068F161 /* SBQueueController.m in Sources */,
|
A961476313F567E10068F161 /* SBQueueController.m in Sources */,
|
||||||
A961476413F567E10068F161 /* SBPresetManager.m in Sources */,
|
A961476413F567E10068F161 /* SBPresetManager.m in Sources */,
|
||||||
A982D0C0140AB66400B92357 /* SBQueueItem.m in Sources */,
|
A982D0C0140AB66400B92357 /* SBQueueItem.m in Sources */,
|
||||||
@@ -912,7 +906,7 @@
|
|||||||
INSTALL_PATH = "$(HOME)/Applications";
|
INSTALL_PATH = "$(HOME)/Applications";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "";
|
LD_RUNPATH_SEARCH_PATHS = "";
|
||||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.6;
|
MACOSX_DEPLOYMENT_TARGET = 10.7;
|
||||||
PRODUCT_NAME = Subler;
|
PRODUCT_NAME = Subler;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
};
|
};
|
||||||
@@ -937,7 +931,7 @@
|
|||||||
INSTALL_PATH = "$(HOME)/Applications";
|
INSTALL_PATH = "$(HOME)/Applications";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "";
|
LD_RUNPATH_SEARCH_PATHS = "";
|
||||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.6;
|
MACOSX_DEPLOYMENT_TARGET = 10.7;
|
||||||
PRODUCT_NAME = Subler;
|
PRODUCT_NAME = Subler;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user