ui/cocoa/list.m

changeset 832
7adbd6b7bf7c
parent 831
32a4415dc69a
child 833
6cbc74aeff13
equal deleted inserted replaced
831:32a4415dc69a 832:7adbd6b7bf7c
405 405
406 UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs *args) { 406 UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs *args) {
407 // create views 407 // create views
408 NSScrollView *scrollview = [[NSScrollView alloc] init]; 408 NSScrollView *scrollview = [[NSScrollView alloc] init];
409 scrollview.autoresizingMask = NSViewWidthSizable; 409 scrollview.autoresizingMask = NSViewWidthSizable;
410 scrollview.hasVerticalScroller = YES;
411 scrollview.hasHorizontalScroller = NO;
412 scrollview.autohidesScrollers = YES;
410 413
411 NSOutlineView *outline = [[NSOutlineView alloc]init]; 414 NSOutlineView *outline = [[NSOutlineView alloc]init];
412 NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"label"]; 415 NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"label"];
413 [outline addTableColumn:column]; 416 [outline addTableColumn:column];
414 outline.outlineTableColumn = column; 417 outline.outlineTableColumn = column;
416 outline.rowSizeStyle = NSTableViewRowSizeStyleDefault; 419 outline.rowSizeStyle = NSTableViewRowSizeStyleDefault;
417 outline.usesAutomaticRowHeights = YES; 420 outline.usesAutomaticRowHeights = YES;
418 outline.indentationPerLevel = 0; 421 outline.indentationPerLevel = 0;
419 422
420 outline.style = NSTableViewStyleSourceList; 423 outline.style = NSTableViewStyleSourceList;
421 outline.selectionHighlightStyle = NSTableViewSelectionHighlightStyleSourceList;
422 424
423 // Make background transparent so vibrancy shows through 425 // Make background transparent so vibrancy shows through
424 //outline.backgroundColor = [NSColor clearColor]; 426 //outline.backgroundColor = [NSColor clearColor];
425 scrollview.drawsBackground = NO; 427 scrollview.drawsBackground = NO;
426 428
461 UiSourceList *sourcelist = (__bridge UiSourceList*)list->obj; 463 UiSourceList *sourcelist = (__bridge UiSourceList*)list->obj;
462 [sourcelist update:row]; 464 [sourcelist update:row];
463 } 465 }
464 466
465 467
468 /*
469 * Data Source and Delegate for the sourcelist NSOutlineView
470 */
466 @implementation UiSourceList 471 @implementation UiSourceList
467 472
468 - (id)init:(UiObject*)obj outline:(NSOutlineView*)view { 473 - (id)init:(UiObject*)obj outline:(NSOutlineView*)view {
469 _obj = obj; 474 _obj = obj;
470 _outlineView = view; 475 _outlineView = view;
515 UiSourceListItem *i = item; 520 UiSourceListItem *i = item;
516 if(i) { 521 if(i) {
517 return [i.items objectAtIndex:index]; 522 return [i.items objectAtIndex:index];
518 } 523 }
519 return [_sections objectAtIndex:index]; 524 return [_sections objectAtIndex:index];
520 }
521
522 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
523 /*
524 UiSourceListItem *i = item;
525 if([[tableColumn identifier] isEqualToString:@"label"]) {
526 return i.label;
527 }
528 */
529 return nil;
530 } 525 }
531 526
532 - (void)outlineView:(NSOutlineView *)outlineView 527 - (void)outlineView:(NSOutlineView *)outlineView
533 setObjectValue:(id)object 528 setObjectValue:(id)object
534 forTableColumn:(NSTableColumn *)tableColumn 529 forTableColumn:(NSTableColumn *)tableColumn
661 } 656 }
662 } 657 }
663 658
664 @end 659 @end
665 660
661 /*
662 * Outline datasource item
663 * Is used for sections (sublists) and individual items
664 */
666 @implementation UiSourceListItem 665 @implementation UiSourceListItem
667 666
668 - (id)init:(UiSourceList*)sourcelist sublist:(UiSubList*)sublist { 667 - (id)init:(UiSourceList*)sourcelist sublist:(UiSubList*)sublist {
669 _sourcelist = sourcelist; 668 _sourcelist = sourcelist;
670 _sublist = sublist; 669 _sublist = sublist;
692 - (BOOL)isSection { 691 - (BOOL)isSection {
693 return _sublist != NULL; 692 return _sublist != NULL;
694 } 693 }
695 694
696 - (void)update:(int)row { 695 - (void)update:(int)row {
696 // TODO: check row
697
697 [_items removeAllObjects]; 698 [_items removeAllObjects];
698 if(_var == NULL) { 699 if(_var == NULL) {
699 return; 700 return;
700 } 701 }
701 UiList *list = _var->value; 702 UiList *list = _var->value;
716 } 717 }
717 } 718 }
718 719
719 @end 720 @end
720 721
722 /*
723 * Custom NSTableRowView implementation
724 * Moves the disclosure button to the right side
725 * Handles mouse hover events (for hiding the disclosure button)
726 */
721 @implementation UiSourceListRow 727 @implementation UiSourceListRow
722 728
723 - (void)layout { 729 - (void)layout {
724 [super layout]; 730 [super layout];
725 731

mercurial