implement ui_window_size/ui_window_default_size (Motif)

Sun, 23 Nov 2025 10:39:51 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 23 Nov 2025 10:39:51 +0100
changeset 930
4ce8df2311f0
parent 929
43cb1ea4c582
child 931
6ca1ef6c8107

implement ui_window_size/ui_window_default_size (Motif)

ui/common/utils.c file | annotate | diff | comparison | revisions
ui/common/utils.h file | annotate | diff | comparison | revisions
ui/gtk/window.c file | annotate | diff | comparison | revisions
ui/motif/menu.c file | annotate | diff | comparison | revisions
ui/motif/menu.h file | annotate | diff | comparison | revisions
ui/motif/window.c file | annotate | diff | comparison | revisions
ui/motif/window.h file | annotate | diff | comparison | revisions
ui/ui/window.h file | annotate | diff | comparison | revisions
--- a/ui/common/utils.c	Sun Nov 23 10:23:10 2025 +0100
+++ b/ui/common/utils.c	Sun Nov 23 10:39:51 2025 +0100
@@ -27,6 +27,7 @@
  */
 
 #include "utils.h"
+#include "properties.h"
 
 #include <cx/string.h>
 
@@ -69,3 +70,16 @@
 
     return elms;
 }
+
+void ui_get_window_default_width(int *width, int *height) {
+    const char *width_str = ui_get_property("ui.window.width");
+    const char *height_str = ui_get_property("ui.window.height");
+    if(width_str && height_str) {
+        int w = atoi(width_str);
+        int h = atoi(height_str);
+        if(w > 0 && h > 0) {
+            *width = w;
+            *height = h;
+        }
+    }
+}
--- a/ui/common/utils.h	Sun Nov 23 10:23:10 2025 +0100
+++ b/ui/common/utils.h	Sun Nov 23 10:39:51 2025 +0100
@@ -37,6 +37,12 @@
 
 UiPathElm* ui_default_pathelm_func(const char* full_path, size_t len, size_t* ret_nelm, void* data);
 
+/*
+ * overrides width/height with values from
+ * ui.window.width and ui.window.height properties if available
+ */
+void ui_get_window_default_width(int *width, int *height);
+
 
 #ifdef __cplusplus
 }
--- a/ui/gtk/window.c	Sun Nov 23 10:23:10 2025 +0100
+++ b/ui/gtk/window.c	Sun Nov 23 10:39:51 2025 +0100
@@ -35,6 +35,7 @@
 #include "../common/context.h"
 #include "../common/menu.h"
 #include "../common/toolbar.h"
+#include "../common/utils.h"
 
 #include <cx/mempool.h>
 
@@ -169,16 +170,7 @@
     int window_width = window_default_width;
     int window_height = window_default_height;
     if(!simple) {
-        const char *width = ui_get_property("ui.window.width");
-        const char *height = ui_get_property("ui.window.height");
-        if(width && height) {
-            int w = atoi(width);
-            int h = atoi(height);
-            if(w > 0 && h > 0) {
-                window_width = w;
-                window_height = h;
-            }
-        }
+        ui_get_window_default_width(&window_width, &window_height);
     }
     gtk_window_set_default_size(
                 GTK_WINDOW(obj->widget),
--- a/ui/motif/menu.c	Sun Nov 23 10:23:10 2025 +0100
+++ b/ui/motif/menu.c	Sun Nov 23 10:39:51 2025 +0100
@@ -55,10 +55,10 @@
     /* UI_MENU_SEPARATOR       */ add_menuseparator_widget
 };
 
-void ui_create_menubar(UiObject *obj, Widget window) {
+Widget ui_create_menubar(UiObject *obj, Widget window) {
     UiMenu *menus_begin = uic_get_menu_list();
     if(!menus_begin) {
-        return;
+        return NULL;
     }
     
     Widget menubar = XmCreateMenuBar(window, "menubar", NULL, 0);
@@ -70,6 +70,8 @@
         add_menu_widget(menubar, 0, &menu->item, obj);
         ls = (UiMenu*)ls->item.next;
     }
+    
+    return menubar;
 }
 
 void ui_add_menu_items(Widget parent, int i, UiMenu *menu, UiObject *obj) {
--- a/ui/motif/menu.h	Sun Nov 23 10:23:10 2025 +0100
+++ b/ui/motif/menu.h	Sun Nov 23 10:39:51 2025 +0100
@@ -52,7 +52,7 @@
     
 typedef void(*ui_menu_add_f)(Widget, int, UiMenuItemI*, UiObject*);
     
-void ui_create_menubar(UiObject *obj, Widget window);
+Widget ui_create_menubar(UiObject *obj, Widget window);
 void ui_add_menu_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj);
 
 void add_menu_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj);
--- a/ui/motif/window.c	Sun Nov 23 10:23:10 2025 +0100
+++ b/ui/motif/window.c	Sun Nov 23 10:39:51 2025 +0100
@@ -32,13 +32,15 @@
 #include <limits.h>
 #include <unistd.h>
 
+#include "window.h"
+
 #include "toolkit.h"
 #include "menu.h"
 #include "toolbar.h"
 #include "container.h"
 #include "pathbar.h"
-#include "../ui/window.h"
 #include "../common/context.h"
+#include "../common/utils.h"
 
 #include "Grid.h"
 #include "Fsb.h"
@@ -79,13 +81,19 @@
     obj->window = window_data;
     obj->destroy = ui_window_widget_destroy;
     
+    int window_width = window_default_width;
+    int window_height = window_default_height;
+    if(!simple) {
+        ui_get_window_default_width(&window_width, &window_height);
+    }
+    
     Arg args[16];
     int n = 0;
     XtSetArg(args[n], XmNtitle, title); n++;
     XtSetArg(args[n], XmNminWidth, 100); n++;
     XtSetArg(args[n], XmNminHeight, 50); n++;
-    XtSetArg(args[n], XmNwidth, window_default_width); n++;
-    XtSetArg(args[n], XmNheight, window_default_height); n++;
+    XtSetArg(args[n], XmNwidth, window_width); n++;
+    XtSetArg(args[n], XmNheight, window_height); n++;
     
     Widget toplevel = XtAppCreateShell(
             ui_appname(),
@@ -148,6 +156,19 @@
     return create_window(title, window_data, TRUE);
 }
 
+void ui_window_size(UiObject *obj, int width, int height) {
+    XtVaSetValues(obj->widget, XmNwidth, width, XmNheight, height, NULL);
+}
+
+void ui_window_default_size(int width, int height) {
+    window_default_width = width;
+    window_default_height = height;
+}
+
+void ui_window_menubar_set_visible(UiObject *obj, UiBool visible) {
+    
+}
+
 static void filedialog_event(UiEventData *event, int result, UiFileList flist) {
     UiEvent evt;
     evt.obj = event->obj;
--- a/ui/motif/window.h	Sun Nov 23 10:23:10 2025 +0100
+++ b/ui/motif/window.h	Sun Nov 23 10:39:51 2025 +0100
@@ -29,11 +29,15 @@
 #ifndef WINDOW_H
 #define WINDOW_H
 
+#include "../ui/window.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-
+typedef struct UiMainWindow {
+    Widget menubar;
+} UiMainWindow;
 
 
 #ifdef __cplusplus
--- a/ui/ui/window.h	Sun Nov 23 10:23:10 2025 +0100
+++ b/ui/ui/window.h	Sun Nov 23 10:39:51 2025 +0100
@@ -83,6 +83,7 @@
 
 UIEXPORT void ui_window_size(UiObject *obj, int width, int height);
 UIEXPORT void ui_window_default_size(int width, int height);
+UIEXPORT void ui_window_menubar_set_visible(UiObject *obj, UiBool visible);
 
 UIEXPORT void ui_splitview_window_set_pos(UiObject *obj, int pos);
 UIEXPORT int ui_splitview_window_get_pos(UiObject *obj);

mercurial