comparison mac/dw.m @ 723:37c8d2b4cec5

Initial key press event/signal handling... does not seem to trap on all controls... perhaps they need focus? Will have to see what to do about that.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 14 Mar 2011 01:57:33 +0000
parents 5a8d5161651d
children 41080d22edc8
comparison
equal deleted inserted replaced
722:5a8d5161651d 723:37c8d2b4cec5
176 { 176 {
177 return sizefunc(object, size.width, size.height, handler->data); 177 return sizefunc(object, size.width, size.height, handler->data);
178 } 178 }
179 return 0; 179 return 0;
180 } 180 }
181 case 2:
182 {
183 int (*keypressfunc)(HWND, char, int, int, void *) = handler->signalfunction;
184 NSString *nchar = [event charactersIgnoringModifiers];
185 int special = (int)[event modifierFlags];
186 char ch;
187
188 /* Reject dead keys */
189 if([nchar length] == 0)
190 {
191 return 0;
192 }
193 /* Handle a valid key */
194 else if([nchar length] == 1)
195 {
196 const char *tmp = [nchar UTF8String];
197 if(tmp)
198 {
199 ch = tmp[0];
200 }
201 }
202
203 return keypressfunc(handler->window, ch, 0, special, handler->data);
204 }
181 /* Button press and release event */ 205 /* Button press and release event */
182 case 3: 206 case 3:
183 case 4: 207 case 4:
184 { 208 {
185 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; 209 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction;
424 -(void)mouseUp:(NSEvent *)theEvent; 448 -(void)mouseUp:(NSEvent *)theEvent;
425 -(NSMenu *)menuForEvent:(NSEvent *)theEvent; 449 -(NSMenu *)menuForEvent:(NSEvent *)theEvent;
426 -(void)rightMouseUp:(NSEvent *)theEvent; 450 -(void)rightMouseUp:(NSEvent *)theEvent;
427 -(void)otherMouseDown:(NSEvent *)theEvent; 451 -(void)otherMouseDown:(NSEvent *)theEvent;
428 -(void)otherMouseUp:(NSEvent *)theEvent; 452 -(void)otherMouseUp:(NSEvent *)theEvent;
453 -(void)keyDown:(NSEvent *)theEvent;
429 -(void)setColor:(unsigned long)input; 454 -(void)setColor:(unsigned long)input;
430 @end 455 @end
431 456
432 @implementation DWBox 457 @implementation DWBox
433 -(id)init 458 -(id)init
463 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)1, 4); } 488 -(void)mouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)1, 4); }
464 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } 489 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; }
465 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)2, 4); } 490 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)2, 4); }
466 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); } 491 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); }
467 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); } 492 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); }
493 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); }
468 -(void)setColor:(unsigned long)input 494 -(void)setColor:(unsigned long)input
469 { 495 {
470 if(input == _colors[DW_CLR_DEFAULT]) 496 if(input == _colors[DW_CLR_DEFAULT])
471 { 497 {
472 bgcolor = nil; 498 bgcolor = nil;
485 } 511 }
486 -(BOOL)windowShouldClose:(id)sender; 512 -(BOOL)windowShouldClose:(id)sender;
487 -(void)setMenu:(NSMenu *)input; 513 -(void)setMenu:(NSMenu *)input;
488 -(void)windowDidBecomeMain:(id)sender; 514 -(void)windowDidBecomeMain:(id)sender;
489 -(void)menuHandler:(id)sender; 515 -(void)menuHandler:(id)sender;
516 -(void)keyDown:(NSEvent *)theEvent;
490 @end 517 @end
491 518
492 @implementation DWView 519 @implementation DWView
493 -(BOOL)windowShouldClose:(id)sender 520 -(BOOL)windowShouldClose:(id)sender
494 { 521 {
524 } 551 }
525 _event_handler(self, nil, 13); 552 _event_handler(self, nil, 13);
526 } 553 }
527 -(void)setMenu:(NSMenu *)input { windowmenu = input; } 554 -(void)setMenu:(NSMenu *)input { windowmenu = input; }
528 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); } 555 -(void)menuHandler:(id)sender { _event_handler(sender, nil, 8); }
556 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); }
529 @end 557 @end
530 558
531 /* Subclass for a button type */ 559 /* Subclass for a button type */
532 @interface DWButton : NSButton 560 @interface DWButton : NSButton
533 { 561 {
809 -(NSMenu *)menuForEvent:(NSEvent *)theEvent; 837 -(NSMenu *)menuForEvent:(NSEvent *)theEvent;
810 -(void)rightMouseUp:(NSEvent *)theEvent; 838 -(void)rightMouseUp:(NSEvent *)theEvent;
811 -(void)otherMouseDown:(NSEvent *)theEvent; 839 -(void)otherMouseDown:(NSEvent *)theEvent;
812 -(void)otherMouseUp:(NSEvent *)theEvent; 840 -(void)otherMouseUp:(NSEvent *)theEvent;
813 -(void)drawRect:(NSRect)rect; 841 -(void)drawRect:(NSRect)rect;
842 -(void)keyDown:(NSEvent *)theEvent;
814 -(BOOL)isFlipped; 843 -(BOOL)isFlipped;
815 @end 844 @end
816 845
817 @implementation DWRender 846 @implementation DWRender
818 -(void *)userdata { return userdata; } 847 -(void *)userdata { return userdata; }
822 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } 851 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; }
823 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)2, 4); } 852 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)2, 4); }
824 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); } 853 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, (void *)3, 3); }
825 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); } 854 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, (void *)3, 4); }
826 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); } 855 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); }
856 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); _event_handler([self window], theEvent, 2); }
827 -(BOOL)isFlipped { return NO; } 857 -(BOOL)isFlipped { return NO; }
828 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 858 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; }
829 @end 859 @end
830 860
831 /* Subclass for a MLE type */ 861 /* Subclass for a MLE type */
6520 * data: User data to be passed to the handler function. 6550 * data: User data to be passed to the handler function.
6521 */ 6551 */
6522 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) 6552 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data)
6523 { 6553 {
6524 ULONG message = 0, msgid = 0; 6554 ULONG message = 0, msgid = 0;
6525 6555
6526 if(window && signame && sigfunc) 6556 if(window && signame && sigfunc)
6527 { 6557 {
6528 if((message = _findsigmessage(signame)) != 0) 6558 if((message = _findsigmessage(signame)) != 0)
6529 { 6559 {
6530 _new_signal(message, window, (int)msgid, sigfunc, data); 6560 _new_signal(message, window, (int)msgid, sigfunc, data);