added list view (Cocoa)

Sat, 31 May 2014 11:08:34 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 31 May 2014 11:08:34 +0200
changeset 50
22b5adeb371f
parent 49
a80ba8741be6
child 51
42506e19eb6b

added list view (Cocoa)

ui/cocoa/tree.m file | annotate | diff | comparison | revisions
--- a/ui/cocoa/tree.m	Tue May 20 13:29:53 2014 +0200
+++ b/ui/cocoa/tree.m	Sat May 31 11:08:34 2014 +0200
@@ -133,6 +133,10 @@
     info->activate(&event, info->userdata);
 }
 
+- (BOOL)tableView:(NSTableView *)tableview isGroupRow:(NSInteger)row {
+    return NO;
+}
+
 @end
 
 
@@ -149,6 +153,7 @@
     NSTableView *tableview = [[NSTableView alloc]initWithFrame:frame];
     [scrollview setDocumentView:tableview];
     [tableview setAllowsMultipleSelection: YES];
+    //[tableview setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
     
     // add columns
     for(int i=0;i<modelinfo->columns;i++) {
@@ -174,6 +179,57 @@
 }
 
 
+UIWIDGET ui_listview_var(UiObject *obj, UiListPtr *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
+    UiContainer *ct = uic_get_current_container(obj);
+    NSRect frame = ct->getframe(ct);
+    
+    NSScrollView *scrollview = [[NSScrollView alloc] initWithFrame:frame];
+    [scrollview setHasVerticalScroller:YES];
+    
+    [scrollview setBorderType:NSNoBorder];
+    
+    NSTableView *tableview = [[NSTableView alloc]initWithFrame:frame];
+    [scrollview setDocumentView:tableview];
+    [tableview setAllowsMultipleSelection: NO];
+    
+    // add single column
+    NSTableColumn *column = [[NSTableColumn alloc]initWithIdentifier:@"c"];
+    [tableview addTableColumn:column];
+    
+    // create model info
+    UiModelInfo *modelinfo = ui_model_info(obj->ctx, UI_STRING, -1);
+    
+    // add source
+    UiTableDataSource *source = [[UiTableDataSource alloc]initWithData:list->list modelInfo:modelinfo];
+    
+    [tableview setDataSource:source];
+    [tableview setDelegate:source];
+
+    [tableview setDoubleAction:@selector(handleDoubleAction:)];
+    [tableview setTarget:source];
+    
+    ct->add(ct, scrollview);
+    return scrollview;
+}
+
+UIWIDGET ui_listview(UiObject *obj, UiList *list, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
+    UiListPtr *listptr = ucx_mempool_malloc(obj->ctx->mempool, sizeof(UiListPtr));
+    listptr->list = list;
+    return ui_listview_var(obj, listptr, getvalue, f, udata);
+}
+
+UIWIDGET ui_listview_nv(UiObject *obj, char *varname, ui_model_getvalue_f getvalue, ui_callback f, void *udata) {
+    UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_LIST);
+    if(var) {
+        UiListVar *value = var->value;
+        return ui_listview_var(obj, value->listptr, getvalue, f, udata);
+    } else {
+        // TODO: error
+    }
+    return NULL;
+}
+
+
 // TODO: motif code duplicate
 char* ui_type_to_string(UiModelType type, void *data, BOOL *free) {
     switch(type) {

mercurial