comparison mac/dw.m @ 1843:2fe7fca61236

Added support for trapping the Mac Quit handler by using DW_DESKTOP as the window handle to dw_signal_connect().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 13 Dec 2012 07:48:30 +0000
parents df7f3967c21e
children 68f923e57542
comparison
equal deleted inserted replaced
1842:123d1a900f54 1843:2fe7fca61236
865 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); } 865 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); }
866 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); } 866 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); }
867 -(BOOL)isFlipped { return YES; } 867 -(BOOL)isFlipped { return YES; }
868 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [font release]; dw_signal_disconnect_by_window(self); [super dealloc]; } 868 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [font release]; dw_signal_disconnect_by_window(self); [super dealloc]; }
869 -(BOOL)acceptsFirstResponder { return YES; } 869 -(BOOL)acceptsFirstResponder { return YES; }
870 @end
871
872 /* Subclass for the application class */
873 @interface DWAppDel : NSObject
874 #ifdef BUILDING_FOR_SNOW_LEOPARD
875 <NSApplicationDelegate>
876 #endif
877 {
878 }
879 -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
880 @end
881
882 @implementation DWAppDel
883 -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
884 {
885 if(_event_handler(sender, nil, 6) > 0)
886 return NSTerminateCancel;
887 return NSTerminateNow;
888 }
870 @end 889 @end
871 890
872 /* Subclass for a top-level window */ 891 /* Subclass for a top-level window */
873 @interface DWView : DWBox 892 @interface DWView : DWBox
874 #ifdef BUILDING_FOR_SNOW_LEOPARD 893 #ifdef BUILDING_FOR_SNOW_LEOPARD
9883 * data: User data to be passed to the handler function. 9902 * data: User data to be passed to the handler function.
9884 */ 9903 */
9885 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data) 9904 void API dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data)
9886 { 9905 {
9887 ULONG message = 0, msgid = 0; 9906 ULONG message = 0, msgid = 0;
9907
9908 /* Handle special case of application delete signal */
9909 if(!window && signame && strcmp(signame, DW_SIGNAL_DELETE) == 0)
9910 {
9911 window = DWApp;
9912 }
9888 9913
9889 if(window && signame && sigfunc) 9914 if(window && signame && sigfunc)
9890 { 9915 {
9891 if((message = _findsigmessage(signame)) != 0) 9916 if((message = _findsigmessage(signame)) != 0)
9892 { 9917 {
10754 * directly, otherwise specify UTF-8 explicitly. 10779 * directly, otherwise specify UTF-8 explicitly.
10755 */ 10780 */
10756 setlocale(LC_ALL, lang && strstr(lang, ".UTF-8") ? lang : "UTF-8"); 10781 setlocale(LC_ALL, lang && strstr(lang, ".UTF-8") ? lang : "UTF-8");
10757 /* Create the application object */ 10782 /* Create the application object */
10758 DWApp = [NSApplication sharedApplication]; 10783 DWApp = [NSApplication sharedApplication];
10784 DWAppDel *del = [[DWAppDel alloc] init];
10785 [DWApp setDelegate:del];
10759 /* Create object for handling timers */ 10786 /* Create object for handling timers */
10760 DWHandler = [[DWTimerHandler alloc] init]; 10787 DWHandler = [[DWTimerHandler alloc] init];
10761 /* If we aren't using garbage collection we need autorelease pools */ 10788 /* If we aren't using garbage collection we need autorelease pools */
10762 #if !defined(GARBAGE_COLLECT) 10789 #if !defined(GARBAGE_COLLECT)
10763 pthread_key_create(&_dw_pool_key, NULL); 10790 pthread_key_create(&_dw_pool_key, NULL);