# HG changeset patch # User Olaf Wintermann # Date 1408879867 -7200 # Node ID 97bafeca1c7cbf326a572477f385a83ff3928846 # Parent 62205699cd0e3baa513ce2d1d2a4e2840dc74273 added Qt window and menu implementation diff -r 62205699cd0e -r 97bafeca1c7c application/main.c --- a/application/main.c Tue Jul 22 19:15:44 2014 +0200 +++ b/application/main.c Sun Aug 24 13:31:07 2014 +0200 @@ -44,7 +44,8 @@ } Document; void action_close(UiEvent *event, void *data) { - ui_close(event->obj); + printf("action_close\n"); + //ui_close(event->obj); } char* person_getvalue(Person *p, int column) { @@ -84,15 +85,17 @@ ui_menu("File"); + //ui_menuitem("Close", action_close, NULL); ui_menuitem_st(UI_STOCK_CLOSE, action_close, NULL); - ui_checkitem("Check", action_button, NULL); + //ui_checkitem("Check", action_button, NULL); - ui_toolitem_st("button", UI_STOCK_GO_BACK, action_button, NULL); - ui_toolbar_add_default("button"); + //ui_toolitem_st("button", UI_STOCK_GO_BACK, action_button, NULL); + //ui_toolbar_add_default("button"); printf("create window\n"); UiObject *window = ui_window("Mod0", NULL); + /* UiModelInfo *model = ui_model_info(window->ctx, UI_STRING, "Name", UI_STRING, "Email", -1); model->getvalue = (ui_model_getvalue_f)person_getvalue; model->activate = action_activate; @@ -142,6 +145,7 @@ ui_document_regtext(doc3, "text", &doc3->text); ui_textarea_nv(tab3, "text"); ui_set_document(tab3, doc3); + */ ui_show(window); ui_main(); diff -r 62205699cd0e -r 97bafeca1c7c make/Makefile.mk --- a/make/Makefile.mk Tue Jul 22 19:15:44 2014 +0200 +++ b/make/Makefile.mk Sun Aug 24 13:31:07 2014 +0200 @@ -45,7 +45,7 @@ cd ucx; $(MAKE) ui: FORCE - cd ui; $(MAKE) + cd ui; $(MAKE) all application: ui FORCE cd application; $(MAKE) diff -r 62205699cd0e -r 97bafeca1c7c make/configure_qt4.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make/configure_qt4.sh Sun Aug 24 13:31:07 2014 +0200 @@ -0,0 +1,53 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2011 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. +# + +touch test.pro +TK_LIBS=`qmake-qt4 -o - test.pro | grep LIBS\ ` +rm -f test.pro + + +cat >> config.mk << __EOF__ + +# toolkit configuration + +CFLAGS += -DUI_QT4 +$TK_LIBS +LDFLAGS += \$(LIBS) + +TOOLKIT = qt + +# override linker +LD = \$(CXX) + +__EOF__ + + + + + + diff -r 62205699cd0e -r 97bafeca1c7c ui/Makefile --- a/ui/Makefile Tue Jul 22 19:15:44 2014 +0200 +++ b/ui/Makefile Sun Aug 24 13:31:07 2014 +0200 @@ -31,19 +31,16 @@ OBJ_DIR = ../build/ -include $(TOOLKIT)/objs.mk -include $(TOOLKIT)/Makefile - include common/objs.mk UI_LIB = ../build/lib/libuitk.$(LIB_EXT) +include $(TOOLKIT)/objs.mk OBJ = $(TOOLKITOBJS) $(COMMONOBJS) all: $(UI_LIB) -$(UI_LIB): $(OBJ) - $(AR) $(ARFLAGS) $(UI_LIB) $(OBJ) +include $(TOOLKIT)/Makefile $(COMMON_OBJPRE)%.o: common/%.c $(CC) -o $@ -c $(CFLAGS) $< diff -r 62205699cd0e -r 97bafeca1c7c ui/cocoa/Makefile --- a/ui/cocoa/Makefile Tue Jul 22 19:15:44 2014 +0200 +++ b/ui/cocoa/Makefile Sun Aug 24 13:31:07 2014 +0200 @@ -28,3 +28,7 @@ $(COCOA_OBJPRE)%.o: cocoa/%.m $(CC) -o $@ -c $(CFLAGS) $< + +$(UI_LIB): $(OBJ) + $(AR) $(ARFLAGS) $(UI_LIB) $(OBJ) + diff -r 62205699cd0e -r 97bafeca1c7c ui/cocoa/objs.mk --- a/ui/cocoa/objs.mk Tue Jul 22 19:15:44 2014 +0200 +++ b/ui/cocoa/objs.mk Sun Aug 24 13:31:07 2014 +0200 @@ -40,5 +40,5 @@ COCOAOBJ += tree.o -TOOLKITOBJS = $(COCOAOBJ:%=$(COCOA_OBJPRE)%) -TOOLKITSOURCE = $(COCOAOBJ:%.o=cocoa/%.m) +TOOLKITOBJS += $(COCOAOBJ:%=$(COCOA_OBJPRE)%) +TOOLKITSOURCE += $(COCOAOBJ:%.o=cocoa/%.m) diff -r 62205699cd0e -r 97bafeca1c7c ui/common/objs.mk --- a/ui/common/objs.mk Tue Jul 22 19:15:44 2014 +0200 +++ b/ui/common/objs.mk Sun Aug 24 13:31:07 2014 +0200 @@ -37,3 +37,4 @@ TOOLKITOBJS += $(COMMON_OBJ:%=$(COMMON_OBJPRE)%) TOOLKITSOURCE += $(COMMON_OBJ:%.o=common/%.c) + diff -r 62205699cd0e -r 97bafeca1c7c ui/gtk/Makefile --- a/ui/gtk/Makefile Tue Jul 22 19:15:44 2014 +0200 +++ b/ui/gtk/Makefile Sun Aug 24 13:31:07 2014 +0200 @@ -28,3 +28,7 @@ $(GTK_OBJPRE)%.o: gtk/%.c $(CC) -o $@ -c $(CFLAGS) $< + +$(UI_LIB): $(OBJ) + $(AR) $(ARFLAGS) $(UI_LIB) $(OBJ) + diff -r 62205699cd0e -r 97bafeca1c7c ui/gtk/objs.mk --- a/ui/gtk/objs.mk Tue Jul 22 19:15:44 2014 +0200 +++ b/ui/gtk/objs.mk Sun Aug 24 13:31:07 2014 +0200 @@ -41,5 +41,5 @@ GTKOBJ += tree.o GTKOBJ += image.o -TOOLKITOBJS = $(GTKOBJ:%=$(GTK_OBJPRE)%) -TOOLKITSOURCE = $(GTKOBJ:%.o=gtk/%.c) +TOOLKITOBJS += $(GTKOBJ:%=$(GTK_OBJPRE)%) +TOOLKITSOURCE += $(GTKOBJ:%.o=gtk/%.c) diff -r 62205699cd0e -r 97bafeca1c7c ui/motif/Makefile --- a/ui/motif/Makefile Tue Jul 22 19:15:44 2014 +0200 +++ b/ui/motif/Makefile Sun Aug 24 13:31:07 2014 +0200 @@ -28,3 +28,6 @@ $(MOTIF_OBJPRE)%.o: motif/%.c $(CC) -o $@ -c $(CFLAGS) $< + +$(UI_LIB): $(OBJ) + $(AR) $(ARFLAGS) $(UI_LIB) $(OBJ) diff -r 62205699cd0e -r 97bafeca1c7c ui/motif/container.c --- a/ui/motif/container.c Tue Jul 22 19:15:44 2014 +0200 +++ b/ui/motif/container.c Sun Aug 24 13:31:07 2014 +0200 @@ -160,14 +160,15 @@ XmString label = XmStringCreateLocalized("tab"); XtSetArg(args[0], XmNlabelString, label); - XtSetArg(args[1], XmNshadowThickness, 1); + XtSetArg(args[1], XmNshadowThickness, 0); XtSetArg(args[2], XmNtraversalOn, FALSE); XtSetArg(args[3], XmNtopAttachment, XmATTACH_FORM); XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM); XtSetArg(args[5], XmNhighlightThickness, 0); XtSetArg(args[6], XmNindicatorOn, XmINDICATOR_NONE); + XtSetArg(args[7], XmNfillOnSelect, TRUE); - Widget button = XmCreateToggleButton(v->tabbar, "tab_button", args, 7); + Widget button = XmCreateToggleButton(v->tabbar, "tab_button", args, 8); tab->tabbedpane = v; tab->content = content; tab->tab_button = button; @@ -189,6 +190,8 @@ XmATTACH_POSITION, XmNrightPosition, pos + part, + XmNset, + FALSE, NULL); is_first = FALSE; } else if(i < count - 1) { @@ -202,6 +205,8 @@ XmATTACH_POSITION, XmNrightPosition, pos + part, + XmNset, + FALSE, NULL); } else { XtVaSetValues( @@ -212,14 +217,16 @@ pos, XmNrightAttachment, XmATTACH_FORM, + XmNset, + FALSE, NULL); } pos += part; i++; } - XtManageChild(button); + XtVaSetValues(button, XmNset, TRUE, NULL); XtAddCallback( button, XmNvalueChangedCallback, diff -r 62205699cd0e -r 97bafeca1c7c ui/motif/objs.mk --- a/ui/motif/objs.mk Tue Jul 22 19:15:44 2014 +0200 +++ b/ui/motif/objs.mk Sun Aug 24 13:31:07 2014 +0200 @@ -40,5 +40,5 @@ MOTIFOBJ += list.o MOTIFOBJ += tree.o -TOOLKITOBJS = $(MOTIFOBJ:%=$(MOTIF_OBJPRE)%) -TOOLKITSOURCE = $(MOTIFOBJ:%.o=motif/%.c) +TOOLKITOBJS += $(MOTIFOBJ:%=$(MOTIF_OBJPRE)%) +TOOLKITSOURCE += $(MOTIFOBJ:%.o=motif/%.c) diff -r 62205699cd0e -r 97bafeca1c7c ui/qt/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/Makefile Sun Aug 24 13:31:07 2014 +0200 @@ -0,0 +1,39 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2012 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. +# + +QT_MAKEFILE = ../build/ui/qt/Makefile.mk + +UI_QT_LIB = ../build/ui/qt/ + +$(QT_MAKEFILE): qt/qt4.pro + qmake-qt4 -o - qt/qt4.pro > $(QT_MAKEFILE) + +$(UI_LIB): $(QT_MAKEFILE) $(OBJ) + $(MAKE) -f $(QT_MAKEFILE) + $(AR) $(ARFLAGS) $(UI_LIB) $(OBJ) + diff -r 62205699cd0e -r 97bafeca1c7c ui/qt/menu.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/menu.cpp Sun Aug 24 13:31:07 2014 +0200 @@ -0,0 +1,226 @@ +/* + * 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 +#include +#include + +#include "menu.h" +#include "toolkit.h" +#include "../common/context.h" +#include "../ui/properties.h" +#include "../ui/window.h" +#include "stock.h" + +static UcxList *menus; +static UcxList *current; + +/* -------------------------- UiMenu -------------------------- */ + +UiMenu::UiMenu(char* label) { + this->items = NULL; + this->label = label; +} + +void UiMenu::addMenuItem(UiMenuItemI* item) { + items = ucx_list_append(items, item); +} + +void UiMenu::addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) { + QMenu *m = NULL; + if(menubar) { + m = menubar->addMenu(label); + } else { + m = menu->addMenu(label); + } + + UCX_FOREACH(elm, items) { + UiMenuItemI *item = (UiMenuItemI*)elm->data; + item->addTo(obj, NULL, m); + } +} + + +/* -------------------------- UiMenuItem -------------------------- */ + +UiMenuItem::UiMenuItem(char* label, ui_callback f, void* userdata) { + this->label = label; + this->callback = f; + this->userdata = userdata; + this->groups = NULL; +} + +void UiMenuItem::addGroup(int group) { + groups = ucx_list_append(groups, (void*)(intptr_t)group); +} + +void UiMenuItem::addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) { + QString str = QString::fromUtf8(label); + UiAction *action = new UiAction(obj, str, callback, userdata); + menu->addAction(action); + //UiEventWrapper *ev = new UiEventWrapper(callback, userdata); + QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); +} + + +/* -------------------------- UiStMenuItem -------------------------- */ + +UiStMenuItem::UiStMenuItem(char* stockid, ui_callback f, void* userdata) { + this->stockid = stockid; + this->callback = f; + this->userdata = userdata; + this->groups = NULL; +} + +void UiStMenuItem::addGroup(int group) { + groups = ucx_list_append(groups, (void*)(intptr_t)group); +} + +void UiStMenuItem::addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) { + UiStockItem *stockItem = ui_get_stock_item(stockid); + + QString str = QString::fromUtf8(stockItem->label); + UiAction *action = new UiAction(obj, str, callback, userdata); + menu->addAction(action); + //UiEventWrapper *ev = new UiEventWrapper(callback, userdata); + QObject::connect(action, SIGNAL(triggered()), action, SLOT(trigger())); +} + + +/* -------------------------- UiAction -------------------------- */ + +UiAction::UiAction(UiObject *obj, QString &label, ui_callback f, void* userdata) : QAction(label, NULL) { + //QAction(label, NULL); + this->obj = obj; + this->callback = f; + this->userdata = userdata; +} + +void UiAction::trigger() { + UiEvent e; + e.obj = obj; + e.window = obj->window; + e.document = obj->ctx->document; + e.eventdata = NULL; + e.intval = 0; + callback(&e, userdata); +} + + +void ui_menu(char *label) { + // free current menu hierarchy + ucx_list_free(current); + + // create menu + UiMenu *menu = new UiMenu(label); + + current = ucx_list_prepend(NULL, menu); + menus = ucx_list_append(menus, menu); +} + +void ui_submenu(char *label) { + UiMenu *menu = new UiMenu(label); + + // add submenu to current menu + UiMenu *cm = (UiMenu*)current->data; + cm->addMenuItem(menu); + + // set the submenu to current menu + current = ucx_list_prepend(current, menu); +} + +void ui_submenu_end() { + if(ucx_list_size(current) < 2) { + return; + } + current = ucx_list_remove(current, current); + //UcxList *c = current; +} + + +void ui_menuitem(char *label, ui_callback f, void *userdata) { + ui_menuitem_gr(label, f, userdata, -1); +} + +void ui_menuitem_st(char *stockid, ui_callback f, void *userdata) { + ui_menuitem_stgr(stockid, f, userdata, -1); +} + +void ui_menuitem_gr(char *label, ui_callback f, void *userdata, ...) { + if(!current) { + return; + } + + UiMenuItem *item = new UiMenuItem(label, f, userdata); + + // add groups + va_list ap; + va_start(ap, userdata); + int group; + while((group = va_arg(ap, int)) != -1) { + item->addGroup(group); + } + va_end(ap); + + UiMenu *cm = (UiMenu*)current->data; + cm->addMenuItem(item); +} + +void ui_menuitem_stgr(char *stockid, ui_callback f, void *userdata, ...) { + if(!current) { + return; + } + + UiStMenuItem *item = new UiStMenuItem(stockid, f, userdata); + + // add groups + va_list ap; + va_start(ap, userdata); + int group; + while((group = va_arg(ap, int)) != -1) { + item->addGroup(group); + } + va_end(ap); + + UiMenu *cm = (UiMenu*)current->data; + cm->addMenuItem(item); +} + + + + +void ui_add_menus(UiObject *obj, QMainWindow *window) { + QMenuBar *mb = window->menuBar(); + + UCX_FOREACH(elm, menus) { + UiMenu *menu = (UiMenu*)elm->data; + menu->addTo(obj, mb, NULL); + } +} diff -r 62205699cd0e -r 97bafeca1c7c ui/qt/menu.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/menu.h Sun Aug 24 13:31:07 2014 +0200 @@ -0,0 +1,102 @@ +/* + * 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 MENU_H +#define MENU_H + +#include "../ui/menu.h" +#include "../../ucx/list.h" + +#include +#include +#include + +class UiMenuItemI { +public: + virtual void addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu) = 0; +}; + +class UiMenu : public UiMenuItemI { +public: + + UcxList *items; + char *label; + + UiMenu(char *label); + + void addMenuItem(UiMenuItemI *item); + + virtual void addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu); +}; + +class UiMenuItem : public UiMenuItemI { + char *label; + ui_callback callback; + void *userdata; + UcxList *groups; + +public: + UiMenuItem(char *label, ui_callback f, void *userdata); + void addGroup(int group); + + virtual void addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu); +}; + +class UiStMenuItem : public UiMenuItemI { + char *stockid; + ui_callback callback; + void *userdata; + UcxList *groups; + +public: + UiStMenuItem(char *stockid, ui_callback f, void *userdata); + void addGroup(int group); + + virtual void addTo(UiObject *obj, QMenuBar *menubar, QMenu *menu); +}; + + +class UiAction : public QAction { + Q_OBJECT + + UiObject *obj; + ui_callback callback; + void *userdata; + +public: + UiAction(UiObject *obj, QString &label, ui_callback f, void *userdata); + +private slots: + void trigger(); +}; + + +void ui_add_menus(UiObject *obj, QMainWindow *window); + +#endif /* MENU_H */ + diff -r 62205699cd0e -r 97bafeca1c7c ui/qt/objs.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/objs.mk Sun Aug 24 13:31:07 2014 +0200 @@ -0,0 +1,36 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2012 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. +# + +QT_SRC_DIR = ui/qt/ +QT_OBJPRE = $(OBJ_DIR)/$(QT_SRC_DIR) + +#QTOBJ = + +TOOLKITOBJS += $(QTOBJ:%=$(QT_OBJPRE)%) +TOOLKITSOURCE += $(QTOBJ:%.o=qt/%.cpp) + diff -r 62205699cd0e -r 97bafeca1c7c ui/qt/qt4.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/qt4.pro Sun Aug 24 13:31:07 2014 +0200 @@ -0,0 +1,47 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2012 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. +# + +TARGET = uitk +TEMPLATE = lib +CONFIG += staticlib warn_off debug +DESTDIR = ../build/lib +MOC_DIR = ../build/ui/qt +OBJECTS_DIR = ../build/ui/qt + +DEFINES += UI_QT4 + +SOURCES += toolkit.cpp +SOURCES += window.cpp +SOURCES += menu.cpp +SOURCES += stock.cpp + +HEADERS += toolkit.h +HEADERS += window.h +HEADERS += menu.h +HEADERS += stock.h + diff -r 62205699cd0e -r 97bafeca1c7c ui/qt/stock.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/stock.cpp Sun Aug 24 13:31:07 2014 +0200 @@ -0,0 +1,77 @@ +/* + * 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 "stock.h" +#include "../ui/properties.h" + +static UcxMap *stock_items; + +void ui_stock_init() { + stock_items = ucx_map_new(64); + + ui_add_stock_item(UI_STOCK_NEW, "New", ""); + ui_add_stock_item(UI_STOCK_OPEN, "Open", ""); + ui_add_stock_item(UI_STOCK_SAVE, "Save", ""); + ui_add_stock_item(UI_STOCK_SAVE_AS, "Save as ...", ""); + ui_add_stock_item(UI_STOCK_REVERT_TO_SAVED, "Revert to saved", ""); + ui_add_stock_item(UI_STOCK_CLOSE, "Close", ""); + ui_add_stock_item(UI_STOCK_UNDO, "Undo", ""); + ui_add_stock_item(UI_STOCK_REDO, "Redo", ""); + ui_add_stock_item(UI_STOCK_GO_BACK, "Back", ""); + ui_add_stock_item(UI_STOCK_GO_FORWARD, "Forward", ""); + ui_add_stock_item(UI_STOCK_CUT, "Cut", ""); + ui_add_stock_item(UI_STOCK_COPY, "Copy", ""); + ui_add_stock_item(UI_STOCK_PASTE, "Paste", ""); + ui_add_stock_item(UI_STOCK_DELETE, "Delete", ""); +} + +void ui_add_stock_item(char *id, char *label, char *icon) { + UiStockItem *item = new UiStockItem(label, icon); + ucx_map_cstr_put(stock_items, id, item); +} + +UiStockItem* ui_get_stock_item(char *id) { + UiStockItem *item = (UiStockItem*)ucx_map_cstr_get(stock_items, id); + if(item) { + char *label = uistr_n(id); + if(label) { + item->label = label; + } + } + return item; +} + + +UiStockItem::UiStockItem(char* label, char* icon_name) { + this->label = label; + this->icon_name = icon_name; +} + + diff -r 62205699cd0e -r 97bafeca1c7c ui/qt/stock.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/stock.h Sun Aug 24 13:31:07 2014 +0200 @@ -0,0 +1,49 @@ +/* + * 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 STOCK_H +#define STOCK_H + +#include "../ui/stock.h" + +class UiStockItem { +public: + + char *label; + char *icon_name; + + UiStockItem(char *label, char *icon_name); +}; + + +void ui_stock_init(); +void ui_add_stock_item(char *id, char *label, char *icon); +UiStockItem* ui_get_stock_item(char *id); + +#endif /* STOCK_H */ + diff -r 62205699cd0e -r 97bafeca1c7c ui/qt/toolkit.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/toolkit.cpp Sun Aug 24 13:31:07 2014 +0200 @@ -0,0 +1,111 @@ +/* + * 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 "toolkit.h" +#include "window.h" +#include "stock.h" + +#include "../common/document.h" +#include "../common/properties.h" + +static char *application_name; + +static ui_callback appclose_fnc; +static void *appclose_udata; + +//static QApplication app(qargc, qargv); +int app_argc; +char **app_argv; +QApplication *application = NULL; + +void ui_init(char *appname, int argc, char **argv) { + application_name = appname; + + app_argc = argc; + app_argv = argv; + application = new QApplication(app_argc, app_argv); + + uic_docmgr_init(); + + uic_load_app_properties(); + + ui_stock_init(); +} + +char* ui_appname() { + return application_name; +} + +void ui_exitfunc(ui_callback f, void *udata) { + appclose_fnc = f; + appclose_udata = udata; +} + +void ui_openfilefunc(ui_callback f, void *userdata) { + // OS X only +} + +void ui_main() { + application->exec(); + + if(appclose_fnc) { + appclose_fnc(NULL, appclose_udata); + } + uic_store_app_properties(); + + delete application; +} + +void ui_show(UiObject *obj) { + obj->widget->show(); +} + +void ui_close(UiObject *obj) { + QMainWindow *window = (QMainWindow*)obj->widget; + window->close(); +} + +void ui_set_enabled(UIWIDGET widget, int enabled) { + +} + + + + +UiEventWrapper::UiEventWrapper(ui_callback f, void* userdata) { + this->callback = f; + this->userdata = userdata; +} + +void UiEventWrapper::slot() { + printf("event\n"); + +} diff -r 62205699cd0e -r 97bafeca1c7c ui/qt/toolkit.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/toolkit.h Sun Aug 24 13:31:07 2014 +0200 @@ -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 TOOLKIT_H +#define TOOLKIT_H + +#include "../ui/toolkit.h" +#include "../common/context.h" +#include "../common/object.h" + +#include + +class UiEventWrapper : public QObject { + Q_OBJECT + + ui_callback callback; + void *userdata; + +public: + UiEventWrapper(ui_callback f, void *userdata); + +public slots: + void slot(); +}; + + +#endif /* TOOLKIT_H */ + diff -r 62205699cd0e -r 97bafeca1c7c ui/qt/window.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/window.cpp Sun Aug 24 13:31:07 2014 +0200 @@ -0,0 +1,49 @@ +/* + * 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 "../../ucx/mempool.h" +#include "../common/context.h" + +#include "window.h" +#include "menu.h" + +UiObject* ui_window(char *title, void *window_data) { + UcxMempool *mp = ucx_mempool_new(256); + UiObject *obj = (UiObject*)ucx_mempool_calloc(mp, 1, sizeof(UiObject)); + obj->ctx = uic_context(obj, mp); + obj->window = window_data; + obj->next = NULL; + + QMainWindow *window = new QMainWindow(); + obj->widget = window; + + ui_add_menus(obj, window); + + obj->widget = window; + return obj; +} diff -r 62205699cd0e -r 97bafeca1c7c ui/qt/window.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/qt/window.h Sun Aug 24 13:31:07 2014 +0200 @@ -0,0 +1,39 @@ +/* + * 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 WINDOW_H +#define WINDOW_H + +#include "../ui/window.h" + +#include + + + +#endif /* WINDOW_H */ + diff -r 62205699cd0e -r 97bafeca1c7c ui/ui/stock.h --- a/ui/ui/stock.h Tue Jul 22 19:15:44 2014 +0200 +++ b/ui/ui/stock.h Sun Aug 24 13:31:07 2014 +0200 @@ -36,7 +36,7 @@ #endif // motif stock ids -#if UI_MOTIF || UI_COCOA +#if UI_MOTIF || UI_COCOA || UI_QT4 || UI_QT5 #define UI_STOCK_NEW "ui.stock.New" #define UI_STOCK_OPEN "ui.stock.Open" diff -r 62205699cd0e -r 97bafeca1c7c ui/ui/toolkit.h --- a/ui/ui/toolkit.h Tue Jul 22 19:15:44 2014 +0200 +++ b/ui/ui/toolkit.h Sun Aug 24 13:31:07 2014 +0200 @@ -110,11 +110,6 @@ void *window; /* - * current document - */ - //void *document; - - /* * window context (private) */ UiContext *ctx;