fixes stultus commit

Sat, 17 Sep 2016 19:57:55 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 17 Sep 2016 19:57:55 +0200
changeset 129
5babf09f5f19
parent 128
c284c15509a8
child 130
212b63dd61be

fixes stultus commit

ui/cocoa/menu.m file | annotate | diff | comparison | revisions
ui/cocoa/objs.mk file | annotate | diff | comparison | revisions
ui/cocoa/toolbar.h file | annotate | diff | comparison | revisions
ui/cocoa/toolbar.m file | annotate | diff | comparison | revisions
ui/cocoa/window.m file | annotate | diff | comparison | revisions
ui/gtk/model.c file | annotate | diff | comparison | revisions
ui/gtk/tree.c file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
ui/ui/tree.h file | annotate | diff | comparison | revisions
--- a/ui/cocoa/menu.m	Sat Sep 17 19:32:44 2016 +0200
+++ b/ui/cocoa/menu.m	Sat Sep 17 19:57:55 2016 +0200
@@ -118,7 +118,10 @@
 @end
 
 
-static NSMenu *currentMenu = NULL;
+//static NSMenu *currentMenu = NULL;
+
+static UcxList *current;
+
 static int currentItemIndex = 0;
 static UiMenuDelegate *delegate;
 
@@ -141,8 +144,34 @@
     [menu setAutoenablesItems:NO];
     
     [[NSApp mainMenu] setSubmenu:menu forItem:menuItem];
-    currentMenu = menu;
+    //currentMenu = menu;
     currentItemIndex = 0;
+    
+    current = ucx_list_prepend(NULL, menu);
+}
+
+void ui_submenu(char *title) {
+    NSString *str = [[NSString alloc] initWithUTF8String:title];
+    NSMenu *currentMenu = current->data;
+    
+    NSMenu *menu = [[NSMenu alloc] initWithTitle: str];
+    NSMenuItem *menuItem = [currentMenu addItemWithTitle:str
+                                                       action:nil keyEquivalent:@""];
+    [menu setDelegate: delegate];
+    [menu setAutoenablesItems:NO];
+    
+    [currentMenu setSubmenu:menu forItem:menuItem];
+    //currentMenu = menu;
+    currentItemIndex = 0;
+    
+    current = ucx_list_prepend(current, menu);
+}
+
+void ui_submenu_end() {
+    if(ucx_list_size(current) < 2) {
+        return;
+    }
+    current = ucx_list_remove(current, current);
 }
 
 void ui_menuitem(char *label, ui_callback f, void *data) {
@@ -169,6 +198,7 @@
     }
     va_end(ap);
     
+    NSMenu *currentMenu = current->data;
     [currentMenu addItem:item];
     
     currentItemIndex++;
@@ -192,6 +222,7 @@
     }
     va_end(ap);
     
+    NSMenu *currentMenu = current->data;
     [currentMenu addItem:item];
     
     currentItemIndex++;
@@ -201,6 +232,7 @@
     EventWrapper *event = [[EventWrapper alloc]initWithData:data callback:f];
     NSString *str = [[NSString alloc] initWithUTF8String:label];
     
+    NSMenu *currentMenu = current->data;
     NSMenuItem *item = [currentMenu addItemWithTitle:str
                                               action:@selector(handleStateEvent:) keyEquivalent:@""];
     [item setTarget:event];
@@ -213,6 +245,7 @@
     EventWrapper *event = [[EventWrapper alloc]initWithData:NULL callback:NULL];
     NSString *str = [[NSString alloc] initWithUTF8String:label];
     
+    NSMenu *currentMenu = current->data;
     NSMenuItem *item = [currentMenu addItemWithTitle:str
                                               action:@selector(handleStateEvent:) keyEquivalent:@""];
     [item setTarget:event];
@@ -222,11 +255,13 @@
 }
 
 void ui_menuseparator() {
+    NSMenu *currentMenu = current->data;
     [currentMenu addItem: [NSMenuItem separatorItem]];
     currentItemIndex++;
 }
 
 void ui_menuitem_list (UiList *items, ui_callback f, void *data) {
+    NSMenu *currentMenu = current->data;
     [delegate addList:items menu:currentMenu index:currentItemIndex callback:f data:data];
 }
 
--- a/ui/cocoa/objs.mk	Sat Sep 17 19:32:44 2016 +0200
+++ b/ui/cocoa/objs.mk	Sat Sep 17 19:57:55 2016 +0200
@@ -38,6 +38,7 @@
 COCOAOBJ += text.o
 COCOAOBJ += resource.o
 COCOAOBJ += tree.o
+COCOAOBJ += graphics.o
 
 
 TOOLKITOBJS += $(COCOAOBJ:%=$(COCOA_OBJPRE)%)
--- a/ui/cocoa/toolbar.h	Sat Sep 17 19:32:44 2016 +0200
+++ b/ui/cocoa/toolbar.h	Sat Sep 17 19:57:55 2016 +0200
@@ -67,6 +67,32 @@
 
 @end
 
+/*
+ * UiToolbarItem
+ *
+ * toolbar item with label and icon
+ */
+@interface UiToolbarItem : NSObject <UiToolItem> {
+    char           *name;
+    char           *label;
+    // icon
+    ui_callback    callback;
+    void           *userdata;
+    UcxList        *groups;
+    BOOL           isToggleButton;
+}
+
+- (UiToolbarItem*) initWithIdentifier:(char*)identifier
+                                     label:(char*)lbl
+                                  callback:(ui_callback)f
+                                  userdata:(void*)data;
+
+- (void) setIsToggleButton:(BOOL)t;
+
+
+@end
+
+
 
 /*
  * UiToolbarDelegate
--- a/ui/cocoa/toolbar.m	Sat Sep 17 19:32:44 2016 +0200
+++ b/ui/cocoa/toolbar.m	Sat Sep 17 19:57:55 2016 +0200
@@ -122,6 +122,83 @@
 @end
 
 
+/* ---------------------      UiToolbarItem     --------------------- */
+
+@implementation UiToolbarItem
+
+- (UiToolbarItem*) initWithIdentifier:(char*)identifier
+                                     label:(char*)lbl
+                                  callback:(ui_callback)f
+                                  userdata:(void*)data
+{
+    name = identifier;
+    label = lbl;
+    callback = f;
+    userdata = data;
+    groups = NULL;
+    isToggleButton = NO;
+    return self;
+}
+
+- (void) setIsToggleButton:(BOOL)t {
+    isToggleButton = t;
+}
+
+- (void) addGroup:(int)group {
+    groups = ucx_list_append(groups, (void*)(intptr_t)group);
+}
+
+
+- (NSToolbarItem *) createItem:(NSToolbar*)toolbar
+                    identifier:(NSString*)identifier
+                        object:(UiObject*)obj
+{
+    NSToolbarItem *item = [[[NSToolbarItem alloc] initWithItemIdentifier:
+                            identifier] autorelease];
+    //[item setLabel:[s label]];
+    //[item setPaletteLabel:[s label]];
+    NSString *l = [[NSString alloc]initWithUTF8String:label];
+    [item setLabel:l];
+    [item setPaletteLabel:@"Operation"];
+    
+    // create button ...
+    NSRect frame = NSMakeRect(0, 0, 40, 22);
+    //NSSearchField *sf = [[NSSearchField alloc]initWithFrame:frame];
+    NSButton *button = [[NSButton alloc]initWithFrame:frame];
+    //[button setImage:[s buttonImage]];
+    //[button setImage:[NSImage imageNamed: NSImageNameAddTemplate]];
+    
+    // TODO: image
+    [button setImage:[NSImage imageNamed: NSImageNameRemoveTemplate]];
+    
+    [button setBezelStyle: NSTexturedRoundedBezelStyle];
+    
+    // event
+    EventWrapper *event = [[EventWrapper alloc]
+                           initWithData:userdata callback:callback];
+    if(isToggleButton) {
+        [button setButtonType: NSPushOnPushOffButton];
+        [button setAction:@selector(handleToggleEvent:)];
+    } else {
+        [button setAction:@selector(handleEvent:)];
+    }
+    [button setTarget:event];
+    
+    if(groups) {
+        uic_add_group_widget(obj->ctx, item, groups);
+    }
+    
+    [item setView:button];
+    return item;
+}
+
+- (UcxList*) groups {
+    return groups;
+}
+
+@end
+
+
 /* ---------------------      UiToolbarDelegate      --------------------- */
 
 @implementation UiToolbarDelegate
@@ -215,6 +292,17 @@
     toolbar_delegate = [[UiToolbarDelegate alloc]init];
 }
 
+void ui_toolitem(char *name, char *label, ui_callback f, void *udata) {
+    UiToolbarItem *item = [[UiToolbarItem alloc]
+                                initWithIdentifier: name
+                                label: label
+                                callback: f
+                                userdata: udata];
+    
+    NSString *identifier = [[NSString alloc]initWithUTF8String:name];
+    [toolbar_delegate addItem: identifier item: item];
+}
+
 void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *udata) {
     ui_toolitem_stgr(name, stockid, f, udata, -1);
 }
--- a/ui/cocoa/window.m	Sat Sep 17 19:32:44 2016 +0200
+++ b/ui/cocoa/window.m	Sat Sep 17 19:57:55 2016 +0200
@@ -186,7 +186,6 @@
     
     obj->widget = (NSView*)window;
     obj->window = window_data;
-    obj->document = NULL;
     obj->container = ui_window_container(obj, window);
     
     
--- a/ui/gtk/model.c	Sat Sep 17 19:32:44 2016 +0200
+++ b/ui/gtk/model.c	Sat Sep 17 19:57:55 2016 +0200
@@ -105,14 +105,14 @@
     return G_TYPE_INVALID;
 }
 
-static void ui_model_set_value(UiModelType type, void *data, GValue *value) {
+static void ui_model_set_value(GType type, void *data, GValue *value) {
     switch(type) {
-        case UI_STRING: {
+        case G_TYPE_STRING: {
             value->g_type = G_TYPE_STRING;
             g_value_set_string(value, data);
             return;
         }
-        case UI_INTEGER: {
+        case G_TYPE_INT: {
             value->g_type = G_TYPE_INT;
             int *i = data;
             g_value_set_int(value, *i);
@@ -126,11 +126,20 @@
     UiListModel *model = g_object_new(list_model_type, NULL);
     model->info = info;
     model->list = list;
-    model->columntypes = malloc(sizeof(GType));
-    model->numcolumns = info->columns;
+    model->columntypes = calloc(sizeof(GType), 2 * info->columns);
+    int ncol = 0;
     for(int i=0;i<info->columns;i++) {
-        model->columntypes[i] = ui_gtk_type(info->types[i]);
+        UiModelType type = info->types[i];
+        if(type == UI_ICON_TEXT) {
+            model->columntypes[ncol] = G_TYPE_STRING;
+            ncol++;
+            model->columntypes[ncol] = G_TYPE_STRING;
+        } else {
+            model->columntypes[ncol] = ui_gtk_type(info->types[i]);
+        }
+        ncol++;
     }
+    model->numcolumns = ncol;
     return model;
 }
 
@@ -237,7 +246,7 @@
     //list->current = iter->user_data3;
     if(model->info->getvalue) {
         void *data = model->info->getvalue(iter->user_data3, column);
-        ui_model_set_value(model->info->types[column], data, value);
+        ui_model_set_value(model->columntypes[column], data, value);
     } else {
         value->g_type = G_TYPE_INVALID;
     }
--- a/ui/gtk/tree.c	Sat Sep 17 19:32:44 2016 +0200
+++ b/ui/gtk/tree.c	Sat Sep 17 19:57:55 2016 +0200
@@ -134,14 +134,33 @@
 UIWIDGET ui_table_var(UiObject *obj, UiListPtr *list, UiModelInfo *modelinfo) {
     // create treeview
     GtkWidget *view = gtk_tree_view_new();
+    int addi = 0;
     for(int i=0;i<modelinfo->columns;i++) {
-        GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
-        GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(
+        GtkTreeViewColumn *column = NULL;
+        if(modelinfo->types[i] == UI_ICON_TEXT) {
+            column = gtk_tree_view_column_new();
+            gtk_tree_view_column_set_title(column, modelinfo->titles[i]);
+            
+            GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new();
+            GtkCellRenderer *textrenderer = gtk_cell_renderer_text_new();
+            
+            gtk_tree_view_column_pack_end(column, textrenderer, TRUE);
+            gtk_tree_view_column_pack_start(column, iconrenderer, FALSE);
+            
+            
+            gtk_tree_view_column_add_attribute(column, iconrenderer, "icon-name", i);
+            gtk_tree_view_column_add_attribute(column, textrenderer, "text", i+1);
+            
+            addi++;
+        } else {
+            GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
+            column = gtk_tree_view_column_new_with_attributes(
                 modelinfo->titles[i],
                 renderer,
                 "text",
-                i,
+                i + addi,
                 NULL);
+        }
         gtk_tree_view_column_set_resizable(column, TRUE);
         gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
     }
@@ -233,8 +252,7 @@
 
 void ui_listview_update(UiEvent *event, UiTableView *view) {
     UiListModel *model = ui_list_model_new(view->list, view->modelinfo);
-    gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), NULL);
-    gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(model));
+    gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(model));   
     
     // TODO: free old model
 }
--- a/ui/ui/toolkit.h	Sat Sep 17 19:32:44 2016 +0200
+++ b/ui/ui/toolkit.h	Sat Sep 17 19:57:55 2016 +0200
@@ -34,8 +34,10 @@
 #ifdef __OBJC__
 #import <Cocoa/Cocoa.h>
 #define UIWIDGET NSView*
+#define UIMENU   NSMenu*
 #else
 typedef void* UIWIDGET;
+typedef void* UIMENU;
 #endif
 
 #elif UI_GTK2 || UI_GTK3
--- a/ui/ui/tree.h	Sat Sep 17 19:32:44 2016 +0200
+++ b/ui/ui/tree.h	Sat Sep 17 19:57:55 2016 +0200
@@ -41,7 +41,9 @@
 
 typedef enum UiModelType {
     UI_STRING = 0,
-    UI_INTEGER
+    UI_INTEGER,
+    UI_ICON,
+    UI_ICON_TEXT,
 } UiModelType;
 
 struct UiModelInfo {

mercurial