Mercurial > dwindows
comparison ios/dw.m @ 2698:5c43d1ee9736
iOS: Implement dw_exec() using posix_spawnp(). Fix a few warnings.
Also put in some extra bounds checks in DWComboBox.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 03 Nov 2021 00:51:38 +0000 |
parents | 0dac724f890f |
children | 0d5e99279c8b |
comparison
equal
deleted
inserted
replaced
2697:4470089e14b3 | 2698:5c43d1ee9736 |
---|---|
19 #include <sys/un.h> | 19 #include <sys/un.h> |
20 #include <sys/mman.h> | 20 #include <sys/mman.h> |
21 #include <sys/time.h> | 21 #include <sys/time.h> |
22 #include <sys/stat.h> | 22 #include <sys/stat.h> |
23 #include <math.h> | 23 #include <math.h> |
24 #include <spawn.h> | |
24 | 25 |
25 /* Macros to handle local auto-release pools */ | 26 /* Macros to handle local auto-release pools */ |
26 #define DW_LOCAL_POOL_IN NSAutoreleasePool *localpool = nil; \ | 27 #define DW_LOCAL_POOL_IN NSAutoreleasePool *localpool = nil; \ |
27 if(DWThread != (DWTID)-1 && pthread_self() != DWThread) \ | 28 if(DWThread != (DWTID)-1 && pthread_self() != DWThread) \ |
28 localpool = [[NSAutoreleasePool alloc] init]; | 29 localpool = [[NSAutoreleasePool alloc] init]; |
1476 -(void)buttonClicked:(id)sender; | 1477 -(void)buttonClicked:(id)sender; |
1477 -(void)setParent:(DWBox *)input; | 1478 -(void)setParent:(DWBox *)input; |
1478 -(DWBox *)parent; | 1479 -(DWBox *)parent; |
1479 -(int)type; | 1480 -(int)type; |
1480 -(void)setType:(int)input; | 1481 -(void)setType:(int)input; |
1481 -(int)state; | 1482 -(int)checkState; |
1482 -(void)setCheckState:(int)input; | 1483 -(void)setCheckState:(int)input; |
1483 @end | 1484 @end |
1484 | 1485 |
1485 @implementation DWButton | 1486 @implementation DWButton |
1486 -(void *)userdata { return userdata; } | 1487 -(void *)userdata { return userdata; } |
2716 } | 2717 } |
2717 -(void)deleteAtIndex:(int)index { if(index > -1 && index < [dataArray count]) [dataArray removeObjectAtIndex:index]; } | 2718 -(void)deleteAtIndex:(int)index { if(index > -1 && index < [dataArray count]) [dataArray removeObjectAtIndex:index]; } |
2718 -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; } | 2719 -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; } |
2719 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component | 2720 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component |
2720 { | 2721 { |
2721 selectedIndex = (int)row; | 2722 if(row > -1 && row < [dataArray count]) |
2722 [self setText:[dataArray objectAtIndex:row]]; | 2723 { |
2723 [self sendActionsForControlEvents:UIControlEventValueChanged]; | 2724 selectedIndex = (int)row; |
2724 _dw_event_handler(self, DW_INT_TO_POINTER(selectedIndex), _DW_EVENT_LIST_SELECT); | 2725 [self setText:[dataArray objectAtIndex:row]]; |
2726 [self sendActionsForControlEvents:UIControlEventValueChanged]; | |
2727 _dw_event_handler(self, DW_INT_TO_POINTER(selectedIndex), _DW_EVENT_LIST_SELECT); | |
2728 } | |
2725 } | 2729 } |
2726 -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return [dataArray count]; } | 2730 -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return [dataArray count]; } |
2727 -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component | 2731 -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component |
2728 { | 2732 { |
2729 return [dataArray objectAtIndex:row]; | 2733 if(row > -1 && row < [dataArray count]) |
2734 return [dataArray objectAtIndex:row]; | |
2735 return nil; | |
2730 } | 2736 } |
2731 -(void)doneClicked:(id)sender | 2737 -(void)doneClicked:(id)sender |
2732 { | 2738 { |
2733 /* Hides the pickerView */ | 2739 /* Hides the pickerView */ |
2734 [self resignFirstResponder]; | 2740 [self resignFirstResponder]; |
10785 * type: Either DW_EXEC_CON or DW_EXEC_GUI. | 10791 * type: Either DW_EXEC_CON or DW_EXEC_GUI. |
10786 * params: An array of pointers to string arguements. | 10792 * params: An array of pointers to string arguements. |
10787 * Returns: | 10793 * Returns: |
10788 * DW_ERROR_UNKNOWN (-1) on error. | 10794 * DW_ERROR_UNKNOWN (-1) on error. |
10789 */ | 10795 */ |
10790 int dw_exec(const char *program, int type, char **params) | 10796 int API dw_exec(const char *program, int type, char **params) |
10791 { | 10797 { |
10792 int ret = DW_ERROR_UNKNOWN; | 10798 int retval = DW_ERROR_UNKNOWN; |
10793 | 10799 pid_t pid; |
10794 #if 0 /* TODO: Figure out how to do this on iOS */ | 10800 |
10795 if(type == DW_EXEC_GUI) | 10801 /* Launch the application directly using posix_spawnp() |
10796 { | 10802 * Might need to use openURLs to open DW_EXEC_GUI. |
10797 NSString *nsprogram = [NSString stringWithUTF8String:program]; | 10803 */ |
10798 NSWorkspace *ws = [NSWorkspace sharedWorkspace]; | 10804 if(posix_spawnp(&pid, program, NULL, NULL, params, NULL) == 0) |
10799 | 10805 { |
10800 if(params && params[0] && params[1]) | 10806 if(pid > 0) |
10801 { | 10807 retval = pid; |
10802 NSURL *url = _dw_url_from_program(nsprogram, ws); | |
10803 NSMutableArray *array = [[NSMutableArray alloc] init]; | |
10804 __block DWDialog *dialog = dw_dialog_new(NULL); | |
10805 int z = 1; | |
10806 | |
10807 while(params[z]) | |
10808 { | |
10809 NSString *thisfile = [NSString stringWithUTF8String:params[z]]; | |
10810 NSURL *nsfile = [NSURL fileURLWithPath:thisfile]; | |
10811 | |
10812 [array addObject:nsfile]; | |
10813 z++; | |
10814 } | |
10815 | |
10816 [ws openURLs:array withApplicationAtURL:url | |
10817 configuration:[NSWorkspaceOpenConfiguration configuration] | |
10818 completionHandler:^(NSRunningApplication *app, NSError *error) { | |
10819 int pid = DW_ERROR_UNKNOWN; | |
10820 | |
10821 if(error) | |
10822 NSLog(@"openURLs: %@", [error localizedDescription]); | |
10823 else | |
10824 pid = [app processIdentifier]; | |
10825 dw_dialog_dismiss(dialog, DW_INT_TO_POINTER(pid)); | |
10826 }]; | |
10827 ret = DW_POINTER_TO_INT(dw_dialog_wait(dialog)); | |
10828 } | |
10829 else | 10808 else |
10830 { | 10809 retval = DW_ERROR_NONE; |
10831 NSURL *url = _dw_url_from_program(nsprogram, ws); | 10810 } |
10832 __block DWDialog *dialog = dw_dialog_new(NULL); | 10811 return retval; |
10833 | |
10834 [ws openApplicationAtURL:url | |
10835 configuration:[NSWorkspaceOpenConfiguration configuration] | |
10836 completionHandler:^(NSRunningApplication *app, NSError *error) { | |
10837 int pid = DW_ERROR_UNKNOWN; | |
10838 | |
10839 if(error) | |
10840 NSLog(@"openApplicationAtURL: %@", [error localizedDescription]); | |
10841 else | |
10842 pid = [app processIdentifier]; | |
10843 dw_dialog_dismiss(dialog, DW_INT_TO_POINTER(pid)); | |
10844 }]; | |
10845 ret = DW_POINTER_TO_INT(dw_dialog_wait(dialog)); | |
10846 } | |
10847 } | |
10848 #endif | |
10849 return ret; | |
10850 } | 10812 } |
10851 | 10813 |
10852 /* | 10814 /* |
10853 * Loads a web browser pointed at the given URL. | 10815 * Loads a web browser pointed at the given URL. |
10854 * Parameters: | 10816 * Parameters: |