--- a/ui/gtk/menu.h Sun May 23 09:44:43 2021 +0200 +++ b/ui/gtk/menu.h Sat Jan 04 16:38:48 2025 +0100 @@ -30,89 +30,45 @@ #define MENU_H #include "../ui/menu.h" -#include <ucx/list.h> +#include "../common/menu.h" +#include <cx/list.h> #include "toolkit.h" + #ifdef __cplusplus extern "C" { #endif -typedef struct UiMenuItemI UiMenuItemI; -typedef struct UiMenu UiMenu; -typedef struct UiMenuItem UiMenuItem; -typedef struct UiStMenuItem UiStMenuItem; -typedef struct UiCheckItem UiCheckItem; -typedef struct UiCheckItemNV UiCheckItemNV; -typedef struct UiMenuItemList UiMenuItemList; +UIMENU ui_create_menu(UiMenuBuilder *builder, UiObject *obj); +void ui_widget_set_contextmenu(GtkWidget *widget, UIMENU menu); + +#if GTK_MAJOR_VERSION <= 3 typedef struct UiActiveMenuItemList UiActiveMenuItemList; -typedef GtkWidget*(*ui_menu_add_f)(GtkWidget *, int, UiMenuItemI*, UiObject*); - -struct UiMenuItemI { - ui_menu_add_f add_to; -}; - -struct UiMenu { - UiMenuItemI item; - char *label; - UcxList *items; - UiMenu *parent; -}; - -struct UiMenuItem { - UiMenuItemI item; - ui_callback callback; - char *label; - void *userdata; - UcxList *groups; -}; - -struct UiStMenuItem { - UiMenuItemI item; - ui_callback callback; - char *stockid; - void *userdata; - UcxList *groups; -}; - -struct UiCheckItem { - UiMenuItemI item; - char *label; - ui_callback callback; - void *userdata; -}; - -struct UiCheckItemNV { - UiMenuItemI item; - char *label; - char *varname; -}; - -struct UiMenuItemList { - UiMenuItemI item; - ui_callback callback; - void *userdata; - UiList *list; -}; +typedef void(*ui_menu_add_f)(GtkWidget *, int, UiMenuItemI*, UiObject*); struct UiActiveMenuItemList { - UiObject *object; - GtkMenuShell *menu; - int index; - int oldcount; - UiList *list; - ui_callback callback; - void *userdata; + UiObject *object; + GtkMenuShell *menu; + int index; + int oldcount; + UiList *list; + ui_getvaluefunc getvalue; + ui_callback callback; + void *userdata; }; GtkWidget *ui_create_menubar(UiObject *obj); +void ui_add_menu_items(GtkWidget *parent, int i, UiMenu *menu, UiObject *obj); + void add_menu_widget(GtkWidget *parent, int i, UiMenuItemI *item, UiObject *obj); void add_menuitem_widget(GtkWidget *parent, int i, UiMenuItemI *item, UiObject *obj); void add_menuitem_st_widget(GtkWidget *p, int i, UiMenuItemI *item, UiObject *obj); void add_menuseparator_widget(GtkWidget *p, int i, UiMenuItemI *item, UiObject *obj); void add_checkitem_widget(GtkWidget *p, int i, UiMenuItemI *item, UiObject *obj); +void add_radioitem_widget(GtkWidget *p, int index, UiMenuItemI *item, UiObject *obj); void add_checkitemnv_widget(GtkWidget *p, int i, UiMenuItemI *item, UiObject *obj); void add_menuitem_list_widget(GtkWidget *p, int i, UiMenuItemI *item, UiObject *obj); @@ -122,6 +78,41 @@ int64_t ui_checkitem_get(UiInteger *i); void ui_checkitem_set(UiInteger *i, int64_t value); +#endif /* GTK_MAJOR_VERSION <= 3 */ + +#if GTK_MAJOR_VERSION >= 4 + +typedef void(*ui_gmenu_add_f)(GMenu *, int, UiMenuItemI*, UiObject*); + +typedef struct UiActiveGMenuItemList UiActiveGMenuItemList; +struct UiActiveGMenuItemList { + UiObject *object; + GMenu *menu; + char action[32]; + int index; + int oldcount; + UiVar *var; + ui_getvaluefunc getvalue; + ui_callback callback; + void *userdata; +}; + +void ui_gmenu_add_menu_items(GMenu *parent, int i, UiMenu *menu, UiObject *obj); + +void ui_gmenu_add_menu(GMenu *parent, int index, UiMenuItemI *item, UiObject *obj); +void ui_gmenu_add_menuitem(GMenu *parent, int index, UiMenuItemI *item, UiObject *obj); +void ui_gmenu_add_menuseparator(GMenu *p, int index, UiMenuItemI *item, UiObject *obj); +void ui_gmenu_add_checkitem(GMenu *p, int index, UiMenuItemI *item, UiObject *obj); +void ui_gmenu_add_radioitem(GMenu *p, int index, UiMenuItemI *item, UiObject *obj); +void ui_gmenu_add_menuitem_list(GMenu *p, int index, UiMenuItemI *item, UiObject *obj); + +void ui_activate_event_wrapper(GSimpleAction* self, GVariant* parameter, UiEventData *event); +void ui_menu_list_item_activate_event_wrapper(GSimpleAction* self, GVariant* parameter, UiEventData *event); +void ui_update_gmenu_item_list(UiEvent *event, UiActiveGMenuItemList *list); + +#endif + + #ifdef __cplusplus } #endif