ui/motif/Grid.c

changeset 101
7b3a3130be44
parent 100
d2bd73d28ff1
--- a/ui/motif/Grid.c	Thu Dec 12 20:01:43 2024 +0100
+++ b/ui/motif/Grid.c	Mon Jan 06 22:22:55 2025 +0100
@@ -52,6 +52,39 @@
 <EnterWindow>:		getfocus()\n\
 <LeaveWindow>:          loosefocus()\n";
 
+static XtResource resources[] =
+{
+    {
+        gridColumnSpacing,
+        gridColumnSpacing,
+        XmRDimension,
+        sizeof (Dimension),
+        XtOffsetOf( GridRec,
+                   mywidget.columnspacing),
+        XmRImmediate,
+        (XtPointer) 0
+    },
+    {
+        gridRowSpacing,
+        gridRowSpacing,
+        XmRDimension,
+        sizeof (Dimension),
+        XtOffsetOf( GridRec,
+                   mywidget.rowspacing),
+        XmRImmediate,
+        (XtPointer) 0
+    },
+    {
+        gridMargin,
+        gridMargin,
+        XmRDimension,
+        sizeof (Dimension),
+        XtOffsetOf( GridRec,
+                   mywidget.margin),
+        XmRImmediate,
+        (XtPointer) 0
+    }
+};
 
 ///*
 static XtResource constraints[] =
@@ -175,11 +208,19 @@
                    grid.vfill),
         XmRImmediate,
         (XtPointer) 0
+    },
+    {
+        gridMinWidth,
+        gridMinWidth,
+        XmRDimension,
+        sizeof (Dimension),
+        XtOffsetOf( GridConstraintRec,
+                   grid.min_width),
+        XmRImmediate,
+        (XtPointer) 0
     }
-    
 };
 //*/
-//static XtResource constraints[] = {};
 
 GridClassRec gridClassRec = {
     // Core Class
@@ -187,17 +228,17 @@
         //(WidgetClass)&constraintClassRec,   // superclass  
         (WidgetClass)&xmManagerClassRec,
         "Grid",                       // class_name
-        sizeof(GridRec),          // widget_size
-        grid_class_initialize,    // class_initialize
+        sizeof(GridRec),              // widget_size
+        grid_class_initialize,        // class_initialize
         NULL,                         // class_part_initialize
         FALSE,                        // class_inited
-        (XtInitProc)grid_initialize,          // initialize
+        (XtInitProc)grid_initialize,  // initialize
         NULL,                         // initialize_hook
-        grid_realize,             // realize
-        actionslist,                         // actions
-        XtNumber(actionslist),                            // num_actions
-        NULL,                         // resources
-        0,                            // num_resources
+        grid_realize,                 // realize
+        actionslist,                  // actions
+        XtNumber(actionslist),        // num_actions
+        resources,                    // resources
+        XtNumber(resources),          // num_resources
         NULLQUARK,                    // xrm_class
         True,                         // compress_motion
         True,                         // compress_exposure
@@ -240,12 +281,12 @@
     // XmManager Class
     ///*
     {
-        NULL,
+        XtInheritTranslations,
         NULL,
         0,
         NULL,
         0,
-        NULL,
+        XmInheritParentProcess,
         NULL
     },
     //*/
@@ -367,6 +408,8 @@
     int req_width = 0;
     int req_height = 0;
     
+    //printf("container width: %d\n", (int)w->core.width);
+    
     // calculate the minimum size requirements for all columns and rows
     // we need to run this 2 times: for widgets without colspan/rowspan first
     // and then again for colspan/rowspan > 1
@@ -375,6 +418,15 @@
         for(int i=0;i<w->composite.num_children;i++) {
             Widget child = w->composite.children[i];
             GridConstraintRec *constraints = child->core.constraints;
+            if(constraints->grid.pref_width == 0) {
+                constraints->grid.pref_width = child->core.width;
+            }
+            if(constraints->grid.pref_height == 0) {
+                constraints->grid.pref_height = child->core.height;
+            }
+            if(constraints->grid.pref_width < constraints->grid.min_width) {
+                constraints->grid.pref_width = constraints->grid.min_width;
+            }
             
             if(constraints->grid.colspan > span_max || constraints->grid.rowspan > span_max) {
                 continue;
@@ -463,7 +515,7 @@
         span_max = 50000; // not sure if this is unreasonable low or high
     }
     
-    
+    // calc required size
     for(int i=0;i<ncols;i++) {
         if(cols[i].expand) {
             num_cols_expanding++;
@@ -478,6 +530,10 @@
     }
     
     if(req_width > 0 && req_height > 0) {
+        // add col/row spacing
+        req_width += (ncols-1)*w->mywidget.columnspacing;
+        req_height += (nrows-1)*w->mywidget.rowspacing;
+        
         Widget parent = w->core.parent;
         Dimension rwidth = req_width;
         Dimension rheight = req_height;
@@ -491,6 +547,13 @@
         if(!w->mywidget.sizerequest) {
             Dimension actual_width, actual_height;
             w->mywidget.sizerequest = TRUE;
+            
+            //XtWidgetGeometry request;
+            //request.width = req_width;
+            //request.request_mode = CWWidth;
+            //XtWidgetGeometry reply;
+            //XtGeometryResult result = XtMakeGeometryRequest((Widget)w, &request, &reply);
+            
             XtMakeResizeRequest((Widget)w, req_width, req_height, &actual_width, &actual_height);
             w->mywidget.sizerequest = FALSE;
             //printf("size request: %d %d\n", (int)actual_width, (int)actual_height);
@@ -500,6 +563,7 @@
         
     }
     
+    // how much space can we add to each expanding col/row
     int hexpand = 0;
     int width_diff = (int)w->core.width - req_width;
     int hexpand2 = 0;
@@ -513,7 +577,7 @@
         if(cols[i].expand) {
             cols[i].size += hexpand + hexpand2;
         }
-        x += cols[i].size;
+        x += cols[i].size + w->mywidget.columnspacing;
         
         hexpand2 = 0;
     }
@@ -531,7 +595,7 @@
         if(rows[i].expand) {
             rows[i].size += vexpand + vexpand2;
         }
-        y += rows[i].size;
+        y += rows[i].size += w->mywidget.rowspacing;
         
         vexpand2 = 0;
     }
@@ -550,12 +614,12 @@
                 Dimension cwidth = 0;
                 for(int j=0;j<constraints->grid.colspan;j++) {
                     if(constraints->grid.x+j < ncols) {
-                        cwidth += cols[constraints->grid.x+j].size;
+                        cwidth += cols[constraints->grid.x+j].size + (j > 0 ? w->mywidget.columnspacing : 0);
                     }
                 }
                 width = cwidth;
             } else {
-                width = c.size;
+                width = c.size - w->mywidget.columnspacing;
             }
         }
         if(constraints->grid.vfill) {
@@ -563,16 +627,18 @@
                 Dimension cheight = 0;
                 for(int j=0;j<constraints->grid.rowspan;j++) {
                     if(constraints->grid.y+j < nrows) {
-                        cheight += rows[constraints->grid.y+j].size;
+                        cheight += rows[constraints->grid.y+j].size + (j > 0 ? w->mywidget.rowspacing : 0);
                     }
                 }
                 height = cheight;
             } else {
-                height = r.size;
+                height = r.size - w->mywidget.rowspacing;
             }
         }
         
-        XtConfigureWidget(child, x, y, width, height, child->core.border_width);
+        if(width > 0 && height > 0) {
+            XtConfigureWidget(child, x, y, width, height, child->core.border_width);
+        }
         //printf("child %d %d - %d %d\n", (int)child->core.x, (int)child->core.y, (int)child->core.width, (int)child->core.height);
     }
     

mercurial