mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 20:01:11 +00:00
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:
parent
9f1698a4a3
commit
0568f0a0c5
7 changed files with 296 additions and 305 deletions
10
ChangeLog
10
ChangeLog
|
@ -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>
|
||||
|
||||
* Source/NSClipView.m: removed C99-ism
|
||||
|
|
|
@ -37,9 +37,7 @@
|
|||
@interface NSWindow (Toolbar)
|
||||
- (void) runToolbarCustomizationPalette: (id)sender;
|
||||
- (void) toggleToolbarShown: (id)sender;
|
||||
- (NSView *) contentViewWithoutToolbar;
|
||||
- (NSToolbar *) toolbar;
|
||||
- (void) setContentViewWithoutToolbar: (NSView *)contentViewWithoutToolbar;
|
||||
- (void) setToolbar: (NSToolbar*)toolbar;
|
||||
@end
|
||||
|
||||
|
|
|
@ -56,12 +56,12 @@
|
|||
static NSNotificationCenter *nc = nil;
|
||||
static const int current_version = 1;
|
||||
|
||||
static NSMutableArray *toolbars;
|
||||
static NSMutableArray *toolbars = nil;
|
||||
|
||||
// Validation stuff
|
||||
static const unsigned int ValidationInterval = 4;
|
||||
@class GSValidationCenter; // Mandatory because the interface is declared later
|
||||
static GSValidationCenter *vc;
|
||||
static GSValidationCenter *vc = nil;
|
||||
|
||||
// Extensions
|
||||
@implementation NSArray (ObjectsWithValueForKey)
|
||||
|
@ -166,18 +166,18 @@ static GSValidationCenter *vc;
|
|||
|
||||
[nc addObserver: self selector: @selector(windowDidUpdate:)
|
||||
name: NSWindowDidUpdateNotification
|
||||
object: window];
|
||||
object: window];
|
||||
[nc addObserver: vc
|
||||
selector: @selector(windowWillClose:)
|
||||
selector: @selector(windowWillClose:)
|
||||
name: NSWindowWillCloseNotification
|
||||
object: window];
|
||||
|
||||
object: window];
|
||||
|
||||
_trackingRectView = [window _windowView];
|
||||
_trackingRect
|
||||
= [_trackingRectView addTrackingRect: [_trackingRectView bounds]
|
||||
owner: self
|
||||
userData: nil
|
||||
assumeInside: NO];
|
||||
= [_trackingRectView addTrackingRect: [_trackingRectView bounds]
|
||||
owner: self
|
||||
userData: nil
|
||||
assumeInside: NO];
|
||||
_window = window;
|
||||
}
|
||||
return self;
|
||||
|
@ -217,7 +217,7 @@ static GSValidationCenter *vc;
|
|||
// currently observing.
|
||||
|
||||
[self setObservers: nil]; // To release observers
|
||||
|
||||
|
||||
[_trackingRectView removeTrackingRect: _trackingRect];
|
||||
// We can safely remove the tracking rect here, because it will never call
|
||||
// this method unlike dealloc.
|
||||
|
@ -315,11 +315,11 @@ static GSValidationCenter *vc;
|
|||
_validationTimer =
|
||||
[NSTimer timerWithTimeInterval: ValidationInterval
|
||||
target: self
|
||||
selector: @selector(scheduledValidate)
|
||||
userInfo: nil
|
||||
repeats: NO];
|
||||
selector: @selector(scheduledValidate)
|
||||
userInfo: nil
|
||||
repeats: NO];
|
||||
[[NSRunLoop currentRunLoop] addTimer: _validationTimer
|
||||
forMode: NSDefaultRunLoopMode];
|
||||
forMode: NSDefaultRunLoopMode];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -371,8 +371,8 @@ static GSValidationCenter *vc;
|
|||
observersArray = [_vobjs valueForKey: @"_observers"];
|
||||
for (i = 0; i < [observersArray count]; i++)
|
||||
{
|
||||
[result addObjectsFromArray: [observersArray objectAtIndex: i]];
|
||||
}
|
||||
[result addObjectsFromArray: [observersArray objectAtIndex: i]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
|
@ -436,12 +436,12 @@ static GSValidationCenter *vc;
|
|||
if (observersWindow != nil && [observersWindow containsObject: observer])
|
||||
{
|
||||
[observersWindow removeObject: observer];
|
||||
if ([observersWindow count] == 0)
|
||||
{
|
||||
if ([observersWindow count] == 0)
|
||||
{
|
||||
[vobj clean];
|
||||
[_vobjs removeObjectIdenticalTo: vobj];
|
||||
}
|
||||
}
|
||||
[_vobjs removeObjectIdenticalTo: vobj];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -556,7 +556,7 @@ static GSValidationCenter *vc;
|
|||
{
|
||||
return [self initWithIdentifier: identifier
|
||||
displayMode: NSToolbarDisplayModeIconAndLabel
|
||||
sizeMode: NSToolbarSizeModeRegular];
|
||||
sizeMode: NSToolbarSizeModeRegular];
|
||||
}
|
||||
|
||||
|
||||
|
@ -585,10 +585,10 @@ static GSValidationCenter *vc;
|
|||
|
||||
if ([toolbarModel displayMode] != displayMode
|
||||
&& [toolbarModel sizeMode] != sizeMode)
|
||||
{
|
||||
// Raise an exception.
|
||||
}
|
||||
|
||||
{
|
||||
// Raise an exception.
|
||||
}
|
||||
|
||||
// [self _loadConfig];
|
||||
}
|
||||
else
|
||||
|
@ -666,7 +666,7 @@ static GSValidationCenter *vc;
|
|||
}
|
||||
|
||||
- (void) insertItemWithItemIdentifier: (NSString *)itemIdentifier
|
||||
atIndex: (int)index
|
||||
atIndex: (int)index
|
||||
{
|
||||
[self _insertItemWithItemIdentifier: itemIdentifier
|
||||
atIndex: index
|
||||
|
@ -841,10 +841,10 @@ static GSValidationCenter *vc;
|
|||
{
|
||||
if ([selectableIdentifiers containsObject: [item itemIdentifier]])
|
||||
{
|
||||
if (![item _selected])
|
||||
[item _setSelected: YES];
|
||||
updated = YES;
|
||||
}
|
||||
if (![item _selected])
|
||||
[item _setSelected: YES];
|
||||
updated = YES;
|
||||
}
|
||||
}
|
||||
|
||||
if (updated)
|
||||
|
@ -906,7 +906,7 @@ static GSValidationCenter *vc;
|
|||
[[toolbarModel items] valueForKey: @"_itemIdentifier"];
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
wantedItemIdentifiers = [_delegate toolbarDefaultItemIdentifiers:self];
|
||||
}
|
||||
|
||||
|
@ -954,9 +954,9 @@ static GSValidationCenter *vc;
|
|||
config = [defaults objectForKey: tableKey];
|
||||
|
||||
if (config != nil)
|
||||
{
|
||||
[self setConfigurationFromDictionary: config];
|
||||
}
|
||||
{
|
||||
[self setConfigurationFromDictionary: config];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1037,35 +1037,35 @@ static GSValidationCenter *vc;
|
|||
{
|
||||
item = [self _toolbarItemForIdentifier: itemIdentifier];
|
||||
if (item == nil)
|
||||
{
|
||||
item =
|
||||
{
|
||||
item =
|
||||
[_delegate toolbar: self itemForItemIdentifier: itemIdentifier
|
||||
willBeInsertedIntoToolbar: YES];
|
||||
}
|
||||
willBeInsertedIntoToolbar: YES];
|
||||
}
|
||||
|
||||
if (item != nil)
|
||||
{
|
||||
NSArray *selectableItems;
|
||||
|
||||
if ([_delegate respondsToSelector:
|
||||
@selector(toolbarSelectableItemIdentifiers:)])
|
||||
{
|
||||
selectableItems =
|
||||
[_delegate toolbarSelectableItemIdentifiers: self];
|
||||
if ([selectableItems containsObject: itemIdentifier])
|
||||
[item _setSelectable: YES];
|
||||
}
|
||||
|
||||
[nc postNotificationName: NSToolbarWillAddItemNotification
|
||||
|
||||
if ([_delegate respondsToSelector:
|
||||
@selector(toolbarSelectableItemIdentifiers:)])
|
||||
{
|
||||
selectableItems =
|
||||
[_delegate toolbarSelectableItemIdentifiers: self];
|
||||
if ([selectableItems containsObject: itemIdentifier])
|
||||
[item _setSelectable: YES];
|
||||
}
|
||||
|
||||
[nc postNotificationName: NSToolbarWillAddItemNotification
|
||||
object: self
|
||||
userInfo: [NSDictionary dictionaryWithObject: item forKey: @"item"]];
|
||||
userInfo: [NSDictionary dictionaryWithObject: item forKey: @"item"]];
|
||||
[item _setToolbar: self];
|
||||
[_items insertObject: item atIndex: index];
|
||||
|
||||
// We reload the toolbarView each time a new item is added except when
|
||||
// we build/create the toolbar
|
||||
|
||||
// We reload the toolbarView each time a new item is added except when
|
||||
// we build/create the toolbar
|
||||
if (!_build)
|
||||
[_toolbarView _reload];
|
||||
[_toolbarView _reload];
|
||||
|
||||
if (broadcast)
|
||||
{
|
||||
|
@ -1097,8 +1097,8 @@ static GSValidationCenter *vc;
|
|||
- (void) _concludeRemoveItem: (NSToolbarItem *)item atIndex: (int)index broadcast: (BOOL)broadcast
|
||||
{
|
||||
[nc postNotificationName: NSToolbarDidRemoveItemNotification
|
||||
object: self
|
||||
userInfo: [NSDictionary dictionaryWithObject: item forKey: @"item"]];
|
||||
object: self
|
||||
userInfo: [NSDictionary dictionaryWithObject: item forKey: @"item"]];
|
||||
|
||||
if (broadcast)
|
||||
{
|
||||
|
@ -1136,7 +1136,7 @@ static GSValidationCenter *vc;
|
|||
if (broadcast)
|
||||
{
|
||||
TRANSMIT(_setConfigurationFromDictionary: _configurationDictionary
|
||||
broadcast: NO);
|
||||
broadcast: NO);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -230,13 +230,13 @@ static const int current_version = 1;
|
|||
if (_window)
|
||||
{
|
||||
if (shown)
|
||||
[_toolbarView _setWillBeVisible: YES];
|
||||
|
||||
[_window toggleToolbarShown: self];
|
||||
|
||||
[_toolbarView _setWillBeVisible: NO];
|
||||
[_toolbarView _setWillBeVisible: YES];
|
||||
|
||||
[_window toggleToolbarShown: self];
|
||||
|
||||
[_toolbarView _setWillBeVisible: NO];
|
||||
}
|
||||
|
||||
|
||||
_visible = shown;
|
||||
// Important to set _visible after the toolbar has been toggled because
|
||||
// NSWindow method contentViewWithoutToolbar uses [NSToolbar visible]
|
||||
|
|
|
@ -191,27 +191,27 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
switch ([[_toolbarItem toolbar] sizeMode])
|
||||
{
|
||||
case NSToolbarSizeModeDefault:
|
||||
layoutedWidth = ItemBackViewDefaultWidth;
|
||||
layoutedHeight = ItemBackViewDefaultHeight;
|
||||
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
||||
break;
|
||||
layoutedWidth = ItemBackViewDefaultWidth;
|
||||
layoutedHeight = ItemBackViewDefaultHeight;
|
||||
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
||||
break;
|
||||
case NSToolbarSizeModeRegular:
|
||||
layoutedWidth = ItemBackViewRegularWidth;
|
||||
layoutedHeight = ItemBackViewRegularHeight;
|
||||
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
||||
break;
|
||||
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
||||
break;
|
||||
case NSToolbarSizeModeSmall:
|
||||
layoutedWidth = ItemBackViewSmallWidth;
|
||||
layoutedHeight = ItemBackViewSmallHeight;
|
||||
[[_toolbarItem image] setSize: NSMakeSize(24, 24)];
|
||||
/* Not use [self image] here because it can return nil, when image
|
||||
position is set to NSNoImage. Even if NSToolbarDisplayModeTextOnly
|
||||
is not true anymore -setImagePosition: is only called below, then
|
||||
[self image] can still returns nil. */
|
||||
font = SmallFont;
|
||||
break;
|
||||
layoutedHeight = ItemBackViewSmallHeight;
|
||||
[[_toolbarItem image] setSize: NSMakeSize(24, 24)];
|
||||
/* Not use [self image] here because it can return nil, when image
|
||||
position is set to NSNoImage. Even if NSToolbarDisplayModeTextOnly
|
||||
is not true anymore -setImagePosition: is only called below, then
|
||||
[self image] can still returns nil. */
|
||||
font = SmallFont;
|
||||
break;
|
||||
default:
|
||||
; // Invalid
|
||||
; // Invalid
|
||||
}
|
||||
|
||||
[[self cell] setFont: font];
|
||||
|
@ -231,7 +231,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
}
|
||||
|
||||
// Adjust the layout in accordance with the label
|
||||
|
||||
|
||||
attr = [NSDictionary dictionaryWithObject: font forKey: NSFontAttributeName];
|
||||
if (label == nil || [label isEqualToString: @""])
|
||||
label = @"Dummy";
|
||||
|
@ -255,13 +255,13 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
case NSToolbarDisplayModeIconOnly:
|
||||
[self setImagePosition: NSImageOnly];
|
||||
layoutedHeight -= [attrStr size].height + InsetItemTextY;
|
||||
break;
|
||||
break;
|
||||
case NSToolbarDisplayModeLabelOnly:
|
||||
[self setImagePosition: NSNoImage];
|
||||
layoutedHeight = [attrStr size].height + InsetItemTextY * 2;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
; // Invalid
|
||||
; // Invalid
|
||||
}
|
||||
DESTROY(attrStr);
|
||||
|
||||
|
@ -282,46 +282,46 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
|
||||
if ([event modifierFlags] == NSCommandKeyMask
|
||||
&& [toolbar allowsUserCustomization])
|
||||
{
|
||||
NSSize viewSize = [self frame].size;
|
||||
NSImage *image = [[NSImage alloc] initWithSize: viewSize];
|
||||
NSCell *cell = [self cell];
|
||||
NSPasteboard *pboard;
|
||||
int index;
|
||||
|
||||
AUTORELEASE(image);
|
||||
|
||||
// Prepare the drag
|
||||
|
||||
RETAIN(self);
|
||||
/* We need to keep this view (aka self) to be able to draw the drag
|
||||
image. */
|
||||
|
||||
// Draw the drag content in an image
|
||||
|
||||
/* The code below is only partially supported by GNUstep, then NSImage
|
||||
needs to be improved. */
|
||||
[image lockFocus];
|
||||
{
|
||||
NSSize viewSize = [self frame].size;
|
||||
NSImage *image = [[NSImage alloc] initWithSize: viewSize];
|
||||
NSCell *cell = [self cell];
|
||||
NSPasteboard *pboard;
|
||||
int index;
|
||||
|
||||
AUTORELEASE(image);
|
||||
|
||||
// Prepare the drag
|
||||
|
||||
RETAIN(self);
|
||||
/* We need to keep this view (aka self) to be able to draw the drag
|
||||
image. */
|
||||
|
||||
// Draw the drag content in an image
|
||||
|
||||
/* The code below is only partially supported by GNUstep, then NSImage
|
||||
needs to be improved. */
|
||||
[image lockFocus];
|
||||
[cell setShowsFirstResponder: NO]; // To remove the dotted rect
|
||||
[cell drawWithFrame:
|
||||
NSMakeRect(0, 0, viewSize.width, viewSize.height) inView: nil];
|
||||
NSMakeRect(0, 0, viewSize.width, viewSize.height) inView: nil];
|
||||
[cell setShowsFirstResponder: YES];
|
||||
[image unlockFocus];
|
||||
|
||||
pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
|
||||
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
|
||||
owner: nil];
|
||||
index = [toolbar _indexOfItem: _toolbarItem];
|
||||
[pboard setString: [NSString stringWithFormat:@"%d", index]
|
||||
forType: GSMovableToolbarItemPboardType];
|
||||
|
||||
[self dragImage: image
|
||||
at: NSMakePoint(0.0, 0.0)
|
||||
offset: NSMakeSize(0.0, 0.0)
|
||||
event: event
|
||||
pasteboard: pboard
|
||||
source: self
|
||||
slideBack: NO];
|
||||
[image unlockFocus];
|
||||
|
||||
pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
|
||||
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
|
||||
owner: nil];
|
||||
index = [toolbar _indexOfItem: _toolbarItem];
|
||||
[pboard setString: [NSString stringWithFormat:@"%d", index]
|
||||
forType: GSMovableToolbarItemPboardType];
|
||||
|
||||
[self dragImage: image
|
||||
at: NSMakePoint(0.0, 0.0)
|
||||
offset: NSMakeSize(0.0, 0.0)
|
||||
event: event
|
||||
pasteboard: pboard
|
||||
source: self
|
||||
slideBack: NO];
|
||||
}
|
||||
else if ([event modifierFlags] != NSCommandKeyMask)
|
||||
{
|
||||
|
@ -342,7 +342,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
|
||||
- (void) draggedImage: (NSImage *)dragImage
|
||||
endedAt: (NSPoint)location
|
||||
operation: (NSDragOperation)operation
|
||||
operation: (NSDragOperation)operation
|
||||
{
|
||||
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
|
||||
to: target
|
||||
from: _toolbarItem];
|
||||
from: _toolbarItem];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -478,7 +478,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
|
||||
// Overriden NSCell method
|
||||
- (void) _drawAttributedText: (NSAttributedString*)aString
|
||||
inFrame: (NSRect)aRect
|
||||
inFrame: (NSRect)aRect
|
||||
{
|
||||
if (aString == nil)
|
||||
return;
|
||||
|
@ -563,7 +563,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
{
|
||||
color = [NSColor disabledControlTextColor];
|
||||
}
|
||||
|
||||
|
||||
pStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
||||
[pStyle setAlignment: NSCenterTextAlignment];
|
||||
|
||||
|
@ -606,26 +606,26 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
switch ([[_toolbarItem toolbar] sizeMode])
|
||||
{
|
||||
case NSToolbarSizeModeDefault:
|
||||
layoutedWidth = ItemBackViewDefaultWidth;
|
||||
layoutedHeight = ItemBackViewDefaultHeight;
|
||||
if ([view frame].size.height > 32)
|
||||
[view removeFromSuperview];
|
||||
break;
|
||||
layoutedWidth = ItemBackViewDefaultWidth;
|
||||
layoutedHeight = ItemBackViewDefaultHeight;
|
||||
if ([view frame].size.height > 32)
|
||||
[view removeFromSuperview];
|
||||
break;
|
||||
case NSToolbarSizeModeRegular:
|
||||
layoutedWidth = ItemBackViewRegularWidth;
|
||||
layoutedHeight = ItemBackViewRegularHeight;
|
||||
if ([view frame].size.height > 32)
|
||||
[view removeFromSuperview];
|
||||
break;
|
||||
if ([view frame].size.height > 32)
|
||||
[view removeFromSuperview];
|
||||
break;
|
||||
case NSToolbarSizeModeSmall:
|
||||
layoutedWidth = ItemBackViewSmallWidth;
|
||||
layoutedHeight = ItemBackViewSmallHeight;
|
||||
_font = SmallFont;
|
||||
if ([view frame].size.height > 24)
|
||||
[view removeFromSuperview];
|
||||
break;
|
||||
layoutedHeight = ItemBackViewSmallHeight;
|
||||
_font = SmallFont;
|
||||
if ([view frame].size.height > 24)
|
||||
[view removeFromSuperview];
|
||||
break;
|
||||
default:
|
||||
NSLog(@"Invalid NSToolbarSizeMode"); // Invalid
|
||||
NSLog(@"Invalid NSToolbarSizeMode"); // Invalid
|
||||
}
|
||||
|
||||
// Adjust the layout in accordance with the border
|
||||
|
@ -669,15 +669,15 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
case NSToolbarDisplayModeIconOnly:
|
||||
_showLabel = NO;
|
||||
layoutedHeight -= [attrStr size].height + InsetItemTextY;
|
||||
break;
|
||||
break;
|
||||
case NSToolbarDisplayModeLabelOnly:
|
||||
_enabled = NO;
|
||||
layoutedHeight = [attrStr size].height + InsetItemTextY * 2;
|
||||
if ([view superview] != nil)
|
||||
[view removeFromSuperview];
|
||||
break;
|
||||
if ([view superview] != nil)
|
||||
[view removeFromSuperview];
|
||||
break;
|
||||
default:
|
||||
; // Invalid
|
||||
; // Invalid
|
||||
}
|
||||
|
||||
/* If the view is visible...
|
||||
|
@ -702,15 +702,15 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
if (_showLabel)
|
||||
{
|
||||
insetItemViewY = ([self frame].size.height - [view frame].size.height
|
||||
- [attrStr size].height - InsetItemTextX) / 2
|
||||
+ [attrStr size].height + InsetItemTextX;
|
||||
}
|
||||
- [attrStr size].height - InsetItemTextX) / 2
|
||||
+ [attrStr size].height + InsetItemTextX;
|
||||
}
|
||||
else
|
||||
{
|
||||
insetItemViewY = ([self frame].size.height
|
||||
- [view frame].size.height) / 2;
|
||||
}
|
||||
|
||||
insetItemViewY = ([self frame].size.height
|
||||
- [view frame].size.height) / 2;
|
||||
}
|
||||
|
||||
[view setFrameOrigin: NSMakePoint((layoutedWidth
|
||||
- [view frame].size.width) / 2, insetItemViewY)];
|
||||
}
|
||||
|
@ -746,43 +746,43 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
|
||||
if ([event modifierFlags] == NSCommandKeyMask
|
||||
&& [toolbar allowsUserCustomization])
|
||||
{
|
||||
NSSize viewSize = [self frame].size;
|
||||
NSImage *image = [[NSImage alloc] initWithSize: viewSize];
|
||||
NSPasteboard *pboard;
|
||||
int index;
|
||||
|
||||
AUTORELEASE(image);
|
||||
|
||||
// Prepare the drag
|
||||
|
||||
RETAIN(self);
|
||||
/* We need to keep this view (aka self) to be able to draw the drag
|
||||
image. */
|
||||
|
||||
// Draw the drag content in an image
|
||||
|
||||
/* The code below is only partially supported by GNUstep, then NSImage
|
||||
needs to be improved. */
|
||||
[image lockFocus];
|
||||
{
|
||||
NSSize viewSize = [self frame].size;
|
||||
NSImage *image = [[NSImage alloc] initWithSize: viewSize];
|
||||
NSPasteboard *pboard;
|
||||
int index;
|
||||
|
||||
AUTORELEASE(image);
|
||||
|
||||
// Prepare the drag
|
||||
|
||||
RETAIN(self);
|
||||
/* We need to keep this view (aka self) to be able to draw the drag
|
||||
image. */
|
||||
|
||||
// Draw the drag content in an image
|
||||
|
||||
/* The code below is only partially supported by GNUstep, then NSImage
|
||||
needs to be improved. */
|
||||
[image lockFocus];
|
||||
[self drawRect:
|
||||
NSMakeRect(0, 0, viewSize.width, viewSize.height)];
|
||||
[image unlockFocus];
|
||||
|
||||
pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
|
||||
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
|
||||
owner: nil];
|
||||
index = [toolbar _indexOfItem: _toolbarItem];
|
||||
[pboard setString: [NSString stringWithFormat:@"%d", index]
|
||||
forType: GSMovableToolbarItemPboardType];
|
||||
|
||||
[self dragImage: image
|
||||
at: NSMakePoint(0.0, 0.0)
|
||||
offset: NSMakeSize(0.0, 0.0)
|
||||
event: event
|
||||
pasteboard: pboard
|
||||
source: self
|
||||
slideBack: NO];
|
||||
NSMakeRect(0, 0, viewSize.width, viewSize.height)];
|
||||
[image unlockFocus];
|
||||
|
||||
pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
|
||||
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
|
||||
owner: nil];
|
||||
index = [toolbar _indexOfItem: _toolbarItem];
|
||||
[pboard setString: [NSString stringWithFormat:@"%d", index]
|
||||
forType: GSMovableToolbarItemPboardType];
|
||||
|
||||
[self dragImage: image
|
||||
at: NSMakePoint(0.0, 0.0)
|
||||
offset: NSMakeSize(0.0, 0.0)
|
||||
event: event
|
||||
pasteboard: pboard
|
||||
source: self
|
||||
slideBack: NO];
|
||||
}
|
||||
else if ([event modifierFlags] != NSCommandKeyMask)
|
||||
{
|
||||
|
@ -803,7 +803,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
|
||||
- (void) draggedImage: (NSImage *)dragImage
|
||||
endedAt: (NSPoint)location
|
||||
operation: (NSDragOperation)operation
|
||||
operation: (NSDragOperation)operation
|
||||
{
|
||||
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 = [[GSToolbarSeparatorItem alloc]
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
}
|
||||
|
||||
else if ([itemIdentifier isEqualToString: @"NSToolbarSpaceItemIdentifier"]
|
||||
|
@ -1068,16 +1068,16 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
{
|
||||
[self release];
|
||||
self = [[GSToolbarSpaceItem alloc]
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
}
|
||||
|
||||
else if ([itemIdentifier
|
||||
isEqualToString: @"NSToolbarFlexibleSpaceItemIdentifier"]
|
||||
isEqualToString: @"NSToolbarFlexibleSpaceItemIdentifier"]
|
||||
&& [self isKindOfClass:[GSToolbarFlexibleSpaceItem class]] == NO)
|
||||
{
|
||||
[self release];
|
||||
self = [[GSToolbarFlexibleSpaceItem alloc]
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
}
|
||||
|
||||
else if ([itemIdentifier
|
||||
|
@ -1086,7 +1086,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
{
|
||||
[self release];
|
||||
self = [[GSToolbarShowColorsItem alloc]
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
}
|
||||
|
||||
else if ([itemIdentifier
|
||||
|
@ -1095,7 +1095,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
{
|
||||
[self release];
|
||||
self = [[GSToolbarShowFontsItem alloc]
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
}
|
||||
|
||||
else if ([itemIdentifier
|
||||
|
@ -1104,7 +1104,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
{
|
||||
[self release];
|
||||
self = [[GSToolbarCustomizeToolbarItem alloc]
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
}
|
||||
|
||||
else if ([itemIdentifier isEqualToString: @"NSToolbarPrintItemIdentifier"]
|
||||
|
@ -1112,9 +1112,9 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
{
|
||||
[self release];
|
||||
self = [[GSToolbarPrintItem alloc]
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
initWithItemIdentifier: itemIdentifier];
|
||||
}
|
||||
|
||||
|
||||
// Normal toolbar items
|
||||
else
|
||||
{
|
||||
|
@ -1142,7 +1142,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
_flags._isEnabled = [_backView respondsToSelector: @selector(isEnabled)];
|
||||
_flags._tag = YES;
|
||||
_flags._action =
|
||||
[_backView respondsToSelector: @selector(toolbarItemAction)];
|
||||
[_backView respondsToSelector: @selector(toolbarItemAction)];
|
||||
_flags._target = [_backView respondsToSelector: @selector(target)];
|
||||
_flags._image = [_backView respondsToSelector: @selector(image)];
|
||||
// sets
|
||||
|
@ -1244,15 +1244,15 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
{
|
||||
if ([_backView isKindOfClass: [GSToolbarButton class]])
|
||||
[(GSToolbarButton *)_backView setToolbarItemAction: action];
|
||||
|
||||
if (action != NULL)
|
||||
{
|
||||
[self setEnabled: YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setEnabled: NO];
|
||||
}
|
||||
|
||||
if (action != NULL)
|
||||
{
|
||||
[self setEnabled: YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setEnabled: NO];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1546,4 +1546,3 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
@interface NSWindow (ToolbarPrivate)
|
||||
- (void) _adjustToolbarView;
|
||||
- (void) _toggleToolbarViewWithDisplay: (BOOL)flag;
|
||||
- (NSView *) contentViewWithoutToolbar;
|
||||
- (void) setContentViewWithoutToolbar: (NSView *)contentViewWithoutToolbar;
|
||||
@end
|
||||
|
||||
@implementation NSWindow (Toolbar)
|
||||
|
@ -66,28 +68,27 @@
|
|||
BOOL isVisible = [toolbar isVisible];
|
||||
GSToolbarView *toolbarView = [toolbar _toolbarView];
|
||||
|
||||
if ([sender isEqual: toolbar])
|
||||
// We can enter this branch when the toolbar class has called
|
||||
// toggleToolbarShown:
|
||||
{
|
||||
if (!isVisible) // In the case : not visible when the method has been called
|
||||
{
|
||||
[toolbarView setFrameSize:
|
||||
NSMakeSize([NSWindow
|
||||
contentRectForFrameRect: [self frame]
|
||||
styleMask: [self styleMask]].size.width, 100)];
|
||||
// -toogleToolbarViewWithDisplay: will reset the toolbarView frame
|
||||
[toolbarView _reload]; // Will recalculate the layout
|
||||
}
|
||||
if ([sender isEqual: toolbar])
|
||||
{
|
||||
if (!isVisible) // In the case : not visible when the method has been called
|
||||
{
|
||||
[toolbarView setFrameSize:
|
||||
NSMakeSize([NSWindow
|
||||
contentRectForFrameRect: [self frame]
|
||||
styleMask: [self styleMask]].size.width, 100)];
|
||||
// -toogleToolbarViewWithDisplay: will reset the toolbarView frame
|
||||
[toolbarView _reload]; // Will recalculate the layout
|
||||
}
|
||||
|
||||
[self _toggleToolbarViewWithDisplay: YES];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We call the toolbar class letting it call back on toggleToolbarShown:
|
||||
[toolbar setVisible: !isVisible];
|
||||
}
|
||||
|
||||
{
|
||||
// We call the toolbar class letting it call back on toggleToolbarShown:
|
||||
[toolbar setVisible: !isVisible];
|
||||
}
|
||||
}
|
||||
|
||||
// Accessors
|
||||
|
@ -97,34 +98,35 @@
|
|||
NSToolbar *toolbar = [self toolbar];
|
||||
|
||||
if (toolbar != nil && [toolbar isVisible])
|
||||
{
|
||||
NSArray *subviews = [_contentView subviews];
|
||||
// Take in account this method call returns an array which is an
|
||||
// autoreleased copy.
|
||||
// By side effect, this increments the toolbar view retain count until the
|
||||
// autorelease pool is cleared.
|
||||
NSView *subview;
|
||||
int i, n = [subviews count];
|
||||
GSToolbarView *toolbarView = [toolbar _toolbarView];
|
||||
|
||||
if (n > 2 || ![[toolbarView superview] isEqual: _contentView]) {
|
||||
[NSException raise: @"_contentView error"
|
||||
format: @"_contenView is not valid. _contentView needs a \
|
||||
{
|
||||
NSArray *subviews = [_contentView subviews];
|
||||
// Take in account this method call returns an array which is an
|
||||
// autoreleased copy.
|
||||
// By side effect, this increments the toolbar view retain count until the
|
||||
// autorelease pool is cleared.
|
||||
NSView *subview;
|
||||
int i, n = [subviews count];
|
||||
GSToolbarView *toolbarView = [toolbar _toolbarView];
|
||||
|
||||
if (n > 2 || ![[toolbarView superview] isEqual: _contentView])
|
||||
{
|
||||
[NSException raise: @"_contentView error"
|
||||
format: @"_contenView is not valid. _contentView needs a \
|
||||
toolbar view and a contentViewWithoutToolbar, with \
|
||||
no others subviews."];
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
subview = [subviews objectAtIndex: i];
|
||||
if (![subview isEqual: toolbarView])
|
||||
{
|
||||
return subview;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
subview = [subviews objectAtIndex: i];
|
||||
if (![subview isEqual: toolbarView])
|
||||
{
|
||||
return subview;
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [self contentView];
|
||||
}
|
||||
|
@ -150,17 +152,16 @@
|
|||
NSToolbar *toolbar = [self toolbar];
|
||||
|
||||
if (toolbar != nil && [toolbar isVisible])
|
||||
{
|
||||
[_contentView replaceSubview: [self contentViewWithoutToolbar]
|
||||
with: contentViewWithoutToolbar];
|
||||
}
|
||||
{
|
||||
[_contentView replaceSubview: [self contentViewWithoutToolbar]
|
||||
with: contentViewWithoutToolbar];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setContentView: contentViewWithoutToolbar];
|
||||
}
|
||||
{
|
||||
[self setContentView: contentViewWithoutToolbar];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void) setToolbar: (NSToolbar*)toolbar
|
||||
{
|
||||
NSToolbar *lastToolbar = [self toolbar];
|
||||
|
@ -170,23 +171,23 @@
|
|||
{
|
||||
NSLog(@"Error: the new toolbar is still owned by a toolbar view");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastToolbar != nil)
|
||||
{
|
||||
// We throw the last toolbar out
|
||||
{
|
||||
// We throw the last toolbar out
|
||||
|
||||
[self _toggleToolbarViewWithDisplay: NO];
|
||||
[lastToolbar _setWindow: nil];
|
||||
}
|
||||
[self _toggleToolbarViewWithDisplay: NO];
|
||||
[lastToolbar _setWindow: nil];
|
||||
}
|
||||
|
||||
// When there is no new toolbar
|
||||
|
||||
if (toolbar == nil)
|
||||
{
|
||||
[self display]; // To show we have toggle the previous toolbar view
|
||||
return;
|
||||
}
|
||||
{
|
||||
[self display]; // To show we have toggle the previous toolbar view
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Else we do
|
||||
|
@ -199,14 +200,15 @@
|
|||
// Instantiate the toolbar view
|
||||
|
||||
if (toolbarView == nil)
|
||||
{
|
||||
toolbarView = [[GSToolbarView alloc] initWithFrame: NSMakeRect(0, 0,
|
||||
[NSWindow contentRectForFrameRect: [self frame]
|
||||
styleMask: [self styleMask]].size.width, 100)];
|
||||
// _toggleToolbarView:display: method will set the toolbar view to the right
|
||||
// frame
|
||||
[toolbarView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin];
|
||||
}
|
||||
{
|
||||
toolbarView = [[GSToolbarView alloc] initWithFrame:
|
||||
NSMakeRect(0, 0,
|
||||
[NSWindow contentRectForFrameRect: [self frame]
|
||||
styleMask: [self styleMask]].size.width, 100)];
|
||||
// _toggleToolbarView:display: method will set the toolbar view to the right
|
||||
// frame
|
||||
[toolbarView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin];
|
||||
}
|
||||
[toolbarView setBorderMask: GSToolbarViewBottomBorder];
|
||||
|
||||
// Load the toolbar inside the toolbar view
|
||||
|
@ -255,7 +257,7 @@
|
|||
[self setFrame: NSMakeRect(
|
||||
windowFrame.origin.x,
|
||||
windowFrame.origin.y + (toolbarViewHeight - newToolbarViewHeight),
|
||||
windowFrame.size.width,
|
||||
windowFrame.size.width,
|
||||
windowFrame.size.height - (toolbarViewHeight - newToolbarViewHeight)) display: NO];
|
||||
|
||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
|
||||
|
@ -273,7 +275,7 @@
|
|||
// Frame
|
||||
NSRect windowContentFrame
|
||||
= [NSWindow contentRectForFrameRect: [self frame]
|
||||
styleMask: [self styleMask]];
|
||||
styleMask: [self styleMask]];
|
||||
|
||||
if ([toolbarView superview] == nil)
|
||||
{
|
||||
|
@ -294,8 +296,8 @@
|
|||
windowContentFrame.size.height += newToolbarViewHeight;
|
||||
|
||||
[self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
|
||||
styleMask: [self styleMask]]
|
||||
display: NO];
|
||||
styleMask: [self styleMask]]
|
||||
display: NO];
|
||||
|
||||
// Plug the toolbar view
|
||||
|
||||
|
@ -304,9 +306,9 @@
|
|||
|
||||
[toolbarView setFrame: NSMakeRect(
|
||||
0,
|
||||
contentViewWithoutToolbarFrame.size.height,
|
||||
contentViewWithoutToolbarFrame.size.height,
|
||||
contentViewWithoutToolbarFrame.size.width,
|
||||
newToolbarViewHeight)];
|
||||
newToolbarViewHeight)];
|
||||
[_contentView addSubview: toolbarView];
|
||||
RELEASE(toolbarView);
|
||||
|
||||
|
@ -338,8 +340,8 @@
|
|||
windowContentFrame.origin.y += toolbarViewHeight;
|
||||
windowContentFrame.size.height -= toolbarViewHeight;
|
||||
[self setFrame: [NSWindow frameRectForContentRect: windowContentFrame
|
||||
styleMask: [self styleMask]]
|
||||
display: NO];
|
||||
styleMask: [self styleMask]]
|
||||
display: NO];
|
||||
|
||||
[contentViewWithoutToolbar setAutoresizingMask: NSViewWidthSizable
|
||||
| NSViewHeightSizable];
|
||||
|
|
|
@ -72,21 +72,17 @@
|
|||
#include "AppKit/NSScreen.h"
|
||||
#include "AppKit/NSTextField.h"
|
||||
#include "AppKit/NSTextFieldCell.h"
|
||||
#include "AppKit/NSToolbar.h"
|
||||
#include "AppKit/NSView.h"
|
||||
#include "AppKit/NSWindow.h"
|
||||
#include "AppKit/NSWindowController.h"
|
||||
#include "AppKit/PSOperators.h"
|
||||
#include "GNUstepGUI/GSTrackingRect.h"
|
||||
#include "GNUstepGUI/GSDisplayServer.h"
|
||||
#include "GNUstepGUI/GSToolbarView.h"
|
||||
#include "GSToolTips.h"
|
||||
|
||||
static GSToolTips *toolTipVisible = nil;
|
||||
|
||||
#include "GSWindowDecorationView.h"
|
||||
|
||||
static id<GSWindowDecorator> windowDecorator;
|
||||
static GSToolTips *toolTipVisible = nil;
|
||||
static id<GSWindowDecorator> windowDecorator = nil;
|
||||
|
||||
|
||||
BOOL GSViewAcceptsDrag(NSView *v, id<NSDraggingInfo> dragInfo);
|
||||
|
@ -111,19 +107,6 @@ BOOL GSViewAcceptsDrag(NSView *v, id<NSDraggingInfo> dragInfo);
|
|||
- (id) _initWithScreenNumber: (int)screen;
|
||||
@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
|
||||
|
@ -138,7 +121,6 @@ BOOL GSViewAcceptsDrag(NSView *v, id<NSDraggingInfo> dragInfo);
|
|||
|
||||
- (void) _lossOfKeyOrMainWindow;
|
||||
- (NSView *) _windowView;
|
||||
// Method used to support validation in the toolbar implementation
|
||||
@end
|
||||
|
||||
@implementation NSWindow (GNUstepPrivate)
|
||||
|
|
Loading…
Reference in a new issue