Mercurial > dwindows
comparison 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 |
comparison
equal
deleted
inserted
replaced
1471:26dbd11399d6 | 1472:1794caee0758 |
---|---|
167 BYTE _blue[] = { 0x00, 0x00, 0x00, 0x00, 0xcc, 0xbb, 0xbb, 0xaa, 0x77, | 167 BYTE _blue[] = { 0x00, 0x00, 0x00, 0x00, 0xcc, 0xbb, 0xbb, 0xaa, 0x77, |
168 0x00, 0x00, 0x00, 0xff, 0xff, 0xee, 0xff, 0xaa, 0x00}; | 168 0x00, 0x00, 0x00, 0xff, 0xff, 0xee, 0xff, 0xaa, 0x00}; |
169 | 169 |
170 HBRUSH _colors[18]; | 170 HBRUSH _colors[18]; |
171 | 171 |
172 static int screenx, screeny; | |
173 HFONT _DefaultFont = NULL; | 172 HFONT _DefaultFont = NULL; |
174 | 173 |
175 #if (defined(BUILD_DLL) || defined(BUILD_HTML)) && !defined(__MINGW32__) | 174 #if (defined(BUILD_DLL) || defined(BUILD_HTML)) && !defined(__MINGW32__) |
176 LRESULT CALLBACK _browserWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); | 175 LRESULT CALLBACK _browserWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); |
177 #endif | 176 #endif |
3684 } | 3683 } |
3685 else | 3684 else |
3686 { | 3685 { |
3687 strncpy( _dw_alternate_temp_dir, alttmpdir, MAX_PATH ); | 3686 strncpy( _dw_alternate_temp_dir, alttmpdir, MAX_PATH ); |
3688 } | 3687 } |
3689 /* | |
3690 * Get screen size. Used to make calls to dw_screen_width() | |
3691 * and dw_screen-height() quicker, but to alos limit the | |
3692 * default size of windows. | |
3693 */ | |
3694 screenx = GetSystemMetrics(SM_CXSCREEN); | |
3695 screeny = GetSystemMetrics(SM_CYSCREEN); | |
3696 | 3688 |
3697 #ifdef GDIPLUS | 3689 #ifdef GDIPLUS |
3698 /* Setup GDI+ */ | 3690 /* Setup GDI+ */ |
3699 si.GdiplusVersion = 1; | 3691 si.GdiplusVersion = 1; |
3700 si.DebugEventCallback = NULL; | 3692 si.DebugEventCallback = NULL; |
6587 /* Attempt to auto-size */ | 6579 /* Attempt to auto-size */ |
6588 if ( width < 1 || height < 1 ) | 6580 if ( width < 1 || height < 1 ) |
6589 _get_window_for_size(handle, &width, &height); | 6581 _get_window_for_size(handle, &width, &height); |
6590 | 6582 |
6591 /* Finally set the size */ | 6583 /* Finally set the size */ |
6592 SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOMOVE); | 6584 SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_NOZORDER | SWP_NOMOVE); |
6593 } | 6585 } |
6594 | 6586 |
6595 /* | 6587 /* |
6596 * Gets the size the system thinks the widget should be. | 6588 * Gets the size the system thinks the widget should be. |
6597 * Parameters: | 6589 * Parameters: |
6607 /* | 6599 /* |
6608 * Returns the width of the screen. | 6600 * Returns the width of the screen. |
6609 */ | 6601 */ |
6610 int API dw_screen_width(void) | 6602 int API dw_screen_width(void) |
6611 { | 6603 { |
6612 return screenx; | 6604 return GetSystemMetrics(SM_CXSCREEN); |
6613 } | 6605 } |
6614 | 6606 |
6615 /* | 6607 /* |
6616 * Returns the height of the screen. | 6608 * Returns the height of the screen. |
6617 */ | 6609 */ |
6618 int API dw_screen_height(void) | 6610 int API dw_screen_height(void) |
6619 { | 6611 { |
6620 return screeny; | 6612 return GetSystemMetrics(SM_CYSCREEN); |
6621 } | 6613 } |
6622 | 6614 |
6623 /* This should return the current color depth */ | 6615 /* This should return the current color depth */ |
6624 unsigned long API dw_color_depth_get(void) | 6616 unsigned long API dw_color_depth_get(void) |
6625 { | 6617 { |
6631 ReleaseDC(HWND_DESKTOP, hdc); | 6623 ReleaseDC(HWND_DESKTOP, hdc); |
6632 | 6624 |
6633 return bpp; | 6625 return bpp; |
6634 } | 6626 } |
6635 | 6627 |
6628 /* | |
6629 * Sets the gravity of a given window (widget). | |
6630 * Gravity controls which corner of the screen and window the position is relative to. | |
6631 * Parameters: | |
6632 * handle: Window (widget) handle. | |
6633 * horz: DW_GRAV_LEFT (default), DW_GRAV_RIGHT or DW_GRAV_CENTER. | |
6634 * vert: DW_GRAV_TOP (default), DW_GRAV_BOTTOM or DW_GRAV_CENTER. | |
6635 */ | |
6636 void API dw_window_set_gravity(HWND handle, int horz, int vert) | |
6637 { | |
6638 dw_window_set_data(handle, "_dw_grav_horz", DW_INT_TO_POINTER(horz)); | |
6639 dw_window_set_data(handle, "_dw_grav_vert", DW_INT_TO_POINTER(vert)); | |
6640 } | |
6641 | |
6642 /* Convert the coordinates based on gravity */ | |
6643 void _handle_gravity(HWND handle, long *x, long *y, unsigned long width, unsigned long height) | |
6644 { | |
6645 int horz = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_horz")); | |
6646 int vert = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_grav_vert")); | |
6647 | |
6648 /* Do any gravity calculations */ | |
6649 if(horz || vert) | |
6650 { | |
6651 long newx = *x, newy = *y; | |
6652 | |
6653 /* Handle horizontal center gravity */ | |
6654 if((horz & 0xf) == DW_GRAV_CENTER) | |
6655 newx += ((dw_screen_width() / 2) - (width / 2)); | |
6656 /* Handle right gravity */ | |
6657 else if((horz & 0xf) == DW_GRAV_RIGHT) | |
6658 newx = dw_screen_width() - width - *x; | |
6659 /* Handle vertical center gravity */ | |
6660 if((vert & 0xf) == DW_GRAV_CENTER) | |
6661 newy += ((dw_screen_height() / 2) - (height / 2)); | |
6662 else if((vert & 0xf) == DW_GRAV_BOTTOM) | |
6663 newy = dw_screen_height() - height - *y; | |
6664 | |
6665 /* Save the new values */ | |
6666 *x = newx; | |
6667 *y = newy; | |
6668 } | |
6669 } | |
6636 | 6670 |
6637 /* | 6671 /* |
6638 * Sets the position of a given window (widget). | 6672 * Sets the position of a given window (widget). |
6639 * Parameters: | 6673 * Parameters: |
6640 * handle: Window (widget) handle. | 6674 * handle: Window (widget) handle. |
6641 * x: X location from the bottom left. | 6675 * x: X location from the bottom left. |
6642 * y: Y location from the bottom left. | 6676 * y: Y location from the bottom left. |
6643 */ | 6677 */ |
6644 void API dw_window_set_pos(HWND handle, long x, long y) | 6678 void API dw_window_set_pos(HWND handle, long x, long y) |
6645 { | 6679 { |
6680 unsigned long width, height; | |
6681 | |
6682 dw_window_get_pos_size(handle, NULL, NULL, &width, &height); | |
6683 _handle_gravity(handle, &x, &y, width, height); | |
6646 SetWindowPos(handle, (HWND)NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); | 6684 SetWindowPos(handle, (HWND)NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); |
6647 } | 6685 } |
6648 | 6686 |
6649 /* | 6687 /* |
6650 * Sets the position and size of a given window (widget). | 6688 * Sets the position and size of a given window (widget). |
6659 { | 6697 { |
6660 /* Attempt to auto-size */ | 6698 /* Attempt to auto-size */ |
6661 if ( width < 1 || height < 1 ) | 6699 if ( width < 1 || height < 1 ) |
6662 _get_window_for_size(handle, &width, &height); | 6700 _get_window_for_size(handle, &width, &height); |
6663 | 6701 |
6702 _handle_gravity(handle, &x, &y, width, height); | |
6664 /* Finally set the size */ | 6703 /* Finally set the size */ |
6665 SetWindowPos(handle, (HWND)NULL, x, y, width, height, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE); | 6704 SetWindowPos(handle, (HWND)NULL, x, y, width, height, SWP_NOZORDER | SWP_NOACTIVATE); |
6666 } | 6705 } |
6667 | 6706 |
6668 /* | 6707 /* |
6669 * Gets the position and size of a given window (widget). | 6708 * Gets the position and size of a given window (widget). |
6670 * Parameters: | 6709 * Parameters: |
8911 { | 8950 { |
8912 Box *newbox = calloc(sizeof(Box), 1); | 8951 Box *newbox = calloc(sizeof(Box), 1); |
8913 HWND tmp = CreateWindow(ObjectClassName, | 8952 HWND tmp = CreateWindow(ObjectClassName, |
8914 "", | 8953 "", |
8915 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, | 8954 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, |
8916 0,0,screenx,screeny, | 8955 0,0,0,0, |
8917 DW_HWND_OBJECT, | 8956 DW_HWND_OBJECT, |
8918 (HMENU)id, | 8957 (HMENU)id, |
8919 DWInstance, | 8958 DWInstance, |
8920 NULL); | 8959 NULL); |
8921 newbox->pad = 0; | 8960 newbox->pad = 0; |