UNIXworkcode

1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2017 Olaf Wintermann. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef CONTAINER_H 30 #define CONTAINER_H 31 32 #include "../ui/toolkit.h" 33 #include "../ui/container.h" 34 #include <string.h> 35 36 #include <cx/allocator.h> 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #define ui_reset_layout(layout) memset(&(layout), 0, sizeof(UiLayout)) 43 #define ui_lb2bool(b) ((b) == UI_LAYOUT_TRUE ? TRUE : FALSE) 44 #define ui_bool2lb(b) ((b) ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE) 45 46 typedef void (*ui_container_add_f)(UiContainer*, GtkWidget*, UiBool); 47 48 typedef struct UiDocumentView UiDocumentView; 49 50 typedef struct UiLayout UiLayout; 51 typedef enum UiLayoutBool UiLayoutBool; 52 53 enum UiLayoutBool { 54 UI_LAYOUT_UNDEFINED = 0, 55 UI_LAYOUT_TRUE, 56 UI_LAYOUT_FALSE, 57 }; 58 59 struct UiLayout { 60 UiLayoutBool fill; 61 UiBool newline; 62 char *label; 63 UiBool hexpand; 64 UiBool vexpand; 65 UiBool hfill; 66 UiBool vfill; 67 int width; 68 int colspan; 69 int rowspan; 70 }; 71 72 struct UiContainer { 73 GtkWidget *widget; 74 UIMENU menu; 75 GtkWidget *current; 76 77 void (*add)(UiContainer*, GtkWidget*, UiBool); 78 UiLayout layout; 79 80 int close; 81 }; 82 83 typedef struct UiBoxContainer { 84 UiContainer container; 85 UiSubContainerType type; 86 UiBool has_fill; 87 } UiBoxContainer; 88 89 typedef struct UiGridContainer { 90 UiContainer container; 91 int x; 92 int y; 93 #ifdef UI_GTK2 94 int width; 95 int height; 96 #endif 97 } UiGridContainer; 98 99 /* 100 typedef struct UiPanedContainer { 101 UiContainer container; 102 GtkWidget *current_pane; 103 int orientation; 104 int max; 105 int cur; 106 } UiPanedContainer; 107 */ 108 109 typedef struct UiTabViewContainer { 110 UiContainer container; 111 } UiTabViewContainer; 112 113 typedef void (*ui_select_tab_func)(UIWIDGET widget, int tab); 114 typedef void (*ui_add_tab_func)(UIWIDGET widget, int index, const char *name, UIWIDGET child); 115 116 typedef struct UiGtkTabView { 117 UiObject *obj; 118 GtkWidget *widget; 119 ui_select_tab_func select_tab; 120 ui_select_tab_func remove_tab; 121 ui_add_tab_func add_tab; 122 UiSubContainerType subcontainer; 123 int margin; 124 int spacing; 125 int columnspacing; 126 int rowspacing; 127 } UiGtkTabView; 128 129 typedef struct UiHeaderbarContainer { 130 UiContainer container; 131 GtkWidget *centerbox; 132 int part; 133 UiHeaderbarAlternative alternative; /* only used by fallback headerbar */ 134 } UiHeaderbarContainer; 135 136 GtkWidget* ui_gtk_vbox_new(int spacing); 137 GtkWidget* ui_gtk_hbox_new(int spacing); 138 139 GtkWidget* ui_subcontainer_create( 140 UiSubContainerType type, 141 UiObject *newobj, 142 int spacing, 143 int columnspacing, 144 int rowspacing, 145 int margin); 146 147 UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame); 148 void ui_frame_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); 149 150 GtkWidget* ui_box_set_margin(GtkWidget *box, int margin); 151 UIWIDGET ui_box_create(UiObject *obj, UiContainerArgs args, UiSubContainerType type); 152 153 UiContainer* ui_box_container(UiObject *obj, GtkWidget *box, UiSubContainerType type); 154 void ui_box_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); 155 156 GtkWidget* ui_create_grid_widget(int colspacing, int rowspacing); 157 UiContainer* ui_grid_container(UiObject *obj, GtkWidget *grid); 158 void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); 159 160 UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame); 161 void ui_frame_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); 162 163 UiContainer* ui_expander_container(UiObject *obj, GtkWidget *expander); 164 void ui_expander_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); 165 166 UiContainer* ui_scrolledwindow_container(UiObject *obj, GtkWidget *scrolledwindow); 167 void ui_scrolledwindow_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); 168 169 UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview); 170 void ui_tabview_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); 171 172 void ui_paned_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); 173 174 void ui_split_container_add1(UiContainer *ct, GtkWidget *widget, UiBool fill); 175 void ui_split_container_add2(UiContainer *ct, GtkWidget *widget, UiBool fill); 176 177 UiGtkTabView* ui_widget_get_tabview_data(UIWIDGET tabview); 178 179 void ui_gtk_notebook_select_tab(GtkWidget *widget, int tab); 180 181 #if GTK_CHECK_VERSION(3, 10, 0) 182 UiContainer* ui_headerbar_container(UiObject *obj, GtkWidget *headerbar); 183 void ui_headerbar_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); 184 #endif 185 186 UiContainer* ui_headerbar_fallback_container(UiObject *obj, GtkWidget *headerbar); 187 void ui_headerbar_fallback_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); 188 189 #ifdef __cplusplus 190 } 191 #endif 192 193 #endif /* CONTAINER_H */ 194 195