Small clean up of toolbar code.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27443 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2008-12-28 15:16:05 +00:00
parent 0aec53d988
commit 6c0a0ef0cb
7 changed files with 296 additions and 305 deletions

View file

@ -1,3 +1,13 @@
2008-12-28 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSWindow.m: Remove left over traces of toolbar handling.
* Headers/AppKit/NSWindow+Toolbar.h: Move some private methods
from here ...
* Source/NSWindow+Toolbar.m: ... to here.
* Source/NSToolbarItem.m,
* Source/GSToolbar.m,
* Source/NSToolbar.m: White space clean up.
2008-12-28 Riccardo Mottola <rmottola@users.sf.net> 2008-12-28 Riccardo Mottola <rmottola@users.sf.net>
* Source/NSClipView.m: removed C99-ism * Source/NSClipView.m: removed C99-ism

View file

@ -37,9 +37,7 @@
@interface NSWindow (Toolbar) @interface NSWindow (Toolbar)
- (void) runToolbarCustomizationPalette: (id)sender; - (void) runToolbarCustomizationPalette: (id)sender;
- (void) toggleToolbarShown: (id)sender; - (void) toggleToolbarShown: (id)sender;
- (NSView *) contentViewWithoutToolbar;
- (NSToolbar *) toolbar; - (NSToolbar *) toolbar;
- (void) setContentViewWithoutToolbar: (NSView *)contentViewWithoutToolbar;
- (void) setToolbar: (NSToolbar*)toolbar; - (void) setToolbar: (NSToolbar*)toolbar;
@end @end

View file

@ -56,12 +56,12 @@
static NSNotificationCenter *nc = nil; static NSNotificationCenter *nc = nil;
static const int current_version = 1; static const int current_version = 1;
static NSMutableArray *toolbars; static NSMutableArray *toolbars = nil;
// Validation stuff // Validation stuff
static const unsigned int ValidationInterval = 4; static const unsigned int ValidationInterval = 4;
@class GSValidationCenter; // Mandatory because the interface is declared later @class GSValidationCenter; // Mandatory because the interface is declared later
static GSValidationCenter *vc; static GSValidationCenter *vc = nil;
// Extensions // Extensions
@implementation NSArray (ObjectsWithValueForKey) @implementation NSArray (ObjectsWithValueForKey)
@ -166,18 +166,18 @@ static GSValidationCenter *vc;
[nc addObserver: self selector: @selector(windowDidUpdate:) [nc addObserver: self selector: @selector(windowDidUpdate:)
name: NSWindowDidUpdateNotification name: NSWindowDidUpdateNotification
object: window]; object: window];
[nc addObserver: vc [nc addObserver: vc
selector: @selector(windowWillClose:) selector: @selector(windowWillClose:)
name: NSWindowWillCloseNotification name: NSWindowWillCloseNotification
object: window]; object: window];
_trackingRectView = [window _windowView]; _trackingRectView = [window _windowView];
_trackingRect _trackingRect
= [_trackingRectView addTrackingRect: [_trackingRectView bounds] = [_trackingRectView addTrackingRect: [_trackingRectView bounds]
owner: self owner: self
userData: nil userData: nil
assumeInside: NO]; assumeInside: NO];
_window = window; _window = window;
} }
return self; return self;
@ -217,7 +217,7 @@ static GSValidationCenter *vc;
// currently observing. // currently observing.
[self setObservers: nil]; // To release observers [self setObservers: nil]; // To release observers
[_trackingRectView removeTrackingRect: _trackingRect]; [_trackingRectView removeTrackingRect: _trackingRect];
// We can safely remove the tracking rect here, because it will never call // We can safely remove the tracking rect here, because it will never call
// this method unlike dealloc. // this method unlike dealloc.
@ -315,11 +315,11 @@ static GSValidationCenter *vc;
_validationTimer = _validationTimer =
[NSTimer timerWithTimeInterval: ValidationInterval [NSTimer timerWithTimeInterval: ValidationInterval
target: self target: self
selector: @selector(scheduledValidate) selector: @selector(scheduledValidate)
userInfo: nil userInfo: nil
repeats: NO]; repeats: NO];
[[NSRunLoop currentRunLoop] addTimer: _validationTimer [[NSRunLoop currentRunLoop] addTimer: _validationTimer
forMode: NSDefaultRunLoopMode]; forMode: NSDefaultRunLoopMode];
} }
@end @end
@ -371,8 +371,8 @@ static GSValidationCenter *vc;
observersArray = [_vobjs valueForKey: @"_observers"]; observersArray = [_vobjs valueForKey: @"_observers"];
for (i = 0; i < [observersArray count]; i++) for (i = 0; i < [observersArray count]; i++)
{ {
[result addObjectsFromArray: [observersArray objectAtIndex: i]]; [result addObjectsFromArray: [observersArray objectAtIndex: i]];
} }
return result; return result;
} }
else else
@ -436,12 +436,12 @@ static GSValidationCenter *vc;
if (observersWindow != nil && [observersWindow containsObject: observer]) if (observersWindow != nil && [observersWindow containsObject: observer])
{ {
[observersWindow removeObject: observer]; [observersWindow removeObject: observer];
if ([observersWindow count] == 0) if ([observersWindow count] == 0)
{ {
[vobj clean]; [vobj clean];
[_vobjs removeObjectIdenticalTo: vobj]; [_vobjs removeObjectIdenticalTo: vobj];
} }
} }
} }
} }
@ -556,7 +556,7 @@ static GSValidationCenter *vc;
{ {
return [self initWithIdentifier: identifier return [self initWithIdentifier: identifier
displayMode: NSToolbarDisplayModeIconAndLabel displayMode: NSToolbarDisplayModeIconAndLabel
sizeMode: NSToolbarSizeModeRegular]; sizeMode: NSToolbarSizeModeRegular];
} }
@ -585,10 +585,10 @@ static GSValidationCenter *vc;
if ([toolbarModel displayMode] != displayMode if ([toolbarModel displayMode] != displayMode
&& [toolbarModel sizeMode] != sizeMode) && [toolbarModel sizeMode] != sizeMode)
{ {
// Raise an exception. // Raise an exception.
} }
// [self _loadConfig]; // [self _loadConfig];
} }
else else
@ -666,7 +666,7 @@ static GSValidationCenter *vc;
} }
- (void) insertItemWithItemIdentifier: (NSString *)itemIdentifier - (void) insertItemWithItemIdentifier: (NSString *)itemIdentifier
atIndex: (int)index atIndex: (int)index
{ {
[self _insertItemWithItemIdentifier: itemIdentifier [self _insertItemWithItemIdentifier: itemIdentifier
atIndex: index atIndex: index
@ -841,10 +841,10 @@ static GSValidationCenter *vc;
{ {
if ([selectableIdentifiers containsObject: [item itemIdentifier]]) if ([selectableIdentifiers containsObject: [item itemIdentifier]])
{ {
if (![item _selected]) if (![item _selected])
[item _setSelected: YES]; [item _setSelected: YES];
updated = YES; updated = YES;
} }
} }
if (updated) if (updated)
@ -906,7 +906,7 @@ static GSValidationCenter *vc;
[[toolbarModel items] valueForKey: @"_itemIdentifier"]; [[toolbarModel items] valueForKey: @"_itemIdentifier"];
} }
else else
{ {
wantedItemIdentifiers = [_delegate toolbarDefaultItemIdentifiers:self]; wantedItemIdentifiers = [_delegate toolbarDefaultItemIdentifiers:self];
} }
@ -954,9 +954,9 @@ static GSValidationCenter *vc;
config = [defaults objectForKey: tableKey]; config = [defaults objectForKey: tableKey];
if (config != nil) if (config != nil)
{ {
[self setConfigurationFromDictionary: config]; [self setConfigurationFromDictionary: config];
} }
} }
} }
@ -1037,35 +1037,35 @@ static GSValidationCenter *vc;
{ {
item = [self _toolbarItemForIdentifier: itemIdentifier]; item = [self _toolbarItemForIdentifier: itemIdentifier];
if (item == nil) if (item == nil)
{ {
item = item =
[_delegate toolbar: self itemForItemIdentifier: itemIdentifier [_delegate toolbar: self itemForItemIdentifier: itemIdentifier
willBeInsertedIntoToolbar: YES]; willBeInsertedIntoToolbar: YES];
} }
if (item != nil) if (item != nil)
{ {
NSArray *selectableItems; NSArray *selectableItems;
if ([_delegate respondsToSelector: if ([_delegate respondsToSelector:
@selector(toolbarSelectableItemIdentifiers:)]) @selector(toolbarSelectableItemIdentifiers:)])
{ {
selectableItems = selectableItems =
[_delegate toolbarSelectableItemIdentifiers: self]; [_delegate toolbarSelectableItemIdentifiers: self];
if ([selectableItems containsObject: itemIdentifier]) if ([selectableItems containsObject: itemIdentifier])
[item _setSelectable: YES]; [item _setSelectable: YES];
} }
[nc postNotificationName: NSToolbarWillAddItemNotification [nc postNotificationName: NSToolbarWillAddItemNotification
object: self object: self
userInfo: [NSDictionary dictionaryWithObject: item forKey: @"item"]]; userInfo: [NSDictionary dictionaryWithObject: item forKey: @"item"]];
[item _setToolbar: self]; [item _setToolbar: self];
[_items insertObject: item atIndex: index]; [_items insertObject: item atIndex: index];
// We reload the toolbarView each time a new item is added except when // We reload the toolbarView each time a new item is added except when
// we build/create the toolbar // we build/create the toolbar
if (!_build) if (!_build)
[_toolbarView _reload]; [_toolbarView _reload];
if (broadcast) if (broadcast)
{ {
@ -1097,8 +1097,8 @@ static GSValidationCenter *vc;
- (void) _concludeRemoveItem: (NSToolbarItem *)item atIndex: (int)index broadcast: (BOOL)broadcast - (void) _concludeRemoveItem: (NSToolbarItem *)item atIndex: (int)index broadcast: (BOOL)broadcast
{ {
[nc postNotificationName: NSToolbarDidRemoveItemNotification [nc postNotificationName: NSToolbarDidRemoveItemNotification
object: self object: self
userInfo: [NSDictionary dictionaryWithObject: item forKey: @"item"]]; userInfo: [NSDictionary dictionaryWithObject: item forKey: @"item"]];
if (broadcast) if (broadcast)
{ {
@ -1136,7 +1136,7 @@ static GSValidationCenter *vc;
if (broadcast) if (broadcast)
{ {
TRANSMIT(_setConfigurationFromDictionary: _configurationDictionary TRANSMIT(_setConfigurationFromDictionary: _configurationDictionary
broadcast: NO); broadcast: NO);
} }
} }

View file

@ -230,13 +230,13 @@ static const int current_version = 1;
if (_window) if (_window)
{ {
if (shown) if (shown)
[_toolbarView _setWillBeVisible: YES]; [_toolbarView _setWillBeVisible: YES];
[_window toggleToolbarShown: self]; [_window toggleToolbarShown: self];
[_toolbarView _setWillBeVisible: NO]; [_toolbarView _setWillBeVisible: NO];
} }
_visible = shown; _visible = shown;
// Important to set _visible after the toolbar has been toggled because // Important to set _visible after the toolbar has been toggled because
// NSWindow method contentViewWithoutToolbar uses [NSToolbar visible] // NSWindow method contentViewWithoutToolbar uses [NSToolbar visible]

View file

@ -191,27 +191,27 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
switch ([[_toolbarItem toolbar] sizeMode]) switch ([[_toolbarItem toolbar] sizeMode])
{ {
case NSToolbarSizeModeDefault: case NSToolbarSizeModeDefault:
layoutedWidth = ItemBackViewDefaultWidth; layoutedWidth = ItemBackViewDefaultWidth;
layoutedHeight = ItemBackViewDefaultHeight; layoutedHeight = ItemBackViewDefaultHeight;
[[_toolbarItem image] setSize: NSMakeSize(32, 32)]; [[_toolbarItem image] setSize: NSMakeSize(32, 32)];
break; break;
case NSToolbarSizeModeRegular: case NSToolbarSizeModeRegular:
layoutedWidth = ItemBackViewRegularWidth; layoutedWidth = ItemBackViewRegularWidth;
layoutedHeight = ItemBackViewRegularHeight; layoutedHeight = ItemBackViewRegularHeight;
[[_toolbarItem image] setSize: NSMakeSize(32, 32)]; [[_toolbarItem image] setSize: NSMakeSize(32, 32)];
break; break;
case NSToolbarSizeModeSmall: case NSToolbarSizeModeSmall:
layoutedWidth = ItemBackViewSmallWidth; layoutedWidth = ItemBackViewSmallWidth;
layoutedHeight = ItemBackViewSmallHeight; layoutedHeight = ItemBackViewSmallHeight;
[[_toolbarItem image] setSize: NSMakeSize(24, 24)]; [[_toolbarItem image] setSize: NSMakeSize(24, 24)];
/* Not use [self image] here because it can return nil, when image /* Not use [self image] here because it can return nil, when image
position is set to NSNoImage. Even if NSToolbarDisplayModeTextOnly position is set to NSNoImage. Even if NSToolbarDisplayModeTextOnly
is not true anymore -setImagePosition: is only called below, then is not true anymore -setImagePosition: is only called below, then
[self image] can still returns nil. */ [self image] can still returns nil. */
font = SmallFont; font = SmallFont;
break; break;
default: default:
; // Invalid ; // Invalid
} }
[[self cell] setFont: font]; [[self cell] setFont: font];
@ -231,7 +231,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
} }
// Adjust the layout in accordance with the label // Adjust the layout in accordance with the label
attr = [NSDictionary dictionaryWithObject: font forKey: NSFontAttributeName]; attr = [NSDictionary dictionaryWithObject: font forKey: NSFontAttributeName];
if (label == nil || [label isEqualToString: @""]) if (label == nil || [label isEqualToString: @""])
label = @"Dummy"; label = @"Dummy";
@ -255,13 +255,13 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
case NSToolbarDisplayModeIconOnly: case NSToolbarDisplayModeIconOnly:
[self setImagePosition: NSImageOnly]; [self setImagePosition: NSImageOnly];
layoutedHeight -= [attrStr size].height + InsetItemTextY; layoutedHeight -= [attrStr size].height + InsetItemTextY;
break; break;
case NSToolbarDisplayModeLabelOnly: case NSToolbarDisplayModeLabelOnly:
[self setImagePosition: NSNoImage]; [self setImagePosition: NSNoImage];
layoutedHeight = [attrStr size].height + InsetItemTextY * 2; layoutedHeight = [attrStr size].height + InsetItemTextY * 2;
break; break;
default: default:
; // Invalid ; // Invalid
} }
DESTROY(attrStr); DESTROY(attrStr);
@ -282,46 +282,46 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
if ([event modifierFlags] == NSCommandKeyMask if ([event modifierFlags] == NSCommandKeyMask
&& [toolbar allowsUserCustomization]) && [toolbar allowsUserCustomization])
{ {
NSSize viewSize = [self frame].size; NSSize viewSize = [self frame].size;
NSImage *image = [[NSImage alloc] initWithSize: viewSize]; NSImage *image = [[NSImage alloc] initWithSize: viewSize];
NSCell *cell = [self cell]; NSCell *cell = [self cell];
NSPasteboard *pboard; NSPasteboard *pboard;
int index; int index;
AUTORELEASE(image); AUTORELEASE(image);
// Prepare the drag // Prepare the drag
RETAIN(self); RETAIN(self);
/* We need to keep this view (aka self) to be able to draw the drag /* We need to keep this view (aka self) to be able to draw the drag
image. */ image. */
// Draw the drag content in an image // Draw the drag content in an image
/* The code below is only partially supported by GNUstep, then NSImage /* The code below is only partially supported by GNUstep, then NSImage
needs to be improved. */ needs to be improved. */
[image lockFocus]; [image lockFocus];
[cell setShowsFirstResponder: NO]; // To remove the dotted rect [cell setShowsFirstResponder: NO]; // To remove the dotted rect
[cell drawWithFrame: [cell drawWithFrame:
NSMakeRect(0, 0, viewSize.width, viewSize.height) inView: nil]; NSMakeRect(0, 0, viewSize.width, viewSize.height) inView: nil];
[cell setShowsFirstResponder: YES]; [cell setShowsFirstResponder: YES];
[image unlockFocus]; [image unlockFocus];
pboard = [NSPasteboard pasteboardWithName: NSDragPboard]; pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType] [pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
owner: nil]; owner: nil];
index = [toolbar _indexOfItem: _toolbarItem]; index = [toolbar _indexOfItem: _toolbarItem];
[pboard setString: [NSString stringWithFormat:@"%d", index] [pboard setString: [NSString stringWithFormat:@"%d", index]
forType: GSMovableToolbarItemPboardType]; forType: GSMovableToolbarItemPboardType];
[self dragImage: image [self dragImage: image
at: NSMakePoint(0.0, 0.0) at: NSMakePoint(0.0, 0.0)
offset: NSMakeSize(0.0, 0.0) offset: NSMakeSize(0.0, 0.0)
event: event event: event
pasteboard: pboard pasteboard: pboard
source: self source: self
slideBack: NO]; slideBack: NO];
} }
else if ([event modifierFlags] != NSCommandKeyMask) else if ([event modifierFlags] != NSCommandKeyMask)
{ {
@ -342,7 +342,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (void) draggedImage: (NSImage *)dragImage - (void) draggedImage: (NSImage *)dragImage
endedAt: (NSPoint)location endedAt: (NSPoint)location
operation: (NSDragOperation)operation operation: (NSDragOperation)operation
{ {
RELEASE(self); // The view is no more needed : no more drawing to do with it. RELEASE(self); // The view is no more needed : no more drawing to do with it.
} }
@ -368,7 +368,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
return [NSApp sendAction: _toolbarItemAction return [NSApp sendAction: _toolbarItemAction
to: target to: target
from: _toolbarItem]; from: _toolbarItem];
} }
else else
{ {
@ -478,7 +478,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
// Overriden NSCell method // Overriden NSCell method
- (void) _drawAttributedText: (NSAttributedString*)aString - (void) _drawAttributedText: (NSAttributedString*)aString
inFrame: (NSRect)aRect inFrame: (NSRect)aRect
{ {
if (aString == nil) if (aString == nil)
return; return;
@ -563,7 +563,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
color = [NSColor disabledControlTextColor]; color = [NSColor disabledControlTextColor];
} }
pStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; pStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[pStyle setAlignment: NSCenterTextAlignment]; [pStyle setAlignment: NSCenterTextAlignment];
@ -606,26 +606,26 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
switch ([[_toolbarItem toolbar] sizeMode]) switch ([[_toolbarItem toolbar] sizeMode])
{ {
case NSToolbarSizeModeDefault: case NSToolbarSizeModeDefault:
layoutedWidth = ItemBackViewDefaultWidth; layoutedWidth = ItemBackViewDefaultWidth;
layoutedHeight = ItemBackViewDefaultHeight; layoutedHeight = ItemBackViewDefaultHeight;
if ([view frame].size.height > 32) if ([view frame].size.height > 32)
[view removeFromSuperview]; [view removeFromSuperview];
break; break;
case NSToolbarSizeModeRegular: case NSToolbarSizeModeRegular:
layoutedWidth = ItemBackViewRegularWidth; layoutedWidth = ItemBackViewRegularWidth;
layoutedHeight = ItemBackViewRegularHeight; layoutedHeight = ItemBackViewRegularHeight;
if ([view frame].size.height > 32) if ([view frame].size.height > 32)
[view removeFromSuperview]; [view removeFromSuperview];
break; break;
case NSToolbarSizeModeSmall: case NSToolbarSizeModeSmall:
layoutedWidth = ItemBackViewSmallWidth; layoutedWidth = ItemBackViewSmallWidth;
layoutedHeight = ItemBackViewSmallHeight; layoutedHeight = ItemBackViewSmallHeight;
_font = SmallFont; _font = SmallFont;
if ([view frame].size.height > 24) if ([view frame].size.height > 24)
[view removeFromSuperview]; [view removeFromSuperview];
break; break;
default: default:
NSLog(@"Invalid NSToolbarSizeMode"); // Invalid NSLog(@"Invalid NSToolbarSizeMode"); // Invalid
} }
// Adjust the layout in accordance with the border // Adjust the layout in accordance with the border
@ -669,15 +669,15 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
case NSToolbarDisplayModeIconOnly: case NSToolbarDisplayModeIconOnly:
_showLabel = NO; _showLabel = NO;
layoutedHeight -= [attrStr size].height + InsetItemTextY; layoutedHeight -= [attrStr size].height + InsetItemTextY;
break; break;
case NSToolbarDisplayModeLabelOnly: case NSToolbarDisplayModeLabelOnly:
_enabled = NO; _enabled = NO;
layoutedHeight = [attrStr size].height + InsetItemTextY * 2; layoutedHeight = [attrStr size].height + InsetItemTextY * 2;
if ([view superview] != nil) if ([view superview] != nil)
[view removeFromSuperview]; [view removeFromSuperview];
break; break;
default: default:
; // Invalid ; // Invalid
} }
/* If the view is visible... /* If the view is visible...
@ -702,15 +702,15 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
if (_showLabel) if (_showLabel)
{ {
insetItemViewY = ([self frame].size.height - [view frame].size.height insetItemViewY = ([self frame].size.height - [view frame].size.height
- [attrStr size].height - InsetItemTextX) / 2 - [attrStr size].height - InsetItemTextX) / 2
+ [attrStr size].height + InsetItemTextX; + [attrStr size].height + InsetItemTextX;
} }
else else
{ {
insetItemViewY = ([self frame].size.height insetItemViewY = ([self frame].size.height
- [view frame].size.height) / 2; - [view frame].size.height) / 2;
} }
[view setFrameOrigin: NSMakePoint((layoutedWidth [view setFrameOrigin: NSMakePoint((layoutedWidth
- [view frame].size.width) / 2, insetItemViewY)]; - [view frame].size.width) / 2, insetItemViewY)];
} }
@ -746,43 +746,43 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
if ([event modifierFlags] == NSCommandKeyMask if ([event modifierFlags] == NSCommandKeyMask
&& [toolbar allowsUserCustomization]) && [toolbar allowsUserCustomization])
{ {
NSSize viewSize = [self frame].size; NSSize viewSize = [self frame].size;
NSImage *image = [[NSImage alloc] initWithSize: viewSize]; NSImage *image = [[NSImage alloc] initWithSize: viewSize];
NSPasteboard *pboard; NSPasteboard *pboard;
int index; int index;
AUTORELEASE(image); AUTORELEASE(image);
// Prepare the drag // Prepare the drag
RETAIN(self); RETAIN(self);
/* We need to keep this view (aka self) to be able to draw the drag /* We need to keep this view (aka self) to be able to draw the drag
image. */ image. */
// Draw the drag content in an image // Draw the drag content in an image
/* The code below is only partially supported by GNUstep, then NSImage /* The code below is only partially supported by GNUstep, then NSImage
needs to be improved. */ needs to be improved. */
[image lockFocus]; [image lockFocus];
[self drawRect: [self drawRect:
NSMakeRect(0, 0, viewSize.width, viewSize.height)]; NSMakeRect(0, 0, viewSize.width, viewSize.height)];
[image unlockFocus]; [image unlockFocus];
pboard = [NSPasteboard pasteboardWithName: NSDragPboard]; pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType] [pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
owner: nil]; owner: nil];
index = [toolbar _indexOfItem: _toolbarItem]; index = [toolbar _indexOfItem: _toolbarItem];
[pboard setString: [NSString stringWithFormat:@"%d", index] [pboard setString: [NSString stringWithFormat:@"%d", index]
forType: GSMovableToolbarItemPboardType]; forType: GSMovableToolbarItemPboardType];
[self dragImage: image [self dragImage: image
at: NSMakePoint(0.0, 0.0) at: NSMakePoint(0.0, 0.0)
offset: NSMakeSize(0.0, 0.0) offset: NSMakeSize(0.0, 0.0)
event: event event: event
pasteboard: pboard pasteboard: pboard
source: self source: self
slideBack: NO]; slideBack: NO];
} }
else if ([event modifierFlags] != NSCommandKeyMask) else if ([event modifierFlags] != NSCommandKeyMask)
{ {
@ -803,7 +803,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (void) draggedImage: (NSImage *)dragImage - (void) draggedImage: (NSImage *)dragImage
endedAt: (NSPoint)location endedAt: (NSPoint)location
operation: (NSDragOperation)operation operation: (NSDragOperation)operation
{ {
RELEASE(self); // The view is no more needed : no more drawing to do with it. RELEASE(self); // The view is no more needed : no more drawing to do with it.
} }
@ -1060,7 +1060,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
[self release]; [self release];
self = [[GSToolbarSeparatorItem alloc] self = [[GSToolbarSeparatorItem alloc]
initWithItemIdentifier: itemIdentifier]; initWithItemIdentifier: itemIdentifier];
} }
else if ([itemIdentifier isEqualToString: @"NSToolbarSpaceItemIdentifier"] else if ([itemIdentifier isEqualToString: @"NSToolbarSpaceItemIdentifier"]
@ -1068,16 +1068,16 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
[self release]; [self release];
self = [[GSToolbarSpaceItem alloc] self = [[GSToolbarSpaceItem alloc]
initWithItemIdentifier: itemIdentifier]; initWithItemIdentifier: itemIdentifier];
} }
else if ([itemIdentifier else if ([itemIdentifier
isEqualToString: @"NSToolbarFlexibleSpaceItemIdentifier"] isEqualToString: @"NSToolbarFlexibleSpaceItemIdentifier"]
&& [self isKindOfClass:[GSToolbarFlexibleSpaceItem class]] == NO) && [self isKindOfClass:[GSToolbarFlexibleSpaceItem class]] == NO)
{ {
[self release]; [self release];
self = [[GSToolbarFlexibleSpaceItem alloc] self = [[GSToolbarFlexibleSpaceItem alloc]
initWithItemIdentifier: itemIdentifier]; initWithItemIdentifier: itemIdentifier];
} }
else if ([itemIdentifier else if ([itemIdentifier
@ -1086,7 +1086,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
[self release]; [self release];
self = [[GSToolbarShowColorsItem alloc] self = [[GSToolbarShowColorsItem alloc]
initWithItemIdentifier: itemIdentifier]; initWithItemIdentifier: itemIdentifier];
} }
else if ([itemIdentifier else if ([itemIdentifier
@ -1095,7 +1095,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
[self release]; [self release];
self = [[GSToolbarShowFontsItem alloc] self = [[GSToolbarShowFontsItem alloc]
initWithItemIdentifier: itemIdentifier]; initWithItemIdentifier: itemIdentifier];
} }
else if ([itemIdentifier else if ([itemIdentifier
@ -1104,7 +1104,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
[self release]; [self release];
self = [[GSToolbarCustomizeToolbarItem alloc] self = [[GSToolbarCustomizeToolbarItem alloc]
initWithItemIdentifier: itemIdentifier]; initWithItemIdentifier: itemIdentifier];
} }
else if ([itemIdentifier isEqualToString: @"NSToolbarPrintItemIdentifier"] else if ([itemIdentifier isEqualToString: @"NSToolbarPrintItemIdentifier"]
@ -1112,9 +1112,9 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
[self release]; [self release];
self = [[GSToolbarPrintItem alloc] self = [[GSToolbarPrintItem alloc]
initWithItemIdentifier: itemIdentifier]; initWithItemIdentifier: itemIdentifier];
} }
// Normal toolbar items // Normal toolbar items
else else
{ {
@ -1142,7 +1142,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
_flags._isEnabled = [_backView respondsToSelector: @selector(isEnabled)]; _flags._isEnabled = [_backView respondsToSelector: @selector(isEnabled)];
_flags._tag = YES; _flags._tag = YES;
_flags._action = _flags._action =
[_backView respondsToSelector: @selector(toolbarItemAction)]; [_backView respondsToSelector: @selector(toolbarItemAction)];
_flags._target = [_backView respondsToSelector: @selector(target)]; _flags._target = [_backView respondsToSelector: @selector(target)];
_flags._image = [_backView respondsToSelector: @selector(image)]; _flags._image = [_backView respondsToSelector: @selector(image)];
// sets // sets
@ -1244,15 +1244,15 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{ {
if ([_backView isKindOfClass: [GSToolbarButton class]]) if ([_backView isKindOfClass: [GSToolbarButton class]])
[(GSToolbarButton *)_backView setToolbarItemAction: action]; [(GSToolbarButton *)_backView setToolbarItemAction: action];
if (action != NULL) if (action != NULL)
{ {
[self setEnabled: YES]; [self setEnabled: YES];
} }
else else
{ {
[self setEnabled: NO]; [self setEnabled: NO];
} }
} }
} }
@ -1546,4 +1546,3 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
} }
@end @end

View file

@ -51,6 +51,8 @@
@interface NSWindow (ToolbarPrivate) @interface NSWindow (ToolbarPrivate)
- (void) _adjustToolbarView; - (void) _adjustToolbarView;
- (void) _toggleToolbarViewWithDisplay: (BOOL)flag; - (void) _toggleToolbarViewWithDisplay: (BOOL)flag;
- (NSView *) contentViewWithoutToolbar;
- (void) setContentViewWithoutToolbar: (NSView *)contentViewWithoutToolbar;
@end @end
@implementation NSWindow (Toolbar) @implementation NSWindow (Toolbar)
@ -66,28 +68,27 @@
BOOL isVisible = [toolbar isVisible]; BOOL isVisible = [toolbar isVisible];
GSToolbarView *toolbarView = [toolbar _toolbarView]; GSToolbarView *toolbarView = [toolbar _toolbarView];
if ([sender isEqual: toolbar])
// We can enter this branch when the toolbar class has called // We can enter this branch when the toolbar class has called
// toggleToolbarShown: // toggleToolbarShown:
{ if ([sender isEqual: toolbar])
if (!isVisible) // In the case : not visible when the method has been called {
{ if (!isVisible) // In the case : not visible when the method has been called
[toolbarView setFrameSize: {
NSMakeSize([NSWindow [toolbarView setFrameSize:
contentRectForFrameRect: [self frame] NSMakeSize([NSWindow
styleMask: [self styleMask]].size.width, 100)]; contentRectForFrameRect: [self frame]
// -toogleToolbarViewWithDisplay: will reset the toolbarView frame styleMask: [self styleMask]].size.width, 100)];
[toolbarView _reload]; // Will recalculate the layout // -toogleToolbarViewWithDisplay: will reset the toolbarView frame
} [toolbarView _reload]; // Will recalculate the layout
}
[self _toggleToolbarViewWithDisplay: YES]; [self _toggleToolbarViewWithDisplay: YES];
} }
else else
{ {
// We call the toolbar class letting it call back on toggleToolbarShown: // We call the toolbar class letting it call back on toggleToolbarShown:
[toolbar setVisible: !isVisible]; [toolbar setVisible: !isVisible];
} }
} }
// Accessors // Accessors
@ -97,34 +98,35 @@
NSToolbar *toolbar = [self toolbar]; NSToolbar *toolbar = [self toolbar];
if (toolbar != nil && [toolbar isVisible]) if (toolbar != nil && [toolbar isVisible])
{ {
NSArray *subviews = [_contentView subviews]; NSArray *subviews = [_contentView subviews];
// Take in account this method call returns an array which is an // Take in account this method call returns an array which is an
// autoreleased copy. // autoreleased copy.
// By side effect, this increments the toolbar view retain count until the // By side effect, this increments the toolbar view retain count until the
// autorelease pool is cleared. // autorelease pool is cleared.
NSView *subview; NSView *subview;
int i, n = [subviews count]; int i, n = [subviews count];
GSToolbarView *toolbarView = [toolbar _toolbarView]; GSToolbarView *toolbarView = [toolbar _toolbarView];
if (n > 2 || ![[toolbarView superview] isEqual: _contentView]) { if (n > 2 || ![[toolbarView superview] isEqual: _contentView])
[NSException raise: @"_contentView error" {
format: @"_contenView is not valid. _contentView needs a \ [NSException raise: @"_contentView error"
format: @"_contenView is not valid. _contentView needs a \
toolbar view and a contentViewWithoutToolbar, with \ toolbar view and a contentViewWithoutToolbar, with \
no others subviews."]; no others subviews."];
} }
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
subview = [subviews objectAtIndex: i]; subview = [subviews objectAtIndex: i];
if (![subview isEqual: toolbarView]) if (![subview isEqual: toolbarView])
{ {
return subview; return subview;
} }
} }
return nil; return nil;
} }
return [self contentView]; return [self contentView];
} }
@ -150,17 +152,16 @@
NSToolbar *toolbar = [self toolbar]; NSToolbar *toolbar = [self toolbar];
if (toolbar != nil && [toolbar isVisible]) if (toolbar != nil && [toolbar isVisible])
{ {
[_contentView replaceSubview: [self contentViewWithoutToolbar] [_contentView replaceSubview: [self contentViewWithoutToolbar]
with: contentViewWithoutToolbar]; with: contentViewWithoutToolbar];
} }
else else
{ {
[self setContentView: contentViewWithoutToolbar]; [self setContentView: contentViewWithoutToolbar];
} }
} }
- (void) setToolbar: (NSToolbar*)toolbar - (void) setToolbar: (NSToolbar*)toolbar
{ {
NSToolbar *lastToolbar = [self toolbar]; NSToolbar *lastToolbar = [self toolbar];
@ -170,23 +171,23 @@
{ {
NSLog(@"Error: the new toolbar is still owned by a toolbar view"); NSLog(@"Error: the new toolbar is still owned by a toolbar view");
return; return;
} }
if (lastToolbar != nil) if (lastToolbar != nil)
{ {
// We throw the last toolbar out // We throw the last toolbar out
[self _toggleToolbarViewWithDisplay: NO]; [self _toggleToolbarViewWithDisplay: NO];
[lastToolbar _setWindow: nil]; [lastToolbar _setWindow: nil];
} }
// When there is no new toolbar // When there is no new toolbar
if (toolbar == nil) if (toolbar == nil)
{ {
[self display]; // To show we have toggle the previous toolbar view [self display]; // To show we have toggle the previous toolbar view
return; return;
} }
/* /*
* Else we do * Else we do
@ -199,14 +200,15 @@
// Instantiate the toolbar view // Instantiate the toolbar view
if (toolbarView == nil) if (toolbarView == nil)
{ {
toolbarView = [[GSToolbarView alloc] initWithFrame: NSMakeRect(0, 0, toolbarView = [[GSToolbarView alloc] initWithFrame:
[NSWindow contentRectForFrameRect: [self frame] NSMakeRect(0, 0,
styleMask: [self styleMask]].size.width, 100)]; [NSWindow contentRectForFrameRect: [self frame]
// _toggleToolbarView:display: method will set the toolbar view to the right styleMask: [self styleMask]].size.width, 100)];
// frame // _toggleToolbarView:display: method will set the toolbar view to the right
[toolbarView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin]; // frame
} [toolbarView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin];
}
[toolbarView setBorderMask: GSToolbarViewBottomBorder]; [toolbarView setBorderMask: GSToolbarViewBottomBorder];
// Load the toolbar inside the toolbar view // Load the toolbar inside the toolbar view
@ -255,7 +257,7 @@
[self setFrame: NSMakeRect( [self setFrame: NSMakeRect(
windowFrame.origin.x, windowFrame.origin.x,
windowFrame.origin.y + (toolbarViewHeight - newToolbarViewHeight), windowFrame.origin.y + (toolbarViewHeight - newToolbarViewHeight),
windowFrame.size.width, windowFrame.size.width,
windowFrame.size.height - (toolbarViewHeight - newToolbarViewHeight)) display: NO]; windowFrame.size.height - (toolbarViewHeight - newToolbarViewHeight)) display: NO];
[contentViewWithoutToolbar setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; [contentViewWithoutToolbar setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
@ -273,7 +275,7 @@
// Frame // Frame
NSRect windowContentFrame NSRect windowContentFrame
= [NSWindow contentRectForFrameRect: [self frame] = [NSWindow contentRectForFrameRect: [self frame]
styleMask: [self styleMask]]; styleMask: [self styleMask]];
if ([toolbarView superview] == nil) if ([toolbarView superview] == nil)
{ {
@ -294,8 +296,8 @@
windowContentFrame.size.height += newToolbarViewHeight; windowContentFrame.size.height += newToolbarViewHeight;
[self setFrame: [NSWindow frameRectForContentRect: windowContentFrame [self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
styleMask: [self styleMask]] styleMask: [self styleMask]]
display: NO]; display: NO];
// Plug the toolbar view // Plug the toolbar view
@ -304,9 +306,9 @@
[toolbarView setFrame: NSMakeRect( [toolbarView setFrame: NSMakeRect(
0, 0,
contentViewWithoutToolbarFrame.size.height, contentViewWithoutToolbarFrame.size.height,
contentViewWithoutToolbarFrame.size.width, contentViewWithoutToolbarFrame.size.width,
newToolbarViewHeight)]; newToolbarViewHeight)];
[_contentView addSubview: toolbarView]; [_contentView addSubview: toolbarView];
RELEASE(toolbarView); RELEASE(toolbarView);
@ -338,8 +340,8 @@
windowContentFrame.origin.y += toolbarViewHeight; windowContentFrame.origin.y += toolbarViewHeight;
windowContentFrame.size.height -= toolbarViewHeight; windowContentFrame.size.height -= toolbarViewHeight;
[self setFrame: [NSWindow frameRectForContentRect: windowContentFrame [self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
styleMask: [self styleMask]] styleMask: [self styleMask]]
display: NO]; display: NO];
[contentViewWithoutToolbar setAutoresizingMask: NSViewWidthSizable [contentViewWithoutToolbar setAutoresizingMask: NSViewWidthSizable
| NSViewHeightSizable]; | NSViewHeightSizable];

View file

@ -72,21 +72,17 @@
#include "AppKit/NSScreen.h" #include "AppKit/NSScreen.h"
#include "AppKit/NSTextField.h" #include "AppKit/NSTextField.h"
#include "AppKit/NSTextFieldCell.h" #include "AppKit/NSTextFieldCell.h"
#include "AppKit/NSToolbar.h"
#include "AppKit/NSView.h" #include "AppKit/NSView.h"
#include "AppKit/NSWindow.h" #include "AppKit/NSWindow.h"
#include "AppKit/NSWindowController.h" #include "AppKit/NSWindowController.h"
#include "AppKit/PSOperators.h" #include "AppKit/PSOperators.h"
#include "GNUstepGUI/GSTrackingRect.h" #include "GNUstepGUI/GSTrackingRect.h"
#include "GNUstepGUI/GSDisplayServer.h" #include "GNUstepGUI/GSDisplayServer.h"
#include "GNUstepGUI/GSToolbarView.h"
#include "GSToolTips.h" #include "GSToolTips.h"
static GSToolTips *toolTipVisible = nil;
#include "GSWindowDecorationView.h" #include "GSWindowDecorationView.h"
static id<GSWindowDecorator> windowDecorator; static GSToolTips *toolTipVisible = nil;
static id<GSWindowDecorator> windowDecorator = nil;
BOOL GSViewAcceptsDrag(NSView *v, id<NSDraggingInfo> dragInfo); BOOL GSViewAcceptsDrag(NSView *v, id<NSDraggingInfo> dragInfo);
@ -111,19 +107,6 @@ BOOL GSViewAcceptsDrag(NSView *v, id<NSDraggingInfo> dragInfo);
- (id) _initWithScreenNumber: (int)screen; - (id) _initWithScreenNumber: (int)screen;
@end @end
/*
* FIXME: Not sure if I should be exposing this here, but it seems to be the only way
* to fix the window frame save issue when a toolbar is present.
*/
@interface NSWindow (ToolbarPrivate)
- (id) toolbar;
- (NSView *)contentViewWithoutToolbar;
@end
@interface NSToolbar (GNUstepPrivate)
- (GSToolbarView *) _toolbarView;
@end
// FIXME: END (GJC)
/* /*
* Category for internal methods (for use only within the NSWindow class itself * Category for internal methods (for use only within the NSWindow class itself
@ -138,7 +121,6 @@ BOOL GSViewAcceptsDrag(NSView *v, id<NSDraggingInfo> dragInfo);
- (void) _lossOfKeyOrMainWindow; - (void) _lossOfKeyOrMainWindow;
- (NSView *) _windowView; - (NSView *) _windowView;
// Method used to support validation in the toolbar implementation
@end @end
@implementation NSWindow (GNUstepPrivate) @implementation NSWindow (GNUstepPrivate)