# HG changeset patch # User Olaf Wintermann # Date 1453578427 -3600 # Node ID a4f4123ca12a99ba2946a14da60a741333b5e5b9 # Parent 86d729874ff46c849dcff67cd53e23b14901b7ad added simple window and open/save file dialogs for Qt diff -r 86d729874ff4 -r a4f4123ca12a application/main.c --- a/application/main.c Sat Jan 23 18:37:30 2016 +0100 +++ b/application/main.c Sat Jan 23 20:47:07 2016 +0100 @@ -37,6 +37,11 @@ printf("action_menu test: {%s}\n", data); printf("text: {%s}\n", ui_gettext(event->obj, "text")); fflush(stdout); + + char *file = ui_openfiledialog(event->obj); + printf("file: %s\n", file); + fflush(stdout); + free(file); } void action_button(UiEvent *event, void *data) { diff -r 86d729874ff4 -r a4f4123ca12a ui/gtk/container.h --- a/ui/gtk/container.h Sat Jan 23 18:37:30 2016 +0100 +++ b/ui/gtk/container.h Sat Jan 23 20:47:07 2016 +0100 @@ -57,8 +57,8 @@ UiLayoutBool fill; UiBool newline; char *label; - UiLayoutBool hexpand; - UiLayoutBool vexpand; + UiBool hexpand; + UiBool vexpand; }; struct UiContainer { diff -r 86d729874ff4 -r a4f4123ca12a ui/gtk/window.c --- a/ui/gtk/window.c Sat Jan 23 18:37:30 2016 +0100 +++ b/ui/gtk/window.c Sat Jan 23 20:47:07 2016 +0100 @@ -57,7 +57,7 @@ } } -UiObject* ui_window(char *title, void *window_data) { +static UiObject* create_window(char *title, void *window_data, UiBool simple) { UcxMempool *mp = ucx_mempool_new(256); UiObject *obj = ucx_mempool_calloc(mp, 1, sizeof(UiObject)); obj->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); @@ -90,16 +90,18 @@ GtkWidget *vbox = ui_gtk_vbox_new(); gtk_container_add(GTK_CONTAINER(obj->widget), vbox); - // menu - GtkWidget *mb = ui_create_menubar(obj); - if(mb) { - gtk_box_pack_start(GTK_BOX(vbox), mb, FALSE, FALSE, 0); - } - - // toolbar - GtkWidget *tb = ui_create_toolbar(obj); - if(tb) { - gtk_box_pack_start(GTK_BOX(vbox), tb, FALSE, FALSE, 0); + if(!simple) { + // menu + GtkWidget *mb = ui_create_menubar(obj); + if(mb) { + gtk_box_pack_start(GTK_BOX(vbox), mb, FALSE, FALSE, 0); + } + + // toolbar + GtkWidget *tb = ui_create_toolbar(obj); + if(tb) { + gtk_box_pack_start(GTK_BOX(vbox), tb, FALSE, FALSE, 0); + } } // window content @@ -116,6 +118,15 @@ return obj; } + +UiObject* ui_window(char *title, void *window_data) { + return create_window(title, window_data, FALSE); +} + +UiObject* ui_simplewindow(char *title, void *window_data) { + return create_window(title, window_data, TRUE); +} + static char* ui_gtkfilechooser(UiObject *obj, GtkFileChooserAction action) { char *button; char *title; diff -r 86d729874ff4 -r a4f4123ca12a ui/motif/container.c --- a/ui/motif/container.c Sat Jan 23 18:37:30 2016 +0100 +++ b/ui/motif/container.c Sat Jan 23 20:47:07 2016 +0100 @@ -370,7 +370,7 @@ } UIWIDGET ui_grid(UiObject *obj) { - return ui_grid_sp(obj, 0, 0); + return ui_grid_sp(obj, 0, 0, 0); } UIWIDGET ui_grid_sp(UiObject *obj, int margin, int columnspacing, int rowspacing) { @@ -725,6 +725,16 @@ ct->layout.fill = ui_bool2lb(fill); } +void ui_layout_hexpand(UiObject *obj, UiBool expand) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.hexpand = expand; +} + +void ui_layout_vexpand(UiObject *obj, UiBool expand) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.vexpand = expand; +} + void ui_newline(UiObject *obj) { UiContainer *ct = uic_get_current_container(obj); ct->layout.newline = TRUE; diff -r 86d729874ff4 -r a4f4123ca12a ui/motif/container.h --- a/ui/motif/container.h Sat Jan 23 18:37:30 2016 +0100 +++ b/ui/motif/container.h Sat Jan 23 20:47:07 2016 +0100 @@ -30,7 +30,7 @@ #define CONTAINER_H #include "../ui/toolkit.h" -#include +#include "../../ucx/list.h" #include #ifdef __cplusplus diff -r 86d729874ff4 -r a4f4123ca12a ui/motif/window.c --- a/ui/motif/window.c Sat Jan 23 18:37:30 2016 +0100 +++ b/ui/motif/window.c Sat Jan 23 20:47:07 2016 +0100 @@ -48,7 +48,7 @@ } } -UiObject* ui_window(char *title, void *window_data) { +static UiObject* create_window(char *title, void *window_data, UiBool simple) { UcxMempool *mp = ucx_mempool_new(256); UiObject *obj = ucx_mempool_calloc(mp, 1, sizeof(UiObject)); obj->ctx = uic_context(obj, mp); @@ -87,24 +87,23 @@ // TODO: use callback ui_set_active_window(toplevel); - // menu Widget window = XtVaCreateManagedWidget( title, xmMainWindowWidgetClass, toplevel, NULL); obj->widget = window; - ui_create_menubar(obj); - - // toolbar Widget form = XtVaCreateManagedWidget( "window_form", xmFormWidgetClass, window, NULL); + Widget toolbar = NULL; - Widget toolbar = ui_create_toolbar(obj, form); - + if(!simple) { + ui_create_menubar(obj); + toolbar = ui_create_toolbar(obj, form); + } // window content XtSetArg(args[0], XmNshadowType, XmSHADOW_ETCHED_OUT); @@ -134,6 +133,14 @@ return obj; } +UiObject* ui_window(char *title, void *window_data) { + return create_window(title, window_data, FALSE); +} + +UiObject* ui_simplewindow(char *title, void *window_data) { + return create_window(title, window_data, TRUE); +} + void ui_close(UiObject *obj) { XtDestroyWidget(obj->widget); window_close_handler(obj->widget, obj, NULL); diff -r 86d729874ff4 -r a4f4123ca12a ui/qt/window.cpp --- a/ui/qt/window.cpp Sat Jan 23 18:37:30 2016 +0100 +++ b/ui/qt/window.cpp Sat Jan 23 20:47:07 2016 +0100 @@ -35,8 +35,9 @@ #include "container.h" #include +#include -UiObject* ui_window(char *title, void *window_data) { +static UiObject* create_window(char *title, void *window_data, bool simple) { UcxMempool *mp = ucx_mempool_new(256); UiObject *obj = (UiObject*)ucx_mempool_calloc(mp, 1, sizeof(UiObject)); obj->ctx = uic_context(obj, mp); @@ -46,10 +47,11 @@ QMainWindow *window = new QMainWindow(); obj->widget = window; - ui_add_menus(obj, window); - - QToolBar *toolbar = ui_create_toolbar(obj); - window->addToolBar(Qt::TopToolBarArea, toolbar); + if(!simple) { + ui_add_menus(obj, window); + QToolBar *toolbar = ui_create_toolbar(obj); + window->addToolBar(Qt::TopToolBarArea, toolbar); + } QBoxLayout *box = new QVBoxLayout(); QWidget *boxWidget = new QWidget(); @@ -60,3 +62,34 @@ obj->widget = window; return obj; } + +UiObject* ui_window(char *title, void *window_data) { + return create_window(title, window_data, FALSE); +} + +UiObject* ui_simplewindow(char *title, void *window_data) { + return create_window(title, window_data, TRUE); +} + + +char* ui_openfiledialog(UiObject *obj) { + QString fileName = QFileDialog::getOpenFileName(obj->widget); + if(fileName.size() > 0) { + QByteArray array = fileName.toLocal8Bit(); + const char *cstr = array.constData(); + return strdup(cstr); + } else { + return NULL; + } +} + +char* ui_savefiledialog(UiObject *obj) { + QString fileName = QFileDialog::getSaveFileName(obj->widget); + if(fileName.size() > 0) { + QByteArray array = fileName.toLocal8Bit(); + const char *cstr = array.constData(); + return strdup(cstr); + } else { + return NULL; + } +} diff -r 86d729874ff4 -r a4f4123ca12a ui/ui/window.h --- a/ui/ui/window.h Sat Jan 23 18:37:30 2016 +0100 +++ b/ui/ui/window.h Sat Jan 23 20:47:07 2016 +0100 @@ -36,6 +36,8 @@ #endif UiObject* ui_window(char *title, void *window_data); +UiObject* ui_simplewindow(char *title, void *window_data); + char* ui_openfiledialog(UiObject *obj); char* ui_savefiledialog(UiObject *obj);