changeset 1871:3f571ad9b92e

First Mac round of changes aimed at separating the data and text (title) functionality on container rows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 07 Aug 2013 18:56:28 +0000
parents 5a4d98cab9d3
children eae36372d64d
files dw.h mac/dw.m
diffstat 2 files changed, 149 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Sat Mar 23 19:52:38 2013 +0000
+++ b/dw.h	Wed Aug 07 18:56:28 2013 +0000
@@ -160,6 +160,8 @@
 #define DW_CRA_SELECTED          CRA_SELECTED
 #define DW_CRA_CURSORED          CRA_CURSORED
 
+#define DW_CR_RETDATA            (1 << 10)
+
 #define DW_LS_MULTIPLESEL        LS_MULTIPLESEL
 
 #define DW_LIT_NONE              -1
@@ -371,6 +373,8 @@
 #define DW_CRA_SELECTED          1
 #define DW_CRA_CURSORED          (1 << 1)
 
+#define DW_CR_RETDATA            (1 << 10)
+
 #define DW_LS_MULTIPLESEL        1
 
 #define DW_LIT_NONE              -1
@@ -549,6 +553,8 @@
 #define DW_CRA_SELECTED          LVNI_SELECTED
 #define DW_CRA_CURSORED          LVNI_FOCUSED
 
+#define DW_CR_RETDATA            (1 << 10)
+
 #define DW_LS_MULTIPLESEL        LBS_MULTIPLESEL
 
 #define DW_LIT_NONE              -1
@@ -812,6 +818,8 @@
 #define DW_CRA_SELECTED          1
 #define DW_CRA_CURSORED          (1 << 1)
 
+#define DW_CR_RETDATA            (1 << 10)
+
 #define DW_LS_MULTIPLESEL        1
 
 #define DW_LIT_NONE              -1
@@ -995,6 +1003,8 @@
 #define DW_CRA_SELECTED          1
 #define DW_CRA_CURSORED          (1 << 1)
 
+#define DW_CR_RETDATA            (1 << 10)
+
 #define DW_LS_MULTIPLESEL        1
 
 #define DW_LIT_NONE              -1
@@ -1625,8 +1635,8 @@
 void API dw_container_set_column_width(HWND handle, int column, int width);
 void API dw_container_set_row_title(void *pointer, int row, char *title);
 void API dw_container_change_row_title(HWND handle, int row, char *title);
-#define dw_container_set_row_data(a, b, c) dw_container_set_row_title(a, b, (char *)c)
-#define dw_container_change_row_data(a, b, c) dw_container_change_row_title(a, b, (char *)c)
+void API dw_container_set_row_data(void *pointer, int row, void *data);
+void API dw_container_change_row_data(HWND handle, int row, void *data);
 void API dw_container_insert(HWND handle, void *pointer, int rowcount);
 void API dw_container_clear(HWND handle, int redraw);
 void API dw_container_delete(HWND handle, int rowcount);
@@ -1634,7 +1644,9 @@
 char * API dw_container_query_next(HWND handle, unsigned long flags);
 void API dw_container_scroll(HWND handle, int direction, long rows);
 void API dw_container_cursor(HWND handle, char *text);
+void API dw_container_cursor_by_data(HWND handle, void *data);
 void API dw_container_delete_row(HWND handle, char *text);
+void API dw_container_delete_row_by_data(HWND handle, void *data);
 void API dw_container_optimize(HWND handle);
 void API dw_container_set_stripe(HWND handle, unsigned long oddcolor, unsigned long evencolor);
 void API dw_filesystem_set_column_title(HWND handle, char *title);
--- a/mac/dw.m	Sat Mar 23 19:52:38 2013 +0000
+++ b/mac/dw.m	Wed Aug 07 18:56:28 2013 +0000
@@ -356,9 +356,10 @@
             /* Container class selection event */
             case 9:
             {
-                int (*containerselectfunc)(HWND, char *, void *) = handler->signalfunction;
-
-                return containerselectfunc(handler->window, (char *)event, handler->data);
+                int (*containerselectfunc)(HWND, char *, void *, void *) = handler->signalfunction;
+                void **params = (void **)event;
+
+                return containerselectfunc(handler->window, params[0], handler->data, params[1]);
             }
             /* Container context menu event */
             case 10:
@@ -1764,6 +1765,7 @@
     NSMutableArray *data;
     NSMutableArray *types;
     NSPointerArray *titles;
+    NSPointerArray *rowdatas;
     NSColor *fgcolor, *oddcolor, *evencolor;
     int lastAddPoint, lastQueryPoint;
     id scrollview;
@@ -1885,6 +1887,7 @@
         }
         [data insertObjects:input atIndexes:set];
         [titles insertPointer:NULL atIndex:index];
+        [rowdatas insertPointer:NULL atIndex:index];
         [set release];
         return (int)[titles count];
     }
@@ -1897,6 +1900,7 @@
         lastAddPoint = (int)[titles count];
         [data addObjectsFromArray:input];
         [titles addPointer:NULL];
+        [rowdatas addPointer:NULL];
         return (int)[titles count];
     }
     return 0;
@@ -1917,6 +1921,7 @@
         for(z=0;z<number;z++)
         {
             [titles addPointer:NULL];
+            [rowdatas addPointer:NULL];
         }
         return (int)[titles count];
     }
@@ -1987,6 +1992,7 @@
             [data removeObjectAtIndex:start];
         }
         [titles removePointerAtIndex:row];
+        [rowdatas removePointerAtIndex:row];
         if(lastAddPoint > 0 && lastAddPoint > row)
         {
             lastAddPoint--;
@@ -1994,7 +2000,9 @@
     }
 }
 -(void)setRow:(int)row title:(void *)input { if(titles && input) { [titles replacePointerAtIndex:row withPointer:input]; } }
+-(void)setRowData:(int)row title:(void *)input { if(rowdatas && input) { [rowdatas replacePointerAtIndex:row withPointer:input]; } }
 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; }
+-(void *)getRowData:(int)row { if(rowdatas && row > -1) { return [rowdatas pointerAtIndex:row]; } return NULL; }
 -(id)getRow:(int)row and:(int)col { if(data) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; }
 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; }
 -(int)lastAddPoint { return lastAddPoint; }
@@ -2014,6 +2022,8 @@
 
     titles = iwopa([NSPointerArray class], swopa);
     [titles retain];
+    rowdatas = iwopa([NSPointerArray class], swopa);
+    [rowdatas retain];
     tvcols = [[[NSMutableArray alloc] init] retain];
     data = [[[NSMutableArray alloc] init] retain];
     types = [[[NSMutableArray alloc] init] retain];
@@ -2153,14 +2163,24 @@
 }
 -(void)doubleClicked:(id)sender
 {
+    void *params[2];
+    
+    params[0] = (void *)[self getRowTitle:(int)[self selectedRow]];
+    params[1] = (void *)[self getRowData:(int)[self selectedRow]];
+    
     /* Handler for container class */
-    _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 9);
+    _event_handler(self, (NSEvent *)params, 9);
 }
 -(void)keyUp:(NSEvent *)theEvent
 {
     if([[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
     {
-        _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 9);
+        void *params[2];
+        
+        params[0] = (void *)[self getRowTitle:(int)[self selectedRow]];
+        params[1] = (void *)[self getRowData:(int)[self selectedRow]];
+        
+        _event_handler(self, (NSEvent *)params, 9);
     }
     [super keyUp:theEvent];
 }
@@ -6804,6 +6824,24 @@
 
 
 /*
+ * Sets the data pointer of a row in the container.
+ * Parameters:
+ *          pointer: Pointer to the allocated memory in dw_container_alloc().
+ *          row: Zero based row of data being set.
+ *          data: Data pointer.
+ */
+void API dw_container_set_row_data(void *pointer, int row, void *data)
+{
+    int _locked_by_me = FALSE;
+    DW_MUTEX_LOCK;
+    DWContainer *cont = pointer;
+    int lastadd = [cont lastAddPoint];
+    [cont setRowData:(row+lastadd) title:data];
+    DW_MUTEX_UNLOCK;
+}
+
+
+/*
  * Sets the title of a row in the container.
  * Parameters:
  *          handle: Handle to window (widget) of container.
@@ -6820,6 +6858,22 @@
 }
 
 /*
+ * Sets the data pointer of a row in the container.
+ * Parameters:
+ *          handle: Handle to window (widget) of container.
+ *          row: Zero based row of data being set.
+ *          data: Data pointer.
+ */
+void API dw_container_change_row_data(HWND handle, int row, void *data)
+{
+    int _locked_by_me = FALSE;
+    DW_MUTEX_LOCK;
+    DWContainer *cont = handle;
+    [cont setRowData:row title:data];
+    DW_MUTEX_UNLOCK;
+}
+
+/*
  * Sets the title of a row in the container.
  * Parameters:
  *          handle: Handle to the container window (widget).
@@ -6950,11 +7004,14 @@
     DWContainer *cont = handle;
     NSIndexSet *selected = [cont selectedRowIndexes];
     NSUInteger result = [selected indexGreaterThanOrEqualToIndex:0];
-    char *retval = NULL;
+    void *retval = NULL;
 
     if(result != NSNotFound)
     {
-        retval = [cont getRowTitle:(int)result];
+        if(flags & DW_CR_RETDATA)
+            retval = [cont getRowData:(int)result];
+        else
+            retval = [cont getRowTitle:(int)result];
         [cont setLastQueryPoint:(int)result];
     }
     DW_MUTEX_UNLOCK;
@@ -6977,11 +7034,14 @@
     int lastQueryPoint = [cont lastQueryPoint];
     NSIndexSet *selected = [cont selectedRowIndexes];
     NSUInteger result = [selected indexGreaterThanIndex:lastQueryPoint];
-    char *retval = NULL;
+    void *retval = NULL;
 
     if(result != NSNotFound)
     {
-        retval = [cont getRowTitle:(int)result];
+        if(flags & DW_CR_RETDATA)
+            retval = [cont getRowData:(int)result];
+        else
+            retval = [cont getRowTitle:(int)result];
         [cont setLastQueryPoint:(int)result];
     }
     DW_MUTEX_UNLOCK;
@@ -7002,13 +7062,12 @@
     DWContainer *cont = handle;
     char *thistext;
     int x, count = (int)[cont numberOfRowsInTableView:cont];
-    int textcomp = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_textcomp"));
 
     for(x=0;x<count;x++)
     {
         thistext = [cont getRowTitle:x];
 
-        if((textcomp && thistext && strcmp(thistext, text) == 0) || (!textcomp && thistext == text))
+        if(thistext && strcmp(thistext, text) == 0)
         {
             NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)x];
 
@@ -7025,6 +7084,41 @@
 }
 
 /*
+ * Cursors the item with the data speficied, and scrolls to that item.
+ * Parameters:
+ *       handle: Handle to the window (widget) to be queried.
+ *       data: Data associated with the row.
+ */
+void API dw_container_cursor_by_data(HWND handle, void *data)
+{
+    int _locked_by_me = FALSE;
+    DW_LOCAL_POOL_IN;
+    DW_MUTEX_LOCK;
+    DWContainer *cont = handle;
+    void *thisdata;
+    int x, count = (int)[cont numberOfRowsInTableView:cont];
+    
+    for(x=0;x<count;x++)
+    {
+        thisdata = [cont getRowData:x];
+        
+        if(thisdata == data)
+        {
+            NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)x];
+            
+            [cont selectRowIndexes:selected byExtendingSelection:YES];
+            [selected release];
+            [cont scrollRowToVisible:x];
+            DW_MUTEX_UNLOCK;
+            DW_LOCAL_POOL_OUT;
+            return;
+        }
+    }
+    DW_MUTEX_UNLOCK;
+    DW_LOCAL_POOL_OUT;
+}
+
+/*
  * Deletes the item with the text speficied.
  * Parameters:
  *       handle: Handle to the window (widget).
@@ -7037,13 +7131,41 @@
     DWContainer *cont = handle;
     char *thistext;
     int x, count = (int)[cont numberOfRowsInTableView:cont];
-    int textcomp = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_textcomp"));
 
     for(x=0;x<count;x++)
     {
         thistext = [cont getRowTitle:x];
 
-        if((textcomp && thistext && strcmp(thistext, text) == 0) || (!textcomp && thistext == text))
+        if(thistext && strcmp(thistext, text) == 0)
+        {
+            [cont removeRow:x];
+            [cont reloadData];
+            DW_MUTEX_UNLOCK;
+            return;
+        }
+    }
+    DW_MUTEX_UNLOCK;
+}
+
+/*
+ * Deletes the item with the data speficied.
+ * Parameters:
+ *       handle: Handle to the window (widget).
+ *       data: Data specified.
+ */
+void API dw_container_delete_row_by_data(HWND handle, void *data)
+{
+    int _locked_by_me = FALSE;
+    DW_MUTEX_LOCK;
+    DWContainer *cont = handle;
+    void *thisdata;
+    int x, count = (int)[cont numberOfRowsInTableView:cont];
+    
+    for(x=0;x<count;x++)
+    {
+        thisdata = [cont getRowData:x];
+        
+        if(thisdata == data)
         {
             [cont removeRow:x];
             [cont reloadData];