ui/cocoa/ListDelegate.m

changeset 712
9693f447a0c7
parent 711
673e7e41c93e
equal deleted inserted replaced
711:673e7e41c93e 712:9693f447a0c7
28 28
29 #import "ListDelegate.h" 29 #import "ListDelegate.h"
30 30
31 @implementation ListDelegate 31 @implementation ListDelegate
32 32
33 - (id)init:(UiObject*)obj { 33 - (id)init:(NSTableView*) tableview obj:(UiObject*)obj {
34 _tableview = tableview;
34 _obj = obj; 35 _obj = obj;
35 return self; 36 return self;
36 } 37 }
37 38
38 - (void)activateEvent:(id)sender { 39 - (void)activateEvent:(id)sender {
55 56
56 _onactivate(&event, _onactivatedata); 57 _onactivate(&event, _onactivatedata);
57 } 58 }
58 } 59 }
59 60
61 - (void) tableViewSelectionDidChange:(NSNotification *) notification {
62 if(_onselection) {
63 UiListSelection sel = ui_tableview_selection(_tableview);
64
65 UiEvent event;
66 event.obj = _obj;
67 event.window = event.obj->window;
68 event.document = event.obj->ctx->document;
69 event.eventdata = &sel;
70 event.eventdatatype = UI_EVENT_DATA_LIST_SELECTION;
71 event.intval = 0;
72 event.set = ui_get_setop();
73
74 _onselection(&event, _onselectiondata);
75 }
76 }
77
60 @end 78 @end
79
80 UiListSelection ui_tableview_selection(NSTableView *tableview) {
81 NSIndexSet *indexSet = tableview.selectedRowIndexes;
82 NSUInteger count = [indexSet count];
83
84 if(count == 0) {
85 return (UiListSelection){0, NULL};
86 }
87
88 int *rows = calloc(count, sizeof(int));
89
90 __block NSUInteger i = 0;
91 [indexSet enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) {
92 rows[i++] = (int)index;
93 }];
94
95 UiListSelection sel;
96 sel.count = (int)count;
97 sel.rows = rows;
98 return sel;
99 }

mercurial