Add relative window positioning to OakChooser

This commit is contained in:
Allan Odgaard
2013-10-27 19:55:31 +01:00
parent e9d60ce7b7
commit 100423a8ee
2 changed files with 16 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ PUBLIC @interface OakChooser : NSObject
@property (nonatomic, readonly) NSArray* selectedItems;
- (void)showWindow:(id)sender;
- (void)showWindowRelativeToFrame:(NSRect)parentFrame;
- (void)close;
// For subclasses

View File

@@ -123,6 +123,21 @@ NSMutableAttributedString* CreateAttributedStringWithMarkedUpRanges (std::string
[_window makeFirstResponder:_searchField];
}
- (void)showWindowRelativeToFrame:(NSRect)parentFrame
{
if(![_window isVisible])
{
[_window layoutIfNeeded];
NSRect frame = [_window frame];
NSRect parent = parentFrame;
frame.origin.x = NSMinX(parent) + round((NSWidth(parent) - NSWidth(frame)) * 1 / 4);
frame.origin.y = NSMinY(parent) + round((NSHeight(parent) - NSHeight(frame)) * 3 / 4);
[_window setFrame:frame display:NO];
}
[self showWindow:self];
}
- (void)close
{
[_window performClose:self];