Extension and clean up of NSToolbarItem.

Add new class NSToolbarItemGroup.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27469 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2008-12-30 22:20:21 +00:00
parent caa3dc7481
commit 8fa68d2f6f
10 changed files with 497 additions and 388 deletions

View file

@ -1,3 +1,17 @@
2008-12-30 Fred Kiefer <FredKiefer@gmx.de>
* Headers/Additions/GNUstepGUI/GSToolbar.h (-_toolbars): Remove.
* Source/NSWindow+Toolbar.m: Add [GSToolbar _toolbars] declaration
here.
* Source/GSToolbar.m,
* Source/NSToolbar.m: Simplify by adding helper methods and
removing dead code.
* Headers/AppKit/NSToolbarItemGroup.h,
* Source/NSToolbarItemGroup.m: New files.
* Source/GNUmakefile: Add new files.
* Headers/AppKit/NSToolbarItem.h: Add 10.5 methods and constants.
* Source/NSToolbarItem.m: New methods and general rewrite.
2008-12-29 Richard Frith-Macdonald <rfm@gnu.org> 2008-12-29 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSInfoPanel.m: * Source/GSInfoPanel.m:

View file

@ -113,11 +113,6 @@ APPKIT_EXPORT NSString *NSToolbarWillAddItemNotification;
- (void) setUsesStandardBackgroundColor: (BOOL)standard; - (void) setUsesStandardBackgroundColor: (BOOL)standard;
- (NSToolbarSizeMode) sizeMode; - (NSToolbarSizeMode) sizeMode;
// Private class method
+ (NSMutableArray *) _toolbars;
@end /* interface of NSToolbar */ @end /* interface of NSToolbar */
/* /*
@ -141,11 +136,4 @@ willBeInsertedIntoToolbar: (BOOL)flag;
- (NSArray *) toolbarSelectableItemIdentifiers: (GSToolbar *)toolbar; - (NSArray *) toolbarSelectableItemIdentifiers: (GSToolbar *)toolbar;
@end @end
// Extensions
@interface NSArray (ObjectsWithValueForKey)
- (NSArray *) objectsWithValue: (id)value forKey: (NSString *)key;
@end
#endif /* _GNUstep_H_NSToolbar */ #endif /* _GNUstep_H_NSToolbar */

View file

@ -57,10 +57,19 @@ APPKIT_EXPORT NSString *NSToolbarShowFontsItemIdentifier;
APPKIT_EXPORT NSString *NSToolbarCustomizeToolbarItemIdentifier; APPKIT_EXPORT NSString *NSToolbarCustomizeToolbarItemIdentifier;
APPKIT_EXPORT NSString *NSToolbarPrintItemIdentifier; APPKIT_EXPORT NSString *NSToolbarPrintItemIdentifier;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
enum _NSToolbarItemVisibilityPriority {
NSToolbarItemVisibilityPriorityStandard = 0,
NSToolbarItemVisibilityPriorityLow = -1000,
NSToolbarItemVisibilityPriorityHigh = 1000,
NSToolbarItemVisibilityPriorityUser = 2000
};
#endif
@interface NSToolbarItem : NSObject <NSCopying, NSValidatedUserInterfaceItem> @interface NSToolbarItem : NSObject <NSCopying, NSValidatedUserInterfaceItem>
{ {
// externally visible variables // externally visible variables
BOOL _allowsDuplicatesInToolbar; BOOL _autovalidates;
NSString *_itemIdentifier; NSString *_itemIdentifier;
NSString *_label; NSString *_label;
NSString *_paletteLabel; NSString *_paletteLabel;
@ -68,7 +77,8 @@ APPKIT_EXPORT NSString *NSToolbarPrintItemIdentifier;
id _view; id _view;
NSMenuItem *_menuFormRepresentation; NSMenuItem *_menuFormRepresentation;
NSString *_toolTip; NSString *_toolTip;
int _tag; NSInteger _tag;
NSInteger _visibilityPriority;
// toolbar // toolbar
GSToolbar *_toolbar; GSToolbar *_toolbar;
@ -86,18 +96,17 @@ APPKIT_EXPORT NSString *NSToolbarPrintItemIdentifier;
{ {
// gets // gets
unsigned int _isEnabled:1; unsigned int _isEnabled:1;
unsigned int _tag:1;
unsigned int _action:1; unsigned int _action:1;
unsigned int _target:1; unsigned int _target:1;
unsigned int _image:1; unsigned int _image:1;
// sets // sets
unsigned int _setEnabled:1; unsigned int _setEnabled:1;
unsigned int _setTag:1;
unsigned int _setAction:1; unsigned int _setAction:1;
unsigned int _setTarget:1; unsigned int _setTarget:1;
unsigned int _setImage:1; unsigned int _setImage:1;
// to even out the long.
unsigned int RESERVED:22; // to even out the int.
unsigned int RESERVED:24;
} _flags; } _flags;
} }
@ -117,7 +126,7 @@ APPKIT_EXPORT NSString *NSToolbarPrintItemIdentifier;
- (NSMenuItem *) menuFormRepresentation; - (NSMenuItem *) menuFormRepresentation;
- (NSSize) minSize; - (NSSize) minSize;
- (NSString *) paletteLabel; - (NSString *) paletteLabel;
- (int) tag; - (NSInteger) tag;
- (id) target; - (id) target;
- (NSString *) toolTip; - (NSString *) toolTip;
- (GSToolbar *) toolbar; - (GSToolbar *) toolbar;
@ -130,10 +139,16 @@ APPKIT_EXPORT NSString *NSToolbarPrintItemIdentifier;
- (void) setMenuFormRepresentation: (NSMenuItem *)menuItem; - (void) setMenuFormRepresentation: (NSMenuItem *)menuItem;
- (void) setMinSize: (NSSize)minSize; - (void) setMinSize: (NSSize)minSize;
- (void) setPaletteLabel: (NSString *)paletteLabel; - (void) setPaletteLabel: (NSString *)paletteLabel;
- (void) setTag: (int)tag; - (void) setTag: (NSInteger)tag;
- (void) setTarget: (id)target; - (void) setTarget: (id)target;
- (void) setToolTip: (NSString *)toolTip; - (void) setToolTip: (NSString *)toolTip;
- (void) setView: (NSView *)view; - (void) setView: (NSView *)view;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
- (BOOL) autovalidates;
- (void) setAutovalidates: (BOOL)autovalidates;
- (NSInteger) visibilityPriority;
- (void) setVisibilityPriority: (NSInteger)visibilityPriority;
#endif
@end /* interface of NSToolbarItem */ @end /* interface of NSToolbarItem */
@ -143,6 +158,6 @@ APPKIT_EXPORT NSString *NSToolbarPrintItemIdentifier;
@end @end
// Extra private stuff // Extra private stuff
extern NSString *GSMovableToolbarItemPboardType; APPKIT_EXPORT NSString *GSMovableToolbarItemPboardType;
#endif /* _GNUstep_H_NSToolbarItem */ #endif /* _GNUstep_H_NSToolbarItem */

View file

@ -0,0 +1,50 @@
/*
NSToolbarItemGroup.h
The toolbar item group class.
Copyright (C) 2008 Free Software Foundation, Inc.
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: Dec 2008
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 Lesser 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_NSToolbarItemGroup
#define _GNUstep_H_NSToolbarItemGroup
#include <AppKit/NSToolbarItem.h>
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
@class NSArray;
@interface NSToolbarItemGroup : NSToolbarItem
{
NSArray *_subitems;
}
- (void) setSubitems: (NSArray *)items;
- (NSArray *) subitems;
@end
#endif
#endif /* _GNUstep_H_NSToolbarItemGroup */

View file

@ -175,6 +175,7 @@ NSTextTable.m \
NSTextTableBlock.m \ NSTextTableBlock.m \
NSToolbar.m \ NSToolbar.m \
NSToolbarItem.m \ NSToolbarItem.m \
NSToolbarItemGroup.m \
NSTokenField.m \ NSTokenField.m \
NSTokenFieldCell.m \ NSTokenFieldCell.m \
NSUserDefaultsController.m \ NSUserDefaultsController.m \
@ -371,6 +372,7 @@ NSTextTable.h \
NSTextView.h \ NSTextView.h \
NSToolbar.h \ NSToolbar.h \
NSToolbarItem.h \ NSToolbarItem.h \
NSToolbarItemGroup.h \
NSTokenField.h \ NSTokenField.h \
NSTokenFieldCell.h \ NSTokenFieldCell.h \
NSUserDefaultsController.h \ NSUserDefaultsController.h \

View file

@ -64,6 +64,10 @@ static const unsigned int ValidationInterval = 4;
static GSValidationCenter *vc = nil; static GSValidationCenter *vc = nil;
// Extensions // Extensions
@interface NSArray (ObjectsWithValueForKey)
- (NSArray *) objectsWithValue: (id)value forKey: (NSString *)key;
@end
@implementation NSArray (ObjectsWithValueForKey) @implementation NSArray (ObjectsWithValueForKey)
- (NSArray *) objectsWithValue: (id)value forKey: (NSString *)key - (NSArray *) objectsWithValue: (id)value forKey: (NSString *)key
@ -359,6 +363,11 @@ static GSValidationCenter *vc = nil;
[super dealloc]; [super dealloc];
} }
- (GSValidationObject *) validationObjectForWindow: (NSWindow*)w
{
return [[_vobjs objectsWithValue: w forKey: @"_window"] objectAtIndex: 0];
}
- (NSArray *) observersWindow: (NSWindow *)window - (NSArray *) observersWindow: (NSWindow *)window
{ {
int i; int i;
@ -377,16 +386,13 @@ static GSValidationCenter *vc = nil;
} }
else else
{ {
result = [[[_vobjs objectsWithValue: window forKey: @"_window"] return [[self validationObjectForWindow: window] observers];
objectAtIndex: 0] observers];
return result;
} }
} }
- (void) addObserver: (id)observer window: (NSWindow *)window - (void) addObserver: (id)observer window: (NSWindow *)window
{ {
GSValidationObject *vobj = GSValidationObject *vobj = [self validationObjectForWindow: window];
[[_vobjs objectsWithValue: window forKey: @"_window"] objectAtIndex: 0];
NSMutableArray *observersWindow = nil; NSMutableArray *observersWindow = nil;
if (window == nil) if (window == nil)
@ -430,7 +436,7 @@ static GSValidationCenter *vc = nil;
while ((w = [e nextObject]) != nil) while ((w = [e nextObject]) != nil)
{ {
vobj = [[_vobjs objectsWithValue: w forKey: @"_window"] objectAtIndex: 0]; vobj = [self validationObjectForWindow: w];
observersWindow = [vobj observers]; observersWindow = [vobj observers];
if (observersWindow != nil && [observersWindow containsObject: observer]) if (observersWindow != nil && [observersWindow containsObject: observer])
@ -452,8 +458,7 @@ static GSValidationCenter *vc = nil;
// NSLog(@"Window will close"); // NSLog(@"Window will close");
vobj = [[_vobjs objectsWithValue: [notification object] forKey: @"_window"] vobj = [self validationObjectForWindow: [notification object]];
objectAtIndex: 0];
if (vobj != nil) if (vobj != nil)
{ {
[vobj clean]; [vobj clean];
@ -469,7 +474,8 @@ static GSValidationCenter *vc = nil;
// Private class method // Private class method
+ (NSMutableArray *) _toolbars; + (NSArray *) _toolbars;
+ (NSArray *) _toolbarsWithIdentifier: (NSString *)identifier;
- (void) _insertItemWithItemIdentifier: (NSString *)itemIdentifier - (void) _insertItemWithItemIdentifier: (NSString *)itemIdentifier
atIndex: (int)index atIndex: (int)index
@ -484,7 +490,6 @@ static GSValidationCenter *vc = nil;
- (void) _setAutosavesConfiguration: (BOOL)flag broadcast: (BOOL)broadcast; - (void) _setAutosavesConfiguration: (BOOL)flag broadcast: (BOOL)broadcast;
- (void) _setConfigurationFromDictionary: (NSDictionary *)configDict - (void) _setConfigurationFromDictionary: (NSDictionary *)configDict
broadcast: (BOOL)broadcast; broadcast: (BOOL)broadcast;
- (void) _setDelegate: (id)delegate broadcast: (BOOL)broadcast;
- (void) _moveItemFromIndex: (int)index toIndex: (int)newIndex broadcast: (BOOL)broadcast; - (void) _moveItemFromIndex: (int)index toIndex: (int)newIndex broadcast: (BOOL)broadcast;
// Few other private methods // Few other private methods
@ -545,11 +550,17 @@ static GSValidationCenter *vc = nil;
// Private class method to access static variable toolbars in subclasses // Private class method to access static variable toolbars in subclasses
+ (NSMutableArray *) _toolbars + (NSArray *) _toolbars
{ {
return toolbars; return toolbars;
} }
+ (NSArray *) _toolbarsWithIdentifier: (NSString *)identifier
{
return [toolbars objectsWithValue: identifier
forKey: @"_identifier"];
}
// Instance methods // Instance methods
- (id) initWithIdentifier: (NSString *)identifier - (id) initWithIdentifier: (NSString *)identifier
@ -780,18 +791,40 @@ static GSValidationCenter *vc = nil;
* -toolbarAllowedItemIdentifiers: and -toolbarDefaultItemIdentifiers: * -toolbarAllowedItemIdentifiers: and -toolbarDefaultItemIdentifiers:
* messages. * messages.
*/ */
- (void) setDelegate: (id)delegate - (void) setDelegate: (id)delegate
{ {
[self _setDelegate: delegate broadcast: NO]; if (_delegate == delegate)
//[self _setDelegate: delegate broadcast: YES]; return;
// Deactivated the delegate synchronization because it can create segmentation if (_delegate != nil)
// faults when the application has not been written specially to support it [nc removeObserver: _delegate name: nil object: self];
// which is the case for the Cocoa applications. Moreover it can be
// difficult to understand how it works in detail because it doesn't fit // Assign the delegate...
// exactly with the delegate philosophy. _delegate = delegate;
// Will be made optional later in the case the developers want to use it.
if (_delegate != nil)
{
#define CHECK_REQUIRED_METHOD(selector_name) \
if (![_delegate respondsToSelector: @selector(selector_name)]) \
[NSException raise: NSInternalInconsistencyException \
format: @"delegate does not respond to %@",@#selector_name]
CHECK_REQUIRED_METHOD(toolbar:itemForItemIdentifier:
willBeInsertedIntoToolbar:);
CHECK_REQUIRED_METHOD(toolbarAllowedItemIdentifiers:);
CHECK_REQUIRED_METHOD(toolbarDefaultItemIdentifiers:);
#define SET_DELEGATE_NOTIFICATION(notif_name) \
if ([_delegate respondsToSelector: @selector(toolbar##notif_name:)]) \
[nc addObserver: _delegate \
selector: @selector(toolbar##notif_name:) \
name: NSToolbar##notif_name##Notification object: self]
SET_DELEGATE_NOTIFICATION(DidRemoveItem);
SET_DELEGATE_NOTIFICATION(WillAddItem);
}
[self _build];
} }
- (void) setSelectedItemIdentifier: (NSString *)itemIdentifier - (void) setSelectedItemIdentifier: (NSString *)itemIdentifier
@ -874,19 +907,19 @@ static GSValidationCenter *vc = nil;
// Private methods // Private methods
/*
* Toolbar build :
* will use the delegate when there is no toolbar model
*/
- (void) _build - (void) _build
{ {
/*
* Toolbar build :
* will use the delegate when there is no toolbar model
*/
GSToolbar *toolbarModel; GSToolbar *toolbarModel;
NSArray *wantedItemIdentifiers; NSArray *wantedItemIdentifiers;
NSEnumerator *e; NSEnumerator *e;
id itemIdentifier; id itemIdentifier;
int i = 0; int i = 0;
// Switch off toolbar view reload
_build = YES; _build = YES;
RELEASE(_items); RELEASE(_items);
@ -920,6 +953,9 @@ static GSValidationCenter *vc = nil;
} }
_build = NO; _build = NO;
// Now do the toolbar view reload
if (_toolbarView != nil)
[_toolbarView _reload];
} }
- (int) _indexOfItem: (NSToolbarItem *)item - (int) _indexOfItem: (NSToolbarItem *)item
@ -965,8 +1001,7 @@ static GSValidationCenter *vc = nil;
NSArray *linked; NSArray *linked;
id toolbar; id toolbar;
linked = [toolbars objectsWithValue: [self identifier] linked = [isa _toolbarsWithIdentifier: [self identifier]];
forKey: @"_identifier"];
if (linked != nil && [linked count] > 0) if (linked != nil && [linked count] > 0)
{ {
@ -1004,15 +1039,15 @@ static GSValidationCenter *vc = nil;
/* /*
* *
* The methods below handles the toolbar edition and broacasts each associated * The methods below handles the toolbar edition and broadcasts each associated
* event to the other toolbars with identical identifiers. * event to the other toolbars with identical identifiers.
* Warning : broadcast process only happens between instances based on the same * Warning : broadcast process only happens between instances based on the same
* class. * class.
*/ */
#define TRANSMIT(signature) \ #define TRANSMIT(signature) \
NSEnumerator *e = [[toolbars objectsWithValue: _identifier forKey: \ NSEnumerator *e = [[GSToolbar _toolbarsWithIdentifier: _identifier] \
@"_identifier"] objectEnumerator]; \ objectEnumerator]; \
GSToolbar *toolbar; \ GSToolbar *toolbar; \
\ \
while ((toolbar = [e nextObject]) != nil) \ while ((toolbar = [e nextObject]) != nil) \
@ -1140,54 +1175,6 @@ static GSValidationCenter *vc = nil;
} }
} }
- (void) _setDelegate: (id)delegate broadcast: (BOOL)broadcast
{
//if (_delegate)
// [nc removeObserver: _delegate name: nil object: self];
if (_delegate == delegate)
return;
if (_delegate != nil)
[nc removeObserver: _delegate name: nil object: self];
// Assign the delegate...
_delegate = delegate;
if (_delegate != nil)
{
#define CHECK_REQUIRED_METHOD(selector_name) \
if (![_delegate respondsToSelector: @selector(selector_name)]) \
[NSException raise: NSInternalInconsistencyException \
format: @"delegate does not respond to %@",@#selector_name]
CHECK_REQUIRED_METHOD(toolbar:itemForItemIdentifier:
willBeInsertedIntoToolbar:);
CHECK_REQUIRED_METHOD(toolbarAllowedItemIdentifiers:);
CHECK_REQUIRED_METHOD(toolbarDefaultItemIdentifiers:);
#define SET_DELEGATE_NOTIFICATION(notif_name) \
if ([_delegate respondsToSelector: @selector(toolbar##notif_name:)]) \
[nc addObserver: _delegate \
selector: @selector(toolbar##notif_name:) \
name: NSToolbar##notif_name##Notification object: self]
SET_DELEGATE_NOTIFICATION(DidRemoveItem);
SET_DELEGATE_NOTIFICATION(WillAddItem);
}
[self _build];
if (_toolbarView != nil)
[_toolbarView _reload];
// Broadcast now...
if (broadcast)
{
TRANSMIT(_setDelegate: _delegate broadcast: NO);
}
}
- (void) _moveItemFromIndex: (int)index toIndex: (int)newIndex broadcast: (BOOL)broadcast - (void) _moveItemFromIndex: (int)index toIndex: (int)newIndex broadcast: (BOOL)broadcast
{ {
id item; id item;
@ -1231,31 +1218,6 @@ static GSValidationCenter *vc = nil;
// Don't do an ASSIGN here, the toolbar itself retains us. // Don't do an ASSIGN here, the toolbar itself retains us.
_toolbarView = toolbarView; _toolbarView = toolbarView;
if (_toolbarView == nil)
return;
/* In the case, the user hasn't set a delegate until now, we set it.
* Why ?
* We don't set it before when the toolbar is initialized, to do only one
* toolbar content load.
* ...
* 1 toolbar = [[GSToolbar alloc] initWithIdentifier: @"blabla"];
* 2 [toolbar setDelegate: myDelegate];
* In case such method like 1 sets a default delegate for the identifier by
* requesting a toolbar model, a toolbar content load would occur.
* With a method like 2 which follows immediatly :
* Another toolbar load content would occur related to a probably different
* delegate.
*/
//if (_delegate == nil)
//[self _setDelegate: [toolbarModel delegate] broadcast: NO];
// Deactivated the delegate synchronization because it can create segmentation
// faults when the application has not been written specially to support it
// which is the case for the Cocoa applications. Moreover it can be
// difficult to understand how it works in detail because it doesn't fit
// exactly with the delegate philosophy.
// Will be made optional later in the case the developers want to use it.
} }
- (GSToolbarView *) _toolbarView - (GSToolbarView *) _toolbarView

View file

@ -48,18 +48,18 @@
static NSNotificationCenter *nc = nil; static NSNotificationCenter *nc = nil;
static const int current_version = 1; static const int current_version = 1;
@interface GSToolbar (GNUstepPrivate)
+ (NSArray *) _toolbarsWithIdentifier: (NSString *)identifier;
@end
@interface NSToolbar (GNUstepPrivate) @interface NSToolbar (GNUstepPrivate)
+ (NSMutableArray *) _toolbars;
// Private methods with broadcast support // Private methods with broadcast support
- (void) _setDisplayMode: (NSToolbarDisplayMode)displayMode - (void) _setDisplayMode: (NSToolbarDisplayMode)displayMode
broadcast: (BOOL)broadcast; broadcast: (BOOL)broadcast;
- (void) _setSizeMode: (NSToolbarSizeMode)sizeMode - (void) _setSizeMode: (NSToolbarSizeMode)sizeMode
broadcast: (BOOL)broadcast; broadcast: (BOOL)broadcast;
- (void) _setVisible: (BOOL)shown broadcast: (BOOL)broadcast; - (void) _setVisible: (BOOL)shown broadcast: (BOOL)broadcast;
- (void) _setDelegate: (id)delegate broadcast: (BOOL)broadcast;
// Few other private methods // Few other private methods
- (void) _loadConfig; - (void) _loadConfig;
@ -185,7 +185,7 @@ static const int current_version = 1;
*/ */
#define TRANSMIT(signature) \ #define TRANSMIT(signature) \
NSEnumerator *e = [[[GSToolbar _toolbars] objectsWithValue: _identifier forKey: @"_identifier"] objectEnumerator]; \ NSEnumerator *e = [[GSToolbar _toolbarsWithIdentifier: _identifier] objectEnumerator]; \
NSToolbar *toolbar; \ NSToolbar *toolbar; \
\ \
while ((toolbar = [e nextObject]) != nil) \ while ((toolbar = [e nextObject]) != nil) \

View file

@ -31,9 +31,7 @@
#include <Foundation/NSObject.h> #include <Foundation/NSObject.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSDebug.h>
#include <Foundation/NSDictionary.h> #include <Foundation/NSDictionary.h>
#include <Foundation/NSException.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include "AppKit/NSApplication.h" #include "AppKit/NSApplication.h"
#include "AppKit/NSAttributedString.h" #include "AppKit/NSAttributedString.h"
@ -87,7 +85,6 @@ static const int InsetItemTextY = 4;
static NSFont *NormalFont = nil; // See NSToolbarItem -initialize method static NSFont *NormalFont = nil; // See NSToolbarItem -initialize method
// [NSFont smallSystemFontSize] or better should be NSControlContentFontSize // [NSFont smallSystemFontSize] or better should be NSControlContentFontSize
static NSFont *SmallFont = nil; static NSFont *SmallFont = nil;
NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType"; NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
@ -102,6 +99,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
@interface NSToolbarItem (GNUstepPrivate) @interface NSToolbarItem (GNUstepPrivate)
- (void) _layout; - (void) _layout;
// --- // ---
- (void) _computeFlags;
- (NSView *) _backView; - (NSView *) _backView;
- (NSMenuItem *) _defaultMenuFormRepresentation; - (NSMenuItem *) _defaultMenuFormRepresentation;
- (BOOL) _isFlexibleSpace; - (BOOL) _isFlexibleSpace;
@ -162,17 +160,19 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
// Don't do an ASSIGN here, the toolbar item itself retains us. // Don't do an ASSIGN here, the toolbar item itself retains us.
_toolbarItem = toolbarItem; _toolbarItem = toolbarItem;
//[self setCell: [[GSToolbarButtonCell alloc] init]];
}
return self;
}
- (void) dealloc [self setTitle: @""];
{ [self setEnabled: NO];
// Nothing to do currently [_cell setBezeled: YES];
[self setImagePosition: NSImageAbove];
[super dealloc]; [self setHighlightsBy:
NSChangeGrayCellMask | NSChangeBackgroundCellMask];
[self setFont: [NSFont systemFontOfSize: 11]];
/* [NSFont smallSystemFontSize] or better should be
controlContentFontSize. */
}
return self;
} }
- (void) layout - (void) layout
@ -214,7 +214,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
; // Invalid ; // Invalid
} }
[[self cell] setFont: font]; [self setFont: font];
// Adjust the layout in accordance with the border // Adjust the layout in accordance with the border
@ -283,45 +283,45 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
if ([event modifierFlags] == NSCommandKeyMask if ([event modifierFlags] == NSCommandKeyMask
&& [toolbar allowsUserCustomization]) && [toolbar allowsUserCustomization])
{ {
NSSize viewSize = [self frame].size; NSSize viewSize = [self frame].size;
NSImage *image = [[NSImage alloc] initWithSize: viewSize]; NSImage *image = [[NSImage alloc] initWithSize: viewSize];
NSCell *cell = [self cell]; NSCell *cell = [self cell];
NSPasteboard *pboard; NSPasteboard *pboard;
int index; int index;
AUTORELEASE(image); AUTORELEASE(image);
// Prepare the drag // Prepare the drag
RETAIN(self);
/* We need to keep this view (aka self) to be able to draw the drag
image. */
// Draw the drag content in an image
/* The code below is only partially supported by GNUstep, then NSImage
needs to be improved. */
[image lockFocus];
[cell setShowsFirstResponder: NO]; // To remove the dotted rect
[cell drawWithFrame:
NSMakeRect(0, 0, viewSize.width, viewSize.height) inView: nil];
[cell setShowsFirstResponder: YES];
[image unlockFocus];
pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
owner: nil];
index = [toolbar _indexOfItem: _toolbarItem];
[pboard setString: [NSString stringWithFormat:@"%d", index]
forType: GSMovableToolbarItemPboardType];
RETAIN(self); [self dragImage: image
/* We need to keep this view (aka self) to be able to draw the drag at: NSMakePoint(0.0, 0.0)
image. */ offset: NSMakeSize(0.0, 0.0)
event: event
// Draw the drag content in an image pasteboard: pboard
source: self
/* The code below is only partially supported by GNUstep, then NSImage slideBack: NO];
needs to be improved. */
[image lockFocus];
[cell setShowsFirstResponder: NO]; // To remove the dotted rect
[cell drawWithFrame:
NSMakeRect(0, 0, viewSize.width, viewSize.height) inView: nil];
[cell setShowsFirstResponder: YES];
[image unlockFocus];
pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
owner: nil];
index = [toolbar _indexOfItem: _toolbarItem];
[pboard setString: [NSString stringWithFormat:@"%d", index]
forType: GSMovableToolbarItemPboardType];
[self dragImage: image
at: NSMakePoint(0.0, 0.0)
offset: NSMakeSize(0.0, 0.0)
event: event
pasteboard: pboard
source: self
slideBack: NO];
} }
else if ([event modifierFlags] != NSCommandKeyMask) else if ([event modifierFlags] != NSCommandKeyMask)
{ {
@ -333,6 +333,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
GSToolbar *toolbar = [_toolbarItem toolbar]; GSToolbar *toolbar = [_toolbarItem toolbar];
// FIXME: Where is this released?
RETAIN(_toolbarItem); RETAIN(_toolbarItem);
/* We retain the toolbar item to be able to have have it reinsered later by /* We retain the toolbar item to be able to have have it reinsered later by
the dragging destination. */ the dragging destination. */
@ -381,7 +382,8 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
return _toolbarItem; return _toolbarItem;
} }
- (void) setToolbarItemAction: (SEL) action // FIXME: Why use this and not the action of the cell?
- (void) setToolbarItemAction: (SEL)action
{ {
_toolbarItemAction = action; _toolbarItemAction = action;
} }
@ -393,7 +395,6 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
@end @end
// FIXME: Why does this class exists at all?
@implementation GSToolbarButtonCell @implementation GSToolbarButtonCell
/* Overriden NSButtonCell method to handle cell type in a basic way which avoids /* Overriden NSButtonCell method to handle cell type in a basic way which avoids
@ -513,6 +514,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem; - (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem;
- (NSToolbarItem *) toolbarItem; - (NSToolbarItem *) toolbarItem;
- (void) layout;
- (BOOL) enabled; - (BOOL) enabled;
- (void) setEnabled: (BOOL)enabled; - (void) setEnabled: (BOOL)enabled;
@end @end
@ -534,18 +536,8 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
return self; return self;
} }
- (void) dealloc
{
/* _font is pointing on a static variable then we do own it and don't need
to release it. */
[super dealloc];
}
- (void) drawRect: (NSRect)rect - (void) drawRect: (NSRect)rect
{ {
[super drawRect: rect]; // We draw _view which is a subview
if (_showLabel) if (_showLabel)
{ {
NSAttributedString *attrString; NSAttributedString *attrString;
@ -738,8 +730,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
* The code below should be kept in sync with GSToolbarButton methods which * The code below should be kept in sync with GSToolbarButton methods which
* have identical names. * have identical names.
*/ */
- (void) mouseDown: (NSEvent *)event - (void) mouseDown: (NSEvent *)event
{ {
GSToolbar *toolbar = [_toolbarItem toolbar]; GSToolbar *toolbar = [_toolbarItem toolbar];
@ -863,6 +854,9 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
NSImage *image = [NSImage imageNamed: @"common_ToolbarSeparatorItem"]; NSImage *image = [NSImage imageNamed: @"common_ToolbarSeparatorItem"];
self = [super initWithItemIdentifier: itemIdentifier]; self = [super initWithItemIdentifier: itemIdentifier];
if (!self)
return nil;
[(NSButton *)[self _backView] setImagePosition: NSImageOnly]; [(NSButton *)[self _backView] setImagePosition: NSImageOnly];
[(NSButton *)[self _backView] setImage: image]; [(NSButton *)[self _backView] setImage: image];
/* We bypass the toolbar item accessor to set the image in order to have it /* We bypass the toolbar item accessor to set the image in order to have it
@ -941,6 +935,12 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
// Override the default implementation in order to reset the _backView to a zero width // Override the default implementation in order to reset the _backView to a zero width
} }
- (BOOL) _isFlexibleSpace
{
return YES;
}
@end @end
// ---- NSToolbarShowColorsItemIdentifier // ---- NSToolbarShowColorsItemIdentifier
@ -952,11 +952,9 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
@implementation GSToolbarShowColorsItem @implementation GSToolbarShowColorsItem
- (id) initWithItemIdentifier: (NSString *)itemIdentifier - (id) initWithItemIdentifier: (NSString *)itemIdentifier
{ {
NSImage *image = [NSImage imageNamed: @"common_ToolbarShowColorsItem"];
self = [super initWithItemIdentifier: itemIdentifier]; self = [super initWithItemIdentifier: itemIdentifier];
[self setImage: image]; [self setImage: [NSImage imageNamed: @"common_ToolbarShowColorsItem"]];
[self setLabel: @"Colors"]; // FIX ME: localize [self setLabel: _(@"Colors")];
// Set action... // Set action...
[self setTarget: nil]; // Goes to first responder.. [self setTarget: nil]; // Goes to first responder..
@ -975,11 +973,9 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
@implementation GSToolbarShowFontsItem @implementation GSToolbarShowFontsItem
- (id) initWithItemIdentifier: (NSString *)itemIdentifier - (id) initWithItemIdentifier: (NSString *)itemIdentifier
{ {
NSImage *image = [NSImage imageNamed: @"common_ToolbarShowFontsItem"];
self = [super initWithItemIdentifier: itemIdentifier]; self = [super initWithItemIdentifier: itemIdentifier];
[self setImage: image]; [self setImage: [NSImage imageNamed: @"common_ToolbarShowFontsItem"]];
[self setLabel: @"Fonts"]; // FIX ME: localize [self setLabel: _(@"Fonts")];
// Set action... // Set action...
[self setTarget: nil]; // Goes to first responder.. [self setTarget: nil]; // Goes to first responder..
@ -998,11 +994,9 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
@implementation GSToolbarCustomizeToolbarItem @implementation GSToolbarCustomizeToolbarItem
- (id) initWithItemIdentifier: (NSString *)itemIdentifier - (id) initWithItemIdentifier: (NSString *)itemIdentifier
{ {
NSImage *image = [NSImage imageNamed: @"common_ToolbarCustomizeToolbarItem"];
self = [super initWithItemIdentifier: itemIdentifier]; self = [super initWithItemIdentifier: itemIdentifier];
[self setImage: image]; [self setImage: [NSImage imageNamed: @"common_ToolbarCustomizeToolbarItem"]];
[self setLabel: @"Customize"]; // FIX ME: localize [self setLabel: _(@"Customize")];
// Set action... // Set action...
[self setTarget: nil]; // Goes to first responder.. [self setTarget: nil]; // Goes to first responder..
@ -1021,15 +1015,13 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
@implementation GSToolbarPrintItem @implementation GSToolbarPrintItem
- (id) initWithItemIdentifier: (NSString *)itemIdentifier - (id) initWithItemIdentifier: (NSString *)itemIdentifier
{ {
NSImage *image = [NSImage imageNamed: @"common_Printer"];
self = [super initWithItemIdentifier: itemIdentifier]; self = [super initWithItemIdentifier: itemIdentifier];
[self setImage: image]; [self setImage: [NSImage imageNamed: @"common_Printer"]];
[self setLabel: @"Print..."]; // FIX ME: localize [self setLabel: _(@"Print...")];
// Set action... // Set action...
[self setTarget: nil]; // goes to first responder.. [self setTarget: nil]; // goes to first responder..
[self setAction: @selector(print:)]; [self setAction: @selector(printDocument:)];
return self; return self;
} }
@ -1037,6 +1029,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
@implementation NSToolbarItem @implementation NSToolbarItem
+ (void) initialize + (void) initialize
{ {
NormalFont = RETAIN([NSFont systemFontOfSize: 11]); NormalFont = RETAIN([NSFont systemFontOfSize: 11]);
@ -1047,114 +1040,76 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (id) initWithItemIdentifier: (NSString *)itemIdentifier - (id) initWithItemIdentifier: (NSString *)itemIdentifier
{ {
GSToolbarButton *button; // GNUstep predefined toolbar items
NSButtonCell *cell; if ([itemIdentifier isEqualToString: NSToolbarSeparatorItemIdentifier]
&& [self isKindOfClass: [GSToolbarSeparatorItem class]] == NO)
if ((self = [super init]) != nil) {
{ RELEASE(self);
return [[GSToolbarSeparatorItem alloc]
// GNUstep predefined toolbar items initWithItemIdentifier: itemIdentifier];
}
if ([itemIdentifier isEqualToString: @"NSToolbarSeparatorItemIdentifier"] else if ([itemIdentifier isEqualToString: NSToolbarSpaceItemIdentifier]
&& [self isKindOfClass:[GSToolbarSeparatorItem class]] == NO) && [self isKindOfClass: [GSToolbarSpaceItem class]] == NO)
{
RELEASE(self);
return [[GSToolbarSpaceItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier
isEqualToString: NSToolbarFlexibleSpaceItemIdentifier]
&& [self isKindOfClass: [GSToolbarFlexibleSpaceItem class]] == NO)
{
RELEASE(self);
return [[GSToolbarFlexibleSpaceItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier
isEqualToString: NSToolbarShowColorsItemIdentifier]
&& [self isKindOfClass: [GSToolbarShowColorsItem class]] == NO)
{
RELEASE(self);
return [[GSToolbarShowColorsItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier
isEqualToString: NSToolbarShowFontsItemIdentifier]
&& [self isKindOfClass: [GSToolbarShowFontsItem class]] == NO)
{
RELEASE(self);
return [[GSToolbarShowFontsItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier
isEqualToString: NSToolbarCustomizeToolbarItemIdentifier]
&& [self isKindOfClass: [GSToolbarCustomizeToolbarItem class]] == NO)
{
RELEASE(self);
return [[GSToolbarCustomizeToolbarItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier isEqualToString: NSToolbarPrintItemIdentifier]
&& [self isKindOfClass: [GSToolbarPrintItem class]] == NO)
{
RELEASE(self);
return [[GSToolbarPrintItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else
{
if ((self = [super init]) != nil)
{ {
[self release]; // Normal toolbar items
self = [[GSToolbarSeparatorItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier isEqualToString: @"NSToolbarSpaceItemIdentifier"]
&& [self isKindOfClass:[GSToolbarSpaceItem class]] == NO)
{
[self release];
self = [[GSToolbarSpaceItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier
isEqualToString: @"NSToolbarFlexibleSpaceItemIdentifier"]
&& [self isKindOfClass:[GSToolbarFlexibleSpaceItem class]] == NO)
{
[self release];
self = [[GSToolbarFlexibleSpaceItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier
isEqualToString: @"NSToolbarShowColorsItemIdentifier"]
&& [self isKindOfClass:[GSToolbarShowColorsItem class]] == NO)
{
[self release];
self = [[GSToolbarShowColorsItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier
isEqualToString: @"NSToolbarShowFontsItemIdentifier"]
&& [self isKindOfClass:[GSToolbarShowFontsItem class]] == NO)
{
[self release];
self = [[GSToolbarShowFontsItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier
isEqualToString: @"NSToolbarCustomizeToolbarItemIdentifier"]
&& [self isKindOfClass:[GSToolbarCustomizeToolbarItem class]] == NO)
{
[self release];
self = [[GSToolbarCustomizeToolbarItem alloc]
initWithItemIdentifier: itemIdentifier];
}
else if ([itemIdentifier isEqualToString: @"NSToolbarPrintItemIdentifier"]
&& [self isKindOfClass:[GSToolbarPrintItem class]] == NO)
{
[self release];
self = [[GSToolbarPrintItem alloc]
initWithItemIdentifier: itemIdentifier];
}
// Normal toolbar items
else
{
ASSIGN(_itemIdentifier, itemIdentifier); ASSIGN(_itemIdentifier, itemIdentifier);
[self setAutovalidates: YES];
button = [[GSToolbarButton alloc] initWithToolbarItem: self];
cell = [button cell];
[button setTitle: @""];
[button setEnabled: NO];
[button setBordered: NO];
[button setImagePosition: NSImageAbove];
[cell setBezeled: YES];
[cell setHighlightsBy:
NSChangeGrayCellMask | NSChangeBackgroundCellMask];
[cell setFont: [NSFont systemFontOfSize: 11]];
/* [NSFont smallSystemFontSize] or better should be
controlContentFontSize. */
[_backView release]; // Set the backview to an GSToolbarButton, will get reset to a
_backView = button; // GSToolbarBackView when setView: gets called.
} RELEASE(_backView);
_backView = [[GSToolbarButton alloc] initWithToolbarItem: self];
// gets
_flags._isEnabled = [_backView respondsToSelector: @selector(isEnabled)]; [self _computeFlags];
_flags._tag = YES; }
_flags._action =
[_backView respondsToSelector: @selector(toolbarItemAction)];
_flags._target = [_backView respondsToSelector: @selector(target)];
_flags._image = [_backView respondsToSelector: @selector(image)];
// sets
_flags._setEnabled =
[_backView respondsToSelector: @selector(setEnabled:)];
_flags._setTag = YES;
_flags._setAction =
[_backView respondsToSelector: @selector(setToolbarItemAction:)];
_flags._setTarget =
[_backView respondsToSelector: @selector(setTarget:)];
_flags._setImage = [_backView respondsToSelector: @selector(setImage:)];
} }
return self; return self;
@ -1168,7 +1123,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
RELEASE(_menuFormRepresentation); RELEASE(_menuFormRepresentation);
RELEASE(_paletteLabel); RELEASE(_paletteLabel);
RELEASE(_toolTip); RELEASE(_toolTip);
RELEASE(_view); TEST_RELEASE(_view);
RELEASE(_backView); RELEASE(_backView);
[super dealloc]; [super dealloc];
@ -1176,14 +1131,17 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (BOOL) allowsDuplicatesInToolbar - (BOOL) allowsDuplicatesInToolbar
{ {
return _allowsDuplicatesInToolbar; return NO;
} }
- (BOOL) isEnabled - (BOOL) isEnabled
{ {
if (_flags._isEnabled) if (_flags._isEnabled)
{ {
return [(id)_backView isEnabled]; if (_view)
return [_view isEnabled];
else
return [(GSToolbarButton*)_backView isEnabled];
} }
return NO; return NO;
} }
@ -1192,10 +1150,13 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
if (_flags._image) if (_flags._image)
{ {
return _image; if (_view)
return [_view image];
else
return [(GSToolbarButton*)_backView image];
} }
return nil; return _image;
} }
- (NSString *) itemIdentifier - (NSString *) itemIdentifier
@ -1205,17 +1166,16 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (NSString *) label - (NSString *) label
{ {
NSMenuItem *menuItem = [self menuFormRepresentation]; // FIXME: I think this is not needed
if ([[self toolbar] displayMode] == NSToolbarDisplayModeLabelOnly)
if ([[self toolbar] displayMode] == NSToolbarDisplayModeLabelOnly
&& menuItem != nil)
{ {
return [menuItem title]; NSMenuItem *menuItem = [self menuFormRepresentation];
}
else if (menuItem != nil)
{ return [menuItem title];
return _label;
} }
return _label;
} }
- (NSSize) maxSize - (NSSize) maxSize
@ -1242,37 +1202,46 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
if (_flags._setAction) if (_flags._setAction)
{ {
if ([_backView isKindOfClass: [GSToolbarButton class]]) if (_view)
[_view setAction: action];
else
[(GSToolbarButton *)_backView setToolbarItemAction: action]; [(GSToolbarButton *)_backView setToolbarItemAction: action];
if (action != NULL) if (action != NULL)
{ {
[self setEnabled: YES]; [self setEnabled: YES];
} }
else else
{ {
[self setEnabled: NO]; [self setEnabled: NO];
} }
} }
} }
- (void) setEnabled: (BOOL)enabled - (void) setEnabled: (BOOL)enabled
{ {
if (_flags._setEnabled) if (_flags._setEnabled)
[(id)_backView setEnabled: enabled]; {
if (_view)
[_view setEnabled: enabled];
else
[(GSToolbarButton*)_backView setEnabled: enabled];
}
} }
- (void) setImage: (NSImage *)image - (void) setImage: (NSImage *)image
{ {
ASSIGN(_image, image);
[_image setScalesWhenResized: YES];
//[_image setSize: NSMakeSize(32, 32)];
if (_flags._setImage) if (_flags._setImage)
{ {
ASSIGN(_image, image); if (_view)
[_view setImage: image];
[_image setScalesWhenResized: YES]; else
//[_image setSize: NSMakeSize(32, 32)]; [(GSToolbarButton*)_backView setImage: image];
if ([_backView isKindOfClass: [NSButton class]])
[(NSButton *)_backView setImage: _image];
} }
} }
@ -1280,8 +1249,8 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
ASSIGN(_label, label); ASSIGN(_label, label);
if ([_backView isKindOfClass: [NSButton class]]) if ([_backView isKindOfClass: [GSToolbarButton class]])
[(NSButton *)_backView setTitle:_label]; [(GSToolbarButton *)_backView setTitle: _label];
_modified = YES; _modified = YES;
if (_toolbar != nil) if (_toolbar != nil)
@ -1308,19 +1277,20 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
ASSIGN(_paletteLabel, paletteLabel); ASSIGN(_paletteLabel, paletteLabel);
} }
- (void) setTag: (int)tag - (void) setTag: (NSInteger)tag
{ {
if (_flags._tag) _tag = tag;
_tag = tag;
} }
- (void) setTarget: (id)target - (void) setTarget: (id)target
{ {
if (_flags._target) if (_flags._setTarget)
{ {
if ([_backView isKindOfClass: [NSButton class]]) if (_view)
[(NSButton *)_backView setTarget: target]; [_view setTarget: target];
} else
[(NSButton *)_backView setTarget: target];
}
} }
- (void) setToolTip: (NSString *)toolTip - (void) setToolTip: (NSString *)toolTip
@ -1331,8 +1301,29 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (void) setView: (NSView *)view - (void) setView: (NSView *)view
{ {
if (_view == view)
return;
ASSIGN(_view, view); ASSIGN(_view, view);
if (view)
{
[_view setToolTip: _toolTip];
RELEASE(_backView);
_backView = [[GSToolbarBackView alloc] initWithToolbarItem: self];
}
else
{
RELEASE(_backView);
_backView = [[GSToolbarButton alloc] initWithToolbarItem: self];
}
[self _computeFlags];
}
- (void) _computeFlags
{
if (_view == nil) if (_view == nil)
{ {
// gets // gets
@ -1340,7 +1331,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
_flags._action = _flags._action =
[_backView respondsToSelector: @selector(toolbarItemAction)]; [_backView respondsToSelector: @selector(toolbarItemAction)];
_flags._target = [_backView respondsToSelector: @selector(target)]; _flags._target = [_backView respondsToSelector: @selector(target)];
_flags._image = [_backView respondsToSelector: @selector(image)]; _flags._image = NO;
// sets // sets
_flags._setEnabled = _flags._setEnabled =
[_backView respondsToSelector: @selector(setEnabled:)]; [_backView respondsToSelector: @selector(setEnabled:)];
@ -1356,25 +1347,18 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
_flags._isEnabled = [_view respondsToSelector: @selector(isEnabled)]; _flags._isEnabled = [_view respondsToSelector: @selector(isEnabled)];
_flags._action = [_view respondsToSelector: @selector(action)]; _flags._action = [_view respondsToSelector: @selector(action)];
_flags._target = [_view respondsToSelector: @selector(target)]; _flags._target = [_view respondsToSelector: @selector(target)];
_flags._image = [_backView respondsToSelector: @selector(image)]; _flags._image = [_view respondsToSelector: @selector(image)];
// sets // sets
_flags._setEnabled = [_view respondsToSelector: @selector(setEnabled:)]; _flags._setEnabled = [_view respondsToSelector: @selector(setEnabled:)];
_flags._setAction = [_view respondsToSelector: @selector(setAction:)]; _flags._setAction = [_view respondsToSelector: @selector(setAction:)];
_flags._setTarget = [_view respondsToSelector: @selector(setTarget:)]; _flags._setTarget = [_view respondsToSelector: @selector(setTarget:)];
_flags._setImage = [_backView respondsToSelector: @selector(setImage:)]; _flags._setImage = [_view respondsToSelector: @selector(setImage:)];
[_view setToolTip: _toolTip];
} }
[_backView release];
_backView = [[GSToolbarBackView alloc] initWithToolbarItem: self];
} }
- (int) tag - (NSInteger) tag
{ {
if (_flags._tag) return _tag;
return _tag;
return 0;
} }
- (NSString *) toolTip - (NSString *) toolTip
@ -1393,7 +1377,11 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
"standard" items are correct. */ "standard" items are correct. */
NSMenuItem *menuItem = [self menuFormRepresentation]; NSMenuItem *menuItem = [self menuFormRepresentation];
id target = [self target]; id target = [self target];
// No validation for custom views
if (_view)
return;
if ([[self toolbar] displayMode] == NSToolbarDisplayModeLabelOnly if ([[self toolbar] displayMode] == NSToolbarDisplayModeLabelOnly
&& menuItem != nil) && menuItem != nil)
{ {
@ -1446,7 +1434,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (BOOL) _isFlexibleSpace - (BOOL) _isFlexibleSpace
{ {
return [self isKindOfClass: [GSToolbarFlexibleSpaceItem class]]; return NO;
} }
- (BOOL) _selectable - (BOOL) _selectable
@ -1466,18 +1454,12 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (void) _setSelected: (BOOL)selected - (void) _setSelected: (BOOL)selected
{ {
if (_selectable && [self _selected] == NO && selected) if (_selectable)
{ {
// FIXME: This is a hack to break a recursion. if ([self _selected] != selected)
// I think the code here is at fault. FK [(GSToolbarButton *)_backView setState: selected];
//[(GSToolbarButton *)_backView performClick:self];
[(GSToolbarButton *)_backView setState: YES];
} }
else if (selected == NO) else
{
[(GSToolbarButton *)_backView setState: NO];
}
else if (_selectable == NO)
{ {
NSLog(@"The toolbar item %@ is not selectable", self); NSLog(@"The toolbar item %@ is not selectable", self);
} }
@ -1502,12 +1484,34 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
_toolbar = toolbar; _toolbar = toolbar;
} }
- (BOOL) autovalidates
{
return _autovalidates;
}
- (void) setAutovalidates: (BOOL)autovalidates
{
_autovalidates = autovalidates;
}
- (NSInteger) visibilityPriority
{
return _visibilityPriority;
}
- (void) setVisibilityPriority: (NSInteger)visibilityPriority
{
_visibilityPriority = visibilityPriority;
}
// NSValidatedUserInterfaceItem protocol // NSValidatedUserInterfaceItem protocol
- (SEL) action - (SEL) action
{ {
if (_flags._action) if (_flags._action)
{ {
if ([_backView isKindOfClass: [GSToolbarButton class]]) if (_view)
return [_view action];
else
return [(GSToolbarButton *)_backView toolbarItemAction]; return [(GSToolbarButton *)_backView toolbarItemAction];
} }
return 0; return 0;
@ -1517,8 +1521,10 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
if (_flags._target) if (_flags._target)
{ {
if ([_backView isKindOfClass: [NSButton class]]) if (_view)
return [(NSButton *)_backView target]; return [_view target];
else
return [(GSToolbarButton *)_backView target];
} }
return nil; return nil;
@ -1539,8 +1545,13 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
[new setImage: [[self image] copyWithZone: zone]]; [new setImage: [[self image] copyWithZone: zone]];
[new setEnabled: [self isEnabled]]; [new setEnabled: [self isEnabled]];
[new setPaletteLabel: [[self paletteLabel] copyWithZone: zone]]; [new setPaletteLabel: [[self paletteLabel] copyWithZone: zone]];
[new setMinSize: NSMakeSize(_minSize.width, _minSize.height)]; [new setLabel: [[self label] copyWithZone: zone]];
[new setMaxSize: NSMakeSize(_maxSize.width, _maxSize.height)]; [new setMinSize: [self minSize]];
[new setMaxSize: [self maxSize]];
[new setAutovalidates: [self autovalidates]];
[new setVisibilityPriority: [self visibilityPriority]];
[new setMenuFormRepresentation: [[self menuFormRepresentation]
copyWithZone: zone]];
return new; return new;
} }

View file

@ -0,0 +1,64 @@
/*
NSToolbarItemGroup.h
The toolbar item group class.
Copyright (C) 2008 Free Software Foundation, Inc.
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: Dec 2008
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 Lesser 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <Foundation/NSArray.h>
#include "AppKit/NSToolbarItemGroup.h"
@implementation NSToolbarItemGroup
// FIXME: Most of the implementation is missing.
- (void) setSubitems: (NSArray *)items
{
ASSIGN(_subitems, items);
}
- (NSArray *) subitems
{
return _subitems;
}
- (void) dealloc
{
RELEASE(_subitems);
[super dealloc];
}
// NSCopying protocol
- (id) copyWithZone: (NSZone *)zone
{
NSToolbarItemGroup *new = (NSToolbarItemGroup *)[super copyWithZone: zone];
[new setSubitems: [self subitems]];
return new;
}
@end

View file

@ -34,6 +34,9 @@
#include "AppKit/NSToolbar.h" #include "AppKit/NSToolbar.h"
#include "GNUstepGUI/GSToolbarView.h" #include "GNUstepGUI/GSToolbarView.h"
@interface GSToolbar (GNUstepPrivate)
+ (NSArray *) _toolbars;
@end
@interface NSToolbar (GNUstepPrivate) @interface NSToolbar (GNUstepPrivate)
- (GSToolbarView *) _toolbarView; - (GSToolbarView *) _toolbarView;