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:
Fred Kiefer 2009-01-02 21:41:29 +00:00
parent 74d7fcffd8
commit 7e9036c434
5 changed files with 133 additions and 188 deletions

View file

@ -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>
* Headers/Additions/GNUstepGUI/GSToolbarView.h: Remove now

View file

@ -33,6 +33,8 @@
#include "GNUstepGUI/GSDisplayServer.h"
#include "GNUstepGUI/GSTheme.h"
#include "NSToolbarFrameworkPrivate.h"
@implementation GSWindowDecorationView
+ (id<GSWindowDecorator>) windowDecorator
@ -105,7 +107,9 @@
if (self != nil)
{
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]];
}
return self;
@ -114,15 +118,34 @@
- (NSRect) contentRectForFrameRect: (NSRect)aRect
styleMask: (unsigned int)aStyle
{
NSRect content = [isa contentRectForFrameRect: aRect
styleMask: aStyle];
NSToolbar *tb = [_window toolbar];
// TODO: Handle toolbar and others
return [isa contentRectForFrameRect: aRect
styleMask: aStyle];
if ([tb isVisible])
{
GSToolbarView *tv = [tb _toolbarView];
content.size.height -= [tv _heightFromLayout];
}
return content;
}
- (NSRect) frameRectForContentRect: (NSRect)aRect
styleMask: (unsigned int)aStyle
{
NSToolbar *tb = [_window toolbar];
// TODO: Handle toolbar and others
if ([tb isVisible])
{
GSToolbarView *tv = [tb _toolbarView];
aRect.size.height += [tv _heightFromLayout];
}
return [isa frameRectForContentRect: aRect
styleMask: aStyle];
}
@ -177,16 +200,35 @@
{
NSSize oldSize = _frame.size;
NSView *cv = [_window contentView];
NSToolbar *tb = [_window toolbar];
_autoresizes_subviews = NO;
[super setFrame: frameRect];
contentRect = [self contentRectForFrameRect: frameRect
contentRect = [isa contentRectForFrameRect: frameRect
styleMask: [window styleMask]];
// Safety Check.
[cv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[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
@ -240,7 +282,74 @@
@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

View file

@ -1157,7 +1157,7 @@ static GSValidationCenter *vc = nil;
if ([self isVisible])
{
[_toolbarView _reload];
[[_toolbarView window] _adjustToolbarView: _toolbarView];
[(id)[[_toolbarView window] _windowView] adjustToolbarView: _toolbarView];
}
if (broadcast)
@ -1177,7 +1177,7 @@ static GSValidationCenter *vc = nil;
if ([self isVisible])
{
[_toolbarView _reload];
[[_toolbarView window] _adjustToolbarView: _toolbarView];
[(id)[[_toolbarView window] _windowView] adjustToolbarView: _toolbarView];
}
if (broadcast)

View file

@ -35,6 +35,8 @@
#include "AppKit/NSWindow+Toolbar.h"
#include "GNUstepGUI/GSToolbarView.h"
#include "GSWindowDecorationView.h"
@interface GSToolbarView (GNUstepPrivate)
- (void) _reload;
@ -107,12 +109,10 @@
- (BOOL) usesStandardBackgroundColor;
@end
@interface NSWindow (ToolbarPrivate)
- (void) _adjustToolbarView: (GSToolbarView*)view;
- (void) _addToolbarView: (GSToolbarView*)view;
- (void) _removeToolbarView: (GSToolbarView*)view;
- (NSView *) _contentViewWithoutToolbar;
@interface GSWindowDecorationView (ToolbarPrivate)
- (void) addToolbarView: (GSToolbarView*)toolbarView;
- (void) removeToolbarView: (GSToolbarView *)toolbarView;
- (void) adjustToolbarView: (GSToolbarView *)toolbarView;
@end
#endif // _NSToolbarFrameworkPrivate_h_INCLUDE

View file

@ -53,11 +53,11 @@
if (isVisible)
{
[self _removeToolbarView: [toolbar _toolbarView]];
[_wv removeToolbarView: [toolbar _toolbarView]];
}
else
{
[self _addToolbarView: [toolbar _toolbarView]];
[_wv addToolbarView: [toolbar _toolbarView]];
}
// Important to set _visible after the toolbar view has been toggled because
@ -89,7 +89,7 @@
// We throw the last toolbar out
if ([_toolbar isVisible])
{
[self _removeToolbarView: toolbarView];
[_wv removeToolbarView: toolbarView];
}
[toolbarView setToolbar: nil];
// Release the toolbarView, this may release the toolbar
@ -128,7 +128,7 @@
// Make the toolbar view visible
if ([toolbar isVisible])
{
[self _addToolbarView: toolbarView];
[_wv addToolbarView: toolbarView];
}
}
@ -137,175 +137,3 @@
}
@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