# HG changeset patch # User Olaf Wintermann # Date 1707686220 -3600 # Node ID 13997c76859b1ea85efb46782bb3fd306f9950e3 # Parent 087cc9216f28673001721fb271d7901a11b13bf1 fix some const related warnings diff -r 087cc9216f28 -r 13997c76859b ui/common/menu.c --- a/ui/common/menu.c Sun Feb 11 22:06:23 2024 +0100 +++ b/ui/common/menu.c Sun Feb 11 22:17:00 2024 +0100 @@ -61,7 +61,7 @@ return s ? strdup(s) : NULL; } -static int* copy_groups(int* groups, size_t *ngroups) { +static int* copy_groups(const int* groups, size_t *ngroups) { *ngroups = 0; if (!groups) { return NULL; diff -r 087cc9216f28 -r 13997c76859b ui/common/menu.h --- a/ui/common/menu.h Sun Feb 11 22:06:23 2024 +0100 +++ b/ui/common/menu.h Sun Feb 11 22:17:00 2024 +0100 @@ -65,7 +65,7 @@ struct UiMenu { UiMenuItemI item; - char *label; + const char *label; UiMenuItemI *items_begin; UiMenuItemI *items_end; UiMenu *parent; diff -r 087cc9216f28 -r 13997c76859b ui/common/objs.mk --- a/ui/common/objs.mk Sun Feb 11 22:06:23 2024 +0100 +++ b/ui/common/objs.mk Sun Feb 11 22:17:00 2024 +0100 @@ -35,6 +35,8 @@ COMMON_OBJ += types.o COMMON_OBJ += menu.o COMMON_OBJ += properties.o +COMMON_OBJ += menu.o +COMMON_OBJ += toolbar.o COMMON_OBJ += ucx_properties.o TOOLKITOBJS += $(COMMON_OBJ:%=$(COMMON_OBJPRE)%) diff -r 087cc9216f28 -r 13997c76859b ui/common/properties.c --- a/ui/common/properties.c Sun Feb 11 22:06:23 2024 +0100 +++ b/ui/common/properties.c Sun Feb 11 22:17:00 2024 +0100 @@ -57,7 +57,7 @@ } char* ui_configfile(char *name) { - char *appname = ui_appname(); + const char *appname = ui_appname(); if(!appname) { return NULL; } diff -r 087cc9216f28 -r 13997c76859b ui/common/toolbar.c --- a/ui/common/toolbar.c Sun Feb 11 22:06:23 2024 +0100 +++ b/ui/common/toolbar.c Sun Feb 11 22:17:00 2024 +0100 @@ -37,108 +37,108 @@ static UiToolbarMenuItem* ui_appmenu; void uic_toolbar_init(void) { - toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); - toolbar_defaults[0] = cxLinkedListCreateSimple(CX_STORE_POINTERS); - toolbar_defaults[1] = cxLinkedListCreateSimple(CX_STORE_POINTERS); - toolbar_defaults[2] = cxLinkedListCreateSimple(CX_STORE_POINTERS); + toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); + toolbar_defaults[0] = cxLinkedListCreateSimple(CX_STORE_POINTERS); + toolbar_defaults[1] = cxLinkedListCreateSimple(CX_STORE_POINTERS); + toolbar_defaults[2] = cxLinkedListCreateSimple(CX_STORE_POINTERS); } -static char* nl_strdup(char* str) { - return str ? strdup(str) : NULL; +static char* nl_strdup(const char* str) { + return str ? strdup(str) : NULL; } static UiToolbarItemArgs itemargs_copy(UiToolbarItemArgs args) { - UiToolbarItemArgs newargs; - newargs.label = nl_strdup(args.label); - newargs.stockid = nl_strdup(args.stockid); - newargs.icon = nl_strdup(args.icon); - newargs.onclick = args.onclick; - newargs.onclickdata = args.onclickdata; - return newargs; + UiToolbarItemArgs newargs; + newargs.label = nl_strdup(args.label); + newargs.stockid = nl_strdup(args.stockid); + newargs.icon = nl_strdup(args.icon); + newargs.onclick = args.onclick; + newargs.onclickdata = args.onclickdata; + return newargs; } void ui_toolbar_item_create(const char* name, UiToolbarItemArgs args) { - UiToolbarItem* item = malloc(sizeof(UiToolbarItem)); - item->item.type = UI_TOOLBAR_ITEM; - item->args = itemargs_copy(args); - cxMapPut(toolbar_items, name, item); + UiToolbarItem* item = malloc(sizeof(UiToolbarItem)); + item->item.type = UI_TOOLBAR_ITEM; + item->args = itemargs_copy(args); + cxMapPut(toolbar_items, name, item); } static UiToolbarToggleItemArgs toggleitemargs_copy(UiToolbarToggleItemArgs args) { - UiToolbarToggleItemArgs newargs; - newargs.label = nl_strdup(args.label); - newargs.stockid = nl_strdup(args.stockid); - newargs.icon = nl_strdup(args.icon); - newargs.varname = nl_strdup(args.varname); - newargs.onchange = args.onchange; - newargs.onchangedata = args.onchangedata; - return newargs; + UiToolbarToggleItemArgs newargs; + newargs.label = nl_strdup(args.label); + newargs.stockid = nl_strdup(args.stockid); + newargs.icon = nl_strdup(args.icon); + newargs.varname = nl_strdup(args.varname); + newargs.onchange = args.onchange; + newargs.onchangedata = args.onchangedata; + return newargs; } void ui_toolbar_toggleitem_create(const char* name, UiToolbarToggleItemArgs args) { - UiToolbarToggleItem* item = malloc(sizeof(UiToolbarToggleItem)); - item->item.type = UI_TOOLBAR_TOGGLEITEM; - item->args = toggleitemargs_copy(args); - cxMapPut(toolbar_items, name, item); + UiToolbarToggleItem* item = malloc(sizeof(UiToolbarToggleItem)); + item->item.type = UI_TOOLBAR_TOGGLEITEM; + item->args = toggleitemargs_copy(args); + cxMapPut(toolbar_items, name, item); } static UiToolbarMenuArgs menuargs_copy(UiToolbarMenuArgs args) { - UiToolbarMenuArgs newargs; - newargs.label = nl_strdup(args.label); - newargs.stockid = nl_strdup(args.stockid); - newargs.icon = nl_strdup(args.icon); - return newargs; + UiToolbarMenuArgs newargs; + newargs.label = nl_strdup(args.label); + newargs.stockid = nl_strdup(args.stockid); + newargs.icon = nl_strdup(args.icon); + return newargs; } UIEXPORT void ui_toolbar_menu_create(const char* name, UiToolbarMenuArgs args) { - UiToolbarMenuItem* item = malloc(sizeof(UiToolbarMenuItem)); - item->item.type = UI_TOOLBAR_MENU; - memset(&item->menu, 0, sizeof(UiMenu)); - item->args = menuargs_copy(args); - - item->end = 0; + UiToolbarMenuItem* item = malloc(sizeof(UiToolbarMenuItem)); + item->item.type = UI_TOOLBAR_MENU; + memset(&item->menu, 0, sizeof(UiMenu)); + item->args = menuargs_copy(args); + + item->end = 0; - if (!name) { - // special appmenu - ui_appmenu = item; - } else { - // toplevel menu - cxMapPut(toolbar_items, name, item); - } + if (!name) { + // special appmenu + ui_appmenu = item; + } else { + // toplevel menu + cxMapPut(toolbar_items, name, item); + } - uic_add_menu_to_stack(&item->menu); + uic_add_menu_to_stack(&item->menu); } CxMap* uic_get_toolbar_items(void) { - return toolbar_items; + return toolbar_items; } CxList* uic_get_toolbar_defaults(enum UiToolbarPos pos) { - if (pos >= 0 && pos < 3) { - return toolbar_defaults[pos]; - } + if (pos >= 0 && pos < 3) { + return toolbar_defaults[pos]; + } + return NULL; } void ui_toolbar_add_default(const char* name, enum UiToolbarPos pos) { - char* cp = strdup(name); - if (pos >= 0 && pos < 3) { - cxListAdd(toolbar_defaults[pos], cp); - } - else { - // TODO: error - } + char* cp = strdup(name); + if (pos >= 0 && pos < 3) { + cxListAdd(toolbar_defaults[pos], cp); + } else { + // TODO: error + } } UiBool uic_toolbar_isenabled(void) { - return toolbar_defaults[0]->size + toolbar_defaults[1]->size + toolbar_defaults[2]->size > 0; + return toolbar_defaults[0]->size + toolbar_defaults[1]->size + toolbar_defaults[2]->size > 0; } UiToolbarItemI* uic_toolbar_get_item(const char* name) { - return cxMapGet(toolbar_items, name); + return cxMapGet(toolbar_items, name); } UiToolbarMenuItem* uic_get_appmenu(void) { - return ui_appmenu; + return ui_appmenu; } diff -r 087cc9216f28 -r 13997c76859b ui/gtk/toolbar.c --- a/ui/gtk/toolbar.c Sun Feb 11 22:06:23 2024 +0100 +++ b/ui/gtk/toolbar.c Sun Feb 11 22:17:00 2024 +0100 @@ -221,11 +221,6 @@ } -void ui_toolbar_add_default(const char *name, enum UiToolbarPos pos) { - char *s = strdup(name); - cxListAdd(defaults, s); -} - GtkWidget* ui_create_toolbar(UiObject *obj) { if(!defaults) { return NULL; diff -r 087cc9216f28 -r 13997c76859b ui/gtk/window.c --- a/ui/gtk/window.c Sun Feb 11 22:06:23 2024 +0100 +++ b/ui/gtk/window.c Sun Feb 11 22:17:00 2024 +0100 @@ -33,6 +33,8 @@ #include "../ui/window.h" #include "../ui/properties.h" #include "../common/context.h" +#include "../common/menu.h" +#include "../common/toolbar.h" #include @@ -110,15 +112,19 @@ if(!simple) { // menu - GtkWidget *mb = ui_create_menubar(obj); - if(mb) { - gtk_box_pack_start(GTK_BOX(vbox), mb, FALSE, FALSE, 0); + if(uic_get_menu_list()) { + GtkWidget *mb = ui_create_menubar(obj); + if(mb) { + gtk_box_pack_start(GTK_BOX(vbox), mb, FALSE, FALSE, 0); + } } // toolbar - GtkWidget *tb = ui_create_toolbar(obj); - if(tb) { - gtk_box_pack_start(GTK_BOX(vbox), tb, FALSE, FALSE, 0); + if(uic_toolbar_isenabled()) { + GtkWidget *tb = ui_create_toolbar(obj); + if(tb) { + gtk_box_pack_start(GTK_BOX(vbox), tb, FALSE, FALSE, 0); + } } }