windialogs.c revision 6747b715
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
576747b715Smrg#if defined(XWIN_MULTIWINDOW)
586747b715Smrgextern HICON                    g_hIconX;
596747b715Smrgextern HICON                    g_hSmallIconX;
606747b715Smrg#endif
6105b261ecSmrg
6205b261ecSmrg/*
6305b261ecSmrg * Local function prototypes
6405b261ecSmrg */
6505b261ecSmrg
6605b261ecSmrgstatic wBOOL CALLBACK
6705b261ecSmrgwinExitDlgProc (HWND hDialog, UINT message,
6805b261ecSmrg		WPARAM wParam, LPARAM lParam);
6905b261ecSmrg
7005b261ecSmrgstatic wBOOL CALLBACK
7105b261ecSmrgwinChangeDepthDlgProc (HWND hDialog, UINT message,
7205b261ecSmrg		       WPARAM wParam, LPARAM lParam);
7305b261ecSmrg
7405b261ecSmrgstatic wBOOL CALLBACK
7505b261ecSmrgwinAboutDlgProc (HWND hDialog, UINT message,
7605b261ecSmrg		 WPARAM wParam, LPARAM lParam);
7705b261ecSmrg
7805b261ecSmrg
7905b261ecSmrgstatic void
8005b261ecSmrgwinDrawURLWindow (LPARAM lParam);
8105b261ecSmrg
8205b261ecSmrgstatic LRESULT CALLBACK
8305b261ecSmrgwinURLWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
8405b261ecSmrg
8505b261ecSmrgstatic void
8605b261ecSmrgwinOverrideURLButton (HWND hdlg, int id);
8705b261ecSmrg
8805b261ecSmrgstatic void
8905b261ecSmrgwinUnoverrideURLButton (HWND hdlg, int id);
9005b261ecSmrg
9105b261ecSmrg
9205b261ecSmrg/*
9305b261ecSmrg * Owner-draw a button as a URL
9405b261ecSmrg */
9505b261ecSmrg
9605b261ecSmrgstatic void
9705b261ecSmrgwinDrawURLWindow (LPARAM lParam)
9805b261ecSmrg{
9905b261ecSmrg  DRAWITEMSTRUCT *draw;
10005b261ecSmrg  char str[256];
10105b261ecSmrg  RECT rect;
10205b261ecSmrg  HFONT font;
10305b261ecSmrg  COLORREF crText;
10405b261ecSmrg
10505b261ecSmrg  draw = (DRAWITEMSTRUCT *) lParam;
10605b261ecSmrg  GetWindowText (draw->hwndItem, str, sizeof(str));
10705b261ecSmrg  str[255] = 0;
10805b261ecSmrg  GetClientRect (draw->hwndItem, &rect);
10905b261ecSmrg
11005b261ecSmrg  /* Color the button depending upon its state */
11105b261ecSmrg  if (draw->itemState & ODS_SELECTED)
11205b261ecSmrg    crText = RGB(128+64,0,0);
11305b261ecSmrg  else if (draw->itemState & ODS_FOCUS)
11405b261ecSmrg    crText = RGB(0,128+64,0);
11505b261ecSmrg  else
11605b261ecSmrg    crText = RGB(0,0,128+64);
11705b261ecSmrg  SetTextColor (draw->hDC, crText);
11805b261ecSmrg
1196747b715Smrg  /* Create font 8 high, standard dialog font */
1206747b715Smrg  font = CreateFont (-8, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
12105b261ecSmrg		     0, 0, 0, 0, 0, "MS Sans Serif");
12205b261ecSmrg  if (!font)
12305b261ecSmrg    {
12405b261ecSmrg      ErrorF ("winDrawURLWindow: Unable to create URL font, bailing.\n");
12505b261ecSmrg      return;
12605b261ecSmrg    }
12705b261ecSmrg  /* Draw it */
12805b261ecSmrg  SetBkMode (draw->hDC, OPAQUE);
12905b261ecSmrg  SelectObject (draw->hDC, font);
13005b261ecSmrg  DrawText (draw->hDC, str, strlen (str),&rect,DT_CENTER | DT_VCENTER);
13105b261ecSmrg  /* Delete the created font, replace it with stock font */
13205b261ecSmrg  DeleteObject (SelectObject (draw->hDC, GetStockObject (ANSI_VAR_FONT)));
13305b261ecSmrg}
13405b261ecSmrg
13505b261ecSmrg
13605b261ecSmrg/*
13705b261ecSmrg * WndProc for overridden buttons
13805b261ecSmrg */
13905b261ecSmrg
14005b261ecSmrgstatic LRESULT CALLBACK
14105b261ecSmrgwinURLWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
14205b261ecSmrg{
14305b261ecSmrg  WNDPROC origCB = NULL;
14405b261ecSmrg  HCURSOR cursor;
14505b261ecSmrg
14605b261ecSmrg  /* If it's a SetCursor message, tell it to the hand */
14705b261ecSmrg  if (msg==WM_SETCURSOR) {
14805b261ecSmrg    cursor = LoadCursor (NULL, IDC_HAND);
14905b261ecSmrg    if (cursor)
15005b261ecSmrg      SetCursor (cursor);
15105b261ecSmrg    return TRUE;
15205b261ecSmrg  }
1536747b715Smrg  origCB = (WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA);
15405b261ecSmrg  /* Otherwise fall through to original WndProc */
15505b261ecSmrg  if (origCB)
15605b261ecSmrg    return CallWindowProc (origCB, hwnd, msg, wParam, lParam);
15705b261ecSmrg  else
15805b261ecSmrg    return FALSE;
15905b261ecSmrg}
16005b261ecSmrg
16105b261ecSmrg
16205b261ecSmrg/*
16305b261ecSmrg * Register and unregister the custom WndProc
16405b261ecSmrg */
16505b261ecSmrg
16605b261ecSmrgstatic void
16705b261ecSmrgwinOverrideURLButton (HWND hwnd, int id)
16805b261ecSmrg{
16905b261ecSmrg  WNDPROC origCB;
1706747b715Smrg  origCB = (WNDPROC)SetWindowLongPtr(GetDlgItem (hwnd, id),
1716747b715Smrg                                     GWLP_WNDPROC, (LONG_PTR)winURLWndProc);
1726747b715Smrg  SetWindowLongPtr(GetDlgItem (hwnd, id), GWLP_USERDATA, (LONG_PTR)origCB);
17305b261ecSmrg}
17405b261ecSmrg
17505b261ecSmrgstatic void
17605b261ecSmrgwinUnoverrideURLButton (HWND hwnd, int id)
17705b261ecSmrg{
17805b261ecSmrg  WNDPROC origCB;
1796747b715Smrg  origCB = (WNDPROC)SetWindowLongPtr(GetDlgItem (hwnd, id),
1806747b715Smrg                                     GWLP_USERDATA, 0);
18105b261ecSmrg  if (origCB)
1826747b715Smrg    SetWindowLongPtr(GetDlgItem (hwnd, id), GWLP_WNDPROC, (LONG_PTR)origCB);
18305b261ecSmrg}
18405b261ecSmrg
18505b261ecSmrg
18605b261ecSmrg/*
18705b261ecSmrg * Center a dialog window in the desktop window
1886747b715Smrg * and set small and large icons to X icons.
18905b261ecSmrg */
19005b261ecSmrg
19105b261ecSmrgstatic void
1926747b715SmrgwinInitDialog (HWND hwndDlg)
19305b261ecSmrg{
19405b261ecSmrg  HWND hwndDesk;
1956747b715Smrg  RECT rc, rcDlg, rcDesk;
1966747b715Smrg  HICON hIcon, hIconSmall;
19705b261ecSmrg
19805b261ecSmrg  hwndDesk = GetParent (hwndDlg);
19905b261ecSmrg  if (!hwndDesk || IsIconic (hwndDesk))
20005b261ecSmrg    hwndDesk = GetDesktopWindow ();
20105b261ecSmrg
2026747b715Smrg  /* Remove minimize and maximize buttons */
2036747b715Smrg  SetWindowLongPtr(hwndDlg, GWL_STYLE,
2046747b715Smrg                   GetWindowLongPtr(hwndDlg, GWL_STYLE)
2056747b715Smrg                   & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
2066747b715Smrg
2076747b715Smrg  /* Set Window not to show in the task bar */
2086747b715Smrg  SetWindowLongPtr(hwndDlg, GWL_EXSTYLE,
2096747b715Smrg                   GetWindowLongPtr(hwndDlg, GWL_EXSTYLE) & ~WS_EX_APPWINDOW );
2106747b715Smrg
2116747b715Smrg  /* Center dialog window in the screen. Not done for multi-monitor systems, where
2126747b715Smrg   * it is likely to end up split across the screens. In that case, it appears
2136747b715Smrg   * near the Tray icon.
2146747b715Smrg   */
2156747b715Smrg  if (GetSystemMetrics(SM_CMONITORS)>1) {
2166747b715Smrg    /* Still need to refresh the frame change. */
2176747b715Smrg    SetWindowPos (hwndDlg, HWND_TOPMOST, 0,0,0,0,
2186747b715Smrg		SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
2196747b715Smrg  } else {
2206747b715Smrg    GetWindowRect (hwndDesk, &rcDesk);
2216747b715Smrg    GetWindowRect (hwndDlg, &rcDlg);
2226747b715Smrg    CopyRect (&rc, &rcDesk);
2236747b715Smrg
2246747b715Smrg    OffsetRect (&rcDlg, -rcDlg.left, -rcDlg.top);
2256747b715Smrg    OffsetRect (&rc, -rc.left, -rc.top);
2266747b715Smrg    OffsetRect (&rc, -rcDlg.right, -rcDlg.bottom);
2276747b715Smrg
2286747b715Smrg    SetWindowPos (hwndDlg,
2296747b715Smrg		HWND_TOPMOST,
2306747b715Smrg		rcDesk.left + (rc.right / 2),
2316747b715Smrg		rcDesk.top + (rc.bottom / 2),
23205b261ecSmrg		0, 0,
2336747b715Smrg		SWP_NOSIZE | SWP_FRAMECHANGED);
2346747b715Smrg  }
2356747b715Smrg
2366747b715Smrg#ifdef XWIN_MULTIWINDOW
2376747b715Smrg  if (g_hIconX) hIcon=g_hIconX;
2386747b715Smrg  else
2396747b715Smrg#endif
2406747b715Smrg  hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
2416747b715Smrg
2426747b715Smrg#ifdef XWIN_MULTIWINDOW
2436747b715Smrg  if (g_hSmallIconX) hIconSmall=g_hSmallIconX;
2446747b715Smrg  else
2456747b715Smrg#endif
2466747b715Smrg  hIconSmall = LoadImage (g_hInstance,
2476747b715Smrg                        MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
2486747b715Smrg                        GetSystemMetrics(SM_CXSMICON),
2496747b715Smrg                        GetSystemMetrics(SM_CYSMICON),
2506747b715Smrg                        LR_SHARED);
2516747b715Smrg
2526747b715Smrg  PostMessage (hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon);
2536747b715Smrg  PostMessage (hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall);
25405b261ecSmrg}
25505b261ecSmrg
25605b261ecSmrg
25705b261ecSmrg/*
25805b261ecSmrg * Display the Exit dialog box
25905b261ecSmrg */
26005b261ecSmrg
26105b261ecSmrgvoid
26205b261ecSmrgwinDisplayExitDialog (winPrivScreenPtr pScreenPriv)
26305b261ecSmrg{
26405b261ecSmrg  int i;
26505b261ecSmrg  int liveClients = 0;
26605b261ecSmrg
2676747b715Smrg  /* Count up running clients (clients[0] is serverClient) */
26805b261ecSmrg  for (i = 1; i < currentMaxClients; i++)
26905b261ecSmrg    if (clients[i] != NullClient)
27005b261ecSmrg      liveClients++;
27105b261ecSmrg#if defined(XWIN_MULTIWINDOW)
27205b261ecSmrg  /* Count down server internal clients */
27305b261ecSmrg  if (pScreenPriv->pScreenInfo->fMultiWindow)
27405b261ecSmrg    liveClients -= 2; /* multiwindow window manager & XMsgProc  */
27505b261ecSmrg#endif
27605b261ecSmrg#if defined(XWIN_CLIPBOARD)
27705b261ecSmrg  if (g_fClipboardStarted)
27805b261ecSmrg    liveClients--; /* clipboard manager */
27905b261ecSmrg#endif
28005b261ecSmrg
28105b261ecSmrg  /* A user reported that this sometimes drops below zero. just eye-candy. */
28205b261ecSmrg  if (liveClients < 0)
28305b261ecSmrg    liveClients = 0;
28405b261ecSmrg
2856747b715Smrg  /* Don't show the exit confirmation dialog if SilentExit & no clients,
2866747b715Smrg     or ForceExit, is enabled */
2876747b715Smrg  if ((pref.fSilentExit && liveClients <= 0) || pref.fForceExit)
28805b261ecSmrg    {
28905b261ecSmrg      if (g_hDlgExit != NULL)
29005b261ecSmrg	{
29105b261ecSmrg	  DestroyWindow (g_hDlgExit);
29205b261ecSmrg	  g_hDlgExit = NULL;
29305b261ecSmrg	}
29405b261ecSmrg      PostMessage (pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
29505b261ecSmrg      return;
29605b261ecSmrg    }
29705b261ecSmrg
29805b261ecSmrg  pScreenPriv->iConnectedClients = liveClients;
29905b261ecSmrg
30005b261ecSmrg  /* Check if dialog already exists */
30105b261ecSmrg  if (g_hDlgExit != NULL)
30205b261ecSmrg    {
30305b261ecSmrg      /* Dialog box already exists, display it */
30405b261ecSmrg      ShowWindow (g_hDlgExit, SW_SHOWDEFAULT);
30505b261ecSmrg
30605b261ecSmrg      /* User has lost the dialog.  Show them where it is. */
30705b261ecSmrg      SetForegroundWindow (g_hDlgExit);
30805b261ecSmrg
30905b261ecSmrg      return;
31005b261ecSmrg    }
31105b261ecSmrg
31205b261ecSmrg  /* Create dialog box */
31305b261ecSmrg  g_hDlgExit = CreateDialogParam (g_hInstance,
31405b261ecSmrg				  "EXIT_DIALOG",
31505b261ecSmrg				  pScreenPriv->hwndScreen,
31605b261ecSmrg				  winExitDlgProc,
31705b261ecSmrg				  (int) pScreenPriv);
31805b261ecSmrg
31905b261ecSmrg  /* Show the dialog box */
32005b261ecSmrg  ShowWindow (g_hDlgExit, SW_SHOW);
32105b261ecSmrg
32205b261ecSmrg  /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */
32305b261ecSmrg  SetForegroundWindow (g_hDlgExit);
32405b261ecSmrg
32505b261ecSmrg  /* Set focus to the Cancel button */
32605b261ecSmrg  PostMessage (g_hDlgExit, WM_NEXTDLGCTL,
3276747b715Smrg	       GetDlgItem (g_hDlgExit, IDCANCEL), TRUE);
32805b261ecSmrg}
32905b261ecSmrg
3306747b715Smrg#define CONNECTED_CLIENTS_FORMAT	"There %s currently %d client%s connected."
33105b261ecSmrg
33205b261ecSmrg
33305b261ecSmrg/*
33405b261ecSmrg * Exit dialog window procedure
33505b261ecSmrg */
33605b261ecSmrg
33705b261ecSmrgstatic wBOOL CALLBACK
33805b261ecSmrgwinExitDlgProc (HWND hDialog, UINT message,
33905b261ecSmrg		WPARAM wParam, LPARAM lParam)
34005b261ecSmrg{
34105b261ecSmrg  static winPrivScreenPtr	s_pScreenPriv = NULL;
34205b261ecSmrg
34305b261ecSmrg  /* Branch on message type */
34405b261ecSmrg  switch (message)
34505b261ecSmrg    {
34605b261ecSmrg    case WM_INITDIALOG:
34705b261ecSmrg      {
34805b261ecSmrg	char			*pszConnectedClients;
34905b261ecSmrg
35005b261ecSmrg	/* Store pointers to private structures for future use */
35105b261ecSmrg	s_pScreenPriv = (winPrivScreenPtr) lParam;
35205b261ecSmrg
3536747b715Smrg	winInitDialog (hDialog);
35405b261ecSmrg
35505b261ecSmrg	/* Format the connected clients string */
35605b261ecSmrg	pszConnectedClients = Xprintf (CONNECTED_CLIENTS_FORMAT,
3576747b715Smrg           (s_pScreenPriv->iConnectedClients == 1) ? "is" : "are",
3586747b715Smrg            s_pScreenPriv->iConnectedClients,
3596747b715Smrg           (s_pScreenPriv->iConnectedClients == 1) ? "" : "s");
36005b261ecSmrg	if (!pszConnectedClients)
36105b261ecSmrg	    return TRUE;
36205b261ecSmrg
36305b261ecSmrg
36405b261ecSmrg
36505b261ecSmrg	/* Set the number of connected clients */
36605b261ecSmrg	SetWindowText (GetDlgItem (hDialog, IDC_CLIENTS_CONNECTED),
36705b261ecSmrg		       pszConnectedClients);
3686747b715Smrg	free(pszConnectedClients);
36905b261ecSmrg      }
37005b261ecSmrg      return TRUE;
37105b261ecSmrg
37205b261ecSmrg    case WM_COMMAND:
37305b261ecSmrg      switch (LOWORD (wParam))
37405b261ecSmrg	{
37505b261ecSmrg	case IDOK:
37605b261ecSmrg	  /* Send message to call the GiveUp function */
37705b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
37805b261ecSmrg	  DestroyWindow (g_hDlgExit);
37905b261ecSmrg	  g_hDlgExit = NULL;
38005b261ecSmrg
38105b261ecSmrg	  /* Fix to make sure keyboard focus isn't trapped */
38205b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
38305b261ecSmrg	  return TRUE;
38405b261ecSmrg
38505b261ecSmrg	case IDCANCEL:
38605b261ecSmrg	  DestroyWindow (g_hDlgExit);
38705b261ecSmrg	  g_hDlgExit = NULL;
38805b261ecSmrg
38905b261ecSmrg	  /* Fix to make sure keyboard focus isn't trapped */
39005b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
39105b261ecSmrg	  return TRUE;
39205b261ecSmrg	}
39305b261ecSmrg      break;
39405b261ecSmrg
39505b261ecSmrg    case WM_MOUSEMOVE:
39605b261ecSmrg    case WM_NCMOUSEMOVE:
39705b261ecSmrg      /* Show the cursor if it is hidden */
39805b261ecSmrg      if (g_fSoftwareCursor && !g_fCursor)
39905b261ecSmrg	{
40005b261ecSmrg	  g_fCursor = TRUE;
40105b261ecSmrg	  ShowCursor (TRUE);
40205b261ecSmrg	}
40305b261ecSmrg      return TRUE;
40405b261ecSmrg
40505b261ecSmrg    case WM_CLOSE:
40605b261ecSmrg      DestroyWindow (g_hDlgExit);
40705b261ecSmrg      g_hDlgExit = NULL;
40805b261ecSmrg
40905b261ecSmrg      /* Fix to make sure keyboard focus isn't trapped */
41005b261ecSmrg      PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
41105b261ecSmrg      return TRUE;
41205b261ecSmrg    }
41305b261ecSmrg
41405b261ecSmrg  return FALSE;
41505b261ecSmrg}
41605b261ecSmrg
41705b261ecSmrg
41805b261ecSmrg/*
41905b261ecSmrg * Display the Depth Change dialog box
42005b261ecSmrg */
42105b261ecSmrg
42205b261ecSmrgvoid
42305b261ecSmrgwinDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv)
42405b261ecSmrg{
42505b261ecSmrg  /* Check if dialog already exists */
42605b261ecSmrg  if (g_hDlgDepthChange != NULL)
42705b261ecSmrg    {
42805b261ecSmrg      /* Dialog box already exists, display it */
42905b261ecSmrg      ShowWindow (g_hDlgDepthChange, SW_SHOWDEFAULT);
43005b261ecSmrg
43105b261ecSmrg      /* User has lost the dialog.  Show them where it is. */
43205b261ecSmrg      SetForegroundWindow (g_hDlgDepthChange);
43305b261ecSmrg
43405b261ecSmrg      return;
43505b261ecSmrg    }
43605b261ecSmrg
43705b261ecSmrg  /*
43805b261ecSmrg   * Display a notification to the user that the visual
43905b261ecSmrg   * will not be displayed until the Windows display depth
44005b261ecSmrg   * is restored to the original value.
44105b261ecSmrg   */
44205b261ecSmrg  g_hDlgDepthChange = CreateDialogParam (g_hInstance,
44305b261ecSmrg					 "DEPTH_CHANGE_BOX",
44405b261ecSmrg					 pScreenPriv->hwndScreen,
44505b261ecSmrg					 winChangeDepthDlgProc,
44605b261ecSmrg					 (int) pScreenPriv);
44705b261ecSmrg  /* Show the dialog box */
44805b261ecSmrg  ShowWindow (g_hDlgDepthChange, SW_SHOW);
44905b261ecSmrg
45005b261ecSmrg  ErrorF ("winDisplayDepthChangeDialog - DialogBox returned: %d\n",
45105b261ecSmrg	  (int) g_hDlgDepthChange);
45205b261ecSmrg  ErrorF ("winDisplayDepthChangeDialog - GetLastError: %d\n",
45305b261ecSmrg	  (int) GetLastError ());
45405b261ecSmrg
45505b261ecSmrg  /* Minimize the display window */
45605b261ecSmrg  ShowWindow (pScreenPriv->hwndScreen, SW_MINIMIZE);
45705b261ecSmrg}
45805b261ecSmrg
45905b261ecSmrg
46005b261ecSmrg/*
46105b261ecSmrg * Process messages for the dialog that is displayed for
46205b261ecSmrg * disruptive screen depth changes.
46305b261ecSmrg */
46405b261ecSmrg
46505b261ecSmrgstatic wBOOL CALLBACK
46605b261ecSmrgwinChangeDepthDlgProc (HWND hwndDialog, UINT message,
46705b261ecSmrg		       WPARAM wParam, LPARAM lParam)
46805b261ecSmrg{
46905b261ecSmrg  static winPrivScreenPtr	s_pScreenPriv = NULL;
47005b261ecSmrg  static winScreenInfo		*s_pScreenInfo = NULL;
47105b261ecSmrg  static ScreenPtr		s_pScreen = NULL;
47205b261ecSmrg
47305b261ecSmrg#if CYGDEBUG
47405b261ecSmrg  winDebug ("winChangeDepthDlgProc\n");
47505b261ecSmrg#endif
47605b261ecSmrg
47705b261ecSmrg  /* Branch on message type */
47805b261ecSmrg  switch (message)
47905b261ecSmrg    {
48005b261ecSmrg    case WM_INITDIALOG:
48105b261ecSmrg#if CYGDEBUG
48205b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_INITDIALOG\n");
48305b261ecSmrg#endif
48405b261ecSmrg
48505b261ecSmrg      /* Store pointers to private structures for future use */
48605b261ecSmrg      s_pScreenPriv = (winPrivScreenPtr) lParam;
48705b261ecSmrg      s_pScreenInfo = s_pScreenPriv->pScreenInfo;
48805b261ecSmrg      s_pScreen = s_pScreenInfo->pScreen;
48905b261ecSmrg
49005b261ecSmrg#if CYGDEBUG
49105b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - s_pScreenPriv: %08x, "
49205b261ecSmrg	      "s_pScreenInfo: %08x, s_pScreen: %08x\n",
49305b261ecSmrg	      s_pScreenPriv, s_pScreenInfo, s_pScreen);
49405b261ecSmrg#endif
49505b261ecSmrg
49605b261ecSmrg#if CYGDEBUG
49705b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - orig bpp: %d, "
49805b261ecSmrg	      "last bpp: %d\n",
49905b261ecSmrg	      s_pScreenInfo->dwBPP,
50005b261ecSmrg	      s_pScreenPriv->dwLastWindowsBitsPixel);
50105b261ecSmrg#endif
50205b261ecSmrg
5036747b715Smrg      winInitDialog( hwndDialog );
50405b261ecSmrg
50505b261ecSmrg      return TRUE;
50605b261ecSmrg
50705b261ecSmrg    case WM_DISPLAYCHANGE:
50805b261ecSmrg#if CYGDEBUG
50905b261ecSmrg      winDebug ("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %d, "
51005b261ecSmrg	      "last bpp: %d, new bpp: %d\n",
51105b261ecSmrg	      s_pScreenInfo->dwBPP,
51205b261ecSmrg	      s_pScreenPriv->dwLastWindowsBitsPixel,
51305b261ecSmrg	      wParam);
51405b261ecSmrg#endif
51505b261ecSmrg
51605b261ecSmrg      /* Dismiss the dialog if the display returns to the original depth */
51705b261ecSmrg      if (wParam == s_pScreenInfo->dwBPP)
51805b261ecSmrg	{
51905b261ecSmrg	  ErrorF ("winChangeDelthDlgProc - wParam == s_pScreenInfo->dwBPP\n");
52005b261ecSmrg
52105b261ecSmrg	  /* Depth has been restored, dismiss dialog */
52205b261ecSmrg	  DestroyWindow (g_hDlgDepthChange);
52305b261ecSmrg	  g_hDlgDepthChange = NULL;
52405b261ecSmrg
52505b261ecSmrg	  /* Flag that we have a valid screen depth */
52605b261ecSmrg	  s_pScreenPriv->fBadDepth = FALSE;
52705b261ecSmrg	}
52805b261ecSmrg      return TRUE;
52905b261ecSmrg
53005b261ecSmrg    case WM_COMMAND:
53105b261ecSmrg      switch (LOWORD (wParam))
53205b261ecSmrg	{
53305b261ecSmrg	case IDOK:
53405b261ecSmrg	case IDCANCEL:
53505b261ecSmrg	  ErrorF ("winChangeDepthDlgProc - WM_COMMAND - IDOK or IDCANCEL\n");
53605b261ecSmrg
53705b261ecSmrg	  /*
53805b261ecSmrg	   * User dismissed the dialog, hide it until the
53905b261ecSmrg	   * display mode is restored.
54005b261ecSmrg	   */
54105b261ecSmrg	  ShowWindow (g_hDlgDepthChange, SW_HIDE);
54205b261ecSmrg	  return TRUE;
54305b261ecSmrg	}
54405b261ecSmrg      break;
54505b261ecSmrg
54605b261ecSmrg    case WM_CLOSE:
54705b261ecSmrg      ErrorF ("winChangeDepthDlgProc - WM_CLOSE\n");
54805b261ecSmrg
54905b261ecSmrg      DestroyWindow (g_hDlgAbout);
55005b261ecSmrg      g_hDlgAbout = NULL;
55105b261ecSmrg
55205b261ecSmrg      /* Fix to make sure keyboard focus isn't trapped */
55305b261ecSmrg      PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
55405b261ecSmrg      return TRUE;
55505b261ecSmrg    }
55605b261ecSmrg
55705b261ecSmrg  return FALSE;
55805b261ecSmrg}
55905b261ecSmrg
56005b261ecSmrg
56105b261ecSmrg/*
56205b261ecSmrg * Display the About dialog box
56305b261ecSmrg */
56405b261ecSmrg
56505b261ecSmrgvoid
56605b261ecSmrgwinDisplayAboutDialog (winPrivScreenPtr pScreenPriv)
56705b261ecSmrg{
56805b261ecSmrg  /* Check if dialog already exists */
56905b261ecSmrg  if (g_hDlgAbout != NULL)
57005b261ecSmrg    {
57105b261ecSmrg      /* Dialog box already exists, display it */
57205b261ecSmrg      ShowWindow (g_hDlgAbout, SW_SHOWDEFAULT);
57305b261ecSmrg
57405b261ecSmrg      /* User has lost the dialog.  Show them where it is. */
57505b261ecSmrg      SetForegroundWindow (g_hDlgAbout);
57605b261ecSmrg
57705b261ecSmrg      return;
57805b261ecSmrg    }
57905b261ecSmrg
58005b261ecSmrg  /*
58105b261ecSmrg   * Display the about box
58205b261ecSmrg   */
58305b261ecSmrg  g_hDlgAbout = CreateDialogParam (g_hInstance,
58405b261ecSmrg				   "ABOUT_BOX",
58505b261ecSmrg				   pScreenPriv->hwndScreen,
58605b261ecSmrg				   winAboutDlgProc,
58705b261ecSmrg				   (int) pScreenPriv);
58805b261ecSmrg
58905b261ecSmrg  /* Show the dialog box */
59005b261ecSmrg  ShowWindow (g_hDlgAbout, SW_SHOW);
59105b261ecSmrg
59205b261ecSmrg  /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */
59305b261ecSmrg  SetForegroundWindow (g_hDlgAbout);
59405b261ecSmrg
59505b261ecSmrg  /* Set focus to the OK button */
59605b261ecSmrg  PostMessage (g_hDlgAbout, WM_NEXTDLGCTL,
5976747b715Smrg	       GetDlgItem (g_hDlgAbout, IDOK), TRUE);
59805b261ecSmrg}
59905b261ecSmrg
60005b261ecSmrg
60105b261ecSmrg/*
60205b261ecSmrg * Process messages for the about dialog.
60305b261ecSmrg */
60405b261ecSmrg
60505b261ecSmrgstatic wBOOL CALLBACK
60605b261ecSmrgwinAboutDlgProc (HWND hwndDialog, UINT message,
60705b261ecSmrg		 WPARAM wParam, LPARAM lParam)
60805b261ecSmrg{
60905b261ecSmrg  static winPrivScreenPtr	s_pScreenPriv = NULL;
61005b261ecSmrg  static winScreenInfo		*s_pScreenInfo = NULL;
61105b261ecSmrg  static ScreenPtr		s_pScreen = NULL;
61205b261ecSmrg
61305b261ecSmrg#if CYGDEBUG
61405b261ecSmrg  winDebug ("winAboutDlgProc\n");
61505b261ecSmrg#endif
61605b261ecSmrg
61705b261ecSmrg  /* Branch on message type */
61805b261ecSmrg  switch (message)
61905b261ecSmrg    {
62005b261ecSmrg    case WM_INITDIALOG:
62105b261ecSmrg#if CYGDEBUG
62205b261ecSmrg      winDebug ("winAboutDlgProc - WM_INITDIALOG\n");
62305b261ecSmrg#endif
62405b261ecSmrg
62505b261ecSmrg      /* Store pointers to private structures for future use */
62605b261ecSmrg      s_pScreenPriv = (winPrivScreenPtr) lParam;
62705b261ecSmrg      s_pScreenInfo = s_pScreenPriv->pScreenInfo;
62805b261ecSmrg      s_pScreen = s_pScreenInfo->pScreen;
62905b261ecSmrg
6306747b715Smrg      winInitDialog (hwndDialog);
63105b261ecSmrg
63205b261ecSmrg      /* Override the URL buttons */
63305b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
63405b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
63505b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_UG);
63605b261ecSmrg      winOverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
63705b261ecSmrg
63805b261ecSmrg      return TRUE;
63905b261ecSmrg
64005b261ecSmrg    case WM_DRAWITEM:
64105b261ecSmrg      /* Draw the URL buttons as needed */
64205b261ecSmrg      winDrawURLWindow (lParam);
64305b261ecSmrg      return TRUE;
64405b261ecSmrg
64505b261ecSmrg    case WM_MOUSEMOVE:
64605b261ecSmrg    case WM_NCMOUSEMOVE:
64705b261ecSmrg      /* Show the cursor if it is hidden */
64805b261ecSmrg      if (g_fSoftwareCursor && !g_fCursor)
64905b261ecSmrg	{
65005b261ecSmrg	  g_fCursor = TRUE;
65105b261ecSmrg	  ShowCursor (TRUE);
65205b261ecSmrg	}
65305b261ecSmrg      return TRUE;
65405b261ecSmrg
65505b261ecSmrg    case WM_COMMAND:
65605b261ecSmrg      switch (LOWORD (wParam))
65705b261ecSmrg	{
65805b261ecSmrg	case IDOK:
65905b261ecSmrg	case IDCANCEL:
66005b261ecSmrg	  ErrorF ("winAboutDlgProc - WM_COMMAND - IDOK or IDCANCEL\n");
66105b261ecSmrg
66205b261ecSmrg	  DestroyWindow (g_hDlgAbout);
66305b261ecSmrg	  g_hDlgAbout = NULL;
66405b261ecSmrg
66505b261ecSmrg	  /* Fix to make sure keyboard focus isn't trapped */
66605b261ecSmrg	  PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
66705b261ecSmrg
66805b261ecSmrg	  /* Restore window procedures for URL buttons */
66905b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
67005b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
67105b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG);
67205b261ecSmrg	  winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
67305b261ecSmrg
67405b261ecSmrg	  return TRUE;
67505b261ecSmrg
67605b261ecSmrg	case ID_ABOUT_CHANGELOG:
67705b261ecSmrg	  {
6786747b715Smrg	    HINSTANCE iReturn;
67905b261ecSmrg#ifdef __CYGWIN__
68005b261ecSmrg	    const char *	pszCygPath = "/usr/X11R6/share/doc/"
68105b261ecSmrg	      "xorg-x11-xwin/changelog.html";
68205b261ecSmrg	    char		pszWinPath[MAX_PATH + 1];
68305b261ecSmrg
68405b261ecSmrg	    /* Convert the POSIX path to a Win32 path */
68505b261ecSmrg	    cygwin_conv_to_win32_path (pszCygPath, pszWinPath);
68605b261ecSmrg#else
68705b261ecSmrg	    const char *	pszWinPath = "http://x.cygwin.com/"
68805b261ecSmrg		    "devel/server/changelog.html";
68905b261ecSmrg#endif
69005b261ecSmrg
6916747b715Smrg	    iReturn = ShellExecute (NULL,
6926747b715Smrg                                    "open",
6936747b715Smrg                                    pszWinPath,
6946747b715Smrg                                    NULL,
6956747b715Smrg                                    NULL,
6966747b715Smrg                                    SW_MAXIMIZE);
69705b261ecSmrg	    if (iReturn < 32)
69805b261ecSmrg	      {
69905b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_CHANGELOG - "
70005b261ecSmrg			"ShellExecute failed: %d\n",
70105b261ecSmrg			iReturn);
70205b261ecSmrg	      }
70305b261ecSmrg	  }
70405b261ecSmrg	  return TRUE;
70505b261ecSmrg
70605b261ecSmrg	case ID_ABOUT_WEBSITE:
70705b261ecSmrg	  {
7086747b715Smrg	    const char *	pszPath = __VENDORDWEBSUPPORT__;
70905b261ecSmrg	    int			iReturn;
71005b261ecSmrg
7116747b715Smrg	    iReturn = ShellExecute (NULL,
7126747b715Smrg                                    "open",
7136747b715Smrg                                    pszPath,
7146747b715Smrg                                    NULL,
7156747b715Smrg                                    NULL,
7166747b715Smrg                                    SW_MAXIMIZE);
71705b261ecSmrg	    if (iReturn < 32)
71805b261ecSmrg	      {
71905b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_WEBSITE - "
72005b261ecSmrg			"ShellExecute failed: %d\n",
72105b261ecSmrg			iReturn);
72205b261ecSmrg	      }
72305b261ecSmrg	  }
72405b261ecSmrg	  return TRUE;
72505b261ecSmrg
72605b261ecSmrg	case ID_ABOUT_UG:
72705b261ecSmrg	  {
72805b261ecSmrg	    const char *	pszPath = "http://x.cygwin.com/docs/ug/";
72905b261ecSmrg	    int			iReturn;
73005b261ecSmrg
7316747b715Smrg	    iReturn = ShellExecute (NULL,
7326747b715Smrg                                    "open",
7336747b715Smrg                                    pszPath,
7346747b715Smrg                                    NULL,
7356747b715Smrg                                    NULL,
7366747b715Smrg                                    SW_MAXIMIZE);
73705b261ecSmrg	    if (iReturn < 32)
73805b261ecSmrg	      {
73905b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_UG - "
74005b261ecSmrg			"ShellExecute failed: %d\n",
74105b261ecSmrg			iReturn);
74205b261ecSmrg	      }
74305b261ecSmrg	  }
74405b261ecSmrg	  return TRUE;
74505b261ecSmrg
74605b261ecSmrg	case ID_ABOUT_FAQ:
74705b261ecSmrg	  {
74805b261ecSmrg	    const char *	pszPath = "http://x.cygwin.com/docs/faq/";
74905b261ecSmrg	    int			iReturn;
75005b261ecSmrg
7516747b715Smrg	    iReturn = ShellExecute (NULL,
7526747b715Smrg                                    "open",
7536747b715Smrg                                    pszPath,
7546747b715Smrg                                    NULL,
7556747b715Smrg                                    NULL,
7566747b715Smrg                                    SW_MAXIMIZE);
75705b261ecSmrg	    if (iReturn < 32)
75805b261ecSmrg	      {
75905b261ecSmrg		ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_FAQ - "
76005b261ecSmrg			"ShellExecute failed: %d\n",
76105b261ecSmrg			iReturn);
76205b261ecSmrg	      }
76305b261ecSmrg	  }
76405b261ecSmrg	  return TRUE;
76505b261ecSmrg	}
76605b261ecSmrg      break;
76705b261ecSmrg
76805b261ecSmrg    case WM_CLOSE:
76905b261ecSmrg      ErrorF ("winAboutDlgProc - WM_CLOSE\n");
77005b261ecSmrg
77105b261ecSmrg      DestroyWindow (g_hDlgAbout);
77205b261ecSmrg      g_hDlgAbout = NULL;
77305b261ecSmrg
77405b261ecSmrg      /* Fix to make sure keyboard focus isn't trapped */
77505b261ecSmrg      PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
77605b261ecSmrg
77705b261ecSmrg      /* Restore window procedures for URL buttons */
77805b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
77905b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
78005b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG);
78105b261ecSmrg      winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
78205b261ecSmrg
78305b261ecSmrg      return TRUE;
78405b261ecSmrg    }
78505b261ecSmrg
78605b261ecSmrg  return FALSE;
78705b261ecSmrg}
788