Forgot to commit NSToolbarItem.m and NSToolbarItem.h

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19694 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Quentin Mathe 2004-07-07 23:21:10 +00:00
parent 605f60b151
commit 6b519561bf
3 changed files with 93 additions and 50 deletions

View file

@ -29,6 +29,7 @@
* Source/GSToolbarView: * Source/GSToolbarView:
* Source/NSToolbar.m: * Source/NSToolbar.m:
* Source/NSWindow+Toolbar.m: * Source/NSWindow+Toolbar.m:
* Source/NSToolbarItem.m:
Related changes and lot of memory leaks fixed permitting to have now Related changes and lot of memory leaks fixed permitting to have now
the toolbar system properly deallocated when the toolbar is not anymore the toolbar system properly deallocated when the toolbar is not anymore
retained by the user and the toolbar view. retained by the user and the toolbar view.
@ -36,7 +37,7 @@
a window, you need to have the option "Window released when closed" a window, you need to have the option "Window released when closed"
checked. checked.
Actual retain logic is strictly : Actual retain logic is strictly :
- Superview in the view hierachy retains toolbar view - Superview in the view hierarchy retains toolbar view
- Toolbar view retains toolbar - Toolbar view retains toolbar
- Toolbar view retains toolbar items view - Toolbar view retains toolbar items view
- Toolbar retains toolbar items - Toolbar retains toolbar items
@ -48,6 +49,7 @@
* Headers/Additions/GNUstepGUI/GSToolbar.h: * Headers/Additions/GNUstepGUI/GSToolbar.h:
* Headers/AppKit/NSToolbar.h: * Headers/AppKit/NSToolbar.h:
Moved the _window ivar from GSToolbar class to NSToolbar class. Moved the _window ivar from GSToolbar class to NSToolbar class.
* Headers/AppKit/NSToolbarItem.h: Added a _tag ivar and other minor changes.
2004-07-07 01:23 Alexander Malmberg <alexander@malmberg.org> 2004-07-07 01:23 Alexander Malmberg <alexander@malmberg.org>

View file

@ -62,14 +62,15 @@ APPKIT_EXPORT NSString *NSToolbarPrintItemIdentifier;
BOOL _allowsDuplicatesInToolbar; BOOL _allowsDuplicatesInToolbar;
NSString *_itemIdentifier; NSString *_itemIdentifier;
NSString *_label; NSString *_label;
NSMenuItem *_menuFormRepresentation;
NSString *_paletteLabel; NSString *_paletteLabel;
NSImage *_image; NSImage *_image;
id _view;
NSMenuItem *_menuFormRepresentation;
NSString *_toolTip;
int _tag;
// toolbar // toolbar
GSToolbar *_toolbar; GSToolbar *_toolbar;
NSString *_toolTip;
id _view;
NSView *_backView; NSView *_backView;
BOOL _modified; BOOL _modified;
BOOL _selectable; BOOL _selectable;

View file

@ -56,6 +56,11 @@
* initWithToolbarItemIdentifier: returns differents concrete subclass in accordance * initWithToolbarItemIdentifier: returns differents concrete subclass in accordance
* with the item identifier. * with the item identifier.
*/ */
static NSFont *NormalFont = nil; // See NSToolbarItem -initialize method
// [NSFont smallSystemFontSize] or better should be NSControlContentFontSize
static NSFont *SmallFont = nil;
@interface GSToolbar (GNUstepPrivate) @interface GSToolbar (GNUstepPrivate)
- (GSToolbarView *) _toolbarView; - (GSToolbarView *) _toolbarView;
@ -69,6 +74,7 @@
- (BOOL) _isFlexibleSpace; - (BOOL) _isFlexibleSpace;
- (BOOL) _isModified; - (BOOL) _isModified;
- (BOOL) _selectable; - (BOOL) _selectable;
- (GSToolbar *) _toolbar;
- (void) _setSelectable: (BOOL)selectable; - (void) _setSelectable: (BOOL)selectable;
- (BOOL) _selected; - (BOOL) _selected;
- (void) _setSelected: (BOOL)selected; - (void) _setSelected: (BOOL)selected;
@ -105,14 +111,15 @@
if (self != nil) if (self != nil)
{ {
ASSIGN(_toolbarItem, toolbarItem); // Don't do an ASSIGN here, the toolbar item itself retains us.
_toolbarItem = toolbarItem;
} }
return self; return self;
} }
- (void) dealloc - (void) dealloc
{ {
RELEASE(_toolbarItem); // Nothing to do currently
[super dealloc]; [super dealloc];
} }
@ -122,12 +129,14 @@
float textWidth, layoutedWidth = -1, layoutedHeight = -1; float textWidth, layoutedWidth = -1, layoutedHeight = -1;
NSAttributedString *attrStr; NSAttributedString *attrStr;
NSDictionary *attr; NSDictionary *attr;
NSFont *font = [NSFont systemFontOfSize: 11]; // [NSFont smallSystemFontSize] or better should NSControlContentFontSize NSFont *font;
unsigned int borderMask = [[[_toolbarItem toolbar] _toolbarView] borderMask]; unsigned int borderMask = [[[_toolbarItem toolbar] _toolbarView] borderMask];
NSString *label = [_toolbarItem label]; NSString *label = [_toolbarItem label];
// Adjust the layout in accordance with NSToolbarSizeMode // Adjust the layout in accordance with NSToolbarSizeMode
font = NormalFont;
switch ([[_toolbarItem toolbar] sizeMode]) switch ([[_toolbarItem toolbar] sizeMode])
{ {
case NSToolbarSizeModeDefault: case NSToolbarSizeModeDefault:
@ -148,10 +157,10 @@
// set to NSNoImage. Even if NSToolbarDisplayModeTextOnly is not true anymore // set to NSNoImage. Even if NSToolbarDisplayModeTextOnly is not true anymore
// -setImagePosition: is only called below, then [self image] can still returns // -setImagePosition: is only called below, then [self image] can still returns
// nil. // nil.
font = [NSFont systemFontOfSize: 9]; font = SmallFont;
break; break;
default: default:
; // invalid ; // Invalid
} }
[[self cell] setFont: font]; [[self cell] setFont: font];
@ -201,7 +210,7 @@
layoutedHeight = [attrStr size].height + _InsetItemTextY * 2; layoutedHeight = [attrStr size].height + _InsetItemTextY * 2;
break; break;
default: default:
; // invalid ; // Invalid
} }
// Set the frame size to use the new layout // Set the frame size to use the new layout
@ -257,13 +266,14 @@
@interface GSToolbarBackView : NSView @interface GSToolbarBackView : NSView
{ {
NSToolbarItem *_toolbarItem; NSToolbarItem *_toolbarItem;
NSFont *_font;
BOOL _enabled; BOOL _enabled;
BOOL _showLabel; BOOL _showLabel;
NSFont *_font;
} }
- (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem; - (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem;
- (NSToolbarItem *) toolbarItem; - (NSToolbarItem *) toolbarItem;
- (BOOL) enabled;
- (void) setEnabled: (BOOL)enabled; - (void) setEnabled: (BOOL)enabled;
@end @end
@ -277,16 +287,17 @@
if (self != nil) if (self != nil)
{ {
ASSIGN(_toolbarItem, toolbarItem); // Don't do an ASSIGN here, the toolbar item itself retains us.
_toolbarItem = toolbarItem;
} }
return self; return self;
} }
- (void) dealloc - (void) dealloc
{ {
RELEASE(_toolbarItem); // _font is pointing on a static variable then we do own it and don't need
//RELEASE(_font); // to release it.
[super dealloc]; [super dealloc];
} }
@ -311,7 +322,7 @@
if (_showLabel) if (_showLabel)
{ {
// we draw the label // We draw the label
attr = [NSDictionary dictionaryWithObjectsAndKeys: _font, attr = [NSDictionary dictionaryWithObjectsAndKeys: _font,
@"NSFontAttributeName", @"NSFontAttributeName",
color, color,
@ -333,7 +344,7 @@
unsigned int borderMask = [[[_toolbarItem toolbar] _toolbarView] borderMask]; unsigned int borderMask = [[[_toolbarItem toolbar] _toolbarView] borderMask];
NSString *label = [_toolbarItem label]; NSString *label = [_toolbarItem label];
_font = [NSFont systemFontOfSize: 11]; // [NSFont smallSystemFontSize] or better should be NSControlContentFontSize _font = NormalFont;
if ([view superview] == nil) // Show the view to eventually hide it later if ([view superview] == nil) // Show the view to eventually hide it later
[self addSubview: view]; [self addSubview: view];
@ -357,7 +368,7 @@
case NSToolbarSizeModeSmall: case NSToolbarSizeModeSmall:
layoutedWidth = _ItemBackViewSmallWidth; layoutedWidth = _ItemBackViewSmallWidth;
layoutedHeight = _ItemBackViewSmallHeight; layoutedHeight = _ItemBackViewSmallHeight;
_font = [NSFont systemFontOfSize: 9]; _font = SmallFont;
if ([view frame].size.height > 24) if ([view frame].size.height > 24)
[view removeFromSuperview]; [view removeFromSuperview];
break; break;
@ -394,7 +405,7 @@
_enabled = YES; _enabled = YES;
_showLabel = YES; _showLabel = YES;
// this boolean variable is used to known when it's needed to draw the label in the -drawRect: // This boolean variable is used to known when it's needed to draw the label in the -drawRect:
// method. // method.
switch ([[_toolbarItem toolbar] displayMode]) switch ([[_toolbarItem toolbar] displayMode])
@ -414,7 +425,7 @@
[view removeFromSuperview]; [view removeFromSuperview];
break; break;
default: default:
; // invalid ; // Invalid
} }
// If the view is visible... // If the view is visible...
@ -456,6 +467,18 @@
return _toolbarItem; return _toolbarItem;
} }
- (BOOL) enabled
{
id view = [_toolbarItem view];
if ([view respondsToSelector: @selector(setEnabled:)])
{
return [view enabled];
}
return _enabled;
}
- (void) setEnabled: (BOOL)enabled - (void) setEnabled: (BOOL)enabled
{ {
id view = [_toolbarItem view]; id view = [_toolbarItem view];
@ -498,14 +521,14 @@
- (NSMenuItem *) _defaultMenuFormRepresentation - (NSMenuItem *) _defaultMenuFormRepresentation
{ {
return nil; // override the default implementation in order to do nothing return nil; // Override the default implementation in order to do nothing
} }
- (void) _layout - (void) _layout
{ {
NSView *backView = [self _backView]; NSView *backView = [self _backView];
// override the default implementation // Override the default implementation
[(id)backView layout]; [(id)backView layout];
[backView setFrameSize: NSMakeSize(30, [backView frame].size.height)]; [backView setFrameSize: NSMakeSize(30, [backView frame].size.height)];
@ -529,7 +552,7 @@
- (NSMenuItem *) _defaultMenuFormRepresentation - (NSMenuItem *) _defaultMenuFormRepresentation
{ {
return nil;// override the default implementation in order to do nothing return nil; // Override the default implementation in order to do nothing
} }
@end @end
@ -551,7 +574,7 @@
- (NSMenuItem *) _defaultMenuFormRepresentation - (NSMenuItem *) _defaultMenuFormRepresentation
{ {
return nil;// override the default implementation in order to do nothing return nil; // Override the default implementation in order to do nothing
} }
- (void) _layout - (void) _layout
@ -562,7 +585,7 @@
[backView setFrameSize: NSMakeSize(0, [backView frame].size.height)]; [backView setFrameSize: NSMakeSize(0, [backView frame].size.height)];
// 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
} }
@end @end
@ -581,8 +604,8 @@
[self setImage: image]; [self setImage: image];
[self setLabel: @"Colors"]; // FIX ME: localize [self setLabel: @"Colors"]; // FIX ME: localize
// set action... // Set action...
[self setTarget: nil]; // goes to first responder.. [self setTarget: nil]; // Goes to first responder..
[self setAction: @selector(orderFrontColorPanel:)]; [self setAction: @selector(orderFrontColorPanel:)];
return self; return self;
@ -604,8 +627,8 @@
[self setImage: image]; [self setImage: image];
[self setLabel: @"Fonts"]; // FIX ME: localize [self setLabel: @"Fonts"]; // FIX ME: localize
// set action... // Set action...
[self setTarget: nil]; // goes to first responder.. [self setTarget: nil]; // Goes to first responder..
[self setAction: @selector(orderFrontFontPanel:)]; [self setAction: @selector(orderFrontFontPanel:)];
return self; return self;
@ -627,8 +650,8 @@
[self setImage: image]; [self setImage: image];
[self setLabel: @"Customize"]; // FIX ME: localize [self setLabel: @"Customize"]; // FIX ME: localize
// set action... // Set action...
[self setTarget: nil]; // goes to first responder.. [self setTarget: nil]; // Goes to first responder..
[self setAction: @selector(runCustomizationPalette:)]; [self setAction: @selector(runCustomizationPalette:)];
return self; return self;
@ -650,7 +673,7 @@
[self setImage: image]; [self setImage: image];
[self setLabel: @"Print..."]; // FIX ME: localize [self setLabel: @"Print..."]; // FIX ME: localize
// 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(print:)];
@ -660,18 +683,12 @@
@implementation NSToolbarItem @implementation NSToolbarItem
- (BOOL) allowsDuplicatesInToolbar + (void) initialize
{ {
return _allowsDuplicatesInToolbar; NormalFont = RETAIN([NSFont systemFontOfSize: 11]);
} // [NSFont smallSystemFontSize] or better should be NSControlContentFontSize
- (NSImage *)image SmallFont = RETAIN([NSFont systemFontOfSize: 9]);
{
if(_flags._image)
{
return _image;
}
return nil;
} }
- (id) initWithItemIdentifier: (NSString *)itemIdentifier - (id) initWithItemIdentifier: (NSString *)itemIdentifier
@ -747,7 +764,8 @@
[button setImagePosition: NSImageAbove]; [button setImagePosition: NSImageAbove];
[cell setBezeled: YES]; [cell setBezeled: YES];
[cell setHighlightsBy: NSChangeGrayCellMask | NSChangeBackgroundCellMask]; [cell setHighlightsBy: NSChangeGrayCellMask | NSChangeBackgroundCellMask];
[cell setFont: [NSFont systemFontOfSize: 11]]; // [NSFont smallSystemFontSize] or better should be controlContentFontSize [cell setFont: [NSFont systemFontOfSize: 11]];
// [NSFont smallSystemFontSize] or better should be controlContentFontSize
[_backView release]; [_backView release];
_backView = button; _backView = button;
@ -785,6 +803,11 @@
[super dealloc]; [super dealloc];
} }
- (BOOL) allowsDuplicatesInToolbar
{
return _allowsDuplicatesInToolbar;
}
- (BOOL) isEnabled - (BOOL) isEnabled
{ {
if(_flags._isEnabled) if(_flags._isEnabled)
@ -794,6 +817,15 @@
return NO; return NO;
} }
- (NSImage *)image
{
if(_flags._image)
{
return _image;
}
return nil;
}
- (NSString *) itemIdentifier - (NSString *) itemIdentifier
{ {
return _itemIdentifier; return _itemIdentifier;
@ -905,7 +937,7 @@
- (void) setTag: (int)tag - (void) setTag: (int)tag
{ {
if(_flags._tag) if(_flags._tag)
[_backView setTag: tag]; _tag = tag;
} }
- (void) setTarget: (id)target - (void) setTarget: (id)target
@ -960,7 +992,7 @@
- (int) tag - (int) tag
{ {
if(_flags._tag) if(_flags._tag)
return [_backView tag]; return _tag;
return 0; return 0;
} }
@ -977,7 +1009,7 @@
- (void) validate - (void) validate
{ {
// validate by default, we know that all of the // Validate by default, we know that all of the
// "standard" items are correct. // "standard" items are correct.
NSMenuItem *menuItem = [self menuFormRepresentation]; NSMenuItem *menuItem = [self menuFormRepresentation];
id target = [self target]; id target = [self target];
@ -992,6 +1024,8 @@
if ([target respondsToSelector: @selector(validateToolbarItem:)]) if ([target respondsToSelector: @selector(validateToolbarItem:)])
[self setEnabled: [target validateToolbarItem: self]]; [self setEnabled: [target validateToolbarItem: self]];
} }
// We can get a crash here when the target is pointing garbage memory...
} }
- (NSView *) view - (NSView *) view
@ -1044,6 +1078,11 @@
return [(GSToolbarButton *)_backView state]; return [(GSToolbarButton *)_backView state];
} }
- (GSToolbar *) _toolbar
{
return _toolbar;
}
- (void) _setSelected: (BOOL)selected - (void) _setSelected: (BOOL)selected
{ {
if (_selectable && ![self _selected] && selected) if (_selectable && ![self _selected] && selected)
@ -1075,7 +1114,8 @@
- (void) _setToolbar: (GSToolbar *)toolbar - (void) _setToolbar: (GSToolbar *)toolbar
{ {
ASSIGN(_toolbar, toolbar); // Don't do an ASSIGN here, the toolbar itself retains us.
_toolbar = toolbar;
} }
// NSValidatedUserInterfaceItem protocol // NSValidatedUserInterfaceItem protocol
@ -1105,7 +1145,7 @@
{ {
NSToolbarItem *new = [[NSToolbarItem allocWithZone: zone] initWithItemIdentifier: _itemIdentifier]; NSToolbarItem *new = [[NSToolbarItem allocWithZone: zone] initWithItemIdentifier: _itemIdentifier];
// copy all items individually... // Copy all items individually...
[new setTarget: [self target]]; [new setTarget: [self target]];
[new setAction: [self action]]; [new setAction: [self action]];
[new setView: [self view]]; [new setView: [self view]];