| 1 | /* $Id: win32wbasepos.cpp,v 1.1 1999-10-13 14:24:49 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Win32 Window Base Class for OS/2 (nonclient/position methods)
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 6 | * Copyright 1999 Daniela Engert (dani@ngrt.de)
|
|---|
| 7 | *
|
|---|
| 8 | * Parts based on Wine Windows code (windows\win.c, windows\nonclient.c)
|
|---|
| 9 | *
|
|---|
| 10 | * Copyright 1993, 1994 Alexandre Julliard
|
|---|
| 11 | *
|
|---|
| 12 | * TODO: Not thread/process safe
|
|---|
| 13 | *
|
|---|
| 14 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 15 | *
|
|---|
| 16 | */
|
|---|
| 17 | #include <os2win.h>
|
|---|
| 18 | #include <win.h>
|
|---|
| 19 | #include <stdlib.h>
|
|---|
| 20 | #include <string.h>
|
|---|
| 21 | #include <stdarg.h>
|
|---|
| 22 | #include <assert.h>
|
|---|
| 23 | #include <misc.h>
|
|---|
| 24 | #include <heapstring.h>
|
|---|
| 25 | #include <win32wbase.h>
|
|---|
| 26 | #include <winres.h>
|
|---|
| 27 | #include <spy.h>
|
|---|
| 28 | #include "wndmsg.h"
|
|---|
| 29 | #include "hooks.h"
|
|---|
| 30 | #include "oslibwin.h"
|
|---|
| 31 | #include "oslibutil.h"
|
|---|
| 32 | #include "oslibgdi.h"
|
|---|
| 33 | #include "oslibres.h"
|
|---|
| 34 | #include "oslibmenu.h"
|
|---|
| 35 | #include "oslibdos.h"
|
|---|
| 36 | #include "syscolor.h"
|
|---|
| 37 | #include "win32wndhandle.h"
|
|---|
| 38 | #include "heapshared.h"
|
|---|
| 39 | #include "dc.h"
|
|---|
| 40 | #include "pmframe.h"
|
|---|
| 41 | #include "win32wdesktop.h"
|
|---|
| 42 |
|
|---|
| 43 | #define HAS_DLGFRAME(style,exStyle) \
|
|---|
| 44 | (((exStyle) & WS_EX_DLGMODALFRAME) || \
|
|---|
| 45 | (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
|
|---|
| 46 |
|
|---|
| 47 | #define HAS_THICKFRAME(style) \
|
|---|
| 48 | (((style) & WS_THICKFRAME) && \
|
|---|
| 49 | !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
|
|---|
| 50 |
|
|---|
| 51 | #define HAS_3DFRAME(exStyle) \
|
|---|
| 52 | ((exStyle & WS_EX_CLIENTEDGE) || (exStyle & WS_EX_STATICEDGE) || (exStyle & WS_EX_WINDOWEDGE))
|
|---|
| 53 |
|
|---|
| 54 | #define HAS_BORDER(style, exStyle) \
|
|---|
| 55 | ((style & WS_BORDER) || HAS_THICKFRAME(style) || HAS_DLGFRAME(style,exStyle))
|
|---|
| 56 |
|
|---|
| 57 | #define IS_OVERLAPPED(style) \
|
|---|
| 58 | !(style & (WS_CHILD | WS_POPUP))
|
|---|
| 59 |
|
|---|
| 60 | #define HAS_MENU() (!(getStyle() & WS_CHILD) && (GetMenu() != 0))
|
|---|
| 61 |
|
|---|
| 62 | #if 0
|
|---|
| 63 | /***********************************************************************
|
|---|
| 64 | * WINPOS_MinMaximize
|
|---|
| 65 | *
|
|---|
| 66 | * Fill in lpRect and return additional flags to be used with SetWindowPos().
|
|---|
| 67 | * This function assumes that 'cmd' is different from the current window
|
|---|
| 68 | * state.
|
|---|
| 69 | */
|
|---|
| 70 | UINT Win32BaseWindow::MinMaximize(UINT cmd, LPRECT lpRect )
|
|---|
| 71 | {
|
|---|
| 72 | UINT swpFlags = 0;
|
|---|
| 73 | POINT pt, size;
|
|---|
| 74 | LPINTERNALPOS lpPos;
|
|---|
| 75 |
|
|---|
| 76 | size.x = rectWindow.left; size.y = rectWindow.top;
|
|---|
| 77 | lpPos = WINPOS_InitInternalPos( wndPtr, size, &rectWindow );
|
|---|
| 78 |
|
|---|
| 79 | if (lpPos && !HOOK_CallHooks16(WH_CBT, HCBT_MINMAX, hwndSelf, cmd))
|
|---|
| 80 | {
|
|---|
| 81 | if( dwStyle & WS_MINIMIZE )
|
|---|
| 82 | {
|
|---|
| 83 | if( !SendMessageA(WM_QUERYOPEN, 0, 0L ) )
|
|---|
| 84 | return (SWP_NOSIZE | SWP_NOMOVE);
|
|---|
| 85 | swpFlags |= SWP_NOCOPYBITS;
|
|---|
| 86 | }
|
|---|
| 87 | switch( cmd )
|
|---|
| 88 | {
|
|---|
| 89 | case SW_MINIMIZE:
|
|---|
| 90 | if( dwStyle & WS_MAXIMIZE)
|
|---|
| 91 | {
|
|---|
| 92 | flags |= WIN_RESTORE_MAX;
|
|---|
| 93 | dwStyle &= ~WS_MAXIMIZE;
|
|---|
| 94 | }
|
|---|
| 95 | else
|
|---|
| 96 | flags &= ~WIN_RESTORE_MAX;
|
|---|
| 97 | dwStyle |= WS_MINIMIZE;
|
|---|
| 98 |
|
|---|
| 99 | #if 0
|
|---|
| 100 | if( flags & WIN_NATIVE )
|
|---|
| 101 | if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, TRUE ) )
|
|---|
| 102 | swpFlags |= MINMAX_NOSWP;
|
|---|
| 103 | #endif
|
|---|
| 104 |
|
|---|
| 105 | lpPos->ptIconPos = WINPOS_FindIconPos( wndPtr, lpPos->ptIconPos );
|
|---|
| 106 |
|
|---|
| 107 | SetRect(lpRect, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
|
|---|
| 108 | GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
|
|---|
| 109 | swpFlags |= SWP_NOCOPYBITS;
|
|---|
| 110 | break;
|
|---|
| 111 |
|
|---|
| 112 | case SW_MAXIMIZE:
|
|---|
| 113 | WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL );
|
|---|
| 114 |
|
|---|
| 115 | if( dwStyle & WS_MINIMIZE )
|
|---|
| 116 | {
|
|---|
| 117 | if( flags & WIN_NATIVE )
|
|---|
| 118 | if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
|
|---|
| 119 | swpFlags |= MINMAX_NOSWP;
|
|---|
| 120 |
|
|---|
| 121 | WINPOS_ShowIconTitle( wndPtr, FALSE );
|
|---|
| 122 | dwStyle &= ~WS_MINIMIZE;
|
|---|
| 123 | }
|
|---|
| 124 | dwStyle |= WS_MAXIMIZE;
|
|---|
| 125 |
|
|---|
| 126 | SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
|
|---|
| 127 | size.x, size.y );
|
|---|
| 128 | break;
|
|---|
| 129 |
|
|---|
| 130 | case SW_RESTORE:
|
|---|
| 131 | if( dwStyle & WS_MINIMIZE )
|
|---|
| 132 | {
|
|---|
| 133 | if( flags & WIN_NATIVE )
|
|---|
| 134 | if( pDriver->pSetHostAttr( wndPtr, HAK_ICONICSTATE, FALSE ) )
|
|---|
| 135 | swpFlags |= MINMAX_NOSWP;
|
|---|
| 136 |
|
|---|
| 137 | dwStyle &= ~WS_MINIMIZE;
|
|---|
| 138 | WINPOS_ShowIconTitle( wndPtr, FALSE );
|
|---|
| 139 |
|
|---|
| 140 | if( flags & WIN_RESTORE_MAX)
|
|---|
| 141 | {
|
|---|
| 142 | /* Restore to maximized position */
|
|---|
| 143 | CONV_POINT16TO32( &lpPos->ptMaxPos, &pt );
|
|---|
| 144 | WINPOS_GetMinMaxInfo( wndPtr, &size, &pt, NULL, NULL);
|
|---|
| 145 | CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
|
|---|
| 146 | dwStyle |= WS_MAXIMIZE;
|
|---|
| 147 | SetRect16( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y, size.x, size.y );
|
|---|
| 148 | break;
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 | else
|
|---|
| 152 | if( !(dwStyle & WS_MAXIMIZE) ) return (UINT16)(-1);
|
|---|
| 153 | else dwStyle &= ~WS_MAXIMIZE;
|
|---|
| 154 |
|
|---|
| 155 | /* Restore to normal position */
|
|---|
| 156 |
|
|---|
| 157 | *lpRect = lpPos->rectNormal;
|
|---|
| 158 | lpRect->right -= lpRect->left;
|
|---|
| 159 | lpRect->bottom -= lpRect->top;
|
|---|
| 160 |
|
|---|
| 161 | break;
|
|---|
| 162 | }
|
|---|
| 163 | } else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
|
|---|
| 164 | return swpFlags;
|
|---|
| 165 | }
|
|---|
| 166 | #endif
|
|---|
| 167 | /*******************************************************************
|
|---|
| 168 | * GetMinMaxInfo
|
|---|
| 169 | *
|
|---|
| 170 | * Get the minimized and maximized information for a window.
|
|---|
| 171 | */
|
|---|
| 172 | void Win32BaseWindow::GetMinMaxInfo(POINT *maxSize, POINT *maxPos,
|
|---|
| 173 | POINT *minTrack, POINT *maxTrack )
|
|---|
| 174 | {
|
|---|
| 175 | MINMAXINFO MinMax;
|
|---|
| 176 | INT xinc, yinc;
|
|---|
| 177 |
|
|---|
| 178 | /* Compute default values */
|
|---|
| 179 |
|
|---|
| 180 | MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
|
|---|
| 181 | MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
|
|---|
| 182 | MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
|
|---|
| 183 | MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
|
|---|
| 184 | MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
|
|---|
| 185 | MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
|
|---|
| 186 |
|
|---|
| 187 | if (flags & WIN_MANAGED) xinc = yinc = 0;
|
|---|
| 188 | else if (HAS_DLGFRAME( dwStyle, dwExStyle ))
|
|---|
| 189 | {
|
|---|
| 190 | xinc = GetSystemMetrics(SM_CXDLGFRAME);
|
|---|
| 191 | yinc = GetSystemMetrics(SM_CYDLGFRAME);
|
|---|
| 192 | }
|
|---|
| 193 | else
|
|---|
| 194 | {
|
|---|
| 195 | xinc = yinc = 0;
|
|---|
| 196 | if (HAS_THICKFRAME(dwStyle))
|
|---|
| 197 | {
|
|---|
| 198 | xinc += GetSystemMetrics(SM_CXFRAME);
|
|---|
| 199 | yinc += GetSystemMetrics(SM_CYFRAME);
|
|---|
| 200 | }
|
|---|
| 201 | if (dwStyle & WS_BORDER)
|
|---|
| 202 | {
|
|---|
| 203 | xinc += GetSystemMetrics(SM_CXBORDER);
|
|---|
| 204 | yinc += GetSystemMetrics(SM_CYBORDER);
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 | MinMax.ptMaxSize.x += 2 * xinc;
|
|---|
| 208 | MinMax.ptMaxSize.y += 2 * yinc;
|
|---|
| 209 |
|
|---|
| 210 | #if 0
|
|---|
| 211 | lpPos = (LPINTERNALPOS)GetPropA( hwndSelf, atomInternalPos );
|
|---|
| 212 | if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
|
|---|
| 213 | CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
|
|---|
| 214 | else
|
|---|
| 215 | {
|
|---|
| 216 | #endif
|
|---|
| 217 | MinMax.ptMaxPosition.x = -xinc;
|
|---|
| 218 | MinMax.ptMaxPosition.y = -yinc;
|
|---|
| 219 | // }
|
|---|
| 220 |
|
|---|
| 221 | SendMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
|
|---|
| 222 |
|
|---|
| 223 | /* Some sanity checks */
|
|---|
| 224 |
|
|---|
| 225 | dprintf(("GetMinMaxInfo: %ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
|
|---|
| 226 | MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
|
|---|
| 227 | MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
|
|---|
| 228 | MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
|
|---|
| 229 | MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y));
|
|---|
| 230 | MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
|
|---|
| 231 | MinMax.ptMinTrackSize.x );
|
|---|
| 232 | MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
|
|---|
| 233 | MinMax.ptMinTrackSize.y );
|
|---|
| 234 |
|
|---|
| 235 | if (maxSize) *maxSize = MinMax.ptMaxSize;
|
|---|
| 236 | if (maxPos) *maxPos = MinMax.ptMaxPosition;
|
|---|
| 237 | if (minTrack) *minTrack = MinMax.ptMinTrackSize;
|
|---|
| 238 | if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
|
|---|
| 239 | }
|
|---|
| 240 | /***********************************************************************
|
|---|
| 241 | * WINPOS_SendNCCalcSize
|
|---|
| 242 | *
|
|---|
| 243 | * Send a WM_NCCALCSIZE message to a window.
|
|---|
| 244 | * All parameters are read-only except newClientRect.
|
|---|
| 245 | * oldWindowRect, oldClientRect and winpos must be non-NULL only
|
|---|
| 246 | * when calcValidRect is TRUE.
|
|---|
| 247 | */
|
|---|
| 248 | LONG Win32BaseWindow::SendNCCalcSize(BOOL calcValidRect, RECT *newWindowRect,
|
|---|
| 249 | RECT *oldWindowRect,
|
|---|
| 250 | RECT *oldClientRect, WINDOWPOS *winpos,
|
|---|
| 251 | RECT *newClientRect )
|
|---|
| 252 | {
|
|---|
| 253 | NCCALCSIZE_PARAMS params;
|
|---|
| 254 | WINDOWPOS winposCopy;
|
|---|
| 255 | LONG result;
|
|---|
| 256 |
|
|---|
| 257 | params.rgrc[0] = *newWindowRect;
|
|---|
| 258 | if (calcValidRect)
|
|---|
| 259 | {
|
|---|
| 260 | winposCopy = *winpos;
|
|---|
| 261 | params.rgrc[1] = *oldWindowRect;
|
|---|
| 262 | params.rgrc[2] = *oldClientRect;
|
|---|
| 263 | params.lppos = &winposCopy;
|
|---|
| 264 | }
|
|---|
| 265 | result = SendMessageA(WM_NCCALCSIZE, calcValidRect,
|
|---|
| 266 | (LPARAM)¶ms );
|
|---|
| 267 | *newClientRect = params.rgrc[0];
|
|---|
| 268 | return result;
|
|---|
| 269 | }
|
|---|
| 270 | //******************************************************************************
|
|---|
| 271 | //******************************************************************************
|
|---|
| 272 | LONG Win32BaseWindow::NCHandleCalcSize(WPARAM wParam, NCCALCSIZE_PARAMS *ncsize)
|
|---|
| 273 | {
|
|---|
| 274 | LONG result = 0;
|
|---|
| 275 |
|
|---|
| 276 | if (getStyle() & CS_VREDRAW) result |= WVR_VREDRAW;
|
|---|
| 277 | if (getStyle() & CS_HREDRAW) result |= WVR_HREDRAW;
|
|---|
| 278 |
|
|---|
| 279 | if(!isFrameWindow()) return result;
|
|---|
| 280 |
|
|---|
| 281 | //TODO: Wine calculates new size of client area even when window is iconic (client edges)
|
|---|
| 282 | if(!(getStyle() & (WS_MINIMIZE | WS_ICONIC)))
|
|---|
| 283 | {
|
|---|
| 284 | dprintf(("NCHandleCalcSize %x (%d,%d) (%d,%d)", getWindowHandle(), ncsize->rgrc[0].left, ncsize->rgrc[0].top, ncsize->rgrc[0].right, ncsize->rgrc[0].bottom));
|
|---|
| 285 | OSLibWinCalcFrameRect(getOS2FrameWindowHandle(), &ncsize->rgrc[0], TRUE); //frame -> client
|
|---|
| 286 | dprintf(("NCHandleCalcSize Adjusted client rect (%d,%d) (%d,%d)", ncsize->rgrc[0].left, ncsize->rgrc[0].top, ncsize->rgrc[0].right, ncsize->rgrc[0].bottom));
|
|---|
| 287 |
|
|---|
| 288 | #if 0
|
|---|
| 289 | //relative to frame -> relative to itself
|
|---|
| 290 | ncsize->rgrc[0].right -= ncsize->rgrc[0].left;
|
|---|
| 291 | ncsize->rgrc[0].left = 0;
|
|---|
| 292 | ncsize->rgrc[0].bottom -= ncsize->rgrc[0].top;
|
|---|
| 293 | ncsize->rgrc[0].top = 0;
|
|---|
| 294 | #endif
|
|---|
| 295 | }
|
|---|
| 296 | #if 0
|
|---|
| 297 | //TODO: Docs say app should return 0 when fCalcValidRects == 0, Wine doesn't do this
|
|---|
| 298 | if(wParam == 0) //fCalcValidRects
|
|---|
| 299 | return 0;
|
|---|
| 300 | #endif
|
|---|
| 301 | return result;
|
|---|
| 302 | }
|
|---|
| 303 | //******************************************************************************
|
|---|
| 304 | //******************************************************************************
|
|---|
| 305 |
|
|---|