Repository: indragiek/INPopoverController Branch: master Commit: ba272ac695df Files: 32 Total size: 140.2 KB Directory structure: gitextract_bwryhk85/ ├── .gitignore ├── INPopoverController/ │ ├── INPopoverController-Info.plist │ ├── INPopoverController.h │ ├── INPopoverController.m │ ├── INPopoverControllerDefines.h │ ├── INPopoverParentWindow.h │ ├── INPopoverParentWindow.m │ ├── INPopoverPrefixHeader.pch │ ├── INPopoverWindow.h │ ├── INPopoverWindow.m │ ├── INPopoverWindowFrame.h │ └── INPopoverWindowFrame.m ├── INPopoverController.podspec ├── INPopoverController.xcodeproj/ │ ├── project.pbxproj │ └── project.xcworkspace/ │ └── contents.xcworkspacedata ├── LICENSE ├── PopoverSampleApp/ │ ├── PopoverSampleApp/ │ │ ├── AlphaColorWell.h │ │ ├── AlphaColorWell.m │ │ ├── ContentViewController.h │ │ ├── ContentViewController.m │ │ ├── ContentViewController.xib │ │ ├── PopoverSampleApp-Info.plist │ │ ├── PopoverSampleApp-Prefix.pch │ │ ├── PopoverSampleAppAppDelegate.h │ │ ├── PopoverSampleAppAppDelegate.m │ │ ├── en.lproj/ │ │ │ ├── Credits.rtf │ │ │ ├── InfoPlist.strings │ │ │ └── MainMenu.xib │ │ └── main.m │ └── PopoverSampleApp.xcodeproj/ │ ├── project.pbxproj │ └── project.xcworkspace/ │ └── contents.xcworkspacedata └── README.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # OS X .DS_Store # Xcode build/ *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 xcuserdata *.xccheckout profile *.moved-aside DerivedData *.hmap *.ipa # CocoaPods Pods # AppCode .idea/ ================================================ FILE: INPopoverController/INPopoverController-Info.plist ================================================ CFBundleDevelopmentRegion English CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIconFile CFBundleIdentifier com.indragie.INPopoverController.${PRODUCT_NAME:rfc1034identifier} CFBundleInfoDictionaryVersion 6.0 CFBundleName ${PRODUCT_NAME} CFBundlePackageType FMWK CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion 1 NSHumanReadableCopyright Copyright © 2011 Indragie Karunaratne. All rights reserved. NSPrincipalClass ================================================ FILE: INPopoverController/INPopoverController.h ================================================ // // INPopoverController.h // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import #import "INPopoverControllerDefines.h" @protocol INPopoverControllerDelegate; @interface INPopoverController : NSObject #pragma mark - #pragma mark Properties /** The delegate of the INPopoverController object (should conform to the INPopoverControllerDelegate protocol) **/ @property (nonatomic, assign) id delegate; /** The background color of the popover. Default value is [NSColor blackColor] with an alpha value of 0.8. Changes to this value are not animated. **/ @property (nonatomic, strong) NSColor *color; /** Border color to use when drawing a border. Default value: [NSColor blackColor]. Changes to this value are not animated. **/ @property (nonatomic, strong) NSColor *borderColor; /** Color to use for drawing a 1px highlight just below the top. Can be nil. Changes to this value are not animated. **/ @property (nonatomic, strong) NSColor *topHighlightColor; /** The width of the popover border, drawn using borderColor. Default value: 0.0 (no border). Changes to this value are not animated. **/ @property (nonatomic, assign) CGFloat borderWidth; /** Corner radius of the popover window. Default value: 4. Changes to this value are not animated. **/ @property (nonatomic, assign) CGFloat cornerRadius; /** The size of the popover arrow. Default value: {23, 12}. Changes to this value are not animated. **/ @property (nonatomic, assign) NSSize arrowSize; /** The current arrow direction of the popover. If the popover has never been displayed, then this will return INPopoverArrowDirectionUndefined */ @property (nonatomic, assign, readonly) INPopoverArrowDirection arrowDirection; /** The size of the content of the popover. This is automatically set to contentViewController's size when the view controller is set, but can be modified. Changes to this value are animated when animates is set to YES **/ @property (nonatomic, assign) NSSize contentSize; /** Whether the popover closes when user presses escape key. Default value: YES */ @property (nonatomic, assign) BOOL closesWhenEscapeKeyPressed; /** Whether the popover closes when the popover window resigns its key status. Default value: YES **/ @property (nonatomic, assign) BOOL closesWhenPopoverResignsKey; /** Whether the popover closes when the application becomes inactive. Default value: NO **/ @property (nonatomic, assign) BOOL closesWhenApplicationBecomesInactive; /** Enable or disable animation when showing/closing the popover and changing the content size. Default value: YES */ @property (nonatomic, assign) BOOL animates; /* If `animates` is `YES`, this is the animation type to use when showing/closing the popover. Default value: `INPopoverAnimationTypePop` **/ @property (nonatomic, assign) INPopoverAnimationType animationType; /** The content view controller from which content is displayed in the popover **/ @property (nonatomic, strong) NSViewController *contentViewController; /** The view that the currently displayed popover is positioned relative to. If there is no popover being displayed, this returns nil. **/ @property (nonatomic, strong, readonly) NSView *positionView; /** The window of the popover **/ @property (nonatomic, strong, readonly) NSWindow *popoverWindow; /** Whether the popover is currently visible or not **/ @property (nonatomic, assign, readonly) BOOL popoverIsVisible; #pragma mark - #pragma mark Methods /** Initializes the popover with a content view already set. @param viewController the content view controller @returns a new instance of INPopoverController */ - (id)initWithContentViewController:(NSViewController *)viewController; /** Displays the popover. @param rect the rect in the positionView from which to display the popover @param positionView the view that the popover is positioned relative to @param direction the prefered direction at which the arrow will point. There is no guarantee that this will be the actual arrow direction, depending on whether the screen is able to accomodate the popover in that position. @param anchors Whether the popover binds to the frame of the positionView. This means that if the positionView is resized or moved, the popover will be repositioned according to the point at which it was originally placed. This also means that if the positionView goes off screen, the popover will be automatically closed. **/ - (void)presentPopoverFromRect:(NSRect)rect inView:(NSView *)positionView preferredArrowDirection:(INPopoverArrowDirection)direction anchorsToPositionView:(BOOL)anchors; /** Recalculates the best arrow direction for the current window position and resets the arrow direction. The change will not be animated. **/ - (void)recalculateAndResetArrowDirection; /** Closes the popover unless NO is returned for the -popoverShouldClose: delegate method @param sender the object that sent this message */ - (IBAction)closePopover:(id)sender; /** Closes the popover regardless of what the delegate returns @param sender the object that sent this message */ - (IBAction)forceClosePopover:(id)sender; /** Returns the frame for a popop window with a given size depending on the arrow direction. @param contentSize the popover window content size @param direction the arrow direction */ - (NSRect)popoverFrameWithSize:(NSSize)contentSize andArrowDirection:(INPopoverArrowDirection)direction; @end @protocol INPopoverControllerDelegate @optional /** When the -closePopover: method is invoked, this method is called to give a change for the delegate to prevent it from closing. Returning NO for this delegate method will prevent the popover being closed. This delegate method does not apply to the -forceClosePopover: method, which will close the popover regardless of what the delegate returns. @param popover the @class INPopoverController object that is controlling the popover @returns whether the popover should close or not */ - (BOOL)popoverShouldClose:(INPopoverController *)popover; /** Invoked right before the popover shows on screen @param popover the @class INPopoverController object that is controlling the popover */ - (void)popoverWillShow:(INPopoverController *)popover; /** Invoked right after the popover shows on screen @param popover the @class INPopoverController object that is controlling the popover */ - (void)popoverDidShow:(INPopoverController *)popover; /** Invoked right before the popover closes @param popover the @class INPopoverController object that is controlling the popover */ - (void)popoverWillClose:(INPopoverController *)popover; /** Invoked right after the popover closes @param popover the @class INPopoverController object that is controlling the popover */ - (void)popoverDidClose:(INPopoverController *)popover; @end ================================================ FILE: INPopoverController/INPopoverController.m ================================================ // // INPopoverController.m // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import "INPopoverController.h" #import "INPopoverWindow.h" #import "INPopoverWindowFrame.h" #import "INPopoverParentWindow.h" #include @implementation INPopoverController { INPopoverWindow *_popoverWindow; NSRect _screenRect; NSRect _viewRect; } #pragma mark - #pragma mark Initialization - (id)init { if ((self = [super init])) { [self _setInitialPropertyValues]; } return self; } - (void)awakeFromNib { [super awakeFromNib]; [self _setInitialPropertyValues]; } #pragma mark - #pragma mark - Memory Management - (void)dealloc { _popoverWindow.popoverController = nil; } #pragma mark - #pragma mark Public Methods - (id)initWithContentViewController:(NSViewController *)viewController { if ((self = [super init])) { [self _setInitialPropertyValues]; self.contentViewController = viewController; } return self; } - (void)presentPopoverFromRect:(NSRect)rect inView:(NSView *)positionView preferredArrowDirection:(INPopoverArrowDirection)direction anchorsToPositionView:(BOOL)anchors { if (self.popoverIsVisible) {return;} // If it's already visible, do nothing NSWindow *mainWindow = [positionView window]; _positionView = positionView; _viewRect = rect; _screenRect = [positionView convertRect:rect toView:nil]; // Convert the rect to window coordinates _screenRect.origin = [mainWindow convertBaseToScreen:_screenRect.origin]; // Convert window coordinates to screen coordinates INPopoverArrowDirection calculatedDirection = [self _arrowDirectionWithPreferredArrowDirection:direction]; // Calculate the best arrow direction [self _setArrowDirection:calculatedDirection]; // Change the arrow direction of the popover NSRect windowFrame = [self popoverFrameWithSize:self.contentSize andArrowDirection:calculatedDirection]; // Calculate the window frame based on the arrow direction [_popoverWindow setFrame:windowFrame display:YES]; // Se the frame of the window [[_popoverWindow animationForKey:@"alphaValue"] setDelegate:self]; // Show the popover [self _callDelegateMethod:@selector(popoverWillShow:)]; // Call the delegate if (self.animates && self.animationType != INPopoverAnimationTypeFadeOut) { // Animate the popover in [_popoverWindow presentAnimated]; } else { [_popoverWindow setAlphaValue:1.0]; [mainWindow addChildWindow:_popoverWindow ordered:NSWindowAbove]; // Add the popover as a child window of the main window [_popoverWindow makeKeyAndOrderFront:nil]; // Show the popover [self _callDelegateMethod:@selector(popoverDidShow:)]; // Call the delegate } NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; if (anchors) { // If the anchors option is enabled, register for frame change notifications [nc addObserver:self selector:@selector(_positionViewFrameChanged:) name:NSViewFrameDidChangeNotification object:self.positionView]; } // When -closesWhenPopoverResignsKey is set to YES, the popover will automatically close when the popover loses its key status if (self.closesWhenPopoverResignsKey) { [nc addObserver:self selector:@selector(closePopover:) name:NSWindowDidResignKeyNotification object:_popoverWindow]; if (!self.closesWhenApplicationBecomesInactive) { [nc addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:nil]; } } else if (self.closesWhenApplicationBecomesInactive) { // this is only needed if closesWhenPopoverResignsKey is NO, otherwise we already get a "resign key" notification when resigning active [nc addObserver:self selector:@selector(closePopover:) name:NSApplicationDidResignActiveNotification object:nil]; } } - (void)recalculateAndResetArrowDirection { INPopoverArrowDirection direction = [self _arrowDirectionWithPreferredArrowDirection:self.arrowDirection]; [self _setArrowDirection:direction]; } - (IBAction)closePopover:(id)sender { if (![_popoverWindow isVisible]) {return;} if ([sender isKindOfClass:[NSNotification class]] && [[(NSNotification *) sender name] isEqualToString:NSWindowDidResignKeyNotification]) { // ignore "resign key" notification sent when app becomes inactive unless closesWhenApplicationBecomesInactive is enabled if (!self.closesWhenApplicationBecomesInactive && ![NSApp isActive]) return; } BOOL close = YES; // Check to see if the delegate has implemented the -popoverShouldClose: method if ([self.delegate respondsToSelector:@selector(popoverShouldClose:)]) { close = [self.delegate popoverShouldClose:self]; } if (close) {[self forceClosePopover:nil];} } - (IBAction)forceClosePopover:(id)sender { if (![_popoverWindow isVisible]) {return;} [self _callDelegateMethod:@selector(popoverWillClose:)]; // Call delegate if (self.animates && self.animationType != INPopoverAnimationTypeFadeIn) { [_popoverWindow dismissAnimated]; } else { [self _closePopoverAndResetVariables]; } } // Calculate the frame of the window depending on the arrow direction - (NSRect)popoverFrameWithSize:(NSSize)contentSize andArrowDirection:(INPopoverArrowDirection)direction { NSRect contentRect = NSZeroRect; contentRect.size = contentSize; NSRect windowFrame = [_popoverWindow frameRectForContentRect:contentRect]; if (direction == INPopoverArrowDirectionUp) { CGFloat xOrigin = NSMidX(_screenRect) - floor(windowFrame.size.width / 2.0); CGFloat yOrigin = NSMinY(_screenRect) - windowFrame.size.height; windowFrame.origin = NSMakePoint(xOrigin, yOrigin); } else if (direction == INPopoverArrowDirectionDown) { CGFloat xOrigin = NSMidX(_screenRect) - floor(windowFrame.size.width / 2.0); windowFrame.origin = NSMakePoint(xOrigin, NSMaxY(_screenRect)); } else if (direction == INPopoverArrowDirectionLeft) { CGFloat yOrigin = NSMidY(_screenRect) - floor(windowFrame.size.height / 2.0); windowFrame.origin = NSMakePoint(NSMaxX(_screenRect), yOrigin); } else if (direction == INPopoverArrowDirectionRight) { CGFloat xOrigin = NSMinX(_screenRect) - windowFrame.size.width; CGFloat yOrigin = NSMidY(_screenRect) - floor(windowFrame.size.height / 2.0); windowFrame.origin = NSMakePoint(xOrigin, yOrigin); } else { // If no arrow direction is specified, just return an empty rect windowFrame = NSZeroRect; } return windowFrame; } - (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag { #pragma unused(animation) #pragma unused(flag) // Detect the end of fade out and close the window if (0.0 == [_popoverWindow alphaValue]) [self _closePopoverAndResetVariables]; else if (1.0 == [_popoverWindow alphaValue]) { [[_positionView window] addChildWindow:_popoverWindow ordered:NSWindowAbove]; [self _callDelegateMethod:@selector(popoverDidShow:)]; } } - (void)applicationDidBecomeActive:(NSNotification *)notification { // when the user clicks in the parent window for activating the app, the parent window becomes key which prevents if ([_popoverWindow isVisible]) [self performSelector:@selector(checkPopoverKeyWindowStatus) withObject:nil afterDelay:0]; } - (void)checkPopoverKeyWindowStatus { id parentWindow = [_positionView window]; // could be INPopoverParentWindow BOOL isKey = [parentWindow respondsToSelector:@selector(isReallyKeyWindow)] ? [parentWindow isReallyKeyWindow] : [parentWindow isKeyWindow]; if (isKey) [_popoverWindow makeKeyWindow]; } #pragma mark - #pragma mark Getters - (NSColor *)color { return _popoverWindow.frameView.color; } - (CGFloat)borderWidth { return _popoverWindow.frameView.borderWidth; } - (NSColor *)borderColor { return _popoverWindow.frameView.borderColor; } - (NSColor *)topHighlightColor { return _popoverWindow.frameView.topHighlightColor; } - (CGFloat)cornerRadius { return _popoverWindow.frameView.cornerRadius; } - (NSSize)arrowSize { return _popoverWindow.frameView.arrowSize; } - (INPopoverArrowDirection)arrowDirection { return _popoverWindow.frameView.arrowDirection; } - (NSView *)contentView { return [_popoverWindow popoverContentView]; } - (BOOL)popoverIsVisible { return [_popoverWindow isVisible]; } #pragma mark - #pragma mark Setters - (void)setColor:(NSColor *)newColor { _popoverWindow.frameView.color = newColor; } - (void)setBorderWidth:(CGFloat)newBorderWidth { _popoverWindow.frameView.borderWidth = newBorderWidth; } - (void)setBorderColor:(NSColor *)newBorderColor { _popoverWindow.frameView.borderColor = newBorderColor; } - (void)setTopHighlightColor:(NSColor *)newTopHighlightColor { _popoverWindow.frameView.topHighlightColor = newTopHighlightColor; } - (void)setCornerRadius:(CGFloat)cornerRadius { _popoverWindow.frameView.cornerRadius = cornerRadius; } - (void)setArrowSize:(NSSize)arrowSize { _popoverWindow.frameView.arrowSize = arrowSize; } - (void)setContentViewController:(NSViewController *)newContentViewController { if (_contentViewController != newContentViewController) { [_popoverWindow setPopoverContentView:nil]; // Clear the content view _contentViewController = newContentViewController; NSView *contentView = [_contentViewController view]; self.contentSize = [contentView frame].size; [_popoverWindow setPopoverContentView:contentView]; } } - (void)setContentSize:(NSSize)newContentSize { // We use -frameRectForContentRect: just to get the frame size because the origin it returns is not the one we want to use. Instead, -windowFrameWithSize:andArrowDirection: is used to complete the frame _contentSize = newContentSize; NSRect adjustedRect = [self popoverFrameWithSize:newContentSize andArrowDirection:self.arrowDirection]; [_popoverWindow setFrame:adjustedRect display:YES animate:self.animates]; } - (void)_setArrowDirection:(INPopoverArrowDirection)direction { _popoverWindow.frameView.arrowDirection = direction; } #pragma mark - #pragma mark Private // Set the default values for all the properties as described in the header documentation - (void)_setInitialPropertyValues { // Create an empty popover window _popoverWindow = [[INPopoverWindow alloc] initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; _popoverWindow.popoverController = self; // set defaults like iCal popover self.color = [NSColor colorWithCalibratedWhite:0.94 alpha:0.92]; self.borderColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.92]; self.borderWidth = 1.0; self.closesWhenEscapeKeyPressed = YES; self.closesWhenPopoverResignsKey = YES; self.closesWhenApplicationBecomesInactive = NO; self.animates = YES; self.animationType = INPopoverAnimationTypePop; // create animation to get callback - delegate is set when opening popover to avoid memory cycles CAAnimation *animation = [CABasicAnimation animation]; [_popoverWindow setAnimations:[NSDictionary dictionaryWithObject:animation forKey:@"alphaValue"]]; } // Figure out which direction best stays in screen bounds - (INPopoverArrowDirection)_arrowDirectionWithPreferredArrowDirection:(INPopoverArrowDirection)direction { NSRect screenFrame = [[[_positionView window] screen] frame]; // If the window with the preferred arrow direction already falls within the screen bounds then no need to go any further NSRect windowFrame = [self popoverFrameWithSize:self.contentSize andArrowDirection:direction]; if (NSContainsRect(screenFrame, windowFrame)) { return direction; } // First thing to try is making the popover go opposite of its current direction INPopoverArrowDirection newDirection = INPopoverArrowDirectionUndefined; switch (direction) { case INPopoverArrowDirectionUp: newDirection = INPopoverArrowDirectionDown; break; case INPopoverArrowDirectionDown: newDirection = INPopoverArrowDirectionUp; break; case INPopoverArrowDirectionLeft: newDirection = INPopoverArrowDirectionRight; break; case INPopoverArrowDirectionRight: newDirection = INPopoverArrowDirectionLeft; break; default: break; } // If the popover now fits within bounds, then return the newly adjusted direction windowFrame = [self popoverFrameWithSize:self.contentSize andArrowDirection:newDirection]; if (NSContainsRect(screenFrame, windowFrame)) { return newDirection; } // Calculate the remaining space on each side and figure out which would be the best to try next CGFloat left = NSMinX(_screenRect); CGFloat right = screenFrame.size.width - NSMaxX(_screenRect); CGFloat up = screenFrame.size.height - NSMaxY(_screenRect); CGFloat down = NSMinY(_screenRect); BOOL arrowLeft = (right > left); BOOL arrowUp = (down > up); // Now the next thing to try is the direction with the most space switch (direction) { case INPopoverArrowDirectionUp: case INPopoverArrowDirectionDown: newDirection = arrowLeft ? INPopoverArrowDirectionLeft : INPopoverArrowDirectionRight; case INPopoverArrowDirectionLeft: case INPopoverArrowDirectionRight: newDirection = arrowUp ? INPopoverArrowDirectionUp : INPopoverArrowDirectionDown; break; default: break; } // If the popover now fits within bounds, then return the newly adjusted direction windowFrame = [self popoverFrameWithSize:self.contentSize andArrowDirection:newDirection]; if (NSContainsRect(screenFrame, windowFrame)) { return newDirection; } // If that didn't fit, then that means that it will be out of bounds on every side so just return the original direction return direction; } - (void)_positionViewFrameChanged:(NSNotification *)notification { NSRect superviewBounds = [[self.positionView superview] bounds]; if (!(NSContainsRect(superviewBounds, [self.positionView frame]))) { [self forceClosePopover:nil]; // If the position view goes off screen then close the popover return; } NSRect newFrame = [_popoverWindow frame]; _screenRect = [self.positionView convertRect:_viewRect toView:nil]; // Convert the rect to window coordinates _screenRect.origin = [[self.positionView window] convertBaseToScreen:_screenRect.origin]; // Convert window coordinates to screen coordinates NSRect calculatedFrame = [self popoverFrameWithSize:self.contentSize andArrowDirection:self.arrowDirection]; // Calculate the window frame based on the arrow direction newFrame.origin = calculatedFrame.origin; [_popoverWindow setFrame:newFrame display:YES animate:NO]; // Set the frame of the window } - (void)_closePopoverAndResetVariables { NSWindow *positionWindow = [self.positionView window]; [_popoverWindow orderOut:nil]; // Close the window [self _callDelegateMethod:@selector(popoverDidClose:)]; // Call the delegate to inform that the popover has closed [positionWindow removeChildWindow:_popoverWindow]; // Remove it as a child window [positionWindow makeKeyAndOrderFront:nil]; // Clear all the ivars [self _setArrowDirection:INPopoverArrowDirectionUndefined]; [[NSNotificationCenter defaultCenter] removeObserver:self]; _positionView = nil; _screenRect = NSZeroRect; _viewRect = NSZeroRect; // When using ARC and no animation, there is a "message sent to deallocated instance" crash if setDelegate: is not performed at the end of the event. [[_popoverWindow animationForKey:@"alphaValue"] performSelector:@selector(setDelegate:) withObject:nil afterDelay:0]; } - (void)_callDelegateMethod:(SEL)selector { if ([self.delegate respondsToSelector:selector]) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" [self.delegate performSelector:selector withObject:self]; #pragma clang diagnostic pop } } @end ================================================ FILE: INPopoverController/INPopoverControllerDefines.h ================================================ // // INPopoverControllerDefines.h // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // typedef NS_ENUM(NSUInteger, INPopoverArrowDirection) { INPopoverArrowDirectionUndefined = 0, INPopoverArrowDirectionLeft, INPopoverArrowDirectionRight, INPopoverArrowDirectionUp, INPopoverArrowDirectionDown }; typedef NS_ENUM(NSInteger, INPopoverAnimationType) { INPopoverAnimationTypePop = 0, // Pop animation similar to NSPopover INPopoverAnimationTypeFadeIn, // Fade in only, no fade out INPopoverAnimationTypeFadeOut, // Fade out only, no fade in INPopoverAnimationTypeFadeInOut // Fade in and out }; ================================================ FILE: INPopoverController/INPopoverParentWindow.h ================================================ // // INPopoverParentWindow.h // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import @interface INPopoverParentWindow : NSWindow - (BOOL)isReallyKeyWindow; @end ================================================ FILE: INPopoverController/INPopoverParentWindow.m ================================================ // // INAlwaysKeyWindow.m // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import "INPopoverParentWindow.h" #import "INPopoverWindow.h" @implementation INPopoverParentWindow - (BOOL)isKeyWindow { BOOL isKey = [super isKeyWindow]; if (!isKey) { for (NSWindow *childWindow in [self childWindows]) { if ([childWindow isKindOfClass:[INPopoverWindow class]]) { // if we have popover attached, window is key if app is active isKey = [NSApp isActive]; break; } } } return isKey; } - (BOOL)isReallyKeyWindow { return [super isKeyWindow]; } @end ================================================ FILE: INPopoverController/INPopoverPrefixHeader.pch ================================================ #ifdef __OBJC__ #import #endif ================================================ FILE: INPopoverController/INPopoverWindow.h ================================================ // // INPopoverWindow.h // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import #import "INPopoverControllerDefines.h" /** @class INPopoverWindow An NSWindow subclass used to draw a custom window frame (@class INPopoverWindowFrame) **/ @class INPopoverWindowFrame; @class INPopoverController; @interface INPopoverWindow : NSPanel @property (nonatomic, readonly) INPopoverWindowFrame *frameView; // Equivalent to contentView @property (nonatomic, assign) INPopoverController *popoverController; @property (nonatomic, strong) NSView *popoverContentView; - (void)presentAnimated; - (void)dismissAnimated; @end ================================================ FILE: INPopoverController/INPopoverWindow.m ================================================ // // INPopoverWindow.m // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import "INPopoverWindow.h" #import "INPopoverControllerDefines.h" #import "INPopoverWindowFrame.h" #import "INPopoverController.h" #import #define START_SIZE NSMakeSize(20, 20) #define OVERSHOOT_FACTOR 1.2 // A lot of this code was adapted from the following article: // @implementation INPopoverWindow { NSView *_popoverContentView; NSWindow *_zoomWindow; } // Borderless, transparent window - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation { if ((self = [super initWithContentRect:contentRect styleMask:NSNonactivatingPanelMask backing:bufferingType defer:deferCreation])) { [self setOpaque:NO]; [self setBackgroundColor:[NSColor clearColor]]; [self setHasShadow:YES]; } return self; } // Leave some space around the content for drawing the arrow - (NSRect)contentRectForFrameRect:(NSRect)windowFrame { windowFrame.origin = NSZeroPoint; const CGFloat arrowHeight = self.frameView.arrowSize.height; return NSInsetRect(windowFrame, arrowHeight, arrowHeight); } - (NSRect)frameRectForContentRect:(NSRect)contentRect { const CGFloat arrowHeight = self.frameView.arrowSize.height; return NSInsetRect(contentRect, -arrowHeight, -arrowHeight); } // Allow the popover to become the key window - (BOOL)canBecomeKeyWindow { return YES; } - (BOOL)canBecomeMainWindow { return NO; } - (BOOL)isVisible { return [super isVisible] || [_zoomWindow isVisible]; } - (INPopoverWindowFrame *)frameView { return (INPopoverWindowFrame *) [self contentView]; } - (void)setContentView:(NSView *)aView { [self setPopoverContentView:aView]; } - (void)setPopoverContentView:(NSView *)aView { if ([_popoverContentView isEqualTo:aView]) {return;} NSRect bounds = [self frame]; bounds.origin = NSZeroPoint; INPopoverWindowFrame *frameView = [self frameView]; if (!frameView) { frameView = [[INPopoverWindowFrame alloc] initWithFrame:bounds]; [super setContentView:frameView]; // Call on super or there will be infinite loop } if (_popoverContentView) { [_popoverContentView removeFromSuperview]; } _popoverContentView = aView; [_popoverContentView setFrame:[self contentRectForFrameRect:bounds]]; [_popoverContentView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [frameView addSubview:_popoverContentView]; } - (void)presentAnimated { if ([self isVisible]) return; switch (self.popoverController.animationType) { case INPopoverAnimationTypePop: [self presentWithPopAnimation]; break; case INPopoverAnimationTypeFadeIn: case INPopoverAnimationTypeFadeInOut: [self presentWithFadeAnimation]; break; default: break; } } - (void)presentWithPopAnimation { NSRect endFrame = [self frame]; NSRect startFrame = [self.popoverController popoverFrameWithSize:START_SIZE andArrowDirection:self.frameView.arrowDirection]; NSRect overshootFrame = [self.popoverController popoverFrameWithSize:NSMakeSize(endFrame.size.width * OVERSHOOT_FACTOR, endFrame.size.height * OVERSHOOT_FACTOR) andArrowDirection:self.frameView.arrowDirection]; _zoomWindow = [self _zoomWindowWithRect:startFrame]; [_zoomWindow setAlphaValue:0.0]; [_zoomWindow orderFront:self]; // configure bounce-out animation CAKeyframeAnimation *anim = [CAKeyframeAnimation animation]; [anim setDelegate:self]; [anim setValues:[NSArray arrayWithObjects:[NSValue valueWithRect:startFrame], [NSValue valueWithRect:overshootFrame], [NSValue valueWithRect:endFrame], nil]]; [_zoomWindow setAnimations:[NSDictionary dictionaryWithObjectsAndKeys:anim, @"frame", nil]]; [NSAnimationContext beginGrouping]; [[_zoomWindow animator] setAlphaValue:1.0]; [[_zoomWindow animator] setFrame:endFrame display:YES]; [NSAnimationContext endGrouping]; } - (void)presentWithFadeAnimation { [self setAlphaValue:0.0]; [self makeKeyAndOrderFront:nil]; [[self animator] setAlphaValue:1.0]; } - (void)dismissAnimated { [[_zoomWindow animator] setAlphaValue:0.0]; // in case zoom window is currently animating [[self animator] setAlphaValue:0.0]; } - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { [self setAlphaValue:1.0]; [self makeKeyAndOrderFront:self]; [_zoomWindow close]; _zoomWindow = nil; // call the animation delegate of the "real" window CAAnimation *windowAnimation = [self animationForKey:@"alphaValue"]; [[windowAnimation delegate] animationDidStop:anim finished:flag]; } - (void)cancelOperation:(id)sender { if (self.popoverController.closesWhenEscapeKeyPressed) [self.popoverController closePopover:nil]; } #pragma mark - #pragma mark Private // The following method is adapted from the following class: // // Copyright 2007-2009 Noodlesoft, LLC. All rights reserved. - (NSWindow *)_zoomWindowWithRect:(NSRect)rect { BOOL isOneShot = [self isOneShot]; if (isOneShot) [self setOneShot:NO]; if ([self windowNumber] <= 0) { // force creation of window device by putting it on-screen. We make it transparent to minimize the chance of visible flicker CGFloat alpha = [self alphaValue]; [self setAlphaValue:0.0]; [self orderBack:self]; [self orderOut:self]; [self setAlphaValue:alpha]; } // get window content as image NSRect frame = [self frame]; NSImage *image = [[NSImage alloc] initWithSize:frame.size]; [self displayIfNeeded]; // refresh view NSView *view = self.contentView; NSBitmapImageRep *imageRep = [view bitmapImageRepForCachingDisplayInRect:view.bounds]; [view cacheDisplayInRect:view.bounds toBitmapImageRep:imageRep]; [image addRepresentation:imageRep]; // create zoom window NSWindow *zoomWindow = [[NSWindow alloc] initWithContentRect:rect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; [zoomWindow setBackgroundColor:[NSColor clearColor]]; [zoomWindow setHasShadow:[self hasShadow]]; [zoomWindow setLevel:[self level]]; [zoomWindow setOpaque:NO]; [zoomWindow setReleasedWhenClosed:NO]; [zoomWindow useOptimizedDrawing:YES]; NSImageView *imageView = [[NSImageView alloc] initWithFrame:[zoomWindow contentRectForFrameRect:frame]]; [imageView setImage:image]; [imageView setImageFrameStyle:NSImageFrameNone]; [imageView setImageScaling:NSScaleToFit]; [imageView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [zoomWindow setContentView:imageView]; // reset one shot flag [self setOneShot:isOneShot]; return zoomWindow; } @end ================================================ FILE: INPopoverController/INPopoverWindowFrame.h ================================================ // // INPopoverWindowFrame.h // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import #import "INPopoverControllerDefines.h" /** @class INPopoverWindowFrame The NSView subclass responsible for drawing the frame of the popover */ @interface INPopoverWindowFrame : NSView @property (nonatomic, strong) NSColor *color; @property (nonatomic, strong) NSColor *borderColor; @property (nonatomic, strong) NSColor *topHighlightColor; @property (nonatomic, assign) CGFloat borderWidth; @property (nonatomic, assign) CGFloat cornerRadius; @property (nonatomic, assign) NSSize arrowSize; @property (nonatomic, assign) INPopoverArrowDirection arrowDirection; @end ================================================ FILE: INPopoverController/INPopoverWindowFrame.m ================================================ // // INPopoverWindowFrame.m // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import "INPopoverWindowFrame.h" @implementation INPopoverWindowFrame - (id)initWithFrame:(NSRect)frame { if ((self = [super initWithFrame:frame])) { _color = [NSColor colorWithCalibratedWhite:0.0 alpha:0.8]; _cornerRadius = 4.0; _arrowSize = NSMakeSize(23.0, 12.0); _arrowDirection = INPopoverArrowDirectionLeft; } return self; } - (void)drawRect:(NSRect)dirtyRect { NSRect bounds = [self bounds]; if (((NSUInteger) self.borderWidth % 2) == 1) { // Remove draw glitch on odd border width bounds = NSInsetRect(bounds, 0.5, 0.5); } NSBezierPath *path = [self _popoverBezierPathWithRect:bounds]; if (self.color) { [self.color set]; [path fill]; } if (self.borderWidth > 0) { [path setLineWidth:self.borderWidth]; [self.borderColor set]; [path stroke]; } const CGFloat arrowWidth = self.arrowSize.width; const CGFloat arrowHeight = self.arrowSize.height; const CGFloat radius = self.cornerRadius; if (self.topHighlightColor) { [self.topHighlightColor set]; NSRect bounds = NSInsetRect([self bounds], arrowHeight, arrowHeight); NSRect lineRect = NSMakeRect(floor(NSMinX(bounds) + (radius / 2.0)), NSMaxY(bounds) - self.borderWidth - 1, NSWidth(bounds) - radius, 1.0); if (self.arrowDirection == INPopoverArrowDirectionUp) { CGFloat width = floor((lineRect.size.width / 2.0) - (arrowWidth / 2.0)); NSRectFill(NSMakeRect(lineRect.origin.x, lineRect.origin.y, width, lineRect.size.height)); NSRectFill(NSMakeRect(floor(lineRect.origin.x + (lineRect.size.width / 2.0) + (arrowWidth / 2.0)), lineRect.origin.y, width, lineRect.size.height)); } else { NSRectFill(lineRect); } } } #pragma mark - #pragma mark Private - (NSBezierPath *)_popoverBezierPathWithRect:(NSRect)aRect { const CGFloat radius = self.cornerRadius; const CGFloat arrowWidth = self.arrowSize.width; const CGFloat arrowHeight = self.arrowSize.height; const CGFloat inset = radius + arrowHeight; const NSRect drawingRect = NSInsetRect(aRect, inset, inset); const CGFloat minX = NSMinX(drawingRect); const CGFloat maxX = NSMaxX(drawingRect); const CGFloat minY = NSMinY(drawingRect); const CGFloat maxY = NSMaxY(drawingRect); NSBezierPath *path = [NSBezierPath bezierPath]; [path setLineJoinStyle:NSRoundLineJoinStyle]; // Bottom left corner [path appendBezierPathWithArcWithCenter:NSMakePoint(minX, minY) radius:radius startAngle:180.0 endAngle:270.0]; if (self.arrowDirection == INPopoverArrowDirectionDown) { CGFloat midX = NSMidX(drawingRect); NSPoint points[3]; points[0] = NSMakePoint(floor(midX - (arrowWidth / 2.0)), minY - radius); // Starting point points[1] = NSMakePoint(floor(midX), points[0].y - arrowHeight); // Arrow tip points[2] = NSMakePoint(floor(midX + (arrowWidth / 2.0)), points[0].y); // Ending point [path appendBezierPathWithPoints:points count:3]; } // Bottom right corner [path appendBezierPathWithArcWithCenter:NSMakePoint(maxX, minY) radius:radius startAngle:270.0 endAngle:360.0]; if (self.arrowDirection == INPopoverArrowDirectionRight) { CGFloat midY = NSMidY(drawingRect); NSPoint points[3]; points[0] = NSMakePoint(maxX + radius, floor(midY - (arrowWidth / 2.0))); points[1] = NSMakePoint(points[0].x + arrowHeight, floor(midY)); points[2] = NSMakePoint(points[0].x, floor(midY + (arrowWidth / 2.0))); [path appendBezierPathWithPoints:points count:3]; } // Top right corner [path appendBezierPathWithArcWithCenter:NSMakePoint(maxX, maxY) radius:radius startAngle:0.0 endAngle:90.0]; if (self.arrowDirection == INPopoverArrowDirectionUp) { CGFloat midX = NSMidX(drawingRect); NSPoint points[3]; points[0] = NSMakePoint(floor(midX + (arrowWidth / 2.0)), maxY + radius); points[1] = NSMakePoint(floor(midX), points[0].y + arrowHeight); points[2] = NSMakePoint(floor(midX - (arrowWidth / 2.0)), points[0].y); [path appendBezierPathWithPoints:points count:3]; } // Top left corner [path appendBezierPathWithArcWithCenter:NSMakePoint(minX, maxY) radius:radius startAngle:90.0 endAngle:180.0]; if (self.arrowDirection == INPopoverArrowDirectionLeft) { CGFloat midY = NSMidY(drawingRect); NSPoint points[3]; points[0] = NSMakePoint(minX - radius, floor(midY + (arrowWidth / 2.0))); points[1] = NSMakePoint(points[0].x - arrowHeight, floor(midY)); points[2] = NSMakePoint(points[0].x, floor(midY - (arrowWidth / 2.0))); [path appendBezierPathWithPoints:points count:3]; } [path closePath]; return path; } #pragma mark - #pragma mark Accessors // Redraw the frame every time a property is changed - (void)setColor:(NSColor *)newColor { if (_color != newColor) { _color = newColor; [self setNeedsDisplay:YES]; } } - (void)setBorderColor:(NSColor *)newBorderColor { if (_borderColor != newBorderColor) { _borderColor = newBorderColor; [self setNeedsDisplay:YES]; } } - (void)setBorderWidth:(CGFloat)newBorderWidth { if (_borderWidth != newBorderWidth) { _borderWidth = newBorderWidth; [self setNeedsDisplay:YES]; } } - (void)setCornerRadius:(CGFloat)cornerRadius { if (_cornerRadius != cornerRadius) { _cornerRadius = cornerRadius; [self setNeedsDisplay:YES]; } } - (void)setArrowSize:(NSSize)arrowSize { if (!NSEqualSizes(_arrowSize, arrowSize)) { _arrowSize = arrowSize; [self setNeedsDisplay:YES]; } } - (void)setArrowDirection:(INPopoverArrowDirection)newArrowDirection { if (_arrowDirection != newArrowDirection) { _arrowDirection = newArrowDirection; [self setNeedsDisplay:YES]; } } @end ================================================ FILE: INPopoverController.podspec ================================================ Pod::Spec.new do |s| s.name = 'INPopoverController' s.version = '0.0.1' s.summary = 'A customizable popover controller for Mac OS X' s.homepage = 'https://github.com/indragiek/INPopoverController' s.author = { 'Indragie Karunaratne' => 'i@indragie.com' } s.source = { :git => 'https://github.com/indragiek/INPopoverController.git' } s.source_files = 'INPopoverController/*.{h,m}' s.public_header_files = 'INPopoverController/*.h' s.platform = :osx s.requires_arc = true s.license = 'BSD' s.frameworks = 'QuartzCore' end ================================================ FILE: INPopoverController.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ 7619A0908F1873F212A86D92 /* INPopoverController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7619A090EED3A0874FFB0542 /* INPopoverController.m */; }; 7619A507692D41F9A4EA0EB1 /* INPopoverController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7619AF3F1F908EC06616FBBA /* INPopoverController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7619A5078560AD04EB09398F /* INPopoverWindowFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 7619AFDD9CA28B629C79B9B7 /* INPopoverWindowFrame.m */; }; 7619A72138650AA792042726 /* INPopoverParentWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 7619A3274F11C96F76F9A2AA /* INPopoverParentWindow.h */; }; 7619A73868BE7D04215703FA /* INPopoverControllerDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 7619A49B8AE793DFA2663E95 /* INPopoverControllerDefines.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7619A73A585AD478336FBD44 /* INPopoverParentWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7619A840E914A3391A33BCB2 /* INPopoverParentWindow.m */; }; 7619A7C39101BC5170F2CF23 /* INPopoverWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 7619AEB4110920D49EB68147 /* INPopoverWindow.h */; }; 7619AFCF3AC75534C6582B37 /* INPopoverWindowFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 7619ABC89C19022487731625 /* INPopoverWindowFrame.h */; }; 7619AFCFD4611DEE23332859 /* INPopoverWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 7619A46EB85527945376718B /* INPopoverWindow.m */; }; 98BA893B143EA04A006F744E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 98BA893A143EA04A006F744E /* Cocoa.framework */; }; 98BA8983143EA1E9006F744E /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 98BA8982143EA1E9006F744E /* QuartzCore.framework */; }; 98BA8985143EA28E006F744E /* INPopoverPrefixHeader.pch in Headers */ = {isa = PBXBuildFile; fileRef = 98BA8984143EA28E006F744E /* INPopoverPrefixHeader.pch */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 7619A090EED3A0874FFB0542 /* INPopoverController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = INPopoverController.m; sourceTree = ""; }; 7619A3274F11C96F76F9A2AA /* INPopoverParentWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = INPopoverParentWindow.h; sourceTree = ""; }; 7619A46EB85527945376718B /* INPopoverWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = INPopoverWindow.m; sourceTree = ""; }; 7619A49B8AE793DFA2663E95 /* INPopoverControllerDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = INPopoverControllerDefines.h; sourceTree = ""; }; 7619A840E914A3391A33BCB2 /* INPopoverParentWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = INPopoverParentWindow.m; sourceTree = ""; }; 7619ABC89C19022487731625 /* INPopoverWindowFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = INPopoverWindowFrame.h; sourceTree = ""; }; 7619AEB4110920D49EB68147 /* INPopoverWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = INPopoverWindow.h; sourceTree = ""; }; 7619AF3F1F908EC06616FBBA /* INPopoverController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = INPopoverController.h; sourceTree = ""; }; 7619AFDD9CA28B629C79B9B7 /* INPopoverWindowFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = INPopoverWindowFrame.m; sourceTree = ""; }; 98BA8937143EA04A006F744E /* INPopoverController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = INPopoverController.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 98BA893A143EA04A006F744E /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 98BA893D143EA04A006F744E /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; 98BA893E143EA04A006F744E /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; 98BA893F143EA04A006F744E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 98BA8942143EA04A006F744E /* INPopoverController-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "INPopoverController-Info.plist"; sourceTree = ""; }; 98BA8982143EA1E9006F744E /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = SDKs/MacOSX10.6.sdk/System/Library/Frameworks/QuartzCore.framework; sourceTree = DEVELOPER_DIR; }; 98BA8984143EA28E006F744E /* INPopoverPrefixHeader.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = INPopoverPrefixHeader.pch; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ 98BA8933143EA04A006F744E /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( 98BA893B143EA04A006F744E /* Cocoa.framework in Frameworks */, 98BA8983143EA1E9006F744E /* QuartzCore.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 98BA892B143EA049006F744E = { isa = PBXGroup; children = ( 98BA8940143EA04A006F744E /* INPopoverController */, 98BA8939143EA04A006F744E /* Frameworks */, 98BA8938143EA04A006F744E /* Products */, ); sourceTree = ""; }; 98BA8938143EA04A006F744E /* Products */ = { isa = PBXGroup; children = ( 98BA8937143EA04A006F744E /* INPopoverController.framework */, ); name = Products; sourceTree = ""; }; 98BA8939143EA04A006F744E /* Frameworks */ = { isa = PBXGroup; children = ( 98BA8982143EA1E9006F744E /* QuartzCore.framework */, 98BA893A143EA04A006F744E /* Cocoa.framework */, 98BA893C143EA04A006F744E /* Other Frameworks */, ); name = Frameworks; sourceTree = ""; }; 98BA893C143EA04A006F744E /* Other Frameworks */ = { isa = PBXGroup; children = ( 98BA893D143EA04A006F744E /* AppKit.framework */, 98BA893E143EA04A006F744E /* CoreData.framework */, 98BA893F143EA04A006F744E /* Foundation.framework */, ); name = "Other Frameworks"; sourceTree = ""; }; 98BA8940143EA04A006F744E /* INPopoverController */ = { isa = PBXGroup; children = ( 98BA8941143EA04A006F744E /* Supporting Files */, 7619A49B8AE793DFA2663E95 /* INPopoverControllerDefines.h */, 7619AF3F1F908EC06616FBBA /* INPopoverController.h */, 7619A090EED3A0874FFB0542 /* INPopoverController.m */, 7619ABC89C19022487731625 /* INPopoverWindowFrame.h */, 7619AFDD9CA28B629C79B9B7 /* INPopoverWindowFrame.m */, 7619AEB4110920D49EB68147 /* INPopoverWindow.h */, 7619A46EB85527945376718B /* INPopoverWindow.m */, 7619A3274F11C96F76F9A2AA /* INPopoverParentWindow.h */, 7619A840E914A3391A33BCB2 /* INPopoverParentWindow.m */, ); path = INPopoverController; sourceTree = ""; }; 98BA8941143EA04A006F744E /* Supporting Files */ = { isa = PBXGroup; children = ( 98BA8984143EA28E006F744E /* INPopoverPrefixHeader.pch */, 98BA8942143EA04A006F744E /* INPopoverController-Info.plist */, ); name = "Supporting Files"; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ 98BA8934143EA04A006F744E /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( 98BA8985143EA28E006F744E /* INPopoverPrefixHeader.pch in Headers */, 7619A507692D41F9A4EA0EB1 /* INPopoverController.h in Headers */, 7619A72138650AA792042726 /* INPopoverParentWindow.h in Headers */, 7619A73868BE7D04215703FA /* INPopoverControllerDefines.h in Headers */, 7619A7C39101BC5170F2CF23 /* INPopoverWindow.h in Headers */, 7619AFCF3AC75534C6582B37 /* INPopoverWindowFrame.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ 98BA8936143EA04A006F744E /* INPopoverController */ = { isa = PBXNativeTarget; buildConfigurationList = 98BA8962143EA04B006F744E /* Build configuration list for PBXNativeTarget "INPopoverController" */; buildPhases = ( 98BA8932143EA04A006F744E /* Sources */, 98BA8933143EA04A006F744E /* Frameworks */, 98BA8934143EA04A006F744E /* Headers */, 98BA8935143EA04A006F744E /* Resources */, ); buildRules = ( ); dependencies = ( ); name = INPopoverController; productName = INPopoverController; productReference = 98BA8937143EA04A006F744E /* INPopoverController.framework */; productType = "com.apple.product-type.framework"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 98BA892D143EA049006F744E /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0500; }; buildConfigurationList = 98BA8930143EA049006F744E /* Build configuration list for PBXProject "INPopoverController" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( en, ); mainGroup = 98BA892B143EA049006F744E; productRefGroup = 98BA8938143EA04A006F744E /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( 98BA8936143EA04A006F744E /* INPopoverController */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ 98BA8935143EA04A006F744E /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ 98BA8932143EA04A006F744E /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 7619A0908F1873F212A86D92 /* INPopoverController.m in Sources */, 7619A5078560AD04EB09398F /* INPopoverWindowFrame.m in Sources */, 7619AFCFD4611DEE23332859 /* INPopoverWindow.m in Sources */, 7619A73A585AD478336FBD44 /* INPopoverParentWindow.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin XCBuildConfiguration section */ 98BA8960143EA04B006F744E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_OBJC_EXCEPTIONS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.6; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; }; name = Debug; }; 98BA8961143EA04B006F744E /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_ENABLE_OBJC_EXCEPTIONS = YES; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.6; SDKROOT = macosx; }; name = Release; }; 98BA8963143EA04B006F744E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = YES; COMBINE_HIDPI_IMAGES = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(DEVELOPER_DIR)/SDKs/MacOSX10.6.sdk/System/Library/Frameworks\"", ); FRAMEWORK_VERSION = A; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = INPopoverController/INPopoverPrefixHeader.pch; GCC_VERSION = ""; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; INFOPLIST_FILE = "INPopoverController/INPopoverController-Info.plist"; INSTALL_PATH = "@rpath"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; WRAPPER_EXTENSION = framework; }; name = Debug; }; 98BA8964143EA04B006F744E /* Release */ = { isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = YES; COMBINE_HIDPI_IMAGES = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(DEVELOPER_DIR)/SDKs/MacOSX10.6.sdk/System/Library/Frameworks\"", ); FRAMEWORK_VERSION = A; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = INPopoverController/INPopoverPrefixHeader.pch; GCC_VERSION = ""; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; INFOPLIST_FILE = "INPopoverController/INPopoverController-Info.plist"; INSTALL_PATH = "@rpath"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; WRAPPER_EXTENSION = framework; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ 98BA8930143EA049006F744E /* Build configuration list for PBXProject "INPopoverController" */ = { isa = XCConfigurationList; buildConfigurations = ( 98BA8960143EA04B006F744E /* Debug */, 98BA8961143EA04B006F744E /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 98BA8962143EA04B006F744E /* Build configuration list for PBXNativeTarget "INPopoverController" */ = { isa = XCConfigurationList; buildConfigurations = ( 98BA8963143EA04B006F744E /* Debug */, 98BA8964143EA04B006F744E /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = 98BA892D143EA049006F744E /* Project object */; } ================================================ FILE: INPopoverController.xcodeproj/project.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: LICENSE ================================================ Copyright (c) 2011-2014, Indragie Karunaratne All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================ FILE: PopoverSampleApp/PopoverSampleApp/AlphaColorWell.h ================================================ // // AlphaColorWell.h // PopoverSampleApp // // Created by Indragie Karunaratne on 1/11/2014. // #import @interface AlphaColorWell : NSColorWell @end ================================================ FILE: PopoverSampleApp/PopoverSampleApp/AlphaColorWell.m ================================================ // // AlphaColorWell.m // PopoverSampleApp // // Created by Indragie Karunaratne on 1/11/2014. // #import "AlphaColorWell.h" @implementation AlphaColorWell - (void)activate:(BOOL)exclusive { [[NSColorPanel sharedColorPanel] setShowsAlpha:YES]; [super activate:exclusive]; } @end ================================================ FILE: PopoverSampleApp/PopoverSampleApp/ContentViewController.h ================================================ // // ContentViewController.h // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import @interface ContentViewController : NSViewController { @private } @end ================================================ FILE: PopoverSampleApp/PopoverSampleApp/ContentViewController.m ================================================ // // ContentViewController.m // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import "ContentViewController.h" @implementation ContentViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Initialization code here. } return self; } @end ================================================ FILE: PopoverSampleApp/PopoverSampleApp/ContentViewController.xib ================================================ 1070 11A390 1510 1110.91 544.00 com.apple.InterfaceBuilder.CocoaPlugin 1510 NSCustomView NSTextField NSTextFieldCell NSCustomObject com.apple.InterfaceBuilder.CocoaPlugin ContentViewController FirstResponder NSApplication 268 268 {{68, 83}, {215, 39}} _NS:3583 YES 67239424 272629760 This is view content loaded from ContentViewController.xib LucidaGrande 13 16 6 System controlColor 3 MC42NjY2NjY2NjY3AA 1 MCAwIDAAA {351, 204} NSView view 3 0 -2 File's Owner -1 First Responder -3 Application 1 6 7 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin {{633, 728}, {480, 272}} com.apple.InterfaceBuilder.CocoaPlugin {628, 654} {{357, 416}, {480, 272}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin 7 ContentViewController NSViewController IBProjectSource ./Classes/ContentViewController.h 0 IBCocoaFramework YES 3 ================================================ FILE: PopoverSampleApp/PopoverSampleApp/PopoverSampleApp-Info.plist ================================================ CFBundleDevelopmentRegion en CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIconFile CFBundleIdentifier com.indragie.${PRODUCT_NAME:rfc1034identifier} CFBundleInfoDictionaryVersion 6.0 CFBundleName ${PRODUCT_NAME} CFBundlePackageType APPL CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion 1 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSMainNibFile MainMenu NSPrincipalClass NSApplication ================================================ FILE: PopoverSampleApp/PopoverSampleApp/PopoverSampleApp-Prefix.pch ================================================ // // Prefix header for all source files of the 'PopoverSampleApp' target in the 'PopoverSampleApp' project // #ifdef __OBJC__ #import #endif ================================================ FILE: PopoverSampleApp/PopoverSampleApp/PopoverSampleAppAppDelegate.h ================================================ // // PopoverSampleAppAppDelegate.h // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import @class INPopoverController; @interface PopoverSampleAppAppDelegate : NSObject { @private NSWindow *__weak window; INPopoverController *popoverController; } @property (nonatomic, strong) INPopoverController *popoverController; @property (weak) IBOutlet NSWindow *window; - (IBAction)togglePopover:(id)sender; @end ================================================ FILE: PopoverSampleApp/PopoverSampleApp/PopoverSampleAppAppDelegate.m ================================================ // // PopoverSampleAppAppDelegate.m // Copyright 2011-2014 Indragie Karunaratne. All rights reserved. // #import "PopoverSampleAppAppDelegate.h" #import "ContentViewController.h" #import @implementation PopoverSampleAppAppDelegate @synthesize window, popoverController; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { ContentViewController *viewController = [[ContentViewController alloc] initWithNibName:@"ContentViewController" bundle:nil]; self.popoverController = [[INPopoverController alloc] initWithContentViewController:viewController]; } - (IBAction)togglePopover:(id)sender { if (self.popoverController.popoverIsVisible) { [self.popoverController closePopover:nil]; } else { [self.popoverController presentPopoverFromRect:[sender bounds] inView:sender preferredArrowDirection:INPopoverArrowDirectionLeft anchorsToPositionView:YES]; } } @end ================================================ FILE: PopoverSampleApp/PopoverSampleApp/en.lproj/Credits.rtf ================================================ {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} {\colortbl;\red255\green255\blue255;} \paperw9840\paperh8400 \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural \f0\b\fs24 \cf0 Engineering: \b0 \ Some people\ \ \b Human Interface Design: \b0 \ Some other people\ \ \b Testing: \b0 \ Hopefully not nobody\ \ \b Documentation: \b0 \ Whoever\ \ \b With special thanks to: \b0 \ Mom\ } ================================================ FILE: PopoverSampleApp/PopoverSampleApp/en.lproj/InfoPlist.strings ================================================ /* Localized versions of Info.plist keys */ ================================================ FILE: PopoverSampleApp/PopoverSampleApp/en.lproj/MainMenu.xib ================================================ Default Left to Right Right to Left Default Left to Right Right to Left ================================================ FILE: PopoverSampleApp/PopoverSampleApp/main.m ================================================ // // main.m // PopoverSampleApp // // Created by Indragie Karunaratne on 11-03-02. // Copyright 2011-2014 PCWiz Computer. All rights reserved. // #import int main(int argc, char *argv[]) { return NSApplicationMain(argc, (const char **)argv); } ================================================ FILE: PopoverSampleApp/PopoverSampleApp.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ 03657F2B187A09BE00C969BA /* INPopoverController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03657F28187A09A000C969BA /* INPopoverController.framework */; }; 03657F2D187A09C900C969BA /* INPopoverController.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 03657F28187A09A000C969BA /* INPopoverController.framework */; }; 0391A4FF18822FAA007D32D5 /* AlphaColorWell.m in Sources */ = {isa = PBXBuildFile; fileRef = 0391A4FE18822FAA007D32D5 /* AlphaColorWell.m */; }; 0393272D131F613D0007496E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0393272C131F613D0007496E /* Cocoa.framework */; }; 03932737131F613D0007496E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 03932735131F613D0007496E /* InfoPlist.strings */; }; 0393273A131F613D0007496E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 03932739131F613D0007496E /* main.m */; }; 0393273D131F613D0007496E /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 0393273B131F613D0007496E /* Credits.rtf */; }; 03932740131F613D0007496E /* PopoverSampleAppAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0393273F131F613D0007496E /* PopoverSampleAppAppDelegate.m */; }; 03932743131F613D0007496E /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 03932741131F613D0007496E /* MainMenu.xib */; }; 0393274C131F61590007496E /* ContentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0393274A131F61590007496E /* ContentViewController.m */; }; 0393274D131F61590007496E /* ContentViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0393274B131F61590007496E /* ContentViewController.xib */; }; BFF06C9116CAAEC100C3D751 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BFF06C9016CAAEC100C3D751 /* QuartzCore.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ 03657F27187A09A000C969BA /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 03657F23187A09A000C969BA /* INPopoverController.xcodeproj */; proxyType = 2; remoteGlobalIDString = 98BA8937143EA04A006F744E; remoteInfo = INPopoverController; }; 03657F29187A09BA00C969BA /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 03657F23187A09A000C969BA /* INPopoverController.xcodeproj */; proxyType = 1; remoteGlobalIDString = 98BA8936143EA04A006F744E; remoteInfo = INPopoverController; }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ 03657F2C187A09C300C969BA /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; dstPath = ""; dstSubfolderSpec = 10; files = ( 03657F2D187A09C900C969BA /* INPopoverController.framework in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ 03657F23187A09A000C969BA /* INPopoverController.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = INPopoverController.xcodeproj; path = ../../INPopoverController.xcodeproj; sourceTree = ""; }; 0391A4FD18822FAA007D32D5 /* AlphaColorWell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlphaColorWell.h; sourceTree = ""; }; 0391A4FE18822FAA007D32D5 /* AlphaColorWell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AlphaColorWell.m; sourceTree = ""; }; 03932728131F613D0007496E /* PopoverSampleApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PopoverSampleApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0393272C131F613D0007496E /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 0393272F131F613D0007496E /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; 03932730131F613D0007496E /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; 03932731131F613D0007496E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 03932734131F613D0007496E /* PopoverSampleApp-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PopoverSampleApp-Info.plist"; sourceTree = ""; }; 03932736131F613D0007496E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 03932738131F613D0007496E /* PopoverSampleApp-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PopoverSampleApp-Prefix.pch"; sourceTree = ""; }; 03932739131F613D0007496E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 0393273C131F613D0007496E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = ""; }; 0393273E131F613D0007496E /* PopoverSampleAppAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PopoverSampleAppAppDelegate.h; sourceTree = ""; }; 0393273F131F613D0007496E /* PopoverSampleAppAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PopoverSampleAppAppDelegate.m; sourceTree = ""; }; 03932742131F613D0007496E /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = ""; }; 03932749131F61590007496E /* ContentViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentViewController.h; sourceTree = ""; }; 0393274A131F61590007496E /* ContentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ContentViewController.m; sourceTree = ""; }; 0393274B131F61590007496E /* ContentViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ContentViewController.xib; sourceTree = ""; }; BFF06C9016CAAEC100C3D751 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ 03932725131F613D0007496E /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( 03657F2B187A09BE00C969BA /* INPopoverController.framework in Frameworks */, BFF06C9116CAAEC100C3D751 /* QuartzCore.framework in Frameworks */, 0393272D131F613D0007496E /* Cocoa.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 03657F24187A09A000C969BA /* Products */ = { isa = PBXGroup; children = ( 03657F28187A09A000C969BA /* INPopoverController.framework */, ); name = Products; sourceTree = ""; }; 0393271D131F613D0007496E = { isa = PBXGroup; children = ( 03932732131F613D0007496E /* PopoverSampleApp */, 0393272B131F613D0007496E /* Frameworks */, 03932729131F613D0007496E /* Products */, ); sourceTree = ""; }; 03932729131F613D0007496E /* Products */ = { isa = PBXGroup; children = ( 03932728131F613D0007496E /* PopoverSampleApp.app */, ); name = Products; sourceTree = ""; }; 0393272B131F613D0007496E /* Frameworks */ = { isa = PBXGroup; children = ( BFF06C9016CAAEC100C3D751 /* QuartzCore.framework */, 0393272C131F613D0007496E /* Cocoa.framework */, 0393272E131F613D0007496E /* Other Frameworks */, ); name = Frameworks; sourceTree = ""; }; 0393272E131F613D0007496E /* Other Frameworks */ = { isa = PBXGroup; children = ( 0393272F131F613D0007496E /* AppKit.framework */, 03932730131F613D0007496E /* CoreData.framework */, 03932731131F613D0007496E /* Foundation.framework */, ); name = "Other Frameworks"; sourceTree = ""; }; 03932732131F613D0007496E /* PopoverSampleApp */ = { isa = PBXGroup; children = ( 03657F23187A09A000C969BA /* INPopoverController.xcodeproj */, 0393273E131F613D0007496E /* PopoverSampleAppAppDelegate.h */, 0393273F131F613D0007496E /* PopoverSampleAppAppDelegate.m */, 03932749131F61590007496E /* ContentViewController.h */, 0393274A131F61590007496E /* ContentViewController.m */, 0391A4FD18822FAA007D32D5 /* AlphaColorWell.h */, 0391A4FE18822FAA007D32D5 /* AlphaColorWell.m */, 03932741131F613D0007496E /* MainMenu.xib */, 0393274B131F61590007496E /* ContentViewController.xib */, 03932733131F613D0007496E /* Supporting Files */, ); path = PopoverSampleApp; sourceTree = ""; }; 03932733131F613D0007496E /* Supporting Files */ = { isa = PBXGroup; children = ( 03932734131F613D0007496E /* PopoverSampleApp-Info.plist */, 03932735131F613D0007496E /* InfoPlist.strings */, 03932738131F613D0007496E /* PopoverSampleApp-Prefix.pch */, 03932739131F613D0007496E /* main.m */, 0393273B131F613D0007496E /* Credits.rtf */, ); name = "Supporting Files"; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ 03932727131F613D0007496E /* PopoverSampleApp */ = { isa = PBXNativeTarget; buildConfigurationList = 03932746131F613D0007496E /* Build configuration list for PBXNativeTarget "PopoverSampleApp" */; buildPhases = ( 03932724131F613D0007496E /* Sources */, 03932725131F613D0007496E /* Frameworks */, 03932726131F613D0007496E /* Resources */, 03657F2C187A09C300C969BA /* CopyFiles */, ); buildRules = ( ); dependencies = ( 03657F2A187A09BA00C969BA /* PBXTargetDependency */, ); name = PopoverSampleApp; productName = PopoverSampleApp; productReference = 03932728131F613D0007496E /* PopoverSampleApp.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 0393271F131F613D0007496E /* Project object */ = { isa = PBXProject; attributes = { ORGANIZATIONNAME = "Indragie Karunaratne"; }; buildConfigurationList = 03932722131F613D0007496E /* Build configuration list for PBXProject "PopoverSampleApp" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( en, ); mainGroup = 0393271D131F613D0007496E; productRefGroup = 03932729131F613D0007496E /* Products */; projectDirPath = ""; projectReferences = ( { ProductGroup = 03657F24187A09A000C969BA /* Products */; ProjectRef = 03657F23187A09A000C969BA /* INPopoverController.xcodeproj */; }, ); projectRoot = ""; targets = ( 03932727131F613D0007496E /* PopoverSampleApp */, ); }; /* End PBXProject section */ /* Begin PBXReferenceProxy section */ 03657F28187A09A000C969BA /* INPopoverController.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; path = INPopoverController.framework; remoteRef = 03657F27187A09A000C969BA /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXReferenceProxy section */ /* Begin PBXResourcesBuildPhase section */ 03932726131F613D0007496E /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( 03932737131F613D0007496E /* InfoPlist.strings in Resources */, 0393273D131F613D0007496E /* Credits.rtf in Resources */, 03932743131F613D0007496E /* MainMenu.xib in Resources */, 0393274D131F61590007496E /* ContentViewController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ 03932724131F613D0007496E /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 0391A4FF18822FAA007D32D5 /* AlphaColorWell.m in Sources */, 0393273A131F613D0007496E /* main.m in Sources */, 03932740131F613D0007496E /* PopoverSampleAppAppDelegate.m in Sources */, 0393274C131F61590007496E /* ContentViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ 03657F2A187A09BA00C969BA /* PBXTargetDependency */ = { isa = PBXTargetDependency; name = INPopoverController; targetProxy = 03657F29187A09BA00C969BA /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ 03932735131F613D0007496E /* InfoPlist.strings */ = { isa = PBXVariantGroup; children = ( 03932736131F613D0007496E /* en */, ); name = InfoPlist.strings; sourceTree = ""; }; 0393273B131F613D0007496E /* Credits.rtf */ = { isa = PBXVariantGroup; children = ( 0393273C131F613D0007496E /* en */, ); name = Credits.rtf; sourceTree = ""; }; 03932741131F613D0007496E /* MainMenu.xib */ = { isa = PBXVariantGroup; children = ( 03932742131F613D0007496E /* en */, ); name = MainMenu.xib; sourceTree = ""; }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ 03932744131F613D0007496E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = DEBUG; GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.7; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; }; name = Debug; }; 03932745131F613D0007496E /* Release */ = { isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_OBJC_ARC = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.7; SDKROOT = macosx; }; name = Release; }; 03932747131F613D0007496E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_OBJC_EXCEPTIONS = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PopoverSampleApp/PopoverSampleApp-Prefix.pch"; INFOPLIST_FILE = "PopoverSampleApp/PopoverSampleApp-Info.plist"; LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; name = Debug; }; 03932748131F613D0007496E /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_ENABLE_OBJC_EXCEPTIONS = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "PopoverSampleApp/PopoverSampleApp-Prefix.pch"; INFOPLIST_FILE = "PopoverSampleApp/PopoverSampleApp-Info.plist"; LD_RUNPATH_SEARCH_PATHS = "@loader_path/../Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ 03932722131F613D0007496E /* Build configuration list for PBXProject "PopoverSampleApp" */ = { isa = XCConfigurationList; buildConfigurations = ( 03932744131F613D0007496E /* Debug */, 03932745131F613D0007496E /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 03932746131F613D0007496E /* Build configuration list for PBXNativeTarget "PopoverSampleApp" */ = { isa = XCConfigurationList; buildConfigurations = ( 03932747131F613D0007496E /* Debug */, 03932748131F613D0007496E /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = 0393271F131F613D0007496E /* Project object */; } ================================================ FILE: PopoverSampleApp/PopoverSampleApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata ================================================ ================================================ FILE: README.md ================================================ ## INPopoverController ### Open source OS X popover implementation OS X 10.7 introduced the `NSPopover` class for displaying popover windows. That said, developers who want to support older versions of OS X (like me) are unable to use that API without breaking backward compatibility. So I developed this class that will allow developers to easily add popovers into their applications and also have it be compatible with older versions of OS X. I've included a sample app to demonstrate how to use INPopoverController: ![INPopoverController](https://raw.github.com/indragiek/INPopoverController/master/screenshot.png) **Features:** - Customizable color, border color, border width, arrow size, and corner radius. - Automatically calculates the best arrow direction depending on screen space and popover position - Displays content from a regular `NSViewController` (can be loaded from a NIB) - Animation for when the popover appears/disappears and when the content size is changed - Popover can anchor to a view - Customizable popover behaviour (close when key status is lost, when application resigns active) ### How to use it The headers are well documented (and I've also included a sample app) so it should be simple to figure out how to use it. There are `color`, `borderColor`, and `borderWidth` properties to customize the appearance of the popover. There are also some hard-coded defines in the `INPopoverControllerDefines.h` file which can be changed to further customize the appearance. The `closesWhenPopoverResignsKey` and `closesWhenApplicationBecomesInactive` properties can be used to control the behaviour of the popover. Everything else should be pretty much self explanatory. If you want to completely customize the drawing of the popover, you can edit the `INPopoverWindowFrame.m` file to run your own drawing code instead of the default. Make sure that you're taking the `arrowDirection` property into account when drawing. **Create a new issue if you have trouble getting it working, or if you want to request new features** ### Contact * Indragie Karunaratne * [@indragie](http://twitter.com/indragie) * [http://indragie.com](http://indragie.com) ### Licensing INPopoverController is licensed under the [BSD license](http://www.opensource.org/licenses/bsd-license.php).