From 16bde74a1ff0240c23879cfd5a23e903b434d1ca Mon Sep 17 00:00:00 2001 From: Thibaut Jarosz Date: Fri, 12 Apr 2013 22:14:56 +0200 Subject: [PATCH 1/3] Add support for window can become key --- INPopoverController.h | 4 + INPopoverController.m | 10 + INPopoverWindow.h | 2 + INPopoverWindow.m | 5 +- .../PopoverSampleApp/en.lproj/MainMenu.xib | 400 +++++++++--------- 5 files changed, 227 insertions(+), 194 deletions(-) diff --git a/INPopoverController.h b/INPopoverController.h index 7e55133..b262bd8 100644 --- a/INPopoverController.h +++ b/INPopoverController.h @@ -20,6 +20,7 @@ BOOL _closesWhenPopoverResignsKey; BOOL _closesWhenApplicationBecomesInactive; BOOL _animates; + BOOL _windowCanBecomeKey; NSViewController *_contentViewController; INPopoverWindow *_popoverWindow; @@ -77,6 +78,9 @@ /** Whether the popover is currently visible or not **/ @property (readonly) BOOL popoverIsVisible; +/** Whether the window can become key or not. Default value: YES **/ +@property (nonatomic, assign) BOOL windowCanBecomeKey; + #pragma mark - #pragma mark Methods diff --git a/INPopoverController.m b/INPopoverController.m index 20220b5..fc16f63 100644 --- a/INPopoverController.m +++ b/INPopoverController.m @@ -403,4 +403,14 @@ - (void)_callDelegateMethod:(SEL)selector } } +- (void)setWindowCanBecomeKey:(BOOL)windowCanBecomeKey +{ + _popoverWindow.canBecomeKeyWindow = windowCanBecomeKey; +} + +- (BOOL)windowCanBecomeKey +{ + return _popoverWindow.canBecomeKeyWindow; +} + @end diff --git a/INPopoverWindow.h b/INPopoverWindow.h index fe3f63a..7fed3bc 100644 --- a/INPopoverWindow.h +++ b/INPopoverWindow.h @@ -17,10 +17,12 @@ @interface INPopoverWindow : NSWindow { NSView *_popoverContentView; NSWindow *_zoomWindow; + BOOL _canBecomeKeyWindow; } @property (nonatomic, readonly) INPopoverWindowFrame *frameView; // Equivalent to contentView @property (nonatomic, retain) NSView *popoverContentView; +@property (nonatomic, assign) BOOL canBecomeKeyWindow; - (void)presentWithPopoverController:(INPopoverController *)popoverController; - (void)dismissAnimated; diff --git a/INPopoverWindow.m b/INPopoverWindow.m index 66448b9..2eaaff4 100644 --- a/INPopoverWindow.m +++ b/INPopoverWindow.m @@ -23,6 +23,8 @@ - (NSWindow *)_zoomWindowWithRect:(NSRect)rect; @implementation INPopoverWindow +@synthesize canBecomeKeyWindow = _canBecomeKeyWindow; + // Borderless, transparent window - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation { @@ -30,6 +32,7 @@ - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle [self setOpaque:NO]; [self setBackgroundColor:[NSColor clearColor]]; [self setHasShadow:YES]; + [self setCanBecomeKeyWindow:YES]; } return self; } @@ -49,7 +52,7 @@ - (NSRect)frameRectForContentRect:(NSRect)contentRect // Allow the popover to become the key window - (BOOL)canBecomeKeyWindow { - return YES; + return _canBecomeKeyWindow; } - (BOOL)canBecomeMainWindow diff --git a/PopoverSampleApp/PopoverSampleApp/en.lproj/MainMenu.xib b/PopoverSampleApp/PopoverSampleApp/en.lproj/MainMenu.xib index 0cf6c21..7cc88d1 100644 --- a/PopoverSampleApp/PopoverSampleApp/en.lproj/MainMenu.xib +++ b/PopoverSampleApp/PopoverSampleApp/en.lproj/MainMenu.xib @@ -1,30 +1,36 @@ - 1060 - 11B26 - 907 - 1138 - 566.00 + 1080 + 12D78 + 3084 + 1187.37 + 626.00 com.apple.InterfaceBuilder.CocoaPlugin - 907 + 3084 - + YES + NSButton + NSButtonCell + NSColorWell + NSCustomObject + NSMenu + NSMenuItem + NSNumberFormatter + NSTextField + NSTextFieldCell + NSView + NSWindowTemplate YES com.apple.InterfaceBuilder.CocoaPlugin - YES - - YES - - - YES - + PluginDependencyRecalculationVersion + YES @@ -1316,15 +1322,14 @@ 7 2 - {{335, 390}, {373, 185}} + {{335, 390}, {373, 205}} 1954021376 PopoverSampleApp INPopoverParentWindow - {1.7976931348623157e+308, 1.7976931348623157e+308} - + 256 YES @@ -1338,11 +1343,13 @@ NSColor pasteboard type - {{132, 145}, {44, 23}} + {{132, 165}, {44, 23}} + _NS:3884 YES + NO YES 1 @@ -1359,11 +1366,13 @@ NSColor pasteboard type - {{132, 114}, {44, 23}} + {{132, 134}, {44, 23}} + _NS:3884 YES + NO YES 1 @@ -1373,19 +1382,20 @@ 268 - {{17, 148}, {97, 17}} + {{17, 168}, {97, 17}} + _NS:3897 YES - 68288064 + 68157504 272630784 Popover Color: LucidaGrande 13 - 1040 + 1044 _NS:3897 @@ -1408,17 +1418,19 @@ + NO 268 - {{25, 117}, {97, 17}} + {{25, 137}, {97, 17}} + _NS:3897 YES - 68288064 + 68157504 272630784 Border Color: @@ -1427,17 +1439,19 @@ + NO 268 - {{24, 87}, {97, 17}} + {{24, 107}, {97, 17}} + _NS:3897 YES - 68288064 + 68157504 272630784 Border Width: @@ -1446,40 +1460,44 @@ + NO 268 - {{220, 109}, {139, 32}} + {{220, 129}, {139, 32}} + _NS:164 YES - 67239424 + 67108864 134217728 Toggle Popover _NS:164 - -2038284033 + -2038284288 129 200 25 + NO 268 - {{132, 82}, {44, 22}} + {{132, 102}, {44, 22}} + _NS:3819 YES - -1803944383 + -1804074943 272630784 @@ -1495,7 +1513,7 @@ numberStyle positiveInfinitySymbol - + YES @@ -1520,10 +1538,10 @@ NaN YES - - + YES + @@ -1566,23 +1584,25 @@ + NO 268 - {{18, 38}, {232, 18}} + {{18, 58}, {232, 18}} + _NS:239 YES - -2080244224 + -2080374784 0 Closes when popover resigns key _NS:239 - 1211912703 + 1211912448 2 NSImage @@ -1596,22 +1616,25 @@ 200 25 + NO 268 - {{18, 18}, {287, 18}} + {{18, 38}, {287, 18}} + + _NS:239 YES - -2080244224 + -2080374784 0 Closes when application becomes inactive _NS:239 - 1211912703 + 1211912448 2 @@ -1620,23 +1643,25 @@ 200 25 + NO 268 - {{18, 58}, {81, 18}} + {{18, 78}, {81, 18}} + _NS:239 YES - -2080244224 + -2080374784 0 Animates _NS:239 - 1211912703 + 1211912448 2 @@ -1645,13 +1670,43 @@ 200 25 + NO + + + + 268 + {{18, 18}, {230, 18}} + + + + _NS:239 + YES + + -2080374784 + 0 + Popover window can become key + + _NS:239 + + 1211912448 + 2 + + + + + 200 + 25 + + NO - {373, 185} + {373, 205} + + {{0, 0}, {1680, 1028}} - {1.7976931348623157e+308, 1.7976931348623157e+308} + {10000000000000, 10000000000000} YES @@ -1664,6 +1719,30 @@ YES + + + terminate: + + + + 449 + + + + orderFrontStandardAboutPanel: + + + + 142 + + + + delegate + + + + 495 + performMiniaturize: @@ -1704,14 +1783,6 @@ 127 - - - orderFrontStandardAboutPanel: - - - - 142 - performClose: @@ -1952,46 +2023,6 @@ 374 - - - addFontTrait: - - - - 421 - - - - addFontTrait: - - - - 422 - - - - modifyFont: - - - - 423 - - - - orderFrontFontPanel: - - - - 424 - - - - modifyFont: - - - - 425 - raiseBaseline: @@ -2120,14 +2151,6 @@ 441 - - - terminate: - - - - 449 - toggleAutomaticSpellingCorrection: @@ -2224,14 +2247,6 @@ 493 - - - delegate - - - - 495 - alignCenter: @@ -2336,6 +2351,46 @@ 530 + + + addFontTrait: + + + + 421 + + + + addFontTrait: + + + + 422 + + + + modifyFont: + + + + 423 + + + + orderFrontFontPanel: + + + + 424 + + + + modifyFont: + + + + 425 + window @@ -2448,6 +2503,22 @@ 585 + + + value: popoverController.windowCanBecomeKey + + + + + + value: popoverController.windowCanBecomeKey + value + popoverController.windowCanBecomeKey + 2 + + + 589 + @@ -3013,6 +3084,7 @@ + @@ -3633,6 +3705,20 @@ + + 586 + + + YES + + + + + + 587 + + + @@ -3802,6 +3888,8 @@ 58.IBPluginDependency 582.IBPluginDependency 583.IBPluginDependency + 586.IBPluginDependency + 587.IBPluginDependency 72.IBPluginDependency 73.IBPluginDependency 74.IBPluginDependency @@ -3815,7 +3903,7 @@ 83.IBPluginDependency 92.IBPluginDependency - + YES com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3992,25 +4080,23 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin YES - - YES - + YES - - YES - + - 585 + 589 @@ -4018,76 +4104,9 @@ INPopoverParentWindow NSWindow - - IBUserSource - - - - - NSDocument - - YES - - YES - printDocument: - revertDocumentToSaved: - runPageLayout: - saveDocument: - saveDocumentAs: - saveDocumentTo: - - - YES - id - id - id - id - id - id - - - - YES - - YES - printDocument: - revertDocumentToSaved: - runPageLayout: - saveDocument: - saveDocumentAs: - saveDocumentTo: - - - YES - - printDocument: - id - - - revertDocumentToSaved: - id - - - runPageLayout: - id - - - saveDocument: - id - - - saveDocumentAs: - id - - - saveDocumentTo: - id - - - IBProjectSource - ./Classes/NSDocument.h + ./Classes/INPopoverParentWindow.h @@ -4124,16 +4143,11 @@ 0 IBCocoaFramework - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 YES - 3 YES @@ -4143,10 +4157,10 @@ NSMenuMixedState NSSwitch - + YES - {9, 8} - {7, 2} + {11, 11} + {10, 3} {15, 15} From d3a609e185892319e76700c660589c560cd17b90 Mon Sep 17 00:00:00 2001 From: Thibaut Jarosz Date: Mon, 29 Apr 2013 18:57:32 +0200 Subject: [PATCH 2/3] Fix bug when dismissing not key windowed popover --- INPopoverController.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/INPopoverController.m b/INPopoverController.m index fc16f63..a9f5fa7 100644 --- a/INPopoverController.m +++ b/INPopoverController.m @@ -376,7 +376,8 @@ - (void)_closePopoverAndResetVariables [_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]; + if ( _windowCanBecomeKey ) + [positionWindow makeKeyAndOrderFront:nil]; // Clear all the ivars [self _setArrowDirection:INPopoverArrowDirectionUndefined]; [self _setPositionView:nil]; From 2a010a0f91b90a67dc1293c4d4d2f961d04e30e7 Mon Sep 17 00:00:00 2001 From: Thibaut Jarosz Date: Thu, 2 May 2013 16:37:09 +0200 Subject: [PATCH 3/3] Fix bug with parent window never becoming key --- INPopoverController.h | 1 - INPopoverController.m | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/INPopoverController.h b/INPopoverController.h index b262bd8..91530bf 100644 --- a/INPopoverController.h +++ b/INPopoverController.h @@ -20,7 +20,6 @@ BOOL _closesWhenPopoverResignsKey; BOOL _closesWhenApplicationBecomesInactive; BOOL _animates; - BOOL _windowCanBecomeKey; NSViewController *_contentViewController; INPopoverWindow *_popoverWindow; diff --git a/INPopoverController.m b/INPopoverController.m index a9f5fa7..65aadfb 100644 --- a/INPopoverController.m +++ b/INPopoverController.m @@ -376,7 +376,7 @@ - (void)_closePopoverAndResetVariables [_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 - if ( _windowCanBecomeKey ) + if ( self.windowCanBecomeKey ) [positionWindow makeKeyAndOrderFront:nil]; // Clear all the ivars [self _setArrowDirection:INPopoverArrowDirectionUndefined];