From e2178bf8f1aae7c2a2f64f3b99014f6ba9d642af Mon Sep 17 00:00:00 2001 From: Alexander Malmberg Date: Tue, 6 Jul 2004 23:31:57 +0000 Subject: [PATCH] Properly convert window frames to content view frames and back. Don't assume that the position of the content view is (0,0). git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19688 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Source/NSWindow+Toolbar.m | 44 ++++++++++++++++++++++++++------------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index a18096710..3231366a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-07-07 01:23 Alexander Malmberg + + * Source/NSWindow+Toolbar.m: Properly convert window frames to + content view frames and back. + (-_toggleToolbarViewWithDisplay:): Move the old content view to the + origin of the new content view. + 2004-07-06 22:15 Alexander Malmberg * Headers/Additions/GNUstepGUI/GSDisplayServer.h: Add diff --git a/Source/NSWindow+Toolbar.m b/Source/NSWindow+Toolbar.m index 7d9c71a93..ae4975654 100644 --- a/Source/NSWindow+Toolbar.m +++ b/Source/NSWindow+Toolbar.m @@ -72,7 +72,10 @@ { if (!isVisible) // In the case : not visible when the method has been called { - [toolbarView setFrameSize: NSMakeSize([self frame].size.width, 100)]; + [toolbarView setFrameSize: + NSMakeSize([NSWindow + contentRectForFrameRect: [self frame] + styleMask: [self styleMask]].size.width, 100)]; // -toogleToolbarViewWithDisplay: will reset the toolbarView frame [toolbarView _reload]; // Will recalculate the layout } @@ -190,7 +193,8 @@ if (toolbarView == nil) { toolbarView = [[GSToolbarView alloc] initWithFrame: NSMakeRect(0, 0, - [self frame].size.width, 100)]; + [NSWindow contentRectForFrameRect: [self frame] + styleMask: [self styleMask]].size.width, 100)]; // _toggleToolbarView:display: method will set the toolbar view to the right // frame [toolbarView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin]; @@ -258,7 +262,9 @@ NSView *contentViewWithoutToolbar; // Frame - NSRect windowFrame = [self frame]; + NSRect windowContentFrame + = [NSWindow contentRectForFrameRect: [self frame] + styleMask: [self styleMask]]; if ([toolbarView superview] == nil) { @@ -274,16 +280,18 @@ [[NSView alloc] initWithFrame: [_contentView frame]]]; // Resize the window - - [self setFrame: NSMakeRect( - windowFrame.origin.x, - windowFrame.origin.y - newToolbarViewHeight, - windowFrame.size.width, - windowFrame.size.height + newToolbarViewHeight) display: NO]; + + windowContentFrame.origin.y -= newToolbarViewHeight; + windowContentFrame.size.height += newToolbarViewHeight; + + [self setFrame: [NSWindow frameRectForContentRect: windowContentFrame + styleMask: [self styleMask]] + display: NO]; // Plug the toolbar view contentViewWithoutToolbarFrame = [contentViewWithoutToolbar frame]; + [toolbarView setFrame: NSMakeRect( 0, @@ -294,7 +302,13 @@ [_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); } @@ -312,11 +326,11 @@ [contentViewWithoutToolbar setAutoresizingMask: NSViewMaxYMargin]; - [self setFrame: NSMakeRect( - windowFrame.origin.x, - windowFrame.origin.y + toolbarViewHeight, - windowFrame.size.width, - windowFrame.size.height - toolbarViewHeight) display: NO]; + windowContentFrame.origin.y += toolbarViewHeight; + windowContentFrame.size.height -= toolbarViewHeight; + [self setFrame: [NSWindow frameRectForContentRect: windowContentFrame + styleMask: [self styleMask]] + display: NO]; [contentViewWithoutToolbar setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];