Mercurial > dwindows
comparison ios/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 | 02c53dd5e21d |
children | ee1cfa7d645e |
comparison
equal
deleted
inserted
replaced
2739:02c53dd5e21d | 2740:9be24001d288 |
---|---|
769 | 769 |
770 if (self) | 770 if (self) |
771 { | 771 { |
772 box = calloc(1, sizeof(Box)); | 772 box = calloc(1, sizeof(Box)); |
773 box->type = DW_VERT; | 773 box->type = DW_VERT; |
774 box->vsize = box->hsize = SIZEEXPAND; | 774 box->vsize = box->hsize = _DW_SIZE_EXPAND; |
775 box->width = box->height = 1; | 775 box->width = box->height = 1; |
776 } | 776 } |
777 return self; | 777 return self; |
778 } | 778 } |
779 -(void)dealloc | 779 -(void)dealloc |
1638 Box *thisbox = [viewbox box]; | 1638 Box *thisbox = [viewbox box]; |
1639 int z; | 1639 int z; |
1640 | 1640 |
1641 for(z=0;z<thisbox->count;z++) | 1641 for(z=0;z<thisbox->count;z++) |
1642 { | 1642 { |
1643 if(thisbox->items[z].type != TYPEBOX) | 1643 if(thisbox->items[z].type != _DW_TYPE_BOX) |
1644 { | 1644 { |
1645 id object = thisbox->items[z].hwnd; | 1645 id object = thisbox->items[z].hwnd; |
1646 | 1646 |
1647 if([object isMemberOfClass:[DWButton class]]) | 1647 if([object isMemberOfClass:[DWButton class]]) |
1648 { | 1648 { |
2994 | 2994 |
2995 for(z=0;z<thisbox->count;z++) | 2995 for(z=0;z<thisbox->count;z++) |
2996 { | 2996 { |
2997 id handle = thisbox->items[z].hwnd; | 2997 id handle = thisbox->items[z].hwnd; |
2998 | 2998 |
2999 if(thisbox->items[z].type == TYPEBOX) | 2999 if(thisbox->items[z].type == _DW_TYPE_BOX) |
3000 { | 3000 { |
3001 Box *tmp = (Box *)[handle box]; | 3001 Box *tmp = (Box *)[handle box]; |
3002 | 3002 |
3003 if(tmp) | 3003 if(tmp) |
3004 { | 3004 { |
3077 /* Count up all the space for all items in the box */ | 3077 /* Count up all the space for all items in the box */ |
3078 for(z=0;z<thisbox->count;z++) | 3078 for(z=0;z<thisbox->count;z++) |
3079 { | 3079 { |
3080 int itempad, itemwidth, itemheight; | 3080 int itempad, itemwidth, itemheight; |
3081 | 3081 |
3082 if(thisbox->items[z].type == TYPEBOX) | 3082 if(thisbox->items[z].type == _DW_TYPE_BOX) |
3083 { | 3083 { |
3084 id box = thisbox->items[z].hwnd; | 3084 id box = thisbox->items[z].hwnd; |
3085 Box *tmp = (Box *)[box box]; | 3085 Box *tmp = (Box *)[box box]; |
3086 | 3086 |
3087 if(tmp) | 3087 if(tmp) |
3120 if(thisbox->type == DW_VERT) | 3120 if(thisbox->type == DW_VERT) |
3121 { | 3121 { |
3122 if(itemwidth > uxmax) | 3122 if(itemwidth > uxmax) |
3123 uxmax = itemwidth; | 3123 uxmax = itemwidth; |
3124 | 3124 |
3125 if(thisbox->items[z].hsize != SIZEEXPAND) | 3125 if(thisbox->items[z].hsize != _DW_SIZE_EXPAND) |
3126 { | 3126 { |
3127 if(itemwidth > upxmax) | 3127 if(itemwidth > upxmax) |
3128 upxmax = itemwidth; | 3128 upxmax = itemwidth; |
3129 } | 3129 } |
3130 else | 3130 else |
3131 { | 3131 { |
3132 if(itempad > upxmax) | 3132 if(itempad > upxmax) |
3133 upxmax = itempad; | 3133 upxmax = itempad; |
3134 } | 3134 } |
3135 thisbox->minheight += itemheight; | 3135 thisbox->minheight += itemheight; |
3136 if(thisbox->items[z].vsize != SIZEEXPAND) | 3136 if(thisbox->items[z].vsize != _DW_SIZE_EXPAND) |
3137 thisbox->usedpady += itemheight; | 3137 thisbox->usedpady += itemheight; |
3138 else | 3138 else |
3139 thisbox->usedpady += itempad; | 3139 thisbox->usedpady += itempad; |
3140 } | 3140 } |
3141 else | 3141 else |
3142 { | 3142 { |
3143 if(itemheight > uymax) | 3143 if(itemheight > uymax) |
3144 uymax = itemheight; | 3144 uymax = itemheight; |
3145 if(thisbox->items[z].vsize != SIZEEXPAND) | 3145 if(thisbox->items[z].vsize != _DW_SIZE_EXPAND) |
3146 { | 3146 { |
3147 if(itemheight > upymax) | 3147 if(itemheight > upymax) |
3148 upymax = itemheight; | 3148 upymax = itemheight; |
3149 } | 3149 } |
3150 else | 3150 else |
3151 { | 3151 { |
3152 if(itempad > upymax) | 3152 if(itempad > upymax) |
3153 upymax = itempad; | 3153 upymax = itempad; |
3154 } | 3154 } |
3155 thisbox->minwidth += itemwidth; | 3155 thisbox->minwidth += itemwidth; |
3156 if(thisbox->items[z].hsize != SIZEEXPAND) | 3156 if(thisbox->items[z].hsize != _DW_SIZE_EXPAND) |
3157 thisbox->usedpadx += itemwidth; | 3157 thisbox->usedpadx += itemwidth; |
3158 else | 3158 else |
3159 thisbox->usedpadx += itempad; | 3159 thisbox->usedpadx += itempad; |
3160 } | 3160 } |
3161 } | 3161 } |
3175 int width = thisbox->items[z].width; | 3175 int width = thisbox->items[z].width; |
3176 int itempad = thisbox->items[z].pad * 2; | 3176 int itempad = thisbox->items[z].pad * 2; |
3177 int thispad = thisbox->pad * 2; | 3177 int thispad = thisbox->pad * 2; |
3178 | 3178 |
3179 /* Calculate the new sizes */ | 3179 /* Calculate the new sizes */ |
3180 if(thisbox->items[z].hsize == SIZEEXPAND) | 3180 if(thisbox->items[z].hsize == _DW_SIZE_EXPAND) |
3181 { | 3181 { |
3182 if(thisbox->type == DW_HORZ) | 3182 if(thisbox->type == DW_HORZ) |
3183 { | 3183 { |
3184 int expandablex = thisbox->minwidth - thisbox->usedpadx; | 3184 int expandablex = thisbox->minwidth - thisbox->usedpadx; |
3185 | 3185 |
3187 width = (int)(((float)width / (float)expandablex) * (float)(x - thisbox->usedpadx)); | 3187 width = (int)(((float)width / (float)expandablex) * (float)(x - thisbox->usedpadx)); |
3188 } | 3188 } |
3189 else | 3189 else |
3190 width = x - (itempad + thispad + thisbox->grouppadx); | 3190 width = x - (itempad + thispad + thisbox->grouppadx); |
3191 } | 3191 } |
3192 if(thisbox->items[z].vsize == SIZEEXPAND) | 3192 if(thisbox->items[z].vsize == _DW_SIZE_EXPAND) |
3193 { | 3193 { |
3194 if(thisbox->type == DW_VERT) | 3194 if(thisbox->type == DW_VERT) |
3195 { | 3195 { |
3196 int expandabley = thisbox->minheight - thisbox->usedpady; | 3196 int expandabley = thisbox->minheight - thisbox->usedpady; |
3197 | 3197 |
3214 rect.size.width = width; | 3214 rect.size.width = width; |
3215 rect.size.height = height; | 3215 rect.size.height = height; |
3216 [handle setFrame:rect]; | 3216 [handle setFrame:rect]; |
3217 | 3217 |
3218 /* After placing a box... place its components */ | 3218 /* After placing a box... place its components */ |
3219 if(thisbox->items[z].type == TYPEBOX) | 3219 if(thisbox->items[z].type == _DW_TYPE_BOX) |
3220 { | 3220 { |
3221 id box = thisbox->items[z].hwnd; | 3221 id box = thisbox->items[z].hwnd; |
3222 Box *tmp = (Box *)[box box]; | 3222 Box *tmp = (Box *)[box box]; |
3223 | 3223 |
3224 if(tmp) | 3224 if(tmp) |
4106 if(hsize && !width) | 4106 if(hsize && !width) |
4107 width = 1; | 4107 width = 1; |
4108 | 4108 |
4109 /* Fill in the item data appropriately */ | 4109 /* Fill in the item data appropriately */ |
4110 if([object isKindOfClass:[DWBox class]]) | 4110 if([object isKindOfClass:[DWBox class]]) |
4111 tmpitem[index].type = TYPEBOX; | 4111 tmpitem[index].type = _DW_TYPE_BOX; |
4112 else | 4112 else |
4113 { | 4113 { |
4114 if(width == 0 && hsize == FALSE) | 4114 if(width == 0 && hsize == FALSE) |
4115 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); | 4115 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); |
4116 if(height == 0 && vsize == FALSE) | 4116 if(height == 0 && vsize == FALSE) |
4117 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); | 4117 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item); |
4118 | 4118 |
4119 tmpitem[index].type = TYPEITEM; | 4119 tmpitem[index].type = _DW_TYPE_ITEM; |
4120 } | 4120 } |
4121 | 4121 |
4122 tmpitem[index].hwnd = item; | 4122 tmpitem[index].hwnd = item; |
4123 tmpitem[index].origwidth = tmpitem[index].width = width; | 4123 tmpitem[index].origwidth = tmpitem[index].width = width; |
4124 tmpitem[index].origheight = tmpitem[index].height = height; | 4124 tmpitem[index].origheight = tmpitem[index].height = height; |
4125 tmpitem[index].pad = pad; | 4125 tmpitem[index].pad = pad; |
4126 tmpitem[index].hsize = hsize ? SIZEEXPAND : SIZESTATIC; | 4126 tmpitem[index].hsize = hsize ? _DW_SIZE_EXPAND : _DW_SIZE_STATIC; |
4127 tmpitem[index].vsize = vsize ? SIZEEXPAND : SIZESTATIC; | 4127 tmpitem[index].vsize = vsize ? _DW_SIZE_EXPAND : _DW_SIZE_STATIC; |
4128 | 4128 |
4129 /* If either of the parameters are -1 ... calculate the size */ | 4129 /* If either of the parameters are -1 (DW_SIZE_AUTO) ... calculate the size */ |
4130 if(width == -1 || height == -1) | 4130 if(width == DW_SIZE_AUTO || height == DW_SIZE_AUTO) |
4131 _dw_control_size(object, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL); | 4131 _dw_control_size(object, width == DW_SIZE_AUTO ? &tmpitem[index].width : NULL, height == DW_SIZE_AUTO ? &tmpitem[index].height : NULL); |
4132 | 4132 |
4133 thisbox->items = tmpitem; | 4133 thisbox->items = tmpitem; |
4134 | 4134 |
4135 /* Update the item count */ | 4135 /* Update the item count */ |
4136 thisbox->count++; | 4136 thisbox->count++; |
8678 return DW_ERROR_UNKNOWN; | 8678 return DW_ERROR_UNKNOWN; |
8679 /* If we changed the text... */ | 8679 /* If we changed the text... */ |
8680 Item *item = _dw_box_item(handle); | 8680 Item *item = _dw_box_item(handle); |
8681 | 8681 |
8682 /* Check to see if any of the sizes need to be recalculated */ | 8682 /* Check to see if any of the sizes need to be recalculated */ |
8683 if(item && (item->origwidth == -1 || item->origheight == -1)) | 8683 if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO)) |
8684 { | 8684 { |
8685 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 8685 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL); |
8686 /* Queue a redraw on the top-level window */ | 8686 /* Queue a redraw on the top-level window */ |
8687 _dw_redraw([object window], TRUE); | 8687 _dw_redraw([object window], TRUE); |
8688 } | 8688 } |
8689 return DW_ERROR_NONE; | 8689 return DW_ERROR_NONE; |
8690 } | 8690 } |
8903 } | 8903 } |
8904 #endif | 8904 #endif |
8905 /* If we changed the text... | 8905 /* If we changed the text... |
8906 * Check to see if any of the sizes need to be recalculated | 8906 * Check to see if any of the sizes need to be recalculated |
8907 */ | 8907 */ |
8908 if(item && (item->origwidth == -1 || item->origheight == -1)) | 8908 if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO)) |
8909 { | 8909 { |
8910 int newwidth, newheight; | 8910 int newwidth, newheight; |
8911 | 8911 |
8912 _dw_control_size(handle, &newwidth, &newheight); | 8912 _dw_control_size(handle, &newwidth, &newheight); |
8913 | 8913 |
8914 /* Only update the item and redraw the window if it changed */ | 8914 /* Only update the item and redraw the window if it changed */ |
8915 if((item->origwidth == -1 && item->width != newwidth) || | 8915 if((item->origwidth == DW_SIZE_AUTO && item->width != newwidth) || |
8916 (item->origheight == -1 && item->height != newheight)) | 8916 (item->origheight == DW_SIZE_AUTO && item->height != newheight)) |
8917 { | 8917 { |
8918 if(item->origwidth == -1) | 8918 if(item->origwidth == DW_SIZE_AUTO) |
8919 item->width = newwidth; | 8919 item->width = newwidth; |
8920 if(item->origheight == -1) | 8920 if(item->origheight == DW_SIZE_AUTO) |
8921 item->height = newheight; | 8921 item->height = newheight; |
8922 /* Queue a redraw on the top-level window */ | 8922 /* Queue a redraw on the top-level window */ |
8923 _dw_redraw([object window], TRUE); | 8923 _dw_redraw([object window], TRUE); |
8924 } | 8924 } |
8925 } | 8925 } |
9038 } | 9038 } |
9039 /* If we changed the bitmap... */ | 9039 /* If we changed the bitmap... */ |
9040 Item *item = _dw_box_item(handle); | 9040 Item *item = _dw_box_item(handle); |
9041 | 9041 |
9042 /* Check to see if any of the sizes need to be recalculated */ | 9042 /* Check to see if any of the sizes need to be recalculated */ |
9043 if(item && (item->origwidth == -1 || item->origheight == -1)) | 9043 if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO)) |
9044 { | 9044 { |
9045 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 9045 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL); |
9046 /* Queue a redraw on the top-level window */ | 9046 /* Queue a redraw on the top-level window */ |
9047 _dw_redraw([object window], TRUE); | 9047 _dw_redraw([object window], TRUE); |
9048 } | 9048 } |
9049 DW_LOCAL_POOL_OUT; | 9049 DW_LOCAL_POOL_OUT; |
9050 } | 9050 } |
9105 | 9105 |
9106 /* If we changed the bitmap... */ | 9106 /* If we changed the bitmap... */ |
9107 Item *item = _dw_box_item(handle); | 9107 Item *item = _dw_box_item(handle); |
9108 | 9108 |
9109 /* Check to see if any of the sizes need to be recalculated */ | 9109 /* Check to see if any of the sizes need to be recalculated */ |
9110 if(item && (item->origwidth == -1 || item->origheight == -1)) | 9110 if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO)) |
9111 { | 9111 { |
9112 _dw_control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL); | 9112 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL); |
9113 /* Queue a redraw on the top-level window */ | 9113 /* Queue a redraw on the top-level window */ |
9114 _dw_redraw([object window], TRUE); | 9114 _dw_redraw([object window], TRUE); |
9115 } | 9115 } |
9116 } | 9116 } |
9117 } | 9117 } |