From 88160ba73375cf9d3548ad9ed58913206b05223f Mon Sep 17 00:00:00 2001 From: fredkiefer Date: Wed, 7 Jan 2009 08:49:53 +0000 Subject: [PATCH] Revert the relationship between NSToolbar and GSToolbarView, now the toolbar retains the view. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27550 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Source/GSToolbarView.m | 7 +------ Source/NSToolbar.m | 21 ++++++++++++--------- Source/NSWindow+Toolbar.m | 29 +++++++---------------------- 4 files changed, 27 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index ed5f13e7d..37d0e153b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-01-07 Fred Kiefer + + * Source/NSWindow+Toolbar.m, + * Source/NSToolbar.m, + * Source/GSToolbarView.m: Revert the relationship between + NSToolbar and GSToolbarView, now the toolbar retains the view. + 2009-01-07 Richard Frith-Macdonald * Source/GSTheme.m: diff --git a/Source/GSToolbarView.m b/Source/GSToolbarView.m index 2dd593927..9c6c61680 100644 --- a/Source/GSToolbarView.m +++ b/Source/GSToolbarView.m @@ -325,7 +325,6 @@ static void initSystemExtensionsColors(void) [[NSNotificationCenter defaultCenter] removeObserver: self]; - RELEASE(_toolbar); RELEASE(_clippedItemsMark); RELEASE(_clipView); @@ -567,11 +566,7 @@ static void initSystemExtensionsColors(void) if (_toolbar == toolbar) return; - // We unset the toolbar view from the previous toolbar - [_toolbar _setToolbarView: nil]; - ASSIGN(_toolbar, toolbar); - // We set the toolbar view on the new toolbar - [_toolbar _setToolbarView: self]; + _toolbar = toolbar; [_clippedItemsMark setToolbar: _toolbar]; // Load the toolbar in the toolbar view diff --git a/Source/NSToolbar.m b/Source/NSToolbar.m index 0e6df8be6..7c0378308 100644 --- a/Source/NSToolbar.m +++ b/Source/NSToolbar.m @@ -546,8 +546,7 @@ static GSValidationCenter *vc = nil; - (void) dealloc { //NSLog(@"Toolbar dealloc %@", self); - - [vc removeObserver: self window: nil]; + [self _setToolbarView: nil]; // Use DESTROY ? RELEASE(_identifier); @@ -567,10 +566,8 @@ static GSValidationCenter *vc = nil; // FIXME: Hack - (void) release { - // We currently only worry about when our toolbar view is deallocated. - // Views which belongs to a window which is deallocated, are released. - // In such case, it's necessary to remove the toolbar which belongs to this - // view from the master list when nobody else still retains us, so that it + // When a toolbar has no external references any more, it's necessary + // to remove the toolbar from the master list, so that it // doesn't cause a memory leak. if ([self retainCount] == 2) [toolbars removeObjectIdenticalTo: self]; @@ -1206,18 +1203,24 @@ static GSValidationCenter *vc = nil; - (void) _setToolbarView: (GSToolbarView *)toolbarView { + if (_toolbarView == toolbarView) + return; + if (_toolbarView != nil) { + // We unset the toolbar from the previous toolbar view + [_toolbarView setToolbar: nil]; [vc removeObserver: self window: nil]; } - // Don't do an ASSIGN here, the toolbar itself retains us. - _toolbarView = toolbarView; + ASSIGN(_toolbarView, toolbarView); if (toolbarView != nil) { - [vc addObserver: self window: [toolbarView window]]; // In the case the window parameter is a nil value, nothing happens. + [vc addObserver: self window: [toolbarView window]]; + // We set the toolbar on the new toolbar view + [_toolbarView setToolbar: self]; } } diff --git a/Source/NSWindow+Toolbar.m b/Source/NSWindow+Toolbar.m index 6fa506c06..d4d20c41f 100644 --- a/Source/NSWindow+Toolbar.m +++ b/Source/NSWindow+Toolbar.m @@ -60,11 +60,6 @@ [_wv addToolbarView: [toolbar _toolbarView]]; } - // Important to set _visible after the toolbar view has been toggled because - // NSWindow method _contentViewWithoutToolbar uses [NSToolbar visible] - // when we toggle the toolbar - // example : the toolbar needs to be still known visible in order to hide - // it. [toolbar setVisible: !isVisible]; [self display]; @@ -84,16 +79,11 @@ if (_toolbar != nil) { - GSToolbarView *toolbarView = [_toolbar _toolbarView]; - // We throw the last toolbar out if ([_toolbar isVisible]) { - [_wv removeToolbarView: toolbarView]; + [_wv removeToolbarView: [_toolbar _toolbarView]]; } - [toolbarView setToolbar: nil]; - // Release the toolbarView, this may release the toolbar - RELEASE(toolbarView); } ASSIGN(_toolbar, toolbar); @@ -102,27 +92,22 @@ { GSToolbarView *toolbarView = [toolbar _toolbarView]; - if (toolbarView != nil) - { - NSLog(@"Error: the new toolbar is still owned by a toolbar view"); - } - else + if (toolbarView == nil) { // Instantiate the toolbar view - // FIXME: Currently this is reatined until the toolbar - // gets removed from the window. toolbarView = [[GSToolbarView alloc] initWithFrame: NSMakeRect(0, 0, [NSWindow contentRectForFrameRect: [self frame] styleMask: [self styleMask]].size.width, 100)]; - // _toggleToolbarView method will set the toolbar view to the right + // addToolbarView: method will set the toolbar view to the right // frame [toolbarView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin]; [toolbarView setBorderMask: GSToolbarViewBottomBorder]; - // Load the toolbar inside the toolbar view - // Will set the _toolbarView variable for the toolbar - [toolbarView setToolbar: toolbar]; + + // Load the toolbar view inside the toolbar + [toolbar _setToolbarView: toolbarView]; + RELEASE(toolbarView); } // Make the toolbar view visible