comparison mac/dw.m @ 1437:a50e8b486a1a

Initial layout engine 2.0 for the Mac... Windows and OS/2 may not compile until the the next commit later tonight or tomorrow.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 08 Dec 2011 06:47:05 +0000
parents 3c5287b8eebb
children bde7ebced556
comparison
equal deleted inserted replaced
1436:18c1b999dd65 1437:a50e8b486a1a
653 self = [super init]; 653 self = [super init];
654 654
655 if (self) 655 if (self)
656 { 656 {
657 box = calloc(1, sizeof(Box)); 657 box = calloc(1, sizeof(Box));
658 box->vsize = box->hsize = SIZEEXPAND;
659 box->width = box->height = 1;
658 } 660 }
659 return self; 661 return self;
660 } 662 }
661 -(void)dealloc 663 -(void)dealloc
662 { 664 {
2406 } 2408 }
2407 2409
2408 /* This function calculates how much space the widgets and boxes require 2410 /* This function calculates how much space the widgets and boxes require
2409 * and does expansion as necessary. 2411 * and does expansion as necessary.
2410 */ 2412 */
2411 static int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy, 2413 static void _resize_box(Box *thisbox, int *depth, int x, int y, int pass)
2412 int pass, int *usedpadx, int *usedpady) 2414 {
2413 { 2415 /* Current item position */
2414 int z, currentx = 0, currenty = 0; 2416 int z, currentx = thisbox->pad, currenty = thisbox->pad;
2417 /* Used x, y and padding maximum values...
2418 * These will be used to find the widest or
2419 * tallest items in a box.
2420 */
2415 int uymax = 0, uxmax = 0; 2421 int uymax = 0, uxmax = 0;
2416 int upymax = 0, upxmax = 0; 2422 int upymax = 0, upxmax = 0;
2417 /* Used for the SIZEEXPAND */ 2423
2418 int nux = *usedx, nuy = *usedy; 2424 /* Reset the box sizes */
2419 int nupx = *usedpadx, nupy = *usedpady; 2425 thisbox->minwidth = thisbox->minheight = thisbox->usedpadx = thisbox->usedpady = thisbox->pad * 2;
2420 int thispadx = thisbox->pad * 2;
2421 int thispady = thisbox->pad * 2;
2422 2426
2423 /* Handle special groupbox case */ 2427 /* Handle special groupbox case */
2424 if(thisbox->grouphwnd) 2428 if(thisbox->grouphwnd)
2425 { 2429 {
2426 DWGroupBox *groupbox = thisbox->grouphwnd; 2430 /* Only calculate the size on the first pass...
2427 NSSize borderSize = [groupbox borderSize]; 2431 * used the cached values on second.
2428 NSRect titleRect; 2432 */
2429 2433 if(pass == 1)
2430 if(borderSize.width == 0 || borderSize.height == 0) 2434 {
2431 { 2435 DWGroupBox *groupbox = thisbox->grouphwnd;
2432 borderSize = [groupbox initBorder]; 2436 NSSize borderSize = [groupbox borderSize];
2433 } 2437 NSRect titleRect;
2434 /* Get the title size for a more accurate groupbox padding size */ 2438
2435 titleRect = [groupbox titleRect]; 2439 if(borderSize.width == 0 || borderSize.height == 0)
2436 2440 {
2437 thisbox->grouppadx = borderSize.width; 2441 borderSize = [groupbox initBorder];
2438 thisbox->grouppady = borderSize.height + titleRect.size.height; 2442 }
2439 2443 /* Get the title size for a more accurate groupbox padding size */
2440 (*usedx) += thisbox->grouppadx; 2444 titleRect = [groupbox titleRect];
2441 (*usedpadx) += thisbox->grouppadx; 2445
2442 (*usedy) += thisbox->grouppady; 2446 thisbox->grouppadx = borderSize.width;
2443 (*usedpady) += thisbox->grouppady; 2447 thisbox->grouppady = borderSize.height + titleRect.size.height;
2444 } 2448 }
2445 2449
2446 (*usedx) += thispadx; 2450 thisbox->minwidth += thisbox->grouppadx;
2447 (*usedy) += thispady; 2451 thisbox->usedpadx += thisbox->grouppadx;
2448 2452 thisbox->minheight += thisbox->grouppady;
2453 thisbox->usedpady += thisbox->grouppady;
2454 }
2455
2456 /* Count up all the space for all items in the box */
2449 for(z=0;z<thisbox->count;z++) 2457 for(z=0;z<thisbox->count;z++)
2450 { 2458 {
2459 int itempad, itemwidth, itemheight;
2460
2451 if(thisbox->items[z].type == TYPEBOX) 2461 if(thisbox->items[z].type == TYPEBOX)
2452 { 2462 {
2453 int initialx, initialy;
2454 id box = thisbox->items[z].hwnd; 2463 id box = thisbox->items[z].hwnd;
2455 Box *tmp = [box box]; 2464 Box *tmp = [box box];
2456 2465
2457 initialx = x - (*usedx);
2458 initialy = y - (*usedy);
2459
2460 if(tmp) 2466 if(tmp)
2461 { 2467 {
2462 int newx, newy; 2468 /* On the first pass calculate the box contents */
2463 int nux = *usedx, nuy = *usedy; 2469 if(pass == 1)
2464 int tmppadx = tmp->pad*2;
2465 int tmppady = tmp->pad*2;
2466 int upx, upy;
2467
2468 upx = *usedpadx + tmppadx;
2469 upy = *usedpady + tmppady;
2470
2471 /* On the second pass we know how big the box needs to be and how
2472 * much space we have, so we can calculate a ratio for the new box.
2473 */
2474 if(pass > 1)
2475 { 2470 {
2476 int deep = *depth + 1; 2471 (*depth)++;
2477 int tux = nux, tuy = nuy, tupx = upx, tupy = upy; 2472
2478 2473 /* Save the newly calculated values on the box */
2479 _resize_box(tmp, &deep, x, y, &tux, &tuy, 1, &tupx, &tupy); 2474 _resize_box(tmp, depth, x, y, pass);
2480 2475
2481 tmp->upx = tupx - *usedpadx; 2476 /* Duplicate the values in the item list for use below */
2482 tmp->upy = tupy - *usedpady; 2477 thisbox->items[z].width = tmp->minwidth;
2483 2478 thisbox->items[z].height = tmp->minheight;
2484 newx = x - tux; 2479
2485 newy = y - tuy; 2480 (*depth)--;
2486
2487 tmp->width = thisbox->items[z].width = initialx - newx;
2488 tmp->height = thisbox->items[z].height = initialy - newy;
2489
2490 tmp->parentxratio = thisbox->xratio;
2491 tmp->parentyratio = thisbox->yratio;
2492
2493 tmp->parentpad = tmp->pad;
2494 tmp->hsize = thisbox->items[z].hsize;
2495 tmp->vsize = thisbox->items[z].vsize;
2496
2497 /* Just in case */
2498 tmp->xratio = thisbox->xratio;
2499 tmp->yratio = thisbox->yratio;
2500
2501 if(thisbox->type == DW_VERT)
2502 {
2503 int tmppad = (thisbox->items[z].pad*2)+(tmp->pad*2)+tmp->grouppady;
2504
2505 if((thisbox->items[z].width - tmppad)!=0)
2506 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmppad))/((float)(thisbox->items[z].width-tmppad));
2507 }
2508 else
2509 {
2510 if((thisbox->items[z].width-tmp->upx)!=0)
2511 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-tmp->upx))/((float)(thisbox->items[z].width-tmp->upx));
2512 }
2513 if(thisbox->type == DW_HORZ)
2514 {
2515 int tmppad = (thisbox->items[z].pad*2)+(tmp->pad*2)+tmp->grouppadx;
2516
2517 if((thisbox->items[z].height-tmppad)!=0)
2518 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmppad))/((float)(thisbox->items[z].height-tmppad));
2519 }
2520 else
2521 {
2522 if((thisbox->items[z].height-tmp->upy)!=0)
2523 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(thisbox->items[z].height-tmp->upy));
2524 }
2525 } 2481 }
2526
2527 (*depth)++;
2528
2529 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy);
2530
2531 (*depth)--;
2532
2533 newx = x - nux;
2534 newy = y - nuy;
2535
2536 tmp->minwidth = thisbox->items[z].width = initialx - newx;
2537 tmp->minheight = thisbox->items[z].height = initialy - newy;
2538 } 2482 }
2539 } 2483 }
2540 2484
2541 if(pass > 1 && *depth > 0) 2485 /* Precalculate these values, since they will
2542 { 2486 * be used used repeatedly in the next section.
2543 if(thisbox->type == DW_VERT) 2487 */
2488 itempad = thisbox->items[z].pad * 2;
2489 itemwidth = thisbox->items[z].width + itempad;
2490 itemheight = thisbox->items[z].height + itempad;
2491
2492 /* Calculate the totals and maximums */
2493 if(thisbox->type == DW_VERT)
2494 {
2495 if(itemwidth > uxmax)
2496 uxmax = itemwidth;
2497
2498 if(thisbox->items[z].hsize != SIZEEXPAND)
2544 { 2499 {
2545 int tmppad = (thisbox->items[z].pad*2)+(thisbox->parentpad*2)+thisbox->grouppadx; 2500 if(itemwidth > upxmax)
2546 2501 upxmax = itemwidth;
2547 if((thisbox->minwidth-tmppad) == 0)
2548 thisbox->items[z].xratio = 1.0;
2549 else
2550 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-tmppad))/((float)(thisbox->minwidth-tmppad));
2551 } 2502 }
2552 else 2503 else
2553 { 2504 {
2554 if(thisbox->minwidth-thisbox->upx == 0) 2505 if(itempad > upxmax)
2555 thisbox->items[z].xratio = 1.0; 2506 upxmax = itempad;
2556 else
2557 thisbox->items[z].xratio = ((float)((thisbox->width * thisbox->parentxratio)-thisbox->upx))/((float)(thisbox->minwidth-thisbox->upx));
2558 } 2507 }
2559 2508 thisbox->minheight += itemheight;
2560 if(thisbox->type == DW_HORZ) 2509 if(thisbox->items[z].vsize != SIZEEXPAND)
2510 thisbox->usedpady += itemheight;
2511 else
2512 thisbox->usedpady += itempad;
2513 }
2514 else
2515 {
2516 if(itemheight > uymax)
2517 uymax = itemheight;
2518 if(thisbox->items[z].vsize != SIZEEXPAND)
2561 { 2519 {
2562 int tmppad = (thisbox->items[z].pad*2)+(thisbox->parentpad*2)+thisbox->grouppady; 2520 if(itemheight > upymax)
2563 2521 upymax = itemheight;
2564 if((thisbox->minheight-tmppad) == 0)
2565 thisbox->items[z].yratio = 1.0;
2566 else
2567 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-tmppad))/((float)(thisbox->minheight-tmppad));
2568 } 2522 }
2569 else 2523 else
2570 { 2524 {
2571 if(thisbox->minheight-thisbox->upy == 0) 2525 if(itempad > upymax)
2572 thisbox->items[z].yratio = 1.0; 2526 upymax = itempad;
2573 else
2574 thisbox->items[z].yratio = ((float)((thisbox->height * thisbox->parentyratio)-thisbox->upy))/((float)(thisbox->minheight-thisbox->upy));
2575 } 2527 }
2576 2528 thisbox->minwidth += itemwidth;
2577 if(thisbox->items[z].type == TYPEBOX)
2578 {
2579 id box = thisbox->items[z].hwnd;
2580 Box *tmp = [box box];
2581
2582 if(tmp)
2583 {
2584 tmp->parentxratio = thisbox->items[z].xratio;
2585 tmp->parentyratio = thisbox->items[z].yratio;
2586 }
2587 }
2588 }
2589 else
2590 {
2591 thisbox->items[z].xratio = thisbox->xratio;
2592 thisbox->items[z].yratio = thisbox->yratio;
2593 }
2594
2595 if(thisbox->type == DW_VERT)
2596 {
2597 if((thisbox->items[z].width + (thisbox->items[z].pad*2)) > uxmax)
2598 uxmax = (thisbox->items[z].width + (thisbox->items[z].pad*2));
2599 if(thisbox->items[z].hsize != SIZEEXPAND) 2529 if(thisbox->items[z].hsize != SIZEEXPAND)
2600 { 2530 thisbox->usedpadx += itemwidth;
2601 if(((thisbox->items[z].pad*2) + thisbox->items[z].width) > upxmax)
2602 upxmax = (thisbox->items[z].pad*2) + thisbox->items[z].width;
2603 }
2604 else 2531 else
2605 { 2532 thisbox->usedpadx += itempad;
2606 if(thisbox->items[z].pad*2 > upxmax) 2533 }
2607 upxmax = thisbox->items[z].pad*2; 2534 }
2608 } 2535
2609 } 2536 /* Add the maximums which were calculated in the previous loop */
2610 else 2537 thisbox->minwidth += uxmax;
2611 { 2538 thisbox->minheight += uymax;
2612 (*usedx) += thisbox->items[z].width + (thisbox->items[z].pad*2); 2539 thisbox->usedpadx += upxmax;
2613 if(thisbox->items[z].hsize != SIZEEXPAND) 2540 thisbox->usedpady += upymax;
2614 (*usedpadx) += (thisbox->items[z].pad*2) + thisbox->items[z].width; 2541
2615 else 2542 /* The second pass is for actual placement. */
2616 (*usedpadx) += thisbox->items[z].pad*2;
2617 }
2618 if(thisbox->type == DW_HORZ)
2619 {
2620 if((thisbox->items[z].height + (thisbox->items[z].pad*2)) > uymax)
2621 uymax = (thisbox->items[z].height + (thisbox->items[z].pad*2));
2622 if(thisbox->items[z].vsize != SIZEEXPAND)
2623 {
2624 if(((thisbox->items[z].pad*2) + thisbox->items[z].height) > upymax)
2625 upymax = (thisbox->items[z].pad*2) + thisbox->items[z].height;
2626 }
2627 else
2628 {
2629 if(thisbox->items[z].pad*2 > upymax)
2630 upymax = thisbox->items[z].pad*2;
2631 }
2632 }
2633 else
2634 {
2635 (*usedy) += thisbox->items[z].height + (thisbox->items[z].pad*2);
2636 if(thisbox->items[z].vsize != SIZEEXPAND)
2637 (*usedpady) += (thisbox->items[z].pad*2) + thisbox->items[z].height;
2638 else
2639 (*usedpady) += thisbox->items[z].pad*2;
2640 }
2641 }
2642
2643 (*usedx) += uxmax;
2644 (*usedy) += uymax;
2645 (*usedpadx) += upxmax;
2646 (*usedpady) += upymax;
2647
2648 currentx += thisbox->pad;
2649 currenty += thisbox->pad;
2650
2651 /* The second pass is for expansion. */
2652 if(pass > 1) 2543 if(pass > 1)
2653 {
2654 /* Any SIZEEXPAND items should be set to uxmax/uymax */
2655 for(z=0;z<thisbox->count;z++)
2656 {
2657 if(thisbox->items[z].hsize == SIZEEXPAND && thisbox->type == DW_VERT)
2658 thisbox->items[z].width = uxmax-(thisbox->items[z].pad*2);
2659 if(thisbox->items[z].vsize == SIZEEXPAND && thisbox->type == DW_HORZ)
2660 thisbox->items[z].height = uymax-(thisbox->items[z].pad*2);
2661 /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */
2662 if(thisbox->items[z].type == TYPEBOX)
2663 {
2664 int tux = nux, tuy = nuy, tupx = nupx, tupy = nupy;
2665 id box = thisbox->items[z].hwnd;
2666 Box *tmp = [box box];
2667
2668 if(tmp)
2669 {
2670 if(*depth > 0)
2671 {
2672 float calcval;
2673
2674 if(thisbox->type == DW_VERT)
2675 {
2676 calcval = (float)(tmp->minwidth-((thisbox->items[z].pad*2)+thispadx));
2677 if(calcval == 0.0)
2678 tmp->xratio = thisbox->xratio;
2679 else
2680 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-((thisbox->items[z].pad*2)+thispadx)))/calcval;
2681 tmp->width = thisbox->items[z].width;
2682 }
2683 if(thisbox->type == DW_HORZ)
2684 {
2685 calcval = (float)(tmp->minheight-((thisbox->items[z].pad*2)+thispady));
2686 if(calcval == 0.0)
2687 tmp->yratio = thisbox->yratio;
2688 else
2689 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-((thisbox->items[z].pad*2)+thispady)))/calcval;
2690 tmp->height = thisbox->items[z].height;
2691 }
2692 }
2693
2694
2695 (*depth)++;
2696
2697 _resize_box(tmp, depth, x, y, &tux, &tuy, pass, &tupx, &tupy);
2698
2699 (*depth)--;
2700
2701 }
2702 }
2703 }
2704 }
2705
2706 /* The third pass is for actual placement. */
2707 if(pass > 2)
2708 { 2544 {
2709 for(z=0;z<(thisbox->count);z++) 2545 for(z=0;z<(thisbox->count);z++)
2710 { 2546 {
2711 int height = thisbox->items[z].height; 2547 int height = thisbox->items[z].height;
2712 int width = thisbox->items[z].width; 2548 int width = thisbox->items[z].width;
2713 int pad = thisbox->items[z].pad; 2549 int itempad = thisbox->items[z].pad * 2;
2714 NSView *handle = thisbox->items[z].hwnd; 2550 int thispad = thisbox->pad * 2;
2715 NSPoint point; 2551
2716 NSSize size; 2552 /* Calculate the new sizes */
2717 int vectorx, vectory; 2553 if(thisbox->items[z].hsize == SIZEEXPAND)
2718
2719 /* When upxmax != pad*2 then ratios are incorrect. */
2720 vectorx = (int)((width*thisbox->items[z].xratio)-width);
2721 vectory = (int)((height*thisbox->items[z].yratio)-height);
2722
2723 if(width > 0 && height > 0)
2724 { 2554 {
2725 /* This is a hack to fix rounding of the sizing */ 2555 if(thisbox->type == DW_HORZ)
2726 if(*depth == 0)
2727 { 2556 {
2728 vectorx++; 2557 int expandablex = thisbox->minwidth - thisbox->usedpadx;
2729 vectory++; 2558
2559 if(expandablex)
2560 width = (int)(((float)width / (float)expandablex) * (float)(x - thisbox->usedpadx));
2730 } 2561 }
2731 2562 else
2732 /* If this item isn't going to expand... reset the vectors to 0 */ 2563 width = x - (itempad + thispad + thisbox->grouppadx);
2733 if(thisbox->items[z].vsize != SIZEEXPAND) 2564 }
2734 vectory = 0; 2565 if(thisbox->items[z].vsize == SIZEEXPAND)
2735 if(thisbox->items[z].hsize != SIZEEXPAND) 2566 {
2736 vectorx = 0; 2567 if(thisbox->type == DW_VERT)
2737 2568 {
2569 int expandabley = thisbox->minheight - thisbox->usedpady;
2570
2571 if(expandabley)
2572 height = (int)(((float)height / (float)expandabley) * (float)(y - thisbox->usedpady));
2573 }
2574 else
2575 height = y - (itempad + thispad + thisbox->grouppady);
2576 }
2577
2578 /* If the calculated size is valid... */
2579 if(height > 0 && width > 0)
2580 {
2581 int pad = thisbox->items[z].pad;
2582 NSView *handle = thisbox->items[z].hwnd;
2583 NSPoint point;
2584 NSSize size;
2585
2738 point.x = currentx + pad; 2586 point.x = currentx + pad;
2739 point.y = currenty + pad; 2587 point.y = currenty + pad;
2740 if(thisbox->type == DW_VERT && thisbox->hsize == SIZESTATIC && thisbox->items[z].hsize == SIZEEXPAND && thisbox->width) 2588 size.width = width;
2741 size.width = thisbox->width; 2589 size.height = height;
2742 else
2743 size.width = width + vectorx;
2744 if(thisbox->type == DW_HORZ && thisbox->vsize == SIZESTATIC && thisbox->items[z].vsize == SIZEEXPAND && thisbox->height)
2745 size.height = thisbox->height;
2746 else
2747 size.height = height + vectory;
2748 [handle setFrameOrigin:point]; 2590 [handle setFrameOrigin:point];
2749 [handle setFrameSize:size]; 2591 [handle setFrameSize:size];
2750 2592
2751 /* After placing a box... place its components */ 2593 /* After placing a box... place its components */
2752 if(thisbox->items[z].type == TYPEBOX) 2594 if(thisbox->items[z].type == TYPEBOX)
2755 Box *tmp = [box box]; 2597 Box *tmp = [box box];
2756 2598
2757 if(tmp) 2599 if(tmp)
2758 { 2600 {
2759 (*depth)++; 2601 (*depth)++;
2760 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &nupx, &nupy); 2602 _resize_box(tmp, depth, width, height, pass);
2761 (*depth)--; 2603 (*depth)--;
2762 } 2604 }
2763 } 2605 }
2764 2606
2765 /* Special handling for notebook controls */ 2607 /* Special handling for notebook controls */
2780 /* Handle laying out scrollviews... if required space is less 2622 /* Handle laying out scrollviews... if required space is less
2781 * than available space, then expand. Otherwise use required space. 2623 * than available space, then expand. Otherwise use required space.
2782 */ 2624 */
2783 else if([handle isMemberOfClass:[DWScrollBox class]]) 2625 else if([handle isMemberOfClass:[DWScrollBox class]])
2784 { 2626 {
2785 int usedx = 0, usedy = 0, usedpadx = 0, usedpady = 0, depth = 0; 2627 int depth = 0;
2786 DWScrollBox *scrollbox = (DWScrollBox *)handle; 2628 DWScrollBox *scrollbox = (DWScrollBox *)handle;
2787 DWBox *contentbox = [scrollbox documentView]; 2629 DWBox *contentbox = [scrollbox documentView];
2788 Box *thisbox = [contentbox box]; 2630 Box *thisbox = [contentbox box];
2789 NSSize contentsize = [scrollbox contentSize]; 2631 NSSize contentsize = [scrollbox contentSize];
2790 2632
2791 /* Get the required space for the box */ 2633 /* Get the required space for the box */
2792 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 1, &usedpadx, &usedpady); 2634 _resize_box(thisbox, &depth, x, y, 1);
2793 2635
2794 if(contentsize.width < usedx) 2636 if(contentsize.width < thisbox->minwidth)
2795 { 2637 {
2796 contentsize.width = usedx; 2638 contentsize.width = thisbox->minwidth;
2797 } 2639 }
2798 if(contentsize.height < usedy) 2640 if(contentsize.height < thisbox->minheight)
2799 { 2641 {
2800 contentsize.height = usedy; 2642 contentsize.height = thisbox->minheight;
2801 } 2643 }
2802 [contentbox setFrameSize:contentsize]; 2644 [contentbox setFrameSize:contentsize];
2803 2645
2804 /* Layout the content of the scrollbox */ 2646 /* Layout the content of the scrollbox */
2805 _do_resize(thisbox, contentsize.width, contentsize.height); 2647 _do_resize(thisbox, contentsize.width, contentsize.height);
2831 { 2673 {
2832 [split splitViewDidResizeSubviews:nil]; 2674 [split splitViewDidResizeSubviews:nil];
2833 } 2675 }
2834 } 2676 }
2835 if(thisbox->type == DW_HORZ) 2677 if(thisbox->type == DW_HORZ)
2836 currentx += width + vectorx + (pad * 2); 2678 currentx += width + (pad * 2);
2837 if(thisbox->type == DW_VERT) 2679 if(thisbox->type == DW_VERT)
2838 currenty += height + vectory + (pad * 2); 2680 currenty += height + (pad * 2);
2839 } 2681 }
2840 } 2682 }
2841 } 2683 }
2842 return 0;
2843 } 2684 }
2844 2685
2845 static void _do_resize(Box *thisbox, int x, int y) 2686 static void _do_resize(Box *thisbox, int x, int y)
2846 { 2687 {
2847 if(x > 0 && y > 0) 2688 if(x > 0 && y > 0)
2848 { 2689 {
2849 if(thisbox) 2690 if(thisbox)
2850 { 2691 {
2851 int usedx = 0, usedy = 0, usedpadx = 0, usedpady = 0, depth = 0; 2692 int depth = 0;
2852 2693
2853 /* Calculate space requirements */ 2694 /* Calculate space requirements */
2854 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 1, &usedpadx, &usedpady); 2695 _resize_box(thisbox, &depth, x, y, 1);
2855 2696
2856 if(usedx-usedpadx == 0 || usedy-usedpady == 0)
2857 return;
2858
2859 thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx));
2860 thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady));
2861
2862 usedx = usedy = usedpadx = usedpady = depth = 0;
2863
2864 /* Calculate sub-box ratios for expansion */
2865 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady);
2866
2867 thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx));
2868 thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady));
2869
2870 usedx = usedy = usedpadx = usedpady = depth = 0;
2871
2872 /* Finally place all the boxes and controls */ 2697 /* Finally place all the boxes and controls */
2873 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 3, &usedpadx, &usedpady); 2698 _resize_box(thisbox, &depth, x, y, 2);
2874 } 2699 }
2875 } 2700 }
2876 } 2701 }
2877 2702
2878 NSMenu *_generate_main_menu() 2703 NSMenu *_generate_main_menu()