4 weeks ago
fix build (WINUI3)
/* * 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_CONTAINER_H #define UI_CONTAINER_H #include "toolkit.h" #ifdef __cplusplus extern "C" { #endif typedef enum UiSubContainerType { UI_CONTAINER_VBOX = 0, UI_CONTAINER_HBOX, UI_CONTAINER_GRID, UI_CONTAINER_NO_SUB } UiSubContainerType; typedef enum UiTabViewType { UI_TABVIEW_DEFAULT = 0, UI_TABVIEW_DOC, UI_TABVIEW_NAVIGATION_SIDE, UI_TABVIEW_NAVIGATION_TOP, UI_TABVIEW_NAVIGATION_TOP2, UI_TABVIEW_INVISIBLE } UiTabViewType; typedef enum UiHeaderbarAlternative { UI_HEADERBAR_ALTERNATIVE_DEFAULT = 0, UI_HEADERBAR_ALTERNATIVE_TOOLBAR, UI_HEADERBAR_ALTERNATIVE_BOX } UiHeaderbarAlternative; typedef struct UiWidgetArgs { UiTri fill; UiBool hexpand; UiBool vexpand; UiBool hfill; UiBool vfill; UiBool override_defaults; int colspan; int rowspan; const char *name; const char *style_class; } UiWidgetArgs; typedef struct UiContainerArgs { UiTri fill; UiBool hexpand; UiBool vexpand; UiBool hfill; UiBool vfill; UiBool override_defaults; int colspan; int rowspan; const char *name; const char *style_class; int margin; int spacing; int columnspacing; int rowspacing; UiBool def_hfill; UiBool def_vfill; UiBool def_hexpand; UiBool def_vexpand; } UiContainerArgs; typedef struct UiFrameArgs { UiTri fill; UiBool hexpand; UiBool vexpand; UiBool hfill; UiBool vfill; UiBool override_defaults; int colspan; int rowspan; const char *name; const char *style_class; UiSubContainerType subcontainer; int margin; int spacing; int columnspacing; int rowspacing; const char* label; UiBool isexpanded; } UiFrameArgs; typedef struct UiTabViewArgs { UiTri fill; UiBool hexpand; UiBool vexpand; UiBool hfill; UiBool vfill; UiBool override_defaults; int colspan; int rowspan; const char *name; const char *style_class; UiTabViewType tabview; UiSubContainerType subcontainer; UiInteger *value; const char* varname; int margin; int spacing; int columnspacing; int rowspacing; const char* label; UiBool isexpanded; } UiTabViewArgs; typedef struct UiHeaderbarArgs { UiTri fill; UiBool hexpand; UiBool vexpand; UiBool hfill; UiBool vfill; UiBool override_defaults; int colspan; int rowspan; const char *name; const char *style_class; UiBool showtitle; UiBool showwindowbuttons; UiHeaderbarAlternative alternative; int alt_spacing; } UiHeaderbarArgs; typedef struct UiSidebarArgs { const char *name; const char *style_class; int margin; int spacing; } UiSidebarArgs; typedef struct UiSplitPaneArgs { UiTri fill; UiBool hexpand; UiBool vexpand; UiBool hfill; UiBool vfill; UiBool override_defaults; int colspan; int rowspan; const char *name; const char *style_class; int margin; int spacing; int columnspacing; int rowspacing; int initial_position; UiInteger *value; const char* varname; int max_panes; } UiSplitPaneArgs; typedef struct UiItemListContainerArgs { UiTri fill; UiBool hexpand; UiBool vexpand; UiBool hfill; UiBool vfill; UiBool override_defaults; int colspan; int rowspan; const char *name; const char *style_class; int margin; int spacing; int sub_margin; int sub_spacing; int sub_columnspacing; int sub_rowspacing; UiList *value; const char *varname; /* * void create_ui(UiObject *obj, int index, void *elm, void *userdata) * * UI constructor for each list element * * This callback is executed for each list element. A new UiObject is * created for every item. */ void (*create_ui)(UiObject *, int, void *, void *); void *userdata; /* * ItemList container type * Only UI_CONTAINER_VBOX or UI_CONTAINER_HBOX are supported */ UiSubContainerType container; /* * item root container */ UiSubContainerType subcontainer; } UiItemListContainerArgs; struct UiContainerX { void *container; int close; UiContainerX *prev; UiContainerX *next; }; #define UI_CTN(obj, ctn) for(ctn;ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_vbox(obj, ...) for(ui_vbox_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_hbox(obj, ...) for(ui_hbox_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_grid(obj, ...) for(ui_grid_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_frame(obj, ...) for(ui_frame_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_expander(obj, ...) for(ui_expander_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_scrolledwindow(obj, ...) for(ui_scrolledwindow_create(obj, (UiFrameArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_tabview(obj, ...) for(ui_tabview_create(obj, (UiTabViewArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_headerbar(obj, ...) for(ui_headerbar_create(obj, (UiHeaderbarArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_sidebar(obj, ...) for(ui_sidebar_create(obj, (UiSidebarArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_vbox0(obj) for(ui_vbox_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_hbox0(obj) for(ui_hbox_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_grid0(obj) for(ui_grid_create(obj, (UiContainerArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_frame0(obj) for(ui_frame_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_expander0(obj) for(ui_expande_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_scrolledwindow0(obj) for(ui_scrolledwindow_create(obj, (UiFrameArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_tabview0(obj) for(ui_tabview_create(obj, (UiTabViewArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_headerbar0(obj) for(ui_headerbar_create(obj, (UiHeaderbarArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_sidebar0(obj) for(ui_sidebar_create(obj, (UiSidebarArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_tabview_w(obj, w, ...) for(w = ui_tabview_create(obj, (UiTabViewArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_hsplitpane(obj, ...) for(ui_hsplitpane_create(obj, (UiSplitPaneArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_vsplitpane(obj, ...) for(ui_vsplitpane_create(obj, (UiSplitPaneArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_hsplitpane0(obj) for(ui_hsplitpane_create(obj, (UiSplitPaneArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_vsplitpane0(obj) for(ui_vsplitpane_create(obj, (UiSplitPaneArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_tab(obj, label) for(ui_tab_create(obj, label);ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_headerbar_start(obj) for(ui_headerbar_start_create(obj);ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_headerbar_center(obj) for(ui_headerbar_center_create(obj);ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_headerbar_end(obj) for(ui_headerbar_end_create(obj);ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_itemlist(obj, ...) ui_itemlist_create(obj, (UiItemListContainerArgs) { __VA_ARGS__} ) UIEXPORT void ui_end(UiObject *obj); // deprecated UIEXPORT void ui_end_new(UiObject *obj); // TODO: rename to ui_end UIEXPORT UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs args); UIEXPORT UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args); UIEXPORT UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args); UIEXPORT UIWIDGET ui_frame_create(UiObject *obj, UiFrameArgs args); UIEXPORT UIWIDGET ui_expander_create(UiObject *obj, UiFrameArgs args); UIEXPORT UIWIDGET ui_scrolledwindow_create(UiObject *obj, UiFrameArgs args); UIEXPORT UIWIDGET ui_tabview_create(UiObject *obj, UiTabViewArgs args); UIEXPORT void ui_tab_create(UiObject *obj, const char* title); UIEXPORT void ui_tabview_select(UIWIDGET tabview, int tab); UIEXPORT void ui_tabview_remove(UIWIDGET tabview, int tab); UIEXPORT UiObject* ui_tabview_add(UIWIDGET tabview, const char *name, int tab_index); UIEXPORT UIWIDGET ui_headerbar_create(UiObject *obj, UiHeaderbarArgs args); UIEXPORT void ui_headerbar_start_create(UiObject *obj); UIEXPORT void ui_headerbar_center_create(UiObject *obj); UIEXPORT void ui_headerbar_end_create(UiObject *obj); UIEXPORT UIWIDGET ui_sidebar_create(UiObject *obj, UiSidebarArgs args); UIEXPORT UIWIDGET ui_itemlist_create(UiObject *obj, UiItemListContainerArgs args); UIEXPORT UIWIDGET ui_hsplitpane_create(UiObject *obj, UiSplitPaneArgs args); UIEXPORT UIWIDGET ui_vsplitpane_create(UiObject *obj, UiSplitPaneArgs args); // box container layout functions UIEXPORT void ui_layout_fill(UiObject *obj, UiBool fill); // grid container layout functions UIEXPORT void ui_layout_hexpand(UiObject *obj, UiBool expand); UIEXPORT void ui_layout_vexpand(UiObject *obj, UiBool expand); UIEXPORT void ui_layout_hfill(UiObject *obj, UiBool fill); UIEXPORT void ui_layout_vfill(UiObject *obj, UiBool fill); UIEXPORT void ui_layout_override_defaults(UiObject *obj, UiBool d); UIEXPORT void ui_layout_width(UiObject *obj, int width); UIEXPORT void ui_layout_height(UiObject* obj, int width); UIEXPORT void ui_layout_colspan(UiObject *obj, int cols); UIEXPORT void ui_layout_rowspan(UiObject* obj, int rows); UIEXPORT void ui_newline(UiObject *obj); // TODO UIEXPORT UiTabbedPane* ui_tabbed_document_view(UiObject *obj); UIEXPORT UiObject* ui_document_tab(UiTabbedPane *view); #ifdef UI_GTK typedef UIWIDGET (*ui_createwidget_func)(UiObject *obj, UiWidgetArgs args, void *userdata); #elif defined(UI_MOTIF) typedef UIWIDGET (*ui_createwidget_func)(UiObject *obj, UiWidgetArgs args, void *userdata, Widget parent, Arg *a, int n); #elif defined(UI_COCOA) typedef UIWIDGET (*ui_createwidget_func)(UiObject *obj, UiWidgetArgs args, void *userdata); #elif defined(UI_WINUI) typedef UIWIDGET(*ui_createwidget_func)(UiObject *obj, UiWidgetArgs args, void *userdata); #endif UIEXPORT UIWIDGET ui_customwidget_create(UiObject *obj, ui_createwidget_func create_widget, void *userdata, UiWidgetArgs args); #define ui_customwidget(obj, create_widget, userdata, ...) ui_customwidget_create(obj, create_widget, userdata, (UiWidgetArgs) { __VA_ARGS__ }) /* used for macro */ UIEXPORT void ui_container_begin_close(UiObject *obj); UIEXPORT int ui_container_finish(UiObject *obj); #define UI_APPLY_LAYOUT1(obj, args) \ if(args.fill != UI_DEFAULT) ui_layout_fill(obj, args.fill == UI_ON ? 1 : 0 ); \ if(args.hexpand) ui_layout_hexpand(obj, 1); \ if(args.vexpand) ui_layout_vexpand(obj, 1); \ if(args.hfill) ui_layout_hfill(obj, 1); \ if(args.vfill) ui_layout_vfill(obj, 1); \ if(args.override_defaults) ui_layout_override_defaults(obj, 1); \ if(args.colspan > 0) ui_layout_colspan(obj, args.colspan); \ if(args.rowspan > 0) ui_layout_rowspan(obj, args.rowspan); \ /*force caller to add ';'*/(void)0 #ifdef __cplusplus } #endif #endif /* UI_CONTAINER_H */