2002-06-30 05:14:21 +00:00
|
|
|
/*
|
|
|
|
<title>NSToolbar.m</title>
|
|
|
|
|
|
|
|
<abstract>The toolbar class.</abstract>
|
|
|
|
|
|
|
|
Copyright (C) 2002 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Gregory John Casamento <greg_casamento@yahoo.com>,
|
|
|
|
Fabien Vallon <fabien.vallon@fr.alcove.com>
|
|
|
|
Date: May 2002
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Foundation/NSObject.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSNotification.h>
|
2004-02-25 03:27:23 +00:00
|
|
|
#include <Foundation/NSLock.h>
|
2002-06-30 05:14:21 +00:00
|
|
|
#include <Foundation/NSUserDefaults.h>
|
2003-06-13 15:01:12 +00:00
|
|
|
#include "AppKit/NSToolbarItem.h"
|
|
|
|
#include "AppKit/NSToolbar.h"
|
|
|
|
#include "AppKit/NSView.h"
|
2004-02-25 03:27:23 +00:00
|
|
|
#include "AppKit/NSClipView.h"
|
2003-06-13 15:01:12 +00:00
|
|
|
#include "AppKit/NSButton.h"
|
|
|
|
#include "AppKit/NSNibLoading.h"
|
2004-02-25 03:27:23 +00:00
|
|
|
#include "AppKit/NSBezierPath.h"
|
|
|
|
#include "AppKit/NSImage.h"
|
|
|
|
#include "AppKit/NSMenu.h"
|
|
|
|
#include "AppKit/NSEvent.h"
|
|
|
|
#include "AppKit/NSWindow.h"
|
2003-08-24 17:22:11 +00:00
|
|
|
#include "GNUstepGUI/GSToolbarView.h"
|
2002-06-30 05:14:21 +00:00
|
|
|
|
2002-12-29 05:38:29 +00:00
|
|
|
// internal
|
2002-06-30 05:14:21 +00:00
|
|
|
static NSNotificationCenter *nc = nil;
|
|
|
|
static const int current_version = 1;
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
static NSMutableArray *toolbars;
|
|
|
|
|
|
|
|
|
|
|
|
@interface NSToolbar (GNUstepPrivate)
|
|
|
|
// Private class methods
|
|
|
|
+ (NSArray *) _toolbars;
|
|
|
|
+ (NSArray *) _toolbarsForIdentifier: (NSString *)identifier;
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
- (void) _insertItemWithItemIdentifier: (NSString *)itemIdentifier atIndex: (int)index broadcast: (BOOL)broadcast;
|
|
|
|
|
|
|
|
// Private methods with broacast support
|
|
|
|
- (void) _insertItemWithItemIdentifier: (NSString *)itemIdentifier atIndex: (int)index broadcast: (BOOL)broadcast;
|
|
|
|
- (void) _removeItemAtIndex: (int)index broadcast: (BOOL)broadcast;
|
|
|
|
- (void) _setAllowsUserCustomization: (BOOL)flag broadcast: (BOOL)broadcast;
|
|
|
|
- (void) _setAutosavesConfiguration: (BOOL)flag broadcast: (BOOL)broadcast;
|
|
|
|
- (void) _setConfigurationFromDictionary: (NSDictionary *)configDict broadcast: (BOOL)broadcast;
|
|
|
|
- (void) _setDisplayMode: (NSToolbarDisplayMode)displayMode broadcast: (BOOL)broadcast;
|
|
|
|
- (void) _setVisible: (BOOL)shown broadcast: (BOOL)broadcast;
|
|
|
|
- (void) _setDelegate: (id)delegate broadcast: (BOOL)broadcast;
|
|
|
|
|
|
|
|
// Few other private methods
|
|
|
|
- (void) _build;
|
|
|
|
- (void) _loadConfig;
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
- (void) _setToolbarView: (GSToolbarView *)toolbarView;
|
|
|
|
- (GSToolbarView *) _toolbarView;
|
|
|
|
- (void) _setWindow: (NSWindow *)window;
|
|
|
|
- (NSWindow *) _window;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSToolbarItem (GNUstepPrivate)
|
|
|
|
- (void) _setToolbar: (NSToolbar *)toolbar;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface GSToolbarView (GNUstepPrivate)
|
|
|
|
- (void) _reload;
|
|
|
|
- (NSArray *) _visibleBackViews;
|
|
|
|
- (BOOL) _willBeVisible;
|
|
|
|
- (void) _setWillBeVisible: (BOOL)willBeVisible;
|
|
|
|
@end
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
@implementation NSToolbar
|
|
|
|
|
|
|
|
// Class methods
|
|
|
|
|
|
|
|
// Initialize the class when it is loaded
|
|
|
|
+ (void) initialize
|
2003-11-11 19:40:18 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
if (self == [NSToolbar class])
|
2003-11-11 19:40:18 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
[self setVersion: current_version];
|
|
|
|
nc = [NSNotificationCenter defaultCenter];
|
|
|
|
toolbars = [[NSMutableArray alloc] init];
|
2003-11-11 19:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
// Private class methods
|
2003-07-21 10:41:10 +00:00
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
+ (NSArray *) _toolbars
|
|
|
|
{
|
|
|
|
return toolbars;
|
2003-07-21 10:41:10 +00:00
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
+ (NSArray *) _toolbarsForIdentifier: (NSString *)identifier
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
NSMutableArray *wanted = [[NSMutableArray alloc] init];
|
|
|
|
NSArray *identifiers = [toolbars valueForKey: @"identifier"];
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
if (identifiers == nil)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
n = [identifiers count];
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
if ([[identifiers objectAtIndex: i] isEqualToString: identifier])
|
|
|
|
{
|
|
|
|
[wanted addObject: [toolbars objectAtIndex: i]];
|
|
|
|
}
|
|
|
|
}
|
2003-08-24 17:22:11 +00:00
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
return wanted;
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
// ---
|
|
|
|
|
|
|
|
// Instance methods
|
|
|
|
|
|
|
|
- (id) initWithIdentifier: (NSString*)identifier
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
NSArray *linked;
|
|
|
|
NSToolbar *toolbarModel = nil;
|
|
|
|
|
|
|
|
[super init];
|
|
|
|
|
|
|
|
ASSIGN(_identifier, identifier);
|
|
|
|
|
|
|
|
_items = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
linked = [NSToolbar _toolbarsForIdentifier: _identifier];
|
|
|
|
|
|
|
|
if (linked != nil && [linked count] > 0)
|
|
|
|
{
|
|
|
|
toolbarModel = [linked objectAtIndex: 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toolbarModel != nil)
|
|
|
|
{
|
|
|
|
_customizationPaletteIsRunning = NO;
|
|
|
|
_allowsUserCustomization = [toolbarModel allowsUserCustomization];
|
|
|
|
_autosavesConfiguration = [toolbarModel autosavesConfiguration];
|
|
|
|
ASSIGN(_configurationDictionary, [toolbarModel configurationDictionary]);
|
|
|
|
_displayMode = [toolbarModel displayMode];
|
|
|
|
_visible = [toolbarModel isVisible];
|
|
|
|
|
|
|
|
//[self _loadConfig];
|
|
|
|
|
|
|
|
[self _setDelegate: [toolbarModel delegate] broadcast: NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_customizationPaletteIsRunning = NO;
|
|
|
|
_allowsUserCustomization = NO;
|
|
|
|
_autosavesConfiguration = NO;
|
|
|
|
_configurationDictionary = nil;
|
|
|
|
_displayMode = NSToolbarDisplayModeDefault;
|
|
|
|
_visible = YES;
|
|
|
|
_items = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
[self _loadConfig];
|
|
|
|
|
|
|
|
_delegate = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
[toolbars addObject: self];
|
|
|
|
|
|
|
|
return self;
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) dealloc
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
DESTROY (_identifier);
|
|
|
|
DESTROY (_configurationDictionary);
|
2003-08-24 17:22:11 +00:00
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
if (_delegate != nil)
|
2003-08-24 17:22:11 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
[nc removeObserver: _delegate name: nil object: self];
|
|
|
|
_delegate = nil;
|
2003-08-24 17:22:11 +00:00
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
[super dealloc];
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) insertItemWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
atIndex: (int)index
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
[self _insertItemWithItemIdentifier: itemIdentifier atIndex: index broadcast: YES];
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) removeItemAtIndex: (int)index
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
[self _removeItemAtIndex: index broadcast: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) runCustomizationPalette: (id)sender
|
|
|
|
{
|
|
|
|
_customizationPaletteIsRunning = [NSBundle loadNibNamed: @"GSToolbarCustomizationPalette"
|
|
|
|
owner: self];
|
|
|
|
if(!_customizationPaletteIsRunning)
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
NSLog(@"Failed to load gorm for GSToolbarCustomizationPalette");
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) validateVisibleItems
|
|
|
|
{
|
|
|
|
NSEnumerator *en = [[self visibleItems] objectEnumerator];
|
|
|
|
NSToolbarItem *item = nil;
|
|
|
|
|
|
|
|
while((item = [en nextObject]) != nil)
|
|
|
|
{
|
|
|
|
[item validate];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
|
2002-10-13 07:00:38 +00:00
|
|
|
- (BOOL) allowsUserCustomization
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _allowsUserCustomization;
|
|
|
|
}
|
|
|
|
|
2002-10-13 07:00:38 +00:00
|
|
|
- (BOOL) autosavesConfiguration
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _autosavesConfiguration;
|
|
|
|
}
|
|
|
|
|
2002-10-13 07:00:38 +00:00
|
|
|
- (NSDictionary *) configurationDictionary
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _configurationDictionary;
|
|
|
|
}
|
|
|
|
|
2002-10-13 07:00:38 +00:00
|
|
|
- (BOOL) customizationPaletteIsRunning
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _customizationPaletteIsRunning;
|
|
|
|
}
|
|
|
|
|
2002-10-13 07:00:38 +00:00
|
|
|
- (id) delegate
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _delegate;
|
|
|
|
}
|
|
|
|
|
2002-10-13 07:00:38 +00:00
|
|
|
- (NSToolbarDisplayMode) displayMode
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _displayMode;
|
|
|
|
}
|
|
|
|
|
2002-10-13 07:00:38 +00:00
|
|
|
- (NSString *) identifier
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _identifier;
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (BOOL) isVisible
|
|
|
|
{
|
|
|
|
return _visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) items
|
|
|
|
{
|
|
|
|
return _items;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) selectedItemIdentifier
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) visibleItems
|
|
|
|
{
|
|
|
|
return [[_toolbarView _visibleBackViews] valueForKey: @"toolbarItem"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAllowsUserCustomization: (BOOL)flag
|
|
|
|
{
|
|
|
|
[self _setAllowsUserCustomization: flag broadcast: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAutosavesConfiguration: (BOOL)flag
|
|
|
|
{
|
|
|
|
[self _setAutosavesConfiguration: flag broadcast: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setConfigurationFromDictionary: (NSDictionary *)configDict
|
|
|
|
{
|
|
|
|
ASSIGN(_configurationDictionary, configDict);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the receivers delegate ... this is the object which will receive
|
|
|
|
* -toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:
|
|
|
|
* -toolbarAllowedItemIdentifiers: and -toolbarDefaultItemIdentifiers:
|
|
|
|
* messages.
|
|
|
|
*/
|
|
|
|
|
|
|
|
- (void) setDelegate: (id)delegate
|
|
|
|
{
|
|
|
|
[self _setDelegate: delegate broadcast: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDisplayMode: (NSToolbarDisplayMode)displayMode
|
|
|
|
{
|
|
|
|
[self _setDisplayMode: displayMode broadcast: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSelectedItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSizeMode: (NSToolbarSizeMode)sizeMode
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setVisible: (BOOL)shown
|
|
|
|
{
|
|
|
|
[self _setVisible: shown broadcast: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSToolbarSizeMode) sizeMode
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Private methods
|
|
|
|
|
|
|
|
- (void) _build
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* toolbar build :
|
|
|
|
* will use the delegate when there is no toolbar model
|
|
|
|
*/
|
|
|
|
|
|
|
|
NSToolbar *toolbarModel;
|
|
|
|
NSArray *wantedItemIdentifiers;
|
|
|
|
NSEnumerator *e;
|
|
|
|
id itemIdentifier;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
_build = YES;
|
|
|
|
|
|
|
|
RELEASE(_items);
|
|
|
|
_items = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
toolbarModel = [[NSToolbar _toolbarsForIdentifier: _identifier] objectAtIndex: 0];
|
|
|
|
if (toolbarModel != nil && toolbarModel != self)
|
|
|
|
{
|
|
|
|
wantedItemIdentifiers = [[toolbarModel items] valueForKey: @"itemIdentifier"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wantedItemIdentifiers = [_delegate toolbarDefaultItemIdentifiers:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
e = [wantedItemIdentifiers objectEnumerator];
|
|
|
|
while ((itemIdentifier = [e nextObject]) != nil)
|
|
|
|
{
|
|
|
|
[self _insertItemWithItemIdentifier: itemIdentifier atIndex: i broadcast: NO];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
_build = NO;
|
|
|
|
}
|
|
|
|
|
2002-06-30 05:14:21 +00:00
|
|
|
- (void) _loadConfig
|
|
|
|
{
|
|
|
|
if(_identifier != nil)
|
|
|
|
{
|
|
|
|
NSUserDefaults *defaults;
|
|
|
|
NSString *tableKey;
|
|
|
|
id config;
|
|
|
|
|
|
|
|
defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
tableKey = [NSString stringWithFormat: @"NSToolbar Config %@",
|
|
|
|
_identifier];
|
|
|
|
config = [defaults objectForKey: tableKey];
|
|
|
|
if (config != nil)
|
|
|
|
{
|
2002-12-29 05:38:29 +00:00
|
|
|
[self setConfigurationFromDictionary: config];
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-03 21:41:09 +00:00
|
|
|
- (id) _toolbarItemForIdentifier: (NSString *)itemIdent
|
|
|
|
{
|
|
|
|
id item = nil;
|
|
|
|
if([itemIdent isEqual: NSToolbarSeparatorItemIdentifier] ||
|
|
|
|
[itemIdent isEqual: NSToolbarSpaceItemIdentifier] ||
|
|
|
|
[itemIdent isEqual: NSToolbarFlexibleSpaceItemIdentifier] ||
|
|
|
|
[itemIdent isEqual: NSToolbarShowColorsItemIdentifier] ||
|
|
|
|
[itemIdent isEqual: NSToolbarShowFontsItemIdentifier] ||
|
|
|
|
[itemIdent isEqual: NSToolbarCustomizeToolbarItemIdentifier] ||
|
|
|
|
[itemIdent isEqual: NSToolbarPrintItemIdentifier])
|
|
|
|
{
|
|
|
|
item = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdent];
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* The methods below handles the toolbar edition and broacasts each associated event
|
|
|
|
* to the other toolbars with identical identifiers.
|
|
|
|
*
|
|
|
|
*/
|
2002-09-24 01:33:36 +00:00
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
#define TRANSMIT(signature) \
|
|
|
|
NSEnumerator *e = [[NSToolbar _toolbarsForIdentifier: _identifier] objectEnumerator]; \
|
|
|
|
NSToolbar *toolbar; \
|
|
|
|
\
|
|
|
|
while ((toolbar = [e nextObject]) != nil) \
|
|
|
|
{ \
|
|
|
|
if (toolbar != self) \
|
|
|
|
[toolbar signature]; \
|
2002-09-24 01:33:36 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) _insertItemWithItemIdentifier: (NSString *)itemIdentifier atIndex: (int)index broadcast: (BOOL)broadcast
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2003-09-13 20:59:10 +00:00
|
|
|
NSToolbarItem *item = nil;
|
|
|
|
NSArray *allowedItems = [_delegate toolbarAllowedItemIdentifiers: self];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2003-09-13 20:59:10 +00:00
|
|
|
if([allowedItems containsObject: itemIdentifier])
|
|
|
|
{
|
2004-03-03 21:41:09 +00:00
|
|
|
item = [self _toolbarItemForIdentifier: itemIdentifier];
|
|
|
|
if(item == nil)
|
|
|
|
{
|
|
|
|
item = [_delegate toolbar: self
|
|
|
|
itemForItemIdentifier: itemIdentifier
|
|
|
|
willBeInsertedIntoToolbar: YES];
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
if (item != nil)
|
2004-03-03 21:41:09 +00:00
|
|
|
{
|
|
|
|
[nc postNotificationName: NSToolbarWillAddItemNotification object: self];
|
|
|
|
[item _setToolbar: self];
|
|
|
|
[_items insertObject: item atIndex: index];
|
|
|
|
// We reload the toolbarView each time a new item is
|
|
|
|
// added except when we build/create the toolbar
|
|
|
|
if (!_build)
|
|
|
|
[_toolbarView _reload];
|
|
|
|
|
|
|
|
if (broadcast)
|
|
|
|
{
|
|
|
|
TRANSMIT(_insertItemWithItemIdentifier: itemIdentifier
|
|
|
|
atIndex: index broadcast: NO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) _removeItemAtIndex: (int)index broadcast: (BOOL)broadcast
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2002-12-22 16:14:00 +00:00
|
|
|
|
|
|
|
[_items removeObjectAtIndex: index];
|
2004-02-25 03:27:23 +00:00
|
|
|
[_toolbarView _reload];
|
2002-12-22 16:14:00 +00:00
|
|
|
[nc postNotificationName: NSToolbarDidRemoveItemNotification
|
|
|
|
object: self];
|
2002-06-30 05:14:21 +00:00
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
if (broadcast)
|
2003-09-13 20:59:10 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
TRANSMIT(_removeItemAtIndex: index broadcast: NO);
|
2003-09-13 20:59:10 +00:00
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) _setAllowsUserCustomization: (BOOL)flag broadcast: (BOOL)broadcast
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
_allowsUserCustomization = flag;
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
if (broadcast)
|
|
|
|
{
|
|
|
|
TRANSMIT(_setAllowsUserCustomization: _allowsUserCustomization broadcast: NO);
|
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) _setAutosavesConfiguration: (BOOL)flag broadcast: (BOOL)broadcast
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
_autosavesConfiguration = flag;
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
if (broadcast)
|
|
|
|
{
|
|
|
|
TRANSMIT(_setAutosavesConfiguration: _autosavesConfiguration broadcast: NO);
|
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) _setConfigurationFromDictionary: (NSDictionary *)configDict broadcast: (BOOL)broadcast
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_configurationDictionary, configDict);
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
if (broadcast)
|
|
|
|
{
|
|
|
|
TRANSMIT(_setConfigurationFromDictionary: _configurationDictionary broadcast: NO);
|
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) _setDisplayMode: (NSToolbarDisplayMode)displayMode broadcast: (BOOL)broadcast
|
|
|
|
{
|
|
|
|
_displayMode = displayMode;
|
|
|
|
|
|
|
|
if (broadcast)
|
|
|
|
{
|
|
|
|
TRANSMIT(_setDisplayMode: _displayMode broadcast: NO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setVisible: (BOOL)shown broadcast: (BOOL)broadcast
|
|
|
|
{
|
|
|
|
if (_visible != shown)
|
|
|
|
{
|
|
|
|
if (_window)
|
|
|
|
{
|
|
|
|
if (shown)
|
|
|
|
[_toolbarView _setWillBeVisible: YES];
|
|
|
|
|
|
|
|
[_window toggleToolbarShown: self];
|
|
|
|
|
|
|
|
[_toolbarView _setWillBeVisible: NO];
|
|
|
|
_visible = shown;
|
|
|
|
// Important to set _visible after the toolbar has been toggled
|
|
|
|
// because NSWindow method contentViewWithoutToolbar uses [NSToolbar visible]
|
|
|
|
// when we toggle the toolbar
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSLog(@"setVisible: doesn't work because the toolbar is not a window toolbar.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (broadcast)
|
|
|
|
{
|
|
|
|
TRANSMIT(_setVisible: _visible broadcast: NO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_setDelegate: (id)delegate broadcast: (BOOL)broadcast
|
|
|
|
{
|
|
|
|
#define CHECK_REQUIRED_METHOD(selector_name) \
|
2002-10-13 07:00:38 +00:00
|
|
|
if (![delegate respondsToSelector: @selector(selector_name)]) \
|
2002-06-30 05:14:21 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException \
|
2004-02-25 03:27:23 +00:00
|
|
|
format: @"delegate does not respond to %@",@#selector_name]
|
2002-06-30 05:14:21 +00:00
|
|
|
|
|
|
|
CHECK_REQUIRED_METHOD(toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:);
|
|
|
|
CHECK_REQUIRED_METHOD(toolbarAllowedItemIdentifiers:);
|
|
|
|
CHECK_REQUIRED_METHOD(toolbarDefaultItemIdentifiers:);
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
if (_delegate)
|
2002-06-30 05:14:21 +00:00
|
|
|
[nc removeObserver: _delegate name: nil object: self];
|
2002-10-13 07:00:38 +00:00
|
|
|
_delegate = delegate;
|
2002-06-30 05:14:21 +00:00
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
#define SET_DELEGATE_NOTIFICATION(notif_name) \
|
2002-06-30 05:14:21 +00:00
|
|
|
if ([_delegate respondsToSelector: @selector(toolbar##notif_name:)]) \
|
|
|
|
[nc addObserver: _delegate \
|
2004-02-25 03:27:23 +00:00
|
|
|
selector: @selector(toolbar##notif_name:) \
|
|
|
|
name: NSToolbar##notif_name##Notification object: self]
|
2002-06-30 05:14:21 +00:00
|
|
|
|
|
|
|
SET_DELEGATE_NOTIFICATION(DidRemoveItem);
|
|
|
|
SET_DELEGATE_NOTIFICATION(WillAddItem);
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
if (_window != nil) // The delegate should be called when the toolbar will become visible (= window not nil)
|
|
|
|
{
|
|
|
|
[self _build]; // Build the toolbar with the delegate or a toolbar model
|
|
|
|
[_toolbarView _reload];
|
|
|
|
}
|
|
|
|
|
|
|
|
// broadcast now...
|
|
|
|
|
|
|
|
if (broadcast)
|
|
|
|
{
|
|
|
|
TRANSMIT(_setDelegate: _delegate broadcast: NO);
|
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
// Private Accessors
|
|
|
|
|
|
|
|
- (void) _setToolbarView: (GSToolbarView *)toolbarView
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
ASSIGN(_toolbarView, toolbarView);
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (GSToolbarView *) _toolbarView
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
return _toolbarView;
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void)_setWindow: (NSWindow *)window
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
ASSIGN(_window, window); // call [NSWindow(Toolbar) setToolbar:] to set the toolbar window
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (NSWindow *) _window
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
return _window;
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
@end
|