Mercurial > dwindows
diff win/dw.c @ 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 | 91bdd9840b9f |
children | 5e4ced521696 |
line wrap: on
line diff
--- 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,