windialogs.c revision 05b261ec
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
4705b261ecSmrgextern Bool			g_fCursor;
4805b261ecSmrgextern HWND			g_hDlgDepthChange;
4905b261ecSmrgextern HWND			g_hDlgExit;
5005b261ecSmrgextern HWND			g_hDlgAbout;
5105b261ecSmrgextern WINPREFS			pref;
5205b261ecSmrg#ifdef XWIN_CLIPBOARD
5305b261ecSmrgextern Bool			g_fClipboardStarted;
5405b261ecSmrg#endif
5505b261ecSmrgextern Bool			g_fSoftwareCursor;
5605b261ecSmrg
5705b261ecSmrg
5805b261ecSmrg/*
5905b261ecSmrg * Local function prototypes
6005b261ecSmrg */
6105b261ecSmrg
6205b261ecSmrgstatic wBOOL CALLBACK
6305b261ecSmrgwinExitDlgProc (HWND hDialog, UINT message,
6405b261ecSmrg		WPARAM wParam, LPARAM lParam);
6505b261ecSmrg
6605b261ecSmrgstatic wBOOL CALLBACK
6705b261ecSmrgwinChangeDepthDlgProc (HWND hDialog, UINT message,
6805b261ecSmrg		       WPARAM wParam, LPARAM lParam);
6905b261ecSmrg
7005b261ecSmrgstatic wBOOL CALLBACK
7105b261ecSmrgwinAboutDlgProc (HWND hDialog, UINT message,
7205b261ecSmrg		 WPARAM wParam, LPARAM lParam);
7305b261ecSmrg
7405b261ecSmrg
7505b261ecSmrgstatic void
7605b261ecSmrgwinDrawURLWindow (LPARAM lParam);
7705b261ecSmrg
7805b261ecSmrgstatic LRESULT CALLBACK
7905b261ecSmrgwinURLWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
8005b261ecSmrg
8105b261ecSmrgstatic void
8205b261ecSmrgwinOverrideURLButton (HWND hdlg, int id);
8305b261ecSmrg
8405b261ecSmrgstatic void
8505b261ecSmrgwinUnoverrideURLButton (HWND hdlg, int id);
8605b261ecSmrg
8705b261ecSmrg
8805b261ecSmrg/*
8905b261ecSmrg * Owner-draw a button as a URL
9005b261ecSmrg */
9105b261ecSmrg
9205b261ecSmrgstatic void
9305b261ecSmrgwinDrawURLWindow (LPARAM lParam)
9405b261ecSmrg{
9505b261ecSmrg  DRAWITEMSTRUCT *draw;
9605b261ecSmrg  char str[256];
9705b261ecSmrg  RECT rect;
9805b261ecSmrg  HFONT font;
9905b261ecSmrg  COLORREF crText;
10005b261ecSmrg
10105b261ecSmrg  draw = (DRAWITEMSTRUCT *) lParam;
10205b261ecSmrg  GetWindowText (draw->hwndItem, str, sizeof(str));
10305b261ecSmrg  str[255] = 0;
10405b261ecSmrg  GetClientRect (draw->hwndItem, &rect);
10505b261ecSmrg
10605b261ecSmrg  /* Color the button depending upon its state */
10705b261ecSmrg  if (draw->itemState & ODS_SELECTED)
10805b261ecSmrg    crText = RGB(128+64,0,0);
10905b261ecSmrg  else if (draw->itemState & ODS_FOCUS)
11005b261ecSmrg    crText = RGB(0,128+64,0);
11105b261ecSmrg  else
11205b261ecSmrg    crText = RGB(0,0,128+64);
11305b261ecSmrg  SetTextColor (draw->hDC, crText);
11405b261ecSmrg
11505b261ecSmrg  /* Create underlined font 14 high, standard dialog font */
11605b261ecSmrg  font = CreateFont (-14, 0, 0, 0, FW_NORMAL, FALSE, TRUE, FALSE,
11705b261ecSmrg		     0, 0, 0, 0, 0, "MS Sans Serif");
11805b261ecSmrg  if (!font)
11905b261ecSmrg    {
12005b261ecSmrg      ErrorF ("winDrawURLWindow: Unable to create URL font, bailing.\n");
12105b261ecSmrg      return;
12205b261ecSmrg    }
12305b261ecSmrg  /* Draw it */
12405b261ecSmrg  SetBkMode (draw->hDC, OPAQUE);
12505b261ecSmrg  SelectObject (draw->hDC, font);
12605b261ecSmrg  DrawText (draw->hDC, str, strlen (str),&rect,DT_CENTER | DT_VCENTER);
12705b261ecSmrg  /* Delete the created font, replace it with stock font */
12805b261ecSmrg  DeleteObject (SelectObject (draw->hDC, GetStockObject (ANSI_VAR_FONT)));
12905b261ecSmrg}
13005b261ecSmrg
13105b261ecSmrg
13205b261ecSmrg/*
13305b261ecSmrg * WndProc for overridden buttons
13405b261ecSmrg */
13505b261ecSmrg
13605b261ecSmrgstatic LRESULT CALLBACK
13705b261ecSmrgwinURLWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
13805b261ecSmrg{
13905b261ecSmrg  WNDPROC origCB = NULL;
14005b261ecSmrg  HCURSOR cursor;
14105b261ecSmrg
14205b261ecSmrg  /* If it's a SetCursor message, tell it to the hand */
14305b261ecSmrg  if (msg==WM_SETCURSOR) {
14405b261ecSmrg    cursor = LoadCursor (NULL, IDC_HAND);
14505b261ecSmrg    if (cursor)
14605b261ecSmrg      SetCursor (cursor);
14705b261ecSmrg    return TRUE;
14805b261ecSmrg  }
14905b261ecSmrg  origCB = (WNDPROC)GetWindowLong (hwnd, GWL_USERDATA);
15005b261ecSmrg  /* Otherwise fall through to original WndProc */
15105b261ecSmrg  if (origCB)
15205b261ecSmrg    return CallWindowProc (origCB, hwnd, msg, wParam, lParam);
15305b261ecSmrg  else
15405b261ecSmrg    return FALSE;
15505b261ecSmrg}
15605b261ecSmrg
15705b261ecSmrg
15805b261ecSmrg/*
15905b261ecSmrg * Register and unregister the custom WndProc
16005b261ecSmrg */
16105b261ecSmrg
16205b261ecSmrgstatic void
16305b261ecSmrgwinOverrideURLButton (HWND hwnd, int id)
16405b261ecSmrg{
16505b261ecSmrg  WNDPROC origCB;
16605b261ecSmrg  origCB = (WNDPROC)SetWindowLong (GetDlgItem (hwnd, id),
16705b261ecSmrg				   GWL_WNDPROC, (LONG)winURLWndProc);
16805b261ecSmrg  SetWindowLong (GetDlgItem (hwnd, id), GWL_USERDATA, (LONG)origCB);
16905b261ecSmrg}
17005b261ecSmrg
17105b261ecSmrgstatic void
17205b261ecSmrgwinUnoverrideURLButton (HWND hwnd, int id)
17305b261ecSmrg{
17405b261ecSmrg  WNDPROC origCB;
17505b261ecSmrg  origCB = (WNDPROC)SetWindowLong (GetDlgItem (hwnd, id),
17605b261ecSmrg				   GWL_USERDATA, 0);
17705b261ecSmrg  if (origCB)
17805b261ecSmrg    SetWindowLong (GetDlgItem (hwnd, id), GWL_WNDPROC, (LONG)origCB);
17905b261ecSmrg}
18005b261ecSmrg
18105b261ecSmrg
18205b261ecSmrg/*
18305b261ecSmrg * Center a dialog window in the desktop window
18405b261ecSmrg */
18505b261ecSmrg
18605b261ecSmrgstatic void
18705b261ecSmrgwinCenterDialog (HWND hwndDlg)
18805b261ecSmrg{
18905b261ecSmrg  HWND hwndDesk;
19005b261ecSmrg  RECT rc, rcDlg, rcDesk;
19105b261ecSmrg
19205b261ecSmrg  hwndDesk = GetParent (hwndDlg);
19305b261ecSmrg  if (!hwndDesk || IsIconic (hwndDesk))
19405b261ecSmrg    hwndDesk = GetDesktopWindow ();
19505b261ecSmrg
19605b261ecSmrg  GetWindowRect (hwndDesk, &rcDesk);
19705b261ecSmrg  GetWindowRect (hwndDlg, &rcDlg);
19805b261ecSmrg  CopyRect (&rc, &rcDesk);
19905b261ecSmrg
20005b261ecSmrg  OffsetRect (&rcDlg, -rcDlg.left, -rcDlg.top);
20105b261ecSmrg  OffsetRect (&rc, -rc.left, -rc.top);
20205b261ecSmrg  OffsetRect (&rc, -rcDlg.right, -rcDlg.bottom);
20305b261ecSmrg
20405b261ecSmrg  SetWindowPos (hwndDlg,
20505b261ecSmrg		HWND_TOP,
20605b261ecSmrg		rcDesk.left + (rc.right / 2),
20705b261ecSmrg		rcDesk.top + (rc.bottom / 2),
20805b261ecSmrg		0, 0,
20905b261ecSmrg		SWP_NOSIZE | SWP_NOZORDER);
21005b261ecSmrg}
21105b261ecSmrg
21205b261ecSmrg
21305b261ecSmrg/*
21405b261ecSmrg * Display the Exit dialog box
21505b261ecSmrg */
21605b261ecSmrg
21705b261ecSmrgvoid
21805b261ecSmrgwinDisplayExitDialog (winPrivScreenPtr pScreenPriv)
21905b261ecSmrg{
22005b261ecSmrg  int i;
22105b261ecSmrg  int liveClients = 0;
22205b261ecSmrg
22305b261ecSmrg  /* Count up running clinets (clients[0] is serverClient) */
22405b261ecSmrg  for (i = 1; i < currentMaxClients; i++)
22505b261ecSmrg    if (clients[i] != NullClient)
22605b261ecSmrg      liveClients++;
22705b261ecSmrg#if defined(XWIN_MULTIWINDOW)
22805b261ecSmrg  /* Count down server internal clients */
22905b261ecSmrg  if (pScreenPriv->pScreenInfo->fMultiWindow)
23005b261ecSmrg    liveClients -= 2; /* multiwindow window manager & XMsgProc  */
23105b261ecSmrg#endif
23205b261ecSmrg#if defined(XWIN_CLIPBOARD)
23305b261ecSmrg  if (g_fClipboardStarted)
23405b261ecSmrg    liveClients--; /* clipboard manager */
23505b261ecSmrg#endif
23605b261ecSmrg
23705b261ecSmrg  /* A user reported that this sometimes drops below zero. just eye-candy. */
23805b261ecSmrg  if (liveClients < 0)
23905b261ecSmrg    liveClients = 0;
24005b261ecSmrg
24105b261ecSmrg  /* Don't show the exit confirmation dialog if SilentExit is enabled */
24205b261ecSmrg  if (pref.fSilentExit && liveClients <= 0)
24305b261ecSmrg    {
24405b261ecSmrg      if (g_hDlgExit != NULL)
24505b261ecSmrg	{
24605b261ecSmrg	  DestroyWindow (g_hDlgExit);
24705b261ecSmrg	  g_hDlgExit = NULL;
24805b261ecSmrg	}
24905b261ecSmrg      PostMessage (pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
25005b261ecSmrg      return;
25105b261ecSmrg    }
25205b261ecSmrg
25305b261ecSmrg  pScreenPriv->iConnectedClients = liveClients;
25405b261ecSmrg
25505b261ecSmrg  /* Check if dialog already exists */
25605b261ecSmrg  if (g_hDlgExit != NULL)
25705b261ecSmrg    {
25805b261ecSmrg      /* Dialog box already exists, display it */
25905b261ecSmrg      ShowWindow (g_hDlgExit, SW_SHOWDEFAULT);
26005b261ecSmrg
26105b261ecSmrg      /* User has lost the dialog.  Show them where it is. */
26205b261ecSmrg      SetForegroundWindow (g_hDlgExit);
26305b261ecSmrg
26405b261ecSmrg      return;
26505b261ecSmrg    }
26605b261ecSmrg
26705b261ecSmrg  /* Create dialog box */
26805b261ecSmrg  g_hDlgExit = CreateDialogParam (g_hInstance,
26905b261ecSmrg				  "EXIT_DIALOG",
27005b261ecSmrg				  pScreenPriv->hwndScreen,
27105b261ecSmrg				  winExitDlgProc,
27205b261ecSmrg				  (int) pScreenPriv);
27305b261ecSmrg
27405b261ecSmrg  /* Drop minimize and maximize buttons */
27505b261ecSmrg  SetWindowLong (g_hDlgExit, GWL_STYLE,
27605b261ecSmrg		 GetWindowLong (g_hDlgExit, GWL_STYLE)
27705b261ecSmrg		 & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
27805b261ecSmrg  SetWindowLong (g_hDlgExit, GWL_EXSTYLE,
27905b261ecSmrg		 GetWindowLong (g_hDlgExit, GWL_EXSTYLE) & ~WS_EX_APPWINDOW );
28005b261ecSmrg  SetWindowPos (g_hDlgExit, HWND_TOPMOST, 0, 0, 0, 0,
28105b261ecSmrg		SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
28205b261ecSmrg
28305b261ecSmrg  /* Show the dialog box */
28405b261ecSmrg  ShowWindow (g_hDlgExit, SW_SHOW);
28505b261ecSmrg
28605b261ecSmrg  /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */
28705b261ecSmrg  SetForegroundWindow (g_hDlgExit);
28805b261ecSmrg
28905b261ecSmrg  /* Set focus to the Cancel button */
29005b261ecSmrg  PostMessage (g_hDlgExit, WM_NEXTDLGCTL,
29105b261ecSmrg	       (int) GetDlgItem (g_hDlgExit, IDCANCEL), TRUE);
29205b261ecSmrg}
29305b261ecSmrg
29405b261ecSmrg#define CONNECTED_CLIENTS_FORMAT	"There are currently %d clients connected."
29505b261ecSmrg
29605b261ecSmrg
29705b261ecSmrg/*
29805b261ecSmrg * Exit dialog window procedure
29905b261ecSmrg */
30005b261ecSmrg
30105b261ecSmrgstatic wBOOL CALLBACK
30205b261ecSmrgwinExitDlgProc (HWND hDialog, UINT message,
30305b261ecSmrg		WPARAM wParam, LPARAM lParam)
30405b261ecSmrg{
30505b261ecSmrg  static winPrivScreenPtr	s_pScreenPriv = NULL;
30605b261ecSmrg
30705b261ecSmrg  /* Branch on message type */
30805b261ecSmrg  switch (message)
30905b261ecSmrg    {
31005b261ecSmrg    case WM_INITDIALOG:
31105b261ecSmrg      {
31205b261ecSmrg	char			*pszConnectedClients;
31305b261ecSmrg
31405b261ecSmrg	/* Store pointers to private structures for future use */
31505b261ecSmrg	s_pScreenPriv = (winPrivScreenPtr) lParam;
31605b261ecSmrg
31705b261ecSmrg	winCenterDialog (hDialog);
31805b261ecSmrg
31905b261ecSmrg	/* Set icon to standard app icon */
32005b261ecSmrg	PostMessage (hDialog,
32105b261ecSmrg		     WM_SETICON,
32205b261ecSmrg		     ICON_SMALL,
32305b261ecSmrg		     (LPARAM) LoadIcon (g_hInstance,
32405b261ecSmrg					MAKEINTRESOURCE(IDI_XWIN)));
32505b261ecSmrg
32605b261ecSmrg	/* Format the connected clients string */
32705b261ecSmrg	pszConnectedClients = Xprintf (CONNECTED_CLIENTS_FORMAT,
32805b261ecSmrg            s_pScreenPriv->iConnectedClients);
32905b261ecSmrg	if (!pszConnectedClients)
33005b261ecSmrg	    return TRUE;
33105b261ecSmrg
33205b261ecSmrg
33305b261ecSmrg
33405b261ecSmrg	/* Set the number of connected clients */
33505b261ecSmrg	SetWindowText (GetDlgItem (hDialog, IDC_CLIENTS_CONNECTED),
33605b261ecSmrg		       pszConnectedClients);
33705b261ecSmrg	xfree (pszConnectedClients);
33805b261ecSmrg      }
33905b261ecSmrg      return TRUE;
34005b261ecSmrg
34105b261ecSmrg    case WM_COMMAND:
34205b261ecSmrg      switch (LOWORD (wParam))
34305b261ecSmrg	{
34405b261ecSmrg	case IDOK:
34505b261ecSmrg	  /* Send message to call the GiveUp function */
34605b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
34705b261ecSmrg	  DestroyWindow (g_hDlgExit);
34805b261ecSmrg	  g_hDlgExit = NULL;
34905b261ecSmrg
35005b261ecSmrg	  /* Fix to make sure keyboard focus isn't trapped */
35105b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
35205b261ecSmrg	  return TRUE;
35305b261ecSmrg
35405b261ecSmrg	case IDCANCEL:
35505b261ecSmrg	  DestroyWindow (g_hDlgExit);
35605b261ecSmrg	  g_hDlgExit = NULL;
35705b261ecSmrg
35805b261ecSmrg	  /* Fix to make sure keyboard focus isn't trapped */
35905b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
36005b261ecSmrg	  return TRUE;
36105b261ecSmrg	}
36205b261ecSmrg      break;
36305b261ecSmrg
36405b261ecSmrg    case WM_MOUSEMOVE:
36505b261ecSmrg    case WM_NCMOUSEMOVE:
36605b261ecSmrg      /* Show the cursor if it is hidden */
36705b261ecSmrg      if (g_fSoftwareCursor && !g_fCursor)
36805b261ecSmrg	{
36905b261ecSmrg	  g_fCursor = TRUE;
37005b261ecSmrg	  ShowCursor (TRUE);
37105b261ecSmrg	}
37205b261ecSmrg      return TRUE;
37305b261ecSmrg
37405b261ecSmrg    case WM_CLOSE:
37505b261ecSmrg      DestroyWindow (g_hDlgExit);
37605b261ecSmrg      g_hDlgExit = NULL;
37705b261ecSmrg
37805b261ecSmrg      /* Fix to make sure keyboard focus isn't trapped */
37905b261ecSmrg      PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
38005b261ecSmrg      return TRUE;
38105b261ecSmrg    }
38205b261ecSmrg
38305b261ecSmrg  return FALSE;
38405b261ecSmrg}
38505b261ecSmrg
38605b261ecSmrg
38705b261ecSmrg/*
38805b261ecSmrg * Display the Depth Change dialog box
38905b261ecSmrg */
39005b261ecSmrg
39105b261ecSmrgvoid
39205b261ecSmrgwinDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv)
39305b261ecSmrg{
39405b261ecSmrg  /* Check if dialog already exists */
39505b261ecSmrg  if (g_hDlgDepthChange != NULL)
39605b261ecSmrg    {
39705b261ecSmrg      /* Dialog box already exists, display it */
39805b261ecSmrg      ShowWindow (g_hDlgDepthChange, SW_SHOWDEFAULT);
39905b261ecSmrg
40005b261ecSmrg      /* User has lost the dialog.  Show them where it is. */
40105b261ecSmrg      SetForegroundWindow (g_hDlgDepthChange);
40205b261ecSmrg
40305b261ecSmrg      return;
40405b261ecSmrg    }
40505b261ecSmrg
40605b261ecSmrg  /*
40705b261ecSmrg   * Display a notification to the user that the visual
40805b261ecSmrg   * will not be displayed until the Windows display depth
40905b261ecSmrg   * is restored to the original value.
41005b261ecSmrg   */
41105b261ecSmrg  g_hDlgDepthChange = CreateDialogParam (g_hInstance,
41205b261ecSmrg					 "DEPTH_CHANGE_BOX",
41305b261ecSmrg					 pScreenPriv->hwndScreen,
41405b261ecSmrg					 winChangeDepthDlgProc,
41505b261ecSmrg					 (int) pScreenPriv);
41605b261ecSmrg
41705b261ecSmrg  /* Drop minimize and maximize buttons */
41805b261ecSmrg  SetWindowLong (g_hDlgDepthChange, GWL_STYLE,
41905b261ecSmrg		 GetWindowLong (g_hDlgDepthChange, GWL_STYLE)
42005b261ecSmrg		 & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
42105b261ecSmrg  SetWindowLong (g_hDlgDepthChange, GWL_EXSTYLE,
42205b261ecSmrg		 GetWindowLong (g_hDlgDepthChange, GWL_EXSTYLE)
42305b261ecSmrg		 & ~WS_EX_APPWINDOW );
42405b261ecSmrg  SetWindowPos (g_hDlgDepthChange, 0, 0, 0, 0, 0,
42505b261ecSmrg		SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER | SWP_NOSIZE);
42605b261ecSmrg
42705b261ecSmrg  /* Show the dialog box */
42805b261ecSmrg  ShowWindow (g_hDlgDepthChange, SW_SHOW);
42905b261ecSmrg
43005b261ecSmrg  ErrorF ("winDisplayDepthChangeDialog - DialogBox returned: %d\n",
43105b261ecSmrg	  (int) g_hDlgDepthChange);
43205b261ecSmrg  ErrorF ("winDisplayDepthChangeDialog - GetLastError: %d\n",
43305b261ecSmrg	  (int) GetLastError ());
43405b261ecSmrg
43505b261ecSmrg  /* Minimize the display window */
43605b261ecSmrg  ShowWindow (pScreenPriv->hwndScreen, SW_MINIMIZE);
43705b261ecSmrg}
43805b261ecSmrg
43905b261ecSmrg
44005b261ecSmrg/*
44105b261ecSmrg * Process messages for the dialog that is displayed for
44205b261ecSmrg * disruptive screen depth changes.
44305b261ecSmrg */
44405b261ecSmrg
44505b261ecSmrgstatic wBOOL CALLBACK
44605b261ecSmrgwinChangeDepthDlgProc (HWND hwndDialog, UINT message,
44705b261ecSmrg		       WPARAM wParam, LPARAM lParam)
44805b261ecSmrg{
44905b261ecSmrg  static winPrivScreenPtr	s_pScreenPriv = NULL;
45005b261ecSmrg  static winScreenInfo		*s_pScreenInfo = NULL;
45105b261ecSmrg  static ScreenPtr		s_pScreen = NULL;
45205b261ecSmrg
45305b261ecSmrg#if CYGDEBUG
45405b261ecSmrg  winDebug ("winChangeDepthDlgProc\n");
45505b261ecSmrg#endif
45605b261ecSmrg
45705b261ecSmrg  /* Branch on message type */
45805b261ecSmrg  switch (message)
45905b261ecSmrg    {
46005b261ecSmrg    case WM_INITDIALOG:
46105b261ecSmrg#if CYGDEBUG
46205b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_INITDIALOG\n");
46305b261ecSmrg#endif
46405b261ecSmrg
46505b261ecSmrg      /* Store pointers to private structures for future use */
46605b261ecSmrg      s_pScreenPriv = (winPrivScreenPtr) lParam;
46705b261ecSmrg      s_pScreenInfo = s_pScreenPriv->pScreenInfo;
46805b261ecSmrg      s_pScreen = s_pScreenInfo->pScreen;
46905b261ecSmrg
47005b261ecSmrg#if CYGDEBUG
47105b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - s_pScreenPriv: %08x, "
47205b261ecSmrg	      "s_pScreenInfo: %08x, s_pScreen: %08x\n",
47305b261ecSmrg	      s_pScreenPriv, s_pScreenInfo, s_pScreen);
47405b261ecSmrg#endif
47505b261ecSmrg
47605b261ecSmrg#if CYGDEBUG
47705b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - orig bpp: %d, "
47805b261ecSmrg	      "last bpp: %d\n",
47905b261ecSmrg	      s_pScreenInfo->dwBPP,
48005b261ecSmrg	      s_pScreenPriv->dwLastWindowsBitsPixel);
48105b261ecSmrg#endif
48205b261ecSmrg
48305b261ecSmrg      winCenterDialog( hwndDialog );
48405b261ecSmrg
48505b261ecSmrg      /* Set icon to standard app icon */
48605b261ecSmrg      PostMessage (hwndDialog,
48705b261ecSmrg		   WM_SETICON,
48805b261ecSmrg		   ICON_SMALL,
48905b261ecSmrg		   (LPARAM) LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN)));
49005b261ecSmrg
49105b261ecSmrg      return TRUE;
49205b261ecSmrg
49305b261ecSmrg    case WM_DISPLAYCHANGE:
49405b261ecSmrg#if CYGDEBUG
49505b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %d, "
49605b261ecSmrg	      "last bpp: %d, new bpp: %d\n",
49705b261ecSmrg	      s_pScreenInfo->dwBPP,
49805b261ecSmrg	      s_pScreenPriv->dwLastWindowsBitsPixel,
49905b261ecSmrg	      wParam);
50005b261ecSmrg#endif
50105b261ecSmrg
50205b261ecSmrg      /* Dismiss the dialog if the display returns to the original depth */
50305b261ecSmrg      if (wParam == 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  /* Drop minimize and maximize buttons */
57605b261ecSmrg  SetWindowLong (g_hDlgAbout, GWL_STYLE,
57705b261ecSmrg		 GetWindowLong (g_hDlgAbout, GWL_STYLE)
57805b261ecSmrg		 & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
57905b261ecSmrg  SetWindowLong (g_hDlgAbout, GWL_EXSTYLE,
58005b261ecSmrg		 GetWindowLong (g_hDlgAbout, GWL_EXSTYLE) & ~WS_EX_APPWINDOW);
58105b261ecSmrg  SetWindowPos (g_hDlgAbout, 0, 0, 0, 0, 0,
58205b261ecSmrg		SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
58305b261ecSmrg
58405b261ecSmrg  /* Show the dialog box */
58505b261ecSmrg  ShowWindow (g_hDlgAbout, SW_SHOW);
58605b261ecSmrg
58705b261ecSmrg  /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */
58805b261ecSmrg  SetForegroundWindow (g_hDlgAbout);
58905b261ecSmrg
59005b261ecSmrg  /* Set focus to the OK button */
59105b261ecSmrg  PostMessage (g_hDlgAbout, WM_NEXTDLGCTL,
59205b261ecSmrg	       (int) GetDlgItem (g_hDlgAbout, IDOK), TRUE);
59305b261ecSmrg}
59405b261ecSmrg
59505b261ecSmrg
59605b261ecSmrg/*
59705b261ecSmrg * Process messages for the about dialog.
59805b261ecSmrg */
59905b261ecSmrg
60005b261ecSmrgstatic wBOOL CALLBACK
60105b261ecSmrgwinAboutDlgProc (HWND hwndDialog, UINT message,
60205b261ecSmrg		 WPARAM wParam, LPARAM lParam)
60305b261ecSmrg{
60405b261ecSmrg  static winPrivScreenPtr	s_pScreenPriv = NULL;
60505b261ecSmrg  static winScreenInfo		*s_pScreenInfo = NULL;
60605b261ecSmrg  static ScreenPtr		s_pScreen = NULL;
60705b261ecSmrg
60805b261ecSmrg#if CYGDEBUG
60905b261ecSmrg  winDebug ("winAboutDlgProc\n");
61005b261ecSmrg#endif
61105b261ecSmrg
61205b261ecSmrg  /* Branch on message type */
61305b261ecSmrg  switch (message)
61405b261ecSmrg    {
61505b261ecSmrg    case WM_INITDIALOG:
61605b261ecSmrg#if CYGDEBUG
61705b261ecSmrg      winDebug ("winAboutDlgProc - WM_INITDIALOG\n");
61805b261ecSmrg#endif
61905b261ecSmrg
62005b261ecSmrg      /* Store pointers to private structures for future use */
62105b261ecSmrg      s_pScreenPriv = (winPrivScreenPtr) lParam;
62205b261ecSmrg      s_pScreenInfo = s_pScreenPriv->pScreenInfo;
62305b261ecSmrg      s_pScreen = s_pScreenInfo->pScreen;
62405b261ecSmrg
62505b261ecSmrg      winCenterDialog (hwndDialog);
62605b261ecSmrg
62705b261ecSmrg      /* Set icon to standard app icon */
62805b261ecSmrg      PostMessage (hwndDialog,
62905b261ecSmrg		   WM_SETICON,
63005b261ecSmrg		   ICON_SMALL,
63105b261ecSmrg		   (LPARAM) LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN)));
63205b261ecSmrg
63305b261ecSmrg      /* Override the URL buttons */
63405b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
63505b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
63605b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_UG);
63705b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
63805b261ecSmrg
63905b261ecSmrg      return TRUE;
64005b261ecSmrg
64105b261ecSmrg    case WM_DRAWITEM:
64205b261ecSmrg      /* Draw the URL buttons as needed */
64305b261ecSmrg      winDrawURLWindow (lParam);
64405b261ecSmrg      return TRUE;
64505b261ecSmrg
64605b261ecSmrg    case WM_MOUSEMOVE:
64705b261ecSmrg    case WM_NCMOUSEMOVE:
64805b261ecSmrg      /* Show the cursor if it is hidden */
64905b261ecSmrg      if (g_fSoftwareCursor && !g_fCursor)
65005b261ecSmrg	{
65105b261ecSmrg	  g_fCursor = TRUE;
65205b261ecSmrg	  ShowCursor (TRUE);
65305b261ecSmrg	}
65405b261ecSmrg      return TRUE;
65505b261ecSmrg
65605b261ecSmrg    case WM_COMMAND:
65705b261ecSmrg      switch (LOWORD (wParam))
65805b261ecSmrg	{
65905b261ecSmrg	case IDOK:
66005b261ecSmrg	case IDCANCEL:
66105b261ecSmrg	  ErrorF ("winAboutDlgProc - WM_COMMAND - IDOK or IDCANCEL\n");
66205b261ecSmrg
66305b261ecSmrg	  DestroyWindow (g_hDlgAbout);
66405b261ecSmrg	  g_hDlgAbout = NULL;
66505b261ecSmrg
66605b261ecSmrg	  /* Fix to make sure keyboard focus isn't trapped */
66705b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
66805b261ecSmrg
66905b261ecSmrg	  /* Restore window procedures for URL buttons */
67005b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
67105b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
67205b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG);
67305b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
67405b261ecSmrg
67505b261ecSmrg	  return TRUE;
67605b261ecSmrg
67705b261ecSmrg	case ID_ABOUT_CHANGELOG:
67805b261ecSmrg	  {
67905b261ecSmrg	    int			iReturn;
68005b261ecSmrg#ifdef __CYGWIN__
68105b261ecSmrg	    const char *	pszCygPath = "/usr/X11R6/share/doc/"
68205b261ecSmrg	      "xorg-x11-xwin/changelog.html";
68305b261ecSmrg	    char		pszWinPath[MAX_PATH + 1];
68405b261ecSmrg
68505b261ecSmrg	    /* Convert the POSIX path to a Win32 path */
68605b261ecSmrg	    cygwin_conv_to_win32_path (pszCygPath, pszWinPath);
68705b261ecSmrg#else
68805b261ecSmrg	    const char *	pszWinPath = "http://x.cygwin.com/"
68905b261ecSmrg		    "devel/server/changelog.html";
69005b261ecSmrg#endif
69105b261ecSmrg
69205b261ecSmrg	    iReturn = (int) ShellExecute (NULL,
69305b261ecSmrg					  "open",
69405b261ecSmrg					  pszWinPath,
69505b261ecSmrg					  NULL,
69605b261ecSmrg					  NULL,
69705b261ecSmrg					  SW_MAXIMIZE);
69805b261ecSmrg	    if (iReturn < 32)
69905b261ecSmrg	      {
70005b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_CHANGELOG - "
70105b261ecSmrg			"ShellExecute failed: %d\n",
70205b261ecSmrg			iReturn);
70305b261ecSmrg	      }
70405b261ecSmrg	  }
70505b261ecSmrg	  return TRUE;
70605b261ecSmrg
70705b261ecSmrg	case ID_ABOUT_WEBSITE:
70805b261ecSmrg	  {
70905b261ecSmrg	    const char *	pszPath = "http://x.cygwin.com/";
71005b261ecSmrg	    int			iReturn;
71105b261ecSmrg
71205b261ecSmrg	    iReturn = (int) ShellExecute (NULL,
71305b261ecSmrg					  "open",
71405b261ecSmrg					  pszPath,
71505b261ecSmrg					  NULL,
71605b261ecSmrg					  NULL,
71705b261ecSmrg					  SW_MAXIMIZE);
71805b261ecSmrg	    if (iReturn < 32)
71905b261ecSmrg	      {
72005b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_WEBSITE - "
72105b261ecSmrg			"ShellExecute failed: %d\n",
72205b261ecSmrg			iReturn);
72305b261ecSmrg	      }
72405b261ecSmrg	  }
72505b261ecSmrg	  return TRUE;
72605b261ecSmrg
72705b261ecSmrg	case ID_ABOUT_UG:
72805b261ecSmrg	  {
72905b261ecSmrg	    const char *	pszPath = "http://x.cygwin.com/docs/ug/";
73005b261ecSmrg	    int			iReturn;
73105b261ecSmrg
73205b261ecSmrg	    iReturn = (int) ShellExecute (NULL,
73305b261ecSmrg					  "open",
73405b261ecSmrg					  pszPath,
73505b261ecSmrg					  NULL,
73605b261ecSmrg					  NULL,
73705b261ecSmrg					  SW_MAXIMIZE);
73805b261ecSmrg	    if (iReturn < 32)
73905b261ecSmrg	      {
74005b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_UG - "
74105b261ecSmrg			"ShellExecute failed: %d\n",
74205b261ecSmrg			iReturn);
74305b261ecSmrg	      }
74405b261ecSmrg	  }
74505b261ecSmrg	  return TRUE;
74605b261ecSmrg
74705b261ecSmrg	case ID_ABOUT_FAQ:
74805b261ecSmrg	  {
74905b261ecSmrg	    const char *	pszPath = "http://x.cygwin.com/docs/faq/";
75005b261ecSmrg	    int			iReturn;
75105b261ecSmrg
75205b261ecSmrg	    iReturn = (int) ShellExecute (NULL,
75305b261ecSmrg					  "open",
75405b261ecSmrg					  pszPath,
75505b261ecSmrg					  NULL,
75605b261ecSmrg					  NULL,
75705b261ecSmrg					  SW_MAXIMIZE);
75805b261ecSmrg	    if (iReturn < 32)
75905b261ecSmrg	      {
76005b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_FAQ - "
76105b261ecSmrg			"ShellExecute failed: %d\n",
76205b261ecSmrg			iReturn);
76305b261ecSmrg	      }
76405b261ecSmrg	  }
76505b261ecSmrg	  return TRUE;
76605b261ecSmrg	}
76705b261ecSmrg      break;
76805b261ecSmrg
76905b261ecSmrg    case WM_CLOSE:
77005b261ecSmrg      ErrorF ("winAboutDlgProc - WM_CLOSE\n");
77105b261ecSmrg
77205b261ecSmrg      DestroyWindow (g_hDlgAbout);
77305b261ecSmrg      g_hDlgAbout = NULL;
77405b261ecSmrg
77505b261ecSmrg      /* Fix to make sure keyboard focus isn't trapped */
77605b261ecSmrg      PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
77705b261ecSmrg
77805b261ecSmrg      /* Restore window procedures for URL buttons */
77905b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
78005b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
78105b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG);
78205b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
78305b261ecSmrg
78405b261ecSmrg      return TRUE;
78505b261ecSmrg    }
78605b261ecSmrg
78705b261ecSmrg  return FALSE;
78805b261ecSmrg}
789