comparison mac/dw.m @ 2188:a02ff8927927

Mac: Change the listbox functions to use NSTableCellView. When a NSTableCellView already exists, use it don't editCell:
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 15 Oct 2020 03:38:23 +0000
parents 6740154cec68
children a5d58393f7d0
comparison
equal deleted inserted replaced
2187:6740154cec68 2188:a02ff8927927
5789 5789
5790 if([object isMemberOfClass:[DWComboBox class]]) 5790 if([object isMemberOfClass:[DWComboBox class]])
5791 { 5791 {
5792 DWComboBox *combo = handle; 5792 DWComboBox *combo = handle;
5793 5793
5794 [combo addItemWithObjectValue:[ NSString stringWithUTF8String:text ]]; 5794 [combo addItemWithObjectValue:[NSString stringWithUTF8String:text]];
5795 } 5795 }
5796 else if([object isMemberOfClass:[DWContainer class]]) 5796 else if([object isMemberOfClass:[DWContainer class]])
5797 { 5797 {
5798 DWContainer *cont = handle; 5798 DWContainer *cont = handle;
5799 NSString *nstr = [ NSString stringWithUTF8String:text ]; 5799 NSString *nstr = [NSString stringWithUTF8String:text];
5800 #ifdef DW_USE_NSVIEW
5801 NSArray *newrow = [NSArray arrayWithObject:_dw_table_cell_view_new(nil, nstr)];
5802 #else
5800 NSArray *newrow = [NSArray arrayWithObject:nstr]; 5803 NSArray *newrow = [NSArray arrayWithObject:nstr];
5804 #endif
5801 5805
5802 [cont addRow:newrow]; 5806 [cont addRow:newrow];
5803 [cont reloadData]; 5807 [cont reloadData];
5804 [cont optimize]; 5808 [cont optimize];
5805 [cont setNeedsDisplay:YES]; 5809 [cont setNeedsDisplay:YES];
5824 5828
5825 if([object isMemberOfClass:[DWComboBox class]]) 5829 if([object isMemberOfClass:[DWComboBox class]])
5826 { 5830 {
5827 DWComboBox *combo = handle; 5831 DWComboBox *combo = handle;
5828 5832
5829 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:text ] atIndex:pos]; 5833 [combo insertItemWithObjectValue:[NSString stringWithUTF8String:text] atIndex:pos];
5830 } 5834 }
5831 else if([object isMemberOfClass:[DWContainer class]]) 5835 else if([object isMemberOfClass:[DWContainer class]])
5832 { 5836 {
5833 DWContainer *cont = handle; 5837 DWContainer *cont = handle;
5834 NSString *nstr = [ NSString stringWithUTF8String:text ]; 5838 NSString *nstr = [NSString stringWithUTF8String:text];
5839 #ifdef DW_USE_NSVIEW
5840 NSArray *newrow = [NSArray arrayWithObject:_dw_table_cell_view_new(nil, nstr)];
5841 #else
5835 NSArray *newrow = [NSArray arrayWithObject:nstr]; 5842 NSArray *newrow = [NSArray arrayWithObject:nstr];
5843 #endif
5836 5844
5837 [cont insertRow:newrow at:pos]; 5845 [cont insertRow:newrow at:pos];
5838 [cont reloadData]; 5846 [cont reloadData];
5839 [cont optimize]; 5847 [cont optimize];
5840 [cont setNeedsDisplay:YES]; 5848 [cont setNeedsDisplay:YES];
5873 int z; 5881 int z;
5874 5882
5875 for(z=0;z<count;z++) 5883 for(z=0;z<count;z++)
5876 { 5884 {
5877 NSString *nstr = [NSString stringWithUTF8String:text[z]]; 5885 NSString *nstr = [NSString stringWithUTF8String:text[z]];
5886 #ifdef DW_USE_NSVIEW
5887 NSArray *newrow = [NSArray arrayWithObjects:_dw_table_cell_view_new(nil, nstr),nil];
5888 #else
5878 NSArray *newrow = [NSArray arrayWithObjects:nstr,nil]; 5889 NSArray *newrow = [NSArray arrayWithObjects:nstr,nil];
5890 #endif
5879 5891
5880 [cont addRow:newrow]; 5892 [cont addRow:newrow];
5881 } 5893 }
5882 [cont reloadData]; 5894 [cont reloadData];
5883 [cont optimize]; 5895 [cont optimize];
6013 { 6025 {
6014 *buffer = '\0'; 6026 *buffer = '\0';
6015 } 6027 }
6016 else 6028 else
6017 { 6029 {
6030 #ifdef DW_USE_NSVIEW
6031 NSTableCellView *cell = [cont getRow:index and:0];
6032 NSString *nstr = [[cell textField] stringValue];
6033 #else
6018 NSString *nstr = [cont getRow:index and:0]; 6034 NSString *nstr = [cont getRow:index and:0];
6019 6035 #endif
6020 strncpy(buffer, [ nstr UTF8String ], length - 1); 6036
6037 strncpy(buffer, [nstr UTF8String], length - 1);
6021 } 6038 }
6022 } 6039 }
6023 DW_FUNCTION_RETURN_NOTHING; 6040 DW_FUNCTION_RETURN_NOTHING;
6024 } 6041 }
6025 6042
6044 int count = (int)[combo numberOfItems]; 6061 int count = (int)[combo numberOfItems];
6045 6062
6046 if(index <= count) 6063 if(index <= count)
6047 { 6064 {
6048 [combo removeItemAtIndex:index]; 6065 [combo removeItemAtIndex:index];
6049 [combo insertItemWithObjectValue:[ NSString stringWithUTF8String:buffer ] atIndex:index]; 6066 [combo insertItemWithObjectValue:[NSString stringWithUTF8String:buffer] atIndex:index];
6050 } 6067 }
6051 } 6068 }
6052 else if([object isMemberOfClass:[DWContainer class]]) 6069 else if([object isMemberOfClass:[DWContainer class]])
6053 { 6070 {
6054 DWContainer *cont = handle; 6071 DWContainer *cont = handle;
6055 int count = (int)[cont numberOfRowsInTableView:cont]; 6072 int count = (int)[cont numberOfRowsInTableView:cont];
6056 6073
6057 if(index <= count) 6074 if(index <= count)
6058 { 6075 {
6059 NSString *nstr = [ NSString stringWithUTF8String:buffer ]; 6076 NSString *nstr = [NSString stringWithUTF8String:buffer];
6060 6077 #ifdef DW_USE_NSVIEW
6078 NSTableCellView *cell = [cont getRow:index and:0];
6079
6080 [[cell textField] setStringValue:nstr];
6081 #else
6061 [cont editCell:nstr at:index and:0]; 6082 [cont editCell:nstr at:index and:0];
6083 #endif
6062 [cont reloadData]; 6084 [cont reloadData];
6063 [cont optimize]; 6085 [cont optimize];
6064 [cont setNeedsDisplay:YES]; 6086 [cont setNeedsDisplay:YES];
6065 } 6087 }
6066 } 6088 }
7647 DW_FUNCTION_NO_RETURN(dw_container_set_item) 7669 DW_FUNCTION_NO_RETURN(dw_container_set_item)
7648 DW_FUNCTION_RESTORE_PARAM5(handle, HWND, pointer, void *, column, int, row, int, data, void *) 7670 DW_FUNCTION_RESTORE_PARAM5(handle, HWND, pointer, void *, column, int, row, int, data, void *)
7649 { 7671 {
7650 DW_FUNCTION_INIT; 7672 DW_FUNCTION_INIT;
7651 DWContainer *cont = handle; 7673 DWContainer *cont = handle;
7652 id object = nil, icon = nil, text = nil; 7674 id icon = nil, text = nil;
7653 int type = [cont cellType:column]; 7675 int type = [cont cellType:column];
7654 int lastadd = 0; 7676 int lastadd = 0;
7655 7677
7656 /* If pointer is NULL we are getting a change request instead of set */ 7678 /* If pointer is NULL we are getting a change request instead of set */
7657 if(pointer) 7679 if(pointer)
7708 text = [ NSString stringWithUTF8String:textbuffer ]; 7730 text = [ NSString stringWithUTF8String:textbuffer ];
7709 } 7731 }
7710 } 7732 }
7711 7733
7712 #ifdef DW_USE_NSVIEW 7734 #ifdef DW_USE_NSVIEW
7713 object = _dw_table_cell_view_new(icon, text); 7735 id object = [cont getRow:(row+lastadd) and:column];
7736
7737 /* If it is a cell, change the content of the cell */
7738 if([object isMemberOfClass:[NSTableCellView class]])
7739 {
7740 NSTableCellView *cell = [cont getRow:(row+lastadd) and:column];
7741 if(icon)
7742 [[cell imageView] setImage:icon];
7743 else
7744 [[cell textField] setStringValue:text];
7745 }
7746 else /* Otherwise replace it with a new cell */
7747 [cont editCell:_dw_table_cell_view_new(icon, text) at:(row+lastadd) and:column];
7714 #else 7748 #else
7715 object = icon ? icon : text; 7749 [cont editCell:(icon ? icon : text) at:(row+lastadd) and:column];
7716 #endif 7750 #endif
7717
7718 [cont editCell:object at:(row+lastadd) and:column];
7719 [cont setNeedsDisplay:YES]; 7751 [cont setNeedsDisplay:YES];
7720 DW_FUNCTION_RETURN_NOTHING; 7752 DW_FUNCTION_RETURN_NOTHING;
7721 } 7753 }
7722 7754
7723 /* 7755 /*