Mercurial > dwindows
comparison mac/dw.m @ 1985:8d130e45430d
Mac: Rewrite dw_messagebox() to make it thread safe on Mojave.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 03 Sep 2019 16:58:09 +0000 |
parents | 09a102c92788 |
children | 218fce0e3b06 |
comparison
equal
deleted
inserted
replaced
1984:09a102c92788 | 1985:8d130e45430d |
---|---|
1151 void (*mycallback)(NSPointerArray *) = [params pointerAtIndex:0]; | 1151 void (*mycallback)(NSPointerArray *) = [params pointerAtIndex:0]; |
1152 if(mycallback) | 1152 if(mycallback) |
1153 mycallback(params); | 1153 mycallback(params); |
1154 } | 1154 } |
1155 #endif | 1155 #endif |
1156 -(void)messageBox:(NSMutableArray *)params | |
1157 { | |
1158 NSInteger iResponse; | |
1159 NSAlert *alert = [[NSAlert alloc] init]; | |
1160 [alert setMessageText:[params objectAtIndex:0]]; | |
1161 [alert setInformativeText:[params objectAtIndex:1]]; | |
1162 [alert addButtonWithTitle:[params objectAtIndex:3]]; | |
1163 if([params count] > 4) | |
1164 [alert addButtonWithTitle:[params objectAtIndex:4]]; | |
1165 if([params count] > 5) | |
1166 [alert addButtonWithTitle:[params objectAtIndex:5]]; | |
1167 [alert setAlertStyle:[[params objectAtIndex:2] integerValue]]; | |
1168 iResponse = [alert runModal]; | |
1169 [alert release]; | |
1170 [params addObject:[NSNumber numberWithInteger:iResponse]]; | |
1171 } | |
1156 -(void)safeCall:(SEL)sel withObject:(id)param | 1172 -(void)safeCall:(SEL)sel withObject:(id)param |
1157 { | 1173 { |
1158 if([self respondsToSelector:sel]) | 1174 if([self respondsToSelector:sel]) |
1159 { | 1175 { |
1160 DWTID curr = pthread_self(); | 1176 DWTID curr = pthread_self(); |
3835 * format: printf style format string. | 3851 * format: printf style format string. |
3836 * ...: Additional variables for use in the format. | 3852 * ...: Additional variables for use in the format. |
3837 */ | 3853 */ |
3838 int API dw_messagebox(char *title, int flags, char *format, ...) | 3854 int API dw_messagebox(char *title, int flags, char *format, ...) |
3839 { | 3855 { |
3840 NSAlert *alert; | |
3841 NSInteger iResponse; | 3856 NSInteger iResponse; |
3842 NSString *button1 = @"OK"; | 3857 NSString *button1 = @"OK"; |
3843 NSString *button2 = nil; | 3858 NSString *button2 = nil; |
3844 NSString *button3 = nil; | 3859 NSString *button3 = nil; |
3860 NSString *mtitle = [NSString stringWithUTF8String:title]; | |
3861 NSString *mtext; | |
3862 NSAlertStyle mstyle = DWAlertStyleWarning; | |
3863 NSArray *params; | |
3845 va_list args; | 3864 va_list args; |
3846 | 3865 |
3847 if(flags & DW_MB_OKCANCEL) | 3866 if(flags & DW_MB_OKCANCEL) |
3848 { | 3867 { |
3849 button2 = @"Cancel"; | 3868 button2 = @"Cancel"; |
3859 button2 = @"No"; | 3878 button2 = @"No"; |
3860 button3 = @"Cancel"; | 3879 button3 = @"Cancel"; |
3861 } | 3880 } |
3862 | 3881 |
3863 va_start(args, format); | 3882 va_start(args, format); |
3864 alert = [[NSAlert alloc] init]; | 3883 mtext = [[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:args] autorelease]; |
3865 [alert setMessageText:[NSString stringWithUTF8String:title]]; | |
3866 [alert setInformativeText:[[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:args] autorelease]]; | |
3867 [alert addButtonWithTitle:button1]; | |
3868 if(button2) | |
3869 [alert addButtonWithTitle:button2]; | |
3870 if(button3) | |
3871 [alert addButtonWithTitle:button3]; | |
3872 va_end(args); | 3884 va_end(args); |
3873 | 3885 |
3874 if(flags & DW_MB_ERROR) | 3886 if(flags & DW_MB_ERROR) |
3875 [alert setAlertStyle:DWAlertStyleCritical]; | 3887 mstyle = DWAlertStyleCritical; |
3876 else if(flags & DW_MB_INFORMATION) | 3888 else if(flags & DW_MB_INFORMATION) |
3877 [alert setAlertStyle:DWAlertStyleInformational]; | 3889 mstyle = DWAlertStyleInformational; |
3878 else | 3890 |
3879 [alert setAlertStyle:DWAlertStyleWarning]; | 3891 params = [NSMutableArray arrayWithObjects:mtitle, mtext, [NSNumber numberWithInteger:mstyle], button1, button2, button3, nil]; |
3880 iResponse = [alert runModal]; | 3892 [DWObj safeCall:@selector(messageBox:) withObject:params]; |
3881 [alert release]; | 3893 iResponse = [[params lastObject] integerValue]; |
3882 | 3894 |
3883 switch(iResponse) | 3895 switch(iResponse) |
3884 { | 3896 { |
3885 case NSAlertFirstButtonReturn: /* user pressed OK */ | 3897 case NSAlertFirstButtonReturn: /* user pressed OK */ |
3886 if(flags & DW_MB_YESNO || flags & DW_MB_YESNOCANCEL) | 3898 if(flags & DW_MB_YESNO || flags & DW_MB_YESNOCANCEL) |