comparison os2/dw.c @ 1444:914ac25f7d37

Fix auto-sizing top-level windows with menus on OS/2 using WinCalcFrameRect().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 08 Dec 2011 23:32:40 +0000
parents 02a329b2b0cd
children 8f7692fcad37
comparison
equal deleted inserted replaced
1443:66999ff50174 1444:914ac25f7d37
6850 { 6850 {
6851 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()"); 6851 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()");
6852 } 6852 }
6853 6853
6854 /* 6854 /*
6855 * The following is an attempt to dynamically size a window based on the size of its
6856 * children before realization. Only applicable when width or height is less than one.
6857 */
6858 void _get_window_for_size(HWND handle, unsigned long *width, unsigned long *height)
6859 {
6860 HWND box = WinWindowFromID(handle, FID_CLIENT);
6861 Box *thisbox = WinQueryWindowPtr(box, QWP_USER);
6862
6863 if(thisbox)
6864 {
6865 int depth = 0;
6866 RECTL rect = { 0 };
6867
6868 /* Calculate space requirements */
6869 _resize_box(thisbox, &depth, *width, *height, 1);
6870
6871 rect.xRight = thisbox->minwidth;
6872 rect.yTop = thisbox->minheight;
6873
6874 /* Take into account the window border and menu here */
6875 WinCalcFrameRect(handle, &rect, FALSE);
6876
6877 if(*width < 1) *width = rect.xRight - rect.xLeft;
6878 if(*height < 1) *height = rect.yTop - rect.yBottom;
6879 }
6880 }
6881
6882 /*
6855 * Sets the size of a given window (widget). 6883 * Sets the size of a given window (widget).
6856 * Parameters: 6884 * Parameters:
6857 * handle: Window (widget) handle. 6885 * handle: Window (widget) handle.
6858 * width: New width in pixels. 6886 * width: New width in pixels.
6859 * height: New height in pixels. 6887 * height: New height in pixels.
6860 */ 6888 */
6861 void API dw_window_set_size(HWND handle, ULONG width, ULONG height) 6889 void API dw_window_set_size(HWND handle, ULONG width, ULONG height)
6862 { 6890 {
6863 Box *thisbox; 6891 /* Attempt to auto-size */
6864 HWND box; 6892 if ( width < 1 || height < 1 )
6865 6893 _get_window_for_size(handle, &width, &height);
6866 if((width < 1 || height < 1) && (box = WinWindowFromID(handle, FID_CLIENT)) &&
6867 (thisbox = WinQueryWindowPtr(box, QWP_USER)))
6868 {
6869 int depth = 0, border = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER) * 2;
6870
6871 /* Calculate space requirements */
6872 _resize_box(thisbox, &depth, width, height, 1);
6873
6874 /* Might need to take into account the window border here */
6875 if(width < 1) width = thisbox->minwidth + border;
6876 if(height < 1) height = thisbox->minheight + WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR) + border;
6877 }
6878 6894
6879 /* Finally set the size */ 6895 /* Finally set the size */
6880 WinSetWindowPos(handle, NULLHANDLE, 0, 0, width, height, SWP_SHOW | SWP_SIZE); 6896 WinSetWindowPos(handle, NULLHANDLE, 0, 0, width, height, SWP_SHOW | SWP_SIZE);
6881 } 6897 }
6882 6898
6944 * height: Height of the widget. 6960 * height: Height of the widget.
6945 */ 6961 */
6946 void API dw_window_set_pos_size(HWND handle, LONG x, LONG y, ULONG width, ULONG height) 6962 void API dw_window_set_pos_size(HWND handle, LONG x, LONG y, ULONG width, ULONG height)
6947 { 6963 {
6948 int myy = _get_frame_height(handle) - (y + height); 6964 int myy = _get_frame_height(handle) - (y + height);
6949 Box *thisbox; 6965
6950 HWND box; 6966 /* Attempt to auto-size */
6951 6967 if ( width < 1 || height < 1 )
6952 if((width < 1 || height < 1) && (box = WinWindowFromID(handle, FID_CLIENT)) && 6968 _get_window_for_size(handle, &width, &height);
6953 (thisbox = WinQueryWindowPtr(box, QWP_USER)))
6954 {
6955 int depth = 0, border = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER) * 2;
6956
6957 /* Calculate space requirements */
6958 _resize_box(thisbox, &depth, width, height, 1);
6959
6960 /* Might need to take into account the window border here */
6961 if(width < 1) width = thisbox->minwidth + border;
6962 if(height < 1) height = thisbox->minheight + WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR) + border;
6963 }
6964 6969
6965 /* Finally set the size */ 6970 /* Finally set the size */
6966 WinSetWindowPos(handle, NULLHANDLE, x, myy, width, height, SWP_MOVE | SWP_SIZE | SWP_SHOW); 6971 WinSetWindowPos(handle, NULLHANDLE, x, myy, width, height, SWP_MOVE | SWP_SIZE | SWP_SHOW);
6967 } 6972 }
6968 6973