ui/cocoa/list.m

changeset 834
8801df33144f
parent 833
6cbc74aeff13
child 869
6b7a178cff7c
equal deleted inserted replaced
833:6cbc74aeff13 834:8801df33144f
488 CxIterator i = cxListIterator(_sublists); 488 CxIterator i = cxListIterator(_sublists);
489 int index = 0; 489 int index = 0;
490 int rownum = 0; 490 int rownum = 0;
491 cx_foreach(UiSubList *, sl, i) { 491 cx_foreach(UiSubList *, sl, i) {
492 UiSourceListItem *section = [[UiSourceListItem alloc] init:self sublist:sl]; 492 UiSourceListItem *section = [[UiSourceListItem alloc] init:self sublist:sl];
493 section.index = index; 493 section.sublistIndex = index;
494 section.rownum = rownum; 494 section.rownum = rownum;
495 section.sublistStartRow = rownum; 495 section.sublistStartRow = rownum;
496 [section update:-1]; 496 [section update:-1];
497 [_sections addObject:section]; 497 [_sections addObject:section];
498 index++; 498 index++;
514 } 514 }
515 } 515 }
516 516
517 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item { 517 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
518 UiSourceListItem *i = item; 518 UiSourceListItem *i = item;
519 return [i isSection]; 519 return [i isSection] ? YES : NO;
520 } 520 }
521 521
522 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item { 522 - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
523 UiSourceListItem *i = item; 523 UiSourceListItem *i = item;
524 if(i) { 524 if(i) {
599 599
600 return cell; 600 return cell;
601 } 601 }
602 602
603 - (NSTableRowView *) outlineView:(NSOutlineView *) outlineView 603 - (NSTableRowView *) outlineView:(NSOutlineView *) outlineView
604 rowViewForItem:(id) item { 604 rowViewForItem:(id)item {
605 UiSourceListItem *it = item;
605 UiSourceListRow *row = [[UiSourceListRow alloc]init]; 606 UiSourceListRow *row = [[UiSourceListRow alloc]init];
607 if([it isSection] && it.sublist->header) {
608 row.showDisclosureButton = YES;
609 }
606 return row; 610 return row;
607 } 611 }
608 612
609 - (BOOL) outlineView:(NSOutlineView *) outlineView 613 - (BOOL) outlineView:(NSOutlineView *) outlineView
610 shouldSelectItem:(id)item 614 shouldSelectItem:(id)item
617 heightOfRowByItem:(id) item 621 heightOfRowByItem:(id) item
618 { 622 {
619 UiSourceListItem *i = item; 623 UiSourceListItem *i = item;
620 CGFloat rowHeight = outlineView.rowHeight; 624 CGFloat rowHeight = outlineView.rowHeight;
621 if([i isSection]) { 625 if([i isSection]) {
622 if(i.index == 0) { 626 if(i.sublist->header) {
623 rowHeight -= 12; 627 rowHeight += i.sublistIndex == 0 ? -12 : 4;
624 } else { 628 } else {
625 rowHeight += 4; 629 rowHeight = i.sublistIndex == 0 ? 0.1 : 12;
626 } 630 }
627 } 631 }
628 return rowHeight; 632 return rowHeight;
629 } 633 }
630 634
646 UiSourceListItem *parent = item.parent; 650 UiSourceListItem *parent = item.parent;
647 UiSubList *sublist = parent != nil ? parent.sublist : item.sublist; 651 UiSubList *sublist = parent != nil ? parent.sublist : item.sublist;
648 UiVar *var = parent != nil ? parent.var : item.var; 652 UiVar *var = parent != nil ? parent.var : item.var;
649 if(item && var) { 653 if(item && var) {
650 sublistEvent.list = var->value; 654 sublistEvent.list = var->value;
651 sublistEvent.sublist_index = parent ? parent.index : item.index; 655 sublistEvent.sublist_index = parent ? parent.sublistIndex : item.sublistIndex;
652 sublistEvent.row_index = (int)selectedRow - item.sublistStartRow - 1; 656 sublistEvent.row_index = (int)selectedRow - item.sublistStartRow - 1;
653 sublistEvent.sublist_userdata = sublist ? sublist->userdata : NULL; 657 sublistEvent.sublist_userdata = sublist ? sublist->userdata : NULL;
654 sublistEvent.event_data = item.eventdata; 658 sublistEvent.event_data = item.eventdata;
655 sublistEvent.row_data = sublistEvent.list->get(sublistEvent.list, sublistEvent.row_index); 659 sublistEvent.row_data = sublistEvent.list->get(sublistEvent.list, sublistEvent.row_index);
656 660
676 _sourcelist = sourcelist; 680 _sourcelist = sourcelist;
677 _sublist = sublist; 681 _sublist = sublist;
678 _items = [[NSMutableArray alloc]initWithCapacity:16]; 682 _items = [[NSMutableArray alloc]initWithCapacity:16];
679 if(sublist->header) { 683 if(sublist->header) {
680 _label = [[NSString alloc]initWithUTF8String:sublist->header]; 684 _label = [[NSString alloc]initWithUTF8String:sublist->header];
685 } else {
686 _label = @"";
681 } 687 }
682 UiVar *var = uic_widget_var(sourcelist.obj->ctx, 688 UiVar *var = uic_widget_var(sourcelist.obj->ctx,
683 sourcelist.obj->ctx, 689 sourcelist.obj->ctx,
684 sublist->value, 690 sublist->value,
685 sublist->varname, 691 sublist->varname,
690 696
691 - (id)init:(UiSubListItem*)item parent:(UiSourceListItem*)parent { 697 - (id)init:(UiSubListItem*)item parent:(UiSourceListItem*)parent {
692 _parent = parent; 698 _parent = parent;
693 if(item->label) { 699 if(item->label) {
694 _label = [[NSString alloc]initWithUTF8String:item->label]; 700 _label = [[NSString alloc]initWithUTF8String:item->label];
701 } else {
702 _label = @"";
695 } 703 }
696 _eventdata = item->eventdata; 704 _eventdata = item->eventdata;
697 return self; 705 return self;
698 } 706 }
699 707
718 } else { 726 } else {
719 item.label = strdup(elm); 727 item.label = strdup(elm);
720 } 728 }
721 729
722 UiSourceListItem *it = [[UiSourceListItem alloc] init:&item parent:self]; 730 UiSourceListItem *it = [[UiSourceListItem alloc] init:&item parent:self];
723 it.index = index; 731 it.sublistIndex = index;
724 it.rownum = self.rownum + index; 732 it.rownum = self.rownum + index;
725 it.sublistStartRow = _parent ? _parent.sublistStartRow : _sublistStartRow; 733 it.sublistStartRow = _parent ? _parent.sublistStartRow : _sublistStartRow;
726 [_items addObject:it]; 734 [_items addObject:it];
727 735
728 elm = list->next(list); 736 elm = list->next(list);
786 [self addTrackingArea:_trackingArea]; 794 [self addTrackingArea:_trackingArea];
787 } 795 }
788 796
789 - (void)mouseEntered:(NSEvent *)event { 797 - (void)mouseEntered:(NSEvent *)event {
790 _hover = YES; 798 _hover = YES;
791 _disclosureButton.hidden = NO; 799 _disclosureButton.hidden = _showDisclosureButton ? NO : YES;
792 } 800 }
793 801
794 - (void)mouseExited:(NSEvent *)event { 802 - (void)mouseExited:(NSEvent *)event {
795 _hover = NO; 803 _hover = NO;
796 _disclosureButton.hidden = YES; 804 _disclosureButton.hidden = YES;

mercurial