diff --git a/ChangeLog b/ChangeLog index f6f8a25f4..ad98ff4cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-04-10 Pierre-Yves Rivaille + + * Source/NSWindow.m ([-sendEvent:], case NSRightMouseDown): + removed code to display the menu. This is now done by + [NSView -rightMouseDown:]. + * Source/NSView.m: overrides -menu, + changes -rightMouseDown: to display the menu, + documents -menu, -menuForEvent: and +defaultMenu. + 2003-04-10 Richard Frith-Macdonald * Source/GSServicesManager.m: on opening file, only activate for diff --git a/Source/NSView.m b/Source/NSView.m index 3f36c7fdc..053c9aa77 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -3764,14 +3765,58 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) } -/* - * Menu operations +/** + *

Returns the default menu to be used for instances of the + * current class: if no menu has been set through setMenu: + * this default menu will be used. + *

+ *

NSView's implementation returns nil. You should override + * this method if you want all instances of your custom view + * to use the same menu. + *

*/ + (NSMenu *)defaultMenu { return nil; } +/** + *

NSResponder's method, overriden by NSView.

+ *

If no menu has been set through the use of setMenu:, or + * if a nil value has been set through setMenu:, then the + * value returned by defaultMenu is used. Otherwise this + * method returns the menu set through NSResponder. + *

+ *

see [NSResponder -menu], [NSResponder -setMenu:], + * [NSView +defaultMenu] and [NSView -menuForEvent:]. + *

+ */ +- (NSMenu *)menu +{ + NSMenu *m = [super menu]; + if (m) + { + return m; + } + else + { + return [[self class] defaultMenu]; + } +} + +/** + *

Returns the menu that it appropriates for the given + * event. NSView's implementation returns the default menu of + * the view.

+ *

This methods is intended to be overriden so that it can + * return a context-sensitive for appropriate mouse's events. ( + * (although it seems it can be used for any kind of event)

+ *

This method is used by NSView's rightMouseDown: method, + * and the returned NSMenu is displayed as a context menu

+ *

see [NSResponder -menu], [NSResponder -setMenu:], + * [NSView +defaultMenu] and [NSView -menu]. + *

+ */ - (NSMenu *)menuForEvent:(NSEvent *)theEvent { return [self menu]; @@ -3938,5 +3983,21 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) } } +- (void) rightMouseDown: (NSEvent *) theEvent +{ + NSMenu *m; + m = [self menuForEvent: theEvent]; + if (m) + { + [NSMenu popUpContextMenu: m + withEvent: theEvent + forView: self]; + } + else + { + [super rightMouseDown: theEvent]; + } +} + @end diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 6520816a1..cfef51d9c 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -2889,17 +2889,7 @@ Code shared with [NSPanel -sendEvent:], remember to update both places. { NSMenu *m; v = [_contentView hitTest: [theEvent locationInWindow]]; - m = [v menuForEvent: theEvent]; - if (m) - { - [NSMenu popUpContextMenu: m - withEvent: theEvent - forView: v]; - } - else - { - [v rightMouseDown: theEvent]; - } + [v rightMouseDown: theEvent]; _lastPoint = [theEvent locationInWindow]; } break;