comparison ios/dw.m @ 2680:1888d0a08365

iOS: Move the check/radio type alignment changes into setType: method. Also using setState: causes side effects, rename method setCheckState:
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 25 Oct 2021 03:41:02 +0000
parents fd223faa7690
children 0dac724f890f
comparison
equal deleted inserted replaced
2679:fd223faa7690 2680:1888d0a08365
1467 /* Subclass for a button type */ 1467 /* Subclass for a button type */
1468 @interface DWButton : UIButton 1468 @interface DWButton : UIButton
1469 { 1469 {
1470 void *userdata; 1470 void *userdata;
1471 DWBox *parent; 1471 DWBox *parent;
1472 int type, state; 1472 int type, checkstate;
1473 } 1473 }
1474 -(void *)userdata; 1474 -(void *)userdata;
1475 -(void)setUserdata:(void *)input; 1475 -(void)setUserdata:(void *)input;
1476 -(void)buttonClicked:(id)sender; 1476 -(void)buttonClicked:(id)sender;
1477 -(void)setParent:(DWBox *)input; 1477 -(void)setParent:(DWBox *)input;
1478 -(DWBox *)parent; 1478 -(DWBox *)parent;
1479 -(int)type; 1479 -(int)type;
1480 -(void)setType:(int)input; 1480 -(void)setType:(int)input;
1481 -(int)state; 1481 -(int)state;
1482 -(void)setState:(int)input; 1482 -(void)setCheckState:(int)input;
1483 @end 1483 @end
1484 1484
1485 @implementation DWButton 1485 @implementation DWButton
1486 -(void *)userdata { return userdata; } 1486 -(void *)userdata { return userdata; }
1487 -(void)setUserdata:(void *)input { userdata = input; } 1487 -(void)setUserdata:(void *)input { userdata = input; }
1488 -(void)buttonClicked:(id)sender 1488 -(void)buttonClicked:(id)sender
1489 { 1489 {
1490 /* Toggle the button */ 1490 /* Toggle the button */
1491 if(type == _DW_BUTTON_TYPE_CHECK) 1491 if(type == _DW_BUTTON_TYPE_CHECK)
1492 [self setState:(state ? FALSE : TRUE)]; 1492 [self setCheckState:(checkstate ? FALSE : TRUE)];
1493 else if(type == _DW_BUTTON_TYPE_RADIO) 1493 else if(type == _DW_BUTTON_TYPE_RADIO)
1494 [self setState:TRUE]; 1494 [self setCheckState:TRUE];
1495 1495
1496 _dw_event_handler(self, nil, _DW_EVENT_CLICKED); 1496 _dw_event_handler(self, nil, _DW_EVENT_CLICKED);
1497 1497
1498 /* If it is a radio button, uncheck all the other radio buttons in the box */ 1498 /* If it is a radio button, uncheck all the other radio buttons in the box */
1499 if(type == _DW_BUTTON_TYPE_RADIO) 1499 if(type == _DW_BUTTON_TYPE_RADIO)
1512 { 1512 {
1513 DWButton *button = object; 1513 DWButton *button = object;
1514 1514
1515 if(button != self && [button type] == _DW_BUTTON_TYPE_RADIO) 1515 if(button != self && [button type] == _DW_BUTTON_TYPE_RADIO)
1516 { 1516 {
1517 [button setState:FALSE]; 1517 [button setCheckState:FALSE];
1518 } 1518 }
1519 } 1519 }
1520 } 1520 }
1521 } 1521 }
1522 } 1522 }
1523 } 1523 }
1524 -(void)setParent:(DWBox *)input { parent = input; } 1524 -(void)setParent:(DWBox *)input { parent = input; }
1525 -(DWBox *)parent { return parent; } 1525 -(DWBox *)parent { return parent; }
1526 -(int)type { return type; } 1526 -(int)type { return type; }
1527 -(void)setType:(int)input { type = input; [self updateImage]; } 1527 -(void)setType:(int)input
1528 {
1529 type = input;
1530 if(type == _DW_BUTTON_TYPE_NORMAL)
1531 [self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
1532 else
1533 [self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
1534 [self updateImage];
1535 }
1528 -(void)updateImage 1536 -(void)updateImage
1529 { 1537 {
1530 NSString *imagename = nil; 1538 NSString *imagename = nil;
1531 1539
1532 switch(type) 1540 switch(type)
1533 { 1541 {
1534 case _DW_BUTTON_TYPE_CHECK: 1542 case _DW_BUTTON_TYPE_CHECK:
1535 { 1543 {
1536 1544
1537 if(state) 1545 if(checkstate)
1538 imagename = @"checkmark.square"; 1546 imagename = @"checkmark.square";
1539 else 1547 else
1540 imagename = @"square"; 1548 imagename = @"square";
1541 [self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
1542 } 1549 }
1543 break; 1550 break;
1544 case _DW_BUTTON_TYPE_RADIO: 1551 case _DW_BUTTON_TYPE_RADIO:
1545 { 1552 {
1546 if(state) 1553 if(checkstate)
1547 imagename = @"largecircle.fill.circle"; 1554 imagename = @"largecircle.fill.circle";
1548 else 1555 else
1549 imagename = @"circle"; 1556 imagename = @"circle";
1550 [self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
1551 } 1557 }
1552 break; 1558 break;
1553 default:
1554 [self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
1555 } 1559 }
1556 if(imagename) 1560 if(imagename)
1557 { 1561 {
1558 UIImage *image = [UIImage systemImageNamed:imagename]; 1562 UIImage *image = [UIImage systemImageNamed:imagename];
1559 CGSize size = [image size]; 1563 CGSize size = [image size];
1560 [self setImage:image forState:UIControlStateNormal]; 1564 [self setImage:image forState:UIControlStateNormal];
1561 [self setTitleEdgeInsets:UIEdgeInsetsMake(0,size.width,0,0)]; 1565 [self setTitleEdgeInsets:UIEdgeInsetsMake(0,size.width,0,0)];
1562 } 1566 }
1563 } 1567 }
1564 -(int)state { return state; } 1568 -(int)checkState { return checkstate; }
1565 -(void)setState:(int)input { state = input; [self updateImage]; } 1569 -(void)setCheckState:(int)input { checkstate = input; [self updateImage]; }
1566 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1570 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1567 @end 1571 @end
1568 1572
1569 /* Subclass for a progress type */ 1573 /* Subclass for a progress type */
1570 @interface DWPercent : UIProgressView 1574 @interface DWPercent : UIProgressView
4665 DW_FUNCTION_ADD_PARAM2(handle, value) 4669 DW_FUNCTION_ADD_PARAM2(handle, value)
4666 DW_FUNCTION_NO_RETURN(dw_checkbox_set) 4670 DW_FUNCTION_NO_RETURN(dw_checkbox_set)
4667 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, value, int) 4671 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, value, int)
4668 { 4672 {
4669 DWButton *button = handle; 4673 DWButton *button = handle;
4670 [button setState:value]; 4674 [button setCheckState:value];
4671 DW_FUNCTION_RETURN_NOTHING; 4675 DW_FUNCTION_RETURN_NOTHING;
4672 } 4676 }
4673 4677
4674 /* Internal common function to create containers and listboxes */ 4678 /* Internal common function to create containers and listboxes */
4675 HWND _dw_cont_new(ULONG cid, int multi) 4679 HWND _dw_cont_new(ULONG cid, int multi)