comparison mac/dw.m @ 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 9c7485b1921c
children 71c8a45b2a35
comparison
equal deleted inserted replaced
1870:5a4d98cab9d3 1871:3f571ad9b92e
354 return clickfunc(object, handler->data); 354 return clickfunc(object, handler->data);
355 } 355 }
356 /* Container class selection event */ 356 /* Container class selection event */
357 case 9: 357 case 9:
358 { 358 {
359 int (*containerselectfunc)(HWND, char *, void *) = handler->signalfunction; 359 int (*containerselectfunc)(HWND, char *, void *, void *) = handler->signalfunction;
360 360 void **params = (void **)event;
361 return containerselectfunc(handler->window, (char *)event, handler->data); 361
362 return containerselectfunc(handler->window, params[0], handler->data, params[1]);
362 } 363 }
363 /* Container context menu event */ 364 /* Container context menu event */
364 case 10: 365 case 10:
365 { 366 {
366 int (* API containercontextfunc)(HWND, char *, int, int, void *, void *) = (int (* API)(HWND, char *, int, int, void *, void *))handler->signalfunction; 367 int (* API containercontextfunc)(HWND, char *, int, int, void *, void *) = (int (* API)(HWND, char *, int, int, void *, void *))handler->signalfunction;
1762 void *userdata; 1763 void *userdata;
1763 NSMutableArray *tvcols; 1764 NSMutableArray *tvcols;
1764 NSMutableArray *data; 1765 NSMutableArray *data;
1765 NSMutableArray *types; 1766 NSMutableArray *types;
1766 NSPointerArray *titles; 1767 NSPointerArray *titles;
1768 NSPointerArray *rowdatas;
1767 NSColor *fgcolor, *oddcolor, *evencolor; 1769 NSColor *fgcolor, *oddcolor, *evencolor;
1768 int lastAddPoint, lastQueryPoint; 1770 int lastAddPoint, lastQueryPoint;
1769 id scrollview; 1771 id scrollview;
1770 int filesystem; 1772 int filesystem;
1771 } 1773 }
1883 { 1885 {
1884 lastAddPoint++; 1886 lastAddPoint++;
1885 } 1887 }
1886 [data insertObjects:input atIndexes:set]; 1888 [data insertObjects:input atIndexes:set];
1887 [titles insertPointer:NULL atIndex:index]; 1889 [titles insertPointer:NULL atIndex:index];
1890 [rowdatas insertPointer:NULL atIndex:index];
1888 [set release]; 1891 [set release];
1889 return (int)[titles count]; 1892 return (int)[titles count];
1890 } 1893 }
1891 return 0; 1894 return 0;
1892 } 1895 }
1895 if(data) 1898 if(data)
1896 { 1899 {
1897 lastAddPoint = (int)[titles count]; 1900 lastAddPoint = (int)[titles count];
1898 [data addObjectsFromArray:input]; 1901 [data addObjectsFromArray:input];
1899 [titles addPointer:NULL]; 1902 [titles addPointer:NULL];
1903 [rowdatas addPointer:NULL];
1900 return (int)[titles count]; 1904 return (int)[titles count];
1901 } 1905 }
1902 return 0; 1906 return 0;
1903 } 1907 }
1904 -(int)addRows:(int)number 1908 -(int)addRows:(int)number
1915 [data addObject:[NSNull null]]; 1919 [data addObject:[NSNull null]];
1916 } 1920 }
1917 for(z=0;z<number;z++) 1921 for(z=0;z<number;z++)
1918 { 1922 {
1919 [titles addPointer:NULL]; 1923 [titles addPointer:NULL];
1924 [rowdatas addPointer:NULL];
1920 } 1925 }
1921 return (int)[titles count]; 1926 return (int)[titles count];
1922 } 1927 }
1923 return 0; 1928 return 0;
1924 } 1929 }
1985 for(z=start;z<end;z++) 1990 for(z=start;z<end;z++)
1986 { 1991 {
1987 [data removeObjectAtIndex:start]; 1992 [data removeObjectAtIndex:start];
1988 } 1993 }
1989 [titles removePointerAtIndex:row]; 1994 [titles removePointerAtIndex:row];
1995 [rowdatas removePointerAtIndex:row];
1990 if(lastAddPoint > 0 && lastAddPoint > row) 1996 if(lastAddPoint > 0 && lastAddPoint > row)
1991 { 1997 {
1992 lastAddPoint--; 1998 lastAddPoint--;
1993 } 1999 }
1994 } 2000 }
1995 } 2001 }
1996 -(void)setRow:(int)row title:(void *)input { if(titles && input) { [titles replacePointerAtIndex:row withPointer:input]; } } 2002 -(void)setRow:(int)row title:(void *)input { if(titles && input) { [titles replacePointerAtIndex:row withPointer:input]; } }
2003 -(void)setRowData:(int)row title:(void *)input { if(rowdatas && input) { [rowdatas replacePointerAtIndex:row withPointer:input]; } }
1997 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; } 2004 -(void *)getRowTitle:(int)row { if(titles && row > -1) { return [titles pointerAtIndex:row]; } return NULL; }
2005 -(void *)getRowData:(int)row { if(rowdatas && row > -1) { return [rowdatas pointerAtIndex:row]; } return NULL; }
1998 -(id)getRow:(int)row and:(int)col { if(data) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; } 2006 -(id)getRow:(int)row and:(int)col { if(data) { int index = (int)(row * [tvcols count]) + col; return [data objectAtIndex:index]; } return nil; }
1999 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; } 2007 -(int)cellType:(int)col { return [[types objectAtIndex:col] intValue]; }
2000 -(int)lastAddPoint { return lastAddPoint; } 2008 -(int)lastAddPoint { return lastAddPoint; }
2001 -(int)lastQueryPoint { return lastQueryPoint; } 2009 -(int)lastQueryPoint { return lastQueryPoint; }
2002 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; } 2010 -(void)setLastQueryPoint:(int)input { lastQueryPoint = input; }
2012 2020
2013 IMP iwopa = [[NSPointerArray class] methodForSelector:swopa]; 2021 IMP iwopa = [[NSPointerArray class] methodForSelector:swopa];
2014 2022
2015 titles = iwopa([NSPointerArray class], swopa); 2023 titles = iwopa([NSPointerArray class], swopa);
2016 [titles retain]; 2024 [titles retain];
2025 rowdatas = iwopa([NSPointerArray class], swopa);
2026 [rowdatas retain];
2017 tvcols = [[[NSMutableArray alloc] init] retain]; 2027 tvcols = [[[NSMutableArray alloc] init] retain];
2018 data = [[[NSMutableArray alloc] init] retain]; 2028 data = [[[NSMutableArray alloc] init] retain];
2019 types = [[[NSMutableArray alloc] init] retain]; 2029 types = [[[NSMutableArray alloc] init] retain];
2020 2030
2021 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:self]; 2031 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSTableViewSelectionDidChangeNotification object:self];
2151 [cell setTextColor:fgcolor]; 2161 [cell setTextColor:fgcolor];
2152 } 2162 }
2153 } 2163 }
2154 -(void)doubleClicked:(id)sender 2164 -(void)doubleClicked:(id)sender
2155 { 2165 {
2166 void *params[2];
2167
2168 params[0] = (void *)[self getRowTitle:(int)[self selectedRow]];
2169 params[1] = (void *)[self getRowData:(int)[self selectedRow]];
2170
2156 /* Handler for container class */ 2171 /* Handler for container class */
2157 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 9); 2172 _event_handler(self, (NSEvent *)params, 9);
2158 } 2173 }
2159 -(void)keyUp:(NSEvent *)theEvent 2174 -(void)keyUp:(NSEvent *)theEvent
2160 { 2175 {
2161 if([[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN) 2176 if([[theEvent charactersIgnoringModifiers] characterAtIndex:0] == VK_RETURN)
2162 { 2177 {
2163 _event_handler(self, (NSEvent *)[self getRowTitle:(int)[self selectedRow]], 9); 2178 void *params[2];
2179
2180 params[0] = (void *)[self getRowTitle:(int)[self selectedRow]];
2181 params[1] = (void *)[self getRowData:(int)[self selectedRow]];
2182
2183 _event_handler(self, (NSEvent *)params, 9);
2164 } 2184 }
2165 [super keyUp:theEvent]; 2185 [super keyUp:theEvent];
2166 } 2186 }
2167 2187
2168 -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn 2188 -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn
6802 DW_MUTEX_UNLOCK; 6822 DW_MUTEX_UNLOCK;
6803 } 6823 }
6804 6824
6805 6825
6806 /* 6826 /*
6827 * Sets the data pointer of a row in the container.
6828 * Parameters:
6829 * pointer: Pointer to the allocated memory in dw_container_alloc().
6830 * row: Zero based row of data being set.
6831 * data: Data pointer.
6832 */
6833 void API dw_container_set_row_data(void *pointer, int row, void *data)
6834 {
6835 int _locked_by_me = FALSE;
6836 DW_MUTEX_LOCK;
6837 DWContainer *cont = pointer;
6838 int lastadd = [cont lastAddPoint];
6839 [cont setRowData:(row+lastadd) title:data];
6840 DW_MUTEX_UNLOCK;
6841 }
6842
6843
6844 /*
6807 * Sets the title of a row in the container. 6845 * Sets the title of a row in the container.
6808 * Parameters: 6846 * Parameters:
6809 * handle: Handle to window (widget) of container. 6847 * handle: Handle to window (widget) of container.
6810 * row: Zero based row of data being set. 6848 * row: Zero based row of data being set.
6811 * title: String title of the item. 6849 * title: String title of the item.
6814 { 6852 {
6815 int _locked_by_me = FALSE; 6853 int _locked_by_me = FALSE;
6816 DW_MUTEX_LOCK; 6854 DW_MUTEX_LOCK;
6817 DWContainer *cont = handle; 6855 DWContainer *cont = handle;
6818 [cont setRow:row title:title]; 6856 [cont setRow:row title:title];
6857 DW_MUTEX_UNLOCK;
6858 }
6859
6860 /*
6861 * Sets the data pointer of a row in the container.
6862 * Parameters:
6863 * handle: Handle to window (widget) of container.
6864 * row: Zero based row of data being set.
6865 * data: Data pointer.
6866 */
6867 void API dw_container_change_row_data(HWND handle, int row, void *data)
6868 {
6869 int _locked_by_me = FALSE;
6870 DW_MUTEX_LOCK;
6871 DWContainer *cont = handle;
6872 [cont setRowData:row title:data];
6819 DW_MUTEX_UNLOCK; 6873 DW_MUTEX_UNLOCK;
6820 } 6874 }
6821 6875
6822 /* 6876 /*
6823 * Sets the title of a row in the container. 6877 * Sets the title of a row in the container.
6948 int _locked_by_me = FALSE; 7002 int _locked_by_me = FALSE;
6949 DW_MUTEX_LOCK; 7003 DW_MUTEX_LOCK;
6950 DWContainer *cont = handle; 7004 DWContainer *cont = handle;
6951 NSIndexSet *selected = [cont selectedRowIndexes]; 7005 NSIndexSet *selected = [cont selectedRowIndexes];
6952 NSUInteger result = [selected indexGreaterThanOrEqualToIndex:0]; 7006 NSUInteger result = [selected indexGreaterThanOrEqualToIndex:0];
6953 char *retval = NULL; 7007 void *retval = NULL;
6954 7008
6955 if(result != NSNotFound) 7009 if(result != NSNotFound)
6956 { 7010 {
6957 retval = [cont getRowTitle:(int)result]; 7011 if(flags & DW_CR_RETDATA)
7012 retval = [cont getRowData:(int)result];
7013 else
7014 retval = [cont getRowTitle:(int)result];
6958 [cont setLastQueryPoint:(int)result]; 7015 [cont setLastQueryPoint:(int)result];
6959 } 7016 }
6960 DW_MUTEX_UNLOCK; 7017 DW_MUTEX_UNLOCK;
6961 return retval; 7018 return retval;
6962 } 7019 }
6975 DW_MUTEX_LOCK; 7032 DW_MUTEX_LOCK;
6976 DWContainer *cont = handle; 7033 DWContainer *cont = handle;
6977 int lastQueryPoint = [cont lastQueryPoint]; 7034 int lastQueryPoint = [cont lastQueryPoint];
6978 NSIndexSet *selected = [cont selectedRowIndexes]; 7035 NSIndexSet *selected = [cont selectedRowIndexes];
6979 NSUInteger result = [selected indexGreaterThanIndex:lastQueryPoint]; 7036 NSUInteger result = [selected indexGreaterThanIndex:lastQueryPoint];
6980 char *retval = NULL; 7037 void *retval = NULL;
6981 7038
6982 if(result != NSNotFound) 7039 if(result != NSNotFound)
6983 { 7040 {
6984 retval = [cont getRowTitle:(int)result]; 7041 if(flags & DW_CR_RETDATA)
7042 retval = [cont getRowData:(int)result];
7043 else
7044 retval = [cont getRowTitle:(int)result];
6985 [cont setLastQueryPoint:(int)result]; 7045 [cont setLastQueryPoint:(int)result];
6986 } 7046 }
6987 DW_MUTEX_UNLOCK; 7047 DW_MUTEX_UNLOCK;
6988 return retval; 7048 return retval;
6989 } 7049 }
7000 DW_LOCAL_POOL_IN; 7060 DW_LOCAL_POOL_IN;
7001 DW_MUTEX_LOCK; 7061 DW_MUTEX_LOCK;
7002 DWContainer *cont = handle; 7062 DWContainer *cont = handle;
7003 char *thistext; 7063 char *thistext;
7004 int x, count = (int)[cont numberOfRowsInTableView:cont]; 7064 int x, count = (int)[cont numberOfRowsInTableView:cont];
7005 int textcomp = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_textcomp"));
7006 7065
7007 for(x=0;x<count;x++) 7066 for(x=0;x<count;x++)
7008 { 7067 {
7009 thistext = [cont getRowTitle:x]; 7068 thistext = [cont getRowTitle:x];
7010 7069
7011 if((textcomp && thistext && strcmp(thistext, text) == 0) || (!textcomp && thistext == text)) 7070 if(thistext && strcmp(thistext, text) == 0)
7012 { 7071 {
7013 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)x]; 7072 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)x];
7014 7073
7015 [cont selectRowIndexes:selected byExtendingSelection:YES]; 7074 [cont selectRowIndexes:selected byExtendingSelection:YES];
7016 [selected release]; 7075 [selected release];
7023 DW_MUTEX_UNLOCK; 7082 DW_MUTEX_UNLOCK;
7024 DW_LOCAL_POOL_OUT; 7083 DW_LOCAL_POOL_OUT;
7025 } 7084 }
7026 7085
7027 /* 7086 /*
7087 * Cursors the item with the data speficied, and scrolls to that item.
7088 * Parameters:
7089 * handle: Handle to the window (widget) to be queried.
7090 * data: Data associated with the row.
7091 */
7092 void API dw_container_cursor_by_data(HWND handle, void *data)
7093 {
7094 int _locked_by_me = FALSE;
7095 DW_LOCAL_POOL_IN;
7096 DW_MUTEX_LOCK;
7097 DWContainer *cont = handle;
7098 void *thisdata;
7099 int x, count = (int)[cont numberOfRowsInTableView:cont];
7100
7101 for(x=0;x<count;x++)
7102 {
7103 thisdata = [cont getRowData:x];
7104
7105 if(thisdata == data)
7106 {
7107 NSIndexSet *selected = [[NSIndexSet alloc] initWithIndex:(NSUInteger)x];
7108
7109 [cont selectRowIndexes:selected byExtendingSelection:YES];
7110 [selected release];
7111 [cont scrollRowToVisible:x];
7112 DW_MUTEX_UNLOCK;
7113 DW_LOCAL_POOL_OUT;
7114 return;
7115 }
7116 }
7117 DW_MUTEX_UNLOCK;
7118 DW_LOCAL_POOL_OUT;
7119 }
7120
7121 /*
7028 * Deletes the item with the text speficied. 7122 * Deletes the item with the text speficied.
7029 * Parameters: 7123 * Parameters:
7030 * handle: Handle to the window (widget). 7124 * handle: Handle to the window (widget).
7031 * text: Text usually returned by dw_container_query(). 7125 * text: Text usually returned by dw_container_query().
7032 */ 7126 */
7035 int _locked_by_me = FALSE; 7129 int _locked_by_me = FALSE;
7036 DW_MUTEX_LOCK; 7130 DW_MUTEX_LOCK;
7037 DWContainer *cont = handle; 7131 DWContainer *cont = handle;
7038 char *thistext; 7132 char *thistext;
7039 int x, count = (int)[cont numberOfRowsInTableView:cont]; 7133 int x, count = (int)[cont numberOfRowsInTableView:cont];
7040 int textcomp = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_textcomp"));
7041 7134
7042 for(x=0;x<count;x++) 7135 for(x=0;x<count;x++)
7043 { 7136 {
7044 thistext = [cont getRowTitle:x]; 7137 thistext = [cont getRowTitle:x];
7045 7138
7046 if((textcomp && thistext && strcmp(thistext, text) == 0) || (!textcomp && thistext == text)) 7139 if(thistext && strcmp(thistext, text) == 0)
7140 {
7141 [cont removeRow:x];
7142 [cont reloadData];
7143 DW_MUTEX_UNLOCK;
7144 return;
7145 }
7146 }
7147 DW_MUTEX_UNLOCK;
7148 }
7149
7150 /*
7151 * Deletes the item with the data speficied.
7152 * Parameters:
7153 * handle: Handle to the window (widget).
7154 * data: Data specified.
7155 */
7156 void API dw_container_delete_row_by_data(HWND handle, void *data)
7157 {
7158 int _locked_by_me = FALSE;
7159 DW_MUTEX_LOCK;
7160 DWContainer *cont = handle;
7161 void *thisdata;
7162 int x, count = (int)[cont numberOfRowsInTableView:cont];
7163
7164 for(x=0;x<count;x++)
7165 {
7166 thisdata = [cont getRowData:x];
7167
7168 if(thisdata == data)
7047 { 7169 {
7048 [cont removeRow:x]; 7170 [cont removeRow:x];
7049 [cont reloadData]; 7171 [cont reloadData];
7050 DW_MUTEX_UNLOCK; 7172 DW_MUTEX_UNLOCK;
7051 return; 7173 return;