mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:40:47 +00:00
Move the handling of the toolbar from the window to the window
decoration view. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27505 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
cf906c58bb
commit
0ab9d38e59
5 changed files with 133 additions and 188 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2009-01-02 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/NSWindow+Toolbar.m: Move window toolbar code from here ...
|
||||||
|
* Source/GSWindowDecorationView.m: ... to here.
|
||||||
|
* Source/NSToolbarFrameworkPrivate.h: Declare new window
|
||||||
|
decoration view toolbar handling methods.
|
||||||
|
* Source/NSToolbar.m: Use them.
|
||||||
|
|
||||||
2009-01-02 Fred Kiefer <FredKiefer@gmx.de>
|
2009-01-02 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Headers/Additions/GNUstepGUI/GSToolbarView.h: Remove now
|
* Headers/Additions/GNUstepGUI/GSToolbarView.h: Remove now
|
||||||
|
|
|
@ -33,6 +33,8 @@
|
||||||
#include "GNUstepGUI/GSDisplayServer.h"
|
#include "GNUstepGUI/GSDisplayServer.h"
|
||||||
#include "GNUstepGUI/GSTheme.h"
|
#include "GNUstepGUI/GSTheme.h"
|
||||||
|
|
||||||
|
#include "NSToolbarFrameworkPrivate.h"
|
||||||
|
|
||||||
@implementation GSWindowDecorationView
|
@implementation GSWindowDecorationView
|
||||||
|
|
||||||
+ (id<GSWindowDecorator>) windowDecorator
|
+ (id<GSWindowDecorator>) windowDecorator
|
||||||
|
@ -105,7 +107,9 @@
|
||||||
if (self != nil)
|
if (self != nil)
|
||||||
{
|
{
|
||||||
window = w;
|
window = w;
|
||||||
contentRect = [self contentRectForFrameRect: frame
|
// Content rect will be everything apart from the border
|
||||||
|
// that is including menu, toolbar and the like.
|
||||||
|
contentRect = [isa contentRectForFrameRect: frame
|
||||||
styleMask: [w styleMask]];
|
styleMask: [w styleMask]];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
|
@ -114,15 +118,34 @@
|
||||||
- (NSRect) contentRectForFrameRect: (NSRect)aRect
|
- (NSRect) contentRectForFrameRect: (NSRect)aRect
|
||||||
styleMask: (unsigned int)aStyle
|
styleMask: (unsigned int)aStyle
|
||||||
{
|
{
|
||||||
|
NSRect content = [isa contentRectForFrameRect: aRect
|
||||||
|
styleMask: aStyle];
|
||||||
|
NSToolbar *tb = [_window toolbar];
|
||||||
|
|
||||||
// TODO: Handle toolbar and others
|
// TODO: Handle toolbar and others
|
||||||
return [isa contentRectForFrameRect: aRect
|
if ([tb isVisible])
|
||||||
styleMask: aStyle];
|
{
|
||||||
|
GSToolbarView *tv = [tb _toolbarView];
|
||||||
|
|
||||||
|
content.size.height -= [tv _heightFromLayout];
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRect) frameRectForContentRect: (NSRect)aRect
|
- (NSRect) frameRectForContentRect: (NSRect)aRect
|
||||||
styleMask: (unsigned int)aStyle
|
styleMask: (unsigned int)aStyle
|
||||||
{
|
{
|
||||||
|
NSToolbar *tb = [_window toolbar];
|
||||||
|
|
||||||
// TODO: Handle toolbar and others
|
// TODO: Handle toolbar and others
|
||||||
|
if ([tb isVisible])
|
||||||
|
{
|
||||||
|
GSToolbarView *tv = [tb _toolbarView];
|
||||||
|
|
||||||
|
aRect.size.height += [tv _heightFromLayout];
|
||||||
|
}
|
||||||
|
|
||||||
return [isa frameRectForContentRect: aRect
|
return [isa frameRectForContentRect: aRect
|
||||||
styleMask: aStyle];
|
styleMask: aStyle];
|
||||||
}
|
}
|
||||||
|
@ -177,16 +200,35 @@
|
||||||
{
|
{
|
||||||
NSSize oldSize = _frame.size;
|
NSSize oldSize = _frame.size;
|
||||||
NSView *cv = [_window contentView];
|
NSView *cv = [_window contentView];
|
||||||
|
NSToolbar *tb = [_window toolbar];
|
||||||
|
|
||||||
_autoresizes_subviews = NO;
|
_autoresizes_subviews = NO;
|
||||||
[super setFrame: frameRect];
|
[super setFrame: frameRect];
|
||||||
|
|
||||||
contentRect = [self contentRectForFrameRect: frameRect
|
contentRect = [isa contentRectForFrameRect: frameRect
|
||||||
styleMask: [window styleMask]];
|
styleMask: [window styleMask]];
|
||||||
|
|
||||||
// Safety Check.
|
// Safety Check.
|
||||||
[cv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
|
[cv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
|
||||||
[cv resizeWithOldSuperviewSize: oldSize];
|
[cv resizeWithOldSuperviewSize: oldSize];
|
||||||
|
|
||||||
|
// FIXME: Should resize all subviews
|
||||||
|
if ([tb isVisible])
|
||||||
|
{
|
||||||
|
GSToolbarView *tv = [tb _toolbarView];
|
||||||
|
NSRect contentViewFrame = [cv frame];
|
||||||
|
float newToolbarViewHeight;
|
||||||
|
|
||||||
|
[tv setFrameSize: NSMakeSize(contentViewFrame.size.width, 100)];
|
||||||
|
// Will recalculate the layout
|
||||||
|
[tv _reload];
|
||||||
|
newToolbarViewHeight = [tv _heightFromLayout];
|
||||||
|
[tv setFrame: NSMakeRect(
|
||||||
|
contentViewFrame.origin.x,
|
||||||
|
contentViewFrame.size.height,
|
||||||
|
contentViewFrame.size.width,
|
||||||
|
newToolbarViewHeight)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setInputState: (int)state
|
- (void) setInputState: (int)state
|
||||||
|
@ -240,7 +282,74 @@
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation GSWindowDecorationView (ToolbarPrivate)
|
||||||
|
|
||||||
|
- (void) addToolbarView: (GSToolbarView*)toolbarView
|
||||||
|
{
|
||||||
|
NSView *contentView = [window contentView];
|
||||||
|
NSRect contentViewFrame = [contentView frame];
|
||||||
|
float newToolbarViewHeight;
|
||||||
|
|
||||||
|
[toolbarView setFrameSize: NSMakeSize(contentViewFrame.size.width, 100)];
|
||||||
|
// Will recalculate the layout
|
||||||
|
[toolbarView _reload];
|
||||||
|
newToolbarViewHeight = [toolbarView _heightFromLayout];
|
||||||
|
|
||||||
|
// Plug the toolbar view
|
||||||
|
[toolbarView setFrame: NSMakeRect(
|
||||||
|
contentViewFrame.origin.x,
|
||||||
|
contentViewFrame.size.height - newToolbarViewHeight,
|
||||||
|
contentViewFrame.size.width,
|
||||||
|
newToolbarViewHeight)];
|
||||||
|
[self addSubview: toolbarView];
|
||||||
|
|
||||||
|
// Resize the content view
|
||||||
|
contentViewFrame.size.height -= newToolbarViewHeight;
|
||||||
|
[contentView setFrame: contentViewFrame];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) removeToolbarView: (GSToolbarView *)toolbarView
|
||||||
|
{
|
||||||
|
NSView *contentView = [window contentView];
|
||||||
|
NSRect contentViewFrame = [contentView frame];
|
||||||
|
float toolbarViewHeight = [toolbarView frame].size.height;
|
||||||
|
|
||||||
|
// Unplug the toolbar view
|
||||||
|
[toolbarView removeFromSuperviewWithoutNeedingDisplay];
|
||||||
|
|
||||||
|
// Resize the content view
|
||||||
|
contentViewFrame.size.height += toolbarViewHeight;
|
||||||
|
[contentView setFrame: contentViewFrame];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) adjustToolbarView: (GSToolbarView *)toolbarView
|
||||||
|
{
|
||||||
|
// Frame and height
|
||||||
|
NSRect toolbarViewFrame = [toolbarView frame];
|
||||||
|
float toolbarViewHeight = toolbarViewFrame.size.height;
|
||||||
|
float newToolbarViewHeight = [toolbarView _heightFromLayout];
|
||||||
|
|
||||||
|
if (toolbarViewHeight != newToolbarViewHeight)
|
||||||
|
{
|
||||||
|
NSView *contentView = [window contentView];
|
||||||
|
NSRect contentViewFrame = [contentView frame];
|
||||||
|
|
||||||
|
[toolbarView setFrame: NSMakeRect(
|
||||||
|
toolbarViewFrame.origin.x,
|
||||||
|
toolbarViewFrame.origin.y + (toolbarViewHeight - newToolbarViewHeight),
|
||||||
|
toolbarViewFrame.size.width,
|
||||||
|
newToolbarViewHeight)];
|
||||||
|
|
||||||
|
// Resize the content view
|
||||||
|
contentViewFrame.size.height += toolbarViewHeight - newToolbarViewHeight;
|
||||||
|
[contentView setFrame: contentViewFrame];
|
||||||
|
|
||||||
|
// Redisplay the window
|
||||||
|
[window display];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation GSBackendWindowDecorationView
|
@implementation GSBackendWindowDecorationView
|
||||||
|
|
||||||
|
|
|
@ -1157,7 +1157,7 @@ static GSValidationCenter *vc = nil;
|
||||||
if ([self isVisible])
|
if ([self isVisible])
|
||||||
{
|
{
|
||||||
[_toolbarView _reload];
|
[_toolbarView _reload];
|
||||||
[[_toolbarView window] _adjustToolbarView: _toolbarView];
|
[(id)[[_toolbarView window] _windowView] adjustToolbarView: _toolbarView];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (broadcast)
|
if (broadcast)
|
||||||
|
@ -1177,7 +1177,7 @@ static GSValidationCenter *vc = nil;
|
||||||
if ([self isVisible])
|
if ([self isVisible])
|
||||||
{
|
{
|
||||||
[_toolbarView _reload];
|
[_toolbarView _reload];
|
||||||
[[_toolbarView window] _adjustToolbarView: _toolbarView];
|
[(id)[[_toolbarView window] _windowView] adjustToolbarView: _toolbarView];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (broadcast)
|
if (broadcast)
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
#include "AppKit/NSWindow+Toolbar.h"
|
#include "AppKit/NSWindow+Toolbar.h"
|
||||||
#include "GNUstepGUI/GSToolbarView.h"
|
#include "GNUstepGUI/GSToolbarView.h"
|
||||||
|
|
||||||
|
#include "GSWindowDecorationView.h"
|
||||||
|
|
||||||
@interface GSToolbarView (GNUstepPrivate)
|
@interface GSToolbarView (GNUstepPrivate)
|
||||||
- (void) _reload;
|
- (void) _reload;
|
||||||
|
|
||||||
|
@ -107,12 +109,10 @@
|
||||||
- (BOOL) usesStandardBackgroundColor;
|
- (BOOL) usesStandardBackgroundColor;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface NSWindow (ToolbarPrivate)
|
@interface GSWindowDecorationView (ToolbarPrivate)
|
||||||
- (void) _adjustToolbarView: (GSToolbarView*)view;
|
- (void) addToolbarView: (GSToolbarView*)toolbarView;
|
||||||
- (void) _addToolbarView: (GSToolbarView*)view;
|
- (void) removeToolbarView: (GSToolbarView *)toolbarView;
|
||||||
- (void) _removeToolbarView: (GSToolbarView*)view;
|
- (void) adjustToolbarView: (GSToolbarView *)toolbarView;
|
||||||
- (NSView *) _contentViewWithoutToolbar;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
#endif // _NSToolbarFrameworkPrivate_h_INCLUDE
|
#endif // _NSToolbarFrameworkPrivate_h_INCLUDE
|
||||||
|
|
|
@ -53,11 +53,11 @@
|
||||||
|
|
||||||
if (isVisible)
|
if (isVisible)
|
||||||
{
|
{
|
||||||
[self _removeToolbarView: [toolbar _toolbarView]];
|
[_wv removeToolbarView: [toolbar _toolbarView]];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[self _addToolbarView: [toolbar _toolbarView]];
|
[_wv addToolbarView: [toolbar _toolbarView]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Important to set _visible after the toolbar view has been toggled because
|
// Important to set _visible after the toolbar view has been toggled because
|
||||||
|
@ -89,7 +89,7 @@
|
||||||
// We throw the last toolbar out
|
// We throw the last toolbar out
|
||||||
if ([_toolbar isVisible])
|
if ([_toolbar isVisible])
|
||||||
{
|
{
|
||||||
[self _removeToolbarView: toolbarView];
|
[_wv removeToolbarView: toolbarView];
|
||||||
}
|
}
|
||||||
[toolbarView setToolbar: nil];
|
[toolbarView setToolbar: nil];
|
||||||
// Release the toolbarView, this may release the toolbar
|
// Release the toolbarView, this may release the toolbar
|
||||||
|
@ -128,7 +128,7 @@
|
||||||
// Make the toolbar view visible
|
// Make the toolbar view visible
|
||||||
if ([toolbar isVisible])
|
if ([toolbar isVisible])
|
||||||
{
|
{
|
||||||
[self _addToolbarView: toolbarView];
|
[_wv addToolbarView: toolbarView];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,175 +137,3 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// Private methods
|
|
||||||
@implementation NSWindow (ToolbarPrivate)
|
|
||||||
|
|
||||||
- (NSView *) _contentViewWithoutToolbar
|
|
||||||
{
|
|
||||||
NSToolbar *toolbar = [self toolbar];
|
|
||||||
|
|
||||||
if (toolbar != nil && [toolbar isVisible])
|
|
||||||
{
|
|
||||||
NSArray *subviews = [_contentView subviews];
|
|
||||||
// Take in account this method call returns an array which is an
|
|
||||||
// autoreleased copy.
|
|
||||||
// By side effect, this increments the toolbar view retain count until the
|
|
||||||
// autorelease pool is cleared.
|
|
||||||
NSView *subview;
|
|
||||||
int i, n = [subviews count];
|
|
||||||
GSToolbarView *toolbarView = [toolbar _toolbarView];
|
|
||||||
|
|
||||||
if (n > 2 || ![[toolbarView superview] isEqual: _contentView])
|
|
||||||
{
|
|
||||||
[NSException raise: @"_contentView error"
|
|
||||||
format: @"_contenView is not valid. _contentView needs a \
|
|
||||||
toolbar view and a contentViewWithoutToolbar, with \
|
|
||||||
no others subviews."];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
subview = [subviews objectAtIndex: i];
|
|
||||||
if (![subview isEqual: toolbarView])
|
|
||||||
{
|
|
||||||
return subview;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [self contentView];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) _adjustToolbarView: (GSToolbarView *)toolbarView
|
|
||||||
{
|
|
||||||
// Frame and height
|
|
||||||
NSRect toolbarViewFrame = [toolbarView frame];
|
|
||||||
float toolbarViewHeight = toolbarViewFrame.size.height;
|
|
||||||
float newToolbarViewHeight = [toolbarView _heightFromLayout];
|
|
||||||
|
|
||||||
if (toolbarViewHeight != newToolbarViewHeight)
|
|
||||||
{
|
|
||||||
NSView *contentViewWithoutToolbar = [self _contentViewWithoutToolbar];
|
|
||||||
NSRect windowFrame = [self frame];
|
|
||||||
|
|
||||||
[toolbarView setFrame: NSMakeRect(
|
|
||||||
toolbarViewFrame.origin.x,
|
|
||||||
toolbarViewFrame.origin.y + (toolbarViewHeight - newToolbarViewHeight),
|
|
||||||
toolbarViewFrame.size.width,
|
|
||||||
newToolbarViewHeight)];
|
|
||||||
|
|
||||||
// Resize the window
|
|
||||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewNotSizable];
|
|
||||||
|
|
||||||
[self setFrame: NSMakeRect(
|
|
||||||
windowFrame.origin.x,
|
|
||||||
windowFrame.origin.y + (toolbarViewHeight - newToolbarViewHeight),
|
|
||||||
windowFrame.size.width,
|
|
||||||
windowFrame.size.height - (toolbarViewHeight - newToolbarViewHeight))
|
|
||||||
display: NO];
|
|
||||||
|
|
||||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
|
|
||||||
|
|
||||||
[self display];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) _addToolbarView: (GSToolbarView*)toolbarView
|
|
||||||
{
|
|
||||||
// Views
|
|
||||||
NSView *contentViewWithoutToolbar;
|
|
||||||
|
|
||||||
// Frame
|
|
||||||
NSRect windowContentFrame
|
|
||||||
= [NSWindow contentRectForFrameRect: [self frame]
|
|
||||||
styleMask: [self styleMask]];
|
|
||||||
|
|
||||||
float newToolbarViewHeight;
|
|
||||||
NSRect contentViewWithoutToolbarFrame;
|
|
||||||
|
|
||||||
[toolbarView setFrameSize:
|
|
||||||
NSMakeSize(windowContentFrame.size.width, 100)];
|
|
||||||
// Will recalculate the layout
|
|
||||||
[toolbarView _reload];
|
|
||||||
newToolbarViewHeight = [toolbarView _heightFromLayout];
|
|
||||||
|
|
||||||
contentViewWithoutToolbar = _contentView;
|
|
||||||
contentViewWithoutToolbarFrame = [contentViewWithoutToolbar frame];
|
|
||||||
|
|
||||||
// Switch the content view
|
|
||||||
RETAIN(contentViewWithoutToolbar);
|
|
||||||
[self setContentView:
|
|
||||||
AUTORELEASE([[NSView alloc] initWithFrame:
|
|
||||||
contentViewWithoutToolbarFrame])];
|
|
||||||
|
|
||||||
// Resize the window
|
|
||||||
windowContentFrame.origin.y -= newToolbarViewHeight;
|
|
||||||
windowContentFrame.size.height += newToolbarViewHeight;
|
|
||||||
[self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
|
|
||||||
styleMask: [self styleMask]]
|
|
||||||
display: NO];
|
|
||||||
|
|
||||||
// Plug the toolbar view
|
|
||||||
[toolbarView setFrame: NSMakeRect(
|
|
||||||
0,
|
|
||||||
contentViewWithoutToolbarFrame.size.height,
|
|
||||||
contentViewWithoutToolbarFrame.size.width,
|
|
||||||
newToolbarViewHeight)];
|
|
||||||
[_contentView addSubview: toolbarView];
|
|
||||||
|
|
||||||
// Insert the previous content view
|
|
||||||
/* We want contentViewWithoutToolbarFrame at the origin of our new
|
|
||||||
content view. There's no guarantee that the old position was (0,0). */
|
|
||||||
contentViewWithoutToolbarFrame.origin.x = 0;
|
|
||||||
contentViewWithoutToolbarFrame.origin.y = 0;
|
|
||||||
[contentViewWithoutToolbar setFrame: contentViewWithoutToolbarFrame];
|
|
||||||
|
|
||||||
[_contentView addSubview: contentViewWithoutToolbar];
|
|
||||||
RELEASE(contentViewWithoutToolbar);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) _removeToolbarView: (GSToolbarView *)toolbarView
|
|
||||||
{
|
|
||||||
// Views
|
|
||||||
NSView *contentViewWithoutToolbar;
|
|
||||||
|
|
||||||
// Frame
|
|
||||||
NSRect windowContentFrame
|
|
||||||
= [NSWindow contentRectForFrameRect: [self frame]
|
|
||||||
styleMask: [self styleMask]];
|
|
||||||
|
|
||||||
float toolbarViewHeight = [toolbarView frame].size.height;
|
|
||||||
|
|
||||||
contentViewWithoutToolbar = [self _contentViewWithoutToolbar];
|
|
||||||
|
|
||||||
// Unplug the toolbar view
|
|
||||||
[toolbarView removeFromSuperviewWithoutNeedingDisplay];
|
|
||||||
|
|
||||||
// Resize the window
|
|
||||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewMaxYMargin];
|
|
||||||
|
|
||||||
windowContentFrame.origin.y += toolbarViewHeight;
|
|
||||||
windowContentFrame.size.height -= toolbarViewHeight;
|
|
||||||
[self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
|
|
||||||
styleMask: [self styleMask]]
|
|
||||||
display: NO];
|
|
||||||
|
|
||||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewWidthSizable
|
|
||||||
| NSViewHeightSizable];
|
|
||||||
// Autoresizing mask will be set again by the setContentView: method
|
|
||||||
|
|
||||||
// Switch the content view
|
|
||||||
RETAIN(contentViewWithoutToolbar);
|
|
||||||
// Because setContentView: will release the parent view (aka _contentView) and
|
|
||||||
// its subviews and actually contentViewWithoutToolbar is a subview of _contentView
|
|
||||||
|
|
||||||
[contentViewWithoutToolbar removeFromSuperviewWithoutNeedingDisplay];
|
|
||||||
[self setContentView: contentViewWithoutToolbar];
|
|
||||||
|
|
||||||
RELEASE(contentViewWithoutToolbar);
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue