changeset 937:83aceaaef6ed

Added initial support for allowing dW_window_destroy() to remove an item from its containing box on Mac. Getting some crashes when using this in connection with dw_notebook_page_destroy() in HandyFTP... but I need to switch computers so committing it as is.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 27 Apr 2011 07:23:12 +0000
parents 4be0c9f963f8
children cfcf66a90e8c
files mac/dw.m
diffstat 1 files changed, 61 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Tue Apr 26 13:44:45 2011 +0000
+++ b/mac/dw.m	Wed Apr 27 07:23:12 2011 +0000
@@ -6551,7 +6551,7 @@
     DWNotebook *notebook = handle;
     NSInteger page = [notebook pageid];
     DWNotebookPage *notepage = [[DWNotebookPage alloc] initWithIdentifier:nil];
-    [notepage setPageid:(NSInteger)page];
+    [notepage setPageid:(int)page];
     if(front)
     {
         [notebook insertTabViewItem:notepage atIndex:(NSInteger)0];
@@ -6560,7 +6560,7 @@
     {
         [notebook addTabViewItem:notepage];
     }
-    [notebook setPageid:(page+1)];
+    [notebook setPageid:(int)(page+1)];
     [notepage release];
     return (unsigned long)page;
 }
@@ -6578,6 +6578,17 @@
 
     if(notepage != nil)
     {
+        DWBox *page = [notepage view];
+        Box *thisbox = [page box];
+        if(thisbox)
+        {
+            id object = thisbox->items[0].hwnd;
+            [object removeFromSuperview];
+            [object retain];
+            free(thisbox->items);
+            thisbox->count = 0;
+            thisbox->items = NULL;
+        }
         [notebook removeTabViewItem:notepage];
         [notepage release];
     }
@@ -7147,13 +7158,59 @@
 {
     int _locked_by_me = FALSE;
     DW_MUTEX_LOCK;
-    NSObject *object = handle;
-
+    id object = handle;
+
+    /* Handle destroying a top-levle window */
     if([ object isKindOfClass:[ NSWindow class ] ])
     {
         NSWindow *window = handle;
         [window close];
     }
+    /* Handle destroying a control or box */
+    else if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[NSControl class]])
+    {
+        DWBox *parent = (DWBox *)[object superview];
+        
+        if([parent isKindOfClass:[DWBox class]])
+        {
+            Box *thisbox = [parent box];
+            int z, index = -1;
+            Item *tmpitem, *thisitem = thisbox->items;
+            
+            [object removeFromSuperview];
+            /* Do we need to release?
+             * [object release];
+             */
+            
+            for(z=0;z<thisbox->count;z++)
+            {
+                if(thisitem[z].hwnd == handle)
+                    index = z;
+            }
+            
+            if(index == -1)
+            {
+                DW_MUTEX_UNLOCK;
+                return 0;
+            }
+            
+            tmpitem = malloc(sizeof(Item)*(thisbox->count-1));
+            
+            /* Copy all but the current entry to the new list */
+            for(z=0;z<index;z++)
+            {
+                tmpitem[z] = thisitem[z];
+            }
+            for(z=index+1;z<thisbox->count;z++)
+            {
+                tmpitem[z-1] = thisitem[z];
+            }
+            
+            thisbox->items = tmpitem;
+            free(thisitem);
+            thisbox->count--;   
+        }
+    }
     DW_MUTEX_UNLOCK;
     return 0;
 }