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:
rmottola 2009-01-23 22:01:40 +00:00
parent 511b5be242
commit d983415d4d
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> 2009-01-22 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSWindowDecorationView.m: Add handling of in-window * Source/GSWindowDecorationView.m: Add handling of in-window

View file

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

View file

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