comparison mac/dw.m @ 1086:4254c9b6d50d

Merge all 3 box packing functions into one internal function on Mac. Also added a couple of parameter checks and usage message boxes that I had previous left out of the Mac implementation.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 28 Jun 2011 18:41:23 +0000
parents 5d3acda4acd4
children 25707e9f5ad1
comparison
equal deleted inserted replaced
1085:5a951cfd67ad 1086:4254c9b6d50d
3152 range = [view bounds].size.width; 3152 range = [view bounds].size.width;
3153 } 3153 }
3154 return range; 3154 return range;
3155 } 3155 }
3156 3156
3157 /* Internal box packing function called by the other 3 functions */
3158 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname)
3159 {
3160 int _locked_by_me = FALSE;
3161 DW_MUTEX_LOCK;
3162 id object = box;
3163 DWBox *view = box;
3164 DWBox *this = item;
3165 Box *thisbox;
3166 int z, x = 0;
3167 Item *tmpitem, *thisitem;
3168
3169 /*
3170 * If you try and pack an item into itself VERY bad things can happen; like at least an
3171 * infinite loop on GTK! Lets be safe!
3172 */
3173 if(box == item)
3174 {
3175 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Danger! Danger! Will Robinson; box and item are the same!");
3176 return;
3177 }
3178
3179 /* Query the objects */
3180 if([ object isKindOfClass:[ NSWindow class ] ])
3181 {
3182 NSWindow *window = box;
3183 view = [window contentView];
3184 }
3185 else if([ object isMemberOfClass:[ DWScrollBox class ] ])
3186 {
3187 DWScrollBox *scrollbox = box;
3188 view = [scrollbox box];
3189 }
3190
3191 thisbox = [view box];
3192 thisitem = thisbox->items;
3193 object = item;
3194
3195 /* Query the objects */
3196 if([ object isKindOfClass:[ DWContainer class ] ])
3197 {
3198 DWContainer *cont = item;
3199 this = item = [cont scrollview];
3200 }
3201 else if([ object isKindOfClass:[ DWTree class ] ])
3202 {
3203 DWTree *tree = item;
3204 this = item = [tree scrollview];
3205 }
3206
3207 /* Do some sanity bounds checking */
3208 if(index < 0)
3209 index = 0;
3210 if(index > thisbox->count)
3211 index = thisbox->count;
3212
3213 /* Duplicate the existing data */
3214 tmpitem = malloc(sizeof(Item)*(thisbox->count+1));
3215
3216 for(z=0;z<thisbox->count;z++)
3217 {
3218 if(z == index)
3219 x++;
3220 tmpitem[x] = thisitem[z];
3221 x++;
3222 }
3223
3224 /* Sanity checks */
3225 if(vsize && !height)
3226 height = 1;
3227 if(hsize && !width)
3228 width = 1;
3229
3230 /* Fill in the item data appropriately */
3231 if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]])
3232 tmpitem[index].type = TYPEBOX;
3233 else
3234 {
3235 if ( width == 0 && hsize == FALSE )
3236 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
3237 if ( height == 0 && vsize == FALSE )
3238 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
3239
3240 tmpitem[index].type = TYPEITEM;
3241 }
3242
3243 tmpitem[index].hwnd = item;
3244 tmpitem[index].origwidth = tmpitem[index].width = width;
3245 tmpitem[index].origheight = tmpitem[index].height = height;
3246 tmpitem[index].pad = pad;
3247 if(hsize)
3248 tmpitem[index].hsize = SIZEEXPAND;
3249 else
3250 tmpitem[index].hsize = SIZESTATIC;
3251
3252 if(vsize)
3253 tmpitem[index].vsize = SIZEEXPAND;
3254 else
3255 tmpitem[index].vsize = SIZESTATIC;
3256
3257 thisbox->items = tmpitem;
3258
3259 /* Update the item count */
3260 thisbox->count++;
3261
3262 /* Add the item to the box */
3263 [view addSubview:this];
3264 /* If we are packing a button... */
3265 if([this isMemberOfClass:[DWButton class]])
3266 {
3267 DWButton *button = (DWButton *)this;
3268
3269 /* Save the parent box so radio
3270 * buttons can use it later.
3271 */
3272 [button setParent:view];
3273 }
3274
3275 /* Free the old data */
3276 if(thisbox->count)
3277 free(thisitem);
3278 DW_MUTEX_UNLOCK;
3279 }
3280
3157 /* 3281 /*
3158 * Pack windows (widgets) into a box at an arbitrary location. 3282 * Pack windows (widgets) into a box at an arbitrary location.
3159 * Parameters: 3283 * Parameters:
3160 * box: Window handle of the box to be packed into. 3284 * box: Window handle of the box to be packed into.
3161 * item: Window handle of the item to be back. 3285 * item: Window handle of the item to be back.
3166 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 3290 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
3167 * pad: Number of pixels of padding around the item. 3291 * pad: Number of pixels of padding around the item.
3168 */ 3292 */
3169 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad) 3293 void API dw_box_pack_at_index(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad)
3170 { 3294 {
3171 int _locked_by_me = FALSE; 3295 _dw_box_pack(box, item, index, width, height, hsize, vsize, pad, "dw_box_pack_at_index()");
3172 DW_MUTEX_LOCK; 3296 }
3173 id object = box; 3297
3174 DWBox *view = box; 3298 /*
3175 DWBox *this = item; 3299 * Pack windows (widgets) into a box from the start (or top).
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[x] = 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 /*
3276 * Pack windows (widgets) into a box from the end (or bottom).
3277 * Parameters: 3300 * Parameters:
3278 * box: Window handle of the box to be packed into. 3301 * box: Window handle of the box to be packed into.
3279 * item: Window handle of the item to be back. 3302 * item: Window handle of the item to be back.
3280 * width: Width in pixels of the item or -1 to be self determined. 3303 * width: Width in pixels of the item or -1 to be self determined.
3281 * height: Height in pixels of the item or -1 to be self determined. 3304 * height: Height in pixels of the item or -1 to be self determined.
3282 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. 3305 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
3283 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 3306 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
3284 * pad: Number of pixels of padding around the item. 3307 * pad: Number of pixels of padding around the item.
3285 */ 3308 */
3286 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) 3309 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
3287 { 3310 {
3288 int _locked_by_me = FALSE; 3311 /* 65536 is the table limit on GTK...
3289 DW_MUTEX_LOCK; 3312 * seems like a high enough value we will never hit it here either.
3290 id object = box; 3313 */
3291 DWBox *view = box; 3314 _dw_box_pack(box, item, 65536, width, height, hsize, vsize, pad, "dw_box_pack_start()");
3292 DWBox *this = item; 3315 }
3293 Box *thisbox; 3316
3294 int z; 3317 /*
3295 Item *tmpitem, *thisitem; 3318 * Pack windows (widgets) into a box from the end (or bottom).
3296
3297 /* Query the objects */
3298 if([ object isKindOfClass:[ NSWindow class ] ])
3299 {
3300 NSWindow *window = box;
3301 view = [window contentView];
3302 }
3303 else if([ object isMemberOfClass:[ DWScrollBox class ] ])
3304 {
3305 DWScrollBox *scrollbox = box;
3306 view = [scrollbox box];
3307 }
3308
3309 thisbox = [view box];
3310 thisitem = thisbox->items;
3311 object = item;
3312
3313 /* Query the objects */
3314 if([ object isKindOfClass:[ DWContainer class ] ])
3315 {
3316 DWContainer *cont = item;
3317 this = item = [cont scrollview];
3318 }
3319 else if([ object isKindOfClass:[ DWTree class ] ])
3320 {
3321 DWTree *tree = item;
3322 this = item = [tree scrollview];
3323 }
3324
3325 /* Duplicate the existing data */
3326 tmpitem = malloc(sizeof(Item)*(thisbox->count+1));
3327
3328 for(z=0;z<thisbox->count;z++)
3329 {
3330 tmpitem[z+1] = thisitem[z];
3331 }
3332
3333 /* Sanity checks */
3334 if(vsize && !height)
3335 height = 1;
3336 if(hsize && !width)
3337 width = 1;
3338
3339 /* Fill in the item data appropriately */
3340 if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]])
3341 tmpitem[0].type = TYPEBOX;
3342 else
3343 tmpitem[0].type = TYPEITEM;
3344
3345 tmpitem[0].hwnd = item;
3346 tmpitem[0].origwidth = tmpitem[0].width = width;
3347 tmpitem[0].origheight = tmpitem[0].height = height;
3348 tmpitem[0].pad = pad;
3349 if(hsize)
3350 tmpitem[0].hsize = SIZEEXPAND;
3351 else
3352 tmpitem[0].hsize = SIZESTATIC;
3353
3354 if(vsize)
3355 tmpitem[0].vsize = SIZEEXPAND;
3356 else
3357 tmpitem[0].vsize = SIZESTATIC;
3358
3359 thisbox->items = tmpitem;
3360
3361 /* Update the item count */
3362 thisbox->count++;
3363
3364 /* Add the item to the box */
3365 [view addSubview:this];
3366 /* If we are packing a button... */
3367 if([this isMemberOfClass:[DWButton class]])
3368 {
3369 DWButton *button = (DWButton *)this;
3370
3371 /* Save the parent box so radio
3372 * buttons can use it later.
3373 */
3374 [button setParent:view];
3375 }
3376
3377 /* Free the old data */
3378 if(thisbox->count)
3379 free(thisitem);
3380 DW_MUTEX_UNLOCK;
3381 }
3382
3383 /*
3384 * Pack windows (widgets) into a box from the start (or top).
3385 * Parameters: 3319 * Parameters:
3386 * box: Window handle of the box to be packed into. 3320 * box: Window handle of the box to be packed into.
3387 * item: Window handle of the item to be back. 3321 * item: Window handle of the item to be back.
3388 * width: Width in pixels of the item or -1 to be self determined. 3322 * width: Width in pixels of the item or -1 to be self determined.
3389 * height: Height in pixels of the item or -1 to be self determined. 3323 * height: Height in pixels of the item or -1 to be self determined.
3390 * hsize: TRUE if the window (widget) should expand horizontally to fill space given. 3324 * hsize: TRUE if the window (widget) should expand horizontally to fill space given.
3391 * vsize: TRUE if the window (widget) should expand vertically to fill space given. 3325 * vsize: TRUE if the window (widget) should expand vertically to fill space given.
3392 * pad: Number of pixels of padding around the item. 3326 * pad: Number of pixels of padding around the item.
3393 */ 3327 */
3394 void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) 3328 void API dw_box_pack_end(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad)
3395 { 3329 {
3396 int _locked_by_me = FALSE; 3330 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()");
3397 DW_MUTEX_LOCK;
3398 id object = box;
3399 DWBox *view = box;
3400 DWBox *this = item;
3401 Box *thisbox;
3402 int z;
3403 Item *tmpitem, *thisitem;
3404
3405 /* Query the objects */
3406 if([ object isKindOfClass:[ NSWindow class ] ])
3407 {
3408 NSWindow *window = box;
3409 view = [window contentView];
3410 }
3411 else if([ object isMemberOfClass:[ DWScrollBox class ] ])
3412 {
3413 DWScrollBox *scrollbox = box;
3414 view = [scrollbox box];
3415 }
3416
3417 thisbox = [view box];
3418 thisitem = thisbox->items;
3419 object = item;
3420
3421 /* Query the objects */
3422 if([ object isKindOfClass:[ DWContainer class ] ])
3423 {
3424 DWContainer *cont = item;
3425 this = item = [cont scrollview];
3426 }
3427 else if([ object isKindOfClass:[ DWTree class ] ])
3428 {
3429 DWTree *tree = item;
3430 this = item = [tree scrollview];
3431 }
3432
3433 /* Duplicate the existing data */
3434 tmpitem = malloc(sizeof(Item)*(thisbox->count+1));
3435
3436 for(z=0;z<thisbox->count;z++)
3437 {
3438 tmpitem[z] = thisitem[z];
3439 }
3440
3441 /* Sanity checks */
3442 if(vsize && !height)
3443 height = 1;
3444 if(hsize && !width)
3445 width = 1;
3446
3447 /* Fill in the item data appropriately */
3448 if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]])
3449 tmpitem[thisbox->count].type = TYPEBOX;
3450 else
3451 tmpitem[thisbox->count].type = TYPEITEM;
3452
3453 tmpitem[thisbox->count].hwnd = item;
3454 tmpitem[thisbox->count].origwidth = tmpitem[thisbox->count].width = width;
3455 tmpitem[thisbox->count].origheight = tmpitem[thisbox->count].height = height;
3456 tmpitem[thisbox->count].pad = pad;
3457 if(hsize)
3458 tmpitem[thisbox->count].hsize = SIZEEXPAND;
3459 else
3460 tmpitem[thisbox->count].hsize = SIZESTATIC;
3461
3462 if(vsize)
3463 tmpitem[thisbox->count].vsize = SIZEEXPAND;
3464 else
3465 tmpitem[thisbox->count].vsize = SIZESTATIC;
3466
3467 thisbox->items = tmpitem;
3468
3469 /* Update the item count */
3470 thisbox->count++;
3471
3472 /* Add the item to the box */
3473 [view addSubview:this];
3474 /* If we are packing a button... */
3475 if([this isMemberOfClass:[DWButton class]])
3476 {
3477 DWButton *button = (DWButton *)this;
3478
3479 /* Save the parent box so radio
3480 * buttons can use it later.
3481 */
3482 [button setParent:view];
3483 }
3484
3485 /* Free the old data */
3486 if(thisbox->count)
3487 free(thisitem);
3488 DW_MUTEX_UNLOCK;
3489 } 3331 }
3490 3332
3491 HWND _button_new(char *text, ULONG cid) 3333 HWND _button_new(char *text, ULONG cid)
3492 { 3334 {
3493 DWButton *button = [[DWButton alloc] init]; 3335 DWButton *button = [[DWButton alloc] init];