mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 02:04:20 +00:00
* Headers/AppKit/NSPopover.h: correct delegate method
for popoverShouldClose: * Headers/AppKit/NSWindow.h: add convertRectToScreen: and convertRectFromScreen: methods. * Source/NSPopover.m: Correct delegate method for popoverShouldClose:. Changes to align popover window with rect it is being placed relative to. * Source/NSWindow.m: implementation of convertRectToScreen: and convertRectFromScreen: methods. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@36577 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7bd5a864cd
commit
f14cc1f3bc
5 changed files with 133 additions and 7 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2013-04-24 05:23-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Headers/AppKit/NSPopover.h: correct delegate method
|
||||
for popoverShouldClose:
|
||||
* Headers/AppKit/NSWindow.h: add convertRectToScreen: and
|
||||
convertRectFromScreen: methods.
|
||||
* Source/NSPopover.m: Correct delegate method for popoverShouldClose:.
|
||||
Changes to align popover window with rect it is being placed relative
|
||||
to.
|
||||
* Source/NSWindow.m: implementation of convertRectToScreen: and
|
||||
convertRectFromScreen: methods.
|
||||
|
||||
2013-04-23 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/GSXibLoader.m: Add -replaceObject:withObject: method.
|
||||
|
|
|
@ -70,7 +70,7 @@ typedef NSInteger NSPopoverBehavior;
|
|||
NSPopoverBehavior _behavior;
|
||||
NSSize _contentSize;
|
||||
IBOutlet NSViewController *_contentViewController;
|
||||
id<NSPopoverDelegate> _delegate;
|
||||
id _delegate;
|
||||
NSRect _positioningRect;
|
||||
BOOL _shown;
|
||||
|
||||
|
@ -88,8 +88,8 @@ typedef NSInteger NSPopoverBehavior;
|
|||
- (NSSize)contentSize;
|
||||
- (void)setContentViewController:(NSViewController *)controller;
|
||||
- (NSViewController *)contentViewController;
|
||||
- (void)setDelegate:(id<NSPopoverDelegate>)value;
|
||||
- (id<NSPopoverDelegate>)delegate;
|
||||
- (void)setDelegate:(id)value;
|
||||
- (id)delegate;
|
||||
- (void)setPositioningRect:(NSRect)value;
|
||||
- (NSRect)positioningRect;
|
||||
- (BOOL)isShown;
|
||||
|
@ -113,7 +113,7 @@ typedef NSInteger NSPopoverBehavior;
|
|||
- (NSWindow *)detachableWindowForPopover:(NSPopover *)popover;
|
||||
- (void)popoverDidClose:(NSNotification *)notification;
|
||||
- (void)popoverDidShow:(NSNotification *)notification;
|
||||
- (void)popoverShouldClose:(NSNotification *)notification;
|
||||
- (BOOL)popoverShouldClose:(NSPopover *)popover;
|
||||
- (void)popoverWillClose:(NSNotification *)notification;
|
||||
- (void)popoverWillShow:(NSNotification *)notification;
|
||||
@end
|
||||
|
|
|
@ -333,6 +333,19 @@ PACKAGE_SCOPE
|
|||
*/
|
||||
- (NSPoint) convertScreenToBase: (NSPoint)aPoint;
|
||||
|
||||
/**
|
||||
* Converts aRect from the coordinate system of the screen
|
||||
* to the coordinate system of the window.
|
||||
*/
|
||||
|
||||
- (NSRect) convertRectFromScreen: (NSRect)aRect;
|
||||
|
||||
/**
|
||||
* Converts aRect from the window coordinate system to a rect in
|
||||
* the screen coordinate system.
|
||||
*/
|
||||
- (NSRect) convertRectToScreen: (NSRect)aRect;
|
||||
|
||||
/**
|
||||
* Returns the frame of the receiver ... the rectangular area that the window
|
||||
* (including any border, title, and other decorations) occupies on screen.
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#import "AppKit/NSPopover.h"
|
||||
#import "AppKit/NSViewController.h"
|
||||
#import "AppKit/NSView.h"
|
||||
#import "AppKit/NSWindow.h"
|
||||
|
||||
|
||||
/* Class */
|
||||
|
@ -90,12 +91,12 @@
|
|||
return _contentViewController;
|
||||
}
|
||||
|
||||
- (void) setDelegate: (id<NSPopoverDelegate>)value
|
||||
- (void) setDelegate: (id)value
|
||||
{
|
||||
_delegate = value;
|
||||
}
|
||||
|
||||
- (id<NSPopoverDelegate>) delegate
|
||||
- (id) delegate
|
||||
{
|
||||
return _delegate;
|
||||
}
|
||||
|
@ -118,17 +119,86 @@
|
|||
/* Methods */
|
||||
- (void) close
|
||||
{
|
||||
[_realWindow close];
|
||||
[_realWindow setDelegate:nil];
|
||||
}
|
||||
|
||||
- (IBAction) performClose: (id)sender
|
||||
{
|
||||
[_realWindow performClose:sender];
|
||||
[_realWindow setDelegate:nil];
|
||||
}
|
||||
|
||||
- (void) showRelativeToRect: (NSRect)positioningRect
|
||||
ofView: (NSView *)positioningView
|
||||
preferredEdge: (NSRectEdge)preferredEdge
|
||||
{
|
||||
// NSLog(@"Test...");
|
||||
NSView *view = nil;
|
||||
NSRect screenRect;
|
||||
NSRect windowFrame;
|
||||
NSRect viewFrame;
|
||||
|
||||
[_contentViewController loadView];
|
||||
view = [_contentViewController view];
|
||||
viewFrame = [view frame];
|
||||
|
||||
_realWindow = [[NSWindow alloc] initWithContentRect: viewFrame
|
||||
styleMask: NSBorderlessWindowMask
|
||||
backing: NSBackingStoreRetained
|
||||
defer: NO];
|
||||
|
||||
screenRect = [[positioningView window] convertRectToScreen:positioningRect];
|
||||
windowFrame = [_realWindow frame];
|
||||
windowFrame.origin = screenRect.origin;
|
||||
|
||||
if(NSMinXEdge == preferredEdge)
|
||||
{
|
||||
windowFrame.origin.y -= viewFrame.size.height;
|
||||
}
|
||||
else if(NSMaxXEdge == preferredEdge)
|
||||
{
|
||||
windowFrame.origin.y += viewFrame.size.height;
|
||||
}
|
||||
else if(NSMinYEdge == preferredEdge)
|
||||
{
|
||||
windowFrame.origin.x -= viewFrame.size.width;
|
||||
}
|
||||
else if(NSMaxYEdge == preferredEdge)
|
||||
{
|
||||
windowFrame.origin.x += viewFrame.size.width;
|
||||
}
|
||||
|
||||
[_realWindow setFrame: windowFrame display: YES];
|
||||
|
||||
NSLog(@"Showing relative to in window %@",NSStringFromRect(positioningRect));
|
||||
NSLog(@"Showing relative to in screen %@",NSStringFromRect(screenRect));
|
||||
// [_realWindow setBackgroundColor:[NSColor clearColor]];
|
||||
// [_realWindow setOpaque:NO];
|
||||
// [_realWindow setLevel:NSFloatingWindowLevel];
|
||||
// [_realWindow setAlphaValue:0.0];
|
||||
|
||||
[[_realWindow contentView] addSubview: view];
|
||||
[_realWindow setDelegate: self];
|
||||
[_realWindow makeKeyAndOrderFront:self];
|
||||
}
|
||||
|
||||
- (BOOL) windowShouldClose: (id)sender
|
||||
{
|
||||
return [_delegate popoverShouldClose:self];
|
||||
}
|
||||
|
||||
- (void) windowDidClose: (NSNotification *)notification
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSPopoverDidCloseNotification
|
||||
object:self
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
- (void) windowWillClose: (NSNotification *)notification
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSPopoverWillCloseNotification
|
||||
object:self
|
||||
userInfo:nil];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)coder
|
||||
|
@ -142,6 +212,7 @@
|
|||
_animates = [coder decodeBoolForKey: @"NSAnimates"];
|
||||
_contentSize.width = [coder decodeDoubleForKey: @"NSContentWidth"];
|
||||
_contentSize.height = [coder decodeDoubleForKey: @"NSContentHeight"];
|
||||
[self setContentViewController:[coder decodeObjectForKey:@"NSContentViewController"]];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -150,6 +221,7 @@
|
|||
[coder decodeValueOfObjCType: @encode(BOOL) at: &_animates];
|
||||
[coder decodeValueOfObjCType: @encode(CGFloat) at: &_contentSize.width];
|
||||
[coder decodeValueOfObjCType: @encode(CGFloat) at: &_contentSize.height];
|
||||
[self setContentViewController:[coder decodeObject]];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
|
@ -165,6 +237,7 @@
|
|||
[coder encodeBool: _animates forKey: @"NSAnimates"];
|
||||
[coder encodeDouble: _contentSize.width forKey: @"NSContentWidth"];
|
||||
[coder encodeDouble: _contentSize.height forKey: @"NSContentHeight"];
|
||||
[coder encodeObject:_contentViewController forKey:@"NSContentViewController"];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -173,6 +246,7 @@
|
|||
[coder encodeValueOfObjCType: @encode(BOOL) at: &_animates];
|
||||
[coder encodeValueOfObjCType: @encode(CGFloat) at: &_contentSize.width];
|
||||
[coder encodeValueOfObjCType: @encode(CGFloat) at: &_contentSize.height];
|
||||
[coder encodeObject:_contentViewController];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -2374,6 +2374,33 @@ titleWithRepresentedFilename(NSString *representedFilename)
|
|||
return basePoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts aRect from the coordinate system of the screen
|
||||
* to the coordinate system of the window.
|
||||
*/
|
||||
|
||||
- (NSRect) convertRectFromScreen: (NSRect)aRect
|
||||
{
|
||||
NSRect result = aRect;
|
||||
NSPoint origin = result.origin;
|
||||
NSPoint newOrigin = [self convertScreenToBase: origin];
|
||||
result.origin = newOrigin;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts aRect from the window coordinate system to a rect in
|
||||
* the screen coordinate system.
|
||||
*/
|
||||
- (NSRect) convertRectToScreen: (NSRect)aRect
|
||||
{
|
||||
NSRect result = aRect;
|
||||
NSPoint origin = result.origin;
|
||||
NSPoint newOrigin = [self convertBaseToScreen: origin];
|
||||
result.origin = newOrigin;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Managing the display
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue