| 1 | /* $Id: win32wbasepos.cpp,v 1.15 2000-06-07 14:51:32 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 | * Wine code based on build 990815
|
|---|
| 15 | *
|
|---|
| 16 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 17 | *
|
|---|
| 18 | */
|
|---|
| 19 | #include <os2win.h>
|
|---|
| 20 | #include <win.h>
|
|---|
| 21 | #include <stdlib.h>
|
|---|
| 22 | #include <string.h>
|
|---|
| 23 | #include <stdarg.h>
|
|---|
| 24 | #include <assert.h>
|
|---|
| 25 | #include <misc.h>
|
|---|
| 26 | #include <win32wbase.h>
|
|---|
| 27 | #include <spy.h>
|
|---|
| 28 | #include "wndmsg.h"
|
|---|
| 29 | #include "oslibwin.h"
|
|---|
| 30 | #include "oslibutil.h"
|
|---|
| 31 | #include "oslibgdi.h"
|
|---|
| 32 | #include "oslibres.h"
|
|---|
| 33 | #include "oslibdos.h"
|
|---|
| 34 | #include "syscolor.h"
|
|---|
| 35 | #include "win32wndhandle.h"
|
|---|
| 36 | #include "dc.h"
|
|---|
| 37 | #include "pmframe.h"
|
|---|
| 38 | #include "win32wdesktop.h"
|
|---|
| 39 | #include <win\hook.h>
|
|---|
| 40 |
|
|---|
| 41 | #define DBG_LOCALLOG DBG_win32wbasepos
|
|---|
| 42 | #include "dbglocal.h"
|
|---|
| 43 |
|
|---|
| 44 | /*******************************************************************
|
|---|
| 45 | * GetMinMaxInfo
|
|---|
| 46 | *
|
|---|
| 47 | * Get the minimized and maximized information for a window.
|
|---|
| 48 | */
|
|---|
| 49 | void Win32BaseWindow::GetMinMaxInfo(POINT *maxSize, POINT *maxPos,
|
|---|
| 50 | POINT *minTrack, POINT *maxTrack )
|
|---|
| 51 | {
|
|---|
| 52 | MINMAXINFO MinMax;
|
|---|
| 53 | INT xinc, yinc;
|
|---|
| 54 |
|
|---|
| 55 | /* Compute default values */
|
|---|
| 56 |
|
|---|
| 57 | MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
|
|---|
| 58 | MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
|
|---|
| 59 | MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
|
|---|
| 60 | MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
|
|---|
| 61 | MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
|
|---|
| 62 | MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
|
|---|
| 63 |
|
|---|
| 64 | if (HAS_DLGFRAME( dwStyle, dwExStyle ))
|
|---|
| 65 | {
|
|---|
| 66 | xinc = GetSystemMetrics(SM_CXDLGFRAME);
|
|---|
| 67 | yinc = GetSystemMetrics(SM_CYDLGFRAME);
|
|---|
| 68 | }
|
|---|
| 69 | else
|
|---|
| 70 | {
|
|---|
| 71 | xinc = yinc = 0;
|
|---|
| 72 | if (HAS_THICKFRAME(dwStyle, dwExStyle))
|
|---|
| 73 | {
|
|---|
| 74 | xinc += GetSystemMetrics(SM_CXFRAME);
|
|---|
| 75 | yinc += GetSystemMetrics(SM_CYFRAME);
|
|---|
| 76 | }
|
|---|
| 77 | if (dwStyle & WS_BORDER)
|
|---|
| 78 | {
|
|---|
| 79 | xinc += GetSystemMetrics(SM_CXBORDER);
|
|---|
| 80 | yinc += GetSystemMetrics(SM_CYBORDER);
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 | MinMax.ptMaxSize.x += 2 * xinc;
|
|---|
| 84 | MinMax.ptMaxSize.y += 2 * yinc;
|
|---|
| 85 |
|
|---|
| 86 | #if 0
|
|---|
| 87 | lpPos = (LPINTERNALPOS)GetPropA( hwndSelf, atomInternalPos );
|
|---|
| 88 | if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
|
|---|
| 89 | CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
|
|---|
| 90 | else
|
|---|
| 91 | {
|
|---|
| 92 | #endif
|
|---|
| 93 | MinMax.ptMaxPosition.x = -xinc;
|
|---|
| 94 | MinMax.ptMaxPosition.y = -yinc;
|
|---|
| 95 | // }
|
|---|
| 96 |
|
|---|
| 97 | SendInternalMessageA(WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
|
|---|
| 98 |
|
|---|
| 99 | /* Some sanity checks */
|
|---|
| 100 |
|
|---|
| 101 | dprintf(("GetMinMaxInfo: %ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
|
|---|
| 102 | MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
|
|---|
| 103 | MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
|
|---|
| 104 | MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
|
|---|
| 105 | MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y));
|
|---|
| 106 | MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x,
|
|---|
| 107 | MinMax.ptMinTrackSize.x );
|
|---|
| 108 | MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y,
|
|---|
| 109 | MinMax.ptMinTrackSize.y );
|
|---|
| 110 |
|
|---|
| 111 | if (maxSize) *maxSize = MinMax.ptMaxSize;
|
|---|
| 112 | if (maxPos) *maxPos = MinMax.ptMaxPosition;
|
|---|
| 113 | if (minTrack) *minTrack = MinMax.ptMinTrackSize;
|
|---|
| 114 | if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
|
|---|
| 115 | }
|
|---|
| 116 | /***********************************************************************
|
|---|
| 117 | * WINPOS_SendNCCalcSize
|
|---|
| 118 | *
|
|---|
| 119 | * Send a WM_NCCALCSIZE message to a window.
|
|---|
| 120 | * All parameters are read-only except newClientRect.
|
|---|
| 121 | * oldWindowRect, oldClientRect and winpos must be non-NULL only
|
|---|
| 122 | * when calcValidRect is TRUE.
|
|---|
| 123 | */
|
|---|
| 124 | LONG Win32BaseWindow::SendNCCalcSize(BOOL calcValidRect, RECT *newWindowRect,
|
|---|
| 125 | RECT *oldWindowRect,
|
|---|
| 126 | RECT *oldClientRect, WINDOWPOS *winpos,
|
|---|
| 127 | RECT *newClientRect )
|
|---|
| 128 | {
|
|---|
| 129 | NCCALCSIZE_PARAMS params;
|
|---|
| 130 | WINDOWPOS winposCopy;
|
|---|
| 131 | LONG result;
|
|---|
| 132 |
|
|---|
| 133 | /* Send WM_NCCALCSIZE message to get new client area */
|
|---|
| 134 | // if((winpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
|
|---|
| 135 | // {
|
|---|
| 136 | params.rgrc[0] = *newWindowRect;
|
|---|
| 137 | if(calcValidRect)
|
|---|
| 138 | {
|
|---|
| 139 | winposCopy = *winpos;
|
|---|
| 140 | params.rgrc[1] = *oldWindowRect;
|
|---|
| 141 | //client rectangel must be in parent coordinates
|
|---|
| 142 | OffsetRect(oldClientRect, rectWindow.left, rectWindow.top);
|
|---|
| 143 |
|
|---|
| 144 | params.rgrc[2] = *oldClientRect;
|
|---|
| 145 | params.lppos = &winposCopy;
|
|---|
| 146 | }
|
|---|
| 147 | result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect, (LPARAM)¶ms );
|
|---|
| 148 |
|
|---|
| 149 | /* If the application send back garbage, ignore it */
|
|---|
| 150 | if(params.rgrc[0].left <= params.rgrc[0].right && params.rgrc[0].top <= params.rgrc[0].bottom)
|
|---|
| 151 | {
|
|---|
| 152 | *newClientRect = params.rgrc[0];
|
|---|
| 153 | //client rectangle now in parent coordinates; convert to 'frame' coordinates
|
|---|
| 154 | OffsetRect(newClientRect, -rectWindow.left, -rectWindow.top);
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | /* FIXME: WVR_ALIGNxxx */
|
|---|
| 158 | if(newClientRect->left != rectClient.left || newClientRect->top != rectClient.top)
|
|---|
| 159 | winpos->flags &= ~SWP_NOCLIENTMOVE;
|
|---|
| 160 |
|
|---|
| 161 | if((newClientRect->right - newClientRect->left != rectClient.right - rectClient.left) ||
|
|---|
| 162 | (newClientRect->bottom - newClientRect->top != rectClient.bottom - rectClient.top))
|
|---|
| 163 | winpos->flags &= ~SWP_NOCLIENTSIZE;
|
|---|
| 164 |
|
|---|
| 165 | // }
|
|---|
| 166 | // else
|
|---|
| 167 | // if(!(winpos->flags & SWP_NOMOVE) &&
|
|---|
| 168 | // (newClientRect->left != rectClient.left || newClientRect->top != rectClient.top)) {
|
|---|
| 169 | // winpos->flags &= ~SWP_NOCLIENTMOVE;
|
|---|
| 170 | // }
|
|---|
| 171 | return result;
|
|---|
| 172 | }
|
|---|
| 173 | /***********************************************************************
|
|---|
| 174 | * WINPOS_HandleWindowPosChanging
|
|---|
| 175 | *
|
|---|
| 176 | * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
|
|---|
| 177 | */
|
|---|
| 178 | LONG Win32BaseWindow::HandleWindowPosChanging(WINDOWPOS *winpos)
|
|---|
| 179 | {
|
|---|
| 180 | POINT maxSize;
|
|---|
| 181 | if (winpos->flags & SWP_NOSIZE) return 0;
|
|---|
| 182 |
|
|---|
| 183 | if ((dwStyle & WS_THICKFRAME) ||
|
|---|
| 184 | ((dwStyle & (WS_POPUP | WS_CHILD)) == 0))
|
|---|
| 185 | {
|
|---|
| 186 | GetMinMaxInfo( &maxSize, NULL, NULL, NULL );
|
|---|
| 187 | winpos->cx = MIN( winpos->cx, maxSize.x );
|
|---|
| 188 | winpos->cy = MIN( winpos->cy, maxSize.y );
|
|---|
| 189 | }
|
|---|
| 190 | return 0;
|
|---|
| 191 | }
|
|---|
| 192 | /******************************************************************************
|
|---|
| 193 | * WINPOS_MinMaximize
|
|---|
| 194 | *
|
|---|
| 195 | * Fill in lpRect and return additional flags to be used with SetWindowPos().
|
|---|
| 196 | * This function assumes that 'cmd' is different from the current window
|
|---|
| 197 | * state.
|
|---|
| 198 | */
|
|---|
| 199 | UINT Win32BaseWindow::MinMaximize(UINT cmd, LPRECT lpRect)
|
|---|
| 200 | {
|
|---|
| 201 | UINT swpFlags = 0;
|
|---|
| 202 | POINT size;
|
|---|
| 203 |
|
|---|
| 204 | size.x = rectWindow.left;
|
|---|
| 205 | size.y = rectWindow.top;
|
|---|
| 206 |
|
|---|
| 207 | if(IsRectEmpty(&windowpos.rcNormalPosition)) {
|
|---|
| 208 | CopyRect(&windowpos.rcNormalPosition, &rectWindow);
|
|---|
| 209 | }
|
|---|
| 210 | if(!HOOK_CallHooksA(WH_CBT, HCBT_MINMAX, getWindowHandle(), cmd))
|
|---|
| 211 | {
|
|---|
| 212 | if(getStyle() & WS_MINIMIZE )
|
|---|
| 213 | {
|
|---|
| 214 | if(!SendInternalMessageA(WM_QUERYOPEN, 0, 0L))
|
|---|
| 215 | return (SWP_NOSIZE | SWP_NOMOVE);
|
|---|
| 216 | }
|
|---|
| 217 | switch( cmd )
|
|---|
| 218 | {
|
|---|
| 219 | case SW_MINIMIZE:
|
|---|
| 220 | if( getStyle() & WS_MAXIMIZE)
|
|---|
| 221 | {
|
|---|
| 222 | setFlags(getFlags() | WIN_RESTORE_MAX);
|
|---|
| 223 | setStyle(getStyle() & ~WS_MAXIMIZE);
|
|---|
| 224 | }
|
|---|
| 225 | else setFlags(getFlags() & ~WIN_RESTORE_MAX);
|
|---|
| 226 |
|
|---|
| 227 | setStyle(getStyle() | WS_MINIMIZE);
|
|---|
| 228 |
|
|---|
| 229 | SetRect(lpRect, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
|
|---|
| 230 | GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
|
|---|
| 231 | break;
|
|---|
| 232 |
|
|---|
| 233 | case SW_MAXIMIZE:
|
|---|
| 234 | GetMinMaxInfo(&size, &windowpos.ptMaxPosition, NULL, NULL );
|
|---|
| 235 |
|
|---|
| 236 | if(getStyle() & WS_MINIMIZE )
|
|---|
| 237 | {
|
|---|
| 238 | setStyle(getStyle() & ~WS_MINIMIZE);
|
|---|
| 239 | }
|
|---|
| 240 | setStyle(getStyle() | WS_MAXIMIZE);
|
|---|
| 241 |
|
|---|
| 242 | SetRect(lpRect, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
|
|---|
| 243 | size.x, size.y );
|
|---|
| 244 | break;
|
|---|
| 245 |
|
|---|
| 246 | case SW_RESTORE:
|
|---|
| 247 | if(getStyle() & WS_MINIMIZE)
|
|---|
| 248 | {
|
|---|
| 249 | setStyle(getStyle() & ~WS_MINIMIZE);
|
|---|
| 250 |
|
|---|
| 251 | if( getFlags() & WIN_RESTORE_MAX)
|
|---|
| 252 | {
|
|---|
| 253 | /* Restore to maximized position */
|
|---|
| 254 | GetMinMaxInfo(&size, &windowpos.ptMaxPosition, NULL, NULL);
|
|---|
| 255 | setStyle(getStyle() | WS_MAXIMIZE);
|
|---|
| 256 | SetRect(lpRect, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y, size.x, size.y);
|
|---|
| 257 | break;
|
|---|
| 258 | }
|
|---|
| 259 | }
|
|---|
| 260 | else
|
|---|
| 261 | if( !(getStyle() & WS_MAXIMIZE) )
|
|---|
| 262 | return 0;
|
|---|
| 263 | else setStyle(getStyle() & ~WS_MAXIMIZE);
|
|---|
| 264 |
|
|---|
| 265 | /* Restore to normal position */
|
|---|
| 266 |
|
|---|
| 267 | *lpRect = windowpos.rcNormalPosition;
|
|---|
| 268 | lpRect->right -= lpRect->left;
|
|---|
| 269 | lpRect->bottom -= lpRect->top;
|
|---|
| 270 | break;
|
|---|
| 271 | }
|
|---|
| 272 | }
|
|---|
| 273 | else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
|
|---|
| 274 |
|
|---|
| 275 | return swpFlags;
|
|---|
| 276 | }
|
|---|
| 277 | //******************************************************************************
|
|---|
| 278 | //******************************************************************************
|
|---|