Mercurial > dwindows
comparison mac/dw.m @ 932:ed10b5284f36
Fixes for dw_window_capture(), dw_window_release() and motion notify events on Mac.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 25 Apr 2011 20:42:56 +0000 |
parents | dfd84cefd80b |
children | b19e6e55fc8e |
comparison
equal
deleted
inserted
replaced
931:dfd84cefd80b | 932:ed10b5284f36 |
---|---|
239 /* Motion notify event */ | 239 /* Motion notify event */ |
240 case 5: | 240 case 5: |
241 { | 241 { |
242 int (* API motionfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; | 242 int (* API motionfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; |
243 int buttonmask = (int)[NSEvent pressedMouseButtons]; | 243 int buttonmask = (int)[NSEvent pressedMouseButtons]; |
244 NSPoint point = [NSEvent mouseLocation]; | 244 NSPoint point = [object convertPoint:[event locationInWindow] fromView:nil]; |
245 | 245 |
246 return motionfunc(object, (int)point.x, (int)point.y, buttonmask, handler->data); | 246 return motionfunc(object, (int)point.x, (int)point.y, buttonmask, handler->data); |
247 } | 247 } |
248 /* Window close event */ | 248 /* Window close event */ |
249 case 6: | 249 case 6: |
381 DWTimerHandler *DWHandler; | 381 DWTimerHandler *DWHandler; |
382 #if !defined(GARBAGE_COLLECT) | 382 #if !defined(GARBAGE_COLLECT) |
383 NSAutoreleasePool *pool; | 383 NSAutoreleasePool *pool; |
384 #endif | 384 #endif |
385 HWND _DWLastDrawable; | 385 HWND _DWLastDrawable; |
386 id _DWCapture; | |
386 HMTX DWRunMutex; | 387 HMTX DWRunMutex; |
387 HMTX DWThreadMutex; | 388 HMTX DWThreadMutex; |
388 HMTX DWThreadMutex2; | 389 HMTX DWThreadMutex2; |
389 DWTID DWThread = (DWTID)-1; | 390 DWTID DWThread = (DWTID)-1; |
390 DWTID _dw_mutex_locked = (DWTID)-1; | 391 DWTID _dw_mutex_locked = (DWTID)-1; |
637 @end | 638 @end |
638 | 639 |
639 @interface DWWindow : NSWindow | 640 @interface DWWindow : NSWindow |
640 -(void)sendEvent:(NSEvent *)theEvent; | 641 -(void)sendEvent:(NSEvent *)theEvent; |
641 -(void)keyDown:(NSEvent *)theEvent; | 642 -(void)keyDown:(NSEvent *)theEvent; |
643 -(void)mouseDragged:(NSEvent *)theEvent; | |
642 @end | 644 @end |
643 | 645 |
644 @implementation DWWindow | 646 @implementation DWWindow |
645 -(void)sendEvent:(NSEvent *)theEvent { if([theEvent type] == NSKeyDown) { _event_handler(self, theEvent, 2); } [super sendEvent:theEvent]; } | 647 -(void)sendEvent:(NSEvent *)theEvent { if([theEvent type] == NSKeyDown) { _event_handler(self, theEvent, 2); } [super sendEvent:theEvent]; } |
646 -(void)keyDown:(NSEvent *)theEvent { } | 648 -(void)keyDown:(NSEvent *)theEvent { } |
649 -(void)mouseDragged:(NSEvent *)theEvent { if(_DWCapture == self) { _event_handler(self, theEvent, 5); } } | |
647 @end | 650 @end |
648 | 651 |
649 /* Subclass for a top-level window */ | 652 /* Subclass for a top-level window */ |
650 @interface DWView : DWBox | 653 @interface DWView : DWBox |
651 #ifdef BUILDING_FOR_SNOW_LEOPARD | 654 #ifdef BUILDING_FOR_SNOW_LEOPARD |
657 } | 660 } |
658 -(BOOL)windowShouldClose:(id)sender; | 661 -(BOOL)windowShouldClose:(id)sender; |
659 -(void)setMenu:(NSMenu *)input; | 662 -(void)setMenu:(NSMenu *)input; |
660 -(void)windowDidBecomeMain:(id)sender; | 663 -(void)windowDidBecomeMain:(id)sender; |
661 -(void)menuHandler:(id)sender; | 664 -(void)menuHandler:(id)sender; |
662 -(void)mouseMoved:(NSEvent *)theEvent; | 665 -(void)mouseDragged:(NSEvent *)theEvent; |
663 @end | 666 @end |
664 | 667 |
665 @implementation DWView | 668 @implementation DWView |
666 -(BOOL)windowShouldClose:(id)sender | 669 -(BOOL)windowShouldClose:(id)sender |
667 { | 670 { |
719 } | 722 } |
720 _event_handler(self, nil, 13); | 723 _event_handler(self, nil, 13); |
721 } | 724 } |
722 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; } | 725 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; } |
723 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); } | 726 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); } |
724 -(void)mouseMoved:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } | 727 -(void)mouseDragged:(NSEvent *)theEvent { if(_DWCapture == self) { _event_handler(self, theEvent, 5); } } |
725 @end | 728 @end |
726 | 729 |
727 /* Subclass for a button type */ | 730 /* Subclass for a button type */ |
728 @interface DWButton : NSButton | 731 @interface DWButton : NSButton |
729 { | 732 { |
1186 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } | 1189 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } |
1187 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } | 1190 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } |
1188 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } | 1191 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } |
1189 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); } | 1192 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); } |
1190 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } | 1193 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } |
1194 -(void)mouseDragged:(NSEvent *)theEvent { if(_DWCapture == self) { _event_handler(self, theEvent, 5); } } | |
1191 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); } | 1195 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); } |
1192 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); } | 1196 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); } |
1193 -(BOOL)isFlipped { return NO; } | 1197 -(BOOL)isFlipped { return NO; } |
1194 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [font release]; [super dealloc]; } | 1198 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [font release]; [super dealloc]; } |
1199 -(BOOL)acceptsFirstResponder { return YES; } | |
1195 @end | 1200 @end |
1196 | 1201 |
1197 /* Subclass for a MLE type */ | 1202 /* Subclass for a MLE type */ |
1198 @interface DWMLE : NSTextView | 1203 @interface DWMLE : NSTextView |
1199 { | 1204 { |
6971 } | 6976 } |
6972 [object setClickDefault:control]; | 6977 [object setClickDefault:control]; |
6973 } | 6978 } |
6974 } | 6979 } |
6975 | 6980 |
6976 static id _DWCapture; | |
6977 | |
6978 /* | 6981 /* |
6979 * Captures the mouse input to this window. | 6982 * Captures the mouse input to this window. |
6980 * Parameters: | 6983 * Parameters: |
6981 * handle: Handle to receive mouse input. | 6984 * handle: Handle to receive mouse input. |
6982 */ | 6985 */ |
6983 void API dw_window_capture(HWND handle) | 6986 void API dw_window_capture(HWND handle) |
6984 { | 6987 { |
6985 id object = handle; | 6988 id object = handle; |
6989 id window = handle; | |
6986 | 6990 |
6987 if(![object isMemberOfClass:[DWWindow class]]) | 6991 if(![object isMemberOfClass:[DWWindow class]]) |
6988 { | 6992 { |
6989 object = [object window]; | 6993 window = [object window]; |
6990 } | 6994 } |
6991 if(object) | 6995 if(window) |
6992 { | 6996 { |
6993 [object setAcceptsMouseMovedEvents:YES]; | |
6994 _DWCapture = object; | 6997 _DWCapture = object; |
6995 } | 6998 } |
6996 } | 6999 } |
6997 | 7000 |
6998 /* | 7001 /* |
7000 */ | 7003 */ |
7001 void API dw_window_release(void) | 7004 void API dw_window_release(void) |
7002 { | 7005 { |
7003 if(_DWCapture) | 7006 if(_DWCapture) |
7004 { | 7007 { |
7005 [_DWCapture setAcceptsMouseMovedEvents:NO]; | |
7006 _DWCapture = nil; | 7008 _DWCapture = nil; |
7007 } | 7009 } |
7008 } | 7010 } |
7009 | 7011 |
7010 /* | 7012 /* |