# HG changeset patch # User Olaf Wintermann # Date 1420480027 -3600 # Node ID 4697592e24ba0a76530d90d1ccc813c2fe315c15 # Parent 6ef2c7f73a30adee260e3d5fae7191c3fddacf9d added label, grid container, simple tabview and textfield (Gtk) diff -r 6ef2c7f73a30 -r 4697592e24ba ui/gtk/button.c --- a/ui/gtk/button.c Mon Jan 05 14:47:19 2015 +0100 +++ b/ui/gtk/button.c Mon Jan 05 18:47:07 2015 +0100 @@ -39,9 +39,10 @@ GtkWidget *button = gtk_button_new_with_label(label); if(f) { - UiEventData *event = ucx_mempool_malloc( - obj->ctx->mempool, - sizeof(UiEventData)); + //UiEventData *event = ucx_mempool_malloc( + // obj->ctx->mempool, + // sizeof(UiEventData)); + UiEventData *event = malloc(sizeof(UiEventData)); event->obj = obj; event->userdata = data; event->callback = f; diff -r 6ef2c7f73a30 -r 4697592e24ba ui/gtk/container.c --- a/ui/gtk/container.c Mon Jan 05 14:47:19 2015 +0100 +++ b/ui/gtk/container.c Mon Jan 05 18:47:07 2015 +0100 @@ -105,6 +105,49 @@ ui_reset_layout(ct->layout); } +UiContainer* ui_grid_container(UiObject *obj, GtkWidget *grid) { + UiGridContainer *ct = ucx_mempool_calloc( + obj->ctx->mempool, + 1, + sizeof(UiGridContainer)); + ct->container.widget = grid; + ct->container.add = ui_grid_container_add; + return (UiContainer*)ct; +} + +void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { + UiGridContainer *grid = (UiGridContainer*)ct; + + if(ct->layout.newline) { + grid->x = 0; + grid->y++; + ct->layout.newline = FALSE; + } + + gtk_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, 1, 1); + grid->x++; + + ui_reset_layout(ct->layout); +} + +UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview) { + UiTabViewContainer *ct = ucx_mempool_calloc( + obj->ctx->mempool, + 1, + sizeof(UiTabViewContainer)); + ct->container.widget = tabview; + ct->container.add = ui_tabview_container_add; + return (UiContainer*)ct; +} + +void ui_tabview_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { + gtk_notebook_append_page( + GTK_NOTEBOOK(ct->widget), + widget, + gtk_label_new(ct->layout.label)); +} + + UIWIDGET ui_vbox(UiObject *obj) { UiContainer *ct = uic_get_current_container(obj); @@ -131,6 +174,44 @@ return hbox; } +UIWIDGET ui_grid(UiObject *obj) { + UiContainer *ct = uic_get_current_container(obj); + + GtkWidget *grid = gtk_grid_new(); + ct->add(ct, grid, TRUE); + + UiObject *newobj = uic_object_new(obj, grid); + newobj->container = ui_grid_container(obj, grid); + uic_obj_add(obj, newobj); + + return grid; +} + +UIWIDGET ui_tabview(UiObject *obj) { + GtkWidget *tabview = gtk_notebook_new(); + gtk_notebook_set_show_border(GTK_NOTEBOOK(tabview), FALSE); + gtk_notebook_set_show_tabs(GTK_NOTEBOOK(tabview), FALSE); + + UiContainer *ct = uic_get_current_container(obj); + ct->add(ct, tabview, TRUE); + + UiObject *tabviewobj = uic_object_new(obj, tabview); + tabviewobj->container = ui_tabview_container(obj, tabview); + uic_obj_add(obj, tabviewobj); + + return tabview; +} + +void ui_tab(UiObject *obj, char *title) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.label = title; + ui_vbox(obj); +} + +void ui_select_tab(UIWIDGET tabview, int tab) { + gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab); +} + /* -------------------- Sidebar -------------------- */ UIWIDGET ui_sidebar(UiObject *obj) { @@ -256,3 +337,8 @@ UiContainer *ct = uic_get_current_container(obj); ct->layout.fill = ui_bool2lb(fill); } + +void ui_newline(UiObject *obj) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.newline = TRUE; +} diff -r 6ef2c7f73a30 -r 4697592e24ba ui/gtk/container.h --- a/ui/gtk/container.h Mon Jan 05 14:47:19 2015 +0100 +++ b/ui/gtk/container.h Mon Jan 05 18:47:07 2015 +0100 @@ -53,6 +53,8 @@ struct UiLayout { UiLayoutBool fill; + UiBool newline; + char *label; }; struct UiContainer { @@ -66,6 +68,16 @@ UiBool has_fill; } UiBoxContainer; +typedef struct UiGridContainer { + UiContainer container; + int x; + int y; +} UiGridContainer; + +typedef struct UiTabViewContainer { + UiContainer container; +} UiTabViewContainer; + GtkWidget* ui_gtk_vbox_new(); GtkWidget* ui_gtk_hbox_new(); @@ -75,6 +87,12 @@ UiContainer* ui_box_container(UiObject *obj, GtkWidget *box); void ui_box_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); +UiContainer* ui_grid_container(UiObject *obj, GtkWidget *grid); +void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); + +UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview); +void ui_tabview_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); + void ui_split_container_add1(UiContainer *ct, GtkWidget *widget, UiBool fill); void ui_split_container_add2(UiContainer *ct, GtkWidget *widget, UiBool fill); diff -r 6ef2c7f73a30 -r 4697592e24ba ui/gtk/label.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/gtk/label.c Mon Jan 05 18:47:07 2015 +0100 @@ -0,0 +1,53 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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. + */ + +#include +#include + +#include "label.h" +#include "container.h" +#include "../../ucx/mempool.h" +#include "../common/context.h" +#include "../common/object.h" + +UIWIDGET ui_label(UiObject *obj, char *label) { + GtkWidget *widget = gtk_label_new(label); + + UiContainer *ct = uic_get_current_container(obj); + ct->add(ct, widget, FALSE); + + return widget; +} + +UIWIDGET ui_space(UiObject *obj) { + GtkWidget *widget = gtk_label_new(""); + UiContainer *ct = uic_get_current_container(obj); + ct->add(ct, widget, TRUE); + + return widget; +} diff -r 6ef2c7f73a30 -r 4697592e24ba ui/gtk/label.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/gtk/label.h Mon Jan 05 18:47:07 2015 +0100 @@ -0,0 +1,47 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 LABEL_H +#define LABEL_H + +#include "../ui/toolkit.h" +#include "toolkit.h" + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif /* LABEL_H */ + diff -r 6ef2c7f73a30 -r 4697592e24ba ui/gtk/objs.mk --- a/ui/gtk/objs.mk Mon Jan 05 14:47:19 2015 +0100 +++ b/ui/gtk/objs.mk Mon Jan 05 18:47:07 2015 +0100 @@ -36,6 +36,7 @@ GTKOBJ += menu.o GTKOBJ += toolbar.o GTKOBJ += button.o +GTKOBJ += label.o GTKOBJ += text.o GTKOBJ += model.o GTKOBJ += tree.o diff -r 6ef2c7f73a30 -r 4697592e24ba ui/gtk/text.c --- a/ui/gtk/text.c Mon Jan 05 14:47:19 2015 +0100 +++ b/ui/gtk/text.c Mon Jan 05 18:47:07 2015 +0100 @@ -445,3 +445,52 @@ mgr->cur = elm; } } + + +UIWIDGET ui_textfield(UiObject *obj, UiString *value) { + GtkWidget *textfield = gtk_entry_new(); + UiContainer *ct = uic_get_current_container(obj); + ct->add(ct, textfield, FALSE); + + if(value) { + if(value->value) { + gtk_entry_set_text(GTK_ENTRY(textfield), value->value); + g_free(value->value); + // TODO: free value + } + + value->get = ui_textfield_get; + value->set = ui_textfield_set; + value->value = NULL; + value->obj = GTK_ENTRY(textfield); + } + + return textfield; +} + +UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) { + UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_STRING); + if(var) { + UiString *value = var->value; + return ui_textfield(obj, value); + } else { + // TODO: error + } + return NULL; +} + +char* ui_textfield_get(UiString *str) { + if(str->value) { + g_free(str->value); + } + str->value = g_strdup(gtk_entry_get_text(str->obj)); + return str->value; +} + +void ui_textfield_set(UiString *str, char *value) { + if(str->value) { + g_free(str->value); + } + str->value = NULL; + gtk_entry_set_text(str->obj, value); +} diff -r 6ef2c7f73a30 -r 4697592e24ba ui/gtk/text.h --- a/ui/gtk/text.h Mon Jan 05 14:47:19 2015 +0100 +++ b/ui/gtk/text.h Mon Jan 05 18:47:07 2015 +0100 @@ -84,6 +84,9 @@ void ui_free_textbuf_op(UiTextBufOp *op); int ui_check_insertstr(char *oldstr, int oldlen, char *newstr, int newlen); +char* ui_textfield_get(UiString *str); +void ui_textfield_set(UiString *str, char *value); + #ifdef __cplusplus } #endif diff -r 6ef2c7f73a30 -r 4697592e24ba ui/motif/container.c --- a/ui/motif/container.c Mon Jan 05 14:47:19 2015 +0100 +++ b/ui/motif/container.c Mon Jan 05 18:47:07 2015 +0100 @@ -330,16 +330,11 @@ if(tabview->current) { XtUnmanageChild(tabview->current); } - if(tabview->tabs) { - // not the first tab, so unmanage the new widget - //XtUnmanageChild(widget); - } else { - tabview->current = widget; - } + tabview->current = widget; - tabview->tabs = ucx_list_append(tabview->tabs, widget); + ui_select_tab(ct->widget, 0); ui_reset_layout(ct->layout); }