changeset 792:fc6a626a96cc

Initial groupbox support. Sizing of the content frame is not quite right yet.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 22 Mar 2011 21:03:35 +0000
parents 4eb337e18caf
children e328c7746cda
files mac/dw.m
diffstat 1 files changed, 42 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Tue Mar 22 05:54:01 2011 +0000
+++ b/mac/dw.m	Tue Mar 22 21:03:35 2011 +0000
@@ -456,6 +456,7 @@
 -(id)init;
 -(void)dealloc;
 -(Box *)box;
+-(id)contentView;
 -(void *)userdata;
 -(void)setUserdata:(void *)input;
 -(void)drawRect:(NSRect)rect;
@@ -489,6 +490,7 @@
     [super dealloc];
 }
 -(Box *)box { return box; }
+-(id)contentView { return self; }
 -(void *)userdata { return userdata; }
 -(void)setUserdata:(void *)input { userdata = input; }
 -(void)drawRect:(NSRect)rect
@@ -523,6 +525,23 @@
 }
 @end
 
+/* Subclass for a group box type */
+@interface DWGroupBox : NSBox 
+{
+    void *userdata;
+    NSColor *bgcolor;
+}
+-(Box *)box;
+-(void *)userdata;
+-(void)setUserdata:(void *)input;
+@end
+
+@implementation DWGroupBox
+-(Box *)box { return [[self contentView] box]; }
+-(void *)userdata { return userdata; }
+-(void)setUserdata:(void *)input { userdata = input; }
+@end
+
 /* Subclass for a top-level window */
 @interface DWView : DWBox
 {
@@ -1571,7 +1590,7 @@
       if(thisbox->items[z].type == TYPEBOX)
       {
         int initialx, initialy;
-        DWBox *box = thisbox->items[z].hwnd;
+        id box = thisbox->items[z].hwnd;
         Box *tmp = [box box];
 
          initialx = x - (*usedx);
@@ -1683,7 +1702,7 @@
 
          if(thisbox->items[z].type == TYPEBOX)
          {
-            DWBox *box = thisbox->items[z].hwnd;
+            id box = thisbox->items[z].hwnd;
             Box *tmp = [box box];
 
             if(tmp)
@@ -1784,7 +1803,7 @@
          /* Run this code segment again to finalize the sized after setting uxmax/uymax values. */
          if(thisbox->items[z].type == TYPEBOX)
          {
-            DWBox *box = thisbox->items[z].hwnd;
+            id box = thisbox->items[z].hwnd;
             Box *tmp = [box box];
 
             if(tmp)
@@ -1864,7 +1883,7 @@
             {
                 DWNotebook *notebook = (DWNotebook *)handle;
                 DWNotebookPage *notepage = (DWNotebookPage *)[notebook selectedTabViewItem];
-                DWBox *view = [notepage view];
+                id view = [notepage view];
 
                 if(view != nil)
                 {
@@ -1884,6 +1903,11 @@
                 [stepper setFrameOrigin:NSMakePoint(size.width-20,0)];
                 [stepper setFrameSize:NSMakeSize(20,size.height)];
             }
+            else if([handle isMemberOfClass:[DWGroupBox class]])
+            {
+                DWGroupBox *groupbox = thisbox->items[z].hwnd;
+                [groupbox sizeToFit];
+            }
             else if([handle isMemberOfClass:[DWRender class]])
             {
                 _event_handler(handle, nil, 1);
@@ -2383,9 +2407,12 @@
  */
 HWND API dw_groupbox_new(int type, int pad, char *title)
 {
+    NSBox *groupbox = [[DWGroupBox alloc] init];
     DWBox *box = dw_box_new(type, pad);
-    [box setFocusRingType:NSFocusRingTypeExterior];
-    return box;
+    [groupbox setBorderType:NSBezelBorder];
+    [groupbox setTitle:[NSString stringWithUTF8String:title]];
+    [groupbox setContentView:box];
+    return groupbox;
 }
 
 #ifndef INCOMPLETE
@@ -2491,7 +2518,7 @@
        width = 1;
 
     /* Fill in the item data appropriately */
-    if([ object isKindOfClass:[ DWBox class ] ])
+    if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]])
        tmpitem[0].type = TYPEBOX;
     else
        tmpitem[0].type = TYPEITEM;
@@ -2584,7 +2611,7 @@
        width = 1;
 
     /* Fill in the item data appropriately */
-    if([ object isKindOfClass:[ DWBox class ] ])
+    if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]])
        tmpitem[thisbox->count].type = TYPEBOX;
     else
        tmpitem[thisbox->count].type = TYPEITEM;
@@ -6025,11 +6052,14 @@
     id object = handle;
     id control = next;
     
-    if([object isMemberOfClass:[NSWindow class]] && [control isMemberOfClass:[DWButton class]])
-    {
-        NSWindow *window = object;
+    if([object isMemberOfClass:[NSWindow class]])
+    {
+        if([control isMemberOfClass:[DWButton class]])
+        {
+            NSWindow *window = object;
         
-        [window setDefaultButtonCell:control];
+            [window setDefaultButtonCell:control];
+        }
     }
     else
     {