wincreatewnd.c 17.7 KB
Newer Older
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1
/*
2
 *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved.
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 *Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 *"Software"), to deal in the Software without restriction, including
 *without limitation the rights to use, copy, modify, merge, publish,
 *distribute, sublicense, and/or sell copies of the Software, and to
 *permit persons to whom the Software is furnished to do so, subject to
 *the following conditions:
 *
 *The above copyright notice and this permission notice shall be
 *included in all copies or substantial portions of the Software.
 *
 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
 *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
19 20 21 22
 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
23
 *Except as contained in this notice, the name of Harold L Hunt II
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
24 25
 *shall not be used in advertising or otherwise to promote the sale, use
 *or other dealings in this Software without prior written authorization
26
 *from Harold L Hunt II.
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
27 28 29 30 31 32 33
 *
 * Authors:	Harold L Hunt II
 */

#include "win.h"
#include "shellapi.h"

34 35 36
#ifndef ABS_AUTOHIDE
#define ABS_AUTOHIDE 1
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

/*
 * Local function prototypes
 */

static Bool
winGetWorkArea (RECT *prcWorkArea, winScreenInfo *pScreenInfo);

static Bool
winAdjustForAutoHide (RECT *prcWorkArea);


/*
 * Create a full screen window
 */

Bool
winCreateBoundingWindowFullScreen (ScreenPtr pScreen)
{
  winScreenPriv(pScreen);
  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
  int			iWidth = pScreenInfo->dwWidth;
  int			iHeight = pScreenInfo->dwHeight;
  HWND			*phwnd = &pScreenPriv->hwndScreen;
  WNDCLASS		wc;
62
  char			szTitle[256];
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
63 64

#if CYGDEBUG
65
  winDebug ("winCreateBoundingWindowFullScreen\n");
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#endif

  /* Setup our window class */
  wc.style = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc = winWindowProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = g_hInstance;
  wc.hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
  wc.hCursor = 0;
  wc.hbrBackground = 0;
  wc.lpszMenuName = NULL;
  wc.lpszClassName = WINDOW_CLASS;
  RegisterClass (&wc);

81 82 83 84 85 86 87 88 89 90 91 92 93
  /* Set display and screen-specific tooltip text */
  if (g_pszQueryHost != NULL)
    snprintf (szTitle,
	    sizeof (szTitle),
	    WINDOW_TITLE_XDMCP,
	    g_pszQueryHost); 
  else    
    snprintf (szTitle,
	    sizeof (szTitle),
	    WINDOW_TITLE,
	    display, 
	    (int) pScreenInfo->dwScreen);

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
94
  /* Create the window */
95
  *phwnd = CreateWindowExA (0,			/* Extended styles */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
96
			    WINDOW_CLASS,	/* Class name */
97
			    szTitle,		/* Window name */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
98 99 100 101 102 103 104 105 106 107 108 109 110
			    WS_POPUP,
			    0,			/* Horizontal position */
			    0,			/* Vertical position */
			    iWidth,		/* Right edge */ 
			    iHeight,		/* Bottom edge */
			    (HWND) NULL,	/* No parent or owner window */
			    (HMENU) NULL,	/* No menu */
			    GetModuleHandle (NULL),/* Instance handle */
			    pScreenPriv);	/* ScreenPrivates */

  /* Branch on the server engine */
  switch (pScreenInfo->dwEngine)
    {
111
#ifdef XWIN_NATIVEGDI
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
112 113 114 115
    case WIN_SERVER_SHADOW_GDI:
      /* Show the window */
      ShowWindow (*phwnd, SW_SHOWMAXIMIZED);
      break;
116
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
117 118 119 120 121 122

    default:
      /* Hide the window */
      ShowWindow (*phwnd, SW_SHOWNORMAL);
      break;
    }
123

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  /* Send first paint message */
  UpdateWindow (*phwnd);

  /* Attempt to bring our window to the top of the display */
  BringWindowToTop (*phwnd);

  return TRUE;
}


/*
 * Create our primary Windows display window
 */

Bool
winCreateBoundingWindowWindowed (ScreenPtr pScreen)
{
  winScreenPriv(pScreen);
  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
  int			iWidth = pScreenInfo->dwUserWidth;
  int			iHeight = pScreenInfo->dwUserHeight;
  HWND			*phwnd = &pScreenPriv->hwndScreen;
  WNDCLASS		wc;
  RECT			rcClient, rcWorkArea;
  DWORD			dwWindowStyle;
149
  char			szTitle[256];
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
150
  
151 152 153 154 155
  winDebug ("winCreateBoundingWindowWindowed - User w: %d h: %d\n",
	  (int) pScreenInfo->dwUserWidth, (int) pScreenInfo->dwUserHeight);
  winDebug ("winCreateBoundingWindowWindowed - Current w: %d h: %d\n",
	  (int) pScreenInfo->dwWidth, (int) pScreenInfo->dwHeight);

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
156 157 158 159 160
  /* Set the common window style flags */
  dwWindowStyle = WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;
  
  /* Decorated or undecorated window */
  if (pScreenInfo->fDecoration
161 162 163
#ifdef XWIN_MULTIWINDOWEXTWM
      && !pScreenInfo->fMWExtWM
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
164
      && !pScreenInfo->fRootless
165 166 167 168
#ifdef XWIN_MULTIWINDOW
      && !pScreenInfo->fMultiWindow
#endif
      )
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
    {
      dwWindowStyle |= WS_CAPTION;
      if (pScreenInfo->fScrollbars)
	dwWindowStyle |= WS_THICKFRAME | WS_MAXIMIZEBOX;
    }
  else
    dwWindowStyle |= WS_POPUP;

  /* Setup our window class */
  wc.style = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc = winWindowProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = g_hInstance;
  wc.hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
  wc.hCursor = 0;
  wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = WINDOW_CLASS;
  RegisterClass (&wc);

  /* Get size of work area */
  winGetWorkArea (&rcWorkArea, pScreenInfo);

  /* Adjust for auto-hide taskbars */
  winAdjustForAutoHide (&rcWorkArea);

  /* Did the user specify a height and width? */
  if (pScreenInfo->fUserGaveHeightAndWidth)
    {
      /* User gave a desired height and width, try to accomodate */
#if CYGDEBUG
201
      winDebug ("winCreateBoundingWindowWindowed - User gave height "
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
202 203 204 205 206
	      "and width\n");
#endif
      
      /* Adjust the window width and height for borders and title bar */
      if (pScreenInfo->fDecoration
207 208 209
#ifdef XWIN_MULTIWINDOWEXTWM
	  && !pScreenInfo->fMWExtWM
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
210
	  && !pScreenInfo->fRootless
211 212 213 214
#ifdef XWIN_MULTIWINDOW
	  && !pScreenInfo->fMultiWindow
#endif
	  )
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
215 216
	{
#if CYGDEBUG
217
	  winDebug ("winCreateBoundingWindowWindowed - Window has decoration\n");
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
218 219 220 221 222
#endif
	  /* Are we using scrollbars? */
	  if (pScreenInfo->fScrollbars)
	    {
#if CYGDEBUG
223
	      winDebug ("winCreateBoundingWindowWindowed - Window has "
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
224 225 226 227 228 229 230 231 232 233
		      "scrollbars\n");
#endif

	      iWidth += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
	      iHeight += 2 * GetSystemMetrics (SM_CYSIZEFRAME) 
		+ GetSystemMetrics (SM_CYCAPTION);
	    }
	  else
	    {
#if CYGDEBUG
234
	      winDebug ("winCreateBoundingWindowWindowed - Window does not have "
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
235 236 237 238 239 240 241 242 243 244 245 246 247
		      "scrollbars\n");
#endif

	      iWidth += 2 * GetSystemMetrics (SM_CXFIXEDFRAME);
	      iHeight += 2 * GetSystemMetrics (SM_CYFIXEDFRAME) 
		+ GetSystemMetrics (SM_CYCAPTION);
	    }
	}
    }
  else
    {
      /* By default, we are creating a window that is as large as possible */
#if CYGDEBUG
248
      winDebug ("winCreateBoundingWindowWindowed - User did not give "
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
249 250 251 252 253 254 255 256 257 258 259 260
	      "height and width\n");
#endif
      /* Defaults are wrong if we have multiple monitors */
      if (pScreenInfo->fMultipleMonitors)
	{
	  iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
	  iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
	}
    }

  /* Clean up the scrollbars flag, if necessary */
  if ((!pScreenInfo->fDecoration
261 262 263
#ifdef XWIN_MULTIWINDOWEXTWM
       || pScreenInfo->fMWExtWM
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
264
       || pScreenInfo->fRootless
265 266 267 268
#ifdef XWIN_MULTIWINDOW
       || pScreenInfo->fMultiWindow
#endif
       )
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
269 270 271 272 273
      && pScreenInfo->fScrollbars)
    {
      /* We cannot have scrollbars if we do not have a window border */
      pScreenInfo->fScrollbars = FALSE;
    }
274 275 276 277 278 279 280 281 282 283 284 285 286
 
  if (TRUE 
#ifdef XWIN_MULTIWINDOWEXTWM
       && !pScreenInfo->fMWExtWM
#endif
#ifdef XWIN_MULTIWINDOW
       && !pScreenInfo->fMultiWindow
#endif
     )
    {
      /* Trim window width to fit work area */
      if (iWidth > (rcWorkArea.right - rcWorkArea.left))
        iWidth = rcWorkArea.right - rcWorkArea.left;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
287
  
288 289 290
      /* Trim window height to fit work area */
      if (iHeight >= (rcWorkArea.bottom - rcWorkArea.top))
        iHeight = rcWorkArea.bottom - rcWorkArea.top;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
291 292
  
#if CYGDEBUG
293 294 295
      winDebug ("winCreateBoundingWindowWindowed - Adjusted width: %d "\
	      "height: %d\n",
    	  iWidth, iHeight);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
296
#endif
297
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
298

299 300 301 302 303 304 305 306 307 308 309 310 311
  /* Set display and screen-specific tooltip text */
  if (g_pszQueryHost != NULL)
    snprintf (szTitle,
	    sizeof (szTitle),
	    WINDOW_TITLE_XDMCP,
	    g_pszQueryHost); 
  else    
    snprintf (szTitle,
	    sizeof (szTitle),
	    WINDOW_TITLE,
	    display, 
	    (int) pScreenInfo->dwScreen);

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
312 313 314
  /* Create the window */
  *phwnd = CreateWindowExA (0,			/* Extended styles */
			    WINDOW_CLASS,	/* Class name */
315
			    szTitle,		/* Window name */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
			    dwWindowStyle,
			    rcWorkArea.left,	/* Horizontal position */
			    rcWorkArea.top,	/* Vertical position */
			    iWidth,		/* Right edge */
			    iHeight,		/* Bottom edge */
			    (HWND) NULL,	/* No parent or owner window */
			    (HMENU) NULL,	/* No menu */
			    GetModuleHandle (NULL),/* Instance handle */
			    pScreenPriv);	/* ScreenPrivates */
  if (*phwnd == NULL)
    {
      ErrorF ("winCreateBoundingWindowWindowed - CreateWindowEx () failed\n");
      return FALSE;
    }

#if CYGDEBUG
332
  winDebug ("winCreateBoundingWindowWindowed - CreateWindowEx () returned\n");
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
333 334 335 336 337 338 339 340 341 342
#endif

  /* Get the client area coordinates */
  if (!GetClientRect (*phwnd, &rcClient))
    {
      ErrorF ("winCreateBoundingWindowWindowed - GetClientRect () "
	      "failed\n");
      return FALSE;
    }

343
  winDebug ("winCreateBoundingWindowWindowed - WindowClient "
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
	  "w %ld h %ld r %ld l %ld b %ld t %ld\n",
	  rcClient.right - rcClient.left,
	  rcClient.bottom - rcClient.top,
	  rcClient.right, rcClient.left,
	  rcClient.bottom, rcClient.top);
  
  /* We adjust the visual size if the user did not specify it */
  if (!(pScreenInfo->fScrollbars && pScreenInfo->fUserGaveHeightAndWidth))
    {
      /*
       * User did not give a height and width with scrollbars enabled,
       * so we will resize the underlying visual to be as large as
       * the initial view port (page size).  This way scrollbars will
       * not appear until the user shrinks the window, if they ever do.
       *
       * NOTE: We have to store the viewport size here because
       * the user may have an autohide taskbar, which would
       * cause the viewport size to be one less in one dimension
       * than the viewport size that we calculated by subtracting
       * the size of the borders and caption.
       */
      pScreenInfo->dwWidth = rcClient.right - rcClient.left;
      pScreenInfo->dwHeight = rcClient.bottom - rcClient.top;
    }

#if 0
  /*
   * NOTE: For the uninitiated, the page size is the number of pixels
   * that we can display in the x or y direction at a time and the
   * range is the total number of pixels in the x or y direction that we
   * have available to display.  In other words, the page size is the
   * size of the window area minus the space the caption, borders, and
   * scrollbars (if any) occupy, and the range is the size of the
   * underlying X visual.  Notice that, contrary to what some of the
   * MSDN Library arcticles lead you to believe, the windows
   * ``client area'' size does not include the scrollbars.  In other words,
   * the whole client area size that is reported to you is drawable by
   * you; you do not have to subtract the size of the scrollbars from
   * the client area size, and if you did it would result in the size
   * of the scrollbars being double counted.
   */

  /* Setup scrollbar page and range, if scrollbars are enabled */
  if (pScreenInfo->fScrollbars)
    {
      SCROLLINFO		si;
      
      /* Initialize the scrollbar info structure */
      si.cbSize = sizeof (si);
      si.fMask = SIF_RANGE | SIF_PAGE;
      si.nMin = 0;
      
      /* Setup the width range and page size */
      si.nMax = pScreenInfo->dwWidth - 1;
      si.nPage = rcClient.right - rcClient.left;
399
      winDebug ("winCreateBoundingWindowWindowed - HORZ nMax: %d nPage :%d\n",
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
400 401 402 403 404 405
	      si.nMax, si.nPage);
      SetScrollInfo (*phwnd, SB_HORZ, &si, TRUE);
      
      /* Setup the height range and page size */
      si.nMax = pScreenInfo->dwHeight - 1;
      si.nPage = rcClient.bottom - rcClient.top;
406
      winDebug ("winCreateBoundingWindowWindowed - VERT nMax: %d nPage :%d\n",
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
407 408 409 410 411 412
	      si.nMax, si.nPage);
      SetScrollInfo (*phwnd, SB_VERT, &si, TRUE);
    }
#endif

  /* Show the window */
413 414 415 416 417 418 419 420
  if (FALSE
#ifdef XWIN_MULTIWINDOWEXTWM
      || pScreenInfo->fMWExtWM
#endif
#ifdef XWIN_MULTIWINDOW
      || pScreenInfo->fMultiWindow
#endif
      )
421
    {
422
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
423
      pScreenPriv->fRootWindowShown = FALSE;
424
#endif
425 426
      ShowWindow (*phwnd, SW_HIDE);
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
427 428 429 430 431 432 433 434 435
  else
    ShowWindow (*phwnd, SW_SHOWNORMAL);
  if (!UpdateWindow (*phwnd))
    {
      ErrorF ("winCreateBoundingWindowWindowed - UpdateWindow () failed\n");
      return FALSE;
    }
  
  /* Attempt to bring our window to the top of the display */
436 437 438 439 440 441 442 443 444
  if (TRUE
#ifdef XWIN_MULTIWINDOWEXTWM
      && !pScreenInfo->fMWExtWM
#endif
      && !pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
      && !pScreenInfo->fMultiWindow
#endif
      )
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
445
    {
446 447 448 449 450 451
      if (!BringWindowToTop (*phwnd))
	{
	  ErrorF ("winCreateBoundingWindowWindowed - BringWindowToTop () "
		  "failed\n");
	  return FALSE;
	}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
452 453
    }

454
#ifdef XWIN_NATIVEGDI
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
455 456 457
  /* Paint window background blue */
  if (pScreenInfo->dwEngine == WIN_SERVER_NATIVE_GDI)
    winPaintBackground (*phwnd, RGB (0x00, 0x00, 0xFF));
458
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
459

460
  winDebug ("winCreateBoundingWindowWindowed -  Returning\n");
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484

  return TRUE;
}


/*
 * Find the work area of all attached monitors
 */

static Bool
winGetWorkArea (RECT *prcWorkArea, winScreenInfo *pScreenInfo)
{
  int			iPrimaryWidth, iPrimaryHeight;
  int			iWidth, iHeight;
  int			iLeft, iTop;
  int			iPrimaryNonWorkAreaWidth, iPrimaryNonWorkAreaHeight;

  /* SPI_GETWORKAREA only gets the work area of the primary screen. */
  SystemParametersInfo (SPI_GETWORKAREA, 0, prcWorkArea, 0);

  /* Bail out here if we aren't using multiple monitors */
  if (!pScreenInfo->fMultipleMonitors)
    return TRUE;
  
485 486 487
  winDebug ("winGetWorkArea - Original WorkArea: %d %d %d %d\n",
	  (int) prcWorkArea->top, (int) prcWorkArea->left,
	  (int) prcWorkArea->bottom, (int) prcWorkArea->right);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
488 489 490 491 492

  /* Get size of full virtual screen */
  iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
  iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);

493
  winDebug ("winGetWorkArea - Virtual screen is %d x %d\n", iWidth, iHeight);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
494 495 496 497 498

  /* Get origin of full virtual screen */
  iLeft = GetSystemMetrics (SM_XVIRTUALSCREEN);
  iTop = GetSystemMetrics (SM_YVIRTUALSCREEN);

499
  winDebug ("winGetWorkArea - Virtual screen origin is %d, %d\n", iLeft, iTop);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
500 501 502 503 504
  
  /* Get size of primary screen */
  iPrimaryWidth = GetSystemMetrics (SM_CXSCREEN);
  iPrimaryHeight = GetSystemMetrics (SM_CYSCREEN);

505
  winDebug ("winGetWorkArea - Primary screen is %d x %d\n",
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
	 iPrimaryWidth, iPrimaryHeight);
  
  /* Work out how much of the primary screen we aren't using */
  iPrimaryNonWorkAreaWidth = iPrimaryWidth - (prcWorkArea->right -
					      prcWorkArea->left);
  iPrimaryNonWorkAreaHeight = iPrimaryHeight - (prcWorkArea->bottom
						- prcWorkArea->top);
  
  /* Update the rectangle to include all monitors */
  if (iLeft < 0) 
    {
      prcWorkArea->left = iLeft;
    }
  if (iTop < 0) 
    {
      prcWorkArea->top = iTop;
    }
  prcWorkArea->right = prcWorkArea->left + iWidth -
    iPrimaryNonWorkAreaWidth;
  prcWorkArea->bottom = prcWorkArea->top + iHeight -
    iPrimaryNonWorkAreaHeight;
  
528
  winDebug ("winGetWorkArea - Adjusted WorkArea for multiple "
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
529
	  "monitors: %d %d %d %d\n",
530 531
	  (int) prcWorkArea->top, (int) prcWorkArea->left,
	  (int) prcWorkArea->bottom, (int) prcWorkArea->right);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
  
  return TRUE;
}


/*
 * Adjust the client area so that any auto-hide toolbars
 * will work correctly.
 */

static Bool
winAdjustForAutoHide (RECT *prcWorkArea)
{
  APPBARDATA		abd;
  HWND			hwndAutoHide;

548 549 550
  winDebug ("winAdjustForAutoHide - Original WorkArea: %d %d %d %d\n",
	  (int) prcWorkArea->top, (int) prcWorkArea->left,
	  (int) prcWorkArea->bottom, (int) prcWorkArea->right);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
551 552 553 554 555

  /* Find out if the Windows taskbar is set to auto-hide */
  ZeroMemory (&abd, sizeof (abd));
  abd.cbSize = sizeof (abd);
  if (SHAppBarMessage (ABM_GETSTATE, &abd) & ABS_AUTOHIDE)
556
    winDebug ("winAdjustForAutoHide - Taskbar is auto hide\n");
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
557 558 559 560 561 562

  /* Look for a TOP auto-hide taskbar */
  abd.uEdge = ABE_TOP;
  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
  if (hwndAutoHide != NULL)
    {
563
      winDebug ("winAdjustForAutoHide - Found TOP auto-hide taskbar\n");
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
564 565 566 567 568 569 570 571
      prcWorkArea->top += 1;
    }

  /* Look for a LEFT auto-hide taskbar */
  abd.uEdge = ABE_LEFT;
  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
  if (hwndAutoHide != NULL)
    {
572
      winDebug ("winAdjustForAutoHide - Found LEFT auto-hide taskbar\n");
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
573 574 575 576 577 578 579 580
      prcWorkArea->left += 1;
    }

  /* Look for a BOTTOM auto-hide taskbar */
  abd.uEdge = ABE_BOTTOM;
  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
  if (hwndAutoHide != NULL)
    {
581
      winDebug ("winAdjustForAutoHide - Found BOTTOM auto-hide taskbar\n");
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
582 583 584 585 586 587 588 589
      prcWorkArea->bottom -= 1;
    }

  /* Look for a RIGHT auto-hide taskbar */
  abd.uEdge = ABE_RIGHT;
  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
  if (hwndAutoHide != NULL)
    {
590
      winDebug ("winAdjustForAutoHide - Found RIGHT auto-hide taskbar\n");
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
591 592 593
      prcWorkArea->right -= 1;
    }

594 595 596
  winDebug ("winAdjustForAutoHide - Adjusted WorkArea: %d %d %d %d\n",
	  (int) prcWorkArea->top, (int) prcWorkArea->left,
	  (int) prcWorkArea->bottom, (int) prcWorkArea->right);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
597 598 599 600 601
  
#if 0
  /* Obtain the task bar window dimensions */
  abd.hWnd = hwndAutoHide;
  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
602
  winDebug ("hwndAutoHide %08x abd.hWnd %08x %d %d %d %d\n",
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
603 604 605 606 607 608
	  hwndAutoHide, abd.hWnd,
	  abd.rc.top, abd.rc.left, abd.rc.bottom, abd.rc.right);
#endif

  return TRUE;
}