comparison mac/dw.m @ 796:3a3fae1f31bd

Initial groupbox padding calculation fix. This may still need more work... very simple version.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 23 Mar 2011 09:16:56 +0000
parents f23cad02cfb3
children aca4e104127c
comparison
equal deleted inserted replaced
795:f23cad02cfb3 796:3a3fae1f31bd
1605 return 0L; 1605 return 0L;
1606 } 1606 }
1607 1607
1608 unsigned long _foreground = 0xAAAAAA, _background = 0; 1608 unsigned long _foreground = 0xAAAAAA, _background = 0;
1609 1609
1610 /* TODO: Figure out how to calculate these on the fly */
1611 #define _DW_GROUPBOX_BORDER_Y 12
1612 #define _DW_GROUPBOX_BORDER_X 8
1613 #define _DW_GROUPBOX_BORDER 4
1614
1610 /* This function calculates how much space the widgets and boxes require 1615 /* This function calculates how much space the widgets and boxes require
1611 * and does expansion as necessary. 1616 * and does expansion as necessary.
1612 */ 1617 */
1613 static int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy, 1618 static int _resize_box(Box *thisbox, int *depth, int x, int y, int *usedx, int *usedy,
1614 int pass, int *usedpadx, int *usedpady) 1619 int pass, int *usedpadx, int *usedpady)
1636 1641
1637 if(tmp) 1642 if(tmp)
1638 { 1643 {
1639 int newx, newy; 1644 int newx, newy;
1640 int nux = *usedx, nuy = *usedy; 1645 int nux = *usedx, nuy = *usedy;
1641 int upx = *usedpadx + (tmp->pad*2), upy = *usedpady + (tmp->pad*2); 1646 int thispadx = tmp->pad*2;
1647 int thispady = tmp->pad*2;
1648 int upx, upy;
1649
1650 /* Handle special groupbox case */
1651 if(tmp->grouphwnd)
1652 {
1653 if(thispadx < _DW_GROUPBOX_BORDER_X)
1654 {
1655 thispadx = _DW_GROUPBOX_BORDER_X;
1656 }
1657 if(thispady < _DW_GROUPBOX_BORDER_Y)
1658 {
1659 thispady = _DW_GROUPBOX_BORDER_Y;
1660 }
1661 }
1662
1663 upx = *usedpadx + thispadx;
1664 upy = *usedpady + thispady;
1642 1665
1643 /* On the second pass we know how big the box needs to be and how 1666 /* On the second pass we know how big the box needs to be and how
1644 * much space we have, so we can calculate a ratio for the new box. 1667 * much space we have, so we can calculate a ratio for the new box.
1645 */ 1668 */
1646 if(pass == 2) 1669 if(pass == 2)
1687 if((thisbox->items[z].height-tmp->upy)!=0) 1710 if((thisbox->items[z].height-tmp->upy)!=0)
1688 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(thisbox->items[z].height-tmp->upy)); 1711 tmp->yratio = ((float)((thisbox->items[z].height * thisbox->yratio)-tmp->upy))/((float)(thisbox->items[z].height-tmp->upy));
1689 } 1712 }
1690 1713
1691 nux = *usedx; nuy = *usedy; 1714 nux = *usedx; nuy = *usedy;
1692 upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2); 1715 upx = *usedpadx + thispadx; upy = *usedpady + thispady;
1693 } 1716 }
1694 1717
1695 (*depth)++; 1718 (*depth)++;
1696 1719
1697 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy); 1720 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy);
1823 (*usedx) += uxmax; 1846 (*usedx) += uxmax;
1824 (*usedy) += uymax; 1847 (*usedy) += uymax;
1825 (*usedpadx) += upxmax; 1848 (*usedpadx) += upxmax;
1826 (*usedpady) += upymax; 1849 (*usedpady) += upymax;
1827 1850
1828 currentx += thisbox->pad; 1851 if(thisbox->grouphwnd)
1829 currenty += thisbox->pad; 1852 {
1853 if(thisbox->pad > _DW_GROUPBOX_BORDER_Y)
1854 {
1855 currentx += thisbox->pad - _DW_GROUPBOX_BORDER;
1856 }
1857 if(thisbox->pad > _DW_GROUPBOX_BORDER)
1858 {
1859 currenty += thisbox->pad - _DW_GROUPBOX_BORDER_X;
1860 }
1861 }
1862 else
1863 {
1864 currentx += thisbox->pad;
1865 currenty += thisbox->pad;
1866 }
1830 1867
1831 /* The second pass is for expansion and actual placement. */ 1868 /* The second pass is for expansion and actual placement. */
1832 if(pass > 1) 1869 if(pass > 1)
1833 { 1870 {
1834 /* Any SIZEEXPAND items should be set to uxmax/uymax */ 1871 /* Any SIZEEXPAND items should be set to uxmax/uymax */
2439 * title: Text to be displayined in the group outline. 2476 * title: Text to be displayined in the group outline.
2440 */ 2477 */
2441 HWND API dw_groupbox_new(int type, int pad, char *title) 2478 HWND API dw_groupbox_new(int type, int pad, char *title)
2442 { 2479 {
2443 NSBox *groupbox = [[DWGroupBox alloc] init]; 2480 NSBox *groupbox = [[DWGroupBox alloc] init];
2444 DWBox *box = dw_box_new(type, pad); 2481 DWBox *thisbox = dw_box_new(type, pad);
2482 Box *box = [thisbox box];
2483 box->grouphwnd = groupbox;
2445 [groupbox setBorderType:NSBezelBorder]; 2484 [groupbox setBorderType:NSBezelBorder];
2446 [groupbox setTitle:[NSString stringWithUTF8String:title]]; 2485 [groupbox setTitle:[NSString stringWithUTF8String:title]];
2447 [groupbox setContentView:box]; 2486 [groupbox setContentView:thisbox];
2448 return groupbox; 2487 return groupbox;
2449 } 2488 }
2450 2489
2451 #ifndef INCOMPLETE 2490 #ifndef INCOMPLETE
2452 /* 2491 /*
2454 * Parameters: 2493 * Parameters:
2455 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). 2494 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal).
2456 * pad: Number of pixels to pad around the box. 2495 * pad: Number of pixels to pad around the box.
2457 * This works fine under GTK+, but is incomplete on other platforms 2496 * This works fine under GTK+, but is incomplete on other platforms
2458 */ 2497 */
2459 HWND dw_scrollbox_new( int type, int pad ) 2498 HWND API dw_scrollbox_new( int type, int pad )
2460 { 2499 {
2461 DWBox *box = dw_box_new(type, pad); 2500 DWBox *box = dw_box_new(type, pad);
2462 [box setFocusRingType:NSFocusRingTypeExterior]; 2501 [box setFocusRingType:NSFocusRingTypeExterior];
2463 NSLog(@"dw_scrollbox_new() unimplemented\n"); 2502 NSLog(@"dw_scrollbox_new() unimplemented\n");
2464 return box; 2503 return box;
2468 * Returns the position of the scrollbar in the scrollbox 2507 * Returns the position of the scrollbar in the scrollbox
2469 * Parameters: 2508 * Parameters:
2470 * handle: Handle to the scrollbox to be queried. 2509 * handle: Handle to the scrollbox to be queried.
2471 * orient: The vertical or horizontal scrollbar. 2510 * orient: The vertical or horizontal scrollbar.
2472 */ 2511 */
2473 int dw_scrollbox_get_pos(HWND handle, int orient) 2512 int API dw_scrollbox_get_pos(HWND handle, int orient)
2474 { 2513 {
2475 int val = -1; 2514 int val = -1;
2476 NSLog(@"dw_scrollbox_get_pos() unimplemented\n"); 2515 NSLog(@"dw_scrollbox_get_pos() unimplemented\n");
2477 return val; 2516 return val;
2478 } 2517 }