windialogs.c revision 9ace9065
105b261ecSmrg/*
205b261ecSmrg *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
305b261ecSmrg *
405b261ecSmrg *Permission is hereby granted, free of charge, to any person obtaining
505b261ecSmrg * a copy of this software and associated documentation files (the
605b261ecSmrg *"Software"), to deal in the Software without restriction, including
705b261ecSmrg *without limitation the rights to use, copy, modify, merge, publish,
805b261ecSmrg *distribute, sublicense, and/or sell copies of the Software, and to
905b261ecSmrg *permit persons to whom the Software is furnished to do so, subject to
1005b261ecSmrg *the following conditions:
1105b261ecSmrg *
1205b261ecSmrg *The above copyright notice and this permission notice shall be
1305b261ecSmrg *included in all copies or substantial portions of the Software.
1405b261ecSmrg *
1505b261ecSmrg *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1605b261ecSmrg *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1705b261ecSmrg *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1805b261ecSmrg *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
1905b261ecSmrg *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
2005b261ecSmrg *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2105b261ecSmrg *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2205b261ecSmrg *
2305b261ecSmrg *Except as contained in this notice, the name of Harold L Hunt II
2405b261ecSmrg *shall not be used in advertising or otherwise to promote the sale, use
2505b261ecSmrg *or other dealings in this Software without prior written authorization
2605b261ecSmrg *from Harold L Hunt II.
2705b261ecSmrg *
2805b261ecSmrg * Authors:	Harold L Hunt II
2905b261ecSmrg *              Earle F. Philhower III
3005b261ecSmrg */
3105b261ecSmrg
3205b261ecSmrg#ifdef HAVE_XWIN_CONFIG_H
3305b261ecSmrg#include <xwin-config.h>
3405b261ecSmrg#endif
3505b261ecSmrg#include "win.h"
3605b261ecSmrg#ifdef __CYGWIN__
3705b261ecSmrg#include <sys/cygwin.h>
3805b261ecSmrg#endif
3905b261ecSmrg#include <shellapi.h>
4005b261ecSmrg#include "winprefs.h"
4105b261ecSmrg
4205b261ecSmrg
4305b261ecSmrg/*
4405b261ecSmrg * References to external globals
4505b261ecSmrg */
4605b261ecSmrg
4705b261ecSmrg#ifdef XWIN_CLIPBOARD
4805b261ecSmrgextern Bool			g_fClipboardStarted;
4905b261ecSmrg#endif
5005b261ecSmrg/*
5105b261ecSmrg * Local function prototypes
5205b261ecSmrg */
5305b261ecSmrg
5405b261ecSmrgstatic wBOOL CALLBACK
5505b261ecSmrgwinExitDlgProc (HWND hDialog, UINT message,
5605b261ecSmrg		WPARAM wParam, LPARAM lParam);
5705b261ecSmrg
5805b261ecSmrgstatic wBOOL CALLBACK
5905b261ecSmrgwinChangeDepthDlgProc (HWND hDialog, UINT message,
6005b261ecSmrg		       WPARAM wParam, LPARAM lParam);
6105b261ecSmrg
6205b261ecSmrgstatic wBOOL CALLBACK
6305b261ecSmrgwinAboutDlgProc (HWND hDialog, UINT message,
6405b261ecSmrg		 WPARAM wParam, LPARAM lParam);
6505b261ecSmrg
6605b261ecSmrg
6705b261ecSmrgstatic void
6805b261ecSmrgwinDrawURLWindow (LPARAM lParam);
6905b261ecSmrg
7005b261ecSmrgstatic LRESULT CALLBACK
7105b261ecSmrgwinURLWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
7205b261ecSmrg
7305b261ecSmrgstatic void
7405b261ecSmrgwinOverrideURLButton (HWND hdlg, int id);
7505b261ecSmrg
7605b261ecSmrgstatic void
7705b261ecSmrgwinUnoverrideURLButton (HWND hdlg, int id);
7805b261ecSmrg
7905b261ecSmrg
8005b261ecSmrg/*
8105b261ecSmrg * Owner-draw a button as a URL
8205b261ecSmrg */
8305b261ecSmrg
8405b261ecSmrgstatic void
8505b261ecSmrgwinDrawURLWindow (LPARAM lParam)
8605b261ecSmrg{
8705b261ecSmrg  DRAWITEMSTRUCT *draw;
8805b261ecSmrg  char str[256];
8905b261ecSmrg  RECT rect;
9005b261ecSmrg  HFONT font;
9105b261ecSmrg  COLORREF crText;
9205b261ecSmrg
9305b261ecSmrg  draw = (DRAWITEMSTRUCT *) lParam;
9405b261ecSmrg  GetWindowText (draw->hwndItem, str, sizeof(str));
9505b261ecSmrg  str[255] = 0;
9605b261ecSmrg  GetClientRect (draw->hwndItem, &rect);
9705b261ecSmrg
9805b261ecSmrg  /* Color the button depending upon its state */
9905b261ecSmrg  if (draw->itemState & ODS_SELECTED)
10005b261ecSmrg    crText = RGB(128+64,0,0);
10105b261ecSmrg  else if (draw->itemState & ODS_FOCUS)
10205b261ecSmrg    crText = RGB(0,128+64,0);
10305b261ecSmrg  else
10405b261ecSmrg    crText = RGB(0,0,128+64);
10505b261ecSmrg  SetTextColor (draw->hDC, crText);
10605b261ecSmrg
1076747b715Smrg  /* Create font 8 high, standard dialog font */
1086747b715Smrg  font = CreateFont (-8, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
10905b261ecSmrg		     0, 0, 0, 0, 0, "MS Sans Serif");
11005b261ecSmrg  if (!font)
11105b261ecSmrg    {
11205b261ecSmrg      ErrorF ("winDrawURLWindow: Unable to create URL font, bailing.\n");
11305b261ecSmrg      return;
11405b261ecSmrg    }
11505b261ecSmrg  /* Draw it */
11605b261ecSmrg  SetBkMode (draw->hDC, OPAQUE);
11705b261ecSmrg  SelectObject (draw->hDC, font);
11805b261ecSmrg  DrawText (draw->hDC, str, strlen (str),&rect,DT_CENTER | DT_VCENTER);
11905b261ecSmrg  /* Delete the created font, replace it with stock font */
12005b261ecSmrg  DeleteObject (SelectObject (draw->hDC, GetStockObject (ANSI_VAR_FONT)));
12105b261ecSmrg}
12205b261ecSmrg
12305b261ecSmrg
12405b261ecSmrg/*
12505b261ecSmrg * WndProc for overridden buttons
12605b261ecSmrg */
12705b261ecSmrg
12805b261ecSmrgstatic LRESULT CALLBACK
12905b261ecSmrgwinURLWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
13005b261ecSmrg{
13105b261ecSmrg  WNDPROC origCB = NULL;
13205b261ecSmrg  HCURSOR cursor;
13305b261ecSmrg
13405b261ecSmrg  /* If it's a SetCursor message, tell it to the hand */
13505b261ecSmrg  if (msg==WM_SETCURSOR) {
13605b261ecSmrg    cursor = LoadCursor (NULL, IDC_HAND);
13705b261ecSmrg    if (cursor)
13805b261ecSmrg      SetCursor (cursor);
13905b261ecSmrg    return TRUE;
14005b261ecSmrg  }
1416747b715Smrg  origCB = (WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA);
14205b261ecSmrg  /* Otherwise fall through to original WndProc */
14305b261ecSmrg  if (origCB)
14405b261ecSmrg    return CallWindowProc (origCB, hwnd, msg, wParam, lParam);
14505b261ecSmrg  else
14605b261ecSmrg    return FALSE;
14705b261ecSmrg}
14805b261ecSmrg
14905b261ecSmrg
15005b261ecSmrg/*
15105b261ecSmrg * Register and unregister the custom WndProc
15205b261ecSmrg */
15305b261ecSmrg
15405b261ecSmrgstatic void
15505b261ecSmrgwinOverrideURLButton (HWND hwnd, int id)
15605b261ecSmrg{
15705b261ecSmrg  WNDPROC origCB;
1586747b715Smrg  origCB = (WNDPROC)SetWindowLongPtr(GetDlgItem (hwnd, id),
1596747b715Smrg                                     GWLP_WNDPROC, (LONG_PTR)winURLWndProc);
1606747b715Smrg  SetWindowLongPtr(GetDlgItem (hwnd, id), GWLP_USERDATA, (LONG_PTR)origCB);
16105b261ecSmrg}
16205b261ecSmrg
16305b261ecSmrgstatic void
16405b261ecSmrgwinUnoverrideURLButton (HWND hwnd, int id)
16505b261ecSmrg{
16605b261ecSmrg  WNDPROC origCB;
1676747b715Smrg  origCB = (WNDPROC)SetWindowLongPtr(GetDlgItem (hwnd, id),
1686747b715Smrg                                     GWLP_USERDATA, 0);
16905b261ecSmrg  if (origCB)
1706747b715Smrg    SetWindowLongPtr(GetDlgItem (hwnd, id), GWLP_WNDPROC, (LONG_PTR)origCB);
17105b261ecSmrg}
17205b261ecSmrg
17305b261ecSmrg
17405b261ecSmrg/*
17505b261ecSmrg * Center a dialog window in the desktop window
1766747b715Smrg * and set small and large icons to X icons.
17705b261ecSmrg */
17805b261ecSmrg
17905b261ecSmrgstatic void
1806747b715SmrgwinInitDialog (HWND hwndDlg)
18105b261ecSmrg{
18205b261ecSmrg  HWND hwndDesk;
1836747b715Smrg  RECT rc, rcDlg, rcDesk;
1846747b715Smrg  HICON hIcon, hIconSmall;
18505b261ecSmrg
18605b261ecSmrg  hwndDesk = GetParent (hwndDlg);
18705b261ecSmrg  if (!hwndDesk || IsIconic (hwndDesk))
18805b261ecSmrg    hwndDesk = GetDesktopWindow ();
18905b261ecSmrg
1906747b715Smrg  /* Remove minimize and maximize buttons */
1916747b715Smrg  SetWindowLongPtr(hwndDlg, GWL_STYLE,
1926747b715Smrg                   GetWindowLongPtr(hwndDlg, GWL_STYLE)
1936747b715Smrg                   & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
1946747b715Smrg
1956747b715Smrg  /* Set Window not to show in the task bar */
1966747b715Smrg  SetWindowLongPtr(hwndDlg, GWL_EXSTYLE,
1976747b715Smrg                   GetWindowLongPtr(hwndDlg, GWL_EXSTYLE) & ~WS_EX_APPWINDOW );
1986747b715Smrg
1996747b715Smrg  /* Center dialog window in the screen. Not done for multi-monitor systems, where
2006747b715Smrg   * it is likely to end up split across the screens. In that case, it appears
2016747b715Smrg   * near the Tray icon.
2026747b715Smrg   */
2036747b715Smrg  if (GetSystemMetrics(SM_CMONITORS)>1) {
2046747b715Smrg    /* Still need to refresh the frame change. */
2056747b715Smrg    SetWindowPos (hwndDlg, HWND_TOPMOST, 0,0,0,0,
2066747b715Smrg		SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
2076747b715Smrg  } else {
2086747b715Smrg    GetWindowRect (hwndDesk, &rcDesk);
2096747b715Smrg    GetWindowRect (hwndDlg, &rcDlg);
2106747b715Smrg    CopyRect (&rc, &rcDesk);
2116747b715Smrg
2126747b715Smrg    OffsetRect (&rcDlg, -rcDlg.left, -rcDlg.top);
2136747b715Smrg    OffsetRect (&rc, -rc.left, -rc.top);
2146747b715Smrg    OffsetRect (&rc, -rcDlg.right, -rcDlg.bottom);
2156747b715Smrg
2166747b715Smrg    SetWindowPos (hwndDlg,
2176747b715Smrg		HWND_TOPMOST,
2186747b715Smrg		rcDesk.left + (rc.right / 2),
2196747b715Smrg		rcDesk.top + (rc.bottom / 2),
22005b261ecSmrg		0, 0,
2216747b715Smrg		SWP_NOSIZE | SWP_FRAMECHANGED);
2226747b715Smrg  }
2236747b715Smrg
2246747b715Smrg#ifdef XWIN_MULTIWINDOW
2256747b715Smrg  if (g_hIconX) hIcon=g_hIconX;
2266747b715Smrg  else
2276747b715Smrg#endif
2286747b715Smrg  hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
2296747b715Smrg
2306747b715Smrg#ifdef XWIN_MULTIWINDOW
2316747b715Smrg  if (g_hSmallIconX) hIconSmall=g_hSmallIconX;
2326747b715Smrg  else
2336747b715Smrg#endif
2346747b715Smrg  hIconSmall = LoadImage (g_hInstance,
2356747b715Smrg                        MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
2366747b715Smrg                        GetSystemMetrics(SM_CXSMICON),
2376747b715Smrg                        GetSystemMetrics(SM_CYSMICON),
2386747b715Smrg                        LR_SHARED);
2396747b715Smrg
2406747b715Smrg  PostMessage (hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon);
2416747b715Smrg  PostMessage (hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall);
24205b261ecSmrg}
24305b261ecSmrg
24405b261ecSmrg
24505b261ecSmrg/*
24605b261ecSmrg * Display the Exit dialog box
24705b261ecSmrg */
24805b261ecSmrg
24905b261ecSmrgvoid
25005b261ecSmrgwinDisplayExitDialog (winPrivScreenPtr pScreenPriv)
25105b261ecSmrg{
25205b261ecSmrg  int i;
25305b261ecSmrg  int liveClients = 0;
25405b261ecSmrg
2556747b715Smrg  /* Count up running clients (clients[0] is serverClient) */
25605b261ecSmrg  for (i = 1; i < currentMaxClients; i++)
25705b261ecSmrg    if (clients[i] != NullClient)
25805b261ecSmrg      liveClients++;
25905b261ecSmrg#if defined(XWIN_MULTIWINDOW)
26005b261ecSmrg  /* Count down server internal clients */
26105b261ecSmrg  if (pScreenPriv->pScreenInfo->fMultiWindow)
26205b261ecSmrg    liveClients -= 2; /* multiwindow window manager & XMsgProc  */
26305b261ecSmrg#endif
26405b261ecSmrg#if defined(XWIN_CLIPBOARD)
26505b261ecSmrg  if (g_fClipboardStarted)
26605b261ecSmrg    liveClients--; /* clipboard manager */
26705b261ecSmrg#endif
26805b261ecSmrg
26905b261ecSmrg  /* A user reported that this sometimes drops below zero. just eye-candy. */
27005b261ecSmrg  if (liveClients < 0)
27105b261ecSmrg    liveClients = 0;
27205b261ecSmrg
2736747b715Smrg  /* Don't show the exit confirmation dialog if SilentExit & no clients,
2746747b715Smrg     or ForceExit, is enabled */
2756747b715Smrg  if ((pref.fSilentExit && liveClients <= 0) || pref.fForceExit)
27605b261ecSmrg    {
27705b261ecSmrg      if (g_hDlgExit != NULL)
27805b261ecSmrg	{
27905b261ecSmrg	  DestroyWindow (g_hDlgExit);
28005b261ecSmrg	  g_hDlgExit = NULL;
28105b261ecSmrg	}
28205b261ecSmrg      PostMessage (pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
28305b261ecSmrg      return;
28405b261ecSmrg    }
28505b261ecSmrg
28605b261ecSmrg  pScreenPriv->iConnectedClients = liveClients;
28705b261ecSmrg
28805b261ecSmrg  /* Check if dialog already exists */
28905b261ecSmrg  if (g_hDlgExit != NULL)
29005b261ecSmrg    {
29105b261ecSmrg      /* Dialog box already exists, display it */
29205b261ecSmrg      ShowWindow (g_hDlgExit, SW_SHOWDEFAULT);
29305b261ecSmrg
29405b261ecSmrg      /* User has lost the dialog.  Show them where it is. */
29505b261ecSmrg      SetForegroundWindow (g_hDlgExit);
29605b261ecSmrg
29705b261ecSmrg      return;
29805b261ecSmrg    }
29905b261ecSmrg
30005b261ecSmrg  /* Create dialog box */
30105b261ecSmrg  g_hDlgExit = CreateDialogParam (g_hInstance,
30205b261ecSmrg				  "EXIT_DIALOG",
30305b261ecSmrg				  pScreenPriv->hwndScreen,
30405b261ecSmrg				  winExitDlgProc,
30505b261ecSmrg				  (int) pScreenPriv);
30605b261ecSmrg
30705b261ecSmrg  /* Show the dialog box */
30805b261ecSmrg  ShowWindow (g_hDlgExit, SW_SHOW);
30905b261ecSmrg
31005b261ecSmrg  /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */
31105b261ecSmrg  SetForegroundWindow (g_hDlgExit);
31205b261ecSmrg
31305b261ecSmrg  /* Set focus to the Cancel button */
31405b261ecSmrg  PostMessage (g_hDlgExit, WM_NEXTDLGCTL,
3159ace9065Smrg	       (WPARAM)GetDlgItem (g_hDlgExit, IDCANCEL), TRUE);
31605b261ecSmrg}
31705b261ecSmrg
3186747b715Smrg#define CONNECTED_CLIENTS_FORMAT	"There %s currently %d client%s connected."
31905b261ecSmrg
32005b261ecSmrg
32105b261ecSmrg/*
32205b261ecSmrg * Exit dialog window procedure
32305b261ecSmrg */
32405b261ecSmrg
32505b261ecSmrgstatic wBOOL CALLBACK
32605b261ecSmrgwinExitDlgProc (HWND hDialog, UINT message,
32705b261ecSmrg		WPARAM wParam, LPARAM lParam)
32805b261ecSmrg{
32905b261ecSmrg  static winPrivScreenPtr	s_pScreenPriv = NULL;
33005b261ecSmrg
33105b261ecSmrg  /* Branch on message type */
33205b261ecSmrg  switch (message)
33305b261ecSmrg    {
33405b261ecSmrg    case WM_INITDIALOG:
33505b261ecSmrg      {
33605b261ecSmrg	char			*pszConnectedClients;
33705b261ecSmrg
33805b261ecSmrg	/* Store pointers to private structures for future use */
33905b261ecSmrg	s_pScreenPriv = (winPrivScreenPtr) lParam;
34005b261ecSmrg
3416747b715Smrg	winInitDialog (hDialog);
34205b261ecSmrg
34305b261ecSmrg	/* Format the connected clients string */
3449ace9065Smrg	if (asprintf (&pszConnectedClients, CONNECTED_CLIENTS_FORMAT,
3456747b715Smrg           (s_pScreenPriv->iConnectedClients == 1) ? "is" : "are",
3466747b715Smrg            s_pScreenPriv->iConnectedClients,
3479ace9065Smrg           (s_pScreenPriv->iConnectedClients == 1) ? "" : "s") == -1)
34805b261ecSmrg	    return TRUE;
34905b261ecSmrg
35005b261ecSmrg
35105b261ecSmrg
35205b261ecSmrg	/* Set the number of connected clients */
35305b261ecSmrg	SetWindowText (GetDlgItem (hDialog, IDC_CLIENTS_CONNECTED),
35405b261ecSmrg		       pszConnectedClients);
3556747b715Smrg	free(pszConnectedClients);
35605b261ecSmrg      }
35705b261ecSmrg      return TRUE;
35805b261ecSmrg
35905b261ecSmrg    case WM_COMMAND:
36005b261ecSmrg      switch (LOWORD (wParam))
36105b261ecSmrg	{
36205b261ecSmrg	case IDOK:
36305b261ecSmrg	  /* Send message to call the GiveUp function */
36405b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
36505b261ecSmrg	  DestroyWindow (g_hDlgExit);
36605b261ecSmrg	  g_hDlgExit = NULL;
36705b261ecSmrg
36805b261ecSmrg	  /* Fix to make sure keyboard focus isn't trapped */
36905b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
37005b261ecSmrg	  return TRUE;
37105b261ecSmrg
37205b261ecSmrg	case IDCANCEL:
37305b261ecSmrg	  DestroyWindow (g_hDlgExit);
37405b261ecSmrg	  g_hDlgExit = NULL;
37505b261ecSmrg
37605b261ecSmrg	  /* Fix to make sure keyboard focus isn't trapped */
37705b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
37805b261ecSmrg	  return TRUE;
37905b261ecSmrg	}
38005b261ecSmrg      break;
38105b261ecSmrg
38205b261ecSmrg    case WM_MOUSEMOVE:
38305b261ecSmrg    case WM_NCMOUSEMOVE:
38405b261ecSmrg      /* Show the cursor if it is hidden */
38505b261ecSmrg      if (g_fSoftwareCursor && !g_fCursor)
38605b261ecSmrg	{
38705b261ecSmrg	  g_fCursor = TRUE;
38805b261ecSmrg	  ShowCursor (TRUE);
38905b261ecSmrg	}
39005b261ecSmrg      return TRUE;
39105b261ecSmrg
39205b261ecSmrg    case WM_CLOSE:
39305b261ecSmrg      DestroyWindow (g_hDlgExit);
39405b261ecSmrg      g_hDlgExit = NULL;
39505b261ecSmrg
39605b261ecSmrg      /* Fix to make sure keyboard focus isn't trapped */
39705b261ecSmrg      PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
39805b261ecSmrg      return TRUE;
39905b261ecSmrg    }
40005b261ecSmrg
40105b261ecSmrg  return FALSE;
40205b261ecSmrg}
40305b261ecSmrg
40405b261ecSmrg
40505b261ecSmrg/*
40605b261ecSmrg * Display the Depth Change dialog box
40705b261ecSmrg */
40805b261ecSmrg
40905b261ecSmrgvoid
41005b261ecSmrgwinDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv)
41105b261ecSmrg{
41205b261ecSmrg  /* Check if dialog already exists */
41305b261ecSmrg  if (g_hDlgDepthChange != NULL)
41405b261ecSmrg    {
41505b261ecSmrg      /* Dialog box already exists, display it */
41605b261ecSmrg      ShowWindow (g_hDlgDepthChange, SW_SHOWDEFAULT);
41705b261ecSmrg
41805b261ecSmrg      /* User has lost the dialog.  Show them where it is. */
41905b261ecSmrg      SetForegroundWindow (g_hDlgDepthChange);
42005b261ecSmrg
42105b261ecSmrg      return;
42205b261ecSmrg    }
42305b261ecSmrg
42405b261ecSmrg  /*
42505b261ecSmrg   * Display a notification to the user that the visual
42605b261ecSmrg   * will not be displayed until the Windows display depth
42705b261ecSmrg   * is restored to the original value.
42805b261ecSmrg   */
42905b261ecSmrg  g_hDlgDepthChange = CreateDialogParam (g_hInstance,
43005b261ecSmrg					 "DEPTH_CHANGE_BOX",
43105b261ecSmrg					 pScreenPriv->hwndScreen,
43205b261ecSmrg					 winChangeDepthDlgProc,
43305b261ecSmrg					 (int) pScreenPriv);
43405b261ecSmrg  /* Show the dialog box */
43505b261ecSmrg  ShowWindow (g_hDlgDepthChange, SW_SHOW);
43605b261ecSmrg
43705b261ecSmrg  ErrorF ("winDisplayDepthChangeDialog - DialogBox returned: %d\n",
43805b261ecSmrg	  (int) g_hDlgDepthChange);
43905b261ecSmrg  ErrorF ("winDisplayDepthChangeDialog - GetLastError: %d\n",
44005b261ecSmrg	  (int) GetLastError ());
44105b261ecSmrg
44205b261ecSmrg  /* Minimize the display window */
44305b261ecSmrg  ShowWindow (pScreenPriv->hwndScreen, SW_MINIMIZE);
44405b261ecSmrg}
44505b261ecSmrg
44605b261ecSmrg
44705b261ecSmrg/*
44805b261ecSmrg * Process messages for the dialog that is displayed for
44905b261ecSmrg * disruptive screen depth changes.
45005b261ecSmrg */
45105b261ecSmrg
45205b261ecSmrgstatic wBOOL CALLBACK
45305b261ecSmrgwinChangeDepthDlgProc (HWND hwndDialog, UINT message,
45405b261ecSmrg		       WPARAM wParam, LPARAM lParam)
45505b261ecSmrg{
45605b261ecSmrg  static winPrivScreenPtr	s_pScreenPriv = NULL;
45705b261ecSmrg  static winScreenInfo		*s_pScreenInfo = NULL;
45805b261ecSmrg  static ScreenPtr		s_pScreen = NULL;
45905b261ecSmrg
46005b261ecSmrg#if CYGDEBUG
46105b261ecSmrg  winDebug ("winChangeDepthDlgProc\n");
46205b261ecSmrg#endif
46305b261ecSmrg
46405b261ecSmrg  /* Branch on message type */
46505b261ecSmrg  switch (message)
46605b261ecSmrg    {
46705b261ecSmrg    case WM_INITDIALOG:
46805b261ecSmrg#if CYGDEBUG
46905b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_INITDIALOG\n");
47005b261ecSmrg#endif
47105b261ecSmrg
47205b261ecSmrg      /* Store pointers to private structures for future use */
47305b261ecSmrg      s_pScreenPriv = (winPrivScreenPtr) lParam;
47405b261ecSmrg      s_pScreenInfo = s_pScreenPriv->pScreenInfo;
47505b261ecSmrg      s_pScreen = s_pScreenInfo->pScreen;
47605b261ecSmrg
47705b261ecSmrg#if CYGDEBUG
47805b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - s_pScreenPriv: %08x, "
47905b261ecSmrg	      "s_pScreenInfo: %08x, s_pScreen: %08x\n",
48005b261ecSmrg	      s_pScreenPriv, s_pScreenInfo, s_pScreen);
48105b261ecSmrg#endif
48205b261ecSmrg
48305b261ecSmrg#if CYGDEBUG
48405b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - orig bpp: %d, "
4859ace9065Smrg	      "current bpp: %d\n",
48605b261ecSmrg	      s_pScreenInfo->dwBPP,
4879ace9065Smrg              GetDeviceCaps(s_pScreenPriv->hdcScreen, BITSPIXEL));
48805b261ecSmrg#endif
4899ace9065Smrg
4906747b715Smrg      winInitDialog( hwndDialog );
49105b261ecSmrg
49205b261ecSmrg      return TRUE;
49305b261ecSmrg
49405b261ecSmrg    case WM_DISPLAYCHANGE:
49505b261ecSmrg#if CYGDEBUG
49605b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %d, "
4979ace9065Smrg	      "new bpp: %d\n",
49805b261ecSmrg	      s_pScreenInfo->dwBPP,
4999ace9065Smrg              GetDeviceCaps(s_pScreenPriv->hdcScreen, BITSPIXEL));
50005b261ecSmrg#endif
50105b261ecSmrg
50205b261ecSmrg      /* Dismiss the dialog if the display returns to the original depth */
5039ace9065Smrg      if (GetDeviceCaps(s_pScreenPriv->hdcScreen, BITSPIXEL) == s_pScreenInfo->dwBPP)
50405b261ecSmrg	{
50505b261ecSmrg	  ErrorF ("winChangeDelthDlgProc - wParam == s_pScreenInfo->dwBPP\n");
50605b261ecSmrg
50705b261ecSmrg	  /* Depth has been restored, dismiss dialog */
50805b261ecSmrg	  DestroyWindow (g_hDlgDepthChange);
50905b261ecSmrg	  g_hDlgDepthChange = NULL;
51005b261ecSmrg
51105b261ecSmrg	  /* Flag that we have a valid screen depth */
51205b261ecSmrg	  s_pScreenPriv->fBadDepth = FALSE;
51305b261ecSmrg	}
51405b261ecSmrg      return TRUE;
51505b261ecSmrg
51605b261ecSmrg    case WM_COMMAND:
51705b261ecSmrg      switch (LOWORD (wParam))
51805b261ecSmrg	{
51905b261ecSmrg	case IDOK:
52005b261ecSmrg	case IDCANCEL:
52105b261ecSmrg	  ErrorF ("winChangeDepthDlgProc - WM_COMMAND - IDOK or IDCANCEL\n");
52205b261ecSmrg
52305b261ecSmrg	  /*
52405b261ecSmrg	   * User dismissed the dialog, hide it until the
52505b261ecSmrg	   * display mode is restored.
52605b261ecSmrg	   */
52705b261ecSmrg	  ShowWindow (g_hDlgDepthChange, SW_HIDE);
52805b261ecSmrg	  return TRUE;
52905b261ecSmrg	}
53005b261ecSmrg      break;
53105b261ecSmrg
53205b261ecSmrg    case WM_CLOSE:
53305b261ecSmrg      ErrorF ("winChangeDepthDlgProc - WM_CLOSE\n");
53405b261ecSmrg
53505b261ecSmrg      DestroyWindow (g_hDlgAbout);
53605b261ecSmrg      g_hDlgAbout = NULL;
53705b261ecSmrg
53805b261ecSmrg      /* Fix to make sure keyboard focus isn't trapped */
53905b261ecSmrg      PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
54005b261ecSmrg      return TRUE;
54105b261ecSmrg    }
54205b261ecSmrg
54305b261ecSmrg  return FALSE;
54405b261ecSmrg}
54505b261ecSmrg
54605b261ecSmrg
54705b261ecSmrg/*
54805b261ecSmrg * Display the About dialog box
54905b261ecSmrg */
55005b261ecSmrg
55105b261ecSmrgvoid
55205b261ecSmrgwinDisplayAboutDialog (winPrivScreenPtr pScreenPriv)
55305b261ecSmrg{
55405b261ecSmrg  /* Check if dialog already exists */
55505b261ecSmrg  if (g_hDlgAbout != NULL)
55605b261ecSmrg    {
55705b261ecSmrg      /* Dialog box already exists, display it */
55805b261ecSmrg      ShowWindow (g_hDlgAbout, SW_SHOWDEFAULT);
55905b261ecSmrg
56005b261ecSmrg      /* User has lost the dialog.  Show them where it is. */
56105b261ecSmrg      SetForegroundWindow (g_hDlgAbout);
56205b261ecSmrg
56305b261ecSmrg      return;
56405b261ecSmrg    }
56505b261ecSmrg
56605b261ecSmrg  /*
56705b261ecSmrg   * Display the about box
56805b261ecSmrg   */
56905b261ecSmrg  g_hDlgAbout = CreateDialogParam (g_hInstance,
57005b261ecSmrg				   "ABOUT_BOX",
57105b261ecSmrg				   pScreenPriv->hwndScreen,
57205b261ecSmrg				   winAboutDlgProc,
57305b261ecSmrg				   (int) pScreenPriv);
57405b261ecSmrg
57505b261ecSmrg  /* Show the dialog box */
57605b261ecSmrg  ShowWindow (g_hDlgAbout, SW_SHOW);
57705b261ecSmrg
57805b261ecSmrg  /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */
57905b261ecSmrg  SetForegroundWindow (g_hDlgAbout);
58005b261ecSmrg
58105b261ecSmrg  /* Set focus to the OK button */
58205b261ecSmrg  PostMessage (g_hDlgAbout, WM_NEXTDLGCTL,
5839ace9065Smrg	       (WPARAM)GetDlgItem (g_hDlgAbout, IDOK), TRUE);
58405b261ecSmrg}
58505b261ecSmrg
58605b261ecSmrg
58705b261ecSmrg/*
58805b261ecSmrg * Process messages for the about dialog.
58905b261ecSmrg */
59005b261ecSmrg
59105b261ecSmrgstatic wBOOL CALLBACK
59205b261ecSmrgwinAboutDlgProc (HWND hwndDialog, UINT message,
59305b261ecSmrg		 WPARAM wParam, LPARAM lParam)
59405b261ecSmrg{
59505b261ecSmrg  static winPrivScreenPtr	s_pScreenPriv = NULL;
59605b261ecSmrg  static winScreenInfo		*s_pScreenInfo = NULL;
59705b261ecSmrg  static ScreenPtr		s_pScreen = NULL;
59805b261ecSmrg
59905b261ecSmrg#if CYGDEBUG
60005b261ecSmrg  winDebug ("winAboutDlgProc\n");
60105b261ecSmrg#endif
60205b261ecSmrg
60305b261ecSmrg  /* Branch on message type */
60405b261ecSmrg  switch (message)
60505b261ecSmrg    {
60605b261ecSmrg    case WM_INITDIALOG:
60705b261ecSmrg#if CYGDEBUG
60805b261ecSmrg      winDebug ("winAboutDlgProc - WM_INITDIALOG\n");
60905b261ecSmrg#endif
61005b261ecSmrg
61105b261ecSmrg      /* Store pointers to private structures for future use */
61205b261ecSmrg      s_pScreenPriv = (winPrivScreenPtr) lParam;
61305b261ecSmrg      s_pScreenInfo = s_pScreenPriv->pScreenInfo;
61405b261ecSmrg      s_pScreen = s_pScreenInfo->pScreen;
61505b261ecSmrg
6166747b715Smrg      winInitDialog (hwndDialog);
61705b261ecSmrg
61805b261ecSmrg      /* Override the URL buttons */
61905b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
62005b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
62105b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_UG);
62205b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
62305b261ecSmrg
62405b261ecSmrg      return TRUE;
62505b261ecSmrg
62605b261ecSmrg    case WM_DRAWITEM:
62705b261ecSmrg      /* Draw the URL buttons as needed */
62805b261ecSmrg      winDrawURLWindow (lParam);
62905b261ecSmrg      return TRUE;
63005b261ecSmrg
63105b261ecSmrg    case WM_MOUSEMOVE:
63205b261ecSmrg    case WM_NCMOUSEMOVE:
63305b261ecSmrg      /* Show the cursor if it is hidden */
63405b261ecSmrg      if (g_fSoftwareCursor && !g_fCursor)
63505b261ecSmrg	{
63605b261ecSmrg	  g_fCursor = TRUE;
63705b261ecSmrg	  ShowCursor (TRUE);
63805b261ecSmrg	}
63905b261ecSmrg      return TRUE;
64005b261ecSmrg
64105b261ecSmrg    case WM_COMMAND:
64205b261ecSmrg      switch (LOWORD (wParam))
64305b261ecSmrg	{
64405b261ecSmrg	case IDOK:
64505b261ecSmrg	case IDCANCEL:
64605b261ecSmrg	  ErrorF ("winAboutDlgProc - WM_COMMAND - IDOK or IDCANCEL\n");
64705b261ecSmrg
64805b261ecSmrg	  DestroyWindow (g_hDlgAbout);
64905b261ecSmrg	  g_hDlgAbout = NULL;
65005b261ecSmrg
65105b261ecSmrg	  /* Fix to make sure keyboard focus isn't trapped */
65205b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
65305b261ecSmrg
65405b261ecSmrg	  /* Restore window procedures for URL buttons */
65505b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
65605b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
65705b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG);
65805b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
65905b261ecSmrg
66005b261ecSmrg	  return TRUE;
66105b261ecSmrg
66205b261ecSmrg	case ID_ABOUT_CHANGELOG:
66305b261ecSmrg	  {
6649ace9065Smrg	    int iReturn;
66505b261ecSmrg#ifdef __CYGWIN__
66605b261ecSmrg	    const char *	pszCygPath = "/usr/X11R6/share/doc/"
66705b261ecSmrg	      "xorg-x11-xwin/changelog.html";
66805b261ecSmrg	    char		pszWinPath[MAX_PATH + 1];
66905b261ecSmrg
67005b261ecSmrg	    /* Convert the POSIX path to a Win32 path */
67105b261ecSmrg	    cygwin_conv_to_win32_path (pszCygPath, pszWinPath);
67205b261ecSmrg#else
67305b261ecSmrg	    const char *	pszWinPath = "http://x.cygwin.com/"
67405b261ecSmrg		    "devel/server/changelog.html";
67505b261ecSmrg#endif
67605b261ecSmrg
6779ace9065Smrg	    iReturn = (int)ShellExecute (NULL,
6786747b715Smrg                                    "open",
6796747b715Smrg                                    pszWinPath,
6806747b715Smrg                                    NULL,
6816747b715Smrg                                    NULL,
6826747b715Smrg                                    SW_MAXIMIZE);
68305b261ecSmrg	    if (iReturn < 32)
68405b261ecSmrg	      {
68505b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_CHANGELOG - "
68605b261ecSmrg			"ShellExecute failed: %d\n",
68705b261ecSmrg			iReturn);
68805b261ecSmrg	      }
68905b261ecSmrg	  }
69005b261ecSmrg	  return TRUE;
69105b261ecSmrg
69205b261ecSmrg	case ID_ABOUT_WEBSITE:
69305b261ecSmrg	  {
6946747b715Smrg	    const char *	pszPath = __VENDORDWEBSUPPORT__;
69505b261ecSmrg	    int			iReturn;
69605b261ecSmrg
6979ace9065Smrg	    iReturn = (int)ShellExecute (NULL,
6986747b715Smrg                                    "open",
6996747b715Smrg                                    pszPath,
7006747b715Smrg                                    NULL,
7016747b715Smrg                                    NULL,
7026747b715Smrg                                    SW_MAXIMIZE);
70305b261ecSmrg	    if (iReturn < 32)
70405b261ecSmrg	      {
70505b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_WEBSITE - "
70605b261ecSmrg			"ShellExecute failed: %d\n",
70705b261ecSmrg			iReturn);
70805b261ecSmrg	      }
70905b261ecSmrg	  }
71005b261ecSmrg	  return TRUE;
71105b261ecSmrg
71205b261ecSmrg	case ID_ABOUT_UG:
71305b261ecSmrg	  {
71405b261ecSmrg	    const char *	pszPath = "http://x.cygwin.com/docs/ug/";
71505b261ecSmrg	    int			iReturn;
71605b261ecSmrg
7179ace9065Smrg	    iReturn = (int)ShellExecute (NULL,
7186747b715Smrg                                    "open",
7196747b715Smrg                                    pszPath,
7206747b715Smrg                                    NULL,
7216747b715Smrg                                    NULL,
7226747b715Smrg                                    SW_MAXIMIZE);
72305b261ecSmrg	    if (iReturn < 32)
72405b261ecSmrg	      {
72505b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_UG - "
72605b261ecSmrg			"ShellExecute failed: %d\n",
72705b261ecSmrg			iReturn);
72805b261ecSmrg	      }
72905b261ecSmrg	  }
73005b261ecSmrg	  return TRUE;
73105b261ecSmrg
73205b261ecSmrg	case ID_ABOUT_FAQ:
73305b261ecSmrg	  {
73405b261ecSmrg	    const char *	pszPath = "http://x.cygwin.com/docs/faq/";
73505b261ecSmrg	    int			iReturn;
73605b261ecSmrg
7379ace9065Smrg	    iReturn = (int)ShellExecute (NULL,
7386747b715Smrg                                    "open",
7396747b715Smrg                                    pszPath,
7406747b715Smrg                                    NULL,
7416747b715Smrg                                    NULL,
7426747b715Smrg                                    SW_MAXIMIZE);
74305b261ecSmrg	    if (iReturn < 32)
74405b261ecSmrg	      {
74505b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_FAQ - "
74605b261ecSmrg			"ShellExecute failed: %d\n",
74705b261ecSmrg			iReturn);
74805b261ecSmrg	      }
74905b261ecSmrg	  }
75005b261ecSmrg	  return TRUE;
75105b261ecSmrg	}
75205b261ecSmrg      break;
75305b261ecSmrg
75405b261ecSmrg    case WM_CLOSE:
75505b261ecSmrg      ErrorF ("winAboutDlgProc - WM_CLOSE\n");
75605b261ecSmrg
75705b261ecSmrg      DestroyWindow (g_hDlgAbout);
75805b261ecSmrg      g_hDlgAbout = NULL;
75905b261ecSmrg
76005b261ecSmrg      /* Fix to make sure keyboard focus isn't trapped */
76105b261ecSmrg      PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
76205b261ecSmrg
76305b261ecSmrg      /* Restore window procedures for URL buttons */
76405b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
76505b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
76605b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG);
76705b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
76805b261ecSmrg
76905b261ecSmrg      return TRUE;
77005b261ecSmrg    }
77105b261ecSmrg
77205b261ecSmrg  return FALSE;
77305b261ecSmrg}
774