comparison win/dw.c @ 1443:66999ff50174

Fix auto-sizing top-level windows with menus on Windows. Similar fix may need to be done for OS/2, but not sure if there is an AdjustWindowRect.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 08 Dec 2011 22:49:37 +0000
parents 02a329b2b0cd
children 8f7692fcad37
comparison
equal deleted inserted replaced
1442:02a329b2b0cd 1443:66999ff50174
6534 { 6534 {
6535 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()"); 6535 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()");
6536 } 6536 }
6537 6537
6538 /* 6538 /*
6539 * The following is an attempt to dynamically size a window based on the size of its
6540 * children before realization. Only applicable when width or height is less than one.
6541 */
6542 void _get_window_for_size(HWND handle, unsigned long *width, unsigned long *height)
6543 {
6544 Box *thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA);
6545
6546 if(thisbox)
6547 {
6548 int depth = 0;
6549 DWORD dwStyle = GetWindowLongPtr(handle, GWL_STYLE);
6550 DWORD dwExStyle = GetWindowLongPtr(handle, GWL_EXSTYLE);
6551 HMENU menu = GetMenu(handle) ;
6552 RECT rc = { 0 } ;
6553
6554 /* Calculate space requirements */
6555 _resize_box(thisbox, &depth, *width, *height, 1);
6556
6557 rc.right = thisbox->minwidth;
6558 rc.bottom = thisbox->minheight;
6559
6560 /* Take into account the window border and menu here */
6561 AdjustWindowRectEx(&rc, dwStyle, menu ? TRUE : FALSE, dwExStyle);
6562
6563 if ( *width < 1 ) *width = rc.right - rc.left;
6564 if ( *height < 1 ) *height = rc.bottom - rc.top;
6565 }
6566 }
6567
6568 /*
6539 * Sets the size of a given window (widget). 6569 * Sets the size of a given window (widget).
6540 * Parameters: 6570 * Parameters:
6541 * handle: Window (widget) handle. 6571 * handle: Window (widget) handle.
6542 * width: New width in pixels. 6572 * width: New width in pixels.
6543 * height: New height in pixels. 6573 * height: New height in pixels.
6544 */ 6574 */
6545 void API dw_window_set_size(HWND handle, ULONG width, ULONG height) 6575 void API dw_window_set_size(HWND handle, ULONG width, ULONG height)
6546 { 6576 {
6547 Box *thisbox; 6577 /* Attempt to auto-size */
6548 6578 if ( width < 1 || height < 1 )
6549 /* 6579 _get_window_for_size(handle, &width, &height);
6550 * The following is an attempt to dynamically size a window based on the size of its
6551 * children before realization. Only applicable when width or height is less than one.
6552 */
6553 if ( (width < 1 || height < 1) && (thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA)) )
6554 {
6555 int depth = 0, border = GetSystemMetrics(SM_CXSIZEFRAME) * 2;
6556
6557 /* Calculate space requirements */
6558 _resize_box(thisbox, &depth, width, height, 1);
6559
6560 /* Might need to take into account the window border here */
6561 if ( width < 1 ) width = thisbox->minwidth + border;
6562 if ( height < 1 ) height = thisbox->minheight + GetSystemMetrics(SM_CYCAPTION) + border;
6563 }
6564 6580
6565 /* Finally set the size */ 6581 /* Finally set the size */
6566 SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOMOVE); 6582 SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOMOVE);
6567 } 6583 }
6568 6584
6629 * width: Width of the widget. 6645 * width: Width of the widget.
6630 * height: Height of the widget. 6646 * height: Height of the widget.
6631 */ 6647 */
6632 void API dw_window_set_pos_size(HWND handle, long x, long y, ULONG width, ULONG height) 6648 void API dw_window_set_pos_size(HWND handle, long x, long y, ULONG width, ULONG height)
6633 { 6649 {
6634 Box *thisbox; 6650 /* Attempt to auto-size */
6635 6651 if ( width < 1 || height < 1 )
6636 /* 6652 _get_window_for_size(handle, &width, &height);
6637 * The following is an attempt to dynamically size a window based on the size of its
6638 * children before realization. Only applicable when width or height is less than one.
6639 */
6640 if ( (width < 1 || height < 1) && (thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA)) )
6641 {
6642 int depth = 0, border = GetSystemMetrics(SM_CXSIZEFRAME) * 2;
6643
6644 /* Calculate space requirements */
6645 _resize_box(thisbox, &depth, width, height, 1);
6646
6647 /* Might need to take into account the window border here */
6648 if ( width < 1 ) width = thisbox->minwidth + border;
6649 if ( height < 1 ) height = thisbox->minheight + GetSystemMetrics(SM_CYCAPTION) + border;
6650 }
6651 6653
6652 /* Finally set the size */ 6654 /* Finally set the size */
6653 SetWindowPos(handle, (HWND)NULL, x, y, width, height, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE); 6655 SetWindowPos(handle, (HWND)NULL, x, y, width, height, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE);
6654 } 6656 }
6655 6657