]> uap-core.de Git - note.git/commitdiff
replace gtk specific icon names with enum values main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 2 Jun 2026 16:25:30 +0000 (18:25 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 2 Jun 2026 16:25:30 +0000 (18:25 +0200)
13 files changed:
application/src/main.rs
ui-rs/src/ui/icon.rs [new file with mode: 0644]
ui-rs/src/ui/mod.rs
ui/cocoa/ListDelegate.m
ui/cocoa/list.m
ui/common/icons.c [new file with mode: 0644]
ui/common/icons.h [new file with mode: 0644]
ui/common/objs.mk
ui/common/wrapper.c
ui/common/wrapper.h
ui/gtk/icon.c
ui/gtk/list.c
ui/ui/icons.h

index 563e6b33ee7eb4c31101d15d89b50f13feaf8ea9..97aa3dda54f59a1edc425ebf5aaaf32db75f45c4 100644 (file)
@@ -122,10 +122,10 @@ impl Application<MainWindow> for App {
 }
 
 fn create_toolbar(app: &AppContext<MainWindow>) {
-    app.toolbar_item("new_notebook").icon("folder-new").action("new_notebook").create();
-    app.toolbar_item("go_back").icon("go-previous").action("go_back").create();
-    app.toolbar_item("go_forward").icon("go-next").action("go_forward").create();
-    app.toolbar_item("new_note").icon("document-new").action("new_note").create();
+    app.toolbar_item("new_notebook").icon(UiIconSet::NewFolder.as_str()).action("new_notebook").create();
+    app.toolbar_item("go_back").icon(UiIconSet::GoBack.as_str()).action("go_back").create();
+    app.toolbar_item("go_forward").icon(UiIconSet::GoForward.as_str()).action("go_forward").create();
+    app.toolbar_item("new_note").icon(UiIconSet::Add.as_str()).action("new_note").create();
 
     app.toolbar_add_default("new_notebook", ToolbarItemPosition::SidebarRight);
     app.toolbar_add_default("go_back", ToolbarItemPosition::Left);
diff --git a/ui-rs/src/ui/icon.rs b/ui-rs/src/ui/icon.rs
new file mode 100644 (file)
index 0000000..d4d4cca
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2026 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+use std::ffi::{c_char, CStr};
+use std::fmt::{Display, Formatter};
+
+#[repr(i32)]
+#[derive(Copy, Clone)]
+pub enum UiIconSet {
+    Home = 0,
+    NewWindow,
+    Refresh,
+    NewFolder,
+    Add,
+    Upload,
+    SaveLocal,
+    Delete,
+    DockLeft,
+    DockRight,
+    GoBack,
+    GoForward,
+    GoUp,
+    GoDown
+}
+
+impl UiIconSet {
+    pub fn as_str(self) -> &'static str {
+        let ptr = unsafe { ui_icon_name(self as i32) };
+        let cstr = unsafe { CStr::from_ptr(ptr) };
+        cstr.to_str().expect("ui_icon_name returned invalid UTF-8")
+    }
+}
+
+extern "C" {
+    fn ui_icon_name(id: i32) ->  *const c_char ;
+}
\ No newline at end of file
index 13bcf84552d01a1acd3ceaa3640b96a5a2273ef3..dd968c40ae76a129091fe3539275dc33d881d7cb 100644 (file)
@@ -39,6 +39,7 @@ pub mod list;
 mod menu;
 mod toolbar;
 mod label;
+mod icon;
 
 pub use toolkit::*;
 pub use event::*;
@@ -50,3 +51,4 @@ pub use text::*;
 pub use list::*;
 pub use toolbar::*;
 pub use menu::*;
+pub use icon::*;
index 9d80a7abc3112f455463e187be9df82394cd2bce..db8ab84329f262fccdcaf10ad633a6d65b0832bf 100644 (file)
@@ -70,7 +70,6 @@
         event.eventdatatype = UI_EVENT_DATA_LIST_SELECTION;
         event.intval = 0;
         event.set = ui_get_setop();
-        
         _onselection(&event, _onselectiondata);
     }
 }
index 97e9e4e8471395e54a316d4d316ddb807352874c..c3c45040a982b9988eec72c9c6e853f592b58f61 100644 (file)
@@ -468,7 +468,7 @@ UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs *args) {
     data.onactivate = args->onactivate;
     data.onactivatedata = args->onactivatedata;
     data.onbuttonclick = args->onbuttonclick;
-    data.onactivatedata = args->onbuttonclickdata;
+    data.onbuttonclickdata = args->onbuttonclickdata;
     [data update:-1];
  
     outline.dataSource = data;
@@ -508,18 +508,37 @@ void ui_sourcelist_update(UiList *list, int row) {
     
     [_sections removeAllObjects];
     
-    CxIterator i = cxListIterator(_sublists);
-    int index = 0;
-    int rownum = 0;
-    cx_foreach(UiSubList *, sl, i) {
-        UiSourceListItem *section = [[UiSourceListItem alloc] init:self sublist:sl];
-        section.sublistIndex = index;
-        section.rownum = rownum;
-        section.sublistStartRow = rownum;
-        [section update:-1];
-        [_sections addObject:section];
-        index++;
-        rownum += 1 + section.items.count;
+    if(_sublists) {
+        CxIterator i = cxListIterator(_sublists);
+        int index = 0;
+        int rownum = 0;
+        cx_foreach(UiSubList *, sl, i) {
+            UiSourceListItem *section = [[UiSourceListItem alloc] init:self sublist:sl];
+            section.sublistIndex = index;
+            section.rownum = rownum;
+            section.sublistStartRow = rownum;
+            [section update:-1];
+            [_sections addObject:section];
+            index++;
+            rownum += 1 + section.items.count;
+        }
+    } else if (_dynamic_sublists) {
+        UiList *sublists = _dynamic_sublists->value;
+        UiSubList *sl = sublists->first(sublists);
+        int index = 0;
+        int rownum = 0;
+        while(sl) {
+            UiSourceListItem *section = [[UiSourceListItem alloc] init:self sublist:sl];
+            section.sublistIndex = index;
+            section.rownum = rownum;
+            section.sublistStartRow = rownum;
+            [section update:-1];
+            [_sections addObject:section];
+            index++;
+            rownum += 1 + section.items.count;
+            
+            sl = sublists->next(sublists);
+        }
     }
     
     [_outlineView reloadData];
diff --git a/ui/common/icons.c b/ui/common/icons.c
new file mode 100644 (file)
index 0000000..26f6049
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2026 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "icons.h"
+
+const char* ui_icon_name(enum UiIconId icon_id) {
+    switch(icon_id) {
+        case UI_ICON_ID_HOME        : return UI_ICON_HOME;
+        case UI_ICON_ID_NEW_WINDOW  : return UI_ICON_NEW_WINDOW;
+        case UI_ICON_ID_REFRESH     : return UI_ICON_REFRESH;
+        case UI_ICON_ID_NEW_FOLDER  : return UI_ICON_NEW_FOLDER;
+        case UI_ICON_ID_ADD         : return UI_ICON_ADD;
+        case UI_ICON_ID_UPLOAD      : return UI_ICON_UPLOAD;
+        case UI_ICON_ID_SAVE_LOCAL  : return UI_ICON_SAVE_LOCAL;
+        case UI_ICON_ID_DELETE      : return UI_ICON_DELETE;
+        case UI_ICON_ID_DOCK_LEFT   : return UI_ICON_DOCK_LEFT;
+        case UI_ICON_ID_DOCK_RIGHT  : return UI_ICON_DOCK_RIGHT;
+        case UI_ICON_ID_GO_BACK     : return UI_ICON_GO_BACK;
+        case UI_ICON_ID_GO_FORWARD  : return UI_ICON_GO_FORWARD;
+        case UI_ICON_ID_GO_UP       : return UI_ICON_GO_UP;
+        case UI_ICON_ID_GO_DOWN     : return UI_ICON_GO_DOWN;
+    }
+    return NULL;
+}
diff --git a/ui/common/icons.h b/ui/common/icons.h
new file mode 100644 (file)
index 0000000..d7062a6
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2026 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UIC_ICONS_H
+#define UIC_ICONS_H
+
+#include "../ui/icons.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* UIC_ICONS_H */
+
index 2ce73a5d7e14c3b2e7e5abc78d358fa80db7010e..35fb9d6d28255f2706c28bf13fbc1c2b1ae86014 100644 (file)
@@ -45,6 +45,7 @@ COMMON_OBJ += args$(OBJ_EXT)
 COMMON_OBJ += wrapper$(OBJ_EXT)
 COMMON_OBJ += utils$(OBJ_EXT)
 COMMON_OBJ += message$(OBJ_EXT)
+COMMON_OBJ += icons$(OBJ_EXT)
 
 TOOLKITOBJS += $(COMMON_OBJ:%=$(COMMON_OBJPRE)uic_%)
 TOOLKITSOURCE += $(COMMON_OBJ:%$(OBJ_EXT)=common/%.c)
index f9184251cbd9a20fcf1a1afc6d9561c3ff9e159b..675c6882854f37ed097e943e7513abbb6ba945ee 100644 (file)
@@ -71,6 +71,14 @@ void ui_mainthread_document_unref(void *doc) {
     ui_call_mainthread(doc_unref, doc);
 }
 
+static int app_unref(void *unused) {
+    ui_app_unref();
+    return 0;
+}
+
+void ui_mainthread_app_unref() {
+    ui_call_mainthread(app_unref, NULL);
+}
 
 /* ---------------------------- UiList ---------------------------- */
 
index 42d49ac6f5ede24af29a88ce7631176641879614..eff32825120bacf6e4b649a31bf450db6502836e 100644 (file)
@@ -44,6 +44,7 @@ UIEXPORT void ui_object_set_onclose(UiObject *obj, ui_callback callback, void *u
 
 UIEXPORT void ui_mainthread_object_unref(UiObject *obj);
 UIEXPORT void ui_mainthread_document_unref(void *doc);
+UIEXPORT void ui_mainthread_app_unref();
 
 UIEXPORT void* ui_list_get_data(UiList *list);
 UIEXPORT void* ui_list_get_iter(UiList *list);
index 16568eed5028fc013aa6f8c1b9287c60a1d740b1..1dfd52fcaa62b27c296683b088b9b3c0f7474bdb 100644 (file)
@@ -123,6 +123,8 @@ UiIcon* ui_fileicon(size_t size) {
     char *path = g_file_get_path(file);
     if(!path) {
         icon = ui_icon("application-x-generic", size);
+    } else {
+        g_free(path);
     }
 #else
     if(!icon) {
@@ -143,6 +145,7 @@ GdkPixbuf* ui_icon_pixbuf(UiIcon *icon) {
         GError *error = NULL;
         char *path = g_file_get_path(file);
         icon->pixbuf = gdk_pixbuf_new_from_file(path, &error);
+        g_free(path);
     }
     return icon->pixbuf;
 }
index 3ae0b656733c08ed04d0488a34d55627d207a3af..fd686718dbb5b4e06cf0d823bbdb8de3d76ced38 100644 (file)
@@ -260,7 +260,7 @@ static void column_factory_setup(GtkListItemFactory *factory, GtkListItem *item,
     } else if(type == UI_BOOL_EDITABLE) {
         GtkWidget *checkbox = gtk_check_button_new();
         gtk_list_item_set_child(item, checkbox);
-    }else {
+    } else {
         GtkWidget *label = gtk_label_new(NULL);
         gtk_label_set_xalign(GTK_LABEL(label), 0);
         gtk_list_item_set_child(item, label);
@@ -351,6 +351,7 @@ static void column_factory_bind(GtkListItemFactory *unused, GtkListItem *item, g
         }
         case UI_STRING: {
             gtk_label_set_label(GTK_LABEL(child), data);
+            gtk_label_set_ellipsize(GTK_LABEL(child), PANGO_ELLIPSIZE_END);
             if(freevalue) {
                 free(data);
             }
index 6589cc9a2ddc68e7edc700d285290c269834f82f..07feff60835d77e3c9ac9e3fe57bfb6e5c2ae5a5 100644 (file)
@@ -54,7 +54,24 @@ extern "C" {
     
 #endif /* UI_GTK */
     
+#ifdef UI_QT
     
+#define UI_ICON_HOME "go-home"
+#define UI_ICON_NEW_WINDOW "list-add"
+#define UI_ICON_REFRESH "view-refresh"
+#define UI_ICON_NEW_FOLDER "folder-new"
+#define UI_ICON_ADD "document-new"
+#define UI_ICON_UPLOAD "document-open"
+#define UI_ICON_SAVE_LOCAL "document-save-as"
+#define UI_ICON_DELETE "edit-delete"
+#define UI_ICON_DOCK_LEFT ""
+#define UI_ICON_DOCK_RIGHT ""
+#define UI_ICON_GO_BACK "go-previous"
+#define UI_ICON_GO_FORWARD "go-next"
+#define UI_ICON_GO_UP "go-up"
+#define UI_ICON_GO_DOWN "go-down"
+    
+#endif /* UI_QT */
 
 #ifdef UI_WINUI
     
@@ -94,6 +111,61 @@ extern "C" {
 
 #endif /* UI_COCOA */
     
+#ifdef UI_MOTIF
+    
+#define UI_ICON_HOME ""
+#define UI_ICON_NEW_WINDOW ""
+#define UI_ICON_REFRESH ""
+#define UI_ICON_NEW_FOLDER ""
+#define UI_ICON_ADD ""
+#define UI_ICON_UPLOAD ""
+#define UI_ICON_SAVE_LOCAL ""
+#define UI_ICON_DELETE ""
+#define UI_ICON_DOCK_LEFT ""
+#define UI_ICON_DOCK_RIGHT ""
+#define UI_ICON_GO_BACK ""
+#define UI_ICON_GO_FORWARD ""
+#define UI_ICON_GO_UP ""
+#define UI_ICON_GO_DOWN "" 
+    
+#endif /* UI_MOTIF */
+    
+#ifdef UI_WIN32
+    
+#define UI_ICON_HOME ""
+#define UI_ICON_NEW_WINDOW ""
+#define UI_ICON_REFRESH ""
+#define UI_ICON_NEW_FOLDER ""
+#define UI_ICON_ADD ""
+#define UI_ICON_UPLOAD ""
+#define UI_ICON_SAVE_LOCAL ""
+#define UI_ICON_DELETE ""
+#define UI_ICON_DOCK_LEFT ""
+#define UI_ICON_DOCK_RIGHT ""
+#define UI_ICON_GO_BACK ""
+#define UI_ICON_GO_FORWARD ""
+#define UI_ICON_GO_UP ""
+#define UI_ICON_GO_DOWN "" 
+    
+#endif /* UI_MOTIF */
+    
+    
+enum UiIconId {
+    UI_ICON_ID_HOME = 0,
+    UI_ICON_ID_NEW_WINDOW,
+    UI_ICON_ID_REFRESH,
+    UI_ICON_ID_NEW_FOLDER,
+    UI_ICON_ID_ADD,
+    UI_ICON_ID_UPLOAD,
+    UI_ICON_ID_SAVE_LOCAL,
+    UI_ICON_ID_DELETE,
+    UI_ICON_ID_DOCK_LEFT,
+    UI_ICON_ID_DOCK_RIGHT,
+    UI_ICON_ID_GO_BACK,
+    UI_ICON_ID_GO_FORWARD,
+    UI_ICON_ID_GO_UP,
+    UI_ICON_ID_GO_DOWN
+};
     
 UIEXPORT UiIcon* ui_icon(const char* name, size_t size);
 UIEXPORT UiIcon* ui_icon_unscaled(const char *name, int size);
@@ -104,6 +176,8 @@ UIEXPORT UiIcon* ui_foldericon(size_t size);
 UIEXPORT UiIcon* ui_fileicon(size_t size);
 
 
+UIEXPORT const char* ui_icon_name(enum UiIconId icon_id);
+
 #ifdef __cplusplus
 }
 #endif