From 6da62ade410c76de27dd0c4d51cf2dbed8edbe15 Mon Sep 17 00:00:00 2001 From: Jjgod Jiang Date: Sun, 9 May 2010 12:58:58 +0800 Subject: [PATCH] Fix right mouse event handling in Cocoa NSView in Cocoa has a different event handling procedure for right mouse events (rightMouseDown: etc.) --- src/video/cocoa/SDL_cocoawindow.m | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 8d1c46aab..d81d9c543 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -376,6 +376,30 @@ - (BOOL)canBecomeMainWindow } @end +@interface SDLView : NSView { + Cocoa_WindowListener *listener; +} +@end + +@implementation SDLView + +- (id) initWithFrame: (NSRect) rect + listener: (Cocoa_WindowListener *) theListener +{ + if (self = [super initWithFrame:rect]) { + listener = theListener; + } + + return self; +} + +- (void)rightMouseDown:(NSEvent *)theEvent +{ + [listener mouseDown:theEvent]; +} + +@end + static int SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created) { @@ -407,6 +431,11 @@ - (BOOL)canBecomeMainWindow { SDL_Rect bounds; NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]]; + NSView *contentView = [[SDLView alloc] initWithFrame: rect + listener: data->listener]; + [nswindow setContentView: contentView]; + [contentView release]; + ConvertNSRect(&rect); Cocoa_GetDisplayBounds(_this, display, &bounds); window->x = (int)rect.origin.x - bounds.x;