~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xwin/wincreatewnd.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved.
 
3
 *
 
4
 *Permission is hereby granted, free of charge, to any person obtaining
 
5
 * a copy of this software and associated documentation files (the
 
6
 *"Software"), to deal in the Software without restriction, including
 
7
 *without limitation the rights to use, copy, modify, merge, publish,
 
8
 *distribute, sublicense, and/or sell copies of the Software, and to
 
9
 *permit persons to whom the Software is furnished to do so, subject to
 
10
 *the following conditions:
 
11
 *
 
12
 *The above copyright notice and this permission notice shall be
 
13
 *included in all copies or substantial portions of the Software.
 
14
 *
 
15
 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
16
 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
17
 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
18
 *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
 
19
 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 
20
 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
21
 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 *
 
23
 *Except as contained in this notice, the name of Harold L Hunt II
 
24
 *shall not be used in advertising or otherwise to promote the sale, use
 
25
 *or other dealings in this Software without prior written authorization
 
26
 *from Harold L Hunt II.
 
27
 *
 
28
 * Authors:     Harold L Hunt II
 
29
 */
 
30
 
 
31
#ifdef HAVE_XWIN_CONFIG_H
 
32
#include <xwin-config.h>
 
33
#endif
 
34
#include "win.h"
 
35
#include "shellapi.h"
 
36
 
 
37
#ifndef ABS_AUTOHIDE
 
38
#define ABS_AUTOHIDE 1
 
39
#endif
 
40
 
 
41
/*
 
42
 * Local function prototypes
 
43
 */
 
44
 
 
45
static Bool
 
46
winGetWorkArea (RECT *prcWorkArea, winScreenInfo *pScreenInfo);
 
47
 
 
48
static Bool
 
49
winAdjustForAutoHide (RECT *prcWorkArea);
 
50
 
 
51
 
 
52
/*
 
53
 * Create a full screen window
 
54
 */
 
55
 
 
56
Bool
 
57
winCreateBoundingWindowFullScreen (ScreenPtr pScreen)
 
58
{
 
59
  winScreenPriv(pScreen);
 
60
  winScreenInfo         *pScreenInfo = pScreenPriv->pScreenInfo;
 
61
  int                   iWidth = pScreenInfo->dwWidth;
 
62
  int                   iHeight = pScreenInfo->dwHeight;
 
63
  HWND                  *phwnd = &pScreenPriv->hwndScreen;
 
64
  WNDCLASS              wc;
 
65
  char                  szTitle[256];
 
66
 
 
67
#if CYGDEBUG
 
68
  winDebug ("winCreateBoundingWindowFullScreen\n");
 
69
#endif
 
70
 
 
71
  /* Setup our window class */
 
72
  wc.style = CS_HREDRAW | CS_VREDRAW;
 
73
  wc.lpfnWndProc = winWindowProc;
 
74
  wc.cbClsExtra = 0;
 
75
  wc.cbWndExtra = 0;
 
76
  wc.hInstance = g_hInstance;
 
77
  wc.hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
 
78
  wc.hCursor = 0;
 
79
  wc.hbrBackground = 0;
 
80
  wc.lpszMenuName = NULL;
 
81
  wc.lpszClassName = WINDOW_CLASS;
 
82
  RegisterClass (&wc);
 
83
 
 
84
  /* Set display and screen-specific tooltip text */
 
85
  if (g_pszQueryHost != NULL)
 
86
    snprintf (szTitle,
 
87
            sizeof (szTitle),
 
88
            WINDOW_TITLE_XDMCP,
 
89
            g_pszQueryHost); 
 
90
  else    
 
91
    snprintf (szTitle,
 
92
            sizeof (szTitle),
 
93
            WINDOW_TITLE,
 
94
            display, 
 
95
            (int) pScreenInfo->dwScreen);
 
96
 
 
97
  /* Create the window */
 
98
  *phwnd = CreateWindowExA (0,                  /* Extended styles */
 
99
                            WINDOW_CLASS,       /* Class name */
 
100
                            szTitle,            /* Window name */
 
101
                            WS_POPUP,
 
102
                            0,                  /* Horizontal position */
 
103
                            0,                  /* Vertical position */
 
104
                            iWidth,             /* Right edge */ 
 
105
                            iHeight,            /* Bottom edge */
 
106
                            (HWND) NULL,        /* No parent or owner window */
 
107
                            (HMENU) NULL,       /* No menu */
 
108
                            GetModuleHandle (NULL),/* Instance handle */
 
109
                            pScreenPriv);       /* ScreenPrivates */
 
110
 
 
111
  /* Branch on the server engine */
 
112
  switch (pScreenInfo->dwEngine)
 
113
    {
 
114
#ifdef XWIN_NATIVEGDI
 
115
    case WIN_SERVER_SHADOW_GDI:
 
116
      /* Show the window */
 
117
      ShowWindow (*phwnd, SW_SHOWMAXIMIZED);
 
118
      break;
 
119
#endif
 
120
 
 
121
    default:
 
122
      /* Hide the window */
 
123
      ShowWindow (*phwnd, SW_SHOWNORMAL);
 
124
      break;
 
125
    }
 
126
 
 
127
  /* Send first paint message */
 
128
  UpdateWindow (*phwnd);
 
129
 
 
130
  /* Attempt to bring our window to the top of the display */
 
131
  BringWindowToTop (*phwnd);
 
132
 
 
133
  return TRUE;
 
134
}
 
135
 
 
136
 
 
137
/*
 
138
 * Create our primary Windows display window
 
139
 */
 
140
 
 
141
Bool
 
142
winCreateBoundingWindowWindowed (ScreenPtr pScreen)
 
143
{
 
144
  winScreenPriv(pScreen);
 
145
  winScreenInfo         *pScreenInfo = pScreenPriv->pScreenInfo;
 
146
  int                   iWidth = pScreenInfo->dwUserWidth;
 
147
  int                   iHeight = pScreenInfo->dwUserHeight;
 
148
  int                   iPosX;
 
149
  int                   iPosY;
 
150
  HWND                  *phwnd = &pScreenPriv->hwndScreen;
 
151
  WNDCLASS              wc;
 
152
  RECT                  rcClient, rcWorkArea;
 
153
  DWORD                 dwWindowStyle;
 
154
  BOOL                  fForceShowWindow = FALSE;
 
155
  char                  szTitle[256];
 
156
  
 
157
  winDebug ("winCreateBoundingWindowWindowed - User w: %d h: %d\n",
 
158
          (int) pScreenInfo->dwUserWidth, (int) pScreenInfo->dwUserHeight);
 
159
  winDebug ("winCreateBoundingWindowWindowed - Current w: %d h: %d\n",
 
160
          (int) pScreenInfo->dwWidth, (int) pScreenInfo->dwHeight);
 
161
 
 
162
  /* Set the common window style flags */
 
163
  dwWindowStyle = WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;
 
164
  
 
165
  /* Decorated or undecorated window */
 
166
  if (pScreenInfo->fDecoration
 
167
#ifdef XWIN_MULTIWINDOWEXTWM
 
168
      && !pScreenInfo->fMWExtWM
 
169
#endif
 
170
      && !pScreenInfo->fRootless
 
171
#ifdef XWIN_MULTIWINDOW
 
172
      && !pScreenInfo->fMultiWindow
 
173
#endif
 
174
      )
 
175
    {
 
176
        /* Try to handle startup via run.exe. run.exe instructs Windows to 
 
177
         * hide all created windows. Detect this case and make sure the 
 
178
         * window is shown nevertheless */
 
179
        STARTUPINFO   startupInfo;
 
180
        GetStartupInfo(&startupInfo);
 
181
        if (startupInfo.dwFlags & STARTF_USESHOWWINDOW && 
 
182
                startupInfo.wShowWindow == SW_HIDE)
 
183
        {
 
184
          fForceShowWindow = TRUE;
 
185
        } 
 
186
        dwWindowStyle |= WS_CAPTION;
 
187
        if (pScreenInfo->fScrollbars)
 
188
            dwWindowStyle |= WS_THICKFRAME | WS_MAXIMIZEBOX;
 
189
    }
 
190
  else
 
191
    dwWindowStyle |= WS_POPUP;
 
192
 
 
193
  /* Setup our window class */
 
194
  wc.style = CS_HREDRAW | CS_VREDRAW;
 
195
  wc.lpfnWndProc = winWindowProc;
 
196
  wc.cbClsExtra = 0;
 
197
  wc.cbWndExtra = 0;
 
198
  wc.hInstance = g_hInstance;
 
199
  wc.hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
 
200
  wc.hCursor = 0;
 
201
  wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
 
202
  wc.lpszMenuName = NULL;
 
203
  wc.lpszClassName = WINDOW_CLASS;
 
204
  RegisterClass (&wc);
 
205
 
 
206
  /* Get size of work area */
 
207
  winGetWorkArea (&rcWorkArea, pScreenInfo);
 
208
 
 
209
  /* Adjust for auto-hide taskbars */
 
210
  winAdjustForAutoHide (&rcWorkArea);
 
211
 
 
212
  /* Did the user specify a position? */
 
213
  if (pScreenInfo->fUserGavePosition)
 
214
    {
 
215
      iPosX = pScreenInfo->dwInitialX;
 
216
      iPosY = pScreenInfo->dwInitialY;
 
217
    }
 
218
  else
 
219
    {
 
220
      iPosX = rcWorkArea.left;
 
221
      iPosY = rcWorkArea.top;
 
222
    }
 
223
 
 
224
  /* Did the user specify a height and width? */
 
225
  if (pScreenInfo->fUserGaveHeightAndWidth)
 
226
    {
 
227
      /* User gave a desired height and width, try to accomodate */
 
228
#if CYGDEBUG
 
229
      winDebug ("winCreateBoundingWindowWindowed - User gave height "
 
230
              "and width\n");
 
231
#endif
 
232
      
 
233
      /* Adjust the window width and height for borders and title bar */
 
234
      if (pScreenInfo->fDecoration
 
235
#ifdef XWIN_MULTIWINDOWEXTWM
 
236
          && !pScreenInfo->fMWExtWM
 
237
#endif
 
238
          && !pScreenInfo->fRootless
 
239
#ifdef XWIN_MULTIWINDOW
 
240
          && !pScreenInfo->fMultiWindow
 
241
#endif
 
242
          )
 
243
        {
 
244
#if CYGDEBUG
 
245
          winDebug ("winCreateBoundingWindowWindowed - Window has decoration\n");
 
246
#endif
 
247
          /* Are we using scrollbars? */
 
248
          if (pScreenInfo->fScrollbars)
 
249
            {
 
250
#if CYGDEBUG
 
251
              winDebug ("winCreateBoundingWindowWindowed - Window has "
 
252
                      "scrollbars\n");
 
253
#endif
 
254
 
 
255
              iWidth += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
 
256
              iHeight += 2 * GetSystemMetrics (SM_CYSIZEFRAME) 
 
257
                + GetSystemMetrics (SM_CYCAPTION);
 
258
            }
 
259
          else
 
260
            {
 
261
#if CYGDEBUG
 
262
              winDebug ("winCreateBoundingWindowWindowed - Window does not have "
 
263
                      "scrollbars\n");
 
264
#endif
 
265
 
 
266
              iWidth += 2 * GetSystemMetrics (SM_CXFIXEDFRAME);
 
267
              iHeight += 2 * GetSystemMetrics (SM_CYFIXEDFRAME) 
 
268
                + GetSystemMetrics (SM_CYCAPTION);
 
269
            }
 
270
        }
 
271
    }
 
272
  else
 
273
    {
 
274
      /* By default, we are creating a window that is as large as possible */
 
275
#if CYGDEBUG
 
276
      winDebug ("winCreateBoundingWindowWindowed - User did not give "
 
277
              "height and width\n");
 
278
#endif
 
279
      /* Defaults are wrong if we have multiple monitors */
 
280
      if (pScreenInfo->fMultipleMonitors)
 
281
        {
 
282
          iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
 
283
          iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
 
284
        }
 
285
    }
 
286
 
 
287
  /* Clean up the scrollbars flag, if necessary */
 
288
  if ((!pScreenInfo->fDecoration
 
289
#ifdef XWIN_MULTIWINDOWEXTWM
 
290
       || pScreenInfo->fMWExtWM
 
291
#endif
 
292
       || pScreenInfo->fRootless
 
293
#ifdef XWIN_MULTIWINDOW
 
294
       || pScreenInfo->fMultiWindow
 
295
#endif
 
296
       )
 
297
      && pScreenInfo->fScrollbars)
 
298
    {
 
299
      /* We cannot have scrollbars if we do not have a window border */
 
300
      pScreenInfo->fScrollbars = FALSE;
 
301
    }
 
302
 
 
303
  if (TRUE 
 
304
#ifdef XWIN_MULTIWINDOWEXTWM
 
305
       && !pScreenInfo->fMWExtWM
 
306
#endif
 
307
#ifdef XWIN_MULTIWINDOW
 
308
       && !pScreenInfo->fMultiWindow
 
309
#endif
 
310
     )
 
311
    {
 
312
      /* Trim window width to fit work area */
 
313
      if (iWidth > (rcWorkArea.right - rcWorkArea.left))
 
314
        iWidth = rcWorkArea.right - rcWorkArea.left;
 
315
  
 
316
      /* Trim window height to fit work area */
 
317
      if (iHeight >= (rcWorkArea.bottom - rcWorkArea.top))
 
318
        iHeight = rcWorkArea.bottom - rcWorkArea.top;
 
319
  
 
320
#if CYGDEBUG
 
321
      winDebug ("winCreateBoundingWindowWindowed - Adjusted width: %d "\
 
322
              "height: %d\n",
 
323
          iWidth, iHeight);
 
324
#endif
 
325
    }
 
326
 
 
327
  /* Set display and screen-specific tooltip text */
 
328
  if (g_pszQueryHost != NULL)
 
329
    snprintf (szTitle,
 
330
            sizeof (szTitle),
 
331
            WINDOW_TITLE_XDMCP,
 
332
            g_pszQueryHost); 
 
333
  else    
 
334
    snprintf (szTitle,
 
335
            sizeof (szTitle),
 
336
            WINDOW_TITLE,
 
337
            display, 
 
338
            (int) pScreenInfo->dwScreen);
 
339
 
 
340
  /* Create the window */
 
341
  *phwnd = CreateWindowExA (0,                  /* Extended styles */
 
342
                            WINDOW_CLASS,       /* Class name */
 
343
                            szTitle,            /* Window name */
 
344
                            dwWindowStyle,
 
345
                            iPosX,              /* Horizontal position */
 
346
                            iPosY,              /* Vertical position */
 
347
                            iWidth,             /* Right edge */
 
348
                            iHeight,            /* Bottom edge */
 
349
                            (HWND) NULL,        /* No parent or owner window */
 
350
                            (HMENU) NULL,       /* No menu */
 
351
                            GetModuleHandle (NULL),/* Instance handle */
 
352
                            pScreenPriv);       /* ScreenPrivates */
 
353
  if (*phwnd == NULL)
 
354
    {
 
355
      ErrorF ("winCreateBoundingWindowWindowed - CreateWindowEx () failed\n");
 
356
      return FALSE;
 
357
    }
 
358
 
 
359
#if CYGDEBUG
 
360
  winDebug ("winCreateBoundingWindowWindowed - CreateWindowEx () returned\n");
 
361
#endif
 
362
 
 
363
  if (fForceShowWindow)
 
364
  {
 
365
      ErrorF("winCreateBoundingWindowWindowed - Setting normal windowstyle\n");
 
366
      ShowWindow(*phwnd, SW_SHOW);      
 
367
  }
 
368
 
 
369
  /* Get the client area coordinates */
 
370
  if (!GetClientRect (*phwnd, &rcClient))
 
371
    {
 
372
      ErrorF ("winCreateBoundingWindowWindowed - GetClientRect () "
 
373
              "failed\n");
 
374
      return FALSE;
 
375
    }
 
376
 
 
377
  winDebug ("winCreateBoundingWindowWindowed - WindowClient "
 
378
          "w %ld h %ld r %ld l %ld b %ld t %ld\n",
 
379
          rcClient.right - rcClient.left,
 
380
          rcClient.bottom - rcClient.top,
 
381
          rcClient.right, rcClient.left,
 
382
          rcClient.bottom, rcClient.top);
 
383
  
 
384
  /* We adjust the visual size if the user did not specify it */
 
385
  if (!(pScreenInfo->fScrollbars && pScreenInfo->fUserGaveHeightAndWidth))
 
386
    {
 
387
      /*
 
388
       * User did not give a height and width with scrollbars enabled,
 
389
       * so we will resize the underlying visual to be as large as
 
390
       * the initial view port (page size).  This way scrollbars will
 
391
       * not appear until the user shrinks the window, if they ever do.
 
392
       *
 
393
       * NOTE: We have to store the viewport size here because
 
394
       * the user may have an autohide taskbar, which would
 
395
       * cause the viewport size to be one less in one dimension
 
396
       * than the viewport size that we calculated by subtracting
 
397
       * the size of the borders and caption.
 
398
       */
 
399
      pScreenInfo->dwWidth = rcClient.right - rcClient.left;
 
400
      pScreenInfo->dwHeight = rcClient.bottom - rcClient.top;
 
401
    }
 
402
 
 
403
#if 0
 
404
  /*
 
405
   * NOTE: For the uninitiated, the page size is the number of pixels
 
406
   * that we can display in the x or y direction at a time and the
 
407
   * range is the total number of pixels in the x or y direction that we
 
408
   * have available to display.  In other words, the page size is the
 
409
   * size of the window area minus the space the caption, borders, and
 
410
   * scrollbars (if any) occupy, and the range is the size of the
 
411
   * underlying X visual.  Notice that, contrary to what some of the
 
412
   * MSDN Library arcticles lead you to believe, the windows
 
413
   * ``client area'' size does not include the scrollbars.  In other words,
 
414
   * the whole client area size that is reported to you is drawable by
 
415
   * you; you do not have to subtract the size of the scrollbars from
 
416
   * the client area size, and if you did it would result in the size
 
417
   * of the scrollbars being double counted.
 
418
   */
 
419
 
 
420
  /* Setup scrollbar page and range, if scrollbars are enabled */
 
421
  if (pScreenInfo->fScrollbars)
 
422
    {
 
423
      SCROLLINFO                si;
 
424
      
 
425
      /* Initialize the scrollbar info structure */
 
426
      si.cbSize = sizeof (si);
 
427
      si.fMask = SIF_RANGE | SIF_PAGE;
 
428
      si.nMin = 0;
 
429
      
 
430
      /* Setup the width range and page size */
 
431
      si.nMax = pScreenInfo->dwWidth - 1;
 
432
      si.nPage = rcClient.right - rcClient.left;
 
433
      winDebug ("winCreateBoundingWindowWindowed - HORZ nMax: %d nPage :%d\n",
 
434
              si.nMax, si.nPage);
 
435
      SetScrollInfo (*phwnd, SB_HORZ, &si, TRUE);
 
436
      
 
437
      /* Setup the height range and page size */
 
438
      si.nMax = pScreenInfo->dwHeight - 1;
 
439
      si.nPage = rcClient.bottom - rcClient.top;
 
440
      winDebug ("winCreateBoundingWindowWindowed - VERT nMax: %d nPage :%d\n",
 
441
              si.nMax, si.nPage);
 
442
      SetScrollInfo (*phwnd, SB_VERT, &si, TRUE);
 
443
    }
 
444
#endif
 
445
 
 
446
  /* Show the window */
 
447
  if (FALSE
 
448
#ifdef XWIN_MULTIWINDOWEXTWM
 
449
      || pScreenInfo->fMWExtWM
 
450
#endif
 
451
#ifdef XWIN_MULTIWINDOW
 
452
      || pScreenInfo->fMultiWindow
 
453
#endif
 
454
      )
 
455
    {
 
456
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
 
457
      pScreenPriv->fRootWindowShown = FALSE;
 
458
#endif
 
459
      ShowWindow (*phwnd, SW_HIDE);
 
460
    }
 
461
  else
 
462
    ShowWindow (*phwnd, SW_SHOWNORMAL);
 
463
  if (!UpdateWindow (*phwnd))
 
464
    {
 
465
      ErrorF ("winCreateBoundingWindowWindowed - UpdateWindow () failed\n");
 
466
      return FALSE;
 
467
    }
 
468
  
 
469
  /* Attempt to bring our window to the top of the display */
 
470
  if (TRUE
 
471
#ifdef XWIN_MULTIWINDOWEXTWM
 
472
      && !pScreenInfo->fMWExtWM
 
473
#endif
 
474
      && !pScreenInfo->fRootless
 
475
#ifdef XWIN_MULTIWINDOW
 
476
      && !pScreenInfo->fMultiWindow
 
477
#endif
 
478
      )
 
479
    {
 
480
      if (!BringWindowToTop (*phwnd))
 
481
        {
 
482
          ErrorF ("winCreateBoundingWindowWindowed - BringWindowToTop () "
 
483
                  "failed\n");
 
484
          return FALSE;
 
485
        }
 
486
    }
 
487
 
 
488
#ifdef XWIN_NATIVEGDI
 
489
  /* Paint window background blue */
 
490
  if (pScreenInfo->dwEngine == WIN_SERVER_NATIVE_GDI)
 
491
    winPaintBackground (*phwnd, RGB (0x00, 0x00, 0xFF));
 
492
#endif
 
493
 
 
494
  winDebug ("winCreateBoundingWindowWindowed -  Returning\n");
 
495
 
 
496
  return TRUE;
 
497
}
 
498
 
 
499
 
 
500
/*
 
501
 * Find the work area of all attached monitors
 
502
 */
 
503
 
 
504
static Bool
 
505
winGetWorkArea (RECT *prcWorkArea, winScreenInfo *pScreenInfo)
 
506
{
 
507
  int                   iPrimaryWidth, iPrimaryHeight;
 
508
  int                   iWidth, iHeight;
 
509
  int                   iLeft, iTop;
 
510
  int                   iPrimaryNonWorkAreaWidth, iPrimaryNonWorkAreaHeight;
 
511
 
 
512
  /* SPI_GETWORKAREA only gets the work area of the primary screen. */
 
513
  SystemParametersInfo (SPI_GETWORKAREA, 0, prcWorkArea, 0);
 
514
 
 
515
  /* Bail out here if we aren't using multiple monitors */
 
516
  if (!pScreenInfo->fMultipleMonitors)
 
517
    return TRUE;
 
518
  
 
519
  winDebug ("winGetWorkArea - Original WorkArea: %d %d %d %d\n",
 
520
          (int) prcWorkArea->top, (int) prcWorkArea->left,
 
521
          (int) prcWorkArea->bottom, (int) prcWorkArea->right);
 
522
 
 
523
  /* Get size of full virtual screen */
 
524
  iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
 
525
  iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
 
526
 
 
527
  winDebug ("winGetWorkArea - Virtual screen is %d x %d\n", iWidth, iHeight);
 
528
 
 
529
  /* Get origin of full virtual screen */
 
530
  iLeft = GetSystemMetrics (SM_XVIRTUALSCREEN);
 
531
  iTop = GetSystemMetrics (SM_YVIRTUALSCREEN);
 
532
 
 
533
  winDebug ("winGetWorkArea - Virtual screen origin is %d, %d\n", iLeft, iTop);
 
534
  
 
535
  /* Get size of primary screen */
 
536
  iPrimaryWidth = GetSystemMetrics (SM_CXSCREEN);
 
537
  iPrimaryHeight = GetSystemMetrics (SM_CYSCREEN);
 
538
 
 
539
  winDebug ("winGetWorkArea - Primary screen is %d x %d\n",
 
540
         iPrimaryWidth, iPrimaryHeight);
 
541
  
 
542
  /* Work out how much of the primary screen we aren't using */
 
543
  iPrimaryNonWorkAreaWidth = iPrimaryWidth - (prcWorkArea->right -
 
544
                                              prcWorkArea->left);
 
545
  iPrimaryNonWorkAreaHeight = iPrimaryHeight - (prcWorkArea->bottom
 
546
                                                - prcWorkArea->top);
 
547
  
 
548
  /* Update the rectangle to include all monitors */
 
549
  if (iLeft < 0) 
 
550
    {
 
551
      prcWorkArea->left = iLeft;
 
552
    }
 
553
  if (iTop < 0) 
 
554
    {
 
555
      prcWorkArea->top = iTop;
 
556
    }
 
557
  prcWorkArea->right = prcWorkArea->left + iWidth -
 
558
    iPrimaryNonWorkAreaWidth;
 
559
  prcWorkArea->bottom = prcWorkArea->top + iHeight -
 
560
    iPrimaryNonWorkAreaHeight;
 
561
  
 
562
  winDebug ("winGetWorkArea - Adjusted WorkArea for multiple "
 
563
          "monitors: %d %d %d %d\n",
 
564
          (int) prcWorkArea->top, (int) prcWorkArea->left,
 
565
          (int) prcWorkArea->bottom, (int) prcWorkArea->right);
 
566
  
 
567
  return TRUE;
 
568
}
 
569
 
 
570
 
 
571
/*
 
572
 * Adjust the client area so that any auto-hide toolbars
 
573
 * will work correctly.
 
574
 */
 
575
 
 
576
static Bool
 
577
winAdjustForAutoHide (RECT *prcWorkArea)
 
578
{
 
579
  APPBARDATA            abd;
 
580
  HWND                  hwndAutoHide;
 
581
 
 
582
  winDebug ("winAdjustForAutoHide - Original WorkArea: %d %d %d %d\n",
 
583
          (int) prcWorkArea->top, (int) prcWorkArea->left,
 
584
          (int) prcWorkArea->bottom, (int) prcWorkArea->right);
 
585
 
 
586
  /* Find out if the Windows taskbar is set to auto-hide */
 
587
  ZeroMemory (&abd, sizeof (abd));
 
588
  abd.cbSize = sizeof (abd);
 
589
  if (SHAppBarMessage (ABM_GETSTATE, &abd) & ABS_AUTOHIDE)
 
590
    winDebug ("winAdjustForAutoHide - Taskbar is auto hide\n");
 
591
 
 
592
  /* Look for a TOP auto-hide taskbar */
 
593
  abd.uEdge = ABE_TOP;
 
594
  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
 
595
  if (hwndAutoHide != NULL)
 
596
    {
 
597
      winDebug ("winAdjustForAutoHide - Found TOP auto-hide taskbar\n");
 
598
      prcWorkArea->top += 1;
 
599
    }
 
600
 
 
601
  /* Look for a LEFT auto-hide taskbar */
 
602
  abd.uEdge = ABE_LEFT;
 
603
  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
 
604
  if (hwndAutoHide != NULL)
 
605
    {
 
606
      winDebug ("winAdjustForAutoHide - Found LEFT auto-hide taskbar\n");
 
607
      prcWorkArea->left += 1;
 
608
    }
 
609
 
 
610
  /* Look for a BOTTOM auto-hide taskbar */
 
611
  abd.uEdge = ABE_BOTTOM;
 
612
  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
 
613
  if (hwndAutoHide != NULL)
 
614
    {
 
615
      winDebug ("winAdjustForAutoHide - Found BOTTOM auto-hide taskbar\n");
 
616
      prcWorkArea->bottom -= 1;
 
617
    }
 
618
 
 
619
  /* Look for a RIGHT auto-hide taskbar */
 
620
  abd.uEdge = ABE_RIGHT;
 
621
  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
 
622
  if (hwndAutoHide != NULL)
 
623
    {
 
624
      winDebug ("winAdjustForAutoHide - Found RIGHT auto-hide taskbar\n");
 
625
      prcWorkArea->right -= 1;
 
626
    }
 
627
 
 
628
  winDebug ("winAdjustForAutoHide - Adjusted WorkArea: %d %d %d %d\n",
 
629
          (int) prcWorkArea->top, (int) prcWorkArea->left,
 
630
          (int) prcWorkArea->bottom, (int) prcWorkArea->right);
 
631
  
 
632
#if 0
 
633
  /* Obtain the task bar window dimensions */
 
634
  abd.hWnd = hwndAutoHide;
 
635
  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
 
636
  winDebug ("hwndAutoHide %08x abd.hWnd %08x %d %d %d %d\n",
 
637
          hwndAutoHide, abd.hWnd,
 
638
          abd.rc.top, abd.rc.left, abd.rc.bottom, abd.rc.right);
 
639
#endif
 
640
 
 
641
  return TRUE;
 
642
}