2002-06-30 05:14:21 +00:00
|
|
|
/*
|
|
|
|
NSToolbarItem.m
|
|
|
|
|
|
|
|
The Toolbar item class.
|
|
|
|
|
|
|
|
Copyright (C) 2002 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Gregory John Casamento <greg_casamento@yahoo.com>,
|
2004-04-13 13:12:53 +00:00
|
|
|
Fabien Vallon <fabien.vallon@fr.alcove.com>,
|
|
|
|
Quentin Mathe <qmathe@club-internet.fr>
|
2002-06-30 05:14:21 +00:00
|
|
|
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/NSString.h>
|
2004-02-25 03:27:23 +00:00
|
|
|
#include <Foundation/NSDebug.h>
|
|
|
|
|
2004-04-27 21:42:24 +00:00
|
|
|
#include "AppKit/NSApplication.h"
|
2003-06-13 15:01:12 +00:00
|
|
|
#include "AppKit/NSToolbarItem.h"
|
2004-02-25 03:27:23 +00:00
|
|
|
#include "AppKit/NSMenu.h"
|
2003-06-13 15:01:12 +00:00
|
|
|
#include "AppKit/NSMenuItem.h"
|
|
|
|
#include "AppKit/NSImage.h"
|
2003-08-29 04:13:48 +00:00
|
|
|
#include "AppKit/NSButton.h"
|
2004-02-25 03:27:23 +00:00
|
|
|
#include "AppKit/NSFont.h"
|
|
|
|
#include "AppKit/NSEvent.h"
|
2004-04-13 13:12:53 +00:00
|
|
|
#include "GNUstepGUI/GSToolbar.h"
|
2004-02-25 03:27:23 +00:00
|
|
|
#include "GNUstepGUI/GSToolbarView.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each NSToolbarItem object are coupled with a backView which is their representation
|
|
|
|
* on the screen.
|
|
|
|
* backView for the standard toolbar item (without custom view) are NSButton subclass
|
|
|
|
* called GSToolbarButton.
|
|
|
|
* backView for the toolbar item with a custom view are NSView subclass called
|
|
|
|
* GSToolbarBackView.
|
|
|
|
* GSToolbarButton and GSToolbarBackView are adjusted according to their content and
|
|
|
|
* their title when the method layout is called.
|
|
|
|
* The predefined GNUstep toolbar items are implemented with a class cluster pattern :
|
|
|
|
* initWithToolbarItemIdentifier: returns differents concrete subclass in accordance
|
|
|
|
* with the item identifier.
|
|
|
|
*/
|
2004-07-07 23:21:10 +00:00
|
|
|
|
2004-07-27 15:15:29 +00:00
|
|
|
typedef enum {
|
|
|
|
ItemBackViewDefaultHeight = 60,
|
|
|
|
ItemBackViewRegularHeight = 60,
|
|
|
|
ItemBackViewSmallHeight = 50
|
|
|
|
} ItemBackViewHeight;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
ItemBackViewDefaultWidth = 60,
|
|
|
|
ItemBackViewRegularWidth = 60,
|
|
|
|
ItemBackViewSmallWidth = 50
|
|
|
|
} ItemBackViewWidth;
|
|
|
|
|
|
|
|
static const int ItemBackViewX = 0;
|
|
|
|
static const int ItemBackViewY = 0;
|
|
|
|
static const int InsetItemViewX = 10;
|
|
|
|
static const int InsetItemViewY = 26;
|
|
|
|
static const int InsetItemTextX = 3;
|
|
|
|
static const int InsetItemTextY = 4;
|
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
static NSFont *NormalFont = nil; // See NSToolbarItem -initialize method
|
|
|
|
// [NSFont smallSystemFontSize] or better should be NSControlContentFontSize
|
|
|
|
|
|
|
|
static NSFont *SmallFont = nil;
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
@interface GSToolbar (GNUstepPrivate)
|
2004-02-25 03:27:23 +00:00
|
|
|
- (GSToolbarView *) _toolbarView;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSToolbarItem (GNUstepPrivate)
|
2004-05-23 18:22:45 +00:00
|
|
|
- (void) _layout;
|
|
|
|
// ---
|
2004-02-25 03:27:23 +00:00
|
|
|
- (NSView *) _backView;
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSMenuItem *) _defaultMenuFormRepresentation;
|
2004-02-25 03:27:23 +00:00
|
|
|
- (BOOL) _isFlexibleSpace;
|
2004-05-18 19:35:58 +00:00
|
|
|
- (BOOL) _isModified;
|
2004-05-23 18:22:45 +00:00
|
|
|
- (BOOL) _selectable;
|
2004-07-07 23:21:10 +00:00
|
|
|
- (GSToolbar *) _toolbar;
|
2004-05-23 18:22:45 +00:00
|
|
|
- (void) _setSelectable: (BOOL)selectable;
|
|
|
|
- (BOOL) _selected;
|
|
|
|
- (void) _setSelected: (BOOL)selected;
|
2004-04-13 13:12:53 +00:00
|
|
|
- (void) _setToolbar: (GSToolbar *)toolbar;
|
2004-02-25 03:27:23 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface GSToolbarView (GNUstepPrivate)
|
|
|
|
- (void) _reload;
|
|
|
|
@end
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NSButton subclass is the toolbar buttons _backView
|
|
|
|
*/
|
|
|
|
@interface GSToolbarButton : NSButton
|
|
|
|
{
|
|
|
|
NSToolbarItem *_toolbarItem;
|
2004-04-27 21:42:24 +00:00
|
|
|
SEL _toolbarItemAction;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem;
|
|
|
|
- (void) layout;
|
2004-05-23 18:22:45 +00:00
|
|
|
|
|
|
|
// Accessors
|
2004-02-25 03:27:23 +00:00
|
|
|
- (NSToolbarItem *) toolbarItem;
|
2004-04-27 21:42:24 +00:00
|
|
|
- (SEL) toolbarItemAction;
|
2004-05-23 18:22:45 +00:00
|
|
|
- (void) setToolbarItemAction: (SEL)action;
|
2004-02-25 03:27:23 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarButton
|
|
|
|
- (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem
|
|
|
|
{
|
2004-07-27 15:15:29 +00:00
|
|
|
self = [super initWithFrame: NSMakeRect(ItemBackViewX, ItemBackViewY, ItemBackViewDefaultWidth, ItemBackViewDefaultHeight)];
|
2004-05-23 18:22:45 +00:00
|
|
|
// Frame will be reset by the layout method
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
if (self != nil)
|
|
|
|
{
|
2004-07-07 23:21:10 +00:00
|
|
|
// Don't do an ASSIGN here, the toolbar item itself retains us.
|
|
|
|
_toolbarItem = toolbarItem;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
- (void) dealloc
|
2004-07-07 23:21:10 +00:00
|
|
|
{
|
|
|
|
// Nothing to do currently
|
2004-05-23 18:22:45 +00:00
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) layout
|
|
|
|
{
|
2004-04-13 13:12:53 +00:00
|
|
|
float textWidth, layoutedWidth = -1, layoutedHeight = -1;
|
2004-02-25 03:27:23 +00:00
|
|
|
NSAttributedString *attrStr;
|
|
|
|
NSDictionary *attr;
|
2004-07-07 23:21:10 +00:00
|
|
|
NSFont *font;
|
2004-05-23 18:22:45 +00:00
|
|
|
unsigned int borderMask = [[[_toolbarItem toolbar] _toolbarView] borderMask];
|
|
|
|
NSString *label = [_toolbarItem label];
|
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
// Adjust the layout in accordance with NSToolbarSizeMode
|
2004-05-23 18:22:45 +00:00
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
font = NormalFont;
|
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
switch ([[_toolbarItem toolbar] sizeMode])
|
|
|
|
{
|
|
|
|
case NSToolbarSizeModeDefault:
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedWidth = ItemBackViewDefaultWidth;
|
|
|
|
layoutedHeight = ItemBackViewDefaultHeight;
|
2004-04-13 13:12:53 +00:00
|
|
|
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
|
|
|
break;
|
|
|
|
case NSToolbarSizeModeRegular:
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedWidth = ItemBackViewRegularWidth;
|
|
|
|
layoutedHeight = ItemBackViewRegularHeight;
|
2004-04-13 13:12:53 +00:00
|
|
|
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
|
|
|
break;
|
|
|
|
case NSToolbarSizeModeSmall:
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedWidth = ItemBackViewSmallWidth;
|
|
|
|
layoutedHeight = ItemBackViewSmallHeight;
|
2004-04-13 13:12:53 +00:00
|
|
|
[[_toolbarItem image] setSize: NSMakeSize(24, 24)];
|
|
|
|
// Not use [self image] here because it can return nil, when image position is
|
|
|
|
// set to NSNoImage. Even if NSToolbarDisplayModeTextOnly is not true anymore
|
|
|
|
// -setImagePosition: is only called below, then [self image] can still returns
|
|
|
|
// nil.
|
2004-07-07 23:21:10 +00:00
|
|
|
font = SmallFont;
|
2004-04-13 13:12:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-07-07 23:21:10 +00:00
|
|
|
; // Invalid
|
2004-04-13 13:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[self cell] setFont: font];
|
2004-05-23 18:22:45 +00:00
|
|
|
|
|
|
|
// Adjust the layout in accordance with the border
|
|
|
|
|
|
|
|
if (!(borderMask & GSToolbarViewBottomBorder))
|
|
|
|
{
|
|
|
|
layoutedHeight++;
|
|
|
|
layoutedWidth++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(borderMask & GSToolbarViewTopBorder))
|
|
|
|
{
|
|
|
|
layoutedHeight++;
|
|
|
|
layoutedWidth++;
|
|
|
|
}
|
2004-04-13 13:12:53 +00:00
|
|
|
|
|
|
|
// Adjust the layout in accordance with the label
|
|
|
|
|
2004-07-24 20:51:39 +00:00
|
|
|
attr = [NSDictionary dictionaryWithObject: font forKey: NSFontAttributeName];
|
2004-05-23 18:22:45 +00:00
|
|
|
if (label == nil || [label isEqualToString: @""])
|
|
|
|
label = @"Dummy";
|
|
|
|
attrStr = [[NSAttributedString alloc] initWithString: label attributes: attr];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-07-27 15:15:29 +00:00
|
|
|
textWidth = [attrStr size].width + 2 * InsetItemTextX;
|
2004-04-13 13:12:53 +00:00
|
|
|
if (layoutedWidth != -1 && textWidth > layoutedWidth)
|
2004-02-25 03:27:23 +00:00
|
|
|
layoutedWidth = textWidth;
|
2004-04-13 13:12:53 +00:00
|
|
|
|
|
|
|
// Adjust the layout in accordance with NSToolbarDisplayMode
|
|
|
|
|
|
|
|
switch ([[_toolbarItem toolbar] displayMode])
|
|
|
|
{
|
|
|
|
case NSToolbarDisplayModeDefault:
|
|
|
|
[self setImagePosition: NSImageAbove];
|
|
|
|
break;
|
|
|
|
case NSToolbarDisplayModeIconAndLabel:
|
|
|
|
[self setImagePosition: NSImageAbove];
|
|
|
|
break;
|
|
|
|
case NSToolbarDisplayModeIconOnly:
|
|
|
|
[self setImagePosition: NSImageOnly];
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedHeight -= [attrStr size].height + InsetItemTextY;
|
|
|
|
layoutedWidth -= [attrStr size].height + InsetItemTextY;
|
2004-04-13 13:12:53 +00:00
|
|
|
break;
|
|
|
|
case NSToolbarDisplayModeLabelOnly:
|
|
|
|
[self setImagePosition: NSNoImage];
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedHeight = [attrStr size].height + InsetItemTextY * 2;
|
2004-04-13 13:12:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-07-07 23:21:10 +00:00
|
|
|
; // Invalid
|
2004-04-13 13:12:53 +00:00
|
|
|
}
|
2004-07-24 20:51:39 +00:00
|
|
|
DESTROY(attrStr);
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
// Set the frame size to use the new layout
|
|
|
|
|
|
|
|
[self setFrameSize: NSMakeSize(layoutedWidth, layoutedHeight)];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
- (void) mouseDown: (NSEvent *)event
|
|
|
|
{
|
|
|
|
if ([_toolbarItem _selectable] && [self state])
|
|
|
|
return; // Abort in case the button is selectable and selected
|
|
|
|
// HACK: must be improved to handle drag event
|
|
|
|
|
|
|
|
[super mouseDown: event];
|
|
|
|
}
|
|
|
|
|
2004-04-27 21:42:24 +00:00
|
|
|
- (BOOL) sendAction: (SEL)action to: (id)target
|
|
|
|
{
|
2004-05-23 18:22:45 +00:00
|
|
|
if ([_toolbarItem _selectable])
|
|
|
|
[[_toolbarItem toolbar] setSelectedItemIdentifier: [_toolbarItem itemIdentifier]];
|
|
|
|
|
2004-04-27 21:42:24 +00:00
|
|
|
if (_toolbarItemAction)
|
|
|
|
{
|
|
|
|
return [NSApp sendAction: _toolbarItemAction to: target from: _toolbarItem];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (NSToolbarItem *) toolbarItem
|
|
|
|
{
|
|
|
|
return _toolbarItem;
|
|
|
|
}
|
2004-04-27 21:42:24 +00:00
|
|
|
|
|
|
|
- (void) setToolbarItemAction: (SEL) action
|
|
|
|
{
|
|
|
|
_toolbarItemAction = action;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SEL) toolbarItemAction
|
|
|
|
{
|
|
|
|
return _toolbarItemAction;
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Back view used to enclose toolbar item's custom view
|
|
|
|
*/
|
|
|
|
@interface GSToolbarBackView : NSView
|
|
|
|
{
|
|
|
|
NSToolbarItem *_toolbarItem;
|
2004-07-07 23:21:10 +00:00
|
|
|
NSFont *_font;
|
2004-02-25 03:27:23 +00:00
|
|
|
BOOL _enabled;
|
2004-04-13 13:12:53 +00:00
|
|
|
BOOL _showLabel;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem;
|
|
|
|
- (NSToolbarItem *) toolbarItem;
|
2004-07-07 23:21:10 +00:00
|
|
|
- (BOOL) enabled;
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) setEnabled: (BOOL)enabled;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarBackView
|
|
|
|
|
|
|
|
- (id)initWithToolbarItem: (NSToolbarItem *)toolbarItem
|
|
|
|
{
|
2004-07-27 15:15:29 +00:00
|
|
|
self = [super initWithFrame: NSMakeRect(ItemBackViewX, ItemBackViewY, ItemBackViewDefaultWidth,
|
|
|
|
ItemBackViewDefaultHeight)];
|
2004-05-23 18:22:45 +00:00
|
|
|
// Frame will be reset by the layout method
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
if (self != nil)
|
|
|
|
{
|
2004-07-07 23:21:10 +00:00
|
|
|
// Don't do an ASSIGN here, the toolbar item itself retains us.
|
|
|
|
_toolbarItem = toolbarItem;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
- (void) dealloc
|
2004-07-07 23:21:10 +00:00
|
|
|
{
|
|
|
|
// _font is pointing on a static variable then we do own it and don't need
|
|
|
|
// to release it.
|
2004-05-23 18:22:45 +00:00
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void)drawRect: (NSRect)rect
|
|
|
|
{
|
|
|
|
NSAttributedString *attrString;
|
|
|
|
NSDictionary *attr;
|
2004-04-13 13:12:53 +00:00
|
|
|
NSColor *color;
|
2004-05-23 18:22:45 +00:00
|
|
|
float textX;
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
[super drawRect: rect]; // We draw _view which is a subview
|
|
|
|
|
|
|
|
if (_enabled)
|
|
|
|
{
|
2004-04-13 13:12:53 +00:00
|
|
|
color = [NSColor blackColor];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-04-13 13:12:53 +00:00
|
|
|
color = [NSColor disabledControlTextColor];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_showLabel)
|
|
|
|
{
|
2004-07-07 23:21:10 +00:00
|
|
|
// We draw the label
|
2004-04-13 13:12:53 +00:00
|
|
|
attr = [NSDictionary dictionaryWithObjectsAndKeys: _font,
|
2004-07-24 20:51:39 +00:00
|
|
|
NSFontAttributeName,
|
2004-04-13 13:12:53 +00:00
|
|
|
color,
|
2004-07-24 20:51:39 +00:00
|
|
|
NSForegroundColorAttributeName,
|
2004-05-23 18:22:45 +00:00
|
|
|
nil];
|
2004-04-13 13:12:53 +00:00
|
|
|
attrString = [[NSAttributedString alloc] initWithString: [_toolbarItem label] attributes: attr];
|
2004-07-27 15:15:29 +00:00
|
|
|
textX = (([self frame].size.width - InsetItemTextX) - [attrString size].width) / 2;
|
|
|
|
[attrString drawAtPoint: NSMakePoint(textX, InsetItemTextY)];
|
2004-07-24 20:51:39 +00:00
|
|
|
DESTROY(attrString);
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) layout
|
|
|
|
{
|
2004-04-13 13:12:53 +00:00
|
|
|
NSView *view = [_toolbarItem view];
|
|
|
|
float insetItemViewY;
|
|
|
|
float textWidth, layoutedWidth = -1, layoutedHeight = -1;
|
2004-02-25 03:27:23 +00:00
|
|
|
NSAttributedString *attrStr;
|
|
|
|
NSDictionary *attr;
|
2004-05-23 18:22:45 +00:00
|
|
|
unsigned int borderMask = [[[_toolbarItem toolbar] _toolbarView] borderMask];
|
|
|
|
NSString *label = [_toolbarItem label];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
_font = NormalFont;
|
2004-04-13 13:12:53 +00:00
|
|
|
|
|
|
|
if ([view superview] == nil) // Show the view to eventually hide it later
|
|
|
|
[self addSubview: view];
|
|
|
|
|
|
|
|
// Adjust the layout in accordance with NSToolbarSizeMode
|
|
|
|
|
|
|
|
switch ([[_toolbarItem toolbar] sizeMode])
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-04-13 13:12:53 +00:00
|
|
|
case NSToolbarSizeModeDefault:
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedWidth = ItemBackViewDefaultWidth;
|
|
|
|
layoutedHeight = ItemBackViewDefaultHeight;
|
2004-04-13 13:12:53 +00:00
|
|
|
if ([view frame].size.height > 32)
|
|
|
|
[view removeFromSuperview];
|
|
|
|
break;
|
|
|
|
case NSToolbarSizeModeRegular:
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedWidth = ItemBackViewRegularWidth;
|
|
|
|
layoutedHeight = ItemBackViewRegularHeight;
|
2004-04-13 13:12:53 +00:00
|
|
|
if ([view frame].size.height > 32)
|
|
|
|
[view removeFromSuperview];
|
|
|
|
break;
|
|
|
|
case NSToolbarSizeModeSmall:
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedWidth = ItemBackViewSmallWidth;
|
|
|
|
layoutedHeight = ItemBackViewSmallHeight;
|
2004-07-07 23:21:10 +00:00
|
|
|
_font = SmallFont;
|
2004-04-13 13:12:53 +00:00
|
|
|
if ([view frame].size.height > 24)
|
|
|
|
[view removeFromSuperview];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSLog(@"Invalid NSToolbarSizeMode"); // invalid
|
|
|
|
}
|
2004-05-23 18:22:45 +00:00
|
|
|
|
|
|
|
// Adjust the layout in accordance with the border
|
|
|
|
|
|
|
|
if (!(borderMask & GSToolbarViewBottomBorder))
|
|
|
|
{
|
|
|
|
layoutedHeight++;
|
|
|
|
layoutedWidth++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(borderMask & GSToolbarViewTopBorder))
|
|
|
|
{
|
|
|
|
layoutedHeight++;
|
|
|
|
layoutedWidth++;
|
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
// Adjust the layout in accordance with the label
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-07-24 20:51:39 +00:00
|
|
|
attr = [NSDictionary dictionaryWithObject: _font forKey: NSFontAttributeName];
|
2004-05-23 18:22:45 +00:00
|
|
|
if (label == nil || [label isEqualToString: @""])
|
|
|
|
label = @"Dummy";
|
|
|
|
attrStr = [[NSAttributedString alloc] initWithString: label attributes: attr];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-07-27 15:15:29 +00:00
|
|
|
textWidth = [attrStr size].width + 2 * InsetItemTextX;
|
2004-04-13 13:12:53 +00:00
|
|
|
if (textWidth > layoutedWidth)
|
|
|
|
layoutedWidth = textWidth;
|
|
|
|
|
|
|
|
// Adjust the layout in accordance with NSToolbarDisplayMode
|
|
|
|
|
|
|
|
_enabled = YES;
|
|
|
|
_showLabel = YES;
|
2004-07-07 23:21:10 +00:00
|
|
|
// This boolean variable is used to known when it's needed to draw the label in the -drawRect:
|
2004-04-13 13:12:53 +00:00
|
|
|
// method.
|
|
|
|
|
|
|
|
switch ([[_toolbarItem toolbar] displayMode])
|
|
|
|
{
|
|
|
|
case NSToolbarDisplayModeDefault:
|
|
|
|
break; // Nothing to do
|
|
|
|
case NSToolbarDisplayModeIconAndLabel:
|
|
|
|
break; // Nothing to do
|
|
|
|
case NSToolbarDisplayModeIconOnly:
|
|
|
|
_showLabel = NO;
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedHeight -= [attrStr size].height + InsetItemTextY;
|
2004-04-13 13:12:53 +00:00
|
|
|
break;
|
|
|
|
case NSToolbarDisplayModeLabelOnly:
|
|
|
|
_enabled = NO;
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedHeight = [attrStr size].height + InsetItemTextY * 2;
|
2004-04-13 13:12:53 +00:00
|
|
|
if ([view superview] != nil)
|
|
|
|
[view removeFromSuperview];
|
|
|
|
break;
|
|
|
|
default:
|
2004-07-07 23:21:10 +00:00
|
|
|
; // Invalid
|
2004-04-13 13:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the view is visible...
|
|
|
|
// Adjust the layout in accordance with the view width in the case it is needed
|
|
|
|
|
|
|
|
if ([view superview] != nil)
|
|
|
|
{
|
2004-07-27 15:15:29 +00:00
|
|
|
if (layoutedWidth < [view frame].size.width + 2 * InsetItemViewX)
|
|
|
|
layoutedWidth = [view frame].size.width + 2 * InsetItemViewX;
|
2004-04-13 13:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the frame size to use the new layout
|
|
|
|
|
|
|
|
[self setFrameSize: NSMakeSize(layoutedWidth, layoutedHeight)];
|
|
|
|
|
|
|
|
// If the view is visible...
|
|
|
|
// Adjust the view position in accordance with the new layout
|
|
|
|
|
|
|
|
if ([view superview] != nil)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-04-13 13:12:53 +00:00
|
|
|
if (_showLabel)
|
|
|
|
{
|
|
|
|
insetItemViewY = ([self frame].size.height
|
2004-07-27 15:15:29 +00:00
|
|
|
- [view frame].size.height - [attrStr size].height - InsetItemTextX) / 2
|
|
|
|
+ [attrStr size].height + InsetItemTextX;
|
2004-04-13 13:12:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
insetItemViewY = ([self frame].size.height - [view frame].size.height) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
[view setFrameOrigin:
|
|
|
|
NSMakePoint((layoutedWidth - [view frame].size.width) / 2, insetItemViewY)];
|
|
|
|
}
|
2004-07-24 20:51:39 +00:00
|
|
|
DESTROY(attrStr);
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSToolbarItem *)toolbarItem
|
|
|
|
{
|
|
|
|
return _toolbarItem;
|
|
|
|
}
|
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
- (BOOL) enabled
|
|
|
|
{
|
|
|
|
id view = [_toolbarItem view];
|
|
|
|
|
|
|
|
if ([view respondsToSelector: @selector(setEnabled:)])
|
|
|
|
{
|
|
|
|
return [view enabled];
|
|
|
|
}
|
|
|
|
|
|
|
|
return _enabled;
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) setEnabled: (BOOL)enabled
|
|
|
|
{
|
|
|
|
id view = [_toolbarItem view];
|
|
|
|
|
|
|
|
_enabled = enabled;
|
|
|
|
if ([view respondsToSelector: @selector(setEnabled:)])
|
|
|
|
{
|
|
|
|
[view setEnabled: enabled];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Standard toolbar items.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// ---- NSToolbarSeparatorItemIdentifier
|
|
|
|
@interface GSToolbarSeparatorItem : NSToolbarItem
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarSeparatorItem
|
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
2004-05-06 02:12:38 +00:00
|
|
|
NSImage *image = [NSImage imageNamed: @"common_ToolbarSeparatorItem"];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
|
|
|
[(NSButton *)[self _backView] setImagePosition: NSImageOnly];
|
|
|
|
[(NSButton *)[self _backView] setImage: image];
|
|
|
|
// We bypass the toolbar item accessor to set the image in order to have it (48 * 48) not resized
|
|
|
|
|
2004-07-27 15:15:29 +00:00
|
|
|
[[self _backView] setFrameSize: NSMakeSize(30, ItemBackViewDefaultHeight)];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSMenuItem *) _defaultMenuFormRepresentation
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-07-07 23:21:10 +00:00
|
|
|
return nil; // Override the default implementation in order to do nothing
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _layout
|
|
|
|
{
|
2004-05-23 18:22:45 +00:00
|
|
|
NSView *backView = [self _backView];
|
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
// Override the default implementation
|
2004-05-23 18:22:45 +00:00
|
|
|
|
|
|
|
[(id)backView layout];
|
|
|
|
[backView setFrameSize: NSMakeSize(30, [backView frame].size.height)];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// ---- NSToolbarSpaceItemIdentifier
|
|
|
|
@interface GSToolbarSpaceItem : NSToolbarItem
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarSpaceItem
|
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
|
|
|
[self setLabel: @""];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSMenuItem *) _defaultMenuFormRepresentation
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-07-07 23:21:10 +00:00
|
|
|
return nil; // Override the default implementation in order to do nothing
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// ---- NSToolbarFlexibleSpaceItemIdentifier
|
|
|
|
@interface GSToolbarFlexibleSpaceItem : NSToolbarItem
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarFlexibleSpaceItem
|
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
|
|
|
[self setLabel: @""];
|
|
|
|
[self _layout];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSMenuItem *) _defaultMenuFormRepresentation
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-07-07 23:21:10 +00:00
|
|
|
return nil; // Override the default implementation in order to do nothing
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _layout
|
|
|
|
{
|
|
|
|
NSView *backView = [self _backView];
|
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
[(id)backView layout];
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
[backView setFrameSize: NSMakeSize(0, [backView frame].size.height)];
|
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
// Override the default implementation in order to reset the _backView to a zero width
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// ---- NSToolbarShowColorsItemIdentifier
|
|
|
|
@interface GSToolbarShowColorsItem : NSToolbarItem
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarShowColorsItem
|
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
NSImage *image = [NSImage imageNamed: @"common_ToolbarShowColorsItem"];
|
|
|
|
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
|
|
|
[self setImage: image];
|
2004-05-23 18:22:45 +00:00
|
|
|
[self setLabel: @"Colors"]; // FIX ME: localize
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
// Set action...
|
|
|
|
[self setTarget: nil]; // Goes to first responder..
|
2004-02-25 03:27:23 +00:00
|
|
|
[self setAction: @selector(orderFrontColorPanel:)];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// ---- NSToolbarShowFontsItemIdentifier
|
|
|
|
@interface GSToolbarShowFontsItem : NSToolbarItem
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarShowFontsItem
|
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
NSImage *image = [NSImage imageNamed: @"common_ToolbarShowFontsItem"];
|
|
|
|
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
|
|
|
[self setImage: image];
|
2004-05-23 18:22:45 +00:00
|
|
|
[self setLabel: @"Fonts"]; // FIX ME: localize
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
// Set action...
|
|
|
|
[self setTarget: nil]; // Goes to first responder..
|
2004-02-25 03:27:23 +00:00
|
|
|
[self setAction: @selector(orderFrontFontPanel:)];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// ---- NSToolbarCustomizeToolbarItemIdentifier
|
|
|
|
@interface GSToolbarCustomizeToolbarItem : NSToolbarItem
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarCustomizeToolbarItem
|
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
NSImage *image = [NSImage imageNamed: @"common_ToolbarCustomizeToolbarItem"];
|
|
|
|
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
|
|
|
[self setImage: image];
|
2004-05-23 18:22:45 +00:00
|
|
|
[self setLabel: @"Customize"]; // FIX ME: localize
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
// Set action...
|
|
|
|
[self setTarget: nil]; // Goes to first responder..
|
2004-02-25 03:27:23 +00:00
|
|
|
[self setAction: @selector(runCustomizationPalette:)];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// ---- NSToolbarPrintItemIdentifier
|
|
|
|
@interface GSToolbarPrintItem : NSToolbarItem
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarPrintItem
|
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
NSImage *image = [NSImage imageNamed: @"common_Printer"];
|
|
|
|
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
|
|
|
[self setImage: image];
|
2004-05-23 18:22:45 +00:00
|
|
|
[self setLabel: @"Print..."]; // FIX ME: localize
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
// Set action...
|
2004-02-25 03:27:23 +00:00
|
|
|
[self setTarget: nil]; // goes to first responder..
|
|
|
|
[self setAction: @selector(print:)];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2002-06-30 05:14:21 +00:00
|
|
|
|
|
|
|
@implementation NSToolbarItem
|
2004-07-07 23:21:10 +00:00
|
|
|
+ (void) initialize
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-07-07 23:21:10 +00:00
|
|
|
NormalFont = RETAIN([NSFont systemFontOfSize: 11]);
|
|
|
|
// [NSFont smallSystemFontSize] or better should be NSControlContentFontSize
|
|
|
|
|
|
|
|
SmallFont = RETAIN([NSFont systemFontOfSize: 9]);
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
GSToolbarButton *button;
|
|
|
|
NSButtonCell *cell;
|
|
|
|
|
|
|
|
if ((self = [super init]) != nil)
|
|
|
|
{
|
|
|
|
|
|
|
|
// GNUstep predefined toolbar items
|
|
|
|
|
|
|
|
if ([itemIdentifier isEqualToString: @"NSToolbarSeparatorItemIdentifier"]
|
|
|
|
&& ![self isKindOfClass:[GSToolbarSeparatorItem class]])
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
self = [[GSToolbarSeparatorItem alloc] initWithItemIdentifier: itemIdentifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ([itemIdentifier isEqualToString: @"NSToolbarSpaceItemIdentifier"]
|
|
|
|
&& ![self isKindOfClass:[GSToolbarSpaceItem class]])
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
self = [[GSToolbarSpaceItem alloc] initWithItemIdentifier: itemIdentifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ([itemIdentifier isEqualToString: @"NSToolbarFlexibleSpaceItemIdentifier"]
|
|
|
|
&& ![self isKindOfClass:[GSToolbarFlexibleSpaceItem class]])
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
self = [[GSToolbarFlexibleSpaceItem alloc] initWithItemIdentifier: itemIdentifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ([itemIdentifier isEqualToString: @"NSToolbarShowColorsItemIdentifier"]
|
|
|
|
&& ![self isKindOfClass:[GSToolbarShowColorsItem class]])
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
self = [[GSToolbarShowColorsItem alloc] initWithItemIdentifier: itemIdentifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ([itemIdentifier isEqualToString: @"NSToolbarShowFontsItemIdentifier"]
|
|
|
|
&& ![self isKindOfClass:[GSToolbarShowFontsItem class]])
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
self = [[GSToolbarShowFontsItem alloc] initWithItemIdentifier: itemIdentifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ([itemIdentifier isEqualToString: @"NSToolbarCustomizeToolbarItemIdentifier"]
|
|
|
|
&& ![self isKindOfClass:[GSToolbarCustomizeToolbarItem class]])
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
self = [[GSToolbarCustomizeToolbarItem alloc] initWithItemIdentifier: itemIdentifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ([itemIdentifier isEqualToString: @"NSToolbarPrintItemIdentifier"]
|
|
|
|
&& ![self isKindOfClass:[GSToolbarPrintItem class]])
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
self = [[GSToolbarPrintItem alloc] initWithItemIdentifier: itemIdentifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normal toolbar items
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
ASSIGN(_itemIdentifier, itemIdentifier);
|
|
|
|
|
|
|
|
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];
|
2004-07-07 23:21:10 +00:00
|
|
|
[cell setFont: [NSFont systemFontOfSize: 11]];
|
|
|
|
// [NSFont smallSystemFontSize] or better should be controlContentFontSize
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
[_backView release];
|
|
|
|
_backView = button;
|
|
|
|
}
|
|
|
|
|
|
|
|
// gets
|
|
|
|
_flags._isEnabled = [_backView respondsToSelector: @selector(isEnabled)];
|
|
|
|
_flags._tag = YES;
|
2004-04-27 21:42:24 +00:00
|
|
|
_flags._action = [_backView respondsToSelector: @selector(toolbarItemAction)];
|
2004-02-25 03:27:23 +00:00
|
|
|
_flags._target = [_backView respondsToSelector: @selector(target)];
|
|
|
|
_flags._image = [_backView respondsToSelector: @selector(image)];
|
|
|
|
// sets
|
|
|
|
_flags._setEnabled = [_backView respondsToSelector: @selector(setEnabled:)];
|
|
|
|
_flags._setTag = YES;
|
2004-04-27 21:42:24 +00:00
|
|
|
_flags._setAction = [_backView respondsToSelector: @selector(setToolbarItemAction:)];
|
2004-02-25 03:27:23 +00:00
|
|
|
_flags._setTarget = [_backView respondsToSelector: @selector(setTarget:)];
|
|
|
|
_flags._setImage = [_backView respondsToSelector: @selector(setImage:)];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-06-30 05:14:21 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
RELEASE(_itemIdentifier);
|
|
|
|
RELEASE(_label);
|
|
|
|
RELEASE(_image);
|
|
|
|
RELEASE(_menuFormRepresentation);
|
|
|
|
RELEASE(_paletteLabel);
|
|
|
|
RELEASE(_toolTip);
|
|
|
|
RELEASE(_view);
|
|
|
|
RELEASE(_backView);
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
- (BOOL) allowsDuplicatesInToolbar
|
|
|
|
{
|
|
|
|
return _allowsDuplicatesInToolbar;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (BOOL) isEnabled
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2003-08-29 04:13:48 +00:00
|
|
|
if(_flags._isEnabled)
|
2003-08-24 17:22:11 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
return [(id)_backView isEnabled];
|
2003-08-24 17:22:11 +00:00
|
|
|
}
|
|
|
|
return NO;
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
- (NSImage *)image
|
|
|
|
{
|
|
|
|
if(_flags._image)
|
|
|
|
{
|
|
|
|
return _image;
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSString *) itemIdentifier
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _itemIdentifier;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSString *) label
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-05-18 19:35:58 +00:00
|
|
|
NSMenuItem *menuItem = [self menuFormRepresentation];
|
|
|
|
|
|
|
|
if ([[self toolbar] displayMode] == NSToolbarDisplayModeLabelOnly && menuItem != nil)
|
|
|
|
{
|
|
|
|
return [menuItem title];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return _label;
|
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSSize) maxSize
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _maxSize;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSMenuItem *) menuFormRepresentation
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-05-18 19:35:58 +00:00
|
|
|
return _menuFormRepresentation;
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSSize) minSize
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _minSize;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSString *) paletteLabel
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _paletteLabel;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setAction: (SEL)action
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2003-08-29 04:13:48 +00:00
|
|
|
if(_flags._setAction)
|
2003-08-24 17:22:11 +00:00
|
|
|
{
|
2004-04-27 21:42:24 +00:00
|
|
|
if ([_backView isKindOfClass: [GSToolbarButton class]])
|
|
|
|
[(GSToolbarButton *)_backView setToolbarItemAction: action];
|
2004-02-25 03:27:23 +00:00
|
|
|
if (action != NULL)
|
|
|
|
{
|
2004-05-18 19:35:58 +00:00
|
|
|
[self setEnabled: YES];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-18 19:35:58 +00:00
|
|
|
[self setEnabled: NO];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
2003-08-24 17:22:11 +00:00
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setEnabled: (BOOL)enabled
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2003-08-29 04:13:48 +00:00
|
|
|
if(_flags._setEnabled)
|
2004-02-25 03:27:23 +00:00
|
|
|
[(id)_backView setEnabled: enabled];
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setImage: (NSImage *)image
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2003-08-29 04:13:48 +00:00
|
|
|
if(_flags._setImage)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_image, image);
|
|
|
|
|
|
|
|
[_image setScalesWhenResized: YES];
|
2004-04-13 13:12:53 +00:00
|
|
|
//[_image setSize: NSMakeSize(32, 32)];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
if ([_backView isKindOfClass: [NSButton class]])
|
|
|
|
[(NSButton *)_backView setImage: _image];
|
2003-08-24 17:22:11 +00:00
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setLabel: (NSString *)label
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_label, label);
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
if ([_backView isKindOfClass: [NSButton class]])
|
|
|
|
[(NSButton *)_backView setTitle:_label];
|
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
_modified = YES;
|
2004-02-25 03:27:23 +00:00
|
|
|
if (_toolbar != nil)
|
|
|
|
[[_toolbar _toolbarView] _reload];
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setMaxSize: (NSSize)maxSize
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
_maxSize = maxSize;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setMenuFormRepresentation: (NSMenuItem *)menuItem
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_menuFormRepresentation, menuItem);
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setMinSize: (NSSize)minSize
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
_minSize = minSize;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setPaletteLabel: (NSString *)paletteLabel
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_paletteLabel, paletteLabel);
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setTag: (int)tag
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2003-08-29 04:13:48 +00:00
|
|
|
if(_flags._tag)
|
2004-07-07 23:21:10 +00:00
|
|
|
_tag = tag;
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setTarget: (id)target
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2003-08-29 04:13:48 +00:00
|
|
|
if(_flags._target)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
if ([_backView isKindOfClass: [NSButton class]])
|
|
|
|
[(NSButton *)_backView setTarget: target];
|
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setToolTip: (NSString *)toolTip
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_toolTip, toolTip);
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setView: (NSView *)view
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_view, view);
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
if (_view == nil)
|
|
|
|
{
|
|
|
|
// gets
|
|
|
|
_flags._isEnabled = [_backView respondsToSelector: @selector(isEnabled)];
|
2004-04-27 21:42:24 +00:00
|
|
|
_flags._action = [_backView respondsToSelector: @selector(toolbarItemAction)];
|
2004-02-25 03:27:23 +00:00
|
|
|
_flags._target = [_backView respondsToSelector: @selector(target)];
|
|
|
|
_flags._image = [_backView respondsToSelector: @selector(image)];
|
|
|
|
// sets
|
|
|
|
_flags._setEnabled = [_backView respondsToSelector: @selector(setEnabled:)];
|
2004-04-27 21:42:24 +00:00
|
|
|
_flags._setAction = [_backView respondsToSelector: @selector(setToolbarItemAction:)];
|
2004-02-25 03:27:23 +00:00
|
|
|
_flags._setTarget = [_backView respondsToSelector: @selector(setTarget:)];
|
|
|
|
_flags._setImage = [_backView respondsToSelector: @selector(setImage:)];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// gets
|
|
|
|
_flags._isEnabled = [_view respondsToSelector: @selector(isEnabled)];
|
|
|
|
_flags._action = [_view respondsToSelector: @selector(action)];
|
|
|
|
_flags._target = [_view respondsToSelector: @selector(target)];
|
|
|
|
_flags._image = [_backView respondsToSelector: @selector(image)];
|
|
|
|
// sets
|
|
|
|
_flags._setEnabled = [_view respondsToSelector: @selector(setEnabled:)];
|
|
|
|
_flags._setAction = [_view respondsToSelector: @selector(setAction:)];
|
|
|
|
_flags._setTarget = [_view respondsToSelector: @selector(setTarget:)];
|
|
|
|
_flags._setImage = [_backView respondsToSelector: @selector(setImage:)];
|
|
|
|
}
|
|
|
|
|
|
|
|
[_backView release];
|
|
|
|
_backView = [[GSToolbarBackView alloc] initWithToolbarItem: self];
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (int) tag
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2003-08-29 04:13:48 +00:00
|
|
|
if(_flags._tag)
|
2004-07-07 23:21:10 +00:00
|
|
|
return _tag;
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2003-08-24 17:22:11 +00:00
|
|
|
return 0;
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSString *) toolTip
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _toolTip;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (GSToolbar *) toolbar
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _toolbar;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) validate
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2004-07-07 23:21:10 +00:00
|
|
|
// Validate by default, we know that all of the
|
2002-12-29 05:38:29 +00:00
|
|
|
// "standard" items are correct.
|
2004-05-18 19:35:58 +00:00
|
|
|
NSMenuItem *menuItem = [self menuFormRepresentation];
|
|
|
|
id target = [self target];
|
|
|
|
|
|
|
|
if ([[self toolbar] displayMode] == NSToolbarDisplayModeLabelOnly && menuItem != nil)
|
|
|
|
{
|
|
|
|
if ([target respondsToSelector: @selector(validateMenuItem:)])
|
|
|
|
[self setEnabled: [target validateMenuItem: menuItem]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([target respondsToSelector: @selector(validateToolbarItem:)])
|
|
|
|
[self setEnabled: [target validateToolbarItem: self]];
|
|
|
|
}
|
2004-07-07 23:21:10 +00:00
|
|
|
|
|
|
|
// We can get a crash here when the target is pointing garbage memory...
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSView *) view
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
|
|
|
return _view;
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
// Private or package like visibility methods
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSView *) _backView
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
return _backView;
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSMenuItem *) _defaultMenuFormRepresentation
|
|
|
|
{
|
|
|
|
NSMenuItem *menuItem;
|
|
|
|
|
|
|
|
menuItem = [[NSMenuItem alloc] initWithTitle: [self label]
|
|
|
|
action: [self action]
|
|
|
|
keyEquivalent: @""];
|
|
|
|
[menuItem setTarget: [self target]];
|
|
|
|
AUTORELEASE(menuItem);
|
|
|
|
|
|
|
|
return menuItem;
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) _layout
|
|
|
|
{
|
|
|
|
[(id)_backView layout];
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (BOOL) _isModified
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-04-13 13:12:53 +00:00
|
|
|
return _modified;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (BOOL) _isFlexibleSpace
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
return [self isKindOfClass: [GSToolbarFlexibleSpaceItem class]];
|
|
|
|
}
|
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
- (BOOL) _selectable
|
|
|
|
{
|
|
|
|
return _selectable;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) _selected
|
|
|
|
{
|
|
|
|
return [(GSToolbarButton *)_backView state];
|
|
|
|
}
|
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
- (GSToolbar *) _toolbar
|
|
|
|
{
|
|
|
|
return _toolbar;
|
|
|
|
}
|
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
- (void) _setSelected: (BOOL)selected
|
|
|
|
{
|
|
|
|
if (_selectable && ![self _selected] && selected)
|
|
|
|
{
|
|
|
|
[(GSToolbarButton *)_backView performClick:self];
|
|
|
|
}
|
|
|
|
else if (!selected)
|
|
|
|
{
|
|
|
|
[(GSToolbarButton *)_backView setState: NO];
|
|
|
|
}
|
|
|
|
else if (!_selectable)
|
|
|
|
{
|
|
|
|
NSLog(@"The toolbar item %@ is not selectable", self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setSelectable: (BOOL)selectable
|
|
|
|
{
|
|
|
|
if ([_backView isKindOfClass: [GSToolbarButton class]])
|
|
|
|
{
|
|
|
|
_selectable = selectable;
|
|
|
|
[(GSToolbarButton *)_backView setButtonType: NSOnOffButton];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSLog(@"The toolbar item %@ is not selectable", self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
- (void) _setToolbar: (GSToolbar *)toolbar
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-07-07 23:21:10 +00:00
|
|
|
// Don't do an ASSIGN here, the toolbar itself retains us.
|
|
|
|
_toolbar = toolbar;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2002-06-30 05:14:21 +00:00
|
|
|
// NSValidatedUserInterfaceItem protocol
|
2004-05-18 19:35:58 +00:00
|
|
|
- (SEL) action
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2003-08-29 04:13:48 +00:00
|
|
|
if(_flags._action)
|
2003-08-24 17:22:11 +00:00
|
|
|
{
|
2004-04-27 21:42:24 +00:00
|
|
|
if ([_backView isKindOfClass: [GSToolbarButton class]])
|
|
|
|
return [(GSToolbarButton *)_backView toolbarItemAction];
|
2003-08-24 17:22:11 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (id) target
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2003-08-29 04:13:48 +00:00
|
|
|
if(_flags._target)
|
2003-08-24 17:22:11 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
if ([_backView isKindOfClass: [NSButton class]])
|
|
|
|
return [(NSButton *)_backView target];
|
2003-08-24 17:22:11 +00:00
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2003-08-24 17:22:11 +00:00
|
|
|
return nil;
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NSCopying protocol
|
2004-05-18 19:35:58 +00:00
|
|
|
- (id) copyWithZone: (NSZone *)zone
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2003-08-29 04:13:48 +00:00
|
|
|
NSToolbarItem *new = [[NSToolbarItem allocWithZone: zone] initWithItemIdentifier: _itemIdentifier];
|
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
// Copy all items individually...
|
2003-08-29 04:13:48 +00:00
|
|
|
[new setTarget: [self target]];
|
|
|
|
[new setAction: [self action]];
|
|
|
|
[new setView: [self view]];
|
|
|
|
[new setToolTip: [[self toolTip] copyWithZone: zone]];
|
|
|
|
[new setTag: [self tag]];
|
|
|
|
[new setImage: [[self image] copyWithZone: zone]];
|
|
|
|
[new setEnabled: [self isEnabled]];
|
|
|
|
[new setPaletteLabel: [[self paletteLabel] copyWithZone: zone]];
|
|
|
|
[new setMinSize: NSMakeSize(_minSize.width, _minSize.height)];
|
|
|
|
[new setMaxSize: NSMakeSize(_maxSize.width, _maxSize.height)];
|
|
|
|
|
2004-07-24 20:51:39 +00:00
|
|
|
return new;
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
2004-05-18 19:35:58 +00:00
|
|
|
|
2002-06-30 05:14:21 +00:00
|
|
|
@end
|
2004-07-24 20:51:39 +00:00
|
|
|
|