Mercurial > dwindows
comparison mac/dw.m @ 894:d1d7e5c51860
Added a DWWindow subclass to trap key events on the main window for Mac.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 18 Apr 2011 00:13:17 +0000 |
parents | 3774af45eb0c |
children | 8c29ea2d17fc |
comparison
equal
deleted
inserted
replaced
893:39ab47d103c3 | 894:d1d7e5c51860 |
---|---|
109 int _dw_main_iteration(NSDate *date); | 109 int _dw_main_iteration(NSDate *date); |
110 | 110 |
111 SignalHandler *_get_handler(HWND window, int messageid) | 111 SignalHandler *_get_handler(HWND window, int messageid) |
112 { | 112 { |
113 SignalHandler *tmp = Root; | 113 SignalHandler *tmp = Root; |
114 | 114 id object = window; |
115 | |
115 /* Find any callbacks for this function */ | 116 /* Find any callbacks for this function */ |
116 while(tmp) | 117 while(tmp) |
117 { | 118 { |
118 if(tmp->message == messageid && window == tmp->window) | 119 if(tmp->message == messageid && window == tmp->window) |
119 { | 120 { |
176 case 1: | 177 case 1: |
177 { | 178 { |
178 int (*sizefunc)(HWND, int, int, void *) = handler->signalfunction; | 179 int (*sizefunc)(HWND, int, int, void *) = handler->signalfunction; |
179 NSSize size; | 180 NSSize size; |
180 | 181 |
181 if([object isMemberOfClass:[NSWindow class]]) | 182 if([object isKindOfClass:[NSWindow class]]) |
182 { | 183 { |
183 NSWindow *window = object; | 184 NSWindow *window = object; |
184 size = [[window contentView] frame].size; | 185 size = [[window contentView] frame].size; |
185 } | 186 } |
186 else | 187 else |
536 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)1, 4); } | 537 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)1, 4); } |
537 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } | 538 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } |
538 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)2, 4); } | 539 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)2, 4); } |
539 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); } | 540 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); } |
540 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); } | 541 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); } |
541 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); } | 542 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); } |
542 -(void)setColor:(unsigned long)input | 543 -(void)setColor:(unsigned long)input |
543 { | 544 { |
544 id orig = bgcolor; | 545 id orig = bgcolor; |
545 | 546 |
546 if(input == _colors[DW_CLR_DEFAULT]) | 547 if(input == _colors[DW_CLR_DEFAULT]) |
573 -(Box *)box { return [[self contentView] box]; } | 574 -(Box *)box { return [[self contentView] box]; } |
574 -(void *)userdata { return userdata; } | 575 -(void *)userdata { return userdata; } |
575 -(void)setUserdata:(void *)input { userdata = input; } | 576 -(void)setUserdata:(void *)input { userdata = input; } |
576 @end | 577 @end |
577 | 578 |
579 @interface DWWindow : NSWindow | |
580 -(void)keyDown:(NSEvent *)theEvent; | |
581 @end | |
582 | |
583 @implementation DWWindow | |
584 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); } | |
585 @end | |
586 | |
578 /* Subclass for a top-level window */ | 587 /* Subclass for a top-level window */ |
579 @interface DWView : DWBox | 588 @interface DWView : DWBox |
580 #ifdef BUILDING_FOR_SNOW_LEOPARD | 589 #ifdef BUILDING_FOR_SNOW_LEOPARD |
581 <NSWindowDelegate> | 590 <NSWindowDelegate> |
582 #endif | 591 #endif |
585 } | 594 } |
586 -(BOOL)windowShouldClose:(id)sender; | 595 -(BOOL)windowShouldClose:(id)sender; |
587 -(void)setMenu:(NSMenu *)input; | 596 -(void)setMenu:(NSMenu *)input; |
588 -(void)windowDidBecomeMain:(id)sender; | 597 -(void)windowDidBecomeMain:(id)sender; |
589 -(void)menuHandler:(id)sender; | 598 -(void)menuHandler:(id)sender; |
590 -(void)keyDown:(NSEvent *)theEvent; | |
591 -(void)mouseMoved:(NSEvent *)theEvent; | 599 -(void)mouseMoved:(NSEvent *)theEvent; |
592 @end | 600 @end |
593 | 601 |
594 @implementation DWView | 602 @implementation DWView |
595 -(BOOL)windowShouldClose:(id)sender | 603 -(BOOL)windowShouldClose:(id)sender |
630 } | 638 } |
631 _event_handler(self, nil, 13); | 639 _event_handler(self, nil, 13); |
632 } | 640 } |
633 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; } | 641 -(void)setMenu:(NSMenu *)input { windowmenu = input; [windowmenu retain]; } |
634 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); } | 642 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); } |
635 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); } | |
636 -(void)mouseMoved:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } | 643 -(void)mouseMoved:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } |
637 @end | 644 @end |
638 | 645 |
639 /* Subclass for a button type */ | 646 /* Subclass for a button type */ |
640 @interface DWButton : NSButton | 647 @interface DWButton : NSButton |
1098 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } | 1105 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } |
1099 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)2, 4); } | 1106 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)2, 4); } |
1100 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); } | 1107 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); } |
1101 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); } | 1108 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); } |
1102 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); } | 1109 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); } |
1103 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); } | 1110 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); } |
1104 -(BOOL)isFlipped { return NO; } | 1111 -(BOOL)isFlipped { return NO; } |
1105 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [font release]; [super dealloc]; } | 1112 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [font release]; [super dealloc]; } |
1106 @end | 1113 @end |
1107 | 1114 |
1108 /* Subclass for a MLE type */ | 1115 /* Subclass for a MLE type */ |
6424 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) | 6431 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) |
6425 { | 6432 { |
6426 int _locked_by_me = FALSE; | 6433 int _locked_by_me = FALSE; |
6427 DW_MUTEX_LOCK; | 6434 DW_MUTEX_LOCK; |
6428 NSRect frame = NSMakeRect(1,1,1,1); | 6435 NSRect frame = NSMakeRect(1,1,1,1); |
6429 NSWindow *window = [[NSWindow alloc] | 6436 DWWindow *window = [[DWWindow alloc] |
6430 initWithContentRect:frame | 6437 initWithContentRect:frame |
6431 styleMask:(flStyle | NSTexturedBackgroundWindowMask) | 6438 styleMask:(flStyle | NSTexturedBackgroundWindowMask) |
6432 backing:NSBackingStoreBuffered | 6439 backing:NSBackingStoreBuffered |
6433 defer:false]; | 6440 defer:false]; |
6434 | 6441 |
6647 */ | 6654 */ |
6648 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) | 6655 void API dw_window_set_style(HWND handle, ULONG style, ULONG mask) |
6649 { | 6656 { |
6650 id object = handle; | 6657 id object = handle; |
6651 | 6658 |
6652 if(DWOSMinor > 5 && [object isMemberOfClass:[NSWindow class]]) | 6659 if(DWOSMinor > 5 && [object isMemberOfClass:[DWWindow class]]) |
6653 { | 6660 { |
6654 NSWindow *window = object; | 6661 DWWindow *window = object; |
6655 int currentstyle = (int)[window styleMask]; | 6662 int currentstyle = (int)[window styleMask]; |
6656 int tmp; | 6663 int tmp; |
6657 | 6664 |
6658 tmp = currentstyle | (int)mask; | 6665 tmp = currentstyle | (int)mask; |
6659 tmp ^= mask; | 6666 tmp ^= mask; |
6702 * window: Toplevel window or dialog. | 6709 * window: Toplevel window or dialog. |
6703 * defaultitem: Handle to the dialog item to be default. | 6710 * defaultitem: Handle to the dialog item to be default. |
6704 */ | 6711 */ |
6705 void API dw_window_default(HWND handle, HWND defaultitem) | 6712 void API dw_window_default(HWND handle, HWND defaultitem) |
6706 { | 6713 { |
6707 NSWindow *window = handle; | 6714 DWWindow *window = handle; |
6708 id object = defaultitem; | 6715 id object = defaultitem; |
6709 | 6716 |
6710 if([window isKindOfClass:[NSWindow class]] && [object isKindOfClass:[NSControl class]]) | 6717 if([window isKindOfClass:[NSWindow class]] && [object isKindOfClass:[NSControl class]]) |
6711 { | 6718 { |
6712 [window setInitialFirstResponder:defaultitem]; | 6719 [window setInitialFirstResponder:defaultitem]; |
6722 void API dw_window_click_default(HWND handle, HWND next) | 6729 void API dw_window_click_default(HWND handle, HWND next) |
6723 { | 6730 { |
6724 id object = handle; | 6731 id object = handle; |
6725 id control = next; | 6732 id control = next; |
6726 | 6733 |
6727 if([object isMemberOfClass:[NSWindow class]]) | 6734 if([object isMemberOfClass:[DWWindow class]]) |
6728 { | 6735 { |
6729 if([control isMemberOfClass:[DWButton class]]) | 6736 if([control isMemberOfClass:[DWButton class]]) |
6730 { | 6737 { |
6731 NSWindow *window = object; | 6738 NSWindow *window = object; |
6732 | 6739 |
6759 */ | 6766 */ |
6760 void API dw_window_capture(HWND handle) | 6767 void API dw_window_capture(HWND handle) |
6761 { | 6768 { |
6762 id object = handle; | 6769 id object = handle; |
6763 | 6770 |
6764 if(![object isMemberOfClass:[NSWindow class]]) | 6771 if(![object isMemberOfClass:[DWWindow class]]) |
6765 { | 6772 { |
6766 object = [object window]; | 6773 object = [object window]; |
6767 } | 6774 } |
6768 if(object) | 6775 if(object) |
6769 { | 6776 { |
6792 */ | 6799 */ |
6793 void API dw_window_reparent(HWND handle, HWND newparent) | 6800 void API dw_window_reparent(HWND handle, HWND newparent) |
6794 { | 6801 { |
6795 id object = handle; | 6802 id object = handle; |
6796 | 6803 |
6797 if([object isMemberOfClass:[NSWindow class]]) | 6804 if([object isMemberOfClass:[DWWindow class]]) |
6798 { | 6805 { |
6799 /* We can't actually reparent on MacOS but if the | 6806 /* We can't actually reparent on MacOS but if the |
6800 * new parent is an MDI window, change to be a | 6807 * new parent is an MDI window, change to be a |
6801 * floating window... otherwise set it to normal. | 6808 * floating window... otherwise set it to normal. |
6802 */ | 6809 */ |
7418 * data: User data to be passed to the handler function. | 7425 * data: User data to be passed to the handler function. |
7419 */ | 7426 */ |
7420 void dw_window_set_data(HWND window, char *dataname, void *data) | 7427 void dw_window_set_data(HWND window, char *dataname, void *data) |
7421 { | 7428 { |
7422 id object = window; | 7429 id object = window; |
7423 if([object isMemberOfClass:[NSWindow class]]) | 7430 if([object isMemberOfClass:[DWWindow class]]) |
7424 { | 7431 { |
7425 NSWindow *win = window; | 7432 NSWindow *win = window; |
7426 object = [win contentView]; | 7433 object = [win contentView]; |
7427 } | 7434 } |
7428 else if([object isMemberOfClass:[NSScrollView class]]) | 7435 else if([object isMemberOfClass:[NSScrollView class]]) |
7460 * data: User data to be passed to the handler function. | 7467 * data: User data to be passed to the handler function. |
7461 */ | 7468 */ |
7462 void *dw_window_get_data(HWND window, char *dataname) | 7469 void *dw_window_get_data(HWND window, char *dataname) |
7463 { | 7470 { |
7464 id object = window; | 7471 id object = window; |
7465 if([object isMemberOfClass:[NSWindow class]]) | 7472 if([object isMemberOfClass:[DWWindow class]]) |
7466 { | 7473 { |
7467 NSWindow *win = window; | 7474 NSWindow *win = window; |
7468 object = [win contentView]; | 7475 object = [win contentView]; |
7469 } | 7476 } |
7470 else if([object isMemberOfClass:[NSScrollView class]]) | 7477 else if([object isMemberOfClass:[NSScrollView class]]) |