2
*Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved.
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:
12
*The above copyright notice and this permission notice shall be
13
*included in all copies or substantial portions of the Software.
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.
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.
28
* Authors: Harold L Hunt II
31
#ifdef HAVE_XWIN_CONFIG_H
32
#include <xwin-config.h>
38
#define ABS_AUTOHIDE 1
42
* Local function prototypes
46
winGetWorkArea (RECT *prcWorkArea, winScreenInfo *pScreenInfo);
49
winAdjustForAutoHide (RECT *prcWorkArea);
53
* Create a full screen window
57
winCreateBoundingWindowFullScreen (ScreenPtr pScreen)
59
winScreenPriv(pScreen);
60
winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
61
int iWidth = pScreenInfo->dwWidth;
62
int iHeight = pScreenInfo->dwHeight;
63
HWND *phwnd = &pScreenPriv->hwndScreen;
68
winDebug ("winCreateBoundingWindowFullScreen\n");
71
/* Setup our window class */
72
wc.style = CS_HREDRAW | CS_VREDRAW;
73
wc.lpfnWndProc = winWindowProc;
76
wc.hInstance = g_hInstance;
77
wc.hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
80
wc.lpszMenuName = NULL;
81
wc.lpszClassName = WINDOW_CLASS;
84
/* Set display and screen-specific tooltip text */
85
if (g_pszQueryHost != NULL)
95
(int) pScreenInfo->dwScreen);
97
/* Create the window */
98
*phwnd = CreateWindowExA (0, /* Extended styles */
99
WINDOW_CLASS, /* Class name */
100
szTitle, /* Window name */
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 */
111
/* Branch on the server engine */
112
switch (pScreenInfo->dwEngine)
114
#ifdef XWIN_NATIVEGDI
115
case WIN_SERVER_SHADOW_GDI:
116
/* Show the window */
117
ShowWindow (*phwnd, SW_SHOWMAXIMIZED);
122
/* Hide the window */
123
ShowWindow (*phwnd, SW_SHOWNORMAL);
127
/* Send first paint message */
128
UpdateWindow (*phwnd);
130
/* Attempt to bring our window to the top of the display */
131
BringWindowToTop (*phwnd);
138
* Create our primary Windows display window
142
winCreateBoundingWindowWindowed (ScreenPtr pScreen)
144
winScreenPriv(pScreen);
145
winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
146
int iWidth = pScreenInfo->dwUserWidth;
147
int iHeight = pScreenInfo->dwUserHeight;
150
HWND *phwnd = &pScreenPriv->hwndScreen;
152
RECT rcClient, rcWorkArea;
154
BOOL fForceShowWindow = FALSE;
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);
162
/* Set the common window style flags */
163
dwWindowStyle = WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;
165
/* Decorated or undecorated window */
166
if (pScreenInfo->fDecoration
167
#ifdef XWIN_MULTIWINDOWEXTWM
168
&& !pScreenInfo->fMWExtWM
170
&& !pScreenInfo->fRootless
171
#ifdef XWIN_MULTIWINDOW
172
&& !pScreenInfo->fMultiWindow
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)
184
fForceShowWindow = TRUE;
186
dwWindowStyle |= WS_CAPTION;
187
if (pScreenInfo->fScrollbars)
188
dwWindowStyle |= WS_THICKFRAME | WS_MAXIMIZEBOX;
191
dwWindowStyle |= WS_POPUP;
193
/* Setup our window class */
194
wc.style = CS_HREDRAW | CS_VREDRAW;
195
wc.lpfnWndProc = winWindowProc;
198
wc.hInstance = g_hInstance;
199
wc.hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
201
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
202
wc.lpszMenuName = NULL;
203
wc.lpszClassName = WINDOW_CLASS;
206
/* Get size of work area */
207
winGetWorkArea (&rcWorkArea, pScreenInfo);
209
/* Adjust for auto-hide taskbars */
210
winAdjustForAutoHide (&rcWorkArea);
212
/* Did the user specify a position? */
213
if (pScreenInfo->fUserGavePosition)
215
iPosX = pScreenInfo->dwInitialX;
216
iPosY = pScreenInfo->dwInitialY;
220
iPosX = rcWorkArea.left;
221
iPosY = rcWorkArea.top;
224
/* Did the user specify a height and width? */
225
if (pScreenInfo->fUserGaveHeightAndWidth)
227
/* User gave a desired height and width, try to accomodate */
229
winDebug ("winCreateBoundingWindowWindowed - User gave height "
233
/* Adjust the window width and height for borders and title bar */
234
if (pScreenInfo->fDecoration
235
#ifdef XWIN_MULTIWINDOWEXTWM
236
&& !pScreenInfo->fMWExtWM
238
&& !pScreenInfo->fRootless
239
#ifdef XWIN_MULTIWINDOW
240
&& !pScreenInfo->fMultiWindow
245
winDebug ("winCreateBoundingWindowWindowed - Window has decoration\n");
247
/* Are we using scrollbars? */
248
if (pScreenInfo->fScrollbars)
251
winDebug ("winCreateBoundingWindowWindowed - Window has "
255
iWidth += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
256
iHeight += 2 * GetSystemMetrics (SM_CYSIZEFRAME)
257
+ GetSystemMetrics (SM_CYCAPTION);
262
winDebug ("winCreateBoundingWindowWindowed - Window does not have "
266
iWidth += 2 * GetSystemMetrics (SM_CXFIXEDFRAME);
267
iHeight += 2 * GetSystemMetrics (SM_CYFIXEDFRAME)
268
+ GetSystemMetrics (SM_CYCAPTION);
274
/* By default, we are creating a window that is as large as possible */
276
winDebug ("winCreateBoundingWindowWindowed - User did not give "
277
"height and width\n");
279
/* Defaults are wrong if we have multiple monitors */
280
if (pScreenInfo->fMultipleMonitors)
282
iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
283
iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
287
/* Clean up the scrollbars flag, if necessary */
288
if ((!pScreenInfo->fDecoration
289
#ifdef XWIN_MULTIWINDOWEXTWM
290
|| pScreenInfo->fMWExtWM
292
|| pScreenInfo->fRootless
293
#ifdef XWIN_MULTIWINDOW
294
|| pScreenInfo->fMultiWindow
297
&& pScreenInfo->fScrollbars)
299
/* We cannot have scrollbars if we do not have a window border */
300
pScreenInfo->fScrollbars = FALSE;
304
#ifdef XWIN_MULTIWINDOWEXTWM
305
&& !pScreenInfo->fMWExtWM
307
#ifdef XWIN_MULTIWINDOW
308
&& !pScreenInfo->fMultiWindow
312
/* Trim window width to fit work area */
313
if (iWidth > (rcWorkArea.right - rcWorkArea.left))
314
iWidth = rcWorkArea.right - rcWorkArea.left;
316
/* Trim window height to fit work area */
317
if (iHeight >= (rcWorkArea.bottom - rcWorkArea.top))
318
iHeight = rcWorkArea.bottom - rcWorkArea.top;
321
winDebug ("winCreateBoundingWindowWindowed - Adjusted width: %d "\
327
/* Set display and screen-specific tooltip text */
328
if (g_pszQueryHost != NULL)
338
(int) pScreenInfo->dwScreen);
340
/* Create the window */
341
*phwnd = CreateWindowExA (0, /* Extended styles */
342
WINDOW_CLASS, /* Class name */
343
szTitle, /* Window name */
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 */
355
ErrorF ("winCreateBoundingWindowWindowed - CreateWindowEx () failed\n");
360
winDebug ("winCreateBoundingWindowWindowed - CreateWindowEx () returned\n");
363
if (fForceShowWindow)
365
ErrorF("winCreateBoundingWindowWindowed - Setting normal windowstyle\n");
366
ShowWindow(*phwnd, SW_SHOW);
369
/* Get the client area coordinates */
370
if (!GetClientRect (*phwnd, &rcClient))
372
ErrorF ("winCreateBoundingWindowWindowed - GetClientRect () "
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);
384
/* We adjust the visual size if the user did not specify it */
385
if (!(pScreenInfo->fScrollbars && pScreenInfo->fUserGaveHeightAndWidth))
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.
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.
399
pScreenInfo->dwWidth = rcClient.right - rcClient.left;
400
pScreenInfo->dwHeight = rcClient.bottom - rcClient.top;
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.
420
/* Setup scrollbar page and range, if scrollbars are enabled */
421
if (pScreenInfo->fScrollbars)
425
/* Initialize the scrollbar info structure */
426
si.cbSize = sizeof (si);
427
si.fMask = SIF_RANGE | SIF_PAGE;
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",
435
SetScrollInfo (*phwnd, SB_HORZ, &si, TRUE);
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",
442
SetScrollInfo (*phwnd, SB_VERT, &si, TRUE);
446
/* Show the window */
448
#ifdef XWIN_MULTIWINDOWEXTWM
449
|| pScreenInfo->fMWExtWM
451
#ifdef XWIN_MULTIWINDOW
452
|| pScreenInfo->fMultiWindow
456
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
457
pScreenPriv->fRootWindowShown = FALSE;
459
ShowWindow (*phwnd, SW_HIDE);
462
ShowWindow (*phwnd, SW_SHOWNORMAL);
463
if (!UpdateWindow (*phwnd))
465
ErrorF ("winCreateBoundingWindowWindowed - UpdateWindow () failed\n");
469
/* Attempt to bring our window to the top of the display */
471
#ifdef XWIN_MULTIWINDOWEXTWM
472
&& !pScreenInfo->fMWExtWM
474
&& !pScreenInfo->fRootless
475
#ifdef XWIN_MULTIWINDOW
476
&& !pScreenInfo->fMultiWindow
480
if (!BringWindowToTop (*phwnd))
482
ErrorF ("winCreateBoundingWindowWindowed - BringWindowToTop () "
488
#ifdef XWIN_NATIVEGDI
489
/* Paint window background blue */
490
if (pScreenInfo->dwEngine == WIN_SERVER_NATIVE_GDI)
491
winPaintBackground (*phwnd, RGB (0x00, 0x00, 0xFF));
494
winDebug ("winCreateBoundingWindowWindowed - Returning\n");
501
* Find the work area of all attached monitors
505
winGetWorkArea (RECT *prcWorkArea, winScreenInfo *pScreenInfo)
507
int iPrimaryWidth, iPrimaryHeight;
510
int iPrimaryNonWorkAreaWidth, iPrimaryNonWorkAreaHeight;
512
/* SPI_GETWORKAREA only gets the work area of the primary screen. */
513
SystemParametersInfo (SPI_GETWORKAREA, 0, prcWorkArea, 0);
515
/* Bail out here if we aren't using multiple monitors */
516
if (!pScreenInfo->fMultipleMonitors)
519
winDebug ("winGetWorkArea - Original WorkArea: %d %d %d %d\n",
520
(int) prcWorkArea->top, (int) prcWorkArea->left,
521
(int) prcWorkArea->bottom, (int) prcWorkArea->right);
523
/* Get size of full virtual screen */
524
iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
525
iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
527
winDebug ("winGetWorkArea - Virtual screen is %d x %d\n", iWidth, iHeight);
529
/* Get origin of full virtual screen */
530
iLeft = GetSystemMetrics (SM_XVIRTUALSCREEN);
531
iTop = GetSystemMetrics (SM_YVIRTUALSCREEN);
533
winDebug ("winGetWorkArea - Virtual screen origin is %d, %d\n", iLeft, iTop);
535
/* Get size of primary screen */
536
iPrimaryWidth = GetSystemMetrics (SM_CXSCREEN);
537
iPrimaryHeight = GetSystemMetrics (SM_CYSCREEN);
539
winDebug ("winGetWorkArea - Primary screen is %d x %d\n",
540
iPrimaryWidth, iPrimaryHeight);
542
/* Work out how much of the primary screen we aren't using */
543
iPrimaryNonWorkAreaWidth = iPrimaryWidth - (prcWorkArea->right -
545
iPrimaryNonWorkAreaHeight = iPrimaryHeight - (prcWorkArea->bottom
548
/* Update the rectangle to include all monitors */
551
prcWorkArea->left = iLeft;
555
prcWorkArea->top = iTop;
557
prcWorkArea->right = prcWorkArea->left + iWidth -
558
iPrimaryNonWorkAreaWidth;
559
prcWorkArea->bottom = prcWorkArea->top + iHeight -
560
iPrimaryNonWorkAreaHeight;
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);
572
* Adjust the client area so that any auto-hide toolbars
573
* will work correctly.
577
winAdjustForAutoHide (RECT *prcWorkArea)
582
winDebug ("winAdjustForAutoHide - Original WorkArea: %d %d %d %d\n",
583
(int) prcWorkArea->top, (int) prcWorkArea->left,
584
(int) prcWorkArea->bottom, (int) prcWorkArea->right);
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");
592
/* Look for a TOP auto-hide taskbar */
594
hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
595
if (hwndAutoHide != NULL)
597
winDebug ("winAdjustForAutoHide - Found TOP auto-hide taskbar\n");
598
prcWorkArea->top += 1;
601
/* Look for a LEFT auto-hide taskbar */
602
abd.uEdge = ABE_LEFT;
603
hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
604
if (hwndAutoHide != NULL)
606
winDebug ("winAdjustForAutoHide - Found LEFT auto-hide taskbar\n");
607
prcWorkArea->left += 1;
610
/* Look for a BOTTOM auto-hide taskbar */
611
abd.uEdge = ABE_BOTTOM;
612
hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
613
if (hwndAutoHide != NULL)
615
winDebug ("winAdjustForAutoHide - Found BOTTOM auto-hide taskbar\n");
616
prcWorkArea->bottom -= 1;
619
/* Look for a RIGHT auto-hide taskbar */
620
abd.uEdge = ABE_RIGHT;
621
hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
622
if (hwndAutoHide != NULL)
624
winDebug ("winAdjustForAutoHide - Found RIGHT auto-hide taskbar\n");
625
prcWorkArea->right -= 1;
628
winDebug ("winAdjustForAutoHide - Adjusted WorkArea: %d %d %d %d\n",
629
(int) prcWorkArea->top, (int) prcWorkArea->left,
630
(int) prcWorkArea->bottom, (int) prcWorkArea->right);
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);