comparison ios/dw.m @ 2404:d4a044d24529

iOS: Fix crashes with full dwtest run. More thread safety. Fix missing textStorage in DWMLE init with NSTextContainer. Retain DWContainer because it might be getting deallocated between threads. Maybe unnecessary lastAddPoint/lastQueryPoint variable names... think the retain fixed it, but not sure.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 28 Mar 2021 17:15:13 +0000
parents b28852b35452
children 38c17a19e00d
comparison
equal deleted inserted replaced
2403:20f05d3a9c64 2404:d4a044d24529
1511 NSPointerArray *titles; 1511 NSPointerArray *titles;
1512 NSPointerArray *rowdatas; 1512 NSPointerArray *rowdatas;
1513 UIColor *fgcolor, *oddcolor, *evencolor; 1513 UIColor *fgcolor, *oddcolor, *evencolor;
1514 unsigned long dw_oddcolor, dw_evencolor; 1514 unsigned long dw_oddcolor, dw_evencolor;
1515 unsigned long _DW_COLOR_ROW_ODD, _DW_COLOR_ROW_EVEN; 1515 unsigned long _DW_COLOR_ROW_ODD, _DW_COLOR_ROW_EVEN;
1516 int lastAddPoint, lastQueryPoint; 1516 int iLastAddPoint, iLastQueryPoint;
1517 id scrollview; 1517 id scrollview;
1518 int filesystem; 1518 int filesystem;
1519 } 1519 }
1520 -(NSInteger)tableView:(UITableView *)aTable numberOfRowsInSection:(NSInteger)section; 1520 -(NSInteger)tableView:(UITableView *)aTable numberOfRowsInSection:(NSInteger)section;
1521 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 1521 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
1657 { 1657 {
1658 if(data) 1658 if(data)
1659 { 1659 {
1660 unsigned long start = [tvcols count] * index; 1660 unsigned long start = [tvcols count] * index;
1661 NSIndexSet *set = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(start, start + [tvcols count])]; 1661 NSIndexSet *set = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(start, start + [tvcols count])];
1662 if(index < lastAddPoint) 1662 if(index < iLastAddPoint)
1663 { 1663 {
1664 lastAddPoint++; 1664 iLastAddPoint++;
1665 } 1665 }
1666 [data insertObjects:input atIndexes:set]; 1666 [data insertObjects:input atIndexes:set];
1667 [titles insertPointer:NULL atIndex:index]; 1667 [titles insertPointer:NULL atIndex:index];
1668 [rowdatas insertPointer:NULL atIndex:index]; 1668 [rowdatas insertPointer:NULL atIndex:index];
1669 [set release]; 1669 [set release];
1673 } 1673 }
1674 -(int)addRow:(NSArray *)input 1674 -(int)addRow:(NSArray *)input
1675 { 1675 {
1676 if(data) 1676 if(data)
1677 { 1677 {
1678 lastAddPoint = (int)[titles count]; 1678 iLastAddPoint = (int)[titles count];
1679 [data addObjectsFromArray:input]; 1679 [data addObjectsFromArray:input];
1680 [titles addPointer:NULL]; 1680 [titles addPointer:NULL];
1681 [rowdatas addPointer:NULL]; 1681 [rowdatas addPointer:NULL];
1682 return (int)[titles count]; 1682 return (int)[titles count];
1683 } 1683 }
1688 if(tvcols) 1688 if(tvcols)
1689 { 1689 {
1690 int count = (int)(number * [tvcols count]); 1690 int count = (int)(number * [tvcols count]);
1691 int z; 1691 int z;
1692 1692
1693 lastAddPoint = (int)[titles count]; 1693 iLastAddPoint = (int)[titles count];
1694 1694
1695 for(z=0;z<count;z++) 1695 for(z=0;z<count;z++)
1696 { 1696 {
1697 [data addObject:[NSNull null]]; 1697 [data addObject:[NSNull null]];
1698 } 1698 }
1734 [data removeObjectAtIndex:start]; 1734 [data removeObjectAtIndex:start];
1735 } 1735 }
1736 oldtitle = [titles pointerAtIndex:row]; 1736 oldtitle = [titles pointerAtIndex:row];
1737 [titles removePointerAtIndex:row]; 1737 [titles removePointerAtIndex:row];
1738 [rowdatas removePointerAtIndex:row]; 1738 [rowdatas removePointerAtIndex:row];
1739 if(lastAddPoint > 0 && lastAddPoint > row) 1739 if(iLastAddPoint > 0 && iLastAddPoint > row)
1740 { 1740 {
1741 lastAddPoint--; 1741 iLastAddPoint--;
1742 } 1742 }
1743 if(oldtitle) 1743 if(oldtitle)
1744 free(oldtitle); 1744 free(oldtitle);
1745 } 1745 }
1746 } 1746 }
1758 -(void)setRowData:(int)row title:(void *)input { if(rowdatas && input) { [rowdatas replacePointerAtIndex:row withPointer:input]; } } 1758 -(void)setRowData:(int)row title:(void *)input { if(rowdatas && input) { [rowdatas replacePointerAtIndex:row withPointer:input]; } }
1759 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; } 1759 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; }
1760 -(void *)getRowData:(int)row { if(rowdatas && row > -1) { return [rowdatas pointerAtIndex:row]; } return NULL; } 1760 -(void *)getRowData:(int)row { if(rowdatas && row > -1) { return [rowdatas pointerAtIndex:row]; } return NULL; }
1761 -(id)getRow:(int)row and:(int)col { if(data && [data count]) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; } 1761 -(id)getRow:(int)row and:(int)col { if(data && [data count]) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; }
1762 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } 1762 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; }
1763 -(int)lastAddPoint { return lastAddPoint; } 1763 -(int)lastAddPoint { return iLastAddPoint; }
1764 -(int)lastQueryPoint { return lastQueryPoint; } 1764 -(int)lastQueryPoint { return iLastQueryPoint; }
1765 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } 1765 -(void)setLastQueryPoint:(int)input { iLastQueryPoint = input; }
1766 -(void)clear 1766 -(void)clear
1767 { 1767 {
1768 if(data) 1768 if(data)
1769 { 1769 {
1770 [data removeAllObjects]; 1770 [data removeAllObjects];
1775 [rowdatas removePointerAtIndex:0]; 1775 [rowdatas removePointerAtIndex:0];
1776 if(oldtitle) 1776 if(oldtitle)
1777 free(oldtitle); 1777 free(oldtitle);
1778 } 1778 }
1779 } 1779 }
1780 lastAddPoint = 0; 1780 iLastAddPoint = 0;
1781 } 1781 }
1782 -(void)setup 1782 -(void)setup
1783 { 1783 {
1784 titles = [[NSPointerArray pointerArrayWithOptions:NSPointerFunctionsOpaqueMemory] retain]; 1784 titles = [[NSPointerArray pointerArrayWithOptions:NSPointerFunctionsOpaqueMemory] retain];
1785 rowdatas = [[NSPointerArray pointerArrayWithOptions:NSPointerFunctionsOpaqueMemory] retain]; 1785 rowdatas = [[NSPointerArray pointerArrayWithOptions:NSPointerFunctionsOpaqueMemory] retain];
2816 * Create a new scrollable Box to be packed. 2816 * Create a new scrollable Box to be packed.
2817 * Parameters: 2817 * Parameters:
2818 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). 2818 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal).
2819 * pad: Number of pixels to pad around the box. 2819 * pad: Number of pixels to pad around the box.
2820 */ 2820 */
2821 HWND API dw_scrollbox_new( int type, int pad ) 2821 DW_FUNCTION_DEFINITION(dw_scrollbox_new, HWND, int type, int pad)
2822 DW_FUNCTION_ADD_PARAM2(type, pad)
2823 DW_FUNCTION_RETURN(dw_scrollbox_new, HWND)
2824 DW_FUNCTION_RESTORE_PARAM2(type, int, pad, int)
2822 { 2825 {
2823 DWScrollBox *scrollbox = [[DWScrollBox alloc] init]; 2826 DWScrollBox *scrollbox = [[DWScrollBox alloc] init];
2824 DWBox *box = dw_box_new(type, pad); 2827 DWBox *box = dw_box_new(type, pad);
2825 DWBox *tmpbox = dw_box_new(DW_VERT, 0); 2828 DWBox *tmpbox = dw_box_new(DW_VERT, 0);
2826 dw_box_pack_start(tmpbox, box, 1, 1, TRUE, TRUE, 0); 2829 dw_box_pack_start(tmpbox, box, 1, 1, TRUE, TRUE, 0);
2827 [scrollbox setBox:box]; 2830 [scrollbox setBox:box];
2828 [scrollbox addSubview:tmpbox]; 2831 [scrollbox addSubview:tmpbox];
2829 [tmpbox autorelease]; 2832 [tmpbox autorelease];
2830 return scrollbox; 2833 DW_FUNCTION_RETURN_THIS(scrollbox);
2831 } 2834 }
2832 2835
2833 /* 2836 /*
2834 * Returns the position of the scrollbar in the scrollbox 2837 * Returns the position of the scrollbar in the scrollbox
2835 * Parameters: 2838 * Parameters:
3845 } 3848 }
3846 3849
3847 /* Internal common function to create containers and listboxes */ 3850 /* Internal common function to create containers and listboxes */
3848 HWND _dw_cont_new(ULONG cid, int multi) 3851 HWND _dw_cont_new(ULONG cid, int multi)
3849 { 3852 {
3850 DWContainer *cont = [[DWContainer alloc] init]; 3853 DWContainer *cont = [[[DWContainer alloc] init] retain];
3851 3854
3852 [cont setAllowsMultipleSelection:(multi ? YES : NO)]; 3855 [cont setAllowsMultipleSelection:(multi ? YES : NO)];
3853 [cont setDataSource:cont]; 3856 [cont setDataSource:cont];
3854 [cont setDelegate:cont]; 3857 [cont setDelegate:cont];
3855 [cont setTag:cid]; 3858 [cont setTag:cid];
3870 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, multi, int) 3873 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, multi, int)
3871 { 3874 {
3872 DW_FUNCTION_INIT; 3875 DW_FUNCTION_INIT;
3873 DWContainer *cont = _dw_cont_new(cid, multi); 3876 DWContainer *cont = _dw_cont_new(cid, multi);
3874 [cont setup]; 3877 [cont setup];
3878 [cont addColumn:@"" andType:DW_CFA_STRING];
3875 DW_FUNCTION_RETURN_THIS(cont); 3879 DW_FUNCTION_RETURN_THIS(cont);
3876 } 3880 }
3877 3881
3878 /* 3882 /*
3879 * Appends the specified text to the listbox's (or combobox) entry list. 3883 * Appends the specified text to the listbox's (or combobox) entry list.
4246 DW_FUNCTION_DEFINITION(dw_mle_new, HWND, ULONG cid) 4250 DW_FUNCTION_DEFINITION(dw_mle_new, HWND, ULONG cid)
4247 DW_FUNCTION_ADD_PARAM1(cid) 4251 DW_FUNCTION_ADD_PARAM1(cid)
4248 DW_FUNCTION_RETURN(dw_mle_new, HWND) 4252 DW_FUNCTION_RETURN(dw_mle_new, HWND)
4249 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) 4253 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG)
4250 { 4254 {
4251 DWMLE *mle = [[DWMLE alloc] init]; 4255 CGRect frame = CGRectMake(0, 0, 100, 50);
4256 NSTextContainer *tc = [[NSTextContainer alloc] initWithSize:frame.size];
4257 DWMLE *mle = [[DWMLE alloc] initWithFrame:frame textContainer:tc];
4252 UIScrollView *scrollview = [[UIScrollView alloc] init]; 4258 UIScrollView *scrollview = [[UIScrollView alloc] init];
4253 CGSize size = [mle intrinsicContentSize]; 4259 CGSize size = [mle intrinsicContentSize];
4254 4260
4255 size.width = size.height; 4261 size.width = size.height;
4256 [mle setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; 4262 [mle setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
6769 * Causes the embedded HTML widget to take action. 6775 * Causes the embedded HTML widget to take action.
6770 * Parameters: 6776 * Parameters:
6771 * handle: Handle to the window. 6777 * handle: Handle to the window.
6772 * action: One of the DW_HTML_* constants. 6778 * action: One of the DW_HTML_* constants.
6773 */ 6779 */
6774 void API dw_html_action(HWND handle, int action) 6780 DW_FUNCTION_DEFINITION(dw_html_action, void, HWND handle, int action)
6781 DW_FUNCTION_ADD_PARAM2(handle, action)
6782 DW_FUNCTION_NO_RETURN(dw_html_action)
6783 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, action, int)
6775 { 6784 {
6776 DWWebView *html = handle; 6785 DWWebView *html = handle;
6777 switch(action) 6786 switch(action)
6778 { 6787 {
6779 case DW_HTML_GOBACK: 6788 case DW_HTML_GOBACK:
6794 [html stopLoading]; 6803 [html stopLoading];
6795 break; 6804 break;
6796 case DW_HTML_PRINT: 6805 case DW_HTML_PRINT:
6797 break; 6806 break;
6798 } 6807 }
6808 DW_FUNCTION_RETURN_NOTHING;
6799 } 6809 }
6800 6810
6801 /* 6811 /*
6802 * Render raw HTML code in the embedded HTML widget.. 6812 * Render raw HTML code in the embedded HTML widget..
6803 * Parameters: 6813 * Parameters:
6805 * string: String buffer containt HTML code to 6815 * string: String buffer containt HTML code to
6806 * be rendered. 6816 * be rendered.
6807 * Returns: 6817 * Returns:
6808 * 0 on success. 6818 * 0 on success.
6809 */ 6819 */
6810 int API dw_html_raw(HWND handle, const char *string) 6820 DW_FUNCTION_DEFINITION(dw_html_raw, int, HWND handle, const char *string)
6821 DW_FUNCTION_ADD_PARAM2(handle, string)
6822 DW_FUNCTION_RETURN(dw_html_raw, int)
6823 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, string, const char *)
6811 { 6824 {
6812 DWWebView *html = handle; 6825 DWWebView *html = handle;
6826 int retval = DW_ERROR_NONE;
6813 [html loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil]; 6827 [html loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil];
6814 return DW_ERROR_NONE; 6828 DW_FUNCTION_RETURN_THIS(retval);
6815 } 6829 }
6816 6830
6817 /* 6831 /*
6818 * Render file or web page in the embedded HTML widget.. 6832 * Render file or web page in the embedded HTML widget..
6819 * Parameters: 6833 * Parameters:
6821 * url: Universal Resource Locator of the web or 6835 * url: Universal Resource Locator of the web or
6822 * file object to be rendered. 6836 * file object to be rendered.
6823 * Returns: 6837 * Returns:
6824 * 0 on success. 6838 * 0 on success.
6825 */ 6839 */
6826 int API dw_html_url(HWND handle, const char *url) 6840 DW_FUNCTION_DEFINITION(dw_html_url, int, HWND handle, const char *url)
6841 DW_FUNCTION_ADD_PARAM2(handle, url)
6842 DW_FUNCTION_RETURN(dw_html_url, int)
6843 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, url, const char *)
6827 { 6844 {
6828 DWWebView *html = handle; 6845 DWWebView *html = handle;
6846 int retval = DW_ERROR_NONE;
6829 [html loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]]; 6847 [html loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]];
6830 return DW_ERROR_NONE; 6848 DW_FUNCTION_RETURN_THIS(retval);
6831 } 6849 }
6832 6850
6833 /* 6851 /*
6834 * Executes the javascript contained in "script" in the HTML window. 6852 * Executes the javascript contained in "script" in the HTML window.
6835 * Parameters: 6853 * Parameters:
6838 * scriptdata: Data passed to the signal handler. 6856 * scriptdata: Data passed to the signal handler.
6839 * Notes: A DW_SIGNAL_HTML_RESULT event will be raised with scriptdata. 6857 * Notes: A DW_SIGNAL_HTML_RESULT event will be raised with scriptdata.
6840 * Returns: 6858 * Returns:
6841 * DW_ERROR_NONE (0) on success. 6859 * DW_ERROR_NONE (0) on success.
6842 */ 6860 */
6843 int dw_html_javascript_run(HWND handle, const char *script, void *scriptdata) 6861 DW_FUNCTION_DEFINITION(dw_html_javascript_run, int, HWND handle, const char *script, void *scriptdata)
6862 DW_FUNCTION_ADD_PARAM3(handle, script, scriptdata)
6863 DW_FUNCTION_RETURN(dw_html_javascript_run, int)
6864 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, script, const char *, scriptdata, void *)
6844 { 6865 {
6845 DWWebView *html = handle; 6866 DWWebView *html = handle;
6867 int retval = DW_ERROR_NONE;
6846 DW_LOCAL_POOL_IN; 6868 DW_LOCAL_POOL_IN;
6847 6869
6848 [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:^(NSString *result, NSError *error) 6870 [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:^(NSString *result, NSError *error)
6849 { 6871 {
6850 void *params[2] = { result, scriptdata }; 6872 void *params[2] = { result, scriptdata };
6851 _dw_event_handler(html, (UIEvent *)params, 18); 6873 _dw_event_handler(html, (UIEvent *)params, 18);
6852 }]; 6874 }];
6853 DW_LOCAL_POOL_OUT; 6875 DW_LOCAL_POOL_OUT;
6854 return DW_ERROR_NONE; 6876 DW_FUNCTION_RETURN_THIS(retval);
6855 } 6877 }
6856 6878
6857 /* 6879 /*
6858 * Create a new HTML window (widget) to be packed. 6880 * Create a new HTML window (widget) to be packed.
6859 * Not available under OS/2, eCS 6881 * Not available under OS/2, eCS