2004-02-25 03:27:23 +00:00
|
|
|
/*
|
2004-03-12 22:55:02 +00:00
|
|
|
<Title>GSToolbarView.m</title>
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
<abstract>The toolbar view class.</abstract>
|
|
|
|
|
2020-12-12 22:32:01 +00:00
|
|
|
Copyright (C) 2004-2020 Free Software Foundation, Inc.
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-03-12 22:55:02 +00:00
|
|
|
Author: Quentin Mathe <qmathe@club-internet.fr>
|
2004-02-25 03:27:23 +00:00
|
|
|
Date: January 2004
|
|
|
|
|
|
|
|
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
|
2004-02-25 03:27:23 +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
|
|
|
|
2004-02-25 03:27:23 +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.
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2004-02-25 03:27:23 +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.
|
2004-02-25 03:27:23 +00:00
|
|
|
*/
|
|
|
|
|
2010-05-12 23:06:02 +00:00
|
|
|
#import <Foundation/NSObject.h>
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
|
|
|
#import <Foundation/NSException.h>
|
|
|
|
#import <Foundation/NSNotification.h>
|
|
|
|
#import <Foundation/NSUserDefaults.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import "AppKit/NSButton.h"
|
|
|
|
#import "AppKit/NSClipView.h"
|
|
|
|
#import "AppKit/NSDragging.h"
|
|
|
|
#import "AppKit/NSEvent.h"
|
|
|
|
#import "AppKit/NSImage.h"
|
|
|
|
#import "AppKit/NSMenu.h"
|
|
|
|
#import "AppKit/NSPasteboard.h"
|
2009-01-01 22:04:38 +00:00
|
|
|
// It contains GSMovableToolbarItemPboardType declaration
|
2010-05-12 23:06:02 +00:00
|
|
|
#import "AppKit/NSToolbarItem.h"
|
|
|
|
#import "AppKit/NSView.h"
|
|
|
|
#import "AppKit/NSWindow.h"
|
2009-02-07 21:58:12 +00:00
|
|
|
|
2010-05-12 23:06:02 +00:00
|
|
|
#import "GNUstepGUI/GSTheme.h"
|
|
|
|
#import "GNUstepGUI/GSToolbarView.h"
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2010-05-12 23:06:02 +00:00
|
|
|
#import "NSToolbarFrameworkPrivate.h"
|
2009-01-02 17:24:06 +00:00
|
|
|
|
2004-07-27 15:15:29 +00:00
|
|
|
typedef enum {
|
|
|
|
ToolbarViewDefaultHeight = 62,
|
|
|
|
ToolbarViewRegularHeight = 62,
|
|
|
|
ToolbarViewSmallHeight = 52
|
|
|
|
} ToolbarViewHeight;
|
|
|
|
|
2010-05-21 15:01:45 +00:00
|
|
|
// Borrow this from NSToolbarItem.m
|
|
|
|
static const int InsetItemViewX = 10;
|
|
|
|
|
2004-07-27 15:15:29 +00:00
|
|
|
static const int ClippedItemsViewWidth = 28;
|
|
|
|
|
2016-12-17 00:00:19 +00:00
|
|
|
static NSUInteger draggedItemIndex = NSNotFound;
|
2010-04-13 21:38:31 +00:00
|
|
|
|
2004-05-18 19:35:58 +00:00
|
|
|
/*
|
|
|
|
* Toolbar related code
|
|
|
|
*/
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-09-02 17:40:00 +00:00
|
|
|
@interface GSToolbarButton
|
|
|
|
- (NSToolbarItem *) toolbarItem;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface GSToolbarBackView
|
|
|
|
- (NSToolbarItem *) toolbarItem;
|
|
|
|
@end
|
|
|
|
|
2004-03-12 22:55:02 +00:00
|
|
|
@interface GSToolbarClippedItemsButton : NSButton
|
|
|
|
{
|
2009-01-01 22:04:38 +00:00
|
|
|
NSToolbar *_toolbar;
|
2004-03-12 22:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init;
|
|
|
|
|
|
|
|
// Accessors
|
2009-01-18 15:11:37 +00:00
|
|
|
- (NSMenu *) overflowMenu;
|
2004-12-30 14:02:00 +00:00
|
|
|
/* This method cannot be called "menu" otherwise it would override NSResponder
|
|
|
|
method with the same name. */
|
2004-03-12 22:55:02 +00:00
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
- (void) layout;
|
2009-01-01 22:04:38 +00:00
|
|
|
- (void) setToolbar: (NSToolbar *)toolbar;
|
2004-03-12 22:55:02 +00:00
|
|
|
@end
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
@implementation GSToolbarClippedItemsButton
|
2004-04-13 13:12:53 +00:00
|
|
|
- (id) init
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
NSImage *image = [NSImage imageNamed: @"common_ToolbarClippedItemsMark"];
|
2004-12-30 14:02:00 +00:00
|
|
|
NSRect dummyRect = NSMakeRect(0, 0, ClippedItemsViewWidth, 100);
|
|
|
|
// The correct height will be set by the layout method
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
if ((self = [super initWithFrame: dummyRect]) != nil)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
[self setBordered: NO];
|
2004-03-12 22:55:02 +00:00
|
|
|
[[self cell] setHighlightsBy: NSChangeGrayCellMask
|
|
|
|
| NSChangeBackgroundCellMask];
|
2004-04-13 13:12:53 +00:00
|
|
|
[self setAutoresizingMask: NSViewNotSizable];
|
2004-02-25 03:27:23 +00:00
|
|
|
[self setImagePosition: NSImageOnly];
|
|
|
|
[image setScalesWhenResized: YES];
|
2004-07-07 21:25:42 +00:00
|
|
|
// [image setSize: NSMakeSize(20, 20)];
|
2004-02-25 03:27:23 +00:00
|
|
|
[self setImage: image];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
/*
|
|
|
|
* Not really used, it is here to be used by the developer who want to adjust
|
|
|
|
* easily a toolbar view attached to a toolbar which is not bind to a window.
|
|
|
|
*/
|
|
|
|
- (void) layout
|
|
|
|
{
|
|
|
|
NSSize layoutSize = NSMakeSize([self frame].size.width,
|
|
|
|
[[_toolbar _toolbarView] _heightFromLayout]);
|
|
|
|
|
|
|
|
[self setFrameSize: layoutSize];
|
2004-04-13 13:12:53 +00:00
|
|
|
}
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
- (void) mouseDown: (NSEvent *)event
|
|
|
|
{
|
2009-01-02 14:05:39 +00:00
|
|
|
NSMenu *clippedItemsMenu = [self menuForEvent: event];
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2009-01-02 14:05:39 +00:00
|
|
|
[super highlight: YES];
|
2004-03-12 22:55:02 +00:00
|
|
|
|
2009-01-02 14:05:39 +00:00
|
|
|
if (clippedItemsMenu != nil)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-03-12 22:55:02 +00:00
|
|
|
[NSMenu popUpContextMenu: clippedItemsMenu withEvent: event
|
2009-01-02 14:05:39 +00:00
|
|
|
forView: self];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
2004-03-12 22:55:02 +00:00
|
|
|
|
2009-01-02 14:05:39 +00:00
|
|
|
[super highlight: NO];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
- (NSMenu *) menuForEvent: (NSEvent *)event
|
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
if ([event type] == NSLeftMouseDown)
|
|
|
|
{
|
2009-01-18 15:11:37 +00:00
|
|
|
return [self overflowMenu];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2009-01-18 15:11:37 +00:00
|
|
|
- (NSMenu *) overflowMenu
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-12-30 14:02:00 +00:00
|
|
|
/* This method cannot be called "menu" otherwise it would
|
|
|
|
override NSResponder method with the same name. */
|
2004-05-23 18:22:45 +00:00
|
|
|
NSMenu *menu = [[NSMenu alloc] initWithTitle: @""];
|
2004-02-25 03:27:23 +00:00
|
|
|
NSEnumerator *e;
|
|
|
|
id item;
|
|
|
|
NSArray *visibleItems;
|
|
|
|
|
|
|
|
visibleItems = [_toolbar visibleItems];
|
|
|
|
|
|
|
|
e = [[_toolbar items] objectEnumerator];
|
|
|
|
while ((item = [e nextObject]) != nil)
|
|
|
|
{
|
|
|
|
if (![visibleItems containsObject: item])
|
|
|
|
{
|
|
|
|
id menuItem;
|
|
|
|
|
2009-01-02 14:05:39 +00:00
|
|
|
menuItem = [item menuFormRepresentation];
|
2004-05-18 19:35:58 +00:00
|
|
|
if (menuItem == nil)
|
2009-01-02 14:05:39 +00:00
|
|
|
menuItem = [item _defaultMenuFormRepresentation];
|
|
|
|
|
|
|
|
if (menuItem != nil)
|
2009-01-18 15:11:37 +00:00
|
|
|
{
|
|
|
|
[item validate];
|
|
|
|
[menu addItem: menuItem];
|
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-02 14:05:39 +00:00
|
|
|
return AUTORELEASE(menu);
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
|
2009-01-01 22:04:38 +00:00
|
|
|
- (void) setToolbar: (NSToolbar *)toolbar
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-07-07 21:25:42 +00:00
|
|
|
// Don't do an ASSIGN here, the toolbar view retains us.
|
|
|
|
_toolbar = toolbar;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2004-09-02 17:40:00 +00:00
|
|
|
// ---
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
// Implementation GSToolbarView
|
|
|
|
|
|
|
|
@implementation GSToolbarView
|
2004-05-18 19:35:58 +00:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
2009-01-02 14:05:39 +00:00
|
|
|
if (self == [GSToolbarView class])
|
2010-12-31 16:19:52 +00:00
|
|
|
{
|
|
|
|
}
|
2004-05-18 19:35:58 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (id) initWithFrame: (NSRect)frame
|
2004-04-13 13:12:53 +00:00
|
|
|
{
|
2009-01-02 14:05:39 +00:00
|
|
|
if ((self = [super initWithFrame: frame]) == nil)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2009-01-02 14:05:39 +00:00
|
|
|
return nil;
|
|
|
|
}
|
2004-09-05 17:56:11 +00:00
|
|
|
|
2009-01-02 14:05:39 +00:00
|
|
|
_heightFromLayout = ToolbarViewDefaultHeight;
|
|
|
|
[self setFrame: NSMakeRect(frame.origin.x, frame.origin.y,
|
|
|
|
frame.size.width, _heightFromLayout)];
|
2004-04-13 13:12:53 +00:00
|
|
|
|
2009-01-02 14:05:39 +00:00
|
|
|
_clipView = [[NSClipView alloc] initWithFrame:
|
|
|
|
NSMakeRect(0, 0, frame.size.width,
|
|
|
|
_heightFromLayout)];
|
|
|
|
[_clipView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
|
2009-02-07 21:58:12 +00:00
|
|
|
[_clipView setDrawsBackground: NO];
|
2009-01-02 14:05:39 +00:00
|
|
|
[self addSubview: _clipView];
|
|
|
|
// Adjust the clip view frame
|
|
|
|
[self setBorderMask: GSToolbarViewTopBorder | GSToolbarViewBottomBorder
|
2004-12-30 14:02:00 +00:00
|
|
|
| GSToolbarViewRightBorder | GSToolbarViewLeftBorder];
|
2009-01-02 14:05:39 +00:00
|
|
|
|
|
|
|
_clippedItemsMark = [[GSToolbarClippedItemsButton alloc] init];
|
|
|
|
|
|
|
|
[self registerForDraggedTypes:
|
|
|
|
[NSArray arrayWithObject: GSMovableToolbarItemPboardType]];
|
|
|
|
|
|
|
|
return self;
|
2004-07-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2004-09-05 17:56:11 +00:00
|
|
|
//NSLog(@"Toolbar view dealloc");
|
2004-07-07 21:25:42 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
RELEASE(_clippedItemsMark);
|
|
|
|
RELEASE(_clipView);
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2004-09-02 17:40:00 +00:00
|
|
|
// Dragging related methods
|
|
|
|
|
2016-12-17 00:00:19 +00:00
|
|
|
+ (NSUInteger) draggedItemIndex
|
2010-04-13 21:38:31 +00:00
|
|
|
{
|
|
|
|
return draggedItemIndex;
|
|
|
|
}
|
|
|
|
|
2016-12-17 00:00:19 +00:00
|
|
|
+ (void) setDraggedItemIndex:(NSUInteger)sourceIndex
|
2010-04-13 21:38:31 +00:00
|
|
|
{
|
|
|
|
draggedItemIndex = sourceIndex;
|
|
|
|
}
|
|
|
|
|
2009-01-02 17:24:06 +00:00
|
|
|
- (int) _insertionIndexAtPoint: (NSPoint)location
|
|
|
|
{
|
2016-12-17 00:00:19 +00:00
|
|
|
NSUInteger index;
|
2010-04-13 21:38:31 +00:00
|
|
|
NSArray *visibleBackViews = [self _visibleBackViews];
|
|
|
|
|
|
|
|
location = [_clipView convertPoint:location fromView:nil];
|
|
|
|
if (draggedItemIndex == NSNotFound)
|
2009-01-02 17:24:06 +00:00
|
|
|
{
|
2010-04-13 21:38:31 +00:00
|
|
|
//simply locate the nearest location between existing items
|
2017-04-16 11:54:21 +00:00
|
|
|
for (index = 0; index < [visibleBackViews count]; index++)
|
2010-04-13 21:38:31 +00:00
|
|
|
{
|
|
|
|
NSRect itemRect = [[visibleBackViews objectAtIndex:index] frame];
|
|
|
|
if (location.x < (itemRect.origin.x + (itemRect.size.width/2)))
|
|
|
|
{
|
2017-04-16 11:54:21 +00:00
|
|
|
NSLog(@"At location %lu", (unsigned long)index);
|
2010-04-13 21:38:31 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [visibleBackViews count];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// don't return a different index unless drag has crossed the midpoint of its neighbor
|
|
|
|
NSRect itemRect;
|
|
|
|
BOOL draggingLeft = YES;
|
|
|
|
if (draggedItemIndex < [visibleBackViews count])
|
|
|
|
{
|
|
|
|
itemRect = [[visibleBackViews objectAtIndex:draggedItemIndex] frame];
|
|
|
|
draggingLeft = (location.x < (itemRect.origin.x + (itemRect.size.width/2)));
|
|
|
|
}
|
|
|
|
if (draggingLeft)
|
|
|
|
{
|
|
|
|
// dragging to the left of dragged item's current location
|
2021-10-27 19:00:38 +00:00
|
|
|
for (index=0; index < draggedItemIndex && index < [visibleBackViews count]; index++)
|
2010-04-13 21:38:31 +00:00
|
|
|
{
|
|
|
|
itemRect = [[visibleBackViews objectAtIndex:index] frame];
|
|
|
|
if (location.x < (itemRect.origin.x + (itemRect.size.width/2)))
|
|
|
|
{
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// dragging to the right of current location
|
2016-12-17 00:00:19 +00:00
|
|
|
// Never called for [visibleBackViews count] == 0
|
2010-04-13 21:38:31 +00:00
|
|
|
for (index=[visibleBackViews count]-1; index > draggedItemIndex; index--)
|
|
|
|
{
|
|
|
|
itemRect = [[visibleBackViews objectAtIndex:index] frame];
|
|
|
|
if (location.x > (itemRect.origin.x + (itemRect.size.width/2)))
|
|
|
|
{
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return draggedItemIndex;
|
2009-01-02 17:24:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-17 00:00:19 +00:00
|
|
|
#define OUTSIDE_INDEX (NSNotFound - 1)
|
|
|
|
|
2010-04-13 21:38:31 +00:00
|
|
|
- (NSDragOperation) updateItemWhileDragging:(id <NSDraggingInfo>)info exited:(BOOL)exited
|
2004-09-02 17:40:00 +00:00
|
|
|
{
|
2010-04-13 21:38:31 +00:00
|
|
|
NSToolbarItem *item = [[info draggingSource] toolbarItem];
|
|
|
|
NSString *identifier = [item itemIdentifier];
|
2009-01-01 22:04:38 +00:00
|
|
|
NSToolbar *toolbar = [self toolbar];
|
2011-11-18 20:15:53 +00:00
|
|
|
NSArray *allowedItemIdentifiers = [toolbar _allowedItemIdentifiers];
|
2010-04-16 18:58:26 +00:00
|
|
|
int newIndex;
|
2010-04-13 21:38:31 +00:00
|
|
|
|
|
|
|
// don't accept any dragging if the customization palette isn't running for this toolbar
|
|
|
|
if (![toolbar customizationPaletteIsRunning] || ![allowedItemIdentifiers containsObject: identifier])
|
|
|
|
{
|
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draggedItemIndex == NSNotFound) // initialize the index for this drag session
|
|
|
|
{
|
|
|
|
// if duplicate items aren't allowed, see if we already have such an item
|
|
|
|
if (![item allowsDuplicatesInToolbar])
|
|
|
|
{
|
|
|
|
NSArray *items = [toolbar items];
|
2016-12-17 00:00:19 +00:00
|
|
|
NSUInteger index;
|
2010-04-13 21:38:31 +00:00
|
|
|
for (index=0; index<[items count]; index++)
|
|
|
|
{
|
|
|
|
NSToolbarItem *anItem = [items objectAtIndex:index];
|
|
|
|
if ([[anItem itemIdentifier] isEqual:identifier])
|
|
|
|
{
|
|
|
|
draggedItemIndex = index; // drag the existing item
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-17 00:00:19 +00:00
|
|
|
else if (draggedItemIndex == OUTSIDE_INDEX)
|
2010-04-13 21:38:31 +00:00
|
|
|
{
|
|
|
|
// re-entering after being dragged off -- treat as unknown location
|
|
|
|
draggedItemIndex = NSNotFound;
|
|
|
|
}
|
|
|
|
|
2010-04-16 18:58:26 +00:00
|
|
|
newIndex = [self _insertionIndexAtPoint: [info draggingLocation]];
|
2004-12-30 14:02:00 +00:00
|
|
|
|
2010-04-13 21:38:31 +00:00
|
|
|
if (draggedItemIndex != NSNotFound)
|
2004-09-02 17:40:00 +00:00
|
|
|
{
|
2010-04-13 21:38:31 +00:00
|
|
|
// existing item being dragged -- either move or remove it
|
|
|
|
if (exited)
|
|
|
|
{
|
|
|
|
[toolbar _removeItemAtIndex:draggedItemIndex broadcast:YES];
|
2016-12-17 00:00:19 +00:00
|
|
|
draggedItemIndex = OUTSIDE_INDEX; // no longer in our items
|
2010-04-13 21:38:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (newIndex != draggedItemIndex)
|
|
|
|
{
|
|
|
|
[toolbar _moveItemFromIndex: draggedItemIndex toIndex: newIndex broadcast: YES];
|
|
|
|
draggedItemIndex = newIndex;
|
|
|
|
}
|
|
|
|
}
|
2004-12-30 14:02:00 +00:00
|
|
|
}
|
2010-04-13 21:38:31 +00:00
|
|
|
else if (!exited)
|
|
|
|
{
|
|
|
|
// new item being dragged in -- add it
|
|
|
|
[toolbar _insertItemWithItemIdentifier: identifier
|
|
|
|
atIndex: newIndex
|
|
|
|
broadcast: YES];
|
|
|
|
draggedItemIndex = newIndex;
|
|
|
|
}
|
2016-12-17 00:00:19 +00:00
|
|
|
return NSDragOperationGeneric;
|
2010-04-13 21:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation) draggingEntered: (id <NSDraggingInfo>)info
|
|
|
|
{
|
2010-05-12 23:06:02 +00:00
|
|
|
return [self updateItemWhileDragging: info exited: NO];
|
2004-09-02 17:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>)info
|
|
|
|
{
|
2010-05-12 23:06:02 +00:00
|
|
|
return [self updateItemWhileDragging: info exited: NO];
|
2004-09-02 17:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) draggingEnded: (id <NSDraggingInfo>)info
|
|
|
|
{
|
2010-04-13 21:38:31 +00:00
|
|
|
draggedItemIndex = NSNotFound;
|
2004-09-02 17:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) draggingExited: (id <NSDraggingInfo>)info
|
|
|
|
{
|
2010-05-12 23:06:02 +00:00
|
|
|
[self updateItemWhileDragging: info exited: YES];
|
2004-09-02 17:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) prepareForDragOperation: (id <NSDraggingInfo>)info
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) performDragOperation: (id <NSDraggingInfo>)info
|
|
|
|
{
|
2009-01-01 22:04:38 +00:00
|
|
|
NSToolbar *toolbar = [self toolbar];
|
2009-03-13 05:03:50 +00:00
|
|
|
|
2010-05-12 23:06:02 +00:00
|
|
|
[self updateItemWhileDragging: info exited: NO];
|
2010-04-13 21:38:31 +00:00
|
|
|
|
|
|
|
draggedItemIndex = NSNotFound;
|
2009-03-16 07:33:31 +00:00
|
|
|
|
|
|
|
// save the configuration...
|
|
|
|
[toolbar _saveConfig];
|
2009-03-13 05:03:50 +00:00
|
|
|
|
2004-09-02 17:40:00 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) concludeDragOperation: (id <NSDraggingInfo>)info
|
|
|
|
{
|
|
|
|
// Nothing to do currently
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
// More overrided methods
|
|
|
|
|
|
|
|
- (void) drawRect: (NSRect)aRect
|
|
|
|
{
|
2009-09-16 07:11:21 +00:00
|
|
|
[[GSTheme theme] drawToolbarRect: aRect
|
2009-02-07 21:58:12 +00:00
|
|
|
frame: [self frame]
|
|
|
|
borderMask: _borderMask];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isOpaque
|
|
|
|
{
|
2010-12-31 16:19:52 +00:00
|
|
|
if ([[[GSTheme theme] toolbarBackgroundColor] alphaComponent] < 1.0)
|
2010-02-25 21:49:24 +00:00
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) windowDidResize: (NSNotification *)notification
|
|
|
|
{
|
2004-03-12 22:55:02 +00:00
|
|
|
if ([self superview] == nil)
|
|
|
|
return;
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
[self _reload];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2004-07-07 21:25:42 +00:00
|
|
|
- (void) viewWillMoveToSuperview: (NSView *)newSuperview
|
|
|
|
{
|
|
|
|
[super viewWillMoveToSuperview: newSuperview];
|
|
|
|
|
|
|
|
[_toolbar _toolbarViewWillMoveToSuperview: newSuperview];
|
|
|
|
// Allow to update the validation system which is window specific
|
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) viewDidMoveToWindow
|
|
|
|
{
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
/* NSView method called when a view is moved to a window (NSView has a
|
|
|
|
variable _window). */
|
2004-02-25 03:27:23 +00:00
|
|
|
[super viewDidMoveToWindow];
|
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
[nc removeObserver: self name: NSWindowDidResizeNotification object: nil];
|
2004-03-12 22:55:02 +00:00
|
|
|
[nc addObserver: self selector: @selector(windowDidResize:)
|
2004-07-07 21:25:42 +00:00
|
|
|
name: NSWindowDidResizeNotification
|
2009-01-02 14:05:39 +00:00
|
|
|
object: _window];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 14:05:39 +00:00
|
|
|
// Accessors
|
2004-02-25 03:27:23 +00:00
|
|
|
|
|
|
|
- (unsigned int) borderMask
|
|
|
|
{
|
|
|
|
return _borderMask;
|
|
|
|
}
|
|
|
|
|
2009-01-01 22:04:38 +00:00
|
|
|
- (NSToolbar *) toolbar
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
return _toolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setBorderMask: (unsigned int)borderMask
|
|
|
|
{
|
2004-05-23 18:22:45 +00:00
|
|
|
NSRect toolbarViewFrame = [self frame];
|
2009-01-02 14:05:39 +00:00
|
|
|
NSRect rect = NSMakeRect(0, 0, toolbarViewFrame.size.width,
|
|
|
|
toolbarViewFrame.size.height);
|
2004-05-23 18:22:45 +00:00
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
_borderMask = borderMask;
|
2004-05-23 18:22:45 +00:00
|
|
|
|
|
|
|
// Take in account the border
|
|
|
|
if (_borderMask & GSToolbarViewBottomBorder)
|
|
|
|
{
|
2004-12-30 14:02:00 +00:00
|
|
|
rect = NSMakeRect(rect.origin.x, ++rect.origin.y, rect.size.width,
|
2009-01-02 14:05:39 +00:00
|
|
|
--rect.size.height);
|
2004-05-23 18:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_borderMask & GSToolbarViewTopBorder)
|
|
|
|
{
|
2004-12-30 14:02:00 +00:00
|
|
|
rect = NSMakeRect(rect.origin.x, rect.origin.y, rect.size.width,
|
2009-01-02 14:05:39 +00:00
|
|
|
--rect.size.height);
|
2004-05-23 18:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_borderMask & GSToolbarViewLeftBorder)
|
|
|
|
{
|
2004-12-30 14:02:00 +00:00
|
|
|
rect = NSMakeRect(++rect.origin.x, rect.origin.y, --rect.size.width,
|
2009-01-02 14:05:39 +00:00
|
|
|
rect.size.height);
|
2004-05-23 18:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_borderMask & GSToolbarViewRightBorder)
|
|
|
|
{
|
2004-12-30 14:02:00 +00:00
|
|
|
rect = NSMakeRect(rect.origin.x, rect.origin.y, --rect.size.width,
|
2009-01-02 14:05:39 +00:00
|
|
|
rect.size.height);
|
2004-05-23 18:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[_clipView setFrame: rect];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2009-01-01 22:04:38 +00:00
|
|
|
- (void) setToolbar: (NSToolbar *)toolbar
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2009-01-01 19:22:50 +00:00
|
|
|
if (_toolbar == toolbar)
|
|
|
|
return;
|
|
|
|
|
2009-01-07 08:49:53 +00:00
|
|
|
_toolbar = toolbar;
|
2009-01-01 19:22:50 +00:00
|
|
|
|
|
|
|
[_clippedItemsMark setToolbar: _toolbar];
|
|
|
|
// Load the toolbar in the toolbar view
|
|
|
|
[self _reload];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Private methods
|
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
- (void) _handleBackViewsFrame
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2020-12-12 00:54:37 +00:00
|
|
|
CGFloat x = 0;
|
|
|
|
CGFloat newHeight = 0;
|
2010-04-13 21:38:31 +00:00
|
|
|
NSArray *subviews = [_clipView subviews];
|
2010-05-12 23:06:02 +00:00
|
|
|
NSEnumerator *e = [[_toolbar items] objectEnumerator];
|
|
|
|
NSToolbarItem *item;
|
2004-04-13 13:12:53 +00:00
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
while ((item = [e nextObject]) != nil)
|
|
|
|
{
|
2010-05-12 23:06:02 +00:00
|
|
|
NSView *itemBackView;
|
|
|
|
NSRect itemBackViewFrame;
|
|
|
|
|
2004-03-12 22:55:02 +00:00
|
|
|
itemBackView = [item _backView];
|
2004-12-30 14:02:00 +00:00
|
|
|
if ([subviews containsObject: itemBackView] == NO
|
2004-03-12 22:55:02 +00:00
|
|
|
|| [item _isModified]
|
|
|
|
|| [item _isFlexibleSpace])
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2009-01-02 14:05:39 +00:00
|
|
|
// When a label is changed, _isModified returns YES to let us known we
|
|
|
|
// must recalculate the text length and then the size for the edited
|
|
|
|
// item back view
|
2004-03-12 22:55:02 +00:00
|
|
|
[item _layout];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
2004-03-12 22:55:02 +00:00
|
|
|
|
|
|
|
itemBackViewFrame = [itemBackView frame];
|
2004-12-30 14:02:00 +00:00
|
|
|
[itemBackView setFrame: NSMakeRect(x, itemBackViewFrame.origin.y,
|
|
|
|
itemBackViewFrame.size.width, itemBackViewFrame.size.height)];
|
2009-01-02 14:05:39 +00:00
|
|
|
|
2004-03-12 22:55:02 +00:00
|
|
|
x += [itemBackView frame].size.width;
|
2004-04-13 13:12:53 +00:00
|
|
|
|
2004-09-05 17:56:11 +00:00
|
|
|
if (itemBackViewFrame.size.height > newHeight)
|
2010-05-12 23:06:02 +00:00
|
|
|
newHeight = itemBackViewFrame.size.height;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2004-09-05 17:56:11 +00:00
|
|
|
if (newHeight > 0)
|
|
|
|
_heightFromLayout = newHeight;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:24:06 +00:00
|
|
|
- (void) _takeInAccountFlexibleSpaces
|
|
|
|
{
|
|
|
|
NSArray *items = [_toolbar items];
|
2010-05-13 16:29:38 +00:00
|
|
|
NSEnumerator *e;
|
2009-01-02 17:24:06 +00:00
|
|
|
NSToolbarItem *item;
|
2010-05-21 15:01:45 +00:00
|
|
|
NSView *backView, *view;
|
|
|
|
CGFloat lengthAvailable;
|
2010-02-25 21:56:34 +00:00
|
|
|
BOOL mustAdjustNext = NO;
|
2010-05-21 15:01:45 +00:00
|
|
|
CGFloat x = 0, visibleItemsMinWidth = 0, backViewsWidth = 0;
|
|
|
|
NSMutableArray *variableWidthItems = [NSMutableArray array];
|
2020-12-12 00:54:37 +00:00
|
|
|
unsigned flexibleItemsCount = 0, maxWidthItemsCount = 0;
|
2010-05-21 15:01:45 +00:00
|
|
|
CGFloat spacePerFlexItem, extraSpace = 0;
|
|
|
|
CGFloat toolbarWidth = [self frame].size.width;
|
2020-12-12 00:54:37 +00:00
|
|
|
NSUInteger i, n;
|
2010-05-21 15:01:45 +00:00
|
|
|
NSMutableArray *visibleItems = [NSMutableArray array];
|
|
|
|
static const int FlexItemWeight = 4; // non-space flexible item counts as much as 4 flexible spaces
|
2020-12-12 00:54:37 +00:00
|
|
|
|
|
|
|
n = [items count];
|
2010-05-21 15:01:45 +00:00
|
|
|
if (n == 0)
|
2009-01-02 17:24:06 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-21 15:01:45 +00:00
|
|
|
// First determine which items can fit in toolbar if all are at their minimum width.
|
|
|
|
// We'd like to show as many items as possible. These are our visibleItems.
|
|
|
|
for (i=0; i < n; i++)
|
2009-01-02 17:24:06 +00:00
|
|
|
{
|
2010-05-21 15:01:45 +00:00
|
|
|
item = [items objectAtIndex:i];
|
|
|
|
backView = [item _backView];
|
|
|
|
view = [item view];
|
|
|
|
if (view != nil)
|
|
|
|
backViewsWidth += [item minSize].width + 2*InsetItemViewX;
|
|
|
|
else
|
|
|
|
backViewsWidth += [backView frame].size.width;
|
2010-05-13 16:29:38 +00:00
|
|
|
|
2010-05-21 15:01:45 +00:00
|
|
|
if ((backViewsWidth + ClippedItemsViewWidth <= toolbarWidth)
|
|
|
|
|| (i == n - 1 && backViewsWidth <= toolbarWidth))
|
|
|
|
{
|
|
|
|
visibleItemsMinWidth = backViewsWidth;
|
|
|
|
[visibleItems addObject:item];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2010-05-13 16:29:38 +00:00
|
|
|
}
|
2010-05-21 15:01:45 +00:00
|
|
|
// next, figure out how much additional space there is for expanding flexible items
|
|
|
|
lengthAvailable = toolbarWidth - visibleItemsMinWidth;
|
|
|
|
if ([visibleItems count] < n)
|
|
|
|
lengthAvailable -= ClippedItemsViewWidth;
|
|
|
|
|
|
|
|
if (lengthAvailable < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We want to divide available space evenly among all flexible items, but some items may
|
|
|
|
// reach their maximum width, making more space available for the other items.
|
|
|
|
// To do this, first we count the flexible items, gathering a list of those that may
|
|
|
|
// have a maximum width.
|
|
|
|
// To match observed behavior on Cocoa (which is NOT as documented!) we allocate only 1/4
|
|
|
|
// as much space to flexible spaces as we do to other flexible items.
|
|
|
|
e = [visibleItems objectEnumerator];
|
2010-05-13 16:29:38 +00:00
|
|
|
while ((item = [e nextObject]) != nil)
|
|
|
|
{
|
|
|
|
if ([item _isFlexibleSpace])
|
2010-05-12 23:06:02 +00:00
|
|
|
{
|
2010-05-21 15:01:45 +00:00
|
|
|
flexibleItemsCount++;
|
2010-05-12 23:06:02 +00:00
|
|
|
}
|
2010-05-21 15:01:45 +00:00
|
|
|
else
|
2010-05-12 23:06:02 +00:00
|
|
|
{
|
2010-05-21 15:01:45 +00:00
|
|
|
CGFloat minWidth = [item minSize].width;
|
|
|
|
CGFloat maxWidth = [item maxSize].width;
|
|
|
|
if (minWidth < maxWidth)
|
|
|
|
{
|
|
|
|
[variableWidthItems addObject:item];
|
|
|
|
flexibleItemsCount += FlexItemWeight; // gets FlexItemWeight times the weight of a flexible space
|
|
|
|
}
|
2010-05-13 16:29:38 +00:00
|
|
|
}
|
2010-05-21 15:01:45 +00:00
|
|
|
}
|
|
|
|
if (flexibleItemsCount == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Now go through any variableWidthItems to see if the available space per item would
|
|
|
|
// cause any of them to exceed their maximum width, and calculate the extra space available
|
|
|
|
spacePerFlexItem = MAX(lengthAvailable / flexibleItemsCount, 0);
|
|
|
|
e = [variableWidthItems objectEnumerator];
|
|
|
|
while ((item = [e nextObject]) != nil)
|
|
|
|
{
|
|
|
|
CGFloat minWidth = [item minSize].width;
|
|
|
|
CGFloat maxWidth = [item maxSize].width;
|
|
|
|
if (maxWidth-minWidth < spacePerFlexItem * FlexItemWeight)
|
2010-05-13 16:29:38 +00:00
|
|
|
{
|
2010-05-21 15:01:45 +00:00
|
|
|
extraSpace += spacePerFlexItem * FlexItemWeight - (maxWidth-minWidth); // give back unneeded space
|
|
|
|
maxWidthItemsCount += FlexItemWeight;
|
2010-05-12 23:06:02 +00:00
|
|
|
}
|
2009-01-02 17:24:06 +00:00
|
|
|
}
|
2010-05-21 15:01:45 +00:00
|
|
|
// Recalculate spacePerFlexItem (unless all flexible items are going to their max width)
|
|
|
|
if (flexibleItemsCount > maxWidthItemsCount)
|
|
|
|
spacePerFlexItem += extraSpace / (flexibleItemsCount-maxWidthItemsCount);
|
|
|
|
|
|
|
|
// Finally, go through all items, adjusting their width and positioning them as needed
|
|
|
|
e = [items objectEnumerator];
|
|
|
|
while ((item = [e nextObject]) != nil)
|
|
|
|
{
|
|
|
|
backView = [item _backView];
|
|
|
|
if ([item _isFlexibleSpace])
|
|
|
|
{
|
|
|
|
NSRect backViewFrame = [backView frame];
|
2020-12-12 22:32:01 +00:00
|
|
|
NSRect newFrameRect = NSMakeRect(x, backViewFrame.origin.y,
|
|
|
|
spacePerFlexItem,
|
|
|
|
backViewFrame.size.height);
|
|
|
|
[backView setFrame: [self centerScanRect:newFrameRect]];
|
2010-05-21 15:01:45 +00:00
|
|
|
mustAdjustNext = YES;
|
|
|
|
}
|
|
|
|
else if ([variableWidthItems indexOfObjectIdenticalTo:item] != NSNotFound)
|
|
|
|
{
|
|
|
|
NSRect backViewFrame = [backView frame];
|
|
|
|
CGFloat maxFlex = [item maxSize].width - [item minSize].width;
|
|
|
|
CGFloat flexAmount = MIN(maxFlex, spacePerFlexItem * FlexItemWeight);
|
|
|
|
CGFloat newWidth = [item minSize].width + flexAmount + 2 * InsetItemViewX;
|
2020-12-12 22:32:01 +00:00
|
|
|
NSRect newFrameRect = NSMakeRect(x, backViewFrame.origin.y,
|
|
|
|
newWidth,
|
|
|
|
backViewFrame.size.height);
|
|
|
|
[backView setFrame: [self centerScanRect: newFrameRect]];
|
2010-05-21 15:01:45 +00:00
|
|
|
mustAdjustNext = YES;
|
|
|
|
}
|
|
|
|
else if (mustAdjustNext)
|
|
|
|
{
|
|
|
|
NSRect backViewFrame = [backView frame];
|
2020-12-12 22:32:01 +00:00
|
|
|
NSRect newFrameRect = NSMakeRect(x, backViewFrame.origin.y,
|
|
|
|
backViewFrame.size.width,
|
|
|
|
backViewFrame.size.height);
|
|
|
|
[backView setFrame: [self centerScanRect: newFrameRect]];
|
2010-05-21 15:01:45 +00:00
|
|
|
}
|
|
|
|
view = [item view];
|
|
|
|
if (view != nil)
|
|
|
|
{
|
|
|
|
NSRect viewFrame = [view frame];
|
|
|
|
// Subtract InsetItemViewX
|
|
|
|
viewFrame.size.width = [backView frame].size.width - 2 * InsetItemViewX;
|
|
|
|
viewFrame.origin.x = InsetItemViewX;
|
|
|
|
[view setFrame: viewFrame];
|
|
|
|
}
|
|
|
|
x += [backView frame].size.width;
|
|
|
|
}
|
2009-01-02 17:24:06 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
- (void) _handleViewsVisibility
|
|
|
|
{
|
2010-05-12 23:06:02 +00:00
|
|
|
NSArray *backViews;
|
2004-04-13 13:12:53 +00:00
|
|
|
NSArray *subviews;
|
2004-02-25 03:27:23 +00:00
|
|
|
NSEnumerator *e;
|
2004-04-13 13:12:53 +00:00
|
|
|
NSView *backView;
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2010-05-12 23:06:02 +00:00
|
|
|
/* The back views which are associated with each toolbar item (the toolbar
|
|
|
|
items doesn't reflect the toolbar view content) */
|
|
|
|
backViews = [[_toolbar items] valueForKey: @"_backView"];
|
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
// We remove each back view associated with a removed toolbar item
|
|
|
|
e = [[_clipView subviews] objectEnumerator];
|
|
|
|
while ((backView = [e nextObject]) != nil)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-12-30 14:02:00 +00:00
|
|
|
if ([backViews containsObject: backView] == NO)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-04-13 13:12:53 +00:00
|
|
|
if ([backView superview] != nil)
|
|
|
|
[backView removeFromSuperview];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
// We add each backView associated with an added toolbar item
|
2004-07-07 21:25:42 +00:00
|
|
|
subviews = [_clipView subviews];
|
2010-05-12 23:06:02 +00:00
|
|
|
e = [backViews objectEnumerator];
|
2004-04-13 13:12:53 +00:00
|
|
|
while ((backView = [e nextObject]) != nil)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-12-30 14:02:00 +00:00
|
|
|
if ([subviews containsObject: backView] == NO)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-04-13 13:12:53 +00:00
|
|
|
[_clipView addSubview: backView];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-12 23:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _manageClipView
|
|
|
|
{
|
|
|
|
NSRect clipViewFrame = [_clipView frame];
|
2020-12-12 00:54:37 +00:00
|
|
|
NSUInteger count = [[_toolbar items] count];
|
2010-05-12 23:06:02 +00:00
|
|
|
// Retrieve the back views which should be visible now that the resize
|
|
|
|
// process has been taken in account
|
|
|
|
NSArray *visibleBackViews = [self _visibleBackViews];
|
|
|
|
|
|
|
|
if ([visibleBackViews count] < count)
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2004-04-13 13:12:53 +00:00
|
|
|
NSView *lastVisibleBackView = [visibleBackViews lastObject];
|
|
|
|
float width = 0;
|
|
|
|
|
|
|
|
// Resize the clip view
|
|
|
|
if (lastVisibleBackView != nil)
|
2004-05-23 18:22:45 +00:00
|
|
|
width = NSMaxX([lastVisibleBackView frame]);
|
2004-03-12 22:55:02 +00:00
|
|
|
[_clipView setFrame: NSMakeRect(clipViewFrame.origin.x,
|
2004-04-13 13:12:53 +00:00
|
|
|
clipViewFrame.origin.y,
|
|
|
|
width,
|
|
|
|
clipViewFrame.size.height)];
|
2009-01-02 14:05:39 +00:00
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
// Adjust the clipped items mark frame handling
|
2004-04-13 13:12:53 +00:00
|
|
|
[_clippedItemsMark layout];
|
2010-05-12 23:06:02 +00:00
|
|
|
|
|
|
|
// We get the new _clipView frame
|
|
|
|
clipViewFrame = [_clipView frame];
|
2004-04-13 13:12:53 +00:00
|
|
|
[_clippedItemsMark setFrameOrigin: NSMakePoint(
|
2004-07-27 15:15:29 +00:00
|
|
|
[self frame].size.width - ClippedItemsViewWidth, clipViewFrame.origin.y)];
|
2009-01-02 14:05:39 +00:00
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
if ([_clippedItemsMark superview] == nil)
|
|
|
|
[self addSubview: _clippedItemsMark];
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
2004-03-12 22:55:02 +00:00
|
|
|
else if (([_clippedItemsMark superview] != nil)
|
2010-05-12 23:06:02 +00:00
|
|
|
&& ([visibleBackViews count] == count))
|
2004-04-13 13:12:53 +00:00
|
|
|
{
|
2004-02-25 03:27:23 +00:00
|
|
|
[_clippedItemsMark removeFromSuperview];
|
2004-04-13 13:12:53 +00:00
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
[_clipView setFrame: NSMakeRect(clipViewFrame.origin.x,
|
2009-01-02 14:05:39 +00:00
|
|
|
clipViewFrame.origin.y,
|
|
|
|
[self frame].size.width,
|
|
|
|
clipViewFrame.size.height)];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-12 22:32:01 +00:00
|
|
|
- (void) _reload
|
|
|
|
{
|
2010-05-12 23:06:02 +00:00
|
|
|
// First, we resize
|
|
|
|
[self _handleBackViewsFrame];
|
|
|
|
[self _takeInAccountFlexibleSpaces];
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
[self _handleViewsVisibility];
|
2010-05-12 23:06:02 +00:00
|
|
|
/* We manage the clipped items view in the case it should become visible or
|
|
|
|
invisible */
|
|
|
|
[self _manageClipView];
|
|
|
|
|
2004-04-13 13:12:53 +00:00
|
|
|
[self setNeedsDisplay: YES];
|
2004-03-12 22:55:02 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
// Accessors private methods
|
|
|
|
|
2020-12-12 01:20:01 +00:00
|
|
|
- (CGFloat) _heightFromLayout
|
2004-04-13 13:12:53 +00:00
|
|
|
{
|
2020-12-12 01:20:01 +00:00
|
|
|
CGFloat height = _heightFromLayout;
|
2004-05-23 18:22:45 +00:00
|
|
|
|
|
|
|
if (_borderMask & GSToolbarViewBottomBorder)
|
|
|
|
{
|
|
|
|
height++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_borderMask & GSToolbarViewTopBorder)
|
|
|
|
{
|
|
|
|
height++;
|
|
|
|
}
|
2004-09-05 17:56:11 +00:00
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
return height;
|
2004-04-13 13:12:53 +00:00
|
|
|
}
|
|
|
|
|
2004-12-30 14:02:00 +00:00
|
|
|
/*
|
|
|
|
* Will return the visible (not clipped) back views in the toolbar view even
|
|
|
|
* when the toolbar is not visible.
|
|
|
|
* May be should be renamed _notClippedBackViews method.
|
|
|
|
*/
|
2004-05-23 18:22:45 +00:00
|
|
|
- (NSArray *) _visibleBackViews
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
|
|
|
NSArray *items = [_toolbar items];
|
2010-05-21 15:01:45 +00:00
|
|
|
NSView *backView, *view;
|
2020-12-12 00:54:37 +00:00
|
|
|
NSUInteger i, n;
|
2004-04-13 13:12:53 +00:00
|
|
|
float backViewsWidth = 0, toolbarWidth = [self frame].size.width;
|
2004-05-23 18:22:45 +00:00
|
|
|
|
2010-05-12 23:06:02 +00:00
|
|
|
NSMutableArray *visibleBackViews = [NSMutableArray array];
|
2020-12-12 00:54:37 +00:00
|
|
|
|
|
|
|
n = [items count];
|
2004-02-25 03:27:23 +00:00
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
2010-05-21 15:01:45 +00:00
|
|
|
NSToolbarItem *item = [items objectAtIndex:i];
|
|
|
|
backView = [item _backView];
|
|
|
|
view = [item view];
|
|
|
|
if (view != nil)
|
|
|
|
backViewsWidth += [item minSize].width + 2*InsetItemViewX;
|
|
|
|
else
|
|
|
|
backViewsWidth += [backView frame].size.width;
|
2004-02-25 03:27:23 +00:00
|
|
|
|
2004-07-27 15:15:29 +00:00
|
|
|
if ((backViewsWidth + ClippedItemsViewWidth <= toolbarWidth)
|
2004-04-13 13:12:53 +00:00
|
|
|
|| (i == n - 1 && backViewsWidth <= toolbarWidth))
|
2004-02-25 03:27:23 +00:00
|
|
|
{
|
2010-05-12 23:06:02 +00:00
|
|
|
[visibleBackViews addObject: backView];
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-12 23:06:02 +00:00
|
|
|
return visibleBackViews;
|
2004-02-25 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 21:58:12 +00:00
|
|
|
- (NSColor *) standardBackgroundColor
|
|
|
|
{
|
|
|
|
NSLog(@"Use of deprecated method %@", NSStringFromSelector(_cmd));
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2004-07-07 21:25:42 +00:00
|
|
|
- (BOOL) _usesStandardBackgroundColor
|
|
|
|
{
|
2009-02-07 21:58:12 +00:00
|
|
|
NSLog(@"Use of deprecated method %@", NSStringFromSelector(_cmd));
|
|
|
|
return NO;
|
2004-07-07 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
2004-05-23 18:22:45 +00:00
|
|
|
- (void) _setUsesStandardBackgroundColor: (BOOL)standard
|
|
|
|
{
|
2009-02-07 21:58:12 +00:00
|
|
|
NSLog(@"Use of deprecated method %@", NSStringFromSelector(_cmd));
|
2004-05-23 18:22:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 20:15:53 +00:00
|
|
|
- (NSMenu *) menuForEvent: (NSEvent *)event
|
|
|
|
{
|
2020-12-06 21:10:13 +00:00
|
|
|
NSMenu *menu = [[NSMenu alloc] initWithTitle: @""];
|
|
|
|
id <NSMenuItem> customize = [menu insertItemWithTitle: _(@"Customize Toolbar")
|
|
|
|
action: @selector(runCustomizationPalette:)
|
|
|
|
keyEquivalent: @""
|
|
|
|
atIndex: 0];
|
2011-11-18 20:15:53 +00:00
|
|
|
[customize setTarget: _toolbar];
|
2020-12-06 21:10:13 +00:00
|
|
|
return AUTORELEASE(menu);
|
2011-11-18 20:15:53 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 03:27:23 +00:00
|
|
|
@end
|