# HG changeset patch # User Olaf Wintermann # Date 1395513944 -3600 # Node ID 19d37cb9c96c8e68ba09d120d18f6d389665ea66 # Parent 39b9b86ec452453884ce9b4ffa62a8cf1da5cf5a added textarea diff -r 39b9b86ec452 -r 19d37cb9c96c application/main.c --- a/application/main.c Sat Mar 22 15:34:20 2014 +0100 +++ b/application/main.c Sat Mar 22 19:45:44 2014 +0100 @@ -38,6 +38,7 @@ typedef struct TestWindowData { TestDocument *doc1; TestDocument *doc2; + UiText text; } TestWindowData; UiInteger check1; @@ -54,6 +55,12 @@ printf("check1: %s\n", ui_getval(doc->check1) ? "true" : "false"); } +void action_save(UiEvent *event, void *data) { + TestWindowData *wd = event->window; + printf("Text: {%s}\n", ui_getval(wd->text)); + ui_setval(wd->text, "--------"); +} + void action_close(UiEvent *event, void *data) { exit(0); } @@ -87,10 +94,12 @@ ui_toolitem_st("new", UI_STOCK_NEW, action_new, NULL); ui_toolitem_st("open", UI_STOCK_OPEN, action_open, NULL); + ui_toolitem_st("save", UI_STOCK_SAVE, action_save, NULL); ui_toolitem_st("close", UI_STOCK_CLOSE, action_close, NULL); ui_toolbar_add_default("new"); ui_toolbar_add_default("open"); + ui_toolbar_add_default("save"); ui_toolbar_add_default("close"); @@ -107,7 +116,8 @@ ui_set_document(window, doc1); - ui_button(window, "OK", action_open, NULL); + //ui_button(window, "OK", action_open, NULL); + ui_textarea(window, &wdata->text); //ui_window_addint(window, "check1"); ui_show(window); diff -r 39b9b86ec452 -r 19d37cb9c96c ui/common/object.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/object.c Sat Mar 22 19:45:44 2014 +0100 @@ -0,0 +1,37 @@ +/* + * 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 "object.h" + +UiContainer* uic_get_current_container(UiObject *obj) { + // TODO + return obj->container; +} diff -r 39b9b86ec452 -r 19d37cb9c96c ui/common/object.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/object.h Sat Mar 22 19:45:44 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 UIC_OBJECT_H +#define UIC_OBJECT_H + +#include "../ui/toolkit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +UiContainer* uic_get_current_container(UiObject *obj); + + +#ifdef __cplusplus +} +#endif + +#endif /* UIC_OBJECT_H */ + diff -r 39b9b86ec452 -r 19d37cb9c96c ui/common/objs.mk --- a/ui/common/objs.mk Sat Mar 22 15:34:20 2014 +0100 +++ b/ui/common/objs.mk Sat Mar 22 19:45:44 2014 +0100 @@ -31,6 +31,7 @@ COMMON_OBJ = context.o COMMON_OBJ += document.o +COMMON_OBJ += object.o #COMMON_OBJ = observer.o #COMMON_OBJ += list.o diff -r 39b9b86ec452 -r 19d37cb9c96c ui/gtk/button.c --- a/ui/gtk/button.c Sat Mar 22 15:34:20 2014 +0100 +++ b/ui/gtk/button.c Sat Mar 22 19:45:44 2014 +0100 @@ -52,7 +52,8 @@ event); } - obj->container->add(obj->container, button); + UiContainer *ct = uic_get_current_container(obj); + ct->add(ct, button); return button; } diff -r 39b9b86ec452 -r 19d37cb9c96c ui/gtk/objs.mk --- a/ui/gtk/objs.mk Sat Mar 22 15:34:20 2014 +0100 +++ b/ui/gtk/objs.mk Sat Mar 22 19:45:44 2014 +0100 @@ -36,6 +36,7 @@ GTKOBJ += menu.o GTKOBJ += toolbar.o GTKOBJ += button.o +GTKOBJ += text.o TOOLKITOBJS = $(GTKOBJ:%=$(GTK_OBJPRE)%) TOOLKITSOURCE = $(GTKOBJ:%.o=gtk/%.c) diff -r 39b9b86ec452 -r 19d37cb9c96c ui/gtk/text.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/gtk/text.c Sat Mar 22 19:45:44 2014 +0100 @@ -0,0 +1,130 @@ +/* + * 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 "text.h" +#include "container.h" + +UIWIDGET ui_textarea(UiObject *obj, UiText *value) { + GtkWidget *text_area = gtk_text_view_new(); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR); + g_signal_connect( + text_area, + "realize", + G_CALLBACK(ui_textarea_realize_event), + NULL); + + GtkWidget *scroll_area = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy( + GTK_SCROLLED_WINDOW(scroll_area), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS + gtk_container_add(GTK_CONTAINER(scroll_area), text_area); + + // font and padding + PangoFontDescription *font; + font = pango_font_description_from_string("Monospace"); + gtk_widget_modify_font(text_area, font); + pango_font_description_free(font); + + gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_area), 2); + gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_area), 2); + + // add + UiContainer *ct = uic_get_current_container(obj); + ct->add(ct, scroll_area); + + // bind value + if(value) { + value->get = ui_textarea_get; + value->set = ui_textarea_set; + value->value = NULL; + GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_area)); + value->obj = buf; + + // register undo manager + g_signal_connect( + buf, + "insert-text", + G_CALLBACK(ui_textbuf_insert), + NULL); + g_signal_connect( + buf, + "delete-range", + G_CALLBACK(ui_textbuf_delete), + NULL); + } + + return scroll_area; +} + +char* ui_textarea_get(UiText *text) { + if(text->value) { + g_free(text->value); + } + GtkTextBuffer *buf = text->obj; + GtkTextIter start; + GtkTextIter end; + gtk_text_buffer_get_bounds(buf, &start, &end); + char *str = gtk_text_buffer_get_text(buf, &start, &end, FALSE); + text->value = str; + return str; +} + +void ui_textarea_set(UiText *text, char *str) { + if(text->value) { + g_free(text->value); + text->value = NULL; + } + gtk_text_buffer_set_text((GtkTextBuffer*)text->obj, str, -1); +} + +void ui_textarea_realize_event(GtkWidget *widget, gpointer data) { + gtk_widget_grab_focus(widget); +} + +void ui_textbuf_insert( + GtkTextBuffer *textbuffer, + GtkTextIter *location, + char *text, + int len, + void *data) +{ + //TODO +} + +void ui_textbuf_delete( + GtkTextBuffer *textbuffer, + GtkTextIter *start, + GtkTextIter *end, + void *data) +{ + //TODO +} diff -r 39b9b86ec452 -r 19d37cb9c96c ui/gtk/text.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/gtk/text.h Sat Mar 22 19:45:44 2014 +0100 @@ -0,0 +1,59 @@ +/* + * 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 TEXT_H +#define TEXT_H + +#include "../ui/text.h" +#include "toolkit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +char* ui_textarea_get(UiText *text); +void ui_textarea_set(UiText *text, char *str); +void ui_textarea_realize_event(GtkWidget *widget, gpointer data); +void ui_textbuf_insert( + GtkTextBuffer *textbuffer, + GtkTextIter *location, + char *text, + int len, + void *data); +void ui_textbuf_delete( + GtkTextBuffer *textbuffer, + GtkTextIter *start, + GtkTextIter *end, + void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* TEXT_H */ + diff -r 39b9b86ec452 -r 19d37cb9c96c ui/gtk/toolkit.h --- a/ui/gtk/toolkit.h Sat Mar 22 15:34:20 2014 +0100 +++ b/ui/gtk/toolkit.h Sat Mar 22 19:45:44 2014 +0100 @@ -30,6 +30,8 @@ #define TOOLKIT_H #include "../ui/toolkit.h" +#include "../common/context.h" +#include "../common/object.h" #ifdef __cplusplus extern "C" { diff -r 39b9b86ec452 -r 19d37cb9c96c ui/motif/button.c --- a/ui/motif/button.c Sat Mar 22 15:34:20 2014 +0100 +++ b/ui/motif/button.c Sat Mar 22 19:45:44 2014 +0100 @@ -36,6 +36,7 @@ UIWIDGET ui_button(UiObject *obj, char *label, ui_callback f, void *data) { + UiContainer *ct = uic_get_current_container(obj); XmString str = XmStringCreateLocalized(label); int n = 0; @@ -43,7 +44,7 @@ XtSetArg(args[n], XmNlabelString, str); n++; - Widget parent = obj->container->add(obj->container, args, &n); + Widget parent = ct->add(ct, args, &n); Widget button = XmCreatePushButton(parent, "button", args, n); if(f) { diff -r 39b9b86ec452 -r 19d37cb9c96c ui/motif/objs.mk --- a/ui/motif/objs.mk Sat Mar 22 15:34:20 2014 +0100 +++ b/ui/motif/objs.mk Sat Mar 22 19:45:44 2014 +0100 @@ -36,6 +36,7 @@ MOTIFOBJ += menu.o MOTIFOBJ += toolbar.o MOTIFOBJ += button.o +MOTIFOBJ += text.o TOOLKITOBJS = $(MOTIFOBJ:%=$(MOTIF_OBJPRE)%) TOOLKITSOURCE = $(MOTIFOBJ:%.o=motif/%.c) diff -r 39b9b86ec452 -r 19d37cb9c96c ui/motif/stock.c --- a/ui/motif/stock.c Sat Mar 22 15:34:20 2014 +0100 +++ b/ui/motif/stock.c Sat Mar 22 19:45:44 2014 +0100 @@ -42,6 +42,8 @@ ui_add_stock_item(UI_STOCK_SAVE, "Save", NULL); ui_add_stock_item(UI_STOCK_SAVE_AS, "Save as ...", NULL); ui_add_stock_item(UI_STOCK_CLOSE, "Close", NULL); + ui_add_stock_item(UI_STOCK_UNDO, "Undo", NULL); + ui_add_stock_item(UI_STOCK_REDO, "Redo", NULL); } void ui_add_stock_item(char *id, char *label, void *icon) { diff -r 39b9b86ec452 -r 19d37cb9c96c ui/motif/text.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/motif/text.c Sat Mar 22 19:45:44 2014 +0100 @@ -0,0 +1,76 @@ +/* + * 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 "text.h" +#include "container.h" + +UIWIDGET ui_textarea(UiObject *obj, UiText *value) { + UiContainer *ct = uic_get_current_container(obj); + int n = 0; + Arg args[16]; + + //XtSetArg(args[n], XmNeditable, TRUE); + //n++; + XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); + n++; + + Widget parent = ct->add(ct, args, &n); + Widget text_area = XmCreateScrolledText(parent, "text_area", args, n); + XtManageChild(text_area); + + // bind value + if(value) { + value->get = ui_textarea_get; + value->set = ui_textarea_set; + value->value = NULL; + value->obj = text_area; + } + + return text_area; +} + +char* ui_textarea_get(UiText *text) { + if(text->value) { + XtFree(text->value); + } + char *str = XmTextGetString(text->obj); + text->value = str; + return str; +} + +void ui_textarea_set(UiText *text, char *str) { + if(text->value) { + XtFree(text->value); + text->value = NULL; + } + text->value = NULL; + XmTextSetString(text->obj, str); +} diff -r 39b9b86ec452 -r 19d37cb9c96c ui/motif/text.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/motif/text.h Sat Mar 22 19:45:44 2014 +0100 @@ -0,0 +1,48 @@ +/* + * 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 TEXT_H +#define TEXT_H + +#include "../ui/text.h" +#include "toolkit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +char* ui_textarea_get(UiText *text); +void ui_textarea_set(UiText *text, char *str); + + +#ifdef __cplusplus +} +#endif + +#endif /* TEXT_H */ + diff -r 39b9b86ec452 -r 19d37cb9c96c ui/motif/toolkit.h --- a/ui/motif/toolkit.h Sat Mar 22 15:34:20 2014 +0100 +++ b/ui/motif/toolkit.h Sat Mar 22 19:45:44 2014 +0100 @@ -30,6 +30,8 @@ #define TOOLKIT_H #include "../ui/toolkit.h" +#include "../common/context.h" +#include "../common/object.h" #ifdef __cplusplus extern "C" { diff -r 39b9b86ec452 -r 19d37cb9c96c ui/motif/window.c --- a/ui/motif/window.c Sat Mar 22 15:34:20 2014 +0100 +++ b/ui/motif/window.c Sat Mar 22 19:45:44 2014 +0100 @@ -56,12 +56,9 @@ Arg args[16]; int n = 0; - XtSetArg(args[n], XmNtitle, title); - n++; - XtSetArg(args[n], XmNbaseWidth, window_default_width); - n++; - XtSetArg(args[n], XmNbaseHeight, window_default_height); - n++; + XtSetArg(args[0], XmNtitle, title); + XtSetArg(args[1], XmNbaseWidth, window_default_width); + XtSetArg(args[2], XmNbaseHeight, window_default_height); Widget toplevel = XtAppCreateShell( "Test123", @@ -70,7 +67,7 @@ vendorShellWidgetClass, ui_get_display(), args, - n); + 3); Atom wm_delete_window; wm_delete_window = XmInternAtom( @@ -104,12 +101,18 @@ // 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); + XtSetArg(args[2], XmNleftAttachment, XmATTACH_FORM); + XtSetArg(args[3], XmNrightAttachment, XmATTACH_FORM); + XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM); + if(toolbar) { + XtSetArg(args[5], XmNtopAttachment, XmATTACH_WIDGET); + XtSetArg(args[6], XmNtopWidget, toolbar); + n = 7; + } else { + XtSetArg(args[5], XmNtopAttachment, XmATTACH_FORM); + n = 6; + } + Widget frame = XmCreateFrame(form, "toolbar_frame", args, n); XtManageChild(frame); obj->container = ui_frame_container(obj, frame); diff -r 39b9b86ec452 -r 19d37cb9c96c ui/ui/text.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/ui/text.h Sat Mar 22 19:45:44 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_TEXT_H +#define UI_TEXT_H + +#include "toolkit.h" + +#ifdef __cplusplus +extern "C" { +#endif + +UIWIDGET ui_textarea(UiObject *obj, UiText *value); + + +#ifdef __cplusplus +} +#endif + +#endif /* UI_TEXT_H */ + diff -r 39b9b86ec452 -r 19d37cb9c96c ui/ui/toolkit.h --- a/ui/ui/toolkit.h Sat Mar 22 15:34:20 2014 +0100 +++ b/ui/ui/toolkit.h Sat Mar 22 19:45:44 2014 +0100 @@ -60,6 +60,7 @@ typedef struct UiInteger UiInteger; typedef struct UiString UiString; +typedef struct UiText UiText; /* private types */ typedef struct UiContext UiContext; @@ -118,6 +119,14 @@ void *obj; }; +struct UiText { + char* (*get)(UiText*); + void (*set)(UiText*, char*); + char* value; + void *obj; + // TODO: selection, undo, replace, ... +}; + void ui_init(char *appname, int argc, char **argv); void ui_exitfunc(ui_callback f, void *udata); diff -r 39b9b86ec452 -r 19d37cb9c96c ui/ui/ui.h --- a/ui/ui/ui.h Sat Mar 22 15:34:20 2014 +0100 +++ b/ui/ui/ui.h Sat Mar 22 19:45:44 2014 +0100 @@ -35,6 +35,7 @@ #include "window.h" #include "stock.h" #include "button.h" +#include "text.h" #endif /* UI_H */