Convert between window and view coordinate system for NSMenuView.

Correct small bugs in last NSDocument rework.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27661 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Riccardo Mottola 2009-01-23 22:01:40 +00:00
parent dda7640fa5
commit 1c25d7e977
3 changed files with 38 additions and 29 deletions

View file

@ -1,3 +1,12 @@
2009-01-23 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSMenuView.m: Convert between the window and the view
coordinate system.
* Source/NSDocument.m (dataOfType:error:): Call dataRepresentationofType:
when that method was overriden.
* Source/NSDocument.m (writeToURL:ofType:error:): Use dataOfType:error:
instead of dataRepresentationofType:.
2009-01-22 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSWindowDecorationView.m: Add handling of in-window

View file

@ -679,6 +679,13 @@ withContentsOfURL: (NSURL *)url
ofType: (NSString *)type
error: (NSError **)error
{
if (OVERRIDDEN(loadDataRepresentation:ofType:))
{
*error = nil;
return [self loadDataRepresentation: data
ofType: type];
}
[NSException raise: NSInternalInconsistencyException format:@"%@ must implement %@",
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
return NO;
@ -959,9 +966,9 @@ withContentsOfURL: (NSURL *)url
}
else
{
NSData *data = [self dataRepresentationOfType: type];
NSData *data = [self dataOfType: type error: error];
if (data == nil)
if (data == nil)
return NO;
return [url setResourceData: data];

View file

@ -106,15 +106,6 @@ static NSMapTable *viewInfo = 0;
@implementation NSMenuView
static NSRect
_addLeftBorderOffsetToRect(NSRect aRect)
{
aRect.origin.x--;
aRect.size.width++;
return aRect;
}
/*
* Class methods.
*/
@ -398,6 +389,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
// Mark the new cell and the menu view as needing resizing.
[cell setNeedsSizing: YES];
[self setNeedsSizing: YES];
[self setNeedsDisplayForItemAtIndex: index];
}
- (NSMenuItemCell*) menuItemCellForItemAtIndex: (int)index
@ -449,10 +441,10 @@ _addLeftBorderOffsetToRect(NSRect aRect)
[aCell setEnabled: [[aCell menuItem] isEnabled]];
// Mark the cell associated with the item as needing resizing.
[aCell setNeedsSizing: YES];
[self setNeedsDisplayForItemAtIndex: index];
// Mark the menu view as needing to be resized.
[self setNeedsSizing: YES];
[self setNeedsDisplayForItemAtIndex: index];
}
- (void) itemAdded: (NSNotification*)notification
@ -490,6 +482,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
// Mark the menu view as needing to be resized.
[self setNeedsSizing: YES];
[self setNeedsDisplay: YES];
}
- (void) itemRemoved: (NSNotification*)notification
@ -510,6 +503,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
}
// Mark the menu view as needing to be resized.
[self setNeedsSizing: YES];
[self setNeedsDisplay: YES];
}
/*
@ -955,7 +949,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
NSRect aRect = [self rectOfItemAtIndex: i];
//NSLog(@"indexOfItemAtPoint called for %@ %@ %d %@", self, NSStringFromPoint(point), i, NSStringFromRect(aRect));
aRect = _addLeftBorderOffsetToRect(aRect);
aRect.origin.x -= _leftBorderOffset;
aRect.size.width += _leftBorderOffset;
if (NSMouseInRect(point, aRect, NO))
return (int)i;
@ -969,7 +964,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
NSRect aRect;
aRect = [self rectOfItemAtIndex: index];
aRect = _addLeftBorderOffsetToRect(aRect);
aRect.origin.x -= _leftBorderOffset;
aRect.size.width += _leftBorderOffset;
[self setNeedsDisplayInRect: aRect];
}
@ -992,10 +988,9 @@ _addLeftBorderOffsetToRect(NSRect aRect)
[aSubmenu menuRepresentation])
== GSWindowMakerInterfaceStyle)
{
NSRect aRect = [self rectOfItemAtIndex:
[_attachedMenu indexOfItemWithSubmenu: aSubmenu]];
NSPoint subOrigin = [_window convertBaseToScreen:
NSMakePoint(aRect.origin.x, aRect.origin.y)];
NSRect aRect = [self convertRect: [self rectOfItemAtIndex:
[_attachedMenu indexOfItemWithSubmenu: aSubmenu]] toView: nil];
NSPoint subOrigin = [_window convertBaseToScreen: aRect.origin];
return NSMakePoint (NSMaxX(frame),
subOrigin.y - NSHeight(submenuFrame) - 3 +
@ -1003,10 +998,10 @@ _addLeftBorderOffsetToRect(NSRect aRect)
}
else if ([self _rootIsHorizontal: 0] == YES)
{
NSRect aRect = [self rectOfItemAtIndex:
[_attachedMenu indexOfItemWithSubmenu: aSubmenu]];
NSPoint subOrigin = [_window convertBaseToScreen:
NSMakePoint(aRect.origin.x, aRect.origin.y)];
NSRect aRect = [self convertRect: [self rectOfItemAtIndex:
[_attachedMenu indexOfItemWithSubmenu: aSubmenu]] toView: nil];
NSPoint subOrigin = [_window convertBaseToScreen: aRect.origin];
// FIXME ... why is the offset +1 needed below?
return NSMakePoint (NSMaxX(frame),
subOrigin.y - NSHeight(submenuFrame) + aRect.size.height + 1);
@ -1019,11 +1014,9 @@ _addLeftBorderOffsetToRect(NSRect aRect)
}
else
{
NSRect aRect = [self rectOfItemAtIndex:
[_attachedMenu indexOfItemWithSubmenu: aSubmenu]];
NSPoint subOrigin = [_window convertBaseToScreen:
NSMakePoint(NSMinX(aRect),
NSMinY(aRect))];
NSRect aRect = [self convertRect: [self rectOfItemAtIndex:
[_attachedMenu indexOfItemWithSubmenu: aSubmenu]] toView: nil];
NSPoint subOrigin = [_window convertBaseToScreen: aRect.origin];
return NSMakePoint(subOrigin.x, subOrigin.y - NSHeight(submenuFrame));
}
@ -1355,8 +1348,8 @@ _addLeftBorderOffsetToRect(NSRect aRect)
int index;
location = [_window mouseLocationOutsideOfEventStream];
index = [self indexOfItemAtPoint: location];
index = [self indexOfItemAtPoint:
[self convertPoint: location fromView: nil]];
if (event == original)
{