mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 20:01:11 +00:00
General clean up of GSToolbarView code.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27501 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3c16aeb873
commit
4fc5a6f196
5 changed files with 322 additions and 396 deletions
|
@ -1,3 +1,11 @@
|
|||
2009-01-02 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSWindow+Toolbar.m,
|
||||
* Source/NSToolbar.m: Rewrote interaction with GSToolbarView.
|
||||
* Source/NSToolbar.m (_toolbarItemForIdentifier:): Fix memory leak.
|
||||
* Headers/Additions/GNUstepGUI/GSToolbarView.h,
|
||||
* Source/GSToolbarView.m: General cleanup of code.
|
||||
|
||||
2009-01-02 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSButtonCell.m: Fix to use the backgroundColor method when
|
||||
|
|
|
@ -55,21 +55,15 @@ typedef enum {
|
|||
@interface GSToolbarView : NSView
|
||||
{
|
||||
NSToolbar *_toolbar;
|
||||
NSClipView *_clipView, *_clipViewForEditMode;
|
||||
NSClipView *_clipView;
|
||||
GSToolbarClippedItemsButton *_clippedItemsMark;
|
||||
NSMutableArray *_visibleBackViews;
|
||||
BOOL _willBeVisible;
|
||||
unsigned int _borderMask;
|
||||
NSToolbarDisplayMode _displayMode;
|
||||
NSToolbarSizeMode _sizeMode;
|
||||
NSRect _rectAvailable;
|
||||
float _heightFromLayout;
|
||||
}
|
||||
|
||||
- (id) initWithFrame: (NSRect)frame;
|
||||
- (id) initWithFrame: (NSRect)frame
|
||||
displayMode: (NSToolbarDisplayMode)displayMode
|
||||
sizeMode: (NSToolbarSizeMode)sizeMode;
|
||||
|
||||
// Accessors
|
||||
- (NSToolbar *) toolbar;
|
||||
|
|
|
@ -78,22 +78,22 @@ static void initSystemExtensionsColors(void)
|
|||
colors as keys and with colors in string format as values. */
|
||||
toolbarBorderColor = [NSColor colorWithCalibratedRed: 0.5
|
||||
green: 0.5
|
||||
blue: 0.5
|
||||
alpha: 1.0];
|
||||
blue: 0.5
|
||||
alpha: 1.0];
|
||||
|
||||
// Window background color by tranparency
|
||||
// Window background color by tranparency
|
||||
toolbarBackgroundColor = [NSColor clearColor];
|
||||
|
||||
// Window backgound color hardcoded
|
||||
/* toolbarBackgroundColor = [NSColor colorWithCalibratedRed: 0.8
|
||||
green: 0.8
|
||||
blue: 0.8
|
||||
alpha: 1.0]; */
|
||||
|
||||
blue: 0.8
|
||||
alpha: 1.0]; */
|
||||
|
||||
colors = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
toolbarBackgroundColor, @"toolbarBackgroundColor",toolbarBorderColor,
|
||||
@"toolbarBorderColor", nil];
|
||||
|
||||
|
||||
SystemExtensionsColors = [NSColorList colorListNamed: @"System extensions"];
|
||||
if (SystemExtensionsColors == nil)
|
||||
{
|
||||
|
@ -111,19 +111,33 @@ static void initSystemExtensionsColors(void)
|
|||
e = [colors keyEnumerator];
|
||||
|
||||
while ((colorKey = (NSString *)[e nextObject]))
|
||||
{
|
||||
if ([SystemExtensionsColors colorWithKey: colorKey])
|
||||
continue;
|
||||
{
|
||||
if ([SystemExtensionsColors colorWithKey: colorKey])
|
||||
continue;
|
||||
|
||||
color = [colors objectForKey: colorKey];
|
||||
[SystemExtensionsColors setColor: color forKey: colorKey];
|
||||
color = [colors objectForKey: colorKey];
|
||||
[SystemExtensionsColors setColor: color forKey: colorKey];
|
||||
|
||||
changed = YES;
|
||||
}
|
||||
changed = YES;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
[SystemExtensionsColors writeToFile: nil];
|
||||
[SystemExtensionsColors writeToFile: nil];
|
||||
}
|
||||
|
||||
|
||||
/* Never released, but that's not a problem because the variables are
|
||||
static and then will be deallocated with the class when the application
|
||||
quits. */
|
||||
StandardBackgroundColor =
|
||||
[NSColor colorWithCalibratedRed: 0.8 green: 0.8 blue: 0.8 alpha: 1.0];
|
||||
RETAIN(StandardBackgroundColor);
|
||||
BackgroundColor =
|
||||
[SystemExtensionsColors colorWithKey: @"toolbarBackgroundColor"];
|
||||
BorderColor =
|
||||
[SystemExtensionsColors colorWithKey: @"toolbarBorderColor"];
|
||||
RETAIN(BackgroundColor);
|
||||
RETAIN(BorderColor);
|
||||
}
|
||||
|
||||
@implementation NSColor (GSToolbarViewAdditions)
|
||||
|
@ -144,10 +158,14 @@ static void initSystemExtensionsColors(void)
|
|||
@interface NSToolbar (GNUstepPrivate)
|
||||
- (void) _build;
|
||||
|
||||
- (void) _concludeRemoveItem: (NSToolbarItem *)item atIndex: (int)index broadcast: (BOOL)broadcast;
|
||||
- (void) _concludeRemoveItem: (NSToolbarItem *)item
|
||||
atIndex: (int)index
|
||||
broadcast: (BOOL)broadcast;
|
||||
- (int) _indexOfItem: (NSToolbarItem *)item;
|
||||
- (void) _insertPassivelyItem: (NSToolbarItem *)item atIndex: (int)newIndex;
|
||||
- (void) _moveItemFromIndex: (int)index toIndex: (int)newIndex broadcast: (BOOL)broacast;
|
||||
- (void) _moveItemFromIndex: (int)index
|
||||
toIndex: (int)newIndex
|
||||
broadcast: (BOOL)broacast;
|
||||
|
||||
- (void) _toolbarViewWillMoveToSuperview: (NSView *)newSuperview;
|
||||
|
||||
|
@ -184,8 +202,6 @@ static void initSystemExtensionsColors(void)
|
|||
// Accessors
|
||||
- (float) _heightFromLayout;
|
||||
- (NSArray *) _visibleBackViews;
|
||||
- (void) _setSizeMode: (NSToolbarSizeMode)sizeMode;
|
||||
- (NSToolbarSizeMode) _sizeMode;
|
||||
- (BOOL) _usesStandardBackgroundColor;
|
||||
- (void) _setUsesStandardBackgroundColor: (BOOL)standard;
|
||||
@end
|
||||
|
@ -206,13 +222,6 @@ static void initSystemExtensionsColors(void)
|
|||
- (void) setToolbar: (NSToolbar *)toolbar;
|
||||
@end
|
||||
|
||||
@interface GSToolbarClipView : NSClipView
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GSToolbarClippedItemsButton
|
||||
- (id) init
|
||||
{
|
||||
|
@ -249,17 +258,17 @@ static void initSystemExtensionsColors(void)
|
|||
|
||||
- (void) mouseDown: (NSEvent *)event
|
||||
{
|
||||
NSMenu *clippedItemsMenu = [self menuForEvent: event];
|
||||
NSMenu *clippedItemsMenu = [self menuForEvent: event];
|
||||
|
||||
[super highlight: YES];
|
||||
[super highlight: YES];
|
||||
|
||||
if (clippedItemsMenu != nil)
|
||||
if (clippedItemsMenu != nil)
|
||||
{
|
||||
[NSMenu popUpContextMenu: clippedItemsMenu withEvent: event
|
||||
forView: self];
|
||||
forView: self];
|
||||
}
|
||||
|
||||
[super highlight: NO];
|
||||
[super highlight: NO];
|
||||
}
|
||||
|
||||
- (NSMenu *) menuForEvent: (NSEvent *)event
|
||||
|
@ -281,8 +290,6 @@ static void initSystemExtensionsColors(void)
|
|||
id item;
|
||||
NSArray *visibleItems;
|
||||
|
||||
AUTORELEASE(menu);
|
||||
|
||||
visibleItems = [_toolbar visibleItems];
|
||||
|
||||
e = [[_toolbar items] objectEnumerator];
|
||||
|
@ -292,16 +299,16 @@ static void initSystemExtensionsColors(void)
|
|||
{
|
||||
id menuItem;
|
||||
|
||||
menuItem = [item menuFormRepresentation];
|
||||
menuItem = [item menuFormRepresentation];
|
||||
if (menuItem == nil)
|
||||
menuItem = [item _defaultMenuFormRepresentation];
|
||||
|
||||
if (menuItem != nil)
|
||||
menuItem = [item _defaultMenuFormRepresentation];
|
||||
|
||||
if (menuItem != nil)
|
||||
[menu addItem: menuItem];
|
||||
}
|
||||
}
|
||||
|
||||
return menu;
|
||||
return AUTORELEASE(menu);
|
||||
}
|
||||
|
||||
// Accessors
|
||||
|
@ -315,103 +322,41 @@ static void initSystemExtensionsColors(void)
|
|||
|
||||
// ---
|
||||
|
||||
@implementation GSToolbarClipView
|
||||
|
||||
// Nothing here
|
||||
|
||||
@end
|
||||
|
||||
// Implementation GSToolbarView
|
||||
|
||||
@implementation GSToolbarView
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self != [GSToolbarView class])
|
||||
return;
|
||||
|
||||
initSystemExtensionsColors();
|
||||
StandardBackgroundColor =
|
||||
[NSColor colorWithCalibratedRed: 0.8 green: 0.8 blue: 0.8 alpha: 1.0];
|
||||
RETAIN(StandardBackgroundColor);
|
||||
/* Never released, but that's not a problem because the variable is static and
|
||||
then will be deallocated with the class when the application quits. */
|
||||
if (self == [GSToolbarView class])
|
||||
initSystemExtensionsColors();
|
||||
}
|
||||
|
||||
- (id) initWithFrame: (NSRect)frame
|
||||
{
|
||||
return [self initWithFrame: frame
|
||||
displayMode: NSToolbarDisplayModeDefault
|
||||
sizeMode: NSToolbarSizeModeDefault];
|
||||
}
|
||||
|
||||
- (id) initWithFrame: (NSRect)frame
|
||||
displayMode: (NSToolbarDisplayMode)displayMode
|
||||
sizeMode: (NSToolbarSizeMode)sizeMode
|
||||
{
|
||||
if ((self = [super initWithFrame: frame]) != nil)
|
||||
if ((self = [super initWithFrame: frame]) == nil)
|
||||
{
|
||||
_displayMode = displayMode;
|
||||
_sizeMode = sizeMode;
|
||||
|
||||
switch (_sizeMode)
|
||||
{
|
||||
case NSToolbarSizeModeDefault:
|
||||
_heightFromLayout = ToolbarViewDefaultHeight;
|
||||
break;
|
||||
case NSToolbarSizeModeRegular:
|
||||
_heightFromLayout = ToolbarViewRegularHeight;
|
||||
break;
|
||||
case NSToolbarSizeModeSmall:
|
||||
_heightFromLayout = ToolbarViewSmallHeight;
|
||||
break;
|
||||
default:
|
||||
// Raise exception
|
||||
_heightFromLayout = 0;
|
||||
}
|
||||
|
||||
[self setFrame: NSMakeRect(frame.origin.x, frame.origin.y,
|
||||
frame.size.width, _heightFromLayout)];
|
||||
|
||||
// ---
|
||||
|
||||
_clipView =
|
||||
[[GSToolbarClipView alloc] initWithFrame: NSMakeRect(0, 0, 100, 100)];
|
||||
|
||||
[_clipView setAutoresizingMask: (NSViewWidthSizable |
|
||||
NSViewHeightSizable)];
|
||||
|
||||
[self setBorderMask: GSToolbarViewTopBorder | GSToolbarViewBottomBorder
|
||||
| GSToolbarViewRightBorder | GSToolbarViewLeftBorder];
|
||||
// Adjust the clip view frame
|
||||
|
||||
[self addSubview: _clipView];
|
||||
|
||||
_clippedItemsMark = [[GSToolbarClippedItemsButton alloc] init];
|
||||
|
||||
BackgroundColor =
|
||||
[SystemExtensionsColors colorWithKey: @"toolbarBackgroundColor"];
|
||||
BorderColor =
|
||||
[SystemExtensionsColors colorWithKey: @"toolbarBorderColor"];
|
||||
RETAIN(BackgroundColor);
|
||||
RETAIN(BorderColor);
|
||||
/* Never released, but that's not a problem because the variables are
|
||||
static and then will be deallocated with the class when the application
|
||||
quits. */
|
||||
|
||||
// ---
|
||||
|
||||
[self registerForDraggedTypes:
|
||||
[NSArray arrayWithObject: GSMovableToolbarItemPboardType]];
|
||||
|
||||
return self;
|
||||
return nil;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id) retain
|
||||
{
|
||||
return [super retain];
|
||||
_heightFromLayout = ToolbarViewDefaultHeight;
|
||||
[self setFrame: NSMakeRect(frame.origin.x, frame.origin.y,
|
||||
frame.size.width, _heightFromLayout)];
|
||||
|
||||
_clipView = [[NSClipView alloc] initWithFrame:
|
||||
NSMakeRect(0, 0, frame.size.width,
|
||||
_heightFromLayout)];
|
||||
[_clipView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
|
||||
[self addSubview: _clipView];
|
||||
// Adjust the clip view frame
|
||||
[self setBorderMask: GSToolbarViewTopBorder | GSToolbarViewBottomBorder
|
||||
| GSToolbarViewRightBorder | GSToolbarViewLeftBorder];
|
||||
|
||||
_clippedItemsMark = [[GSToolbarClippedItemsButton alloc] init];
|
||||
|
||||
[self registerForDraggedTypes:
|
||||
[NSArray arrayWithObject: GSMovableToolbarItemPboardType]];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
|
@ -440,9 +385,9 @@ static void initSystemExtensionsColors(void)
|
|||
if ([self _insertionIndexAtPoint: [info draggingLocation]] != NSNotFound
|
||||
&& [allowedItemIdentifiers containsObject: itemIdentifier]);
|
||||
{
|
||||
return NSDragOperationGeneric;
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
|
@ -457,9 +402,9 @@ static void initSystemExtensionsColors(void)
|
|||
if ([self _insertionIndexAtPoint: [info draggingLocation]] != NSNotFound
|
||||
&& [allowedItemIdentifiers containsObject: itemIdentifier]);
|
||||
{
|
||||
return NSDragOperationGeneric;
|
||||
return NSDragOperationGeneric;
|
||||
}
|
||||
|
||||
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
|
@ -510,41 +455,40 @@ static void initSystemExtensionsColors(void)
|
|||
|
||||
- (void) drawRect: (NSRect)aRect
|
||||
{
|
||||
NSBezierPath *rect = [NSBezierPath bezierPathWithRect: aRect];
|
||||
NSRect viewFrame = [self frame];
|
||||
|
||||
// We draw the background
|
||||
if (![BackgroundColor isEqual: [NSColor clearColor]])
|
||||
{
|
||||
[BackgroundColor set];
|
||||
[rect fill];
|
||||
[NSBezierPath fillRect: aRect];
|
||||
}
|
||||
|
||||
// We draw the border
|
||||
[BorderColor set];
|
||||
if (_borderMask & GSToolbarViewBottomBorder)
|
||||
{
|
||||
[NSBezierPath strokeLineFromPoint: NSMakePoint(0, 0.5)
|
||||
toPoint: NSMakePoint(viewFrame.size.width, 0.5)];
|
||||
}
|
||||
{
|
||||
[NSBezierPath strokeLineFromPoint: NSMakePoint(0, 0.5)
|
||||
toPoint: NSMakePoint(viewFrame.size.width, 0.5)];
|
||||
}
|
||||
if (_borderMask & GSToolbarViewTopBorder)
|
||||
{
|
||||
[NSBezierPath strokeLineFromPoint: NSMakePoint(0,
|
||||
viewFrame.size.height - 0.5)
|
||||
toPoint: NSMakePoint(viewFrame.size.width,
|
||||
{
|
||||
[NSBezierPath strokeLineFromPoint: NSMakePoint(0,
|
||||
viewFrame.size.height - 0.5)
|
||||
toPoint: NSMakePoint(viewFrame.size.width,
|
||||
viewFrame.size.height - 0.5)];
|
||||
}
|
||||
}
|
||||
if (_borderMask & GSToolbarViewLeftBorder)
|
||||
{
|
||||
[NSBezierPath strokeLineFromPoint: NSMakePoint(0.5, 0)
|
||||
toPoint: NSMakePoint(0.5, viewFrame.size.height)];
|
||||
}
|
||||
{
|
||||
[NSBezierPath strokeLineFromPoint: NSMakePoint(0.5, 0)
|
||||
toPoint: NSMakePoint(0.5, viewFrame.size.height)];
|
||||
}
|
||||
if (_borderMask & GSToolbarViewRightBorder)
|
||||
{
|
||||
[NSBezierPath strokeLineFromPoint: NSMakePoint(viewFrame.size.width - 0.5,0)
|
||||
toPoint: NSMakePoint(viewFrame.size.width - 0.5,
|
||||
{
|
||||
[NSBezierPath strokeLineFromPoint: NSMakePoint(viewFrame.size.width - 0.5,0)
|
||||
toPoint: NSMakePoint(viewFrame.size.width - 0.5,
|
||||
viewFrame.size.height)];
|
||||
}
|
||||
}
|
||||
|
||||
[super drawRect: aRect];
|
||||
}
|
||||
|
@ -588,10 +532,10 @@ static void initSystemExtensionsColors(void)
|
|||
[nc removeObserver: self name: NSWindowDidResizeNotification object: nil];
|
||||
[nc addObserver: self selector: @selector(windowDidResize:)
|
||||
name: NSWindowDidResizeNotification
|
||||
object: _window];
|
||||
object: _window];
|
||||
}
|
||||
|
||||
// More methods... Accessors
|
||||
// Accessors
|
||||
|
||||
- (unsigned int) borderMask
|
||||
{
|
||||
|
@ -606,51 +550,34 @@ static void initSystemExtensionsColors(void)
|
|||
- (void) setBorderMask: (unsigned int)borderMask
|
||||
{
|
||||
NSRect toolbarViewFrame = [self frame];
|
||||
NSRect rect = NSMakeRect(0, 0, toolbarViewFrame.size.width, 100);
|
||||
NSRect rect = NSMakeRect(0, 0, toolbarViewFrame.size.width,
|
||||
toolbarViewFrame.size.height);
|
||||
|
||||
_borderMask = borderMask;
|
||||
|
||||
// Take in account the size mode
|
||||
|
||||
switch (_sizeMode)
|
||||
{
|
||||
case NSToolbarSizeModeDefault:
|
||||
rect.size.height = ToolbarViewDefaultHeight;
|
||||
break;
|
||||
case NSToolbarSizeModeRegular:
|
||||
rect.size.height = ToolbarViewRegularHeight;
|
||||
break;
|
||||
case NSToolbarSizeModeSmall:
|
||||
rect.size.height = ToolbarViewSmallHeight;
|
||||
break;
|
||||
default:
|
||||
; // Invalid
|
||||
}
|
||||
|
||||
// Take in account the border
|
||||
|
||||
if (_borderMask & GSToolbarViewBottomBorder)
|
||||
{
|
||||
rect = NSMakeRect(rect.origin.x, ++rect.origin.y, rect.size.width,
|
||||
--rect.size.height);
|
||||
--rect.size.height);
|
||||
}
|
||||
|
||||
if (_borderMask & GSToolbarViewTopBorder)
|
||||
{
|
||||
rect = NSMakeRect(rect.origin.x, rect.origin.y, rect.size.width,
|
||||
--rect.size.height);
|
||||
--rect.size.height);
|
||||
}
|
||||
|
||||
if (_borderMask & GSToolbarViewLeftBorder)
|
||||
{
|
||||
rect = NSMakeRect(++rect.origin.x, rect.origin.y, --rect.size.width,
|
||||
rect.size.height);
|
||||
rect.size.height);
|
||||
}
|
||||
|
||||
if (_borderMask & GSToolbarViewRightBorder)
|
||||
{
|
||||
rect = NSMakeRect(rect.origin.x, rect.origin.y, --rect.size.width,
|
||||
rect.size.height);
|
||||
rect.size.height);
|
||||
}
|
||||
|
||||
[_clipView setFrame: rect];
|
||||
|
@ -658,9 +585,6 @@ static void initSystemExtensionsColors(void)
|
|||
|
||||
- (void) setToolbar: (NSToolbar *)toolbar
|
||||
{
|
||||
if ([toolbar sizeMode] != _sizeMode)
|
||||
; // FIXME: Raise exception here
|
||||
|
||||
if (_toolbar == toolbar)
|
||||
return;
|
||||
|
||||
|
@ -702,16 +626,16 @@ static void initSystemExtensionsColors(void)
|
|||
|| [item _isModified]
|
||||
|| [item _isFlexibleSpace])
|
||||
{
|
||||
// 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
|
||||
// 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
|
||||
[item _layout];
|
||||
}
|
||||
|
||||
itemBackViewFrame = [itemBackView frame];
|
||||
[itemBackView setFrame: NSMakeRect(x, itemBackViewFrame.origin.y,
|
||||
itemBackViewFrame.size.width, itemBackViewFrame.size.height)];
|
||||
|
||||
|
||||
x += [itemBackView frame].size.width;
|
||||
|
||||
if (itemBackViewFrame.size.height > newHeight)
|
||||
|
@ -795,7 +719,7 @@ static void initSystemExtensionsColors(void)
|
|||
clipViewFrame.origin.y,
|
||||
width,
|
||||
clipViewFrame.size.height)];
|
||||
|
||||
|
||||
// Adjust the clipped items mark frame handling
|
||||
|
||||
[_clippedItemsMark layout];
|
||||
|
@ -803,9 +727,9 @@ static void initSystemExtensionsColors(void)
|
|||
clipViewFrame = [_clipView frame]; // We get the new _clipView frame
|
||||
[_clippedItemsMark setFrameOrigin: NSMakePoint(
|
||||
[self frame].size.width - ClippedItemsViewWidth, clipViewFrame.origin.y)];
|
||||
|
||||
|
||||
// ---
|
||||
|
||||
|
||||
if ([_clippedItemsMark superview] == nil)
|
||||
[self addSubview: _clippedItemsMark];
|
||||
|
||||
|
@ -816,10 +740,10 @@ static void initSystemExtensionsColors(void)
|
|||
[_clippedItemsMark removeFromSuperview];
|
||||
|
||||
[_clipView setFrame: NSMakeRect(clipViewFrame.origin.x,
|
||||
clipViewFrame.origin.y, [self frame].size.width,
|
||||
clipViewFrame.size.height)];
|
||||
clipViewFrame.origin.y,
|
||||
[self frame].size.width,
|
||||
clipViewFrame.size.height)];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void) _reload
|
||||
|
@ -870,7 +794,7 @@ static void initSystemExtensionsColors(void)
|
|||
|
||||
[backView setFrame: NSMakeRect(x, backViewFrame.origin.y,
|
||||
lengthAvailable / flexibleSpaceItemsNumber,
|
||||
backViewFrame.size.height)];
|
||||
backViewFrame.size.height)];
|
||||
mustAdjustNext = YES;
|
||||
}
|
||||
else if (mustAdjustNext)
|
||||
|
@ -955,16 +879,6 @@ static void initSystemExtensionsColors(void)
|
|||
|
||||
}
|
||||
|
||||
- (void) _setSizeMode: (NSToolbarSizeMode)sizeMode
|
||||
{
|
||||
_sizeMode = sizeMode;
|
||||
}
|
||||
|
||||
- (NSToolbarSizeMode) _sizeMode
|
||||
{
|
||||
return _sizeMode;
|
||||
}
|
||||
|
||||
- (BOOL) _usesStandardBackgroundColor
|
||||
{
|
||||
return [BackgroundColor isEqual: [self standardBackgroundColor]];
|
||||
|
|
|
@ -520,15 +520,13 @@ static GSValidationCenter *vc = nil;
|
|||
- (void) _reload;
|
||||
|
||||
// Accessors
|
||||
- (void) _setSizeMode: (NSToolbarSizeMode)sizeMode;
|
||||
- (NSToolbarSizeMode) _sizeMode;
|
||||
- (NSArray *) _visibleBackViews;
|
||||
- (BOOL) _usesStandardBackgroundColor;
|
||||
- (void) _setUsesStandardBackgroundColor: (BOOL)standard;
|
||||
@end
|
||||
|
||||
@interface NSWindow (ToolbarPrivate)
|
||||
- (void) _adjustToolbarView;
|
||||
- (void) _adjustToolbarView: (GSToolbarView*)view;
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
@ -1044,7 +1042,7 @@ static GSValidationCenter *vc = nil;
|
|||
item = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdent];
|
||||
}
|
||||
|
||||
return item;
|
||||
return AUTORELEASE(item);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1216,8 +1214,11 @@ static GSValidationCenter *vc = nil;
|
|||
{
|
||||
_displayMode = displayMode;
|
||||
|
||||
[_toolbarView _reload];
|
||||
[[_toolbarView window] _adjustToolbarView];
|
||||
if ([self isVisible])
|
||||
{
|
||||
[_toolbarView _reload];
|
||||
[[_toolbarView window] _adjustToolbarView: _toolbarView];
|
||||
}
|
||||
|
||||
if (broadcast)
|
||||
{
|
||||
|
@ -1233,10 +1234,11 @@ static GSValidationCenter *vc = nil;
|
|||
{
|
||||
_sizeMode = sizeMode;
|
||||
|
||||
[_toolbarView _setSizeMode: _sizeMode];
|
||||
|
||||
[_toolbarView _reload];
|
||||
[[_toolbarView window] _adjustToolbarView];
|
||||
if ([self isVisible])
|
||||
{
|
||||
[_toolbarView _reload];
|
||||
[[_toolbarView window] _adjustToolbarView: _toolbarView];
|
||||
}
|
||||
|
||||
if (broadcast)
|
||||
{
|
||||
|
|
|
@ -44,8 +44,9 @@
|
|||
@end
|
||||
|
||||
@interface NSWindow (ToolbarPrivate)
|
||||
- (void) _adjustToolbarView;
|
||||
- (void) _toggleToolbarView;
|
||||
- (void) _adjustToolbarView: (GSToolbarView*)view;
|
||||
- (void) _addToolbarView: (GSToolbarView*)view;
|
||||
- (void) _removeToolbarView: (GSToolbarView*)view;
|
||||
- (NSView *) _contentViewWithoutToolbar;
|
||||
@end
|
||||
|
||||
|
@ -59,24 +60,99 @@
|
|||
- (void) toggleToolbarShown: (id)sender
|
||||
{
|
||||
NSToolbar *toolbar = [self toolbar];
|
||||
BOOL isVisible = [toolbar isVisible];
|
||||
|
||||
if (!toolbar)
|
||||
return;
|
||||
|
||||
[self _toggleToolbarView];
|
||||
|
||||
if (isVisible)
|
||||
{
|
||||
[self _removeToolbarView: [toolbar _toolbarView]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self _addToolbarView: [toolbar _toolbarView]];
|
||||
}
|
||||
|
||||
// Important to set _visible after the toolbar view has been toggled because
|
||||
// NSWindow method contentViewWithoutToolbar uses [NSToolbar visible]
|
||||
// NSWindow method _contentViewWithoutToolbar uses [NSToolbar visible]
|
||||
// when we toggle the toolbar
|
||||
// example : the toolbar needs to be still known visible in order to hide
|
||||
// it.
|
||||
[toolbar setVisible: ![toolbar isVisible]];
|
||||
[toolbar setVisible: !isVisible];
|
||||
|
||||
[self display];
|
||||
}
|
||||
|
||||
// Accessors
|
||||
|
||||
- (NSToolbar *) toolbar
|
||||
{
|
||||
return _toolbar;
|
||||
}
|
||||
|
||||
- (void) setToolbar: (NSToolbar*)toolbar
|
||||
{
|
||||
if (toolbar == _toolbar)
|
||||
return;
|
||||
|
||||
if (_toolbar != nil)
|
||||
{
|
||||
GSToolbarView *toolbarView = [_toolbar _toolbarView];
|
||||
|
||||
// We throw the last toolbar out
|
||||
if ([_toolbar isVisible])
|
||||
{
|
||||
[self _removeToolbarView: toolbarView];
|
||||
}
|
||||
[toolbarView setToolbar: nil];
|
||||
// Release the toolbarView, this may release the toolbar
|
||||
RELEASE(toolbarView);
|
||||
}
|
||||
|
||||
ASSIGN(_toolbar, toolbar);
|
||||
|
||||
if (toolbar != nil)
|
||||
{
|
||||
GSToolbarView *toolbarView = [toolbar _toolbarView];
|
||||
|
||||
if (toolbarView != nil)
|
||||
{
|
||||
NSLog(@"Error: the new toolbar is still owned by a toolbar view");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Instantiate the toolbar view
|
||||
toolbarView = [[GSToolbarView alloc]
|
||||
initWithFrame:
|
||||
NSMakeRect(0, 0,
|
||||
[NSWindow contentRectForFrameRect: [self frame]
|
||||
styleMask: [self styleMask]].size.width, 100)];
|
||||
// _toggleToolbarView method will set the toolbar view to the right
|
||||
// frame
|
||||
[toolbarView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin];
|
||||
[toolbarView setBorderMask: GSToolbarViewBottomBorder];
|
||||
// Load the toolbar inside the toolbar view
|
||||
// Will set the _toolbarView variable for the toolbar
|
||||
[toolbarView setToolbar: toolbar];
|
||||
}
|
||||
|
||||
// Make the toolbar view visible
|
||||
if ([toolbar isVisible])
|
||||
{
|
||||
[self _addToolbarView: toolbarView];
|
||||
}
|
||||
}
|
||||
|
||||
// To show the changed toolbar
|
||||
[self displayIfNeeded];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// Private methods
|
||||
@implementation NSWindow (ToolbarPrivate)
|
||||
|
||||
- (NSView *) _contentViewWithoutToolbar
|
||||
{
|
||||
NSToolbar *toolbar = [self toolbar];
|
||||
|
@ -115,117 +191,43 @@
|
|||
return [self contentView];
|
||||
}
|
||||
|
||||
- (NSToolbar *) toolbar
|
||||
- (void) _adjustToolbarView: (GSToolbarView *)toolbarView
|
||||
{
|
||||
return _toolbar;
|
||||
}
|
||||
|
||||
- (void) setToolbar: (NSToolbar*)toolbar
|
||||
{
|
||||
if (toolbar == _toolbar)
|
||||
return;
|
||||
|
||||
if (_toolbar != nil)
|
||||
// Frame and height
|
||||
NSRect toolbarViewFrame = [toolbarView frame];
|
||||
float toolbarViewHeight = toolbarViewFrame.size.height;
|
||||
float newToolbarViewHeight = [toolbarView _heightFromLayout];
|
||||
|
||||
if (toolbarViewHeight != newToolbarViewHeight)
|
||||
{
|
||||
GSToolbarView *toolbarView = [_toolbar _toolbarView];
|
||||
|
||||
// We throw the last toolbar out
|
||||
if ([_toolbar isVisible])
|
||||
{
|
||||
[self _toggleToolbarView];
|
||||
}
|
||||
[toolbarView setToolbar: nil];
|
||||
// Release the toolbarView, this will release the toolbar
|
||||
RELEASE(toolbarView);
|
||||
NSView *contentViewWithoutToolbar = [self _contentViewWithoutToolbar];
|
||||
NSRect windowFrame = [self frame];
|
||||
|
||||
[toolbarView setFrame: NSMakeRect(
|
||||
toolbarViewFrame.origin.x,
|
||||
toolbarViewFrame.origin.y + (toolbarViewHeight - newToolbarViewHeight),
|
||||
toolbarViewFrame.size.width,
|
||||
newToolbarViewHeight)];
|
||||
|
||||
// Resize the window
|
||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewNotSizable];
|
||||
|
||||
[self setFrame: NSMakeRect(
|
||||
windowFrame.origin.x,
|
||||
windowFrame.origin.y + (toolbarViewHeight - newToolbarViewHeight),
|
||||
windowFrame.size.width,
|
||||
windowFrame.size.height - (toolbarViewHeight - newToolbarViewHeight))
|
||||
display: NO];
|
||||
|
||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
|
||||
|
||||
[self display];
|
||||
}
|
||||
|
||||
ASSIGN(_toolbar, toolbar);
|
||||
|
||||
if (toolbar != nil)
|
||||
{
|
||||
GSToolbarView *toolbarView = [toolbar _toolbarView];
|
||||
|
||||
if (toolbarView != nil)
|
||||
{
|
||||
NSLog(@"Error: the new toolbar is still owned by a toolbar view");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Instantiate the toolbar view
|
||||
toolbarView = [[GSToolbarView alloc]
|
||||
initWithFrame:
|
||||
NSMakeRect(0, 0,
|
||||
[NSWindow contentRectForFrameRect: [self frame]
|
||||
styleMask: [self styleMask]].size.width, 100)];
|
||||
// _toggleToolbarView method will set the toolbar view to the right
|
||||
// frame
|
||||
[toolbarView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin];
|
||||
[toolbarView setBorderMask: GSToolbarViewBottomBorder];
|
||||
// Load the toolbar inside the toolbar view
|
||||
// Will set the _toolbarView variable for the toolbar
|
||||
[toolbarView setToolbar: toolbar];
|
||||
}
|
||||
|
||||
// Make the toolbar view visible
|
||||
if ([toolbar isVisible])
|
||||
{
|
||||
[self _toggleToolbarView];
|
||||
}
|
||||
}
|
||||
|
||||
// To show the changed toolbar
|
||||
[self display];
|
||||
}
|
||||
|
||||
// Private methods
|
||||
|
||||
- (void) _adjustToolbarView
|
||||
{
|
||||
NSToolbar *toolbar = [self toolbar];
|
||||
|
||||
if ([toolbar isVisible])
|
||||
{
|
||||
// Views
|
||||
GSToolbarView *toolbarView = [toolbar _toolbarView];
|
||||
|
||||
// Frame and height
|
||||
NSRect toolbarViewFrame = [toolbarView frame];
|
||||
float toolbarViewHeight = toolbarViewFrame.size.height;
|
||||
float newToolbarViewHeight = [toolbarView _heightFromLayout];
|
||||
|
||||
if (toolbarViewHeight != newToolbarViewHeight)
|
||||
{
|
||||
NSView *contentViewWithoutToolbar = [self _contentViewWithoutToolbar];
|
||||
NSRect windowFrame = [self frame];
|
||||
|
||||
[toolbarView setFrame: NSMakeRect(
|
||||
toolbarViewFrame.origin.x,
|
||||
toolbarViewFrame.origin.y + (toolbarViewHeight - newToolbarViewHeight),
|
||||
toolbarViewFrame.size.width,
|
||||
newToolbarViewHeight)];
|
||||
|
||||
// Resize the window
|
||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewNotSizable];
|
||||
|
||||
[self setFrame: NSMakeRect(
|
||||
windowFrame.origin.x,
|
||||
windowFrame.origin.y + (toolbarViewHeight - newToolbarViewHeight),
|
||||
windowFrame.size.width,
|
||||
windowFrame.size.height - (toolbarViewHeight - newToolbarViewHeight))
|
||||
display: NO];
|
||||
|
||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
|
||||
|
||||
[self display];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void) _toggleToolbarView
|
||||
- (void) _addToolbarView: (GSToolbarView*)toolbarView
|
||||
{
|
||||
// Views
|
||||
GSToolbarView *toolbarView = [[self toolbar] _toolbarView];
|
||||
NSView *contentViewWithoutToolbar;
|
||||
|
||||
// Frame
|
||||
|
@ -233,85 +235,91 @@
|
|||
= [NSWindow contentRectForFrameRect: [self frame]
|
||||
styleMask: [self styleMask]];
|
||||
|
||||
if ([toolbarView superview] == nil)
|
||||
{
|
||||
float newToolbarViewHeight;
|
||||
NSRect contentViewWithoutToolbarFrame;
|
||||
float newToolbarViewHeight;
|
||||
NSRect contentViewWithoutToolbarFrame;
|
||||
|
||||
[toolbarView setFrameSize:
|
||||
NSMakeSize(windowContentFrame.size.width, 100)];
|
||||
// Will recalculate the layout
|
||||
[toolbarView _reload];
|
||||
newToolbarViewHeight = [toolbarView _heightFromLayout];
|
||||
|
||||
contentViewWithoutToolbar = _contentView;
|
||||
contentViewWithoutToolbarFrame = [contentViewWithoutToolbar frame];
|
||||
|
||||
// Switch the content view
|
||||
RETAIN(contentViewWithoutToolbar);
|
||||
[self setContentView:
|
||||
AUTORELEASE([[NSView alloc] initWithFrame:
|
||||
contentViewWithoutToolbarFrame])];
|
||||
|
||||
// Resize the window
|
||||
windowContentFrame.origin.y -= newToolbarViewHeight;
|
||||
windowContentFrame.size.height += newToolbarViewHeight;
|
||||
[self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
|
||||
styleMask: [self styleMask]]
|
||||
display: NO];
|
||||
[toolbarView setFrameSize:
|
||||
NSMakeSize(windowContentFrame.size.width, 100)];
|
||||
// Will recalculate the layout
|
||||
[toolbarView _reload];
|
||||
newToolbarViewHeight = [toolbarView _heightFromLayout];
|
||||
|
||||
// Plug the toolbar view
|
||||
[toolbarView setFrame: NSMakeRect(
|
||||
0,
|
||||
contentViewWithoutToolbarFrame.size.height,
|
||||
contentViewWithoutToolbarFrame.size.width,
|
||||
contentViewWithoutToolbar = _contentView;
|
||||
contentViewWithoutToolbarFrame = [contentViewWithoutToolbar frame];
|
||||
|
||||
// Switch the content view
|
||||
RETAIN(contentViewWithoutToolbar);
|
||||
[self setContentView:
|
||||
AUTORELEASE([[NSView alloc] initWithFrame:
|
||||
contentViewWithoutToolbarFrame])];
|
||||
|
||||
// Resize the window
|
||||
windowContentFrame.origin.y -= newToolbarViewHeight;
|
||||
windowContentFrame.size.height += newToolbarViewHeight;
|
||||
[self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
|
||||
styleMask: [self styleMask]]
|
||||
display: NO];
|
||||
|
||||
// Plug the toolbar view
|
||||
[toolbarView setFrame: NSMakeRect(
|
||||
0,
|
||||
contentViewWithoutToolbarFrame.size.height,
|
||||
contentViewWithoutToolbarFrame.size.width,
|
||||
newToolbarViewHeight)];
|
||||
[_contentView addSubview: toolbarView];
|
||||
RELEASE(toolbarView);
|
||||
|
||||
// Insert the previous content view
|
||||
/* We want contentViewWithoutToolbarFrame at the origin of our new
|
||||
content view. There's no guarantee that the old position was (0,0). */
|
||||
contentViewWithoutToolbarFrame.origin.x = 0;
|
||||
contentViewWithoutToolbarFrame.origin.y = 0;
|
||||
[contentViewWithoutToolbar setFrame: contentViewWithoutToolbarFrame];
|
||||
|
||||
[_contentView addSubview: contentViewWithoutToolbar];
|
||||
RELEASE(contentViewWithoutToolbar);
|
||||
}
|
||||
else
|
||||
{
|
||||
float toolbarViewHeight = [toolbarView frame].size.height;
|
||||
|
||||
contentViewWithoutToolbar = [self _contentViewWithoutToolbar];
|
||||
|
||||
// Unplug the toolbar view
|
||||
RETAIN(toolbarView);
|
||||
[toolbarView removeFromSuperviewWithoutNeedingDisplay];
|
||||
|
||||
// Resize the window
|
||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewMaxYMargin];
|
||||
[_contentView addSubview: toolbarView];
|
||||
RELEASE(toolbarView);
|
||||
|
||||
windowContentFrame.origin.y += toolbarViewHeight;
|
||||
windowContentFrame.size.height -= toolbarViewHeight;
|
||||
[self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
|
||||
styleMask: [self styleMask]]
|
||||
display: NO];
|
||||
|
||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewWidthSizable
|
||||
| NSViewHeightSizable];
|
||||
// Autoresizing mask will be set again by the setContentView: method
|
||||
|
||||
// Switch the content view
|
||||
RETAIN(contentViewWithoutToolbar);
|
||||
// Because setContentView: will release the parent view (aka _contentView) and
|
||||
// its subviews and actually contentViewWithoutToolbar is a subview of _contentView
|
||||
// Insert the previous content view
|
||||
/* We want contentViewWithoutToolbarFrame at the origin of our new
|
||||
content view. There's no guarantee that the old position was (0,0). */
|
||||
contentViewWithoutToolbarFrame.origin.x = 0;
|
||||
contentViewWithoutToolbarFrame.origin.y = 0;
|
||||
[contentViewWithoutToolbar setFrame: contentViewWithoutToolbarFrame];
|
||||
|
||||
[_contentView addSubview: contentViewWithoutToolbar];
|
||||
RELEASE(contentViewWithoutToolbar);
|
||||
}
|
||||
|
||||
[contentViewWithoutToolbar removeFromSuperviewWithoutNeedingDisplay];
|
||||
[self setContentView: contentViewWithoutToolbar];
|
||||
|
||||
RELEASE(contentViewWithoutToolbar);
|
||||
}
|
||||
- (void) _removeToolbarView: (GSToolbarView *)toolbarView
|
||||
{
|
||||
// Views
|
||||
NSView *contentViewWithoutToolbar;
|
||||
|
||||
// Frame
|
||||
NSRect windowContentFrame
|
||||
= [NSWindow contentRectForFrameRect: [self frame]
|
||||
styleMask: [self styleMask]];
|
||||
|
||||
float toolbarViewHeight = [toolbarView frame].size.height;
|
||||
|
||||
contentViewWithoutToolbar = [self _contentViewWithoutToolbar];
|
||||
|
||||
// Unplug the toolbar view
|
||||
RETAIN(toolbarView);
|
||||
[toolbarView removeFromSuperviewWithoutNeedingDisplay];
|
||||
|
||||
// Resize the window
|
||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewMaxYMargin];
|
||||
|
||||
windowContentFrame.origin.y += toolbarViewHeight;
|
||||
windowContentFrame.size.height -= toolbarViewHeight;
|
||||
[self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
|
||||
styleMask: [self styleMask]]
|
||||
display: NO];
|
||||
|
||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewWidthSizable
|
||||
| NSViewHeightSizable];
|
||||
// Autoresizing mask will be set again by the setContentView: method
|
||||
|
||||
// Switch the content view
|
||||
RETAIN(contentViewWithoutToolbar);
|
||||
// Because setContentView: will release the parent view (aka _contentView) and
|
||||
// its subviews and actually contentViewWithoutToolbar is a subview of _contentView
|
||||
|
||||
[contentViewWithoutToolbar removeFromSuperviewWithoutNeedingDisplay];
|
||||
[self setContentView: contentViewWithoutToolbar];
|
||||
|
||||
RELEASE(contentViewWithoutToolbar);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue