changeset 806:16964b141964

More accurate groupbox paddig calculations. Title rectangle is now calculated on the fly. Additionally the default border size of 5 is pulled from the Apple documentation to replace my guess of 4.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 24 Mar 2011 06:35:41 +0000
parents 1a0bbb2aa9dd
children f7016a38bedd
files mac/dw.m
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Thu Mar 24 02:07:12 2011 +0000
+++ b/mac/dw.m	Thu Mar 24 06:35:41 2011 +0000
@@ -1621,10 +1621,8 @@
 
 unsigned long _foreground = 0xAAAAAA, _background = 0;
 
-/* TODO: Figure out how to calculate these on the fly */
-#define _DW_GROUPBOX_BORDER_Y   12
-#define _DW_GROUPBOX_BORDER_X   8
-#define _DW_GROUPBOX_BORDER     4
+/* Default border is 5.0 according to the documentation */
+#define _DW_GROUPBOX_BORDER     5
 
 /* This function calculates how much space the widgets and boxes require
  * and does expansion as necessary.
@@ -1644,8 +1642,13 @@
     /* Handle special groupbox case */
     if(thisbox->grouphwnd)
     {
-        thisbox->grouppadx = _DW_GROUPBOX_BORDER_X;
-        thisbox->grouppady = _DW_GROUPBOX_BORDER_Y;
+        DWGroupBox *groupbox = thisbox->grouphwnd;
+        NSRect titleRect;
+        
+        /* Get the title size for a more accurate groupbox padding size */
+        titleRect = [groupbox titleRect];
+        thisbox->grouppadx = _DW_GROUPBOX_BORDER * 2;
+        thisbox->grouppady = (_DW_GROUPBOX_BORDER * 2) + titleRect.size.height;
         
         (*usedx) += thisbox->grouppadx;
         (*usedpadx) += thisbox->grouppadx;
@@ -2481,9 +2484,10 @@
     NSBox *groupbox = [[DWGroupBox alloc] init];
     DWBox *thisbox = dw_box_new(type, pad);
     Box *box = [thisbox box];
-    box->grouphwnd = groupbox;
+    
     [groupbox setBorderType:NSBezelBorder];
     [groupbox setTitle:[NSString stringWithUTF8String:title]];
+    box->grouphwnd = groupbox;
     [groupbox setContentView:thisbox];
     return groupbox;
 }