changeset 33995:9c2779f24077

Move common code to new function wsWindowPosition(). Use the new function in wsCreateWindow() and wsMoveWindow().
author ib
date Thu, 08 Sep 2011 13:30:50 +0000
parents 8e5680eccf54
children acf8545dc4b5
files gui/wm/ws.c
diffstat 1 files changed, 43 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/gui/wm/ws.c	Thu Sep 08 12:34:28 2011 +0000
+++ b/gui/wm/ws.c	Thu Sep 08 13:30:50 2011 +0000
@@ -377,6 +377,46 @@
     }
 }
 
+/**
+ * @brief Calculate and store the x and y position for a window.
+ *
+ * @param win pointer to a ws window structure
+ * @param x x position of the window (real/absolute or mock)
+ * @param y y position of the window (real/absolute or mock)
+ * @param width width of the area to place the window in
+ * @param height height of the area to place the window in
+ */
+static void wsWindowPosition(wsTWindow *win, int x, int y, int width, int height)
+{
+    switch (x) {
+    case -1:
+        win->X = wsOrgX + (wsMaxX - width) / 2;
+        break;
+
+    case -2:
+        win->X = wsOrgX + wsMaxX - width;
+        break;
+
+    default:
+        win->X = x;
+        break;
+    }
+
+    switch (y) {
+    case -1:
+        win->Y = wsOrgY + (wsMaxY - height) / 2;
+        break;
+
+    case -2:
+        win->Y = wsOrgY + wsMaxY - height;
+        break;
+
+    default:
+        win->Y = y;
+        break;
+    }
+}
+
 // ----------------------------------------------------------------------------------------------
 //   Create window.
 //     X,Y   : window position
@@ -402,34 +442,7 @@
 
     wsHGC = DefaultGC(wsDisplay, wsScreen);
 
-// The window position and size.
-    switch (X) {
-    case -1:
-        win->X = (wsMaxX / 2) - (wX / 2) + wsOrgX;
-        break;
-
-    case -2:
-        win->X = wsMaxX - wX - 1 + wsOrgX;
-        break;
-
-    default:
-        win->X = X;
-        break;
-    }
-
-    switch (Y) {
-    case -1:
-        win->Y = (wsMaxY / 2) - (hY / 2) + wsOrgY;
-        break;
-
-    case -2:
-        win->Y = wsMaxY - hY - 1 + wsOrgY;
-        break;
-
-    default:
-        win->Y = Y;
-        break;
-    }
+    wsWindowPosition(win, X, Y, wX, hY);
 
     win->Width     = wX;
     win->Height    = hY;
@@ -1060,35 +1073,8 @@
     if (abs) {
         win->X = x;
         win->Y = y;
-    } else {
-        switch (x) {
-        case -1:
-            win->X = (wsMaxX / 2) - (win->Width / 2) + wsOrgX;
-            break;
-
-        case -2:
-            win->X = wsMaxX - win->Width + wsOrgX;
-            break;
-
-        default:
-            win->X = x;
-            break;
-        }
-
-        switch (y) {
-        case -1:
-            win->Y = (wsMaxY / 2) - (win->Height / 2) + wsOrgY;
-            break;
-
-        case -2:
-            win->Y = wsMaxY - win->Height + wsOrgY;
-            break;
-
-        default:
-            win->Y = y;
-            break;
-        }
-    }
+    } else
+        wsWindowPosition(win, x, y, win->Width, win->Height);
 
     win->SizeHint.flags       = PPosition | PWinGravity;
     win->SizeHint.x           = win->X;