changeset 1472:1794caee0758

Initial versions of dw_window_set_gravity for Windows and OS/2. Fixed an error in the gravity calculation for bottom on GTK.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 20 Dec 2011 16:10:13 +0000
parents 26dbd11399d6
children 4468ac1db710
files gtk/dw.c gtk3/dw.c os2/dw.c os2/dw.def os2/dw.lnk win/dw-mingw.def win/dw.c win/dw.def
diffstat 8 files changed, 94 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/dw.c	Tue Dec 20 15:05:14 2011 +0000
+++ b/gtk/dw.c	Tue Dec 20 16:10:13 2011 +0000
@@ -10431,7 +10431,7 @@
             if((vert & 0xf) == DW_GRAV_CENTER)
                newy += ((gdk_screen_height() / 2) - (height / 2));
             else if((vert & 0xf) == DW_GRAV_BOTTOM)
-               newy = gdk_screen_height() - height - x;
+               newy = gdk_screen_height() - height - y;
          }            
          if(GTK_WIDGET_MAPPED(handle))
          {
--- a/gtk3/dw.c	Tue Dec 20 15:05:14 2011 +0000
+++ b/gtk3/dw.c	Tue Dec 20 16:10:13 2011 +0000
@@ -8809,7 +8809,7 @@
             if((vert & 0xf) == DW_GRAV_CENTER)
                newy += ((gdk_screen_height() / 2) - (height / 2));
             else if((vert & 0xf) == DW_GRAV_BOTTOM)
-               newy = gdk_screen_height() - height - x;
+               newy = gdk_screen_height() - height - y;
          }            
          /* Finally move the window into place */
          gtk_window_move(GTK_WINDOW(handle), newx, newy);
--- a/os2/dw.c	Tue Dec 20 15:05:14 2011 +0000
+++ b/os2/dw.c	Tue Dec 20 16:10:13 2011 +0000
@@ -6907,7 +6907,7 @@
       _get_window_for_size(handle, &width, &height);
    
    /* Finally set the size */
-   WinSetWindowPos(handle, NULLHANDLE, 0, 0, width, height, SWP_SHOW | SWP_SIZE);
+   WinSetWindowPos(handle, NULLHANDLE, 0, 0, width, height, SWP_SIZE);
 }
 
 /*
@@ -6949,6 +6949,34 @@
    return colors;
 }
 
+/* Convert the coordinates based on gravity */
+void _handle_gravity(HWND handle, long *x, long *y, unsigned long width, unsigned long height)
+{
+   int horz = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_horz"));
+   int vert = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_vert"));
+   
+   /* Do any gravity calculations */
+   if(horz || (vert & 0xf) != DW_GRAV_BOTTOM)
+   {
+      long newx = *x, newy = *y;
+   
+      /* Handle horizontal center gravity */
+      if((horz & 0xf) == DW_GRAV_CENTER)
+         newx += ((dw_screen_width() / 2) - (width / 2));
+      /* Handle right gravity */
+      else if((horz & 0xf) == DW_GRAV_RIGHT)
+         newx = dw_screen_width() - width - *x;
+      /* Handle vertical center gravity */
+      if((vert & 0xf) == DW_GRAV_CENTER)
+         newy += ((dw_screen_height() / 2) - (height / 2));
+      else if((vert & 0xf) == DW_GRAV_TOP)
+         newy = dw_screen_height() - height - *y;
+        
+      /* Save the new values */
+      *x = newx;
+      *y = newy;
+   }            
+}
 
 /*
  * Sets the position of a given window (widget).
@@ -6959,9 +6987,11 @@
  */
 void API dw_window_set_pos(HWND handle, LONG x, LONG y)
 {
-   int myy = _get_frame_height(handle) - (y + _get_height(handle));
-
-   WinSetWindowPos(handle, NULLHANDLE, x, myy, 0, 0, SWP_MOVE);
+   unsigned long width, height;
+   
+   dw_window_get_pos_size(handle, NULL, NULL, &width, &height);
+   _handle_gravity(handle, &x, &y, width, height);
+   WinSetWindowPos(handle, NULLHANDLE, x, y, 0, 0, SWP_MOVE);
 }
 
 /*
@@ -6975,14 +7005,13 @@
  */
 void API dw_window_set_pos_size(HWND handle, LONG x, LONG y, ULONG width, ULONG height)
 {
-   int myy = _get_frame_height(handle) - (y + height);
-
    /* Attempt to auto-size */
    if ( width < 1 || height < 1 )
       _get_window_for_size(handle, &width, &height);
    
+   _handle_gravity(handle, &x, &y, width, height);
    /* Finally set the size */
-   WinSetWindowPos(handle, NULLHANDLE, x, myy, width, height, SWP_MOVE | SWP_SIZE | SWP_SHOW);
+   WinSetWindowPos(handle, NULLHANDLE, x, y, width, height, SWP_MOVE | SWP_SIZE);
 }
 
 /*
--- a/os2/dw.def	Tue Dec 20 15:05:14 2011 +0000
+++ b/os2/dw.def	Tue Dec 20 16:10:13 2011 +0000
@@ -69,6 +69,7 @@
   dw_window_get_font                     @82
   dw_window_set_tooltip                  @83
   dw_window_get_preferred_size           @84
+  dw_window_set_gravity                  @85
 
   dw_button_new                          @90
   dw_bitmapbutton_new                    @91
--- a/os2/dw.lnk	Tue Dec 20 15:05:14 2011 +0000
+++ b/os2/dw.lnk	Tue Dec 20 16:10:13 2011 +0000
@@ -62,6 +62,7 @@
 export dw_window_get_font.82
 export dw_window_set_tooltip.83
 export dw_window_get_preferred_size.84
+export dw_window_set_gravity.85
 
 export dw_button_new.90
 export dw_bitmapbutton_new.91
--- a/win/dw-mingw.def	Tue Dec 20 15:05:14 2011 +0000
+++ b/win/dw-mingw.def	Tue Dec 20 16:10:13 2011 +0000
@@ -66,6 +66,7 @@
   dw_window_get_font                     @82
   dw_window_set_tooltip                  @83
   dw_window_get_preferred_size           @84
+  dw_window_set_gravity                  @85
 
   dw_button_new                          @90
   dw_bitmapbutton_new                    @91
--- a/win/dw.c	Tue Dec 20 15:05:14 2011 +0000
+++ b/win/dw.c	Tue Dec 20 16:10:13 2011 +0000
@@ -169,7 +169,6 @@
 
 HBRUSH _colors[18];
 
-static int screenx, screeny;
 HFONT _DefaultFont = NULL;
 
 #if (defined(BUILD_DLL) || defined(BUILD_HTML)) && !defined(__MINGW32__)
@@ -3686,13 +3685,6 @@
    {
       strncpy( _dw_alternate_temp_dir, alttmpdir, MAX_PATH );
    }
-   /*
-    * Get screen size. Used to make calls to dw_screen_width()
-    * and dw_screen-height() quicker, but to alos limit the
-    * default size of windows.
-    */
-   screenx = GetSystemMetrics(SM_CXSCREEN);
-   screeny = GetSystemMetrics(SM_CYSCREEN);
 
 #ifdef GDIPLUS
    /* Setup GDI+ */
@@ -6589,7 +6581,7 @@
       _get_window_for_size(handle, &width, &height);
    
    /* Finally set the size */
-   SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOMOVE);
+   SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_NOZORDER | SWP_NOMOVE);
 }
 
 /*
@@ -6609,7 +6601,7 @@
  */
 int API dw_screen_width(void)
 {
-   return screenx;
+   return GetSystemMetrics(SM_CXSCREEN);
 }
 
 /*
@@ -6617,7 +6609,7 @@
  */
 int API dw_screen_height(void)
 {
-   return screeny;
+   return GetSystemMetrics(SM_CYSCREEN);
 }
 
 /* This should return the current color depth */
@@ -6633,6 +6625,48 @@
    return bpp;
 }
 
+/*
+ * Sets the gravity of a given window (widget).
+ * Gravity controls which corner of the screen and window the position is relative to.
+ * Parameters:
+ *          handle: Window (widget) handle.
+ *          horz: DW_GRAV_LEFT (default), DW_GRAV_RIGHT or DW_GRAV_CENTER.
+ *          vert: DW_GRAV_TOP (default), DW_GRAV_BOTTOM or DW_GRAV_CENTER.
+ */
+void API dw_window_set_gravity(HWND handle, int horz, int vert)
+{
+   dw_window_set_data(handle, "_dw_grav_horz", DW_INT_TO_POINTER(horz));
+   dw_window_set_data(handle, "_dw_grav_vert", DW_INT_TO_POINTER(vert));
+}
+
+/* Convert the coordinates based on gravity */
+void _handle_gravity(HWND handle, long *x, long *y, unsigned long width, unsigned long height)
+{
+   int horz = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_horz"));
+   int vert = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_vert"));
+   
+   /* Do any gravity calculations */
+   if(horz || vert)
+   {
+      long newx = *x, newy = *y;
+   
+      /* Handle horizontal center gravity */
+      if((horz & 0xf) == DW_GRAV_CENTER)
+         newx += ((dw_screen_width() / 2) - (width / 2));
+      /* Handle right gravity */
+      else if((horz & 0xf) == DW_GRAV_RIGHT)
+         newx = dw_screen_width() - width - *x;
+      /* Handle vertical center gravity */
+      if((vert & 0xf) == DW_GRAV_CENTER)
+         newy += ((dw_screen_height() / 2) - (height / 2));
+      else if((vert & 0xf) == DW_GRAV_BOTTOM)
+         newy = dw_screen_height() - height - *y;
+        
+      /* Save the new values */
+      *x = newx;
+      *y = newy;
+   }            
+}
 
 /*
  * Sets the position of a given window (widget).
@@ -6643,6 +6677,10 @@
  */
 void API dw_window_set_pos(HWND handle, long x, long y)
 {
+   unsigned long width, height;
+   
+   dw_window_get_pos_size(handle, NULL, NULL, &width, &height);
+   _handle_gravity(handle, &x, &y, width, height);
    SetWindowPos(handle, (HWND)NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
 }
 
@@ -6661,8 +6699,9 @@
    if ( width < 1 || height < 1 )
       _get_window_for_size(handle, &width, &height);
    
+   _handle_gravity(handle, &x, &y, width, height);
    /* Finally set the size */
-   SetWindowPos(handle, (HWND)NULL, x, y, width, height, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE);
+   SetWindowPos(handle, (HWND)NULL, x, y, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
 }
 
 /*
@@ -8913,7 +8952,7 @@
    HWND tmp = CreateWindow(ObjectClassName,
                      "",
                      WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
-                     0,0,screenx,screeny,
+                     0,0,0,0,
                      DW_HWND_OBJECT,
                      (HMENU)id,
                      DWInstance,
--- a/win/dw.def	Tue Dec 20 15:05:14 2011 +0000
+++ b/win/dw.def	Tue Dec 20 16:10:13 2011 +0000
@@ -66,6 +66,7 @@
   dw_window_get_font                     @82
   dw_window_set_tooltip                  @83
   dw_window_get_preferred_size           @84
+  dw_window_set_gravity                  @85
 
   dw_button_new                          @90
   dw_bitmapbutton_new                    @91