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>,
|
2007-10-29 21:16:17 +00:00
|
|
|
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
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2002-06-30 05:14:21 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:01:49 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2007-10-29 21:16:17 +00:00
|
|
|
|
2002-06-30 05:14:21 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-29 21:16:17 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2002-06-30 05:14:21 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2002-06-30 05:14:21 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
2007-10-29 21:16:17 +00:00
|
|
|
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.
|
2002-06-30 05:14:21 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-31 08:14:50 +00:00
|
|
|
#import <Foundation/NSObject.h>
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSArchiver.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import "AppKit/NSApplication.h"
|
|
|
|
#import "AppKit/NSAttributedString.h"
|
|
|
|
#import "AppKit/NSButton.h"
|
|
|
|
#import "AppKit/NSButtonCell.h"
|
|
|
|
#import "AppKit/NSDragging.h"
|
|
|
|
#import "AppKit/NSEvent.h"
|
|
|
|
#import "AppKit/NSFont.h"
|
|
|
|
#import "AppKit/NSImage.h"
|
|
|
|
#import "AppKit/NSMenu.h"
|
|
|
|
#import "AppKit/NSMenuItem.h"
|
|
|
|
#import "AppKit/NSParagraphStyle.h"
|
|
|
|
#import "AppKit/NSPasteboard.h"
|
|
|
|
#import "AppKit/NSStringDrawing.h"
|
|
|
|
#import "AppKit/NSToolbar.h"
|
|
|
|
#import "AppKit/NSView.h"
|
|
|
|
#import "GNUstepGUI/GSToolbarView.h"
|
|
|
|
#import "AppKit/NSToolbarItem.h"
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2010-03-31 08:14:50 +00:00
|
|
|
#import "NSToolbarFrameworkPrivate.h"
|
|
|
|
#import "GSGuiPrivate.h"
|
2009-01-02 17:24:06 +00:00
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
/*
|
2004-12-30 14:02:00 +00:00
|
|
|
* 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.
|
2004-02-25 03:27:23 +00:00
|
|
|
* backView for the toolbar item with a custom view are NSView subclass called
|
|
|
|
* GSToolbarBackView.
|
2004-12-30 14:02:00 +00:00
|
|
|
* 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-02-25 03:27:23 +00:00
|
|
|
*/
|
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;
|
2020-04-24 08:29:15 +00:00
|
|
|
// static const int InsetItemViewY = 26;
|
2004-07-27 15:15:29 +00:00
|
|
|
static const int InsetItemTextX = 3;
|
|
|
|
static const int InsetItemTextY = 4;
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
// See NSToolbarItem -initialize method
|
|
|
|
static NSFont *NormalFont = nil;
|
2004-07-07 23:21:10 +00:00
|
|
|
static NSFont *SmallFont = nil;
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-09-02 17:40:00 +00:00
|
|
|
NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
/*
|
|
|
|
* NSButton subclass is the toolbar buttons _backView
|
|
|
|
*/
|
|
|
|
@interface GSToolbarButton : NSButton
|
|
|
|
{
|
|
|
|
NSToolbarItem *_toolbarItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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;
|
|
|
|
@end
|
|
|
|
|
2004-08-30 21:33:17 +00:00
|
|
|
@interface GSToolbarButtonCell : NSButtonCell
|
|
|
|
{
|
|
|
|
NSRect titleRect;
|
|
|
|
NSRect imageRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
@implementation GSToolbarButton
|
2009-08-04 20:12:35 +00:00
|
|
|
|
2004-09-21 16:55:43 +00:00
|
|
|
+ (Class) cellClass
|
2004-08-30 21:33:17 +00:00
|
|
|
{
|
2004-09-21 16:55:43 +00:00
|
|
|
return [GSToolbarButtonCell class];
|
2004-08-30 21:33:17 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem
|
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
// Frame will be reset by the layout method
|
2004-08-30 21:33:17 +00:00
|
|
|
self = [super initWithFrame: NSMakeRect(ItemBackViewX, ItemBackViewY,
|
|
|
|
ItemBackViewDefaultWidth, ItemBackViewDefaultHeight)];
|
2004-05-23 18:22:45 +00:00
|
|
|
|
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;
|
2008-12-30 22:20:21 +00:00
|
|
|
|
|
|
|
[self setTitle: @""];
|
|
|
|
[self setEnabled: NO];
|
|
|
|
[_cell setBezeled: YES];
|
|
|
|
[self setImagePosition: NSImageAbove];
|
|
|
|
[self setHighlightsBy:
|
|
|
|
NSChangeGrayCellMask | NSChangeBackgroundCellMask];
|
2009-08-04 20:12:35 +00:00
|
|
|
[self setFont: NormalFont];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2008-12-30 22:20:21 +00:00
|
|
|
return self;
|
2004-05-23 18:22:45 +00:00
|
|
|
}
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
/*
|
|
|
|
* The code below should be kept in sync with GSToolbarBackView methods which
|
|
|
|
* have identical names.
|
|
|
|
*/
|
|
|
|
|
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-07-07 23:21:10 +00:00
|
|
|
NSFont *font;
|
2004-05-23 18:22:45 +00:00
|
|
|
unsigned int borderMask = [[[_toolbarItem toolbar] _toolbarView] borderMask];
|
2009-08-04 20:12:35 +00:00
|
|
|
NSSize labelSize = NSZeroSize;
|
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
font = NormalFont;
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
// Adjust the layout in accordance with NSToolbarSizeMode
|
2004-04-13 13:12:53 +00:00
|
|
|
switch ([[_toolbarItem toolbar] sizeMode])
|
|
|
|
{
|
|
|
|
case NSToolbarSizeModeDefault:
|
2008-12-28 15:16:05 +00:00
|
|
|
layoutedWidth = ItemBackViewDefaultWidth;
|
|
|
|
layoutedHeight = ItemBackViewDefaultHeight;
|
|
|
|
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
|
|
|
break;
|
2004-04-13 13:12:53 +00:00
|
|
|
case NSToolbarSizeModeRegular:
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedWidth = ItemBackViewRegularWidth;
|
|
|
|
layoutedHeight = ItemBackViewRegularHeight;
|
2008-12-28 15:16:05 +00:00
|
|
|
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
|
|
|
break;
|
2004-04-13 13:12:53 +00:00
|
|
|
case NSToolbarSizeModeSmall:
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedWidth = ItemBackViewSmallWidth;
|
2008-12-28 15:16:05 +00:00
|
|
|
layoutedHeight = ItemBackViewSmallHeight;
|
|
|
|
/* 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. */
|
2009-08-04 20:12:35 +00:00
|
|
|
[[_toolbarItem image] setSize: NSMakeSize(24, 24)];
|
2008-12-28 15:16:05 +00:00
|
|
|
font = SmallFont;
|
|
|
|
break;
|
2004-04-13 13:12:53 +00:00
|
|
|
default:
|
2009-08-04 20:12:35 +00:00
|
|
|
NSLog(@"Invalid NSToolbarSizeMode"); // Invalid
|
2004-04-13 13:12:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-30 22:20:21 +00:00
|
|
|
[self 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
|
2009-08-04 20:12:35 +00:00
|
|
|
{
|
|
|
|
NSAttributedString *attrStr;
|
|
|
|
NSDictionary *attr;
|
|
|
|
NSString *label = [_toolbarItem label];
|
|
|
|
|
|
|
|
attr = [NSDictionary dictionaryWithObject: font forKey: NSFontAttributeName];
|
|
|
|
if (label == nil || [label isEqualToString: @""])
|
|
|
|
label = @"Dummy";
|
|
|
|
attrStr = [[NSAttributedString alloc] initWithString: label attributes: attr];
|
|
|
|
labelSize = [attrStr size];
|
|
|
|
DESTROY(attrStr);
|
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
textWidth = labelSize.width + 2 * InsetItemTextX;
|
2005-12-15 16:59:29 +00:00
|
|
|
if ([[_toolbarItem toolbar] displayMode] != NSToolbarDisplayModeIconOnly
|
|
|
|
&& 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];
|
2009-08-04 20:12:35 +00:00
|
|
|
layoutedHeight -= labelSize.height + InsetItemTextY;
|
2008-12-28 15:16:05 +00:00
|
|
|
break;
|
2004-04-13 13:12:53 +00:00
|
|
|
case NSToolbarDisplayModeLabelOnly:
|
|
|
|
[self setImagePosition: NSNoImage];
|
2009-08-04 20:12:35 +00:00
|
|
|
layoutedHeight = labelSize.height + InsetItemTextY * 2;
|
2008-12-28 15:16:05 +00:00
|
|
|
break;
|
2004-04-13 13:12:53 +00:00
|
|
|
default:
|
2008-12-28 15:16:05 +00:00
|
|
|
; // Invalid
|
2004-04-13 13:12:53 +00:00
|
|
|
}
|
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
|
|
|
|
{
|
2009-01-01 22:04:38 +00:00
|
|
|
NSToolbar *toolbar = [_toolbarItem toolbar];
|
2004-12-30 14:02:00 +00:00
|
|
|
|
2009-02-10 21:02:33 +00:00
|
|
|
if (([event modifierFlags] == NSCommandKeyMask
|
|
|
|
&& [toolbar allowsUserCustomization])
|
|
|
|
|| [toolbar customizationPaletteIsRunning] || toolbar == nil)
|
2008-12-28 15:16:05 +00:00
|
|
|
{
|
2008-12-30 22:20:21 +00:00
|
|
|
NSSize viewSize = [self frame].size;
|
|
|
|
NSImage *image = [[NSImage alloc] initWithSize: viewSize];
|
|
|
|
NSCell *cell = [self cell];
|
|
|
|
NSPasteboard *pboard;
|
2011-12-17 17:16:09 +00:00
|
|
|
NSInteger index = NSNotFound;
|
2008-12-28 15:16:05 +00:00
|
|
|
|
2008-12-30 22:20:21 +00:00
|
|
|
// Prepare the drag
|
|
|
|
|
|
|
|
/* We need to keep this view (aka self) to be able to draw the drag
|
|
|
|
image. */
|
2009-08-04 20:12:35 +00:00
|
|
|
RETAIN(self);
|
2008-12-30 22:20:21 +00:00
|
|
|
|
|
|
|
// 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];
|
2009-02-10 21:02:33 +00:00
|
|
|
if (toolbar != nil)
|
2009-08-04 20:12:35 +00:00
|
|
|
{
|
2009-02-10 21:02:33 +00:00
|
|
|
index = [toolbar _indexOfItem: _toolbarItem];
|
|
|
|
}
|
2010-04-13 21:38:31 +00:00
|
|
|
[GSToolbarView setDraggedItemIndex:index];
|
2015-05-26 17:15:16 +00:00
|
|
|
[pboard setString: [NSString stringWithFormat:@"%ld", (long) index]
|
2008-12-30 22:20:21 +00:00
|
|
|
forType: GSMovableToolbarItemPboardType];
|
2008-12-28 15:16:05 +00:00
|
|
|
|
2008-12-30 22:20:21 +00:00
|
|
|
[self dragImage: image
|
2009-02-10 21:02:33 +00:00
|
|
|
at: NSMakePoint(0.0, viewSize.height)
|
2008-12-30 22:20:21 +00:00
|
|
|
offset: NSMakeSize(0.0, 0.0)
|
|
|
|
event: event
|
|
|
|
pasteboard: pboard
|
|
|
|
source: self
|
|
|
|
slideBack: NO];
|
2009-02-10 21:02:33 +00:00
|
|
|
RELEASE(image);
|
2004-09-02 17:40:00 +00:00
|
|
|
}
|
2004-12-30 14:02:00 +00:00
|
|
|
else if ([event modifierFlags] != NSCommandKeyMask)
|
2004-09-02 17:40:00 +00:00
|
|
|
{
|
|
|
|
[super mouseDown: event];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) draggedImage: (NSImage *)dragImage beganAt: (NSPoint)location
|
|
|
|
{
|
2010-04-13 21:38:31 +00:00
|
|
|
//nothing to do
|
2004-05-23 18:22:45 +00:00
|
|
|
}
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
- (void) draggedImage: (NSImage *)dragImage
|
|
|
|
endedAt: (NSPoint)location
|
2008-12-28 15:16:05 +00:00
|
|
|
operation: (NSDragOperation)operation
|
2004-09-02 17:40:00 +00:00
|
|
|
{
|
2010-04-13 21:38:31 +00:00
|
|
|
//nothing to do
|
2004-09-02 17:40:00 +00:00
|
|
|
}
|
|
|
|
|
2010-12-22 16:16:14 +00:00
|
|
|
- (NSDragOperation) draggingSourceOperationMaskForLocal: (BOOL)isLocal
|
2004-09-02 17:40:00 +00:00
|
|
|
{
|
|
|
|
return isLocal ? NSDragOperationGeneric : NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
- (NSToolbarItem *) toolbarItem
|
|
|
|
{
|
|
|
|
return _toolbarItem;
|
|
|
|
}
|
|
|
|
|
2004-09-02 17:40:00 +00:00
|
|
|
/*
|
|
|
|
* End of the code to keep in sync
|
|
|
|
*/
|
|
|
|
|
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])
|
2004-12-30 14:02:00 +00:00
|
|
|
{
|
|
|
|
[[_toolbarItem toolbar]
|
|
|
|
setSelectedItemIdentifier: [_toolbarItem itemIdentifier]];
|
|
|
|
}
|
2004-05-23 18:22:45 +00:00
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
if (action)
|
2004-04-27 21:42:24 +00:00
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
// Send from toolbar item not self
|
|
|
|
return [NSApp sendAction: action
|
2004-12-30 14:02:00 +00:00
|
|
|
to: target
|
2008-12-28 15:16:05 +00:00
|
|
|
from: _toolbarItem];
|
2004-04-27 21:42:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
@end
|
|
|
|
|
2004-08-30 21:33:17 +00:00
|
|
|
@implementation GSToolbarButtonCell
|
|
|
|
|
2006-02-03 16:19:27 +00:00
|
|
|
/* Overriden NSButtonCell method to handle cell type in a basic way which avoids
|
|
|
|
to lose image or empty title on new image position (when this involves a cell
|
|
|
|
type switch) and the need to reset it. That would happen in GSToolbarButton
|
|
|
|
-layout method (on toolbar display mode switch).
|
|
|
|
Note that empty title are used with space or separator toolbar items. */
|
|
|
|
- (void) setImagePosition: (NSCellImagePosition)aPosition
|
|
|
|
{
|
|
|
|
_cell.image_position = aPosition;
|
|
|
|
|
|
|
|
if (_cell.image_position == NSNoImage)
|
|
|
|
{
|
|
|
|
_cell.type = NSTextCellType;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_cell.type = NSImageCellType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
/* Allways return the image, even when no image gets displayed. */
|
|
|
|
- (NSImage*) image
|
|
|
|
{
|
|
|
|
return _cell_image;
|
|
|
|
}
|
|
|
|
|
2008-03-08 11:11:52 +00:00
|
|
|
// Overriden NSButtonCell method to make sure all text is at the same height.
|
2004-08-30 21:33:17 +00:00
|
|
|
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
|
|
|
{
|
2007-09-12 12:54:38 +00:00
|
|
|
BOOL flippedView = [controlView isFlipped];
|
|
|
|
NSCellImagePosition ipos = _cell.image_position;
|
2004-08-30 21:33:17 +00:00
|
|
|
// We ignore alternateAttributedTitle, it is not needed
|
2007-09-12 12:54:38 +00:00
|
|
|
NSSize titleSize = [[self attributedTitle] size];
|
2004-08-30 21:33:17 +00:00
|
|
|
|
2007-09-12 12:54:38 +00:00
|
|
|
if (flippedView == YES)
|
|
|
|
{
|
|
|
|
if (ipos == NSImageAbove)
|
|
|
|
{
|
|
|
|
ipos = NSImageBelow;
|
|
|
|
}
|
|
|
|
else if (ipos == NSImageBelow)
|
|
|
|
{
|
|
|
|
ipos = NSImageAbove;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
/* We store the values we need to customize the drawing into titleRect and
|
|
|
|
imageRect. */
|
2007-09-12 12:54:38 +00:00
|
|
|
switch (ipos)
|
|
|
|
{
|
|
|
|
case NSNoImage:
|
|
|
|
titleRect = cellFrame;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSImageOnly:
|
|
|
|
imageRect = cellFrame;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case NSImageBelow:
|
|
|
|
titleRect.origin.x = cellFrame.origin.x;
|
|
|
|
titleRect.origin.y = NSMaxY(cellFrame) - titleSize.height - InsetItemTextY;
|
|
|
|
titleRect.size.width = cellFrame.size.width;
|
|
|
|
titleRect.size.height = titleSize.height;
|
|
|
|
|
|
|
|
imageRect.origin.x = cellFrame.origin.x;
|
|
|
|
imageRect.origin.y = cellFrame.origin.y;
|
|
|
|
imageRect.size.width = cellFrame.size.width;
|
|
|
|
imageRect.size.height = cellFrame.size.height - titleRect.size.height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSImageAbove:
|
|
|
|
titleRect.origin.x = cellFrame.origin.x;
|
|
|
|
titleRect.origin.y = cellFrame.origin.y + InsetItemTextY;
|
|
|
|
titleRect.size.width = cellFrame.size.width;
|
|
|
|
titleRect.size.height = titleSize.height;
|
|
|
|
|
|
|
|
imageRect.origin.x = cellFrame.origin.x;
|
|
|
|
imageRect.origin.y = cellFrame.origin.y + titleRect.size.height;
|
|
|
|
imageRect.size.width = cellFrame.size.width;
|
|
|
|
imageRect.size.height = cellFrame.size.height - titleRect.size.height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-08-30 21:33:17 +00:00
|
|
|
[super drawInteriorWithFrame: cellFrame inView: controlView];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overriden NSCell method
|
|
|
|
- (void) _drawAttributedText: (NSAttributedString*)aString
|
2008-12-28 15:16:05 +00:00
|
|
|
inFrame: (NSRect)aRect
|
2004-08-30 21:33:17 +00:00
|
|
|
{
|
|
|
|
if (aString == nil)
|
|
|
|
return;
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
/* Important: text should always be vertically centered without considering
|
|
|
|
descender (as if descender did not exist). This is particularly important
|
|
|
|
for single line texts.Please make sure the output remains always
|
|
|
|
correct. */
|
|
|
|
|
|
|
|
[aString drawInRect: titleRect]; // We ignore aRect value
|
2004-08-30 21:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Overriden NSButtonCell method
|
2007-01-23 14:17:02 +00:00
|
|
|
- (void) drawImage: (NSImage *)anImage withFrame: (NSRect)aRect inView: (NSView*)controlView
|
2004-08-30 21:33:17 +00:00
|
|
|
{
|
|
|
|
// We ignore aRect value
|
2007-01-23 14:17:02 +00:00
|
|
|
[super drawImage: anImage withFrame: imageRect inView: controlView];
|
2004-08-30 21:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
2009-08-04 20:12:35 +00:00
|
|
|
// record the fact that the view responds to these
|
|
|
|
// to save time.
|
|
|
|
struct __flags
|
|
|
|
{
|
|
|
|
// gets
|
|
|
|
unsigned int _isEnabled:1;
|
|
|
|
unsigned int _action:1;
|
|
|
|
unsigned int _target:1;
|
|
|
|
unsigned int _image:1;
|
|
|
|
// sets
|
|
|
|
unsigned int _setEnabled:1;
|
|
|
|
unsigned int _setAction:1;
|
|
|
|
unsigned int _setTarget:1;
|
|
|
|
unsigned int _setImage:1;
|
|
|
|
|
|
|
|
// to even out the int.
|
|
|
|
unsigned int RESERVED:24;
|
|
|
|
} _flags;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem;
|
2008-12-30 22:20:21 +00:00
|
|
|
- (void) layout;
|
2009-08-04 20:12:35 +00:00
|
|
|
|
|
|
|
- (NSToolbarItem *) toolbarItem;
|
2009-02-10 21:02:33 +00:00
|
|
|
- (BOOL) isEnabled;
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) setEnabled: (BOOL)enabled;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarBackView
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
- (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-12-30 14:02:00 +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)
|
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
NSView *view;
|
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
// Don't do an ASSIGN here, the toolbar item itself retains us.
|
|
|
|
_toolbarItem = toolbarItem;
|
2009-08-04 20:12:35 +00:00
|
|
|
view = [toolbarItem view];
|
|
|
|
|
|
|
|
// gets
|
|
|
|
_flags._isEnabled = [view respondsToSelector: @selector(isEnabled)];
|
|
|
|
_flags._action = [view respondsToSelector: @selector(action)];
|
|
|
|
_flags._target = [view respondsToSelector: @selector(target)];
|
|
|
|
_flags._image = [view respondsToSelector: @selector(image)];
|
|
|
|
// sets
|
|
|
|
_flags._setEnabled = [view respondsToSelector: @selector(setEnabled:)];
|
|
|
|
_flags._setAction = [view respondsToSelector: @selector(setAction:)];
|
|
|
|
_flags._setTarget = [view respondsToSelector: @selector(setTarget:)];
|
|
|
|
_flags._setImage = [view respondsToSelector: @selector(setImage:)];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2004-08-30 21:33:17 +00:00
|
|
|
- (void) drawRect: (NSRect)rect
|
|
|
|
{
|
2015-09-13 21:36:40 +00:00
|
|
|
if (_showLabel && NSIntersectsRect(rect, [self bounds]))
|
2004-04-13 13:12:53 +00:00
|
|
|
{
|
2004-08-30 21:33:17 +00:00
|
|
|
NSAttributedString *attrString;
|
|
|
|
NSDictionary *attr;
|
|
|
|
NSColor *color;
|
2006-07-04 21:31:49 +00:00
|
|
|
NSMutableParagraphStyle *pStyle;
|
2004-08-30 21:33:17 +00:00
|
|
|
NSRect titleRect;
|
|
|
|
NSRect viewBounds = [self bounds];
|
|
|
|
|
|
|
|
if (_enabled)
|
|
|
|
{
|
|
|
|
color = [NSColor blackColor];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color = [NSColor disabledControlTextColor];
|
|
|
|
}
|
2008-12-28 15:16:05 +00:00
|
|
|
|
2006-07-04 21:31:49 +00:00
|
|
|
pStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
2004-08-30 21:33:17 +00:00
|
|
|
[pStyle setAlignment: NSCenterTextAlignment];
|
|
|
|
|
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-12-30 14:02:00 +00:00
|
|
|
NSFontAttributeName, color, NSForegroundColorAttributeName, pStyle,
|
|
|
|
NSParagraphStyleAttributeName, nil];
|
2006-07-04 21:31:49 +00:00
|
|
|
RELEASE(pStyle);
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
attrString = [[NSAttributedString alloc]
|
|
|
|
initWithString: [_toolbarItem label] attributes: attr];
|
2004-08-30 21:33:17 +00:00
|
|
|
|
|
|
|
titleRect.origin.x = viewBounds.origin.x;
|
|
|
|
titleRect.origin.y = viewBounds.origin.y + InsetItemTextY;
|
|
|
|
titleRect.size.width = viewBounds.size.width;
|
|
|
|
titleRect.size.height = [attrString size].height;
|
|
|
|
[attrString drawInRect: titleRect];
|
|
|
|
|
2004-07-24 20:51:39 +00:00
|
|
|
DESTROY(attrString);
|
2004-08-30 21:33:17 +00:00
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
- (NSView *) hitTest: (NSPoint)point
|
|
|
|
{
|
|
|
|
if (_super_view && [_super_view mouse: point inRect: _frame])
|
|
|
|
{
|
|
|
|
NSEvent *event = [NSApp currentEvent];
|
|
|
|
NSToolbar *toolbar = [_toolbarItem toolbar];
|
|
|
|
|
|
|
|
if (([event type] == NSLeftMouseDown)
|
|
|
|
&& (([event modifierFlags] == NSCommandKeyMask
|
|
|
|
&& [toolbar allowsUserCustomization])
|
|
|
|
|| [toolbar customizationPaletteIsRunning] || toolbar == nil))
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [super hitTest: point];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The code below should be kept in sync with GSToolbarButton methods which
|
|
|
|
* have identical names.
|
|
|
|
*/
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) layout
|
|
|
|
{
|
2004-04-13 13:12:53 +00:00
|
|
|
NSView *view = [_toolbarItem view];
|
|
|
|
float textWidth, layoutedWidth = -1, layoutedHeight = -1;
|
2009-08-04 20:12:35 +00:00
|
|
|
NSFont *font;
|
2004-05-23 18:22:45 +00:00
|
|
|
unsigned int borderMask = [[[_toolbarItem toolbar] _toolbarView] borderMask];
|
2009-08-04 20:12:35 +00:00
|
|
|
NSSize labelSize = NSZeroSize;
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2009-08-04 20:12:35 +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];
|
2010-04-13 21:38:31 +00:00
|
|
|
|
2010-05-12 23:06:02 +00:00
|
|
|
if ([view respondsToSelector: @selector(sizeToFit)])
|
2010-04-13 21:38:31 +00:00
|
|
|
{
|
|
|
|
NSSize newSize, minSize = [_toolbarItem minSize];
|
2010-05-12 23:06:02 +00:00
|
|
|
|
|
|
|
[(id)view sizeToFit];
|
|
|
|
newSize = [view frame].size;
|
2010-05-21 15:01:45 +00:00
|
|
|
if (minSize.width > 0 || newSize.height < minSize.height)
|
2010-05-12 23:06:02 +00:00
|
|
|
{
|
2010-05-21 15:01:45 +00:00
|
|
|
if (minSize.width > 0)
|
|
|
|
newSize.width = minSize.width;
|
2010-05-12 23:06:02 +00:00
|
|
|
newSize.height = MAX(newSize.height, minSize.height);
|
|
|
|
[view setFrameSize: newSize];
|
|
|
|
}
|
2010-04-13 21:38:31 +00:00
|
|
|
}
|
2010-05-12 23:06:02 +00:00
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
// 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:
|
2008-12-28 15:16:05 +00:00
|
|
|
layoutedWidth = ItemBackViewDefaultWidth;
|
|
|
|
layoutedHeight = ItemBackViewDefaultHeight;
|
|
|
|
if ([view frame].size.height > 32)
|
|
|
|
[view removeFromSuperview];
|
|
|
|
break;
|
2004-04-13 13:12:53 +00:00
|
|
|
case NSToolbarSizeModeRegular:
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedWidth = ItemBackViewRegularWidth;
|
|
|
|
layoutedHeight = ItemBackViewRegularHeight;
|
2008-12-28 15:16:05 +00:00
|
|
|
if ([view frame].size.height > 32)
|
|
|
|
[view removeFromSuperview];
|
|
|
|
break;
|
2004-04-13 13:12:53 +00:00
|
|
|
case NSToolbarSizeModeSmall:
|
2004-07-27 15:15:29 +00:00
|
|
|
layoutedWidth = ItemBackViewSmallWidth;
|
2008-12-28 15:16:05 +00:00
|
|
|
layoutedHeight = ItemBackViewSmallHeight;
|
2009-08-04 20:12:35 +00:00
|
|
|
font = SmallFont;
|
2008-12-28 15:16:05 +00:00
|
|
|
if ([view frame].size.height > 24)
|
|
|
|
[view removeFromSuperview];
|
|
|
|
break;
|
2004-04-13 13:12:53 +00:00
|
|
|
default:
|
2008-12-28 15:16:05 +00:00
|
|
|
NSLog(@"Invalid NSToolbarSizeMode"); // Invalid
|
2004-04-13 13:12:53 +00:00
|
|
|
}
|
2004-05-23 18:22:45 +00:00
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
_font = 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-02-25 03:27:23 +00:00
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
// Adjust the layout in accordance with the label
|
2009-08-04 20:12:35 +00:00
|
|
|
{
|
|
|
|
NSAttributedString *attrStr;
|
|
|
|
NSDictionary *attr;
|
|
|
|
NSString *label = [_toolbarItem label];
|
|
|
|
|
|
|
|
attr = [NSDictionary dictionaryWithObject: font forKey: NSFontAttributeName];
|
|
|
|
if (label == nil || [label isEqualToString: @""])
|
|
|
|
label = @"Dummy";
|
|
|
|
attrStr = [[NSAttributedString alloc] initWithString: label attributes: attr];
|
|
|
|
labelSize = [attrStr size];
|
|
|
|
DESTROY(attrStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
textWidth = labelSize.width + 2 * InsetItemTextX;
|
2004-04-13 13:12:53 +00:00
|
|
|
if (textWidth > layoutedWidth)
|
|
|
|
layoutedWidth = textWidth;
|
|
|
|
|
|
|
|
_enabled = YES;
|
2004-12-30 14:02:00 +00:00
|
|
|
/* This boolean variable is used to known when it's needed to draw the label
|
|
|
|
in the -drawRect: method. */
|
2009-08-04 20:12:35 +00:00
|
|
|
_showLabel = YES;
|
2004-04-13 13:12:53 +00:00
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
// Adjust the layout in accordance with NSToolbarDisplayMode
|
2004-04-13 13:12:53 +00:00
|
|
|
switch ([[_toolbarItem toolbar] displayMode])
|
|
|
|
{
|
|
|
|
case NSToolbarDisplayModeDefault:
|
|
|
|
break; // Nothing to do
|
|
|
|
case NSToolbarDisplayModeIconAndLabel:
|
|
|
|
break; // Nothing to do
|
|
|
|
case NSToolbarDisplayModeIconOnly:
|
|
|
|
_showLabel = NO;
|
2009-08-04 20:12:35 +00:00
|
|
|
layoutedHeight -= labelSize.height + InsetItemTextY;
|
2008-12-28 15:16:05 +00:00
|
|
|
break;
|
2004-04-13 13:12:53 +00:00
|
|
|
case NSToolbarDisplayModeLabelOnly:
|
|
|
|
_enabled = NO;
|
2009-08-04 20:12:35 +00:00
|
|
|
layoutedHeight = labelSize.height + InsetItemTextY * 2;
|
2008-12-28 15:16:05 +00:00
|
|
|
if ([view superview] != nil)
|
|
|
|
[view removeFromSuperview];
|
|
|
|
break;
|
2004-04-13 13:12:53 +00:00
|
|
|
default:
|
2008-12-28 15:16:05 +00:00
|
|
|
; // Invalid
|
2004-04-13 13:12:53 +00:00
|
|
|
}
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
/* If the view is visible...
|
|
|
|
Adjust the layout in accordance with the view width in the case it is
|
|
|
|
needed. */
|
2004-04-13 13:12:53 +00:00
|
|
|
if ([view superview] != nil)
|
|
|
|
{
|
2004-12-30 14:02:00 +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)];
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
/* If the view is visible...
|
|
|
|
Adjust the view position in accordance with the new layout. */
|
2004-04-13 13:12:53 +00:00
|
|
|
if ([view superview] != nil)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
float insetItemViewY = ([self frame].size.height
|
|
|
|
- [view frame].size.height) / 2;
|
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
if (_showLabel)
|
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
insetItemViewY += (labelSize.height + InsetItemTextY) / 2;
|
2008-12-28 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
[view setFrameOrigin: NSMakePoint((layoutedWidth
|
|
|
|
- [view frame].size.width) / 2, insetItemViewY)];
|
2009-08-04 20:12:35 +00:00
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2004-09-02 17:40:00 +00:00
|
|
|
- (void) mouseDown: (NSEvent *)event
|
|
|
|
{
|
2009-01-01 22:04:38 +00:00
|
|
|
NSToolbar *toolbar = [_toolbarItem toolbar];
|
2004-12-30 14:02:00 +00:00
|
|
|
|
2009-02-10 21:02:33 +00:00
|
|
|
if (([event modifierFlags] == NSCommandKeyMask
|
|
|
|
&& [toolbar allowsUserCustomization])
|
|
|
|
|| [toolbar customizationPaletteIsRunning] || toolbar == nil)
|
2008-12-28 15:16:05 +00:00
|
|
|
{
|
2009-02-10 21:02:33 +00:00
|
|
|
NSSize viewSize = [self frame].size;
|
|
|
|
NSImage *image = [[NSImage alloc] initWithSize: viewSize];
|
|
|
|
NSPasteboard *pboard;
|
2011-12-17 17:16:09 +00:00
|
|
|
NSInteger index = NSNotFound;
|
2009-02-10 21:02:33 +00:00
|
|
|
|
|
|
|
// Prepare the drag
|
|
|
|
|
|
|
|
/* We need to keep this view (aka self) to be able to draw the drag
|
|
|
|
image. */
|
2009-08-04 20:12:35 +00:00
|
|
|
RETAIN(self);
|
2009-02-10 21:02:33 +00:00
|
|
|
|
|
|
|
// Draw the drag content in an image
|
|
|
|
/* The code below is only partially supported by GNUstep, then NSImage
|
|
|
|
needs to be improved. */
|
|
|
|
[image lockFocus];
|
|
|
|
[self drawRect:
|
|
|
|
NSMakeRect(0, 0, viewSize.width, viewSize.height)];
|
|
|
|
[image unlockFocus];
|
|
|
|
|
|
|
|
pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
|
|
|
|
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
|
|
|
|
owner: nil];
|
|
|
|
if (toolbar != nil)
|
2009-08-04 20:12:35 +00:00
|
|
|
{
|
2008-12-28 15:16:05 +00:00
|
|
|
index = [toolbar _indexOfItem: _toolbarItem];
|
2009-02-10 21:02:33 +00:00
|
|
|
}
|
2010-04-13 21:38:31 +00:00
|
|
|
[GSToolbarView setDraggedItemIndex:index];
|
2015-05-26 17:15:16 +00:00
|
|
|
[pboard setString: [NSString stringWithFormat:@"%ld", (long) index]
|
2009-02-10 21:02:33 +00:00
|
|
|
forType: GSMovableToolbarItemPboardType];
|
|
|
|
|
|
|
|
[self dragImage: image
|
2009-08-04 20:12:35 +00:00
|
|
|
//at: NSMakePoint(0.0, viewSize.height)
|
|
|
|
at: NSMakePoint(0.0, 0.0)
|
2009-02-10 21:02:33 +00:00
|
|
|
offset: NSMakeSize(0.0, 0.0)
|
|
|
|
event: event
|
|
|
|
pasteboard: pboard
|
|
|
|
source: self
|
|
|
|
slideBack: NO];
|
|
|
|
RELEASE(image);
|
2004-09-02 17:40:00 +00:00
|
|
|
}
|
2004-12-30 14:02:00 +00:00
|
|
|
else if ([event modifierFlags] != NSCommandKeyMask)
|
2004-09-02 17:40:00 +00:00
|
|
|
{
|
|
|
|
[super mouseDown: event];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) draggedImage: (NSImage *)dragImage beganAt: (NSPoint)location
|
|
|
|
{
|
2010-04-13 21:38:31 +00:00
|
|
|
//nothing to do
|
2004-09-02 17:40:00 +00:00
|
|
|
}
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
- (void) draggedImage: (NSImage *)dragImage
|
|
|
|
endedAt: (NSPoint)location
|
2008-12-28 15:16:05 +00:00
|
|
|
operation: (NSDragOperation)operation
|
2004-09-02 17:40:00 +00:00
|
|
|
{
|
2010-04-13 21:38:31 +00:00
|
|
|
//nothing to do
|
2004-09-02 17:40:00 +00:00
|
|
|
}
|
|
|
|
|
2010-12-22 16:16:14 +00:00
|
|
|
- (NSDragOperation) draggingSourceOperationMaskForLocal: (BOOL)isLocal
|
2004-09-02 17:40:00 +00:00
|
|
|
{
|
|
|
|
return isLocal ? NSDragOperationGeneric : NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
- (NSToolbarItem *) toolbarItem
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
return _toolbarItem;
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
/*
|
|
|
|
* End of the code to keep in sync
|
|
|
|
*/
|
|
|
|
|
2009-02-10 21:02:33 +00:00
|
|
|
- (BOOL) isEnabled
|
2004-07-07 23:21:10 +00:00
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
if (_flags._isEnabled)
|
2009-02-10 21:02:33 +00:00
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
id view = [_toolbarItem view];
|
|
|
|
|
2009-02-10 21:02:33 +00:00
|
|
|
return [view isEnabled];
|
|
|
|
}
|
2009-08-04 20:12:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return _enabled;
|
|
|
|
}
|
2004-07-07 23:21:10 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) setEnabled: (BOOL)enabled
|
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
if (_flags._setEnabled)
|
2009-02-10 21:02:33 +00:00
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
id view = [_toolbarItem view];
|
|
|
|
|
2009-02-10 21:02:33 +00:00
|
|
|
[view setEnabled: enabled];
|
|
|
|
}
|
2009-08-04 20:12:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_enabled = enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSImage *) image
|
|
|
|
{
|
|
|
|
if (_flags._image)
|
|
|
|
{
|
|
|
|
id view = [_toolbarItem view];
|
|
|
|
|
|
|
|
return [view image];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setImage: (NSImage *)image
|
|
|
|
{
|
|
|
|
if (_flags._setImage)
|
|
|
|
{
|
|
|
|
id view = [_toolbarItem view];
|
|
|
|
|
|
|
|
[view setImage: image];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAction: (SEL)action
|
|
|
|
{
|
|
|
|
if (_flags._setAction)
|
|
|
|
{
|
|
|
|
id view = [_toolbarItem view];
|
|
|
|
|
|
|
|
[view setAction: action];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SEL) action
|
|
|
|
{
|
|
|
|
if (_flags._action)
|
|
|
|
{
|
|
|
|
id view = [_toolbarItem view];
|
|
|
|
|
|
|
|
return [view action];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTarget: (id)target
|
|
|
|
{
|
|
|
|
if (_flags._setTarget)
|
|
|
|
{
|
|
|
|
id view = [_toolbarItem view];
|
|
|
|
|
|
|
|
[view setTarget: target];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) target
|
|
|
|
{
|
|
|
|
if (_flags._target)
|
|
|
|
{
|
|
|
|
id view = [_toolbarItem view];
|
|
|
|
|
|
|
|
return [view target];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Standard toolbar items.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// ---- NSToolbarSeparatorItemIdentifier
|
2011-11-18 20:15:53 +00:00
|
|
|
@interface NSToolbarSeparatorItem : NSToolbarItem
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2011-11-18 20:15:53 +00:00
|
|
|
@implementation NSToolbarSeparatorItem
|
2004-02-25 03:27:23 +00:00
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
2008-12-30 22:20:21 +00:00
|
|
|
if (!self)
|
|
|
|
return nil;
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
[(NSButton *)[self _backView] setImagePosition: NSImageOnly];
|
2009-02-10 21:02:33 +00:00
|
|
|
[(NSButton *)[self _backView] setImage:
|
|
|
|
[NSImage imageNamed: @"common_ToolbarSeparatorItem"]];
|
2004-12-30 14:02:00 +00:00
|
|
|
/* We bypass the toolbar item accessor to set the image in order to have it
|
|
|
|
(48 * 48) not resized. */
|
2010-04-13 21:38:31 +00:00
|
|
|
[self setPaletteLabel: _(@"Separator")];
|
|
|
|
|
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];
|
2009-02-10 21:02:33 +00:00
|
|
|
if ([self toolbar] != nil)
|
|
|
|
[backView setFrameSize: NSMakeSize(30, [backView frame].size.height)];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
2010-04-13 21:38:31 +00:00
|
|
|
|
|
|
|
- (BOOL) allowsDuplicatesInToolbar
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
// ---- NSToolbarSpaceItemIdentifier
|
2011-11-18 20:15:53 +00:00
|
|
|
@interface NSToolbarSpaceItem : NSToolbarItem
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2011-11-18 20:15:53 +00:00
|
|
|
@implementation NSToolbarSpaceItem
|
2004-02-25 03:27:23 +00:00
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
2009-02-10 21:02:33 +00:00
|
|
|
if (!self)
|
|
|
|
return nil;
|
|
|
|
[self setPaletteLabel: _(@"Space")];
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
// Override the default implementation in order to do nothing
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSMenuItem *) _defaultMenuFormRepresentation
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
return nil;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
2010-04-13 21:38:31 +00:00
|
|
|
|
|
|
|
- (BOOL) allowsDuplicatesInToolbar
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
// ---- NSToolbarFlexibleSpaceItemIdentifier
|
2011-11-18 20:15:53 +00:00
|
|
|
@interface NSToolbarFlexibleSpaceItem : NSToolbarItem
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2011-11-18 20:15:53 +00:00
|
|
|
@implementation NSToolbarFlexibleSpaceItem
|
2004-02-25 03:27:23 +00:00
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
2009-02-10 21:02:33 +00:00
|
|
|
if (!self)
|
|
|
|
return nil;
|
|
|
|
[self setPaletteLabel: _(@"Flexible Space")];
|
2004-02-25 03:27:23 +00:00
|
|
|
[self _layout];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
// Override the default implementation in order to do nothing
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSMenuItem *) _defaultMenuFormRepresentation
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
return nil;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
// Override the default implementation in order to reset the _backView to a zero width
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) _layout
|
|
|
|
{
|
|
|
|
NSView *backView = [self _backView];
|
2009-08-04 20:12:35 +00:00
|
|
|
NSSize size;
|
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
[(id)backView layout];
|
2009-08-04 20:12:35 +00:00
|
|
|
size = [backView frame].size;
|
2004-05-23 18:22:45 +00:00
|
|
|
|
2009-02-10 21:02:33 +00:00
|
|
|
/* If the item is not part of a toolbar, this usually means it is used by
|
|
|
|
customization palette, we shouldn't resize it in this case. */
|
|
|
|
if ([self toolbar] != nil)
|
2009-08-04 20:12:35 +00:00
|
|
|
[backView setFrameSize: NSMakeSize(0, size.height)];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
[self setMinSize: NSMakeSize(0, size.height)];
|
|
|
|
[self setMaxSize: NSMakeSize(10000, size.height)];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
2008-12-30 22:20:21 +00:00
|
|
|
|
|
|
|
- (BOOL) _isFlexibleSpace
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2010-04-13 21:38:31 +00:00
|
|
|
- (BOOL) allowsDuplicatesInToolbar
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
// ---- NSToolbarShowColorsItemIdentifier
|
|
|
|
@interface GSToolbarShowColorsItem : NSToolbarItem
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarShowColorsItem
|
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
2009-02-10 21:02:33 +00:00
|
|
|
if (!self)
|
|
|
|
return nil;
|
2008-12-30 22:20:21 +00:00
|
|
|
[self setImage: [NSImage imageNamed: @"common_ToolbarShowColorsItem"]];
|
|
|
|
[self setLabel: _(@"Colors")];
|
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
|
|
|
|
{
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
2009-02-10 21:02:33 +00:00
|
|
|
if (!self)
|
|
|
|
return nil;
|
2008-12-30 22:20:21 +00:00
|
|
|
[self setImage: [NSImage imageNamed: @"common_ToolbarShowFontsItem"]];
|
|
|
|
[self setLabel: _(@"Fonts")];
|
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
|
|
|
|
{
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
2009-02-10 21:02:33 +00:00
|
|
|
if (!self)
|
|
|
|
return nil;
|
2008-12-30 22:20:21 +00:00
|
|
|
[self setImage: [NSImage imageNamed: @"common_ToolbarCustomizeToolbarItem"]];
|
|
|
|
[self setLabel: _(@"Customize")];
|
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..
|
2009-02-10 21:02:33 +00:00
|
|
|
[self setAction: @selector(runToolbarCustomizationPalette:)];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// ---- NSToolbarPrintItemIdentifier
|
|
|
|
@interface GSToolbarPrintItem : NSToolbarItem
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSToolbarPrintItem
|
|
|
|
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
|
|
|
{
|
|
|
|
self = [super initWithItemIdentifier: itemIdentifier];
|
2009-02-10 21:02:33 +00:00
|
|
|
if (!self)
|
|
|
|
return nil;
|
2008-12-30 22:20:21 +00:00
|
|
|
[self setImage: [NSImage imageNamed: @"common_Printer"]];
|
|
|
|
[self setLabel: _(@"Print...")];
|
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..
|
2008-12-30 22:20:21 +00:00
|
|
|
[self setAction: @selector(printDocument:)];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2002-06-30 05:14:21 +00:00
|
|
|
|
|
|
|
@implementation NSToolbarItem
|
2008-12-30 22:20:21 +00:00
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
+ (void) initialize
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
// This used to be size 11.
|
|
|
|
NormalFont = RETAIN([NSFont systemFontOfSize: [NSFont systemFontSize]]);
|
2004-07-07 23:21:10 +00:00
|
|
|
// [NSFont smallSystemFontSize] or better should be NSControlContentFontSize
|
2009-08-04 20:12:35 +00:00
|
|
|
SmallFont = RETAIN([NSFont systemFontOfSize: [NSFont smallSystemFontSize]]);
|
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
|
|
|
{
|
2008-12-30 22:20:21 +00:00
|
|
|
// GNUstep predefined toolbar items
|
|
|
|
if ([itemIdentifier isEqualToString: NSToolbarSeparatorItemIdentifier]
|
2011-11-18 20:15:53 +00:00
|
|
|
&& [self isKindOfClass: [NSToolbarSeparatorItem class]] == NO)
|
2008-12-30 22:20:21 +00:00
|
|
|
{
|
|
|
|
RELEASE(self);
|
2011-11-18 20:15:53 +00:00
|
|
|
return [[NSToolbarSeparatorItem alloc]
|
2008-12-30 22:20:21 +00:00
|
|
|
initWithItemIdentifier: itemIdentifier];
|
|
|
|
}
|
|
|
|
else if ([itemIdentifier isEqualToString: NSToolbarSpaceItemIdentifier]
|
2011-11-18 20:15:53 +00:00
|
|
|
&& [self isKindOfClass: [NSToolbarSpaceItem class]] == NO)
|
2008-12-30 22:20:21 +00:00
|
|
|
{
|
|
|
|
RELEASE(self);
|
2011-11-18 20:15:53 +00:00
|
|
|
return [[NSToolbarSpaceItem alloc]
|
2008-12-30 22:20:21 +00:00
|
|
|
initWithItemIdentifier: itemIdentifier];
|
|
|
|
}
|
|
|
|
else if ([itemIdentifier
|
|
|
|
isEqualToString: NSToolbarFlexibleSpaceItemIdentifier]
|
2011-11-18 20:15:53 +00:00
|
|
|
&& [self isKindOfClass: [NSToolbarFlexibleSpaceItem class]] == NO)
|
2008-12-30 22:20:21 +00:00
|
|
|
{
|
|
|
|
RELEASE(self);
|
2011-11-18 20:15:53 +00:00
|
|
|
return [[NSToolbarFlexibleSpaceItem alloc]
|
2008-12-30 22:20:21 +00:00
|
|
|
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)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2008-12-30 22:20:21 +00:00
|
|
|
// Normal toolbar items
|
2004-02-25 03:27:23 +00:00
|
|
|
ASSIGN(_itemIdentifier, itemIdentifier);
|
2008-12-30 22:20:21 +00:00
|
|
|
[self setAutovalidates: YES];
|
|
|
|
|
|
|
|
// Set the backview to an GSToolbarButton, will get reset to a
|
|
|
|
// GSToolbarBackView when setView: gets called.
|
2009-08-04 20:12:35 +00:00
|
|
|
[self setView: nil];
|
2008-12-30 22:20:21 +00:00
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2008-12-30 22:20:21 +00:00
|
|
|
TEST_RELEASE(_view);
|
2004-05-23 18:22:45 +00:00
|
|
|
RELEASE(_backView);
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2004-07-07 23:21:10 +00:00
|
|
|
- (BOOL) allowsDuplicatesInToolbar
|
|
|
|
{
|
2008-12-30 22:20:21 +00:00
|
|
|
return NO;
|
2004-07-07 23:21:10 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (BOOL) isEnabled
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
return [(GSToolbarButton*)_backView isEnabled];
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
- (NSImage *) image
|
2004-07-07 23:21:10 +00:00
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
// return [(GSToolbarButton*)_backView image];
|
2008-12-30 22:20:21 +00:00
|
|
|
return _image;
|
2004-07-07 23:21:10 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-12-30 22:20:21 +00:00
|
|
|
// FIXME: I think this is not needed
|
|
|
|
if ([[self toolbar] displayMode] == NSToolbarDisplayModeLabelOnly)
|
2004-05-18 19:35:58 +00:00
|
|
|
{
|
2008-12-30 22:20:21 +00:00
|
|
|
NSMenuItem *menuItem = [self menuFormRepresentation];
|
|
|
|
|
|
|
|
if (menuItem != nil)
|
|
|
|
return [menuItem title];
|
2004-05-18 19:35:58 +00:00
|
|
|
}
|
2008-12-30 22:20:21 +00:00
|
|
|
|
2011-07-21 06:31:34 +00:00
|
|
|
if (nil != _label)
|
|
|
|
{
|
|
|
|
return _label;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return @"";
|
|
|
|
}
|
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
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
[(GSToolbarButton *)_backView setAction: action];
|
2008-12-28 15:16:05 +00:00
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
[self setEnabled: (action != NULL)];
|
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
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
[(GSToolbarButton*)_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
|
|
|
{
|
2008-12-30 22:20:21 +00:00
|
|
|
ASSIGN(_image, image);
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2008-12-30 22:20:21 +00:00
|
|
|
[_image setScalesWhenResized: YES];
|
|
|
|
//[_image setSize: NSMakeSize(32, 32)];
|
|
|
|
|
2014-04-02 20:55:19 +00:00
|
|
|
// Do not set the image on the button if we are in "LabelOnly"
|
|
|
|
// mode. If the toolbar's displayMode changes later, we'll
|
|
|
|
// put the image on the button in the layout method.
|
|
|
|
if ([[self toolbar] displayMode] != NSToolbarDisplayModeLabelOnly)
|
|
|
|
{
|
|
|
|
[(GSToolbarButton*)_backView setImage: image];
|
|
|
|
}
|
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
|
|
|
|
2009-08-04 20:12:35 +00:00
|
|
|
if (!_view)
|
2008-12-30 22:20:21 +00:00
|
|
|
[(GSToolbarButton *)_backView setTitle: _label];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-12-30 22:20:21 +00:00
|
|
|
- (void) setTag: (NSInteger)tag
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2008-12-30 22:20:21 +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
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
[(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);
|
2014-12-02 22:34:07 +00:00
|
|
|
if (_view)
|
|
|
|
{
|
|
|
|
[_view setToolTip: _toolTip];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[_backView setToolTip: _toolTip];
|
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (void) setView: (NSView *)view
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
if ((_view == view) && (_backView != nil))
|
2008-12-30 22:20:21 +00:00
|
|
|
return;
|
|
|
|
|
2002-06-30 05:14:21 +00:00
|
|
|
ASSIGN(_view, view);
|
2008-12-30 22:20:21 +00:00
|
|
|
|
|
|
|
if (view)
|
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
NSSize size;
|
|
|
|
|
|
|
|
size = [view frame].size;
|
2010-05-17 20:19:00 +00:00
|
|
|
if (NSEqualSizes(NSZeroSize, _minSize))
|
|
|
|
[self setMinSize: size];
|
|
|
|
if (NSEqualSizes(NSZeroSize, _maxSize))
|
|
|
|
[self setMaxSize: size];
|
2009-08-04 20:12:35 +00:00
|
|
|
|
2008-12-30 22:20:21 +00:00
|
|
|
[_view setToolTip: _toolTip];
|
|
|
|
|
|
|
|
RELEASE(_backView);
|
|
|
|
_backView = [[GSToolbarBackView alloc] initWithToolbarItem: self];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RELEASE(_backView);
|
|
|
|
_backView = [[GSToolbarButton alloc] initWithToolbarItem: self];
|
2014-12-02 22:34:07 +00:00
|
|
|
[_backView setToolTip: _toolTip];
|
2008-12-30 22:20:21 +00:00
|
|
|
}
|
2002-06-30 05:14:21 +00:00
|
|
|
}
|
|
|
|
|
2008-12-30 22:20:21 +00:00
|
|
|
- (NSInteger) tag
|
2002-06-30 05:14:21 +00:00
|
|
|
{
|
2008-12-30 22:20:21 +00:00
|
|
|
return _tag;
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-01 22:04:38 +00:00
|
|
|
- (NSToolbar *) 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
|
|
|
{
|
2009-01-18 15:11:37 +00:00
|
|
|
BOOL enabled = YES;
|
|
|
|
id target;
|
2008-12-30 22:20:21 +00:00
|
|
|
|
2009-01-18 15:11:37 +00:00
|
|
|
/* No validation for custom views */
|
2008-12-30 22:20:21 +00:00
|
|
|
if (_view)
|
|
|
|
return;
|
|
|
|
|
2009-01-18 15:11:37 +00:00
|
|
|
target = [NSApp targetForAction: [self action] to: [self target] from: self];
|
|
|
|
if (target == nil || ![target respondsToSelector: [self action]])
|
2004-05-18 19:35:58 +00:00
|
|
|
{
|
2009-01-18 15:11:37 +00:00
|
|
|
enabled = NO;
|
2004-05-18 19:35:58 +00:00
|
|
|
}
|
2009-01-18 15:11:37 +00:00
|
|
|
else if ([target respondsToSelector: @selector(validateToolbarItem:)])
|
2004-05-18 19:35:58 +00:00
|
|
|
{
|
2009-01-18 15:11:37 +00:00
|
|
|
enabled = [target validateToolbarItem: self];
|
|
|
|
}
|
|
|
|
else if ([target respondsToSelector: @selector(validateUserInterfaceItem:)])
|
|
|
|
{
|
|
|
|
enabled = [target validateUserInterfaceItem: self];
|
|
|
|
}
|
|
|
|
[self setEnabled: enabled];
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-10 20:46:39 +00:00
|
|
|
//
|
|
|
|
// This method invokes using the toolbar item as the sender.
|
|
|
|
// When invoking from the menu, it shouldn't send the menuitem as the
|
|
|
|
// sender since some applications check this and try to get additional
|
2009-01-18 15:11:37 +00:00
|
|
|
// information about the toolbar item which this is coming from. Since
|
|
|
|
// we implement the menu's action, we must also validate it.
|
2009-01-10 20:46:39 +00:00
|
|
|
//
|
|
|
|
- (void) _sendAction: (id)sender
|
|
|
|
{
|
|
|
|
[NSApp sendAction: [self action]
|
|
|
|
to: [self target]
|
|
|
|
from: self];
|
|
|
|
}
|
|
|
|
|
2009-01-18 15:11:37 +00:00
|
|
|
- (BOOL) validateMenuItem: (NSMenuItem *)menuItem
|
|
|
|
{
|
|
|
|
return [self isEnabled];
|
|
|
|
}
|
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
- (NSMenuItem *) _defaultMenuFormRepresentation
|
|
|
|
{
|
|
|
|
NSMenuItem *menuItem;
|
|
|
|
|
|
|
|
menuItem = [[NSMenuItem alloc] initWithTitle: [self label]
|
2009-01-10 20:46:39 +00:00
|
|
|
action: @selector(_sendAction:)
|
2004-05-18 19:35:58 +00:00
|
|
|
keyEquivalent: @""];
|
2009-01-10 20:46:39 +00:00
|
|
|
[menuItem setTarget: self];
|
2004-05-18 19:35:58 +00:00
|
|
|
AUTORELEASE(menuItem);
|
|
|
|
|
|
|
|
return menuItem;
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) _layout
|
|
|
|
{
|
2014-04-02 20:55:19 +00:00
|
|
|
// Reset to image on the backview: We may have toggled
|
|
|
|
// from one NSToolbarDisplayMode to another, and it is
|
|
|
|
// possible setImage: would have been called on the
|
|
|
|
// NSToolbarItem while we were in NSToolbarDisplayModeLabelOnly
|
|
|
|
if ([[self toolbar] displayMode] != NSToolbarDisplayModeLabelOnly)
|
|
|
|
{
|
|
|
|
[(GSToolbarButton*)_backView setImage: _image];
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
[(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
|
|
|
{
|
2010-05-12 23:06:02 +00:00
|
|
|
return NO;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
- (BOOL) _selectable
|
|
|
|
{
|
|
|
|
return _selectable;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) _selected
|
|
|
|
{
|
|
|
|
return [(GSToolbarButton *)_backView state];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setSelected: (BOOL)selected
|
|
|
|
{
|
2008-12-30 22:20:21 +00:00
|
|
|
if (_selectable)
|
2004-05-23 18:22:45 +00:00
|
|
|
{
|
2008-12-30 22:20:21 +00:00
|
|
|
if ([self _selected] != selected)
|
|
|
|
[(GSToolbarButton *)_backView setState: selected];
|
2004-05-23 18:22:45 +00:00
|
|
|
}
|
2008-12-30 22:20:21 +00:00
|
|
|
else
|
2004-05-23 18:22:45 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-01 22:04:38 +00:00
|
|
|
- (void) _setToolbar: (NSToolbar *)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
|
|
|
}
|
|
|
|
|
2008-12-30 22:20:21 +00:00
|
|
|
- (BOOL) autovalidates
|
|
|
|
{
|
|
|
|
return _autovalidates;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAutovalidates: (BOOL)autovalidates
|
|
|
|
{
|
|
|
|
_autovalidates = autovalidates;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger) visibilityPriority
|
|
|
|
{
|
|
|
|
return _visibilityPriority;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setVisibilityPriority: (NSInteger)visibilityPriority
|
|
|
|
{
|
|
|
|
_visibilityPriority = visibilityPriority;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
return [(GSToolbarButton *)_backView action];
|
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
|
|
|
{
|
2009-08-04 20:12:35 +00:00
|
|
|
return [(GSToolbarButton *)_backView target];
|
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
|
|
|
{
|
2004-12-30 14:02:00 +00:00
|
|
|
NSToolbarItem *new = [[NSToolbarItem allocWithZone: zone]
|
|
|
|
initWithItemIdentifier: _itemIdentifier];
|
2010-09-12 16:34:22 +00:00
|
|
|
NSString *toolTip;
|
|
|
|
NSImage *image;
|
|
|
|
NSString *label;
|
|
|
|
NSMenuItem *item;
|
2003-08-29 04:13:48 +00:00
|
|
|
|
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]];
|
2010-09-12 16:34:22 +00:00
|
|
|
|
|
|
|
toolTip = [[self toolTip] copyWithZone: zone];
|
|
|
|
[new setToolTip: toolTip];
|
|
|
|
RELEASE(toolTip);
|
2003-08-29 04:13:48 +00:00
|
|
|
[new setTag: [self tag]];
|
2010-09-12 16:34:22 +00:00
|
|
|
image = [[self image] copyWithZone: zone];
|
|
|
|
[new setImage: image];
|
|
|
|
RELEASE(image);
|
2003-08-29 04:13:48 +00:00
|
|
|
[new setEnabled: [self isEnabled]];
|
2010-09-12 16:34:22 +00:00
|
|
|
label = [[self paletteLabel] copyWithZone: zone];
|
|
|
|
[new setPaletteLabel: label];
|
|
|
|
RELEASE(label);
|
|
|
|
label = [[self label] copyWithZone: zone];
|
|
|
|
[new setLabel: label];
|
|
|
|
RELEASE(label);
|
2008-12-30 22:20:21 +00:00
|
|
|
[new setMinSize: [self minSize]];
|
|
|
|
[new setMaxSize: [self maxSize]];
|
|
|
|
[new setAutovalidates: [self autovalidates]];
|
|
|
|
[new setVisibilityPriority: [self visibilityPriority]];
|
2010-09-12 16:34:22 +00:00
|
|
|
item = [[self menuFormRepresentation] copyWithZone: zone];
|
|
|
|
[new setMenuFormRepresentation: item];
|
|
|
|
RELEASE(item);
|
2003-08-29 04:13:48 +00:00
|
|
|
|
2009-02-10 21:02:33 +00:00
|
|
|
if ([self view] != nil)
|
|
|
|
{
|
|
|
|
NSData *encodedView = nil;
|
|
|
|
NSView *superview = nil;
|
|
|
|
|
|
|
|
/* NSView doesn't implement -copyWithZone:, that's why we encode
|
|
|
|
then decode the view to create a copy of it. */
|
|
|
|
superview = [[self view] superview];
|
|
|
|
/* We must avoid to encode view hierarchy */
|
|
|
|
[[self view] removeFromSuperviewWithoutNeedingDisplay];
|
|
|
|
NSLog(@"Encode toolbar item with label %@, view %@ and superview %@",
|
|
|
|
[self label], [self view], superview);
|
|
|
|
// NOTE: Keyed archiver would fail on NSSlider here.
|
|
|
|
encodedView = [NSArchiver archivedDataWithRootObject: [self view]];
|
|
|
|
[new setView: [NSUnarchiver unarchiveObjectWithData: encodedView]];
|
|
|
|
// Re-add the view to its hierarchy
|
|
|
|
[superview addSubview: [self view]];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-03-16 05:25:22 +00:00
|
|
|
- (NSString *) description
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"<%@ - <%@>>",[super description],[self itemIdentifier]];
|
|
|
|
}
|
2011-11-18 20:15:53 +00:00
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder *)aCoder
|
|
|
|
{
|
|
|
|
self = [self initWithItemIdentifier: [aCoder decodeObjectForKey:@"NSToolbarItemIdentifier"]];
|
|
|
|
|
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemTarget"])
|
|
|
|
[self setTarget: [aCoder decodeObjectForKey:@"NSToolbarItemTarget"]];
|
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemAction"])
|
|
|
|
[self setAction: NSSelectorFromString([aCoder decodeObjectForKey:@"NSToolbarItemAction"])];
|
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemToolTip"])
|
|
|
|
[self setToolTip: [aCoder decodeObjectForKey:@"NSToolbarItemToolTip"]];
|
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemTag"])
|
|
|
|
[self setTag: [aCoder decodeIntForKey:@"NSToolbarItemTag"]];
|
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemImage"])
|
|
|
|
[self setImage: [aCoder decodeObjectForKey:@"NSToolbarItemImage"]];
|
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemEnabled"])
|
|
|
|
[self setEnabled: [aCoder decodeBoolForKey:@"NSToolbarItemEnabled"]];
|
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemPaletteLabel"])
|
|
|
|
[self setPaletteLabel: [aCoder decodeObjectForKey:@"NSToolbarItemPaletteLabel"]];
|
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemLabel"])
|
|
|
|
[self setLabel: [aCoder decodeObjectForKey:@"NSToolbarItemLabel"]];
|
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemMinSize"])
|
2020-01-12 20:00:00 +00:00
|
|
|
[self setMinSize: [aCoder decodeSizeForKey:@"NSToolbarItemMinSize"]];
|
2011-11-18 20:15:53 +00:00
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemMaxSize"])
|
2020-01-12 20:00:00 +00:00
|
|
|
[self setMaxSize: [aCoder decodeSizeForKey:@"NSToolbarItemMaxSize"]];
|
2011-11-18 20:15:53 +00:00
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemAutovalidates"])
|
|
|
|
[self setAutovalidates: [aCoder decodeBoolForKey:@"NSToolbarItemAutovalidates"]];
|
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemVisibilityPriority"])
|
|
|
|
[self setVisibilityPriority: [aCoder decodeIntForKey:@"NSToolbarItemVisibilityPriority"]];
|
|
|
|
if ([aCoder containsValueForKey: @"NSToolbarItemView"])
|
|
|
|
[self setView: [aCoder decodeObjectForKey: @"NSToolbarItemView"]];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2002-06-30 05:14:21 +00:00
|
|
|
@end
|