mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 06:10:59 +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
2c07551e5d
commit
2358f07c43
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>
|
2009-01-02 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSButtonCell.m: Fix to use the backgroundColor method when
|
* Source/NSButtonCell.m: Fix to use the backgroundColor method when
|
||||||
|
|
|
@ -55,21 +55,15 @@ typedef enum {
|
||||||
@interface GSToolbarView : NSView
|
@interface GSToolbarView : NSView
|
||||||
{
|
{
|
||||||
NSToolbar *_toolbar;
|
NSToolbar *_toolbar;
|
||||||
NSClipView *_clipView, *_clipViewForEditMode;
|
NSClipView *_clipView;
|
||||||
GSToolbarClippedItemsButton *_clippedItemsMark;
|
GSToolbarClippedItemsButton *_clippedItemsMark;
|
||||||
NSMutableArray *_visibleBackViews;
|
NSMutableArray *_visibleBackViews;
|
||||||
BOOL _willBeVisible;
|
|
||||||
unsigned int _borderMask;
|
unsigned int _borderMask;
|
||||||
NSToolbarDisplayMode _displayMode;
|
|
||||||
NSToolbarSizeMode _sizeMode;
|
|
||||||
NSRect _rectAvailable;
|
NSRect _rectAvailable;
|
||||||
float _heightFromLayout;
|
float _heightFromLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithFrame: (NSRect)frame;
|
- (id) initWithFrame: (NSRect)frame;
|
||||||
- (id) initWithFrame: (NSRect)frame
|
|
||||||
displayMode: (NSToolbarDisplayMode)displayMode
|
|
||||||
sizeMode: (NSToolbarSizeMode)sizeMode;
|
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
- (NSToolbar *) toolbar;
|
- (NSToolbar *) toolbar;
|
||||||
|
|
|
@ -124,6 +124,20 @@ static void initSystemExtensionsColors(void)
|
||||||
if (changed)
|
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)
|
@implementation NSColor (GSToolbarViewAdditions)
|
||||||
|
@ -144,10 +158,14 @@ static void initSystemExtensionsColors(void)
|
||||||
@interface NSToolbar (GNUstepPrivate)
|
@interface NSToolbar (GNUstepPrivate)
|
||||||
- (void) _build;
|
- (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;
|
- (int) _indexOfItem: (NSToolbarItem *)item;
|
||||||
- (void) _insertPassivelyItem: (NSToolbarItem *)item atIndex: (int)newIndex;
|
- (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;
|
- (void) _toolbarViewWillMoveToSuperview: (NSView *)newSuperview;
|
||||||
|
|
||||||
|
@ -184,8 +202,6 @@ static void initSystemExtensionsColors(void)
|
||||||
// Accessors
|
// Accessors
|
||||||
- (float) _heightFromLayout;
|
- (float) _heightFromLayout;
|
||||||
- (NSArray *) _visibleBackViews;
|
- (NSArray *) _visibleBackViews;
|
||||||
- (void) _setSizeMode: (NSToolbarSizeMode)sizeMode;
|
|
||||||
- (NSToolbarSizeMode) _sizeMode;
|
|
||||||
- (BOOL) _usesStandardBackgroundColor;
|
- (BOOL) _usesStandardBackgroundColor;
|
||||||
- (void) _setUsesStandardBackgroundColor: (BOOL)standard;
|
- (void) _setUsesStandardBackgroundColor: (BOOL)standard;
|
||||||
@end
|
@end
|
||||||
|
@ -206,13 +222,6 @@ static void initSystemExtensionsColors(void)
|
||||||
- (void) setToolbar: (NSToolbar *)toolbar;
|
- (void) setToolbar: (NSToolbar *)toolbar;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface GSToolbarClipView : NSClipView
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation GSToolbarClippedItemsButton
|
@implementation GSToolbarClippedItemsButton
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
|
@ -281,8 +290,6 @@ static void initSystemExtensionsColors(void)
|
||||||
id item;
|
id item;
|
||||||
NSArray *visibleItems;
|
NSArray *visibleItems;
|
||||||
|
|
||||||
AUTORELEASE(menu);
|
|
||||||
|
|
||||||
visibleItems = [_toolbar visibleItems];
|
visibleItems = [_toolbar visibleItems];
|
||||||
|
|
||||||
e = [[_toolbar items] objectEnumerator];
|
e = [[_toolbar items] objectEnumerator];
|
||||||
|
@ -301,7 +308,7 @@ static void initSystemExtensionsColors(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return menu;
|
return AUTORELEASE(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
|
@ -315,105 +322,43 @@ static void initSystemExtensionsColors(void)
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
@implementation GSToolbarClipView
|
|
||||||
|
|
||||||
// Nothing here
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
// Implementation GSToolbarView
|
// Implementation GSToolbarView
|
||||||
|
|
||||||
@implementation GSToolbarView
|
@implementation GSToolbarView
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (self != [GSToolbarView class])
|
if (self == [GSToolbarView class])
|
||||||
return;
|
|
||||||
|
|
||||||
initSystemExtensionsColors();
|
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. */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithFrame: (NSRect)frame
|
- (id) initWithFrame: (NSRect)frame
|
||||||
{
|
{
|
||||||
return [self initWithFrame: frame
|
if ((self = [super initWithFrame: frame]) == nil)
|
||||||
displayMode: NSToolbarDisplayModeDefault
|
{
|
||||||
sizeMode: NSToolbarSizeModeDefault];
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithFrame: (NSRect)frame
|
|
||||||
displayMode: (NSToolbarDisplayMode)displayMode
|
|
||||||
sizeMode: (NSToolbarSizeMode)sizeMode
|
|
||||||
{
|
|
||||||
if ((self = [super initWithFrame: frame]) != nil)
|
|
||||||
{
|
|
||||||
_displayMode = displayMode;
|
|
||||||
_sizeMode = sizeMode;
|
|
||||||
|
|
||||||
switch (_sizeMode)
|
|
||||||
{
|
|
||||||
case NSToolbarSizeModeDefault:
|
|
||||||
_heightFromLayout = ToolbarViewDefaultHeight;
|
_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,
|
[self setFrame: NSMakeRect(frame.origin.x, frame.origin.y,
|
||||||
frame.size.width, _heightFromLayout)];
|
frame.size.width, _heightFromLayout)];
|
||||||
|
|
||||||
// ---
|
_clipView = [[NSClipView alloc] initWithFrame:
|
||||||
|
NSMakeRect(0, 0, frame.size.width,
|
||||||
_clipView =
|
_heightFromLayout)];
|
||||||
[[GSToolbarClipView alloc] initWithFrame: NSMakeRect(0, 0, 100, 100)];
|
[_clipView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
|
||||||
|
[self addSubview: _clipView];
|
||||||
[_clipView setAutoresizingMask: (NSViewWidthSizable |
|
// Adjust the clip view frame
|
||||||
NSViewHeightSizable)];
|
|
||||||
|
|
||||||
[self setBorderMask: GSToolbarViewTopBorder | GSToolbarViewBottomBorder
|
[self setBorderMask: GSToolbarViewTopBorder | GSToolbarViewBottomBorder
|
||||||
| GSToolbarViewRightBorder | GSToolbarViewLeftBorder];
|
| GSToolbarViewRightBorder | GSToolbarViewLeftBorder];
|
||||||
// Adjust the clip view frame
|
|
||||||
|
|
||||||
[self addSubview: _clipView];
|
|
||||||
|
|
||||||
_clippedItemsMark = [[GSToolbarClippedItemsButton alloc] init];
|
_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:
|
[self registerForDraggedTypes:
|
||||||
[NSArray arrayWithObject: GSMovableToolbarItemPboardType]];
|
[NSArray arrayWithObject: GSMovableToolbarItemPboardType]];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) retain
|
|
||||||
{
|
|
||||||
return [super retain];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
//NSLog(@"Toolbar view dealloc");
|
//NSLog(@"Toolbar view dealloc");
|
||||||
|
@ -510,14 +455,13 @@ static void initSystemExtensionsColors(void)
|
||||||
|
|
||||||
- (void) drawRect: (NSRect)aRect
|
- (void) drawRect: (NSRect)aRect
|
||||||
{
|
{
|
||||||
NSBezierPath *rect = [NSBezierPath bezierPathWithRect: aRect];
|
|
||||||
NSRect viewFrame = [self frame];
|
NSRect viewFrame = [self frame];
|
||||||
|
|
||||||
// We draw the background
|
// We draw the background
|
||||||
if (![BackgroundColor isEqual: [NSColor clearColor]])
|
if (![BackgroundColor isEqual: [NSColor clearColor]])
|
||||||
{
|
{
|
||||||
[BackgroundColor set];
|
[BackgroundColor set];
|
||||||
[rect fill];
|
[NSBezierPath fillRect: aRect];
|
||||||
}
|
}
|
||||||
|
|
||||||
// We draw the border
|
// We draw the border
|
||||||
|
@ -591,7 +535,7 @@ static void initSystemExtensionsColors(void)
|
||||||
object: _window];
|
object: _window];
|
||||||
}
|
}
|
||||||
|
|
||||||
// More methods... Accessors
|
// Accessors
|
||||||
|
|
||||||
- (unsigned int) borderMask
|
- (unsigned int) borderMask
|
||||||
{
|
{
|
||||||
|
@ -606,29 +550,12 @@ static void initSystemExtensionsColors(void)
|
||||||
- (void) setBorderMask: (unsigned int)borderMask
|
- (void) setBorderMask: (unsigned int)borderMask
|
||||||
{
|
{
|
||||||
NSRect toolbarViewFrame = [self frame];
|
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;
|
_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
|
// Take in account the border
|
||||||
|
|
||||||
if (_borderMask & GSToolbarViewBottomBorder)
|
if (_borderMask & GSToolbarViewBottomBorder)
|
||||||
{
|
{
|
||||||
rect = NSMakeRect(rect.origin.x, ++rect.origin.y, rect.size.width,
|
rect = NSMakeRect(rect.origin.x, ++rect.origin.y, rect.size.width,
|
||||||
|
@ -658,9 +585,6 @@ static void initSystemExtensionsColors(void)
|
||||||
|
|
||||||
- (void) setToolbar: (NSToolbar *)toolbar
|
- (void) setToolbar: (NSToolbar *)toolbar
|
||||||
{
|
{
|
||||||
if ([toolbar sizeMode] != _sizeMode)
|
|
||||||
; // FIXME: Raise exception here
|
|
||||||
|
|
||||||
if (_toolbar == toolbar)
|
if (_toolbar == toolbar)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -816,10 +740,10 @@ static void initSystemExtensionsColors(void)
|
||||||
[_clippedItemsMark removeFromSuperview];
|
[_clippedItemsMark removeFromSuperview];
|
||||||
|
|
||||||
[_clipView setFrame: NSMakeRect(clipViewFrame.origin.x,
|
[_clipView setFrame: NSMakeRect(clipViewFrame.origin.x,
|
||||||
clipViewFrame.origin.y, [self frame].size.width,
|
clipViewFrame.origin.y,
|
||||||
|
[self frame].size.width,
|
||||||
clipViewFrame.size.height)];
|
clipViewFrame.size.height)];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) _reload
|
- (void) _reload
|
||||||
|
@ -955,16 +879,6 @@ static void initSystemExtensionsColors(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) _setSizeMode: (NSToolbarSizeMode)sizeMode
|
|
||||||
{
|
|
||||||
_sizeMode = sizeMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSToolbarSizeMode) _sizeMode
|
|
||||||
{
|
|
||||||
return _sizeMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL) _usesStandardBackgroundColor
|
- (BOOL) _usesStandardBackgroundColor
|
||||||
{
|
{
|
||||||
return [BackgroundColor isEqual: [self standardBackgroundColor]];
|
return [BackgroundColor isEqual: [self standardBackgroundColor]];
|
||||||
|
|
|
@ -520,15 +520,13 @@ static GSValidationCenter *vc = nil;
|
||||||
- (void) _reload;
|
- (void) _reload;
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
- (void) _setSizeMode: (NSToolbarSizeMode)sizeMode;
|
|
||||||
- (NSToolbarSizeMode) _sizeMode;
|
|
||||||
- (NSArray *) _visibleBackViews;
|
- (NSArray *) _visibleBackViews;
|
||||||
- (BOOL) _usesStandardBackgroundColor;
|
- (BOOL) _usesStandardBackgroundColor;
|
||||||
- (void) _setUsesStandardBackgroundColor: (BOOL)standard;
|
- (void) _setUsesStandardBackgroundColor: (BOOL)standard;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface NSWindow (ToolbarPrivate)
|
@interface NSWindow (ToolbarPrivate)
|
||||||
- (void) _adjustToolbarView;
|
- (void) _adjustToolbarView: (GSToolbarView*)view;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
@ -1044,7 +1042,7 @@ static GSValidationCenter *vc = nil;
|
||||||
item = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdent];
|
item = [[NSToolbarItem alloc] initWithItemIdentifier: itemIdent];
|
||||||
}
|
}
|
||||||
|
|
||||||
return item;
|
return AUTORELEASE(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1216,8 +1214,11 @@ static GSValidationCenter *vc = nil;
|
||||||
{
|
{
|
||||||
_displayMode = displayMode;
|
_displayMode = displayMode;
|
||||||
|
|
||||||
|
if ([self isVisible])
|
||||||
|
{
|
||||||
[_toolbarView _reload];
|
[_toolbarView _reload];
|
||||||
[[_toolbarView window] _adjustToolbarView];
|
[[_toolbarView window] _adjustToolbarView: _toolbarView];
|
||||||
|
}
|
||||||
|
|
||||||
if (broadcast)
|
if (broadcast)
|
||||||
{
|
{
|
||||||
|
@ -1233,10 +1234,11 @@ static GSValidationCenter *vc = nil;
|
||||||
{
|
{
|
||||||
_sizeMode = sizeMode;
|
_sizeMode = sizeMode;
|
||||||
|
|
||||||
[_toolbarView _setSizeMode: _sizeMode];
|
if ([self isVisible])
|
||||||
|
{
|
||||||
[_toolbarView _reload];
|
[_toolbarView _reload];
|
||||||
[[_toolbarView window] _adjustToolbarView];
|
[[_toolbarView window] _adjustToolbarView: _toolbarView];
|
||||||
|
}
|
||||||
|
|
||||||
if (broadcast)
|
if (broadcast)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,8 +44,9 @@
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface NSWindow (ToolbarPrivate)
|
@interface NSWindow (ToolbarPrivate)
|
||||||
- (void) _adjustToolbarView;
|
- (void) _adjustToolbarView: (GSToolbarView*)view;
|
||||||
- (void) _toggleToolbarView;
|
- (void) _addToolbarView: (GSToolbarView*)view;
|
||||||
|
- (void) _removeToolbarView: (GSToolbarView*)view;
|
||||||
- (NSView *) _contentViewWithoutToolbar;
|
- (NSView *) _contentViewWithoutToolbar;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -59,24 +60,99 @@
|
||||||
- (void) toggleToolbarShown: (id)sender
|
- (void) toggleToolbarShown: (id)sender
|
||||||
{
|
{
|
||||||
NSToolbar *toolbar = [self toolbar];
|
NSToolbar *toolbar = [self toolbar];
|
||||||
|
BOOL isVisible = [toolbar isVisible];
|
||||||
|
|
||||||
if (!toolbar)
|
if (!toolbar)
|
||||||
return;
|
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
|
// 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
|
// when we toggle the toolbar
|
||||||
// example : the toolbar needs to be still known visible in order to hide
|
// example : the toolbar needs to be still known visible in order to hide
|
||||||
// it.
|
// it.
|
||||||
[toolbar setVisible: ![toolbar isVisible]];
|
[toolbar setVisible: !isVisible];
|
||||||
|
|
||||||
[self display];
|
[self display];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessors
|
// 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
|
- (NSView *) _contentViewWithoutToolbar
|
||||||
{
|
{
|
||||||
NSToolbar *toolbar = [self toolbar];
|
NSToolbar *toolbar = [self toolbar];
|
||||||
|
@ -115,79 +191,8 @@
|
||||||
return [self contentView];
|
return [self contentView];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSToolbar *) toolbar
|
- (void) _adjustToolbarView: (GSToolbarView *)toolbarView
|
||||||
{
|
{
|
||||||
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 _toggleToolbarView];
|
|
||||||
}
|
|
||||||
[toolbarView setToolbar: nil];
|
|
||||||
// Release the toolbarView, this will 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 _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
|
// Frame and height
|
||||||
NSRect toolbarViewFrame = [toolbarView frame];
|
NSRect toolbarViewFrame = [toolbarView frame];
|
||||||
float toolbarViewHeight = toolbarViewFrame.size.height;
|
float toolbarViewHeight = toolbarViewFrame.size.height;
|
||||||
|
@ -220,12 +225,9 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
- (void) _addToolbarView: (GSToolbarView*)toolbarView
|
||||||
|
|
||||||
- (void) _toggleToolbarView
|
|
||||||
{
|
{
|
||||||
// Views
|
// Views
|
||||||
GSToolbarView *toolbarView = [[self toolbar] _toolbarView];
|
|
||||||
NSView *contentViewWithoutToolbar;
|
NSView *contentViewWithoutToolbar;
|
||||||
|
|
||||||
// Frame
|
// Frame
|
||||||
|
@ -233,8 +235,6 @@
|
||||||
= [NSWindow contentRectForFrameRect: [self frame]
|
= [NSWindow contentRectForFrameRect: [self frame]
|
||||||
styleMask: [self styleMask]];
|
styleMask: [self styleMask]];
|
||||||
|
|
||||||
if ([toolbarView superview] == nil)
|
|
||||||
{
|
|
||||||
float newToolbarViewHeight;
|
float newToolbarViewHeight;
|
||||||
NSRect contentViewWithoutToolbarFrame;
|
NSRect contentViewWithoutToolbarFrame;
|
||||||
|
|
||||||
|
@ -279,8 +279,17 @@
|
||||||
[_contentView addSubview: contentViewWithoutToolbar];
|
[_contentView addSubview: contentViewWithoutToolbar];
|
||||||
RELEASE(contentViewWithoutToolbar);
|
RELEASE(contentViewWithoutToolbar);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
- (void) _removeToolbarView: (GSToolbarView *)toolbarView
|
||||||
{
|
{
|
||||||
|
// Views
|
||||||
|
NSView *contentViewWithoutToolbar;
|
||||||
|
|
||||||
|
// Frame
|
||||||
|
NSRect windowContentFrame
|
||||||
|
= [NSWindow contentRectForFrameRect: [self frame]
|
||||||
|
styleMask: [self styleMask]];
|
||||||
|
|
||||||
float toolbarViewHeight = [toolbarView frame].size.height;
|
float toolbarViewHeight = [toolbarView frame].size.height;
|
||||||
|
|
||||||
contentViewWithoutToolbar = [self _contentViewWithoutToolbar];
|
contentViewWithoutToolbar = [self _contentViewWithoutToolbar];
|
||||||
|
@ -312,6 +321,5 @@
|
||||||
|
|
||||||
RELEASE(contentViewWithoutToolbar);
|
RELEASE(contentViewWithoutToolbar);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue