1706f2543Smrg/*
2706f2543Smrg *Copyright (C) 2001-2004 Harold L Hunt II All Rights Reserved.
3706f2543Smrg *
4706f2543Smrg *Permission is hereby granted, free of charge, to any person obtaining
5706f2543Smrg * a copy of this software and associated documentation files (the
6706f2543Smrg *"Software"), to deal in the Software without restriction, including
7706f2543Smrg *without limitation the rights to use, copy, modify, merge, publish,
8706f2543Smrg *distribute, sublicense, and/or sell copies of the Software, and to
9706f2543Smrg *permit persons to whom the Software is furnished to do so, subject to
10706f2543Smrg *the following conditions:
11706f2543Smrg *
12706f2543Smrg *The above copyright notice and this permission notice shall be
13706f2543Smrg *included in all copies or substantial portions of the Software.
14706f2543Smrg *
15706f2543Smrg *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16706f2543Smrg *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17706f2543Smrg *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18706f2543Smrg *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
19706f2543Smrg *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20706f2543Smrg *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21706f2543Smrg *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22706f2543Smrg *
23706f2543Smrg *Except as contained in this notice, the name of Harold L Hunt II
24706f2543Smrg *shall not be used in advertising or otherwise to promote the sale, use
25706f2543Smrg *or other dealings in this Software without prior written authorization
26706f2543Smrg *from Harold L Hunt II.
27706f2543Smrg *
28706f2543Smrg * Authors:	Harold L Hunt II
29706f2543Smrg */
30706f2543Smrg
31706f2543Smrg#ifdef HAVE_XWIN_CONFIG_H
32706f2543Smrg#include <xwin-config.h>
33706f2543Smrg#endif
34706f2543Smrg#include "win.h"
35706f2543Smrg#include "shellapi.h"
36706f2543Smrg
37706f2543Smrg#ifndef ABS_AUTOHIDE
38706f2543Smrg#define ABS_AUTOHIDE 1
39706f2543Smrg#endif
40706f2543Smrg
41706f2543Smrg/*
42706f2543Smrg * Local function prototypes
43706f2543Smrg */
44706f2543Smrg
45706f2543Smrgstatic Bool
46706f2543SmrgwinGetWorkArea (RECT *prcWorkArea, winScreenInfo *pScreenInfo);
47706f2543Smrg
48706f2543Smrgstatic Bool
49706f2543SmrgwinAdjustForAutoHide (RECT *prcWorkArea);
50706f2543Smrg
51706f2543Smrg
52706f2543Smrg/*
53706f2543Smrg * Create a full screen window
54706f2543Smrg */
55706f2543Smrg
56706f2543SmrgBool
57706f2543SmrgwinCreateBoundingWindowFullScreen (ScreenPtr pScreen)
58706f2543Smrg{
59706f2543Smrg  winScreenPriv(pScreen);
60706f2543Smrg  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
61706f2543Smrg  int			iX = pScreenInfo->dwInitialX;
62706f2543Smrg  int			iY = pScreenInfo->dwInitialY;
63706f2543Smrg  int			iWidth = pScreenInfo->dwWidth;
64706f2543Smrg  int			iHeight = pScreenInfo->dwHeight;
65706f2543Smrg  HWND			*phwnd = &pScreenPriv->hwndScreen;
66706f2543Smrg  WNDCLASSEX		wc;
67706f2543Smrg  char			szTitle[256];
68706f2543Smrg
69706f2543Smrg#if CYGDEBUG
70706f2543Smrg  winDebug ("winCreateBoundingWindowFullScreen\n");
71706f2543Smrg#endif
72706f2543Smrg
73706f2543Smrg  /* Setup our window class */
74706f2543Smrg  wc.cbSize=sizeof(WNDCLASSEX);
75706f2543Smrg  wc.style = CS_HREDRAW | CS_VREDRAW;
76706f2543Smrg  wc.lpfnWndProc = winWindowProc;
77706f2543Smrg  wc.cbClsExtra = 0;
78706f2543Smrg  wc.cbWndExtra = 0;
79706f2543Smrg  wc.hInstance = g_hInstance;
80706f2543Smrg  wc.hIcon = (HICON)LoadImage (g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
81706f2543Smrg		GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
82706f2543Smrg  wc.hCursor = 0;
83706f2543Smrg  wc.hbrBackground = 0;
84706f2543Smrg  wc.lpszMenuName = NULL;
85706f2543Smrg  wc.lpszClassName = WINDOW_CLASS;
86706f2543Smrg  wc.hIconSm = (HICON)LoadImage (g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
87706f2543Smrg		GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTSIZE);
88706f2543Smrg  RegisterClassEx (&wc);
89706f2543Smrg
90706f2543Smrg  /* Set display and screen-specific tooltip text */
91706f2543Smrg  if (g_pszQueryHost != NULL)
92706f2543Smrg    snprintf (szTitle,
93706f2543Smrg	    sizeof (szTitle),
94706f2543Smrg	    WINDOW_TITLE_XDMCP,
95706f2543Smrg	    g_pszQueryHost,
96706f2543Smrg	    display,
97706f2543Smrg	    (int) pScreenInfo->dwScreen);
98706f2543Smrg  else
99706f2543Smrg    snprintf (szTitle,
100706f2543Smrg	    sizeof (szTitle),
101706f2543Smrg	    WINDOW_TITLE,
102706f2543Smrg	    display,
103706f2543Smrg	    (int) pScreenInfo->dwScreen);
104706f2543Smrg
105706f2543Smrg  /* Create the window */
106706f2543Smrg  *phwnd = CreateWindowExA (0,			/* Extended styles */
107706f2543Smrg			    WINDOW_CLASS,	/* Class name */
108706f2543Smrg			    szTitle,		/* Window name */
109706f2543Smrg			    WS_POPUP,
110706f2543Smrg			    iX,			/* Horizontal position */
111706f2543Smrg			    iY,			/* Vertical position */
112706f2543Smrg			    iWidth,		/* Right edge */
113706f2543Smrg			    iHeight,		/* Bottom edge */
114706f2543Smrg			    (HWND) NULL,	/* No parent or owner window */
115706f2543Smrg			    (HMENU) NULL,	/* No menu */
116706f2543Smrg			    GetModuleHandle (NULL),/* Instance handle */
117706f2543Smrg			    pScreenPriv);	/* ScreenPrivates */
118706f2543Smrg
119706f2543Smrg  /* Branch on the server engine */
120706f2543Smrg  switch (pScreenInfo->dwEngine)
121706f2543Smrg    {
122706f2543Smrg#ifdef XWIN_NATIVEGDI
123706f2543Smrg    case WIN_SERVER_SHADOW_GDI:
124706f2543Smrg      /* Show the window */
125706f2543Smrg      ShowWindow (*phwnd, SW_SHOWMAXIMIZED);
126706f2543Smrg      break;
127706f2543Smrg#endif
128706f2543Smrg
129706f2543Smrg    default:
130706f2543Smrg      /* Hide the window */
131706f2543Smrg      ShowWindow (*phwnd, SW_SHOWNORMAL);
132706f2543Smrg      break;
133706f2543Smrg    }
134706f2543Smrg
135706f2543Smrg  /* Send first paint message */
136706f2543Smrg  UpdateWindow (*phwnd);
137706f2543Smrg
138706f2543Smrg  /* Attempt to bring our window to the top of the display */
139706f2543Smrg  BringWindowToTop (*phwnd);
140706f2543Smrg
141706f2543Smrg  return TRUE;
142706f2543Smrg}
143706f2543Smrg
144706f2543Smrg
145706f2543Smrg/*
146706f2543Smrg * Create our primary Windows display window
147706f2543Smrg */
148706f2543Smrg
149706f2543SmrgBool
150706f2543SmrgwinCreateBoundingWindowWindowed (ScreenPtr pScreen)
151706f2543Smrg{
152706f2543Smrg  winScreenPriv(pScreen);
153706f2543Smrg  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
154706f2543Smrg  int			iWidth = pScreenInfo->dwUserWidth;
155706f2543Smrg  int			iHeight = pScreenInfo->dwUserHeight;
156706f2543Smrg  int                   iPosX;
157706f2543Smrg  int                   iPosY;
158706f2543Smrg  HWND			*phwnd = &pScreenPriv->hwndScreen;
159706f2543Smrg  WNDCLASSEX		wc;
160706f2543Smrg  RECT			rcClient, rcWorkArea;
161706f2543Smrg  DWORD			dwWindowStyle;
162706f2543Smrg  BOOL			fForceShowWindow = FALSE;
163706f2543Smrg  char			szTitle[256];
164706f2543Smrg
165706f2543Smrg  winDebug ("winCreateBoundingWindowWindowed - User w: %d h: %d\n",
166706f2543Smrg	  (int) pScreenInfo->dwUserWidth, (int) pScreenInfo->dwUserHeight);
167706f2543Smrg  winDebug ("winCreateBoundingWindowWindowed - Current w: %d h: %d\n",
168706f2543Smrg	  (int) pScreenInfo->dwWidth, (int) pScreenInfo->dwHeight);
169706f2543Smrg
170706f2543Smrg  /* Set the common window style flags */
171706f2543Smrg  dwWindowStyle = WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;
172706f2543Smrg
173706f2543Smrg  /* Decorated or undecorated window */
174706f2543Smrg  if (pScreenInfo->fDecoration
175706f2543Smrg#ifdef XWIN_MULTIWINDOWEXTWM
176706f2543Smrg      && !pScreenInfo->fMWExtWM
177706f2543Smrg#endif
178706f2543Smrg      && !pScreenInfo->fRootless
179706f2543Smrg#ifdef XWIN_MULTIWINDOW
180706f2543Smrg      && !pScreenInfo->fMultiWindow
181706f2543Smrg#endif
182706f2543Smrg      )
183706f2543Smrg    {
184706f2543Smrg        /* Try to handle startup via run.exe. run.exe instructs Windows to
185706f2543Smrg         * hide all created windows. Detect this case and make sure the
186706f2543Smrg         * window is shown nevertheless */
187706f2543Smrg        STARTUPINFO   startupInfo;
188706f2543Smrg        GetStartupInfo(&startupInfo);
189706f2543Smrg        if (startupInfo.dwFlags & STARTF_USESHOWWINDOW &&
190706f2543Smrg                startupInfo.wShowWindow == SW_HIDE)
191706f2543Smrg        {
192706f2543Smrg          fForceShowWindow = TRUE;
193706f2543Smrg        }
194706f2543Smrg        dwWindowStyle |= WS_CAPTION;
195706f2543Smrg        if (pScreenInfo->iResizeMode != notAllowed)
196706f2543Smrg            dwWindowStyle |= WS_THICKFRAME | WS_MAXIMIZEBOX;
197706f2543Smrg    }
198706f2543Smrg  else
199706f2543Smrg    dwWindowStyle |= WS_POPUP;
200706f2543Smrg
201706f2543Smrg  /* Setup our window class */
202706f2543Smrg  wc.cbSize=sizeof(WNDCLASSEX);
203706f2543Smrg  wc.style = CS_HREDRAW | CS_VREDRAW;
204706f2543Smrg  wc.lpfnWndProc = winWindowProc;
205706f2543Smrg  wc.cbClsExtra = 0;
206706f2543Smrg  wc.cbWndExtra = 0;
207706f2543Smrg  wc.hInstance = g_hInstance;
208706f2543Smrg  wc.hIcon = (HICON)LoadImage (g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
209706f2543Smrg		GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
210706f2543Smrg  wc.hCursor = 0;
211706f2543Smrg  wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
212706f2543Smrg  wc.lpszMenuName = NULL;
213706f2543Smrg  wc.lpszClassName = WINDOW_CLASS;
214706f2543Smrg  wc.hIconSm = (HICON)LoadImage (g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
215706f2543Smrg		GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTSIZE);
216706f2543Smrg  RegisterClassEx (&wc);
217706f2543Smrg
218706f2543Smrg  /* Get size of work area */
219706f2543Smrg  winGetWorkArea (&rcWorkArea, pScreenInfo);
220706f2543Smrg
221706f2543Smrg  /* Adjust for auto-hide taskbars */
222706f2543Smrg  winAdjustForAutoHide (&rcWorkArea);
223706f2543Smrg
224706f2543Smrg  /* Did the user specify a position? */
225706f2543Smrg  if (pScreenInfo->fUserGavePosition)
226706f2543Smrg    {
227706f2543Smrg      iPosX = pScreenInfo->dwInitialX;
228706f2543Smrg      iPosY = pScreenInfo->dwInitialY;
229706f2543Smrg    }
230706f2543Smrg  else
231706f2543Smrg    {
232706f2543Smrg      iPosX = rcWorkArea.left;
233706f2543Smrg      iPosY = rcWorkArea.top;
234706f2543Smrg    }
235706f2543Smrg
236706f2543Smrg  /* Clean up the scrollbars flag, if necessary */
237706f2543Smrg  if ((!pScreenInfo->fDecoration
238706f2543Smrg#ifdef XWIN_MULTIWINDOWEXTWM
239706f2543Smrg       || pScreenInfo->fMWExtWM
240706f2543Smrg#endif
241706f2543Smrg       || pScreenInfo->fRootless
242706f2543Smrg#ifdef XWIN_MULTIWINDOW
243706f2543Smrg       || pScreenInfo->fMultiWindow
244706f2543Smrg#endif
245706f2543Smrg       )
246706f2543Smrg      && (pScreenInfo->iResizeMode == resizeWithScrollbars))
247706f2543Smrg    {
248706f2543Smrg      /* We cannot have scrollbars if we do not have a window border */
249706f2543Smrg      pScreenInfo->iResizeMode = notAllowed;
250706f2543Smrg    }
251706f2543Smrg
252706f2543Smrg  /* Did the user specify a height and width? */
253706f2543Smrg  if (pScreenInfo->fUserGaveHeightAndWidth)
254706f2543Smrg    {
255706f2543Smrg      /* User gave a desired height and width, try to accomodate */
256706f2543Smrg#if CYGDEBUG
257706f2543Smrg      winDebug ("winCreateBoundingWindowWindowed - User gave height "
258706f2543Smrg	      "and width\n");
259706f2543Smrg#endif
260706f2543Smrg
261706f2543Smrg      /* Adjust the window width and height for borders and title bar */
262706f2543Smrg      if (pScreenInfo->fDecoration
263706f2543Smrg#ifdef XWIN_MULTIWINDOWEXTWM
264706f2543Smrg	  && !pScreenInfo->fMWExtWM
265706f2543Smrg#endif
266706f2543Smrg	  && !pScreenInfo->fRootless
267706f2543Smrg#ifdef XWIN_MULTIWINDOW
268706f2543Smrg	  && !pScreenInfo->fMultiWindow
269706f2543Smrg#endif
270706f2543Smrg	  )
271706f2543Smrg	{
272706f2543Smrg#if CYGDEBUG
273706f2543Smrg	  winDebug ("winCreateBoundingWindowWindowed - Window has decoration\n");
274706f2543Smrg#endif
275706f2543Smrg
276706f2543Smrg          /* Are we resizable */
277706f2543Smrg          if (pScreenInfo->iResizeMode != notAllowed)
278706f2543Smrg	    {
279706f2543Smrg#if CYGDEBUG
280706f2543Smrg	      winDebug ("winCreateBoundingWindowWindowed - Window is resizable\n");
281706f2543Smrg#endif
282706f2543Smrg
283706f2543Smrg	      iWidth += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
284706f2543Smrg	      iHeight += 2 * GetSystemMetrics (SM_CYSIZEFRAME)
285706f2543Smrg		+ GetSystemMetrics (SM_CYCAPTION);
286706f2543Smrg	    }
287706f2543Smrg	  else
288706f2543Smrg	    {
289706f2543Smrg#if CYGDEBUG
290706f2543Smrg	      winDebug ("winCreateBoundingWindowWindowed - Window is not resizable\n");
291706f2543Smrg#endif
292706f2543Smrg
293706f2543Smrg	      iWidth += 2 * GetSystemMetrics (SM_CXFIXEDFRAME);
294706f2543Smrg	      iHeight += 2 * GetSystemMetrics (SM_CYFIXEDFRAME)
295706f2543Smrg		+ GetSystemMetrics (SM_CYCAPTION);
296706f2543Smrg	    }
297706f2543Smrg	}
298706f2543Smrg    }
299706f2543Smrg  else
300706f2543Smrg    {
301706f2543Smrg      /* By default, we are creating a window that is as large as possible */
302706f2543Smrg#if CYGDEBUG
303706f2543Smrg      winDebug ("winCreateBoundingWindowWindowed - User did not give "
304706f2543Smrg	      "height and width\n");
305706f2543Smrg#endif
306706f2543Smrg      /* Defaults are wrong if we have multiple monitors */
307706f2543Smrg      if (pScreenInfo->fMultipleMonitors)
308706f2543Smrg	{
309706f2543Smrg	  iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
310706f2543Smrg	  iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
311706f2543Smrg	}
312706f2543Smrg    }
313706f2543Smrg
314706f2543Smrg  /* Make sure window is no bigger than work area */
315706f2543Smrg  if (TRUE
316706f2543Smrg#ifdef XWIN_MULTIWINDOWEXTWM
317706f2543Smrg       && !pScreenInfo->fMWExtWM
318706f2543Smrg#endif
319706f2543Smrg#ifdef XWIN_MULTIWINDOW
320706f2543Smrg       && !pScreenInfo->fMultiWindow
321706f2543Smrg#endif
322706f2543Smrg     )
323706f2543Smrg    {
324706f2543Smrg      /* Trim window width to fit work area */
325706f2543Smrg      if (iWidth > (rcWorkArea.right - rcWorkArea.left))
326706f2543Smrg        iWidth = rcWorkArea.right - rcWorkArea.left;
327706f2543Smrg
328706f2543Smrg      /* Trim window height to fit work area */
329706f2543Smrg      if (iHeight >= (rcWorkArea.bottom - rcWorkArea.top))
330706f2543Smrg        iHeight = rcWorkArea.bottom - rcWorkArea.top;
331706f2543Smrg
332706f2543Smrg#if CYGDEBUG
333706f2543Smrg      winDebug ("winCreateBoundingWindowWindowed - Adjusted width: %d "\
334706f2543Smrg	      "height: %d\n",
335706f2543Smrg    	  iWidth, iHeight);
336706f2543Smrg#endif
337706f2543Smrg    }
338706f2543Smrg
339706f2543Smrg  /* Set display and screen-specific tooltip text */
340706f2543Smrg  if (g_pszQueryHost != NULL)
341706f2543Smrg    snprintf (szTitle,
342706f2543Smrg	    sizeof (szTitle),
343706f2543Smrg	    WINDOW_TITLE_XDMCP,
344706f2543Smrg	    g_pszQueryHost,
345706f2543Smrg	    display,
346706f2543Smrg	    (int) pScreenInfo->dwScreen);
347706f2543Smrg  else
348706f2543Smrg    snprintf (szTitle,
349706f2543Smrg	    sizeof (szTitle),
350706f2543Smrg	    WINDOW_TITLE,
351706f2543Smrg	    display,
352706f2543Smrg	    (int) pScreenInfo->dwScreen);
353706f2543Smrg
354706f2543Smrg  /* Create the window */
355706f2543Smrg  *phwnd = CreateWindowExA (0,			/* Extended styles */
356706f2543Smrg			    WINDOW_CLASS,	/* Class name */
357706f2543Smrg			    szTitle,		/* Window name */
358706f2543Smrg			    dwWindowStyle,
359706f2543Smrg			    iPosX,	        /* Horizontal position */
360706f2543Smrg			    iPosY,	        /* Vertical position */
361706f2543Smrg			    iWidth,		/* Right edge */
362706f2543Smrg			    iHeight,		/* Bottom edge */
363706f2543Smrg			    (HWND) NULL,	/* No parent or owner window */
364706f2543Smrg			    (HMENU) NULL,	/* No menu */
365706f2543Smrg			    GetModuleHandle (NULL),/* Instance handle */
366706f2543Smrg			    pScreenPriv);	/* ScreenPrivates */
367706f2543Smrg  if (*phwnd == NULL)
368706f2543Smrg    {
369706f2543Smrg      ErrorF ("winCreateBoundingWindowWindowed - CreateWindowEx () failed\n");
370706f2543Smrg      return FALSE;
371706f2543Smrg    }
372706f2543Smrg
373706f2543Smrg#if CYGDEBUG
374706f2543Smrg  winDebug ("winCreateBoundingWindowWindowed - CreateWindowEx () returned\n");
375706f2543Smrg#endif
376706f2543Smrg
377706f2543Smrg  if (fForceShowWindow)
378706f2543Smrg  {
379706f2543Smrg      ErrorF("winCreateBoundingWindowWindowed - Setting normal windowstyle\n");
380706f2543Smrg      ShowWindow(*phwnd, SW_SHOW);
381706f2543Smrg  }
382706f2543Smrg
383706f2543Smrg  /* Get the client area coordinates */
384706f2543Smrg  if (!GetClientRect (*phwnd, &rcClient))
385706f2543Smrg    {
386706f2543Smrg      ErrorF ("winCreateBoundingWindowWindowed - GetClientRect () "
387706f2543Smrg	      "failed\n");
388706f2543Smrg      return FALSE;
389706f2543Smrg    }
390706f2543Smrg
391706f2543Smrg  winDebug ("winCreateBoundingWindowWindowed - WindowClient "
392706f2543Smrg	  "w %ld h %ld r %ld l %ld b %ld t %ld\n",
393706f2543Smrg	  rcClient.right - rcClient.left,
394706f2543Smrg	  rcClient.bottom - rcClient.top,
395706f2543Smrg	  rcClient.right, rcClient.left,
396706f2543Smrg	  rcClient.bottom, rcClient.top);
397706f2543Smrg
398706f2543Smrg  /* We adjust the visual size if the user did not specify it */
399706f2543Smrg  if (!((pScreenInfo->iResizeMode == resizeWithScrollbars) && pScreenInfo->fUserGaveHeightAndWidth))
400706f2543Smrg    {
401706f2543Smrg      /*
402706f2543Smrg       * User did not give a height and width with scrollbars enabled,
403706f2543Smrg       * so we will resize the underlying visual to be as large as
404706f2543Smrg       * the initial view port (page size).  This way scrollbars will
405706f2543Smrg       * not appear until the user shrinks the window, if they ever do.
406706f2543Smrg       *
407706f2543Smrg       * NOTE: We have to store the viewport size here because
408706f2543Smrg       * the user may have an autohide taskbar, which would
409706f2543Smrg       * cause the viewport size to be one less in one dimension
410706f2543Smrg       * than the viewport size that we calculated by subtracting
411706f2543Smrg       * the size of the borders and caption.
412706f2543Smrg       */
413706f2543Smrg      pScreenInfo->dwWidth = rcClient.right - rcClient.left;
414706f2543Smrg      pScreenInfo->dwHeight = rcClient.bottom - rcClient.top;
415706f2543Smrg    }
416706f2543Smrg
417706f2543Smrg#if 0
418706f2543Smrg  /*
419706f2543Smrg   * NOTE: For the uninitiated, the page size is the number of pixels
420706f2543Smrg   * that we can display in the x or y direction at a time and the
421706f2543Smrg   * range is the total number of pixels in the x or y direction that we
422706f2543Smrg   * have available to display.  In other words, the page size is the
423706f2543Smrg   * size of the window area minus the space the caption, borders, and
424706f2543Smrg   * scrollbars (if any) occupy, and the range is the size of the
425706f2543Smrg   * underlying X visual.  Notice that, contrary to what some of the
426706f2543Smrg   * MSDN Library arcticles lead you to believe, the windows
427706f2543Smrg   * ``client area'' size does not include the scrollbars.  In other words,
428706f2543Smrg   * the whole client area size that is reported to you is drawable by
429706f2543Smrg   * you; you do not have to subtract the size of the scrollbars from
430706f2543Smrg   * the client area size, and if you did it would result in the size
431706f2543Smrg   * of the scrollbars being double counted.
432706f2543Smrg   */
433706f2543Smrg
434706f2543Smrg  /* Setup scrollbar page and range, if scrollbars are enabled */
435706f2543Smrg  if (pScreenInfo->fScrollbars)
436706f2543Smrg    {
437706f2543Smrg      SCROLLINFO		si;
438706f2543Smrg
439706f2543Smrg      /* Initialize the scrollbar info structure */
440706f2543Smrg      si.cbSize = sizeof (si);
441706f2543Smrg      si.fMask = SIF_RANGE | SIF_PAGE;
442706f2543Smrg      si.nMin = 0;
443706f2543Smrg
444706f2543Smrg      /* Setup the width range and page size */
445706f2543Smrg      si.nMax = pScreenInfo->dwWidth - 1;
446706f2543Smrg      si.nPage = rcClient.right - rcClient.left;
447706f2543Smrg      winDebug ("winCreateBoundingWindowWindowed - HORZ nMax: %d nPage :%d\n",
448706f2543Smrg	      si.nMax, si.nPage);
449706f2543Smrg      SetScrollInfo (*phwnd, SB_HORZ, &si, TRUE);
450706f2543Smrg
451706f2543Smrg      /* Setup the height range and page size */
452706f2543Smrg      si.nMax = pScreenInfo->dwHeight - 1;
453706f2543Smrg      si.nPage = rcClient.bottom - rcClient.top;
454706f2543Smrg      winDebug ("winCreateBoundingWindowWindowed - VERT nMax: %d nPage :%d\n",
455706f2543Smrg	      si.nMax, si.nPage);
456706f2543Smrg      SetScrollInfo (*phwnd, SB_VERT, &si, TRUE);
457706f2543Smrg    }
458706f2543Smrg#endif
459706f2543Smrg
460706f2543Smrg  /* Show the window */
461706f2543Smrg  if (FALSE
462706f2543Smrg#ifdef XWIN_MULTIWINDOWEXTWM
463706f2543Smrg      || pScreenInfo->fMWExtWM
464706f2543Smrg#endif
465706f2543Smrg#ifdef XWIN_MULTIWINDOW
466706f2543Smrg      || pScreenInfo->fMultiWindow
467706f2543Smrg#endif
468706f2543Smrg      )
469706f2543Smrg    {
470706f2543Smrg#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
471706f2543Smrg      pScreenPriv->fRootWindowShown = FALSE;
472706f2543Smrg#endif
473706f2543Smrg      ShowWindow (*phwnd, SW_HIDE);
474706f2543Smrg    }
475706f2543Smrg  else
476706f2543Smrg    ShowWindow (*phwnd, SW_SHOWNORMAL);
477706f2543Smrg  if (!UpdateWindow (*phwnd))
478706f2543Smrg    {
479706f2543Smrg      ErrorF ("winCreateBoundingWindowWindowed - UpdateWindow () failed\n");
480706f2543Smrg      return FALSE;
481706f2543Smrg    }
482706f2543Smrg
483706f2543Smrg  /* Attempt to bring our window to the top of the display */
484706f2543Smrg  if (TRUE
485706f2543Smrg#ifdef XWIN_MULTIWINDOWEXTWM
486706f2543Smrg      && !pScreenInfo->fMWExtWM
487706f2543Smrg#endif
488706f2543Smrg      && !pScreenInfo->fRootless
489706f2543Smrg#ifdef XWIN_MULTIWINDOW
490706f2543Smrg      && !pScreenInfo->fMultiWindow
491706f2543Smrg#endif
492706f2543Smrg      )
493706f2543Smrg    {
494706f2543Smrg      if (!BringWindowToTop (*phwnd))
495706f2543Smrg	{
496706f2543Smrg	  ErrorF ("winCreateBoundingWindowWindowed - BringWindowToTop () "
497706f2543Smrg		  "failed\n");
498706f2543Smrg	  return FALSE;
499706f2543Smrg	}
500706f2543Smrg    }
501706f2543Smrg
502706f2543Smrg#ifdef XWIN_NATIVEGDI
503706f2543Smrg  /* Paint window background blue */
504706f2543Smrg  if (pScreenInfo->dwEngine == WIN_SERVER_NATIVE_GDI)
505706f2543Smrg    winPaintBackground (*phwnd, RGB (0x00, 0x00, 0xFF));
506706f2543Smrg#endif
507706f2543Smrg
508706f2543Smrg  winDebug ("winCreateBoundingWindowWindowed -  Returning\n");
509706f2543Smrg
510706f2543Smrg  return TRUE;
511706f2543Smrg}
512706f2543Smrg
513706f2543Smrg
514706f2543Smrg/*
515706f2543Smrg * Find the work area of all attached monitors
516706f2543Smrg */
517706f2543Smrg
518706f2543Smrgstatic Bool
519706f2543SmrgwinGetWorkArea (RECT *prcWorkArea, winScreenInfo *pScreenInfo)
520706f2543Smrg{
521706f2543Smrg  int			iPrimaryWidth, iPrimaryHeight;
522706f2543Smrg  int			iWidth, iHeight;
523706f2543Smrg  int			iLeft, iTop;
524706f2543Smrg  int			iPrimaryNonWorkAreaWidth, iPrimaryNonWorkAreaHeight;
525706f2543Smrg
526706f2543Smrg  /* SPI_GETWORKAREA only gets the work area of the primary screen. */
527706f2543Smrg  SystemParametersInfo (SPI_GETWORKAREA, 0, prcWorkArea, 0);
528706f2543Smrg
529706f2543Smrg  /* Bail out here if we aren't using multiple monitors */
530706f2543Smrg  if (!pScreenInfo->fMultipleMonitors)
531706f2543Smrg    return TRUE;
532706f2543Smrg
533706f2543Smrg  winDebug ("winGetWorkArea - Original WorkArea: %d %d %d %d\n",
534706f2543Smrg	  (int) prcWorkArea->top, (int) prcWorkArea->left,
535706f2543Smrg	  (int) prcWorkArea->bottom, (int) prcWorkArea->right);
536706f2543Smrg
537706f2543Smrg  /* Get size of full virtual screen */
538706f2543Smrg  iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
539706f2543Smrg  iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
540706f2543Smrg
541706f2543Smrg  winDebug ("winGetWorkArea - Virtual screen is %d x %d\n", iWidth, iHeight);
542706f2543Smrg
543706f2543Smrg  /* Get origin of full virtual screen */
544706f2543Smrg  iLeft = GetSystemMetrics (SM_XVIRTUALSCREEN);
545706f2543Smrg  iTop = GetSystemMetrics (SM_YVIRTUALSCREEN);
546706f2543Smrg
547706f2543Smrg  winDebug ("winGetWorkArea - Virtual screen origin is %d, %d\n", iLeft, iTop);
548706f2543Smrg
549706f2543Smrg  /* Get size of primary screen */
550706f2543Smrg  iPrimaryWidth = GetSystemMetrics (SM_CXSCREEN);
551706f2543Smrg  iPrimaryHeight = GetSystemMetrics (SM_CYSCREEN);
552706f2543Smrg
553706f2543Smrg  winDebug ("winGetWorkArea - Primary screen is %d x %d\n",
554706f2543Smrg	 iPrimaryWidth, iPrimaryHeight);
555706f2543Smrg
556706f2543Smrg  /* Work out how much of the primary screen we aren't using */
557706f2543Smrg  iPrimaryNonWorkAreaWidth = iPrimaryWidth - (prcWorkArea->right -
558706f2543Smrg					      prcWorkArea->left);
559706f2543Smrg  iPrimaryNonWorkAreaHeight = iPrimaryHeight - (prcWorkArea->bottom
560706f2543Smrg						- prcWorkArea->top);
561706f2543Smrg
562706f2543Smrg  /* Update the rectangle to include all monitors */
563706f2543Smrg  if (iLeft < 0)
564706f2543Smrg    {
565706f2543Smrg      prcWorkArea->left = iLeft;
566706f2543Smrg    }
567706f2543Smrg  if (iTop < 0)
568706f2543Smrg    {
569706f2543Smrg      prcWorkArea->top = iTop;
570706f2543Smrg    }
571706f2543Smrg  prcWorkArea->right = prcWorkArea->left + iWidth -
572706f2543Smrg    iPrimaryNonWorkAreaWidth;
573706f2543Smrg  prcWorkArea->bottom = prcWorkArea->top + iHeight -
574706f2543Smrg    iPrimaryNonWorkAreaHeight;
575706f2543Smrg
576706f2543Smrg  winDebug ("winGetWorkArea - Adjusted WorkArea for multiple "
577706f2543Smrg	  "monitors: %d %d %d %d\n",
578706f2543Smrg	  (int) prcWorkArea->top, (int) prcWorkArea->left,
579706f2543Smrg	  (int) prcWorkArea->bottom, (int) prcWorkArea->right);
580706f2543Smrg
581706f2543Smrg  return TRUE;
582706f2543Smrg}
583706f2543Smrg
584706f2543Smrg
585706f2543Smrg/*
586706f2543Smrg * Adjust the client area so that any auto-hide toolbars
587706f2543Smrg * will work correctly.
588706f2543Smrg */
589706f2543Smrg
590706f2543Smrgstatic Bool
591706f2543SmrgwinAdjustForAutoHide (RECT *prcWorkArea)
592706f2543Smrg{
593706f2543Smrg  APPBARDATA		abd;
594706f2543Smrg  HWND			hwndAutoHide;
595706f2543Smrg
596706f2543Smrg  winDebug ("winAdjustForAutoHide - Original WorkArea: %d %d %d %d\n",
597706f2543Smrg	  (int) prcWorkArea->top, (int) prcWorkArea->left,
598706f2543Smrg	  (int) prcWorkArea->bottom, (int) prcWorkArea->right);
599706f2543Smrg
600706f2543Smrg  /* Find out if the Windows taskbar is set to auto-hide */
601706f2543Smrg  ZeroMemory (&abd, sizeof (abd));
602706f2543Smrg  abd.cbSize = sizeof (abd);
603706f2543Smrg  if (SHAppBarMessage (ABM_GETSTATE, &abd) & ABS_AUTOHIDE)
604706f2543Smrg    winDebug ("winAdjustForAutoHide - Taskbar is auto hide\n");
605706f2543Smrg
606706f2543Smrg  /* Look for a TOP auto-hide taskbar */
607706f2543Smrg  abd.uEdge = ABE_TOP;
608706f2543Smrg  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
609706f2543Smrg  if (hwndAutoHide != NULL)
610706f2543Smrg    {
611706f2543Smrg      winDebug ("winAdjustForAutoHide - Found TOP auto-hide taskbar\n");
612706f2543Smrg      prcWorkArea->top += 1;
613706f2543Smrg    }
614706f2543Smrg
615706f2543Smrg  /* Look for a LEFT auto-hide taskbar */
616706f2543Smrg  abd.uEdge = ABE_LEFT;
617706f2543Smrg  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
618706f2543Smrg  if (hwndAutoHide != NULL)
619706f2543Smrg    {
620706f2543Smrg      winDebug ("winAdjustForAutoHide - Found LEFT auto-hide taskbar\n");
621706f2543Smrg      prcWorkArea->left += 1;
622706f2543Smrg    }
623706f2543Smrg
624706f2543Smrg  /* Look for a BOTTOM auto-hide taskbar */
625706f2543Smrg  abd.uEdge = ABE_BOTTOM;
626706f2543Smrg  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
627706f2543Smrg  if (hwndAutoHide != NULL)
628706f2543Smrg    {
629706f2543Smrg      winDebug ("winAdjustForAutoHide - Found BOTTOM auto-hide taskbar\n");
630706f2543Smrg      prcWorkArea->bottom -= 1;
631706f2543Smrg    }
632706f2543Smrg
633706f2543Smrg  /* Look for a RIGHT auto-hide taskbar */
634706f2543Smrg  abd.uEdge = ABE_RIGHT;
635706f2543Smrg  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETAUTOHIDEBAR, &abd);
636706f2543Smrg  if (hwndAutoHide != NULL)
637706f2543Smrg    {
638706f2543Smrg      winDebug ("winAdjustForAutoHide - Found RIGHT auto-hide taskbar\n");
639706f2543Smrg      prcWorkArea->right -= 1;
640706f2543Smrg    }
641706f2543Smrg
642706f2543Smrg  winDebug ("winAdjustForAutoHide - Adjusted WorkArea: %d %d %d %d\n",
643706f2543Smrg	  (int) prcWorkArea->top, (int) prcWorkArea->left,
644706f2543Smrg	  (int) prcWorkArea->bottom, (int) prcWorkArea->right);
645706f2543Smrg
646706f2543Smrg#if 0
647706f2543Smrg  /* Obtain the task bar window dimensions */
648706f2543Smrg  abd.hWnd = hwndAutoHide;
649706f2543Smrg  hwndAutoHide = (HWND) SHAppBarMessage (ABM_GETTASKBARPOS, &abd);
650706f2543Smrg  winDebug ("hwndAutoHide %08x abd.hWnd %08x %d %d %d %d\n",
651706f2543Smrg	  hwndAutoHide, abd.hWnd,
652706f2543Smrg	  abd.rc.top, abd.rc.left, abd.rc.bottom, abd.rc.right);
653706f2543Smrg#endif
654706f2543Smrg
655706f2543Smrg  return TRUE;
656706f2543Smrg}
657