Tue, 26 Nov 2024 10:40:45 +0100
add context menu, implement 'Select All'
/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2017 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 UI_MENU_H #define UI_MENU_H #include "toolkit.h" #ifdef __cplusplus extern "C" { #endif typedef struct UiMenuItemArgs { const char* label; const char* stockid; const char* icon; ui_callback onclick; void* onclickdata; const int* groups; } UiMenuItemArgs; typedef struct UiMenuToggleItemArgs { const char* label; const char* stockid; const char* icon; const char* varname; ui_callback onchange; void* onchangedata; const int* groups; } UiMenuToggleItemArgs; typedef struct UiMenuItemListArgs { const char* varname; ui_getvaluefunc getvalue; ui_callback onselect; void* onselectdata; } UiMenuItemListArgs; #define ui_menu(label) for(ui_menu_create(label);ui_menu_is_open();ui_menu_close()) #define ui_menuitem(...) ui_menuitem_create((UiMenuItemArgs){ __VA_ARGS__ }) #define ui_menu_toggleitem(...) ui_menu_toggleitem_create((UiMenuToggleItemArgs){ __VA_ARGS__ }) #define ui_menu_radioitem(...) ui_menu_radioitem_create((UiMenuToggleItemArgs){ __VA_ARGS__ }) #define ui_menu_itemlist(...) ui_menu_itemlist_create((UiMenuItemListArgs) { __VA_ARGS__ } ) #define ui_menu_togglelist(...) ui_menu_itemlist_create((UiMenuItemListArgs) { __VA_ARGS} ) #define ui_menu_radiolist(...) ui_menu_itemlist_create((UiMenuItemListArgs) { __VA_ARGS} ) UIEXPORT void ui_menu_create(const char* label); UIEXPORT void ui_menuitem_create(UiMenuItemArgs args); UIEXPORT void ui_menu_toggleitem_create(UiMenuToggleItemArgs args); UIEXPORT void ui_menu_radioitem_create(UiMenuToggleItemArgs args); UIEXPORT void ui_menuseparator(); UIEXPORT void ui_menu_itemlist_create(UiMenuItemListArgs args); UIEXPORT void ui_menu_toggleitemlist_create(UiMenuItemListArgs args); UIEXPORT void ui_menu_radioitemlist_create(UiMenuItemListArgs args); UIEXPORT void ui_menu_end(void); // TODO: private /* * widget menu functions */ #define ui_contextmenu(builder) for(ui_contextmenu_builder(builder);ui_menu_is_open();ui_menu_close()) UIEXPORT void ui_contextmenu_builder(UiMenuBuilder **out_builder); UIEXPORT void ui_menubuilder_free(UiMenuBuilder *builder); UIEXPORT UIMENU ui_contextmenu_create(UiMenuBuilder *builder, UiObject *obj, UIWIDGET widget); UIEXPORT void ui_contextmenu_popup(UIMENU menu, UIWIDGET widget, int x, int y); // used for macro UIEXPORT void ui_menu_close(void); UIEXPORT int ui_menu_is_open(void); #ifdef __cplusplus } #endif #endif /* UI_MENU_H */