Mercurial > dwindows
comparison mac/dw.m @ 2740:9be24001d288
Style update. Add DW_SIZE_AUTO (-1) for passing automatic sizing to packing.
Also convert SIZEEXPAND/STATIC and TYPEBOX/ITEM to the new format based on
our new style guidelines. as _DW_SIZE_EXPAND/STATIC and _DW_TYPE_BOX/ITEM.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 19 Dec 2021 15:39:43 +0000 |
parents | cff8f6b6e302 |
children | ee1cfa7d645e |
comparison
equal
deleted
inserted
replaced
2739:02c53dd5e21d | 2740:9be24001d288 |
---|---|
989 | 989 |
990 if (self) | 990 if (self) |
991 { | 991 { |
992 box = calloc(1, sizeof(Box)); | 992 box = calloc(1, sizeof(Box)); |
993 box->type = DW_VERT; | 993 box->type = DW_VERT; |
994 box->vsize = box->hsize = SIZEEXPAND; | 994 box->vsize = box->hsize = _DW_SIZE_EXPAND; |
995 box->width = box->height = 1; | 995 box->width = box->height = 1; |
996 } | 996 } |
997 return self; | 997 return self; |
998 } | 998 } |
999 -(void)dealloc | 999 -(void)dealloc |
1673 Box *thisbox = [viewbox box]; | 1673 Box *thisbox = [viewbox box]; |
1674 int z; | 1674 int z; |
1675 | 1675 |
1676 for(z=0;z<thisbox->count;z++) | 1676 for(z=0;z<thisbox->count;z++) |
1677 { | 1677 { |
1678 if(thisbox->items[z].type != TYPEBOX) | 1678 if(thisbox->items[z].type != _DW_TYPE_BOX) |
1679 { | 1679 { |
1680 id object = thisbox->items[z].hwnd; | 1680 id object = thisbox->items[z].hwnd; |
1681 | 1681 |
1682 if([object isMemberOfClass:[DWButton class]]) | 1682 if([object isMemberOfClass:[DWButton class]]) |
1683 { | 1683 { |
3681 | 3681 |
3682 for(z=0;z<thisbox->count;z++) | 3682 for(z=0;z<thisbox->count;z++) |
3683 { | 3683 { |
3684 id handle = thisbox->items[z].hwnd; | 3684 id handle = thisbox->items[z].hwnd; |
3685 | 3685 |
3686 if(thisbox->items[z].type == TYPEBOX) | 3686 if(thisbox->items[z].type == _DW_TYPE_BOX) |
3687 { | 3687 { |
3688 Box *tmp = (Box *)[handle box]; | 3688 Box *tmp = (Box *)[handle box]; |
3689 | 3689 |
3690 if(tmp) | 3690 if(tmp) |
3691 { | 3691 { |
3800 /* Count up all the space for all items in the box */ | 3800 /* Count up all the space for all items in the box */ |
3801 for(z=0;z<thisbox->count;z++) | 3801 for(z=0;z<thisbox->count;z++) |
3802 { | 3802 { |
3803 int itempad, itemwidth, itemheight; | 3803 int itempad, itemwidth, itemheight; |
3804 | 3804 |
3805 if(thisbox->items[z].type == TYPEBOX) | 3805 if(thisbox->items[z].type == _DW_TYPE_BOX) |
3806 { | 3806 { |
3807 id box = thisbox->items[z].hwnd; | 3807 id box = thisbox->items[z].hwnd; |
3808 Box *tmp = (Box *)[box box]; | 3808 Box *tmp = (Box *)[box box]; |
3809 | 3809 |
3810 if(tmp) | 3810 if(tmp) |
3843 if(thisbox->type == DW_VERT) | 3843 if(thisbox->type == DW_VERT) |
3844 { | 3844 { |
3845 if(itemwidth > uxmax) | 3845 if(itemwidth > uxmax) |
3846 uxmax = itemwidth; | 3846 uxmax = itemwidth; |
3847 | 3847 |
3848 if(thisbox->items[z].hsize != SIZEEXPAND) | 3848 if(thisbox->items[z].hsize != _DW_SIZE_EXPAND) |
3849 { | 3849 { |
3850 if(itemwidth > upxmax) | 3850 if(itemwidth > upxmax) |
3851 upxmax = itemwidth; | 3851 upxmax = itemwidth; |
3852 } | 3852 } |
3853 else | 3853 else |
3854 { | 3854 { |
3855 if(itempad > upxmax) | 3855 if(itempad > upxmax) |
3856 upxmax = itempad; | 3856 upxmax = itempad; |
3857 } | 3857 } |
3858 thisbox->minheight += itemheight; | 3858 thisbox->minheight += itemheight; |
3859 if(thisbox->items[z].vsize != SIZEEXPAND) | 3859 if(thisbox->items[z].vsize != _DW_SIZE_EXPAND) |
3860 thisbox->usedpady += itemheight; | 3860 thisbox->usedpady += itemheight; |
3861 else | 3861 else |
3862 thisbox->usedpady += itempad; | 3862 thisbox->usedpady += itempad; |
3863 } | 3863 } |
3864 else | 3864 else |
3865 { | 3865 { |
3866 if(itemheight > uymax) | 3866 if(itemheight > uymax) |
3867 uymax = itemheight; | 3867 uymax = itemheight; |
3868 if(thisbox->items[z].vsize != SIZEEXPAND) | 3868 if(thisbox->items[z].vsize != _DW_SIZE_EXPAND) |
3869 { | 3869 { |
3870 if(itemheight > upymax) | 3870 if(itemheight > upymax) |
3871 upymax = itemheight; | 3871 upymax = itemheight; |
3872 } | 3872 } |
3873 else | 3873 else |
3874 { | 3874 { |
3875 if(itempad > upymax) | 3875 if(itempad > upymax) |
3876 upymax = itempad; | 3876 upymax = itempad; |
3877 } | 3877 } |
3878 thisbox->minwidth += itemwidth; | 3878 thisbox->minwidth += itemwidth; |
3879 if(thisbox->items[z].hsize != SIZEEXPAND) | 3879 if(thisbox->items[z].hsize != _DW_SIZE_EXPAND) |
3880 thisbox->usedpadx += itemwidth; | 3880 thisbox->usedpadx += itemwidth; |
3881 else | 3881 else |
3882 thisbox->usedpadx += itempad; | 3882 thisbox->usedpadx += itempad; |
3883 } | 3883 } |
3884 } | 3884 } |
3898 int width = thisbox->items[z].width; | 3898 int width = thisbox->items[z].width; |
3899 int itempad = thisbox->items[z].pad * 2; | 3899 int itempad = thisbox->items[z].pad * 2; |
3900 int thispad = thisbox->pad * 2; | 3900 int thispad = thisbox->pad * 2; |
3901 | 3901 |
3902 /* Calculate the new sizes */ | 3902 /* Calculate the new sizes */ |
3903 if(thisbox->items[z].hsize == SIZEEXPAND) | 3903 if(thisbox->items[z].hsize == _DW_SIZE_EXPAND) |
3904 { | 3904 { |
3905 if(thisbox->type == DW_HORZ) | 3905 if(thisbox->type == DW_HORZ) |
3906 { | 3906 { |
3907 int expandablex = thisbox->minwidth - thisbox->usedpadx; | 3907 int expandablex = thisbox->minwidth - thisbox->usedpadx; |
3908 | 3908 |
3910 width = (int)(((float)width / (float)expandablex) * (float)(x - thisbox->usedpadx)); | 3910 width = (int)(((float)width / (float)expandablex) * (float)(x - thisbox->usedpadx)); |
3911 } | 3911 } |
3912 else | 3912 else |
3913 width = x - (itempad + thispad + thisbox->grouppadx); | 3913 width = x - (itempad + thispad + thisbox->grouppadx); |
3914 } | 3914 } |
3915 if(thisbox->items[z].vsize == SIZEEXPAND) | 3915 if(thisbox->items[z].vsize == _DW_SIZE_EXPAND) |
3916 { | 3916 { |
3917 if(thisbox->type == DW_VERT) | 3917 if(thisbox->type == DW_VERT) |
3918 { | 3918 { |
3919 int expandabley = thisbox->minheight - thisbox->usedpady; | 3919 int expandabley = thisbox->minheight - thisbox->usedpady; |
3920 | 3920 |
3939 size.height = height; | 3939 size.height = height; |
3940 [handle setFrameOrigin:point]; | 3940 [handle setFrameOrigin:point]; |
3941 [handle setFrameSize:size]; | 3941 [handle setFrameSize:size]; |
3942 | 3942 |
3943 /* After placing a box... place its components */ | 3943 /* After placing a box... place its components */ |
3944 if(thisbox->items[z].type == TYPEBOX) | 3944 if(thisbox->items[z].type == _DW_TYPE_BOX) |
3945 { | 3945 { |
3946 id box = thisbox->items[z].hwnd; | 3946 id box = thisbox->items[z].hwnd; |
3947 Box *tmp = (Box *)[box box]; | 3947 Box *tmp = (Box *)[box box]; |
3948 | 3948 |
3949 if(tmp) | 3949 if(tmp) |
5130 if(hsize && !width) | 5130 if(hsize && !width) |
5131 width = 1; | 5131 width = 1; |
5132 | 5132 |
5133 /* Fill in the item data appropriately */ | 5133 /* Fill in the item data appropriately */ |
5134 if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]]) | 5134 if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]]) |
5135 tmpitem[index].type = TYPEBOX; | 5135 tmpitem[index].type = _DW_TYPE_BOX; |
5136 else | 5136 else |
5137 { | 5137 { |
5138 if ( width == 0 && hsize == FALSE ) | 5138 if(width == 0 && hsize == FALSE) |
5139 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); | 5139 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); |
5140 if ( height == 0 && vsize == FALSE ) | 5140 if(height == 0 && vsize == FALSE) |
5141 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); | 5141 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); |
5142 | 5142 |
5143 tmpitem[index].type = TYPEITEM; | 5143 tmpitem[index].type = _DW_TYPE_ITEM; |
5144 } | 5144 } |
5145 | 5145 |
5146 tmpitem[index].hwnd = item; | 5146 tmpitem[index].hwnd = item; |
5147 tmpitem[index].origwidth = tmpitem[index].width = width; | 5147 tmpitem[index].origwidth = tmpitem[index].width = width; |
5148 tmpitem[index].origheight = tmpitem[index].height = height; | 5148 tmpitem[index].origheight = tmpitem[index].height = height; |
5149 tmpitem[index].pad = pad; | 5149 tmpitem[index].pad = pad; |
5150 tmpitem[index].hsize = hsize ? SIZEEXPAND : SIZESTATIC; | 5150 tmpitem[index].hsize = hsize ? _DW_SIZE_EXPAND : _DW_SIZE_STATIC; |
5151 tmpitem[index].vsize = vsize ? SIZEEXPAND : SIZESTATIC; | 5151 tmpitem[index].vsize = vsize ? _DW_SIZE_EXPAND : _DW_SIZE_STATIC; |
5152 | 5152 |
5153 /* If either of the parameters are -1 ... calculate the size */ | 5153 /* If either of the parameters are -1 ... calculate the size */ |
5154 if(width == -1 || height == -1) | 5154 if(width == DW_SIZE_AUTO || height == DW_SIZE_AUTO) |
5155 _dw_control_size(object, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL); | 5155 _dw_control_size(object, width == DW_SIZE_AUTO ? &tmpitem[index].width : NULL, height == DW_SIZE_AUTO ? &tmpitem[index].height : NULL); |
5156 | 5156 |
5157 thisbox->items = tmpitem; | 5157 thisbox->items = tmpitem; |
5158 | 5158 |
5159 /* Update the item count */ | 5159 /* Update the item count */ |
5160 thisbox->count++; | 5160 thisbox->count++; |
10443 return DW_ERROR_UNKNOWN; | 10443 return DW_ERROR_UNKNOWN; |
10444 /* If we changed the text... */ | 10444 /* If we changed the text... */ |
10445 Item *item = _dw_box_item(handle); | 10445 Item *item = _dw_box_item(handle); |
10446 | 10446 |
10447 /* Check to see if any of the sizes need to be recalculated */ | 10447 /* Check to see if any of the sizes need to be recalculated */ |
10448 if(item && (item->origwidth == -1 || item->origheight == -1)) | 10448 if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO)) |
10449 { | 10449 { |
10450 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 10450 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL); |
10451 /* Queue a redraw on the top-level window */ | 10451 /* Queue a redraw on the top-level window */ |
10452 _dw_redraw([object window], TRUE); | 10452 _dw_redraw([object window], TRUE); |
10453 } | 10453 } |
10454 return DW_ERROR_NONE; | 10454 return DW_ERROR_NONE; |
10455 } | 10455 } |
10641 return; | 10641 return; |
10642 /* If we changed the text... */ | 10642 /* If we changed the text... */ |
10643 Item *item = _dw_box_item(handle); | 10643 Item *item = _dw_box_item(handle); |
10644 | 10644 |
10645 /* Check to see if any of the sizes need to be recalculated */ | 10645 /* Check to see if any of the sizes need to be recalculated */ |
10646 if(item && (item->origwidth == -1 || item->origheight == -1)) | 10646 if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO)) |
10647 { | 10647 { |
10648 int newwidth, newheight; | 10648 int newwidth, newheight; |
10649 | 10649 |
10650 _dw_control_size(handle, &newwidth, &newheight); | 10650 _dw_control_size(handle, &newwidth, &newheight); |
10651 | 10651 |
10652 /* Only update the item and redraw the window if it changed */ | 10652 /* Only update the item and redraw the window if it changed */ |
10653 if((item->origwidth == -1 && item->width != newwidth) || | 10653 if((item->origwidth == DW_SIZE_AUTO && item->width != newwidth) || |
10654 (item->origheight == -1 && item->height != newheight)) | 10654 (item->origheight == DW_SIZE_AUTO && item->height != newheight)) |
10655 { | 10655 { |
10656 if(item->origwidth == -1) | 10656 if(item->origwidth == DW_SIZE_AUTO) |
10657 item->width = newwidth; | 10657 item->width = newwidth; |
10658 if(item->origheight == -1) | 10658 if(item->origheight == DW_SIZE_AUTO) |
10659 item->height = newheight; | 10659 item->height = newheight; |
10660 /* Queue a redraw on the top-level window */ | 10660 /* Queue a redraw on the top-level window */ |
10661 _dw_redraw([object window], TRUE); | 10661 _dw_redraw([object window], TRUE); |
10662 } | 10662 } |
10663 } | 10663 } |
10774 } | 10774 } |
10775 /* If we changed the bitmap... */ | 10775 /* If we changed the bitmap... */ |
10776 Item *item = _dw_box_item(handle); | 10776 Item *item = _dw_box_item(handle); |
10777 | 10777 |
10778 /* Check to see if any of the sizes need to be recalculated */ | 10778 /* Check to see if any of the sizes need to be recalculated */ |
10779 if(item && (item->origwidth == -1 || item->origheight == -1)) | 10779 if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO)) |
10780 { | 10780 { |
10781 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 10781 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL); |
10782 /* Queue a redraw on the top-level window */ | 10782 /* Queue a redraw on the top-level window */ |
10783 _dw_redraw([object window], TRUE); | 10783 _dw_redraw([object window], TRUE); |
10784 } | 10784 } |
10785 DW_LOCAL_POOL_OUT; | 10785 DW_LOCAL_POOL_OUT; |
10786 } | 10786 } |
10832 | 10832 |
10833 /* If we changed the bitmap... */ | 10833 /* If we changed the bitmap... */ |
10834 Item *item = _dw_box_item(handle); | 10834 Item *item = _dw_box_item(handle); |
10835 | 10835 |
10836 /* Check to see if any of the sizes need to be recalculated */ | 10836 /* Check to see if any of the sizes need to be recalculated */ |
10837 if(item && (item->origwidth == -1 || item->origheight == -1)) | 10837 if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO)) |
10838 { | 10838 { |
10839 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 10839 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL); |
10840 /* Queue a redraw on the top-level window */ | 10840 /* Queue a redraw on the top-level window */ |
10841 _dw_redraw([object window], TRUE); | 10841 _dw_redraw([object window], TRUE); |
10842 } | 10842 } |
10843 } | 10843 } |
10844 } | 10844 } |