added simple container

Sat, 22 Mar 2014 15:34:20 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 22 Mar 2014 15:34:20 +0100
changeset 4
39b9b86ec452
parent 3
c1a75454b444
child 5
19d37cb9c96c

added simple container

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/button.c file | annotate | diff | comparison | revisions
ui/gtk/container.c file | annotate | diff | comparison | revisions
ui/gtk/container.h file | annotate | diff | comparison | revisions
ui/gtk/objs.mk file | annotate | diff | comparison | revisions
ui/gtk/window.c file | annotate | diff | comparison | revisions
ui/motif/button.c file | annotate | diff | comparison | revisions
ui/motif/container.c file | annotate | diff | comparison | revisions
ui/motif/container.h file | annotate | diff | comparison | revisions
ui/motif/objs.mk file | annotate | diff | comparison | revisions
ui/motif/toolbar.c file | annotate | diff | comparison | revisions
ui/motif/toolbar.h file | annotate | diff | comparison | revisions
ui/motif/window.c file | annotate | diff | comparison | revisions
ui/ui/button.h file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
ui/ui/ui.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Sat Mar 22 10:37:12 2014 +0100
+++ b/application/main.c	Sat Mar 22 15:34:20 2014 +0100
@@ -107,6 +107,8 @@
     
     ui_set_document(window, doc1);
     
+    ui_button(window, "OK", action_open, NULL);
+    
     //ui_window_addint(window, "check1");
     ui_show(window);
     ui_main();
--- a/ui/gtk/button.c	Sat Mar 22 10:37:12 2014 +0100
+++ b/ui/gtk/button.c	Sat Mar 22 15:34:20 2014 +0100
@@ -30,7 +30,32 @@
 #include <stdlib.h>
 
 #include "button.h"
+#include "container.h"
+#include "../../ucx/mempool.h"
+#include "../common/context.h"
 
+UIWIDGET ui_button(UiObject *obj, char *label, ui_callback f, void *data) {
+    GtkWidget *button = gtk_button_new_with_label(label);
+    
+    if(f) {
+        UiEventData *event = ucx_mempool_malloc(
+                obj->ctx->mempool,
+                sizeof(UiEventData));
+        event->obj = obj;
+        event->user_data = data;
+        event->callback = f;
+
+        g_signal_connect(
+                button,
+                "clicked",
+                G_CALLBACK(ui_button_clicked),
+                event);
+    }
+    
+    obj->container->add(obj->container, button);
+    
+    return button;
+}
 
 
 void ui_button_clicked(GtkWidget *widget, UiEventData *event) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/gtk/container.c	Sat Mar 22 15:34:20 2014 +0100
@@ -0,0 +1,46 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#include "container.h"
+#include "../common/context.h"
+
+UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame) {
+    UiContainer *ct = ucx_mempool_malloc(
+            obj->ctx->mempool,
+            sizeof(UiContainer));
+    ct->widget = frame;
+    ct->add = ui_frame_container_add;
+    return ct;
+}
+
+void ui_frame_container_add(UiContainer *ct, GtkWidget *widget) {
+    gtk_container_add(GTK_CONTAINER(ct->widget), widget);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/gtk/container.h	Sat Mar 22 15:34:20 2014 +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.
+ */
+
+#ifndef CONTAINER_H
+#define	CONTAINER_H
+
+#include "../ui/toolkit.h"
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+typedef void (*ui_container_add_f)(UiContainer*, GtkWidget*);
+
+struct UiContainer {
+    GtkWidget *widget;
+    void (*add)(UiContainer*, GtkWidget*);
+};
+
+UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame);
+void ui_frame_container_add(UiContainer *ct, GtkWidget *widget);
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* CONTAINER_H */
+
--- a/ui/gtk/objs.mk	Sat Mar 22 10:37:12 2014 +0100
+++ b/ui/gtk/objs.mk	Sat Mar 22 15:34:20 2014 +0100
@@ -32,6 +32,7 @@
 # some objects are defined in config.mk
 GTKOBJ += toolkit.o
 GTKOBJ += window.o
+GTKOBJ += container.o
 GTKOBJ += menu.o
 GTKOBJ += toolbar.o
 GTKOBJ += button.o
--- a/ui/gtk/window.c	Sat Mar 22 10:37:12 2014 +0100
+++ b/ui/gtk/window.c	Sat Mar 22 15:34:20 2014 +0100
@@ -34,6 +34,7 @@
 
 #include "menu.h"
 #include "toolbar.h"
+#include "container.h"
 
 static int nwindows = 0;
 
@@ -93,6 +94,11 @@
         gtk_box_pack_start(GTK_BOX(vbox), tb, FALSE, FALSE, 0);
     }
     
+    // window content
+    GtkWidget *frame = gtk_alignment_new(0.5, 0.5, 1, 1);
+    gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
+    obj->container = ui_frame_container(obj, frame);
+    
     nwindows++;
     return obj;
 }
--- a/ui/motif/button.c	Sat Mar 22 10:37:12 2014 +0100
+++ b/ui/motif/button.c	Sat Mar 22 15:34:20 2014 +0100
@@ -30,6 +30,40 @@
 #include <stdlib.h>
 
 #include "button.h"
+#include "container.h"
+#include "../common/context.h"
+#include "../../ucx/mempool.h"
+
+
+UIWIDGET ui_button(UiObject *obj, char *label, ui_callback f, void *data) {
+    XmString str = XmStringCreateLocalized(label);
+    
+    int n = 0;
+    Arg args[16];
+    XtSetArg(args[n], XmNlabelString, str);
+    n++;
+    
+    Widget parent = obj->container->add(obj->container, args, &n);
+    Widget button = XmCreatePushButton(parent, "button", args, n);
+    
+    if(f) {
+        UiEventData *event = ucx_mempool_malloc(
+                obj->ctx->mempool,
+                sizeof(UiEventData));
+        event->obj = obj;
+        event->user_data = data;
+        event->callback = f;
+        XtAddCallback(
+                button,
+                XmNactivateCallback,
+                (XtCallbackProc)ui_push_button_callback,
+                event);
+    }
+    
+    XtManageChild(button);
+    
+    return button;
+}
 
 // wrapper
 int ui_toggle_button_get(UiInteger *i) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/motif/container.c	Sat Mar 22 15:34:20 2014 +0100
@@ -0,0 +1,46 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#include "container.h"
+#include "../common/context.h"
+
+UiContainer* ui_frame_container(UiObject *obj, Widget frame) {
+    UiContainer *ct = ucx_mempool_malloc(
+            obj->ctx->mempool,
+            sizeof(UiContainer));
+    ct->widget = frame;
+    ct->add = ui_frame_container_add;
+    return ct;
+}
+
+Widget ui_frame_container_add(UiContainer *ct, Arg *args, int *n) {
+    return ct->widget;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/motif/container.h	Sat Mar 22 15:34:20 2014 +0100
@@ -0,0 +1,56 @@
+/*
+ * 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 CONTAINER_H
+#define	CONTAINER_H
+
+#include "../ui/toolkit.h"
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+typedef Widget (*ui_container_add_f)(UiContainer*, Arg*, int*);
+
+struct UiContainer {
+    Widget widget;
+    Widget (*add)(UiContainer*, Arg *, int*);
+};
+    
+
+UiContainer* ui_frame_container(UiObject *obj, Widget frame);
+Widget ui_frame_container_add(UiContainer *ct, Arg *args, int *n);
+
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* CONTAINER_H */
+
--- a/ui/motif/objs.mk	Sat Mar 22 10:37:12 2014 +0100
+++ b/ui/motif/objs.mk	Sat Mar 22 15:34:20 2014 +0100
@@ -32,6 +32,7 @@
 MOTIFOBJ = toolkit.o
 MOTIFOBJ += stock.o
 MOTIFOBJ += window.o
+MOTIFOBJ += container.o
 MOTIFOBJ += menu.o
 MOTIFOBJ += toolbar.o
 MOTIFOBJ += button.o
--- a/ui/motif/toolbar.c	Sat Mar 22 10:37:12 2014 +0100
+++ b/ui/motif/toolbar.c	Sat Mar 22 15:34:20 2014 +0100
@@ -68,9 +68,9 @@
     defaults = ucx_list_append(defaults, s);
 }
 
-void ui_create_toolbar(UiObject *obj, Widget parent) {
+Widget ui_create_toolbar(UiObject *obj, Widget parent) {
     if(!defaults) {
-        return;
+        return NULL;
     }
     
     Arg args[8];
@@ -83,14 +83,15 @@
     
     XtSetArg(args[0], XmNorientation, XmHORIZONTAL);
     XtSetArg(args[1], XmNpacking, XmPACK_TIGHT);
-    Widget toolbar = XmCreateRowColumn (frame, "toolbar", args, 2);
+    XtSetArg(args[2], XmNspacing, 1);
+    Widget toolbar = XmCreateRowColumn (frame, "toolbar", args, 3);
     
     UCX_FOREACH(elm, defaults) {
         UiToolItemI *item = ucx_map_cstr_get(toolbar_items, elm->data);
         if(item) {
             item->add_to(toolbar, item, obj);
         } else if(!strcmp(elm->data, "@separator")) {
-            
+            // TODO
         } else {
             fprintf(stderr, "UI Error: Unknown toolbar item: %s\n", elm->data);
         }
@@ -98,6 +99,8 @@
     
     XtManageChild(toolbar);
     XtManageChild(frame);
+    
+    return frame;
 }
 
 void add_toolitem_widget(Widget parent, UiToolItem *item, UiObject *obj) {
--- a/ui/motif/toolbar.h	Sat Mar 22 10:37:12 2014 +0100
+++ b/ui/motif/toolbar.h	Sat Mar 22 15:34:20 2014 +0100
@@ -63,7 +63,7 @@
 
 void ui_toolbar_init();
 
-void ui_create_toolbar(UiObject *obj, Widget parent);
+Widget ui_create_toolbar(UiObject *obj, Widget parent);
 
 void add_toolitem_widget(Widget tb, UiToolItem *item, UiObject *obj);
 void add_toolitem_st_widget(Widget tb, UiStToolItem *item, UiObject *obj);
--- a/ui/motif/window.c	Sat Mar 22 10:37:12 2014 +0100
+++ b/ui/motif/window.c	Sat Mar 22 15:34:20 2014 +0100
@@ -32,6 +32,7 @@
 #include "toolkit.h"
 #include "menu.h"
 #include "toolbar.h"
+#include "container.h"
 #include "../ui/window.h"
 #include "../common/context.h"
 
@@ -98,7 +99,20 @@
             window,
             NULL);
     
-    ui_create_toolbar(obj, form);
+    Widget toolbar = ui_create_toolbar(obj, form);
+    
+    // window content
+    XtSetArg(args[0], XmNshadowType, XmSHADOW_ETCHED_OUT);
+    XtSetArg(args[1], XmNshadowThickness, 0);
+    XtSetArg(args[2], XmNtopAttachment, XmATTACH_WIDGET);
+    XtSetArg(args[3], XmNtopWidget, toolbar);
+    XtSetArg(args[4], XmNleftAttachment, XmATTACH_FORM);
+    XtSetArg(args[5], XmNrightAttachment, XmATTACH_FORM);
+    XtSetArg(args[6], XmNbottomAttachment, XmATTACH_FORM);
+    Widget frame = XmCreateFrame(form, "toolbar_frame", args, 7);
+    XtManageChild(frame);
+    
+    obj->container = ui_frame_container(obj, frame);
     
     
     XtManageChild(form);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/ui/button.h	Sat Mar 22 15:34:20 2014 +0100
@@ -0,0 +1,46 @@
+/*
+ * 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 UI_BUTTON_H
+#define	UI_BUTTON_H
+
+#include "toolkit.h"
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+UIWIDGET ui_button(UiObject *obj, char *label, ui_callback f, void *data);
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* UI_BUTTON_H */
+
--- a/ui/ui/toolkit.h	Sat Mar 22 10:37:12 2014 +0100
+++ b/ui/ui/toolkit.h	Sat Mar 22 15:34:20 2014 +0100
@@ -62,7 +62,8 @@
 typedef struct UiString  UiString;
 
 /* private types */
-typedef struct UiContext UiContext;
+typedef struct UiContext   UiContext;
+typedef struct UiContainer UiContainer;
 
 #define ui_getval(val) (val).get(&(val))
 #define ui_setval(val, v) (val).set(&(val), v)
@@ -76,11 +77,6 @@
     UIWIDGET  widget;
     
     /*
-     * window context
-     */
-    UiContext *ctx;
-    
-    /*
      * user window data
      */
     void      *window;
@@ -89,6 +85,16 @@
      * current document
      */
     void      *document;
+    
+    /*
+     * window context (private)
+     */
+    UiContext *ctx;
+    
+    /*
+     * container interface (private)
+     */
+    UiContainer *container;
 };
 
 struct UiEvent {
--- a/ui/ui/ui.h	Sat Mar 22 10:37:12 2014 +0100
+++ b/ui/ui/ui.h	Sat Mar 22 15:34:20 2014 +0100
@@ -34,6 +34,7 @@
 #include "toolbar.h"
 #include "window.h"
 #include "stock.h"
+#include "button.h"
 
 #endif	/* UI_H */
 

mercurial