ui/cocoa/tree.m

changeset 50
22b5adeb371f
parent 47
97792f44d919
child 157
0b33b9396851
equal deleted inserted replaced
49:a80ba8741be6 50:22b5adeb371f
131 event.intval = lastSelection->count == 0 ? -1 : lastSelection->rows[0]; 131 event.intval = lastSelection->count == 0 ? -1 : lastSelection->rows[0];
132 132
133 info->activate(&event, info->userdata); 133 info->activate(&event, info->userdata);
134 } 134 }
135 135
136 - (BOOL)tableView:(NSTableView *)tableview isGroupRow:(NSInteger)row {
137 return NO;
138 }
139
136 @end 140 @end
137 141
138 142
139 UIWIDGET ui_table(UiObject *obj, UiList *model, UiModelInfo *modelinfo) { 143 UIWIDGET ui_table(UiObject *obj, UiList *model, UiModelInfo *modelinfo) {
140 UiContainer *ct = uic_get_current_container(obj); 144 UiContainer *ct = uic_get_current_container(obj);
147 //[scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable]; 151 //[scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
148 152
149 NSTableView *tableview = [[NSTableView alloc]initWithFrame:frame]; 153 NSTableView *tableview = [[NSTableView alloc]initWithFrame:frame];
150 [scrollview setDocumentView:tableview]; 154 [scrollview setDocumentView:tableview];
151 [tableview setAllowsMultipleSelection: YES]; 155 [tableview setAllowsMultipleSelection: YES];
156 //[tableview setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
152 157
153 // add columns 158 // add columns
154 for(int i=0;i<modelinfo->columns;i++) { 159 for(int i=0;i<modelinfo->columns;i++) {
155 NSString *cid = [[NSString alloc]initWithFormat: @"%d", i]; 160 NSString *cid = [[NSString alloc]initWithFormat: @"%d", i];
156 NSTableColumn *column = [[NSTableColumn alloc]initWithIdentifier:cid]; 161 NSTableColumn *column = [[NSTableColumn alloc]initWithIdentifier:cid];
169 [tableview setTarget:source]; 174 [tableview setTarget:source];
170 175
171 176
172 ct->add(ct, scrollview); 177 ct->add(ct, scrollview);
173 return scrollview; 178 return scrollview;
179 }
180
181
182 UIWIDGET ui_listview_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
183 UiContainer *ct = uic_get_current_container(obj);
184 NSRect frame = ct->getframe(ct);
185
186 NSScrollView *scrollview = [[NSScrollView alloc] initWithFrame:frame];
187 [scrollview setHasVerticalScroller:YES];
188
189 [scrollview setBorderType:NSNoBorder];
190
191 NSTableView *tableview = [[NSTableView alloc]initWithFrame:frame];
192 [scrollview setDocumentView:tableview];
193 [tableview setAllowsMultipleSelection: NO];
194
195 // add single column
196 NSTableColumn *column = [[NSTableColumn alloc]initWithIdentifier:@"c"];
197 [tableview addTableColumn:column];
198
199 // create model info
200 UiModelInfo *modelinfo = ui_model_info(obj->ctx, UI_STRING, -1);
201
202 // add source
203 UiTableDataSource *source = [[UiTableDataSource alloc]initWithData:list->list modelInfo:modelinfo];
204
205 [tableview setDataSource:source];
206 [tableview setDelegate:source];
207
208 [tableview setDoubleAction:@selector(handleDoubleAction:)];
209 [tableview setTarget:source];
210
211 ct->add(ct, scrollview);
212 return scrollview;
213 }
214
215 UIWIDGET ui_listview(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
216 UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr));
217 listptr->list = list;
218 return ui_listview_var(obj, listptr, getvalue, f, udata);
219 }
220
221 UIWIDGET ui_listview_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
222 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST);
223 if(var) {
224 UiListVar *value = var->value;
225 return ui_listview_var(obj, value->listptr, getvalue, f, udata);
226 } else {
227 // TODO: error
228 }
229 return NULL;
174 } 230 }
175 231
176 232
177 // TODO: motif code duplicate 233 // TODO: motif code duplicate
178 char* ui_type_to_string(UiModelType type, void *data, BOOL *free) { 234 char* ui_type_to_string(UiModelType type, void *data, BOOL *free) {

mercurial