adds new app callbacks (Motif)

Sun, 22 Jan 2017 11:48:50 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 22 Jan 2017 11:48:50 +0100
changeset 134
69e8e0936858
parent 133
6dd780cbc8c6
child 135
b9dc9cdfa23a

adds new app callbacks (Motif)

ui/gtk/toolkit.c file | annotate | diff | comparison | revisions
ui/gtk/toolkit.h file | annotate | diff | comparison | revisions
ui/gtk/window.c file | annotate | diff | comparison | revisions
ui/motif/toolkit.c file | annotate | diff | comparison | revisions
--- a/ui/gtk/toolkit.c	Sun Jan 22 11:16:21 2017 +0100
+++ b/ui/gtk/toolkit.c	Sun Jan 22 11:48:50 2017 +0100
@@ -42,7 +42,9 @@
 
 #include <pthread.h>
 
+#ifndef UI_GTK2
 static GtkApplication *app;
+#endif
 
 static char *application_name;
 
@@ -93,16 +95,20 @@
 }
 
 
+#ifndef UI_GTK2
 static void app_startup(GtkApplication* app, gpointer userdata) {
-    startup_func(NULL, startup_data);
+    if(startup_func) {
+        startup_func(NULL, startup_data);
+    }
 }
 
 static void app_activate(GtkApplication* app, gpointer userdata) {
     printf("activate\n");
 }
+#endif
 
 void ui_main() {
-#ifndef GTK2_LEGACY
+#ifndef UI_GTK2
     sstr_t appid = ucx_sprintf(
             "ui.%s",
             application_name ? application_name : "application1");
@@ -117,14 +123,18 @@
     
     free(appid.ptr);
 #else
+    if(startup_func) {
+        startup_func(NULL, startup_data);
+    }
     gtk_main();
 #endif
-    if(appclose_fnc) {
-        appclose_fnc(NULL, appclose_udata);
+    if(exit_func) {
+        exit_func(NULL, exit_data);
     }
     uic_store_app_properties();
 }
 
+#ifndef UI_GTK2
 void ui_app_quit() {
     g_application_quit(G_APPLICATION(app));
 }
@@ -132,6 +142,7 @@
 GtkApplication* ui_get_application() {
     return app;
 }
+#endif
 
 void ui_show(UiObject *obj) {
     uic_check_group_widgets(obj->ctx);
--- a/ui/gtk/toolkit.h	Sun Jan 22 11:16:21 2017 +0100
+++ b/ui/gtk/toolkit.h	Sun Jan 22 11:48:50 2017 +0100
@@ -55,8 +55,10 @@
 typedef enum UiOrientation UiOrientation;
 enum UiOrientation { UI_HORIZONTAL = 0, UI_VERTICAL };
 
+#ifndef UI_GTK2
 void ui_app_quit();
 GtkApplication* ui_get_application();
+#endif
 
 void ui_destroy_userdata(GtkWidget *object, void *userdata);
 
--- a/ui/gtk/window.c	Sun Jan 22 11:16:21 2017 +0100
+++ b/ui/gtk/window.c	Sun Jan 22 11:48:50 2017 +0100
@@ -58,7 +58,7 @@
     // TODO: free UiObject
     
     nwindows--;
-#ifdef GTK2_LEGACY
+#ifdef UI_GTK2
     if(nwindows == 0) {
         gtk_main_quit();
     }
@@ -69,7 +69,7 @@
     UcxMempool *mp = ucx_mempool_new(256);
     UiObject *obj = ucx_mempool_calloc(mp, 1, sizeof(UiObject)); 
     
-#ifndef GTK2_LEGACY
+#ifndef UI_GTK2
     obj->widget = gtk_application_window_new(ui_get_application());
 #else
     obj->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
--- a/ui/motif/toolkit.c	Sun Jan 22 11:16:21 2017 +0100
+++ b/ui/motif/toolkit.c	Sun Jan 22 11:48:50 2017 +0100
@@ -43,6 +43,13 @@
 static Widget active_window;
 static char *application_name;
 
+static ui_callback   startup_func;
+static void          *startup_data;
+static ui_callback   open_func;
+void                 *open_data;
+static ui_callback   exit_func;
+void                 *exit_data;
+
 static ui_callback appclose_fnc;
 static void *appclose_udata;
 
@@ -134,19 +141,28 @@
     return display;
 }
 
-void ui_exitfunc(ui_callback f, void *udata) {
-    appclose_fnc = f;
-    appclose_udata = udata;
+void ui_onstartup(ui_callback f, void *userdata) {
+    startup_func = f;
+    startup_data = userdata;
 }
 
-void ui_openfilefunc(ui_callback f, void *userdata) {
-    // OS X only
+void ui_onopen(ui_callback f, void *userdata) {
+    open_func = f;
+    open_data = userdata;
+}
+
+void ui_onexit(ui_callback f, void *userdata) {
+    exit_func = f;
+    exit_data = userdata;
 }
 
 void ui_main() {
+    if(startup_func) {
+        startup_func(NULL, startup_data);
+    }
     XtAppMainLoop(app);
-    if(appclose_fnc) {
-        appclose_fnc(NULL, appclose_udata);
+    if(exit_func) {
+        exit_func(NULL, exit_data);
     }
     uic_store_app_properties();
 }

mercurial