Mercurial > dwindows
comparison mac/dw.m @ 682:de4aa126fb2f
Fixes for tree packing and a data source issue. Implemented most of the missing tree functions.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 02 Mar 2011 17:29:33 +0000 |
parents | 5fe12469c1fb |
children | 7385011c3327 |
comparison
equal
deleted
inserted
replaced
681:5fe12469c1fb | 682:de4aa126fb2f |
---|---|
766 return nil; | 766 return nil; |
767 } | 767 } |
768 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } | 768 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } |
769 @end | 769 @end |
770 | 770 |
771 /* Dive into the tree showing all nodes */ | |
772 void _free_tree_recurse(NSMutableArray *node, NSPointerArray *item) | |
773 { | |
774 if(node) | |
775 { | |
776 int count = (int)[node count]; | |
777 int z; | |
778 | |
779 for(z=0;z<count;z++) | |
780 { | |
781 NSPointerArray *pnt = [node objectAtIndex:z]; | |
782 NSMutableArray *children = (NSMutableArray *)[pnt pointerAtIndex:3]; | |
783 | |
784 if(children) | |
785 { | |
786 if(item == pnt) | |
787 { | |
788 _free_tree_recurse(children, NULL); | |
789 } | |
790 else | |
791 { | |
792 _free_tree_recurse(children, item); | |
793 } | |
794 } | |
795 if(!item || item == pnt) | |
796 { | |
797 [pnt release]; | |
798 } | |
799 } | |
800 } | |
801 if(!item) | |
802 { | |
803 [node release]; | |
804 } | |
805 } | |
806 | |
771 /* Subclass for a Tree type */ | 807 /* Subclass for a Tree type */ |
772 @interface DWTree : NSOutlineView <NSOutlineViewDataSource> | 808 @interface DWTree : NSOutlineView <NSOutlineViewDataSource> |
773 { | 809 { |
774 void *userdata; | 810 void *userdata; |
775 NSTableColumn *imagecol; | 811 NSTableColumn *imagecol; |
787 -(void)addTree:(NSPointerArray *)item and:(NSPointerArray *)parent; | 823 -(void)addTree:(NSPointerArray *)item and:(NSPointerArray *)parent; |
788 -(void *)userdata; | 824 -(void *)userdata; |
789 -(void)setUserdata:(void *)input; | 825 -(void)setUserdata:(void *)input; |
790 -(NSScrollView *)scrollview; | 826 -(NSScrollView *)scrollview; |
791 -(void)setScrollview:(NSScrollView *)input; | 827 -(void)setScrollview:(NSScrollView *)input; |
828 -(void)deleteNode:(NSPointerArray *)item; | |
829 -(void)clear; | |
792 @end | 830 @end |
793 | 831 |
794 @implementation DWTree | 832 @implementation DWTree |
795 -(id)init | 833 -(id)init |
796 { | 834 { |
804 [imagecol setResizingMask:NSTableColumnNoResizing]; | 842 [imagecol setResizingMask:NSTableColumnNoResizing]; |
805 [imagecol setWidth:20]; | 843 [imagecol setWidth:20]; |
806 [self addTableColumn:imagecol]; | 844 [self addTableColumn:imagecol]; |
807 textcol = [[NSTableColumn alloc] init]; | 845 textcol = [[NSTableColumn alloc] init]; |
808 [self addTableColumn:textcol]; | 846 [self addTableColumn:textcol]; |
847 [self setOutlineTableColumn:textcol]; | |
809 } | 848 } |
810 return self; | 849 return self; |
811 } | 850 } |
812 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item | 851 -(id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item |
813 { | 852 { |
814 if (item) | 853 if(item) |
815 { | 854 { |
816 NSMutableArray *array = [item pointerAtIndex:3]; | 855 NSMutableArray *array = [item pointerAtIndex:3]; |
817 return array ? [array objectAtIndex:index] : nil; | 856 return array ? [array objectAtIndex:index] : nil; |
818 } | 857 } |
819 else | 858 else |
878 } | 917 } |
879 else | 918 else |
880 { | 919 { |
881 if(!data) | 920 if(!data) |
882 { | 921 { |
883 data = [[NSMutableArray alloc] init]; | 922 children = data = [[NSMutableArray alloc] init]; |
884 } | 923 } |
885 } | 924 } |
886 [children addObject:item]; | 925 [children addObject:item]; |
887 } | 926 } |
888 -(void *)userdata { return userdata; } | 927 -(void *)userdata { return userdata; } |
889 -(void)setUserdata:(void *)input { userdata = input; } | 928 -(void)setUserdata:(void *)input { userdata = input; } |
890 -(NSScrollView *)scrollview { return scrollview; } | 929 -(NSScrollView *)scrollview { return scrollview; } |
891 -(void)setScrollview:(NSScrollView *)input { scrollview = input; } | 930 -(void)setScrollview:(NSScrollView *)input { scrollview = input; } |
931 -(void)deleteNode:(NSPointerArray *)item { _free_tree_recurse(data, item); } | |
932 -(void)clear { NSMutableArray *toclear = data; data = nil; _free_tree_recurse(toclear, NULL); [self reloadData]; } | |
933 -(void)dealloc | |
934 { | |
935 UserData *root = userdata; | |
936 _remove_userdata(&root, NULL, TRUE); | |
937 _free_tree_recurse(data, NULL); | |
938 [imagecol release]; | |
939 [textcol release]; | |
940 [super dealloc]; | |
941 } | |
892 @end | 942 @end |
893 | 943 |
894 /* Subclass for a Calendar type */ | 944 /* Subclass for a Calendar type */ |
895 @interface DWCalendar : NSDatePicker | 945 @interface DWCalendar : NSDatePicker |
896 { | 946 { |
1924 if([ object isKindOfClass:[ DWContainer class ] ]) | 1974 if([ object isKindOfClass:[ DWContainer class ] ]) |
1925 { | 1975 { |
1926 DWContainer *cont = item; | 1976 DWContainer *cont = item; |
1927 this = item = [cont scrollview]; | 1977 this = item = [cont scrollview]; |
1928 } | 1978 } |
1979 else if([ object isKindOfClass:[ DWTree class ] ]) | |
1980 { | |
1981 DWTree *tree = item; | |
1982 this = item = [tree scrollview]; | |
1983 } | |
1929 | 1984 |
1930 /* Duplicate the existing data */ | 1985 /* Duplicate the existing data */ |
1931 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | 1986 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); |
1932 | 1987 |
1933 for(z=0;z<thisbox->count;z++) | 1988 for(z=0;z<thisbox->count;z++) |
2008 /* Query the objects */ | 2063 /* Query the objects */ |
2009 if([ object isKindOfClass:[ DWContainer class ] ]) | 2064 if([ object isKindOfClass:[ DWContainer class ] ]) |
2010 { | 2065 { |
2011 DWContainer *cont = item; | 2066 DWContainer *cont = item; |
2012 this = item = [cont scrollview]; | 2067 this = item = [cont scrollview]; |
2068 } | |
2069 else if([ object isKindOfClass:[ DWTree class ] ]) | |
2070 { | |
2071 DWTree *tree = item; | |
2072 this = item = [tree scrollview]; | |
2013 } | 2073 } |
2014 | 2074 |
2015 /* Duplicate the existing data */ | 2075 /* Duplicate the existing data */ |
2016 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); | 2076 tmpitem = malloc(sizeof(Item)*(thisbox->count+1)); |
2017 | 2077 |
3436 * title: The text title of the entry. | 3496 * title: The text title of the entry. |
3437 * icon: Handle to coresponding icon. | 3497 * icon: Handle to coresponding icon. |
3438 */ | 3498 */ |
3439 void API dw_tree_item_change(HWND handle, HTREEITEM item, char *title, HICN icon) | 3499 void API dw_tree_item_change(HWND handle, HTREEITEM item, char *title, HICN icon) |
3440 { | 3500 { |
3441 NSLog(@"dw_tree_item_change() unimplemented\n"); | 3501 DWTree *tree = handle; |
3502 NSPointerArray *array = (NSPointerArray *)item; | |
3503 if(title) | |
3504 { | |
3505 NSString *nstr = [NSString stringWithUTF8String:title]; | |
3506 [array replacePointerAtIndex:1 withPointer:nstr]; | |
3507 } | |
3508 if(icon) | |
3509 { | |
3510 [array replacePointerAtIndex:0 withPointer:icon]; | |
3511 } | |
3512 [tree reloadData]; | |
3442 } | 3513 } |
3443 | 3514 |
3444 /* | 3515 /* |
3445 * Sets the item data of a tree item. | 3516 * Sets the item data of a tree item. |
3446 * Parameters: | 3517 * Parameters: |
3448 * item: Handle of the item to be modified. | 3519 * item: Handle of the item to be modified. |
3449 * itemdata: User defined data to be associated with item. | 3520 * itemdata: User defined data to be associated with item. |
3450 */ | 3521 */ |
3451 void API dw_tree_item_set_data(HWND handle, HTREEITEM item, void *itemdata) | 3522 void API dw_tree_item_set_data(HWND handle, HTREEITEM item, void *itemdata) |
3452 { | 3523 { |
3453 NSLog(@"dw_tree_item_set_data() unimplemented\n"); | 3524 NSPointerArray *array = (NSPointerArray *)item; |
3525 [array replacePointerAtIndex:2 withPointer:itemdata]; | |
3454 } | 3526 } |
3455 | 3527 |
3456 /* | 3528 /* |
3457 * Gets the item data of a tree item. | 3529 * Gets the item data of a tree item. |
3458 * Parameters: | 3530 * Parameters: |
3459 * handle: Handle to the tree containing the item. | 3531 * handle: Handle to the tree containing the item. |
3460 * item: Handle of the item to be modified. | 3532 * item: Handle of the item to be modified. |
3461 */ | 3533 */ |
3462 void * API dw_tree_item_get_data(HWND handle, HTREEITEM item) | 3534 void * API dw_tree_item_get_data(HWND handle, HTREEITEM item) |
3463 { | 3535 { |
3464 NSLog(@"dw_tree_item_get_data() unimplemented\n"); | 3536 NSPointerArray *array = (NSPointerArray *)item; |
3465 return NULL; | 3537 return [array pointerAtIndex:2]; |
3466 } | 3538 } |
3467 | 3539 |
3468 /* | 3540 /* |
3469 * Sets this item as the active selection. | 3541 * Sets this item as the active selection. |
3470 * Parameters: | 3542 * Parameters: |
3471 * handle: Handle to the tree window (widget) to be selected. | 3543 * handle: Handle to the tree window (widget) to be selected. |
3472 * item: Handle to the item to be selected. | 3544 * item: Handle to the item to be selected. |
3473 */ | 3545 */ |
3474 void API dw_tree_item_select(HWND handle, HTREEITEM item) | 3546 void API dw_tree_item_select(HWND handle, HTREEITEM item) |
3475 { | 3547 { |
3476 NSLog(@"dw_tree_item_select() unimplemented\n"); | 3548 DWTree *tree = handle; |
3549 NSInteger itemIndex = [tree rowForItem:item]; | |
3550 if(itemIndex > -1) | |
3551 { | |
3552 [tree selectRowIndexes:[NSIndexSet indexSetWithIndex:itemIndex] byExtendingSelection:NO]; | |
3553 } | |
3477 } | 3554 } |
3478 | 3555 |
3479 /* | 3556 /* |
3480 * Removes all nodes from a tree. | 3557 * Removes all nodes from a tree. |
3481 * Parameters: | 3558 * Parameters: |
3482 * handle: Handle to the window (widget) to be cleared. | 3559 * handle: Handle to the window (widget) to be cleared. |
3483 */ | 3560 */ |
3484 void API dw_tree_clear(HWND handle) | 3561 void API dw_tree_clear(HWND handle) |
3485 { | 3562 { |
3486 NSLog(@"dw_tree_clear() unimplemented\n"); | 3563 DWTree *tree = handle; |
3564 [tree clear]; | |
3487 } | 3565 } |
3488 | 3566 |
3489 /* | 3567 /* |
3490 * Expands a node on a tree. | 3568 * Expands a node on a tree. |
3491 * Parameters: | 3569 * Parameters: |
3492 * handle: Handle to the tree window (widget). | 3570 * handle: Handle to the tree window (widget). |
3493 * item: Handle to node to be expanded. | 3571 * item: Handle to node to be expanded. |
3494 */ | 3572 */ |
3495 void API dw_tree_item_expand(HWND handle, HTREEITEM item) | 3573 void API dw_tree_item_expand(HWND handle, HTREEITEM item) |
3496 { | 3574 { |
3497 NSLog(@"dw_tree_item_expand() unimplemented\n"); | 3575 DWTree *tree = handle; |
3576 [tree expandItem:item]; | |
3498 } | 3577 } |
3499 | 3578 |
3500 /* | 3579 /* |
3501 * Collapses a node on a tree. | 3580 * Collapses a node on a tree. |
3502 * Parameters: | 3581 * Parameters: |
3503 * handle: Handle to the tree window (widget). | 3582 * handle: Handle to the tree window (widget). |
3504 * item: Handle to node to be collapsed. | 3583 * item: Handle to node to be collapsed. |
3505 */ | 3584 */ |
3506 void API dw_tree_item_collapse(HWND handle, HTREEITEM item) | 3585 void API dw_tree_item_collapse(HWND handle, HTREEITEM item) |
3507 { | 3586 { |
3508 NSLog(@"dw_tree_item_collapse() unimplemented\n"); | 3587 DWTree *tree = handle; |
3588 [tree collapseItem:item]; | |
3509 } | 3589 } |
3510 | 3590 |
3511 /* | 3591 /* |
3512 * Removes a node from a tree. | 3592 * Removes a node from a tree. |
3513 * Parameters: | 3593 * Parameters: |
3514 * handle: Handle to the window (widget) to be cleared. | 3594 * handle: Handle to the window (widget) to be cleared. |
3515 * item: Handle to node to be deleted. | 3595 * item: Handle to node to be deleted. |
3516 */ | 3596 */ |
3517 void API dw_tree_item_delete(HWND handle, HTREEITEM item) | 3597 void API dw_tree_item_delete(HWND handle, HTREEITEM item) |
3518 { | 3598 { |
3519 NSLog(@"dw_tree_item_delete() unimplemented\n"); | 3599 DWTree *tree = handle; |
3600 [tree deleteNode:item]; | |
3601 [tree reloadData]; | |
3520 } | 3602 } |
3521 | 3603 |
3522 /* | 3604 /* |
3523 * Create a container object to be packed. | 3605 * Create a container object to be packed. |
3524 * Parameters: | 3606 * Parameters: |