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
This commit is contained in:
Alexander Malmberg 2004-07-06 23:31:57 +00:00
parent 7ac30eed06
commit e2178bf8f1
2 changed files with 36 additions and 15 deletions

View file

@ -1,3 +1,10 @@
2004-07-07 01:23 Alexander Malmberg <alexander@malmberg.org>
* 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 <alexander@malmberg.org> 2004-07-06 22:15 Alexander Malmberg <alexander@malmberg.org>
* Headers/Additions/GNUstepGUI/GSDisplayServer.h: Add * Headers/Additions/GNUstepGUI/GSDisplayServer.h: Add

View file

@ -72,7 +72,10 @@
{ {
if (!isVisible) // In the case : not visible when the method has been called 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 // -toogleToolbarViewWithDisplay: will reset the toolbarView frame
[toolbarView _reload]; // Will recalculate the layout [toolbarView _reload]; // Will recalculate the layout
} }
@ -190,7 +193,8 @@
if (toolbarView == nil) if (toolbarView == nil)
{ {
toolbarView = [[GSToolbarView alloc] initWithFrame: NSMakeRect(0, 0, 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 // _toggleToolbarView:display: method will set the toolbar view to the right
// frame // frame
[toolbarView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin]; [toolbarView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin];
@ -258,7 +262,9 @@
NSView *contentViewWithoutToolbar; NSView *contentViewWithoutToolbar;
// Frame // Frame
NSRect windowFrame = [self frame]; NSRect windowContentFrame
= [NSWindow contentRectForFrameRect: [self frame]
styleMask: [self styleMask]];
if ([toolbarView superview] == nil) if ([toolbarView superview] == nil)
{ {
@ -274,16 +280,18 @@
[[NSView alloc] initWithFrame: [_contentView frame]]]; [[NSView alloc] initWithFrame: [_contentView frame]]];
// Resize the window // Resize the window
[self setFrame: NSMakeRect( windowContentFrame.origin.y -= newToolbarViewHeight;
windowFrame.origin.x, windowContentFrame.size.height += newToolbarViewHeight;
windowFrame.origin.y - newToolbarViewHeight,
windowFrame.size.width, [self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
windowFrame.size.height + newToolbarViewHeight) display: NO]; styleMask: [self styleMask]]
display: NO];
// Plug the toolbar view // Plug the toolbar view
contentViewWithoutToolbarFrame = [contentViewWithoutToolbar frame]; contentViewWithoutToolbarFrame = [contentViewWithoutToolbar frame];
[toolbarView setFrame: NSMakeRect( [toolbarView setFrame: NSMakeRect(
0, 0,
@ -294,7 +302,13 @@
[_contentView addSubview: toolbarView]; [_contentView addSubview: toolbarView];
// Insert the previous content view // 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]; [_contentView addSubview: contentViewWithoutToolbar];
RELEASE(contentViewWithoutToolbar); RELEASE(contentViewWithoutToolbar);
} }
@ -312,11 +326,11 @@
[contentViewWithoutToolbar setAutoresizingMask: NSViewMaxYMargin]; [contentViewWithoutToolbar setAutoresizingMask: NSViewMaxYMargin];
[self setFrame: NSMakeRect( windowContentFrame.origin.y += toolbarViewHeight;
windowFrame.origin.x, windowContentFrame.size.height -= toolbarViewHeight;
windowFrame.origin.y + toolbarViewHeight, [self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
windowFrame.size.width, styleMask: [self styleMask]]
windowFrame.size.height - toolbarViewHeight) display: NO]; display: NO];
[contentViewWithoutToolbar setAutoresizingMask: NSViewWidthSizable [contentViewWithoutToolbar setAutoresizingMask: NSViewWidthSizable
| NSViewHeightSizable]; | NSViewHeightSizable];