comparison mac/dw.m @ 1077:34f1d6f5f1c3

Added function dw_box_pack_at_index() on Windows, Mac and OS/2. And an example usage in dwtest. Only tested on Windows... will be testing on OS/2 and Mac shortly... then implementing the GTK versions of the function after that.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 28 Jun 2011 04:41:43 +0000
parents 3d117071a50b
children 5d3acda4acd4
comparison
equal deleted inserted replaced
1076:dbaf1b11c301 1077:34f1d6f5f1c3
3153 } 3153 }
3154 return range; 3154 return range;
3155 } 3155 }
3156 3156
3157 /* 3157 /*
3158 * Pack windows (widgets) into a box at an arbitrary location.
3159 * Parameters:
3160 * box: Window handle of the box to be packed into.
3161 * item: Window handle of the item to be back.
3162 * index: 0 based index of packed items.
3163 * width: Width in pixels of the item or -1 to be self determined.
3164 * height: Height in pixels of the item or -1 to be self determined.
3165 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
3166 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
3167 * pad: Number of pixels of padding around the item.
3168 */
3169 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad)
3170 {
3171 int _locked_by_me = FALSE;
3172 DW_MUTEX_LOCK;
3173 id object = box;
3174 DWBox *view = box;
3175 DWBox *this = item;
3176 Box *thisbox;
3177 int z, x = 0;
3178 Item *tmpitem, *thisitem;
3179
3180 /* Query the objects */
3181 if([ object isKindOfClass:[ NSWindow class ] ])
3182 {
3183 NSWindow *window = box;
3184 view = [window contentView];
3185 }
3186 else if([ object isMemberOfClass:[ DWScrollBox class ] ])
3187 {
3188 DWScrollBox *scrollbox = box;
3189 view = [scrollbox box];
3190 }
3191
3192 thisbox = [view box];
3193 thisitem = thisbox->items;
3194 object = item;
3195
3196 /* Query the objects */
3197 if([ object isKindOfClass:[ DWContainer class ] ])
3198 {
3199 DWContainer *cont = item;
3200 this = item = [cont scrollview];
3201 }
3202 else if([ object isKindOfClass:[ DWTree class ] ])
3203 {
3204 DWTree *tree = item;
3205 this = item = [tree scrollview];
3206 }
3207
3208 /* Do some sanity bounds checking */
3209 if(index < 0)
3210 index = 0;
3211 if(index > thisbox->count)
3212 index = thisbox->count;
3213
3214 /* Duplicate the existing data */
3215 tmpitem = malloc(sizeof(Item)*(thisbox->count+1));
3216
3217 for(z=0;z<thisbox->count;z++)
3218 {
3219 if(z == index)
3220 x++;
3221 tmpitem[z+1] = thisitem[z];
3222 x++;
3223 }
3224
3225 /* Sanity checks */
3226 if(vsize && !height)
3227 height = 1;
3228 if(hsize && !width)
3229 width = 1;
3230
3231 /* Fill in the item data appropriately */
3232 if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]])
3233 tmpitem[index].type = TYPEBOX;
3234 else
3235 tmpitem[index].type = TYPEITEM;
3236
3237 tmpitem[index].hwnd = item;
3238 tmpitem[index].origwidth = tmpitem[index].width = width;
3239 tmpitem[index].origheight = tmpitem[index].height = height;
3240 tmpitem[index].pad = pad;
3241 if(hsize)
3242 tmpitem[index].hsize = SIZEEXPAND;
3243 else
3244 tmpitem[index].hsize = SIZESTATIC;
3245
3246 if(vsize)
3247 tmpitem[index].vsize = SIZEEXPAND;
3248 else
3249 tmpitem[index].vsize = SIZESTATIC;
3250
3251 thisbox->items = tmpitem;
3252
3253 /* Update the item count */
3254 thisbox->count++;
3255
3256 /* Add the item to the box */
3257 [view addSubview:this];
3258 /* If we are packing a button... */
3259 if([this isMemberOfClass:[DWButton class]])
3260 {
3261 DWButton *button = (DWButton *)this;
3262
3263 /* Save the parent box so radio
3264 * buttons can use it later.
3265 */
3266 [button setParent:view];
3267 }
3268
3269 /* Free the old data */
3270 if(thisbox->count)
3271 free(thisitem);
3272 DW_MUTEX_UNLOCK;
3273 }
3274
3275 /*
3158 * Pack windows (widgets) into a box from the end (or bottom). 3276 * Pack windows (widgets) into a box from the end (or bottom).
3159 * Parameters: 3277 * Parameters:
3160 * box: Window handle of the box to be packed into. 3278 * box: Window handle of the box to be packed into.
3161 * item: Window handle of the item to be back. 3279 * item: Window handle of the item to be back.
3162 * width: Width in pixels of the item or -1 to be self determined. 3280 * width: Width in pixels of the item or -1 to be self determined.