comparison ios/dw.m @ 2419:65ff339e9cd2

iOS: A number of fixes, notebook layout select first page if none selected. DWText is a kind of UILabel so check Kind not Member. Disable the calendar control for now, since it was hanging the UI. Cleanup some of the dwtest changes, now that no tabs are disabled. Remove some unnecessary macros since functionality is included in the thread safety macros.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 03 Apr 2021 18:44:01 +0000
parents ccfc4ee9c4a7
children 384d076ed52a
comparison
equal deleted inserted replaced
2418:50e1ddce0aeb 2419:65ff339e9cd2
1559 -(NSMutableArray<DWNotebookPage *> *)views { return views; }; 1559 -(NSMutableArray<DWNotebookPage *> *)views { return views; };
1560 -(void)pageChanged:(id)sender 1560 -(void)pageChanged:(id)sender
1561 { 1561 {
1562 NSInteger intpageid = [tabs selectedSegmentIndex]; 1562 NSInteger intpageid = [tabs selectedSegmentIndex];
1563 1563
1564 if(intpageid != NSNotFound && intpageid < [views count]) 1564 if(intpageid != -1 && intpageid < [views count])
1565 { 1565 {
1566 DWNotebookPage *page = [views objectAtIndex:intpageid]; 1566 DWNotebookPage *page = [views objectAtIndex:intpageid];
1567 1567
1568 /* Hide the previously visible page contents */ 1568 /* Hide the previously visible page contents */
1569 if(page != visible) 1569 if(page != visible)
2304 else if([handle isMemberOfClass:[DWNotebook class]]) 2304 else if([handle isMemberOfClass:[DWNotebook class]])
2305 { 2305 {
2306 DWNotebook *notebook = handle; 2306 DWNotebook *notebook = handle;
2307 NSInteger intpageid = [[notebook tabs] selectedSegmentIndex]; 2307 NSInteger intpageid = [[notebook tabs] selectedSegmentIndex];
2308 2308
2309 if(intpageid != NSNotFound && intpageid < [[notebook views] count]) 2309 if(intpageid != -1 && intpageid < [[notebook views] count])
2310 { 2310 {
2311 DWNotebookPage *page = [[notebook views] objectAtIndex:intpageid]; 2311 DWNotebookPage *page = [[notebook views] objectAtIndex:intpageid];
2312 2312
2313 if([page isKindOfClass:[DWBox class]]) 2313 if([page isKindOfClass:[DWBox class]])
2314 { 2314 {
2509 /* Special handling for notebook controls */ 2509 /* Special handling for notebook controls */
2510 if([handle isMemberOfClass:[DWNotebook class]]) 2510 if([handle isMemberOfClass:[DWNotebook class]])
2511 { 2511 {
2512 DWNotebook *notebook = handle; 2512 DWNotebook *notebook = handle;
2513 NSInteger intpageid = [[notebook tabs] selectedSegmentIndex]; 2513 NSInteger intpageid = [[notebook tabs] selectedSegmentIndex];
2514 2514
2515 if(intpageid != NSNotFound && intpageid < [[notebook views] count]) 2515 if(intpageid == -1)
2516 {
2517 if([[notebook tabs] numberOfSegments] > 0)
2518 {
2519 DWNotebookPage *notepage = [[notebook views] firstObject];
2520
2521 /* If there is no selected segment, select the first one... */
2522 [[notebook tabs] setSelectedSegmentIndex:0];
2523 intpageid = 0;
2524 [notepage setHidden:NO];
2525 }
2526 }
2527
2528 if(intpageid != -1 && intpageid < [[notebook views] count])
2516 { 2529 {
2517 DWNotebookPage *page = [[notebook views] objectAtIndex:intpageid]; 2530 DWNotebookPage *page = [[notebook views] objectAtIndex:intpageid];
2518 2531
2519 /* If the new page is a valid box, lay it out */ 2532 /* If the new page is a valid box, lay it out */
2520 if([page isKindOfClass:[DWBox class]]) 2533 if([page isKindOfClass:[DWBox class]])
3221 if(thisheight < _DW_SCROLLED_MIN_HEIGHT) 3234 if(thisheight < _DW_SCROLLED_MIN_HEIGHT)
3222 thisheight = _DW_SCROLLED_MIN_HEIGHT; 3235 thisheight = _DW_SCROLLED_MIN_HEIGHT;
3223 if(thisheight > _DW_SCROLLED_MAX_HEIGHT) 3236 if(thisheight > _DW_SCROLLED_MAX_HEIGHT)
3224 thisheight = _DW_SCROLLED_MAX_HEIGHT; 3237 thisheight = _DW_SCROLLED_MAX_HEIGHT;
3225 } 3238 }
3226 else if([ object isMemberOfClass:[UILabel class] ]) 3239 else if([ object isKindOfClass:[UILabel class] ])
3227 nsstr = [object text]; 3240 nsstr = [object text];
3228 /* Any other control type */ 3241 /* Any other control type */
3229 else if([ object isKindOfClass:[ UIControl class ] ]) 3242 else if([ object isKindOfClass:[ UIControl class ] ])
3230 nsstr = [object text]; 3243 nsstr = [object text];
3231 3244
6785 DW_FUNCTION_DEFINITION(dw_calendar_new, HWND, ULONG cid) 6798 DW_FUNCTION_DEFINITION(dw_calendar_new, HWND, ULONG cid)
6786 DW_FUNCTION_ADD_PARAM1(cid) 6799 DW_FUNCTION_ADD_PARAM1(cid)
6787 DW_FUNCTION_RETURN(dw_calendar_new, HWND) 6800 DW_FUNCTION_RETURN(dw_calendar_new, HWND)
6788 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) 6801 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG)
6789 { 6802 {
6803 DWCalendar *calendar = nil;
6804 #if 0 /* TODO: Figure out why this hangs the UI */
6790 DWCalendar *calendar = [[[DWCalendar alloc] init] retain]; 6805 DWCalendar *calendar = [[[DWCalendar alloc] init] retain];
6791 [calendar setDatePickerMode:UIDatePickerModeDate]; 6806 [calendar setDatePickerMode:UIDatePickerModeDate];
6792 [calendar setTag:cid]; 6807 [calendar setTag:cid];
6793 [calendar setDate:[NSDate date]]; 6808 [calendar setDate:[NSDate date]];
6809 #endif
6794 DW_FUNCTION_RETURN_THIS(calendar); 6810 DW_FUNCTION_RETURN_THIS(calendar);
6795 } 6811 }
6796 6812
6797 /* 6813 /*
6798 * Sets the current date of a calendar. 6814 * Sets the current date of a calendar.
6805 DW_FUNCTION_NO_RETURN(dw_calendar_set_date) 6821 DW_FUNCTION_NO_RETURN(dw_calendar_set_date)
6806 DW_FUNCTION_RESTORE_PARAM4(handle, HWND, year, unsigned int, month, unsigned int, day, unsigned int) 6822 DW_FUNCTION_RESTORE_PARAM4(handle, HWND, year, unsigned int, month, unsigned int, day, unsigned int)
6807 { 6823 {
6808 DWCalendar *calendar = handle; 6824 DWCalendar *calendar = handle;
6809 NSDate *date; 6825 NSDate *date;
6810 char buffer[101]; 6826 char buffer[101] = {0};
6811 DW_LOCAL_POOL_IN;
6812 6827
6813 snprintf(buffer, 100, "%04d-%02d-%02d", year, month, day); 6828 snprintf(buffer, 100, "%04d-%02d-%02d", year, month, day);
6814 6829
6815 NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 6830 NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
6816 dateFormatter.dateFormat = @"yyyy-MM-dd"; 6831 dateFormatter.dateFormat = @"yyyy-MM-dd";
6817 6832
6818 date = [dateFormatter dateFromString:[NSString stringWithUTF8String:buffer]]; 6833 date = [dateFormatter dateFromString:[NSString stringWithUTF8String:buffer]];
6819 [calendar setDate:date]; 6834 [calendar setDate:date];
6820 [date release]; 6835 [date release];
6821 DW_LOCAL_POOL_OUT;
6822 DW_FUNCTION_RETURN_NOTHING; 6836 DW_FUNCTION_RETURN_NOTHING;
6823 } 6837 }
6824 6838
6825 /* 6839 /*
6826 * Gets the current date of a calendar. 6840 * Gets the current date of a calendar.
6831 DW_FUNCTION_ADD_PARAM4(handle, year, month, day) 6845 DW_FUNCTION_ADD_PARAM4(handle, year, month, day)
6832 DW_FUNCTION_NO_RETURN(dw_calendar_get_date) 6846 DW_FUNCTION_NO_RETURN(dw_calendar_get_date)
6833 DW_FUNCTION_RESTORE_PARAM4(handle, HWND, year, unsigned int *, month, unsigned int *, day, unsigned int *) 6847 DW_FUNCTION_RESTORE_PARAM4(handle, HWND, year, unsigned int *, month, unsigned int *, day, unsigned int *)
6834 { 6848 {
6835 DWCalendar *calendar = handle; 6849 DWCalendar *calendar = handle;
6836 DW_LOCAL_POOL_IN;
6837 NSCalendar *mycalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; 6850 NSCalendar *mycalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
6838 NSDate *date = [calendar date]; 6851 NSDate *date = [calendar date];
6839 NSDateComponents* components = [mycalendar components:NSCalendarUnitDay|NSCalendarUnitMonth|NSCalendarUnitYear fromDate:date]; 6852 NSDateComponents* components = [mycalendar components:NSCalendarUnitDay|NSCalendarUnitMonth|NSCalendarUnitYear fromDate:date];
6840 *day = (unsigned int)[components day]; 6853 *day = (unsigned int)[components day];
6841 *month = (unsigned int)[components month]; 6854 *month = (unsigned int)[components month];
6842 *year = (unsigned int)[components year]; 6855 *year = (unsigned int)[components year];
6843 [mycalendar release]; 6856 [mycalendar release];
6844 DW_LOCAL_POOL_OUT;
6845 DW_FUNCTION_RETURN_NOTHING; 6857 DW_FUNCTION_RETURN_NOTHING;
6846 } 6858 }
6847 6859
6848 /* 6860 /*
6849 * Causes the embedded HTML widget to take action. 6861 * Causes the embedded HTML widget to take action.
7307 } 7319 }
7308 [notebook addSubview:notepage]; 7320 [notebook addSubview:notepage];
7309 [notepage autorelease]; 7321 [notepage autorelease];
7310 [notebook setPageid:(int)(page+1)]; 7322 [notebook setPageid:(int)(page+1)];
7311 7323
7312 #if 0
7313 if([views objectAtIndex:[[notebook tabs] selectedSegmentIndex]] == notepage)
7314 {
7315 /* If the page we added is the visible page.. lay it out */
7316 [notebook pageChanged:notebook];
7317 }
7318 else
7319 #endif
7320 if([views count] != 1) 7324 if([views count] != 1)
7321 { 7325 {
7322 /* Otherwise hide the page */ 7326 /* Otherwise hide the page */
7323 [notepage setHidden:YES]; 7327 [notepage setHidden:YES];
7324 } 7328 }
7371 { 7375 {
7372 DWNotebook *notebook = handle; 7376 DWNotebook *notebook = handle;
7373 NSInteger index = [[notebook tabs] selectedSegmentIndex]; 7377 NSInteger index = [[notebook tabs] selectedSegmentIndex];
7374 unsigned long retval = 0; 7378 unsigned long retval = 0;
7375 7379
7376 if(index != NSNotFound) 7380 if(index != -1)
7377 { 7381 {
7378 NSMutableArray<DWNotebookPage *> *views = [notebook views]; 7382 NSMutableArray<DWNotebookPage *> *views = [notebook views];
7379 DWNotebookPage *notepage = [views objectAtIndex:index]; 7383 DWNotebookPage *notepage = [views objectAtIndex:index];
7380 7384
7381 retval = [notepage pageid]; 7385 retval = [notepage pageid];
7400 if(notepage != nil) 7404 if(notepage != nil)
7401 { 7405 {
7402 NSMutableArray<DWNotebookPage *> *views = [notebook views]; 7406 NSMutableArray<DWNotebookPage *> *views = [notebook views];
7403 NSUInteger index = [views indexOfObject:notepage]; 7407 NSUInteger index = [views indexOfObject:notepage];
7404 7408
7405 if(index != NSNotFound) 7409 if(index != -1)
7406 { 7410 {
7407 [notebook tabs].selectedSegmentIndex = index; 7411 [[notebook tabs] setSelectedSegmentIndex:index];
7408 } 7412 }
7409 } 7413 }
7410 DW_FUNCTION_RETURN_NOTHING; 7414 DW_FUNCTION_RETURN_NOTHING;
7411 } 7415 }
7412 7416