| 1 | /* | 
|---|
| 2 | * Window tracking related functions. | 
|---|
| 3 | * | 
|---|
| 4 | * Copyright 2001 Sander van Leeuwen | 
|---|
| 5 | * | 
|---|
| 6 | * Changes from Wine code: (20011004) | 
|---|
| 7 | * - Only draw changed track frame instead of clearing the old one and | 
|---|
| 8 | *   drawing the new one (less flickering) | 
|---|
| 9 | * - Send WM_MOVING when moving a window (not done in Wine) | 
|---|
| 10 | * - Send WM_SIZING only when sizing a window | 
|---|
| 11 | * - Fixed handling of rectangles changed by WM_SIZING/MOVING | 
|---|
| 12 | * | 
|---|
| 13 | * Based on Wine code: (dlls\x11drv\winpos.c) | 
|---|
| 14 | * | 
|---|
| 15 | * Copyright 1993, 1994, 1995, 2001 Alexandre Julliard | 
|---|
| 16 | * Copyright 1995, 1996, 1999 Alex Korobka | 
|---|
| 17 | * | 
|---|
| 18 | */ | 
|---|
| 19 | #include <os2win.h> | 
|---|
| 20 | #include <string.h> | 
|---|
| 21 |  | 
|---|
| 22 | #include "win32wbase.h" | 
|---|
| 23 | #include "hook.h" | 
|---|
| 24 |  | 
|---|
| 25 | #define ON_LEFT_BORDER(hit) \ | 
|---|
| 26 | (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT)) | 
|---|
| 27 | #define ON_RIGHT_BORDER(hit) \ | 
|---|
| 28 | (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT)) | 
|---|
| 29 | #define ON_TOP_BORDER(hit) \ | 
|---|
| 30 | (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT)) | 
|---|
| 31 | #define ON_BOTTOM_BORDER(hit) \ | 
|---|
| 32 | (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT)) | 
|---|
| 33 |  | 
|---|
| 34 | #define RECT_WIDTH(a)   ((a)->right - (a)->left) | 
|---|
| 35 | #define RECT_HEIGHT(a)  ((a)->bottom - (a)->top) | 
|---|
| 36 | #define RECT_EQUAL(a,b) (memcmp(a, b, sizeof(RECT)) == 0) | 
|---|
| 37 |  | 
|---|
| 38 | #ifdef CUSTOM_TRACKFRAME | 
|---|
| 39 |  | 
|---|
| 40 | /*********************************************************************** | 
|---|
| 41 | *           draw_moving_frame | 
|---|
| 42 | * | 
|---|
| 43 | * Draw the frame used when moving or resizing window. | 
|---|
| 44 | * | 
|---|
| 45 | * FIXME:  This causes problems in Win95 mode.  (why?) | 
|---|
| 46 | */ | 
|---|
| 47 | static void draw_moving_frame( HDC hdc, RECT *rect, BOOL thickframe, DWORD hittest, BOOL fRedraw) | 
|---|
| 48 | { | 
|---|
| 49 | if (thickframe) | 
|---|
| 50 | { | 
|---|
| 51 | const int width = GetSystemMetrics(SM_CXFRAME); | 
|---|
| 52 | const int height = GetSystemMetrics(SM_CYFRAME); | 
|---|
| 53 |  | 
|---|
| 54 | static RECT oldRect = {0}; | 
|---|
| 55 |  | 
|---|
| 56 | if(fRedraw && EqualRect(&oldRect, rect)) { | 
|---|
| 57 | return; | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) ); | 
|---|
| 61 | if(fRedraw && hittest != HTCAPTION) | 
|---|
| 62 | { | 
|---|
| 63 | int x, y, linewidth, lineheight; | 
|---|
| 64 |  | 
|---|
| 65 | //This should be done in a better way (less code), but at least | 
|---|
| 66 | //it works. | 
|---|
| 67 | switch(hittest) { | 
|---|
| 68 | case HTLEFT: | 
|---|
| 69 | //clear old edge | 
|---|
| 70 | PatBlt( hdc, oldRect.left, oldRect.top + height, | 
|---|
| 71 | width, RECT_HEIGHT(&oldRect) - 2*height, PATINVERT ); | 
|---|
| 72 | //and draw new one | 
|---|
| 73 | PatBlt( hdc, rect->left, rect->top + height, | 
|---|
| 74 | width, RECT_HEIGHT(rect) - 2*height, PATINVERT ); | 
|---|
| 75 |  | 
|---|
| 76 | if(oldRect.left > rect->left) { | 
|---|
| 77 | x = rect->left; | 
|---|
| 78 | linewidth = oldRect.left - rect->left; | 
|---|
| 79 | } | 
|---|
| 80 | else { | 
|---|
| 81 | x = oldRect.left; | 
|---|
| 82 | linewidth = rect->left - oldRect.left; | 
|---|
| 83 | } | 
|---|
| 84 | PatBlt(hdc, x, oldRect.top,      linewidth, height,  PATINVERT); | 
|---|
| 85 | PatBlt(hdc, x, oldRect.bottom-1, linewidth, -height, PATINVERT); | 
|---|
| 86 | break; | 
|---|
| 87 | case HTRIGHT: | 
|---|
| 88 | //clear old edge | 
|---|
| 89 | PatBlt( hdc, oldRect.right-1, oldRect.top + height, | 
|---|
| 90 | -width, RECT_HEIGHT(&oldRect) - 2*height, PATINVERT ); | 
|---|
| 91 | //and draw new one | 
|---|
| 92 | PatBlt( hdc, rect->right-1, rect->top + height, | 
|---|
| 93 | -width, RECT_HEIGHT(rect) - 2*height, PATINVERT ); | 
|---|
| 94 |  | 
|---|
| 95 | if(oldRect.right > rect->right) { | 
|---|
| 96 | x = rect->right; | 
|---|
| 97 | linewidth = oldRect.right - rect->right; | 
|---|
| 98 | } | 
|---|
| 99 | else { | 
|---|
| 100 | x = oldRect.right; | 
|---|
| 101 | linewidth = rect->right - oldRect.right; | 
|---|
| 102 | } | 
|---|
| 103 | PatBlt( hdc, x, oldRect.top,      linewidth,  height, PATINVERT ); | 
|---|
| 104 | PatBlt( hdc, x, oldRect.bottom-1, linewidth, -height, PATINVERT ); | 
|---|
| 105 | break; | 
|---|
| 106 |  | 
|---|
| 107 | case HTTOP: | 
|---|
| 108 | //clear old edge | 
|---|
| 109 | PatBlt( hdc, oldRect.left + width, oldRect.top, | 
|---|
| 110 | RECT_WIDTH(&oldRect) - 2*width, height, PATINVERT ); | 
|---|
| 111 | //and draw new one | 
|---|
| 112 | PatBlt( hdc, rect->left + width, rect->top, | 
|---|
| 113 | RECT_WIDTH(rect) - 2*width, height, PATINVERT ); | 
|---|
| 114 |  | 
|---|
| 115 | if(oldRect.top > rect->top) { | 
|---|
| 116 | y = rect->top; | 
|---|
| 117 | lineheight = oldRect.top - rect->top; | 
|---|
| 118 | } | 
|---|
| 119 | else { | 
|---|
| 120 | y = oldRect.top; | 
|---|
| 121 | lineheight = rect->top - oldRect.top; | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | PatBlt( hdc, oldRect.left,      y,  width, lineheight, PATINVERT ); | 
|---|
| 125 | PatBlt( hdc, oldRect.right - 1, y, -width, lineheight, PATINVERT ); | 
|---|
| 126 | break; | 
|---|
| 127 |  | 
|---|
| 128 | case HTBOTTOM: | 
|---|
| 129 | //clear old edge | 
|---|
| 130 | PatBlt( hdc, oldRect.left + width, oldRect.bottom-1, | 
|---|
| 131 | RECT_WIDTH(&oldRect) - 2*width, -height, PATINVERT ); | 
|---|
| 132 | //and draw new one | 
|---|
| 133 | PatBlt( hdc, rect->left + width, rect->bottom-1, | 
|---|
| 134 | RECT_WIDTH(rect) - 2*width, -height, PATINVERT ); | 
|---|
| 135 |  | 
|---|
| 136 | if(oldRect.bottom > rect->bottom) { | 
|---|
| 137 | y = rect->bottom; | 
|---|
| 138 | lineheight = oldRect.bottom - rect->bottom; | 
|---|
| 139 | } | 
|---|
| 140 | else { | 
|---|
| 141 | y = oldRect.bottom; | 
|---|
| 142 | lineheight = rect->bottom - oldRect.bottom; | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 | PatBlt( hdc, oldRect.left,      y,  width, lineheight, PATINVERT ); | 
|---|
| 146 | PatBlt( hdc, oldRect.right - 1, y, -width, lineheight, PATINVERT ); | 
|---|
| 147 | break; | 
|---|
| 148 |  | 
|---|
| 149 | case HTBOTTOMLEFT: | 
|---|
| 150 | //clear old edge (bottom) | 
|---|
| 151 | PatBlt( hdc, oldRect.left, oldRect.bottom-1, | 
|---|
| 152 | RECT_WIDTH(&oldRect) - width, -height, PATINVERT ); | 
|---|
| 153 | //and draw new one | 
|---|
| 154 | PatBlt( hdc, rect->left, rect->bottom-1, | 
|---|
| 155 | RECT_WIDTH(rect) - width, -height, PATINVERT ); | 
|---|
| 156 |  | 
|---|
| 157 | //clear old edge (left) | 
|---|
| 158 | PatBlt( hdc, oldRect.left, oldRect.top + height, | 
|---|
| 159 | width, RECT_HEIGHT(&oldRect) - 2*height, PATINVERT ); | 
|---|
| 160 | //and draw new one | 
|---|
| 161 | PatBlt( hdc, rect->left, rect->top + height, | 
|---|
| 162 | width, RECT_HEIGHT(rect) - 2*height, PATINVERT ); | 
|---|
| 163 |  | 
|---|
| 164 | //right | 
|---|
| 165 | if(oldRect.bottom > rect->bottom) { | 
|---|
| 166 | y = rect->bottom; | 
|---|
| 167 | lineheight = oldRect.bottom - rect->bottom; | 
|---|
| 168 | } | 
|---|
| 169 | else { | 
|---|
| 170 | y = oldRect.bottom; | 
|---|
| 171 | lineheight = rect->bottom - oldRect.bottom; | 
|---|
| 172 | } | 
|---|
| 173 | PatBlt( hdc, oldRect.right-1, y,  -width, lineheight, PATINVERT ); | 
|---|
| 174 |  | 
|---|
| 175 | //top | 
|---|
| 176 | if(oldRect.left > rect->left) { | 
|---|
| 177 | x = rect->left; | 
|---|
| 178 | linewidth = oldRect.left - rect->left; | 
|---|
| 179 | } | 
|---|
| 180 | else { | 
|---|
| 181 | x = oldRect.left; | 
|---|
| 182 | linewidth = rect->left - oldRect.left; | 
|---|
| 183 | } | 
|---|
| 184 | PatBlt(hdc, x, oldRect.top, linewidth, height,  PATINVERT); | 
|---|
| 185 | break; | 
|---|
| 186 |  | 
|---|
| 187 | case HTBOTTOMRIGHT: | 
|---|
| 188 | //clear old edge (bottom) | 
|---|
| 189 | PatBlt( hdc, oldRect.left + width, oldRect.bottom-1, | 
|---|
| 190 | RECT_WIDTH(&oldRect) - width, -height, PATINVERT ); | 
|---|
| 191 | //and draw new one | 
|---|
| 192 | PatBlt( hdc, rect->left + width, rect->bottom-1, | 
|---|
| 193 | RECT_WIDTH(rect) - width, -height, PATINVERT ); | 
|---|
| 194 |  | 
|---|
| 195 | //clear old edge (right) | 
|---|
| 196 | PatBlt( hdc, oldRect.right-1, oldRect.top + height, | 
|---|
| 197 | -width, RECT_HEIGHT(&oldRect) - 2*height, PATINVERT ); | 
|---|
| 198 | //and draw new one | 
|---|
| 199 | PatBlt( hdc, rect->right-1, rect->top + height, | 
|---|
| 200 | -width, RECT_HEIGHT(rect) - 2*height, PATINVERT ); | 
|---|
| 201 |  | 
|---|
| 202 | //left | 
|---|
| 203 | if(oldRect.bottom > rect->bottom) { | 
|---|
| 204 | y = rect->bottom; | 
|---|
| 205 | lineheight = oldRect.bottom - rect->bottom; | 
|---|
| 206 | } | 
|---|
| 207 | else { | 
|---|
| 208 | y = oldRect.bottom; | 
|---|
| 209 | lineheight = rect->bottom - oldRect.bottom; | 
|---|
| 210 | } | 
|---|
| 211 | PatBlt( hdc, oldRect.left, y, width, lineheight, PATINVERT ); | 
|---|
| 212 |  | 
|---|
| 213 | //top | 
|---|
| 214 | if(oldRect.right > rect->right) { | 
|---|
| 215 | x = rect->right; | 
|---|
| 216 | linewidth = oldRect.right - rect->right; | 
|---|
| 217 | } | 
|---|
| 218 | else { | 
|---|
| 219 | x = oldRect.right; | 
|---|
| 220 | linewidth = rect->right - oldRect.right; | 
|---|
| 221 | } | 
|---|
| 222 | PatBlt(hdc, x, oldRect.top, linewidth, height,  PATINVERT); | 
|---|
| 223 | break; | 
|---|
| 224 |  | 
|---|
| 225 | case HTTOPLEFT: | 
|---|
| 226 | //clear old edge (top) | 
|---|
| 227 | PatBlt( hdc, oldRect.left, oldRect.top, | 
|---|
| 228 | RECT_WIDTH(&oldRect) - width, height, PATINVERT ); | 
|---|
| 229 | //and draw new one | 
|---|
| 230 | PatBlt( hdc, rect->left, rect->top, | 
|---|
| 231 | RECT_WIDTH(rect) - width, height, PATINVERT ); | 
|---|
| 232 |  | 
|---|
| 233 | //clear old edge (left) | 
|---|
| 234 | PatBlt( hdc, oldRect.left, oldRect.top + height, | 
|---|
| 235 | width, RECT_HEIGHT(&oldRect) - 2*height, PATINVERT ); | 
|---|
| 236 | //and draw new one | 
|---|
| 237 | PatBlt( hdc, rect->left, rect->top + height, | 
|---|
| 238 | width, RECT_HEIGHT(rect) - 2*height, PATINVERT ); | 
|---|
| 239 |  | 
|---|
| 240 | //right | 
|---|
| 241 | if(oldRect.top > rect->top) { | 
|---|
| 242 | y = rect->top; | 
|---|
| 243 | lineheight = oldRect.top - rect->top; | 
|---|
| 244 | } | 
|---|
| 245 | else { | 
|---|
| 246 | y = oldRect.top; | 
|---|
| 247 | lineheight = rect->top - oldRect.top; | 
|---|
| 248 | } | 
|---|
| 249 | PatBlt( hdc, oldRect.right-1, y,  -width, lineheight, PATINVERT ); | 
|---|
| 250 |  | 
|---|
| 251 | //bottom | 
|---|
| 252 | if(oldRect.left > rect->left) { | 
|---|
| 253 | x = rect->left; | 
|---|
| 254 | linewidth = oldRect.left - rect->left; | 
|---|
| 255 | } | 
|---|
| 256 | else { | 
|---|
| 257 | x = oldRect.left; | 
|---|
| 258 | linewidth = rect->left - oldRect.left; | 
|---|
| 259 | } | 
|---|
| 260 | PatBlt(hdc, x, oldRect.bottom-1, linewidth, -height,  PATINVERT); | 
|---|
| 261 | break; | 
|---|
| 262 |  | 
|---|
| 263 | case HTTOPRIGHT: | 
|---|
| 264 | //clear old edge (top) | 
|---|
| 265 | PatBlt( hdc, oldRect.left+width, oldRect.top, | 
|---|
| 266 | RECT_WIDTH(&oldRect) - width, height, PATINVERT ); | 
|---|
| 267 | //and draw new one | 
|---|
| 268 | PatBlt( hdc, rect->left+width, rect->top, | 
|---|
| 269 | RECT_WIDTH(rect) - width, height, PATINVERT ); | 
|---|
| 270 |  | 
|---|
| 271 | //clear old edge (right) | 
|---|
| 272 | PatBlt( hdc, oldRect.right-1, oldRect.top + height, | 
|---|
| 273 | -width, RECT_HEIGHT(&oldRect) - 2*height, PATINVERT ); | 
|---|
| 274 | //and draw new one | 
|---|
| 275 | PatBlt( hdc, rect->right-1, rect->top + height, | 
|---|
| 276 | -width, RECT_HEIGHT(rect) - 2*height, PATINVERT ); | 
|---|
| 277 |  | 
|---|
| 278 | //left | 
|---|
| 279 | if(oldRect.top > rect->top) { | 
|---|
| 280 | y = rect->top; | 
|---|
| 281 | lineheight = oldRect.top - rect->top; | 
|---|
| 282 | } | 
|---|
| 283 | else { | 
|---|
| 284 | y = oldRect.top; | 
|---|
| 285 | lineheight = rect->top - oldRect.top; | 
|---|
| 286 | } | 
|---|
| 287 | PatBlt( hdc, oldRect.left, y,  width, lineheight, PATINVERT); | 
|---|
| 288 |  | 
|---|
| 289 | //bottom | 
|---|
| 290 | if(oldRect.right > rect->right) { | 
|---|
| 291 | x = rect->right; | 
|---|
| 292 | linewidth = oldRect.right - rect->right; | 
|---|
| 293 | } | 
|---|
| 294 | else { | 
|---|
| 295 | x = oldRect.right; | 
|---|
| 296 | linewidth = rect->right - oldRect.right; | 
|---|
| 297 | } | 
|---|
| 298 | PatBlt(hdc, x, oldRect.bottom-1, linewidth, -height,  PATINVERT); | 
|---|
| 299 | break; | 
|---|
| 300 | } | 
|---|
| 301 | oldRect = *rect; | 
|---|
| 302 | } | 
|---|
| 303 | else { | 
|---|
| 304 | if(fRedraw) { | 
|---|
| 305 | PatBlt( hdc, oldRect.left, oldRect.top, | 
|---|
| 306 | RECT_WIDTH(&oldRect) - width, height, PATINVERT ); | 
|---|
| 307 | PatBlt( hdc, oldRect.left, oldRect.top + height, width, | 
|---|
| 308 | RECT_HEIGHT(&oldRect) - height, PATINVERT ); | 
|---|
| 309 | PatBlt( hdc, oldRect.left + width, oldRect.bottom - 1, | 
|---|
| 310 | RECT_WIDTH(&oldRect) - width, -height, PATINVERT ); | 
|---|
| 311 | PatBlt( hdc, oldRect.right - 1, oldRect.top, -width, | 
|---|
| 312 | RECT_HEIGHT(&oldRect) - height, PATINVERT ); | 
|---|
| 313 | } | 
|---|
| 314 | oldRect = *rect; | 
|---|
| 315 | PatBlt( hdc, rect->left, rect->top, | 
|---|
| 316 | rect->right - rect->left - width, height, PATINVERT ); | 
|---|
| 317 | PatBlt( hdc, rect->left, rect->top + height, width, | 
|---|
| 318 | rect->bottom - rect->top - height, PATINVERT ); | 
|---|
| 319 | PatBlt( hdc, rect->left + width, rect->bottom - 1, | 
|---|
| 320 | rect->right - rect->left - width, -height, PATINVERT ); | 
|---|
| 321 | PatBlt( hdc, rect->right - 1, rect->top, -width, | 
|---|
| 322 | rect->bottom - rect->top - height, PATINVERT ); | 
|---|
| 323 | } | 
|---|
| 324 | SelectObject( hdc, hbrush ); | 
|---|
| 325 | } | 
|---|
| 326 | else DrawFocusRect( hdc, rect ); | 
|---|
| 327 | } | 
|---|
| 328 |  | 
|---|
| 329 |  | 
|---|
| 330 | /*********************************************************************** | 
|---|
| 331 | *           start_size_move | 
|---|
| 332 | * | 
|---|
| 333 | * Initialisation of a move or resize, when initiatied from a menu choice. | 
|---|
| 334 | * Return hit test code for caption or sizing border. | 
|---|
| 335 | */ | 
|---|
| 336 | static LONG start_size_move( Win32BaseWindow *win32wnd, WPARAM wParam, POINT *capturePoint, LONG style ) | 
|---|
| 337 | { | 
|---|
| 338 | HWND hwnd = win32wnd->getWindowHandle(); | 
|---|
| 339 | LONG hittest = 0; | 
|---|
| 340 | POINT pt; | 
|---|
| 341 | MSG msg; | 
|---|
| 342 | RECT rectWindow; | 
|---|
| 343 |  | 
|---|
| 344 | GetWindowRect( hwnd, &rectWindow ); | 
|---|
| 345 |  | 
|---|
| 346 | if ((wParam & 0xfff0) == SC_MOVE) | 
|---|
| 347 | { | 
|---|
| 348 | /* Move pointer at the center of the caption */ | 
|---|
| 349 | RECT rect; | 
|---|
| 350 | win32wnd->GetInsideRect( &rect ); | 
|---|
| 351 | if (style & WS_SYSMENU) | 
|---|
| 352 | rect.left += GetSystemMetrics(SM_CXSIZE) + 1; | 
|---|
| 353 | if (style & WS_MINIMIZEBOX) | 
|---|
| 354 | rect.right -= GetSystemMetrics(SM_CXSIZE) + 1; | 
|---|
| 355 | if (style & WS_MAXIMIZEBOX) | 
|---|
| 356 | rect.right -= GetSystemMetrics(SM_CXSIZE) + 1; | 
|---|
| 357 | pt.x = rectWindow.left + (rect.right - rect.left) / 2; | 
|---|
| 358 | pt.y = rectWindow.top + rect.top + GetSystemMetrics(SM_CYSIZE)/2; | 
|---|
| 359 | hittest = HTCAPTION; | 
|---|
| 360 | *capturePoint = pt; | 
|---|
| 361 | } | 
|---|
| 362 | else  /* SC_SIZE */ | 
|---|
| 363 | { | 
|---|
| 364 | while(!hittest) | 
|---|
| 365 | { | 
|---|
| 366 | //            GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST ); | 
|---|
| 367 | GetMessageW( &msg, 0, 0, 0 ); | 
|---|
| 368 | if (CallMsgFilterW( &msg, MSGF_SIZE )) continue; | 
|---|
| 369 |  | 
|---|
| 370 | switch(msg.message) | 
|---|
| 371 | { | 
|---|
| 372 | case WM_MOUSEMOVE: | 
|---|
| 373 | hittest = win32wnd->HandleNCHitTest( msg.pt ); | 
|---|
| 374 | //                hittest = NC_HandleNCHitTest( hwnd, msg.pt ); | 
|---|
| 375 | if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) | 
|---|
| 376 | hittest = 0; | 
|---|
| 377 | break; | 
|---|
| 378 |  | 
|---|
| 379 | case WM_LBUTTONUP: | 
|---|
| 380 | return 0; | 
|---|
| 381 |  | 
|---|
| 382 | case WM_KEYDOWN: | 
|---|
| 383 | switch(msg.wParam) | 
|---|
| 384 | { | 
|---|
| 385 | case VK_UP: | 
|---|
| 386 | hittest = HTTOP; | 
|---|
| 387 | pt.x =(rectWindow.left+rectWindow.right)/2; | 
|---|
| 388 | pt.y = rectWindow.top + GetSystemMetrics(SM_CYFRAME) / 2; | 
|---|
| 389 | break; | 
|---|
| 390 | case VK_DOWN: | 
|---|
| 391 | hittest = HTBOTTOM; | 
|---|
| 392 | pt.x =(rectWindow.left+rectWindow.right)/2; | 
|---|
| 393 | pt.y = rectWindow.bottom - GetSystemMetrics(SM_CYFRAME) / 2; | 
|---|
| 394 | break; | 
|---|
| 395 | case VK_LEFT: | 
|---|
| 396 | hittest = HTLEFT; | 
|---|
| 397 | pt.x = rectWindow.left + GetSystemMetrics(SM_CXFRAME) / 2; | 
|---|
| 398 | pt.y =(rectWindow.top+rectWindow.bottom)/2; | 
|---|
| 399 | break; | 
|---|
| 400 | case VK_RIGHT: | 
|---|
| 401 | hittest = HTRIGHT; | 
|---|
| 402 | pt.x = rectWindow.right - GetSystemMetrics(SM_CXFRAME) / 2; | 
|---|
| 403 | pt.y =(rectWindow.top+rectWindow.bottom)/2; | 
|---|
| 404 | break; | 
|---|
| 405 | case VK_RETURN: | 
|---|
| 406 | case VK_ESCAPE: return 0; | 
|---|
| 407 | } | 
|---|
| 408 | } | 
|---|
| 409 | } | 
|---|
| 410 | *capturePoint = pt; | 
|---|
| 411 | } | 
|---|
| 412 | SetCursorPos( pt.x, pt.y ); | 
|---|
| 413 | win32wnd->DefWindowProcA(WM_SETCURSOR, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE )); | 
|---|
| 414 | //    NC_HandleSetCursor( hwnd, (WPARAM)hwnd, MAKELONG( hittest, WM_MOUSEMOVE )); | 
|---|
| 415 | dprintf(("start_size_move: hittest %d", hittest)); | 
|---|
| 416 | return hittest; | 
|---|
| 417 | } | 
|---|
| 418 |  | 
|---|
| 419 |  | 
|---|
| 420 | /*********************************************************************** | 
|---|
| 421 | *           SysCommandSizeMove   (X11DRV.@) | 
|---|
| 422 | * | 
|---|
| 423 | * Perform SC_MOVE and SC_SIZE commands. | 
|---|
| 424 | */ | 
|---|
| 425 | void Frame_SysCommandSizeMove(Win32BaseWindow *win32wnd, WPARAM wParam ) | 
|---|
| 426 | { | 
|---|
| 427 | HWND hwnd = win32wnd->getWindowHandle(); | 
|---|
| 428 | MSG msg; | 
|---|
| 429 | RECT sizingRect, mouseRect, origRect, lastsizingRect; | 
|---|
| 430 | HDC hdc; | 
|---|
| 431 | HWND parent; | 
|---|
| 432 | LONG hittest = (LONG)(wParam & 0x0f); | 
|---|
| 433 | HCURSOR16 hDragCursor = 0, hOldCursor = 0; | 
|---|
| 434 | POINT minTrack, maxTrack; | 
|---|
| 435 | POINT capturePoint, pt; | 
|---|
| 436 | LONG style = GetWindowLongA( hwnd, GWL_STYLE ); | 
|---|
| 437 | LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE ); | 
|---|
| 438 | BOOL    thickframe = HAS_THICKFRAME( style, exstyle ); | 
|---|
| 439 | BOOL    iconic = style & WS_MINIMIZE; | 
|---|
| 440 | BOOL    moved = FALSE; | 
|---|
| 441 | DWORD     dwPoint = GetMessagePos (); | 
|---|
| 442 | BOOL DragFullWindows = FALSE; | 
|---|
| 443 | BOOL grab; | 
|---|
| 444 | int iWndsLocks; | 
|---|
| 445 |  | 
|---|
| 446 | dprintf(("FrameTrackFrame %x", wParam)); | 
|---|
| 447 |  | 
|---|
| 448 | SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS, 0, &DragFullWindows, 0); | 
|---|
| 449 |  | 
|---|
| 450 | pt.x = SLOWORD(dwPoint); | 
|---|
| 451 | pt.y = SHIWORD(dwPoint); | 
|---|
| 452 | capturePoint = pt; | 
|---|
| 453 |  | 
|---|
| 454 | //    if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) || (exstyle & WS_EX_MANAGED)) return; | 
|---|
| 455 | if (IsZoomed(hwnd) || !IsWindowVisible(hwnd)) return; | 
|---|
| 456 |  | 
|---|
| 457 | if ((wParam & 0xfff0) == SC_MOVE) | 
|---|
| 458 | { | 
|---|
| 459 | if (!hittest) hittest = start_size_move( win32wnd, wParam, &capturePoint, style ); | 
|---|
| 460 | if (!hittest) return; | 
|---|
| 461 | } | 
|---|
| 462 | else  /* SC_SIZE */ | 
|---|
| 463 | { | 
|---|
| 464 | if (!thickframe) return; | 
|---|
| 465 | if ( hittest && hittest != HTSYSMENU ) hittest += 2; | 
|---|
| 466 | else | 
|---|
| 467 | { | 
|---|
| 468 | SetCapture(hwnd); | 
|---|
| 469 | hittest = start_size_move( win32wnd, wParam, &capturePoint, style ); | 
|---|
| 470 | if (!hittest) | 
|---|
| 471 | { | 
|---|
| 472 | ReleaseCapture(); | 
|---|
| 473 | return; | 
|---|
| 474 | } | 
|---|
| 475 | } | 
|---|
| 476 | } | 
|---|
| 477 |  | 
|---|
| 478 | /* Get min/max info */ | 
|---|
| 479 |  | 
|---|
| 480 | //    WINPOS_GetMinMaxInfo( hwnd, NULL, NULL, &minTrack, &maxTrack ); | 
|---|
| 481 | win32wnd->AdjustTrackInfo(&minTrack, &maxTrack); | 
|---|
| 482 | GetWindowRect( hwnd, &sizingRect ); | 
|---|
| 483 | if (style & WS_CHILD) | 
|---|
| 484 | { | 
|---|
| 485 | parent = GetParent(hwnd); | 
|---|
| 486 | /* make sizing rect relative to parent */ | 
|---|
| 487 | MapWindowPoints( 0, parent, (POINT*)&sizingRect, 2 ); | 
|---|
| 488 | GetClientRect( parent, &mouseRect ); | 
|---|
| 489 | } | 
|---|
| 490 | else | 
|---|
| 491 | { | 
|---|
| 492 | parent = GetDesktopWindow(); | 
|---|
| 493 | SetRect(&mouseRect, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); | 
|---|
| 494 | } | 
|---|
| 495 | origRect = sizingRect; | 
|---|
| 496 |  | 
|---|
| 497 | if (ON_LEFT_BORDER(hittest)) | 
|---|
| 498 | { | 
|---|
| 499 | mouseRect.left  = max( mouseRect.left, sizingRect.right-maxTrack.x ); | 
|---|
| 500 | mouseRect.right = min( mouseRect.right, sizingRect.right-minTrack.x ); | 
|---|
| 501 | } | 
|---|
| 502 | else if (ON_RIGHT_BORDER(hittest)) | 
|---|
| 503 | { | 
|---|
| 504 | mouseRect.left  = max( mouseRect.left, sizingRect.left+minTrack.x ); | 
|---|
| 505 | mouseRect.right = min( mouseRect.right, sizingRect.left+maxTrack.x ); | 
|---|
| 506 | } | 
|---|
| 507 | if (ON_TOP_BORDER(hittest)) | 
|---|
| 508 | { | 
|---|
| 509 | mouseRect.top    = max( mouseRect.top, sizingRect.bottom-maxTrack.y ); | 
|---|
| 510 | mouseRect.bottom = min( mouseRect.bottom,sizingRect.bottom-minTrack.y); | 
|---|
| 511 | } | 
|---|
| 512 | else if (ON_BOTTOM_BORDER(hittest)) | 
|---|
| 513 | { | 
|---|
| 514 | mouseRect.top    = max( mouseRect.top, sizingRect.top+minTrack.y ); | 
|---|
| 515 | mouseRect.bottom = min( mouseRect.bottom, sizingRect.top+maxTrack.y ); | 
|---|
| 516 | } | 
|---|
| 517 | if (parent) MapWindowPoints( parent, 0, (LPPOINT)&mouseRect, 2 ); | 
|---|
| 518 |  | 
|---|
| 519 | /* Retrieve a default cache DC (without using the window style) */ | 
|---|
| 520 | hdc = GetDCEx( parent, 0, DCX_CACHE); | 
|---|
| 521 |  | 
|---|
| 522 | if( iconic ) /* create a cursor for dragging */ | 
|---|
| 523 | { | 
|---|
| 524 | HICON hIcon = GetClassLongA( hwnd, GCL_HICON); | 
|---|
| 525 | if(!hIcon) hIcon = (HICON)SendMessageA( hwnd, WM_QUERYDRAGICON, 0, 0L); | 
|---|
| 526 | if( hIcon ) hDragCursor = hIcon; | 
|---|
| 527 | // CURSORICON_IconToCursor( hIcon, TRUE ); | 
|---|
| 528 | if( !hDragCursor ) iconic = FALSE; | 
|---|
| 529 | } | 
|---|
| 530 |  | 
|---|
| 531 | /* repaint the window before moving it around */ | 
|---|
| 532 | RedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN ); | 
|---|
| 533 |  | 
|---|
| 534 | SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 ); | 
|---|
| 535 | SetCapture( hwnd ); | 
|---|
| 536 |  | 
|---|
| 537 | //prevent the app from drawing to this window (or its children) | 
|---|
| 538 | if(!DragFullWindows) | 
|---|
| 539 | LockWindowUpdate(hwnd); | 
|---|
| 540 |  | 
|---|
| 541 | while(1) | 
|---|
| 542 | { | 
|---|
| 543 | int dx = 0, dy = 0; | 
|---|
| 544 |  | 
|---|
| 545 | //        if (!GetMessageW( &msg, 0, WM_KEYFIRST, WM_MOUSELAST )) break; | 
|---|
| 546 | if (!GetMessageW( &msg, 0, 0, 0 )) break; | 
|---|
| 547 | if (CallMsgFilterW( &msg, MSGF_SIZE )) continue; | 
|---|
| 548 |  | 
|---|
| 549 | /* Exit on button-up, Return, or Esc */ | 
|---|
| 550 | if ((msg.message == WM_LBUTTONUP) || | 
|---|
| 551 | ((msg.message == WM_KEYDOWN) && | 
|---|
| 552 | ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break; | 
|---|
| 553 |  | 
|---|
| 554 | if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE)) { | 
|---|
| 555 | DispatchMessageA(&msg); | 
|---|
| 556 | continue;  /* We are not interested in other messages */ | 
|---|
| 557 | } | 
|---|
| 558 |  | 
|---|
| 559 | pt = msg.pt; | 
|---|
| 560 |  | 
|---|
| 561 | if (msg.message == WM_KEYDOWN) switch(msg.wParam) | 
|---|
| 562 | { | 
|---|
| 563 | case VK_UP:    pt.y -= 8; break; | 
|---|
| 564 | case VK_DOWN:  pt.y += 8; break; | 
|---|
| 565 | case VK_LEFT:  pt.x -= 8; break; | 
|---|
| 566 | case VK_RIGHT: pt.x += 8; break; | 
|---|
| 567 | } | 
|---|
| 568 |  | 
|---|
| 569 | pt.x = max( pt.x, mouseRect.left ); | 
|---|
| 570 | pt.x = min( pt.x, mouseRect.right ); | 
|---|
| 571 | pt.y = max( pt.y, mouseRect.top ); | 
|---|
| 572 | pt.y = min( pt.y, mouseRect.bottom ); | 
|---|
| 573 |  | 
|---|
| 574 | dprintf(("mouseRect (%d,%d)(%d,%d)", mouseRect.left, mouseRect.top, mouseRect.right, mouseRect.bottom)); | 
|---|
| 575 | dprintf(("capturePoint (%d,%d)", capturePoint.x, capturePoint.y)); | 
|---|
| 576 | dx = pt.x - capturePoint.x; | 
|---|
| 577 | dy = pt.y - capturePoint.y; | 
|---|
| 578 |  | 
|---|
| 579 | if (dx || dy) | 
|---|
| 580 | { | 
|---|
| 581 | if( !moved ) | 
|---|
| 582 | { | 
|---|
| 583 | moved = TRUE; | 
|---|
| 584 |  | 
|---|
| 585 | if( iconic ) /* ok, no system popup tracking */ | 
|---|
| 586 | { | 
|---|
| 587 | hOldCursor = SetCursor(hDragCursor); | 
|---|
| 588 | ShowCursor( TRUE ); | 
|---|
| 589 | //                    WINPOS_ShowIconTitle( hwnd, FALSE ); | 
|---|
| 590 | } | 
|---|
| 591 | else if(!DragFullWindows) | 
|---|
| 592 | draw_moving_frame( hdc, &sizingRect, thickframe, hittest, FALSE ); | 
|---|
| 593 | } | 
|---|
| 594 |  | 
|---|
| 595 | if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y ); | 
|---|
| 596 | else | 
|---|
| 597 | { | 
|---|
| 598 | RECT newRect = sizingRect, tempRect; | 
|---|
| 599 | WPARAM wpSizingHit = 0; | 
|---|
| 600 |  | 
|---|
| 601 | if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy ); | 
|---|
| 602 |  | 
|---|
| 603 | if (ON_LEFT_BORDER(hittest)) newRect.left += dx; | 
|---|
| 604 | else | 
|---|
| 605 | if (ON_RIGHT_BORDER(hittest)) newRect.right += dx; | 
|---|
| 606 |  | 
|---|
| 607 | if (ON_TOP_BORDER(hittest)) newRect.top += dy; | 
|---|
| 608 | else | 
|---|
| 609 | if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy; | 
|---|
| 610 |  | 
|---|
| 611 | ////                if(!iconic && !DragFullWindows) draw_moving_frame( hdc, &sizingRect, thickframe, hittest, TRUE); | 
|---|
| 612 |  | 
|---|
| 613 | /* determine the hit location */ | 
|---|
| 614 | if (hittest >= HTLEFT && hittest <= HTBOTTOMRIGHT) | 
|---|
| 615 | wpSizingHit = WMSZ_LEFT + (hittest - HTLEFT); | 
|---|
| 616 |  | 
|---|
| 617 | tempRect = newRect; | 
|---|
| 618 |  | 
|---|
| 619 | dprintf(("WM_SIZING rect (%d,%d)(%d,%d)", newRect.left, newRect.top, newRect.right, newRect.bottom)); | 
|---|
| 620 |  | 
|---|
| 621 | //Although the docs say the app should return TRUE when processing | 
|---|
| 622 | //this message, experiments show that NT checks the rectangle | 
|---|
| 623 | //regardless of the return value | 
|---|
| 624 | if ((wParam & 0xfff0) == SC_MOVE) { | 
|---|
| 625 | SendMessageA( hwnd, WM_MOVING, wpSizingHit, (LPARAM)&newRect ); | 
|---|
| 626 | } | 
|---|
| 627 | else SendMessageA( hwnd, WM_SIZING, wpSizingHit, (LPARAM)&newRect ); | 
|---|
| 628 |  | 
|---|
| 629 | dprintf(("WM_SIZING rect (%d,%d)(%d,%d)", newRect.left, newRect.top, newRect.right, newRect.bottom)); | 
|---|
| 630 |  | 
|---|
| 631 | dprintf(("update capture point dx %d dy %d", dx, dy)); | 
|---|
| 632 | capturePoint   = pt; | 
|---|
| 633 | sizingRect     = tempRect; | 
|---|
| 634 | lastsizingRect = newRect; | 
|---|
| 635 |  | 
|---|
| 636 | if (!iconic) | 
|---|
| 637 | { | 
|---|
| 638 | if(!DragFullWindows) | 
|---|
| 639 | draw_moving_frame( hdc, &newRect, thickframe, hittest, TRUE ); | 
|---|
| 640 | else { | 
|---|
| 641 | /* To avoid any deadlocks, all the locks on the windows | 
|---|
| 642 | structures must be suspended before the SetWindowPos */ | 
|---|
| 643 | //                        iWndsLocks = WIN_SuspendWndsLock(); | 
|---|
| 644 | SetWindowPos( hwnd, 0, newRect.left, newRect.top, | 
|---|
| 645 | newRect.right - newRect.left, | 
|---|
| 646 | newRect.bottom - newRect.top, | 
|---|
| 647 | ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 ); | 
|---|
| 648 | //                        WIN_RestoreWndsLock(iWndsLocks); | 
|---|
| 649 | } | 
|---|
| 650 | } | 
|---|
| 651 | } | 
|---|
| 652 | } | 
|---|
| 653 | } | 
|---|
| 654 |  | 
|---|
| 655 | //Enable window update | 
|---|
| 656 | if(!DragFullWindows) | 
|---|
| 657 | LockWindowUpdate(NULL); | 
|---|
| 658 |  | 
|---|
| 659 | ReleaseCapture(); | 
|---|
| 660 | if( iconic ) | 
|---|
| 661 | { | 
|---|
| 662 | if( moved ) /* restore cursors, show icon title later on */ | 
|---|
| 663 | { | 
|---|
| 664 | ShowCursor( FALSE ); | 
|---|
| 665 | SetCursor( hOldCursor ); | 
|---|
| 666 | } | 
|---|
| 667 | DestroyCursor( hDragCursor ); | 
|---|
| 668 | } | 
|---|
| 669 | else if (moved && !DragFullWindows) | 
|---|
| 670 | draw_moving_frame( hdc, &lastsizingRect, thickframe, hittest, FALSE); | 
|---|
| 671 |  | 
|---|
| 672 | ReleaseDC( parent, hdc ); | 
|---|
| 673 |  | 
|---|
| 674 | //    wine_tsx11_lock(); | 
|---|
| 675 | //    XUngrabPointer( display, CurrentTime ); | 
|---|
| 676 | //    if (grab) | 
|---|
| 677 | //    { | 
|---|
| 678 | //        XSync( display, False ); | 
|---|
| 679 | //        XUngrabServer( display ); | 
|---|
| 680 | //        XSync( display, False ); | 
|---|
| 681 | //        gdi_display = old_gdi_display; | 
|---|
| 682 | //    } | 
|---|
| 683 | //    wine_tsx11_unlock(); | 
|---|
| 684 |  | 
|---|
| 685 | if (HOOK_CallHooksA( WH_CBT, HCBT_MOVESIZE, (WPARAM)hwnd, (LPARAM)&lastsizingRect )) moved = FALSE; | 
|---|
| 686 |  | 
|---|
| 687 | SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, 0 ); | 
|---|
| 688 | SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), 0L); | 
|---|
| 689 |  | 
|---|
| 690 | /* window moved or resized */ | 
|---|
| 691 | if (moved) | 
|---|
| 692 | { | 
|---|
| 693 | /* To avoid any deadlocks, all the locks on the windows | 
|---|
| 694 | structures must be suspended before the SetWindowPos */ | 
|---|
| 695 | //        iWndsLocks = WIN_SuspendWndsLock(); | 
|---|
| 696 |  | 
|---|
| 697 | /* if the moving/resizing isn't canceled call SetWindowPos | 
|---|
| 698 | * with the new position or the new size of the window | 
|---|
| 699 | */ | 
|---|
| 700 | if (!((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) ) | 
|---|
| 701 | { | 
|---|
| 702 | /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */ | 
|---|
| 703 | if(!DragFullWindows) | 
|---|
| 704 | SetWindowPos( hwnd, 0, lastsizingRect.left, lastsizingRect.top, | 
|---|
| 705 | lastsizingRect.right - lastsizingRect.left, | 
|---|
| 706 | lastsizingRect.bottom - lastsizingRect.top, | 
|---|
| 707 | ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 ); | 
|---|
| 708 | } | 
|---|
| 709 | else | 
|---|
| 710 | { /* restore previous size/position */ | 
|---|
| 711 | if(DragFullWindows) | 
|---|
| 712 | SetWindowPos( hwnd, 0, origRect.left, origRect.top, | 
|---|
| 713 | origRect.right - origRect.left, | 
|---|
| 714 | origRect.bottom - origRect.top, | 
|---|
| 715 | ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 ); | 
|---|
| 716 | } | 
|---|
| 717 |  | 
|---|
| 718 | //        WIN_RestoreWndsLock(iWndsLocks); | 
|---|
| 719 | } | 
|---|
| 720 |  | 
|---|
| 721 | if (IsIconic(hwnd)) | 
|---|
| 722 | { | 
|---|
| 723 | /* Single click brings up the system menu when iconized */ | 
|---|
| 724 |  | 
|---|
| 725 | if( !moved ) | 
|---|
| 726 | { | 
|---|
| 727 | if(style & WS_SYSMENU ) | 
|---|
| 728 | SendMessageA( hwnd, WM_SYSCOMMAND, | 
|---|
| 729 | SC_MOUSEMENU + HTSYSMENU, MAKELONG(pt.x,pt.y)); | 
|---|
| 730 | } | 
|---|
| 731 | //        else WINPOS_ShowIconTitle( hwnd, TRUE ); | 
|---|
| 732 | } | 
|---|
| 733 | } | 
|---|
| 734 |  | 
|---|
| 735 | #endif //#ifdef CUSTOM_TRACKFRAME | 
|---|