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#include <shellapi.h>
3705b261ecSmrg#include "winprefs.h"
3805b261ecSmrg
3905b261ecSmrg/*
4005b261ecSmrg * Local function prototypes
4105b261ecSmrg */
4205b261ecSmrg
4335c4bbdfSmrgstatic INT_PTR CALLBACK
4435c4bbdfSmrgwinExitDlgProc(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam);
4505b261ecSmrg
4635c4bbdfSmrgstatic INT_PTR CALLBACK
4735c4bbdfSmrgwinChangeDepthDlgProc(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam);
4805b261ecSmrg
4935c4bbdfSmrgstatic INT_PTR CALLBACK
5035c4bbdfSmrgwinAboutDlgProc(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam);
5105b261ecSmrg
5205b261ecSmrgstatic void
5335c4bbdfSmrg winDrawURLWindow(LPARAM lParam);
5405b261ecSmrg
5505b261ecSmrgstatic LRESULT CALLBACK
5635c4bbdfSmrgwinURLWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
5705b261ecSmrg
5805b261ecSmrgstatic void
5935c4bbdfSmrg winOverrideURLButton(HWND hdlg, int id);
6005b261ecSmrg
6105b261ecSmrgstatic void
6235c4bbdfSmrg winUnoverrideURLButton(HWND hdlg, int id);
6305b261ecSmrg
6405b261ecSmrg/*
6505b261ecSmrg * Owner-draw a button as a URL
6605b261ecSmrg */
6705b261ecSmrg
6805b261ecSmrgstatic void
6935c4bbdfSmrgwinDrawURLWindow(LPARAM lParam)
7005b261ecSmrg{
7135c4bbdfSmrg    DRAWITEMSTRUCT *draw;
7235c4bbdfSmrg    char str[256];
7335c4bbdfSmrg    RECT rect;
7435c4bbdfSmrg    HFONT font;
7535c4bbdfSmrg    COLORREF crText;
7635c4bbdfSmrg
7735c4bbdfSmrg    draw = (DRAWITEMSTRUCT *) lParam;
7835c4bbdfSmrg    GetWindowText(draw->hwndItem, str, sizeof(str));
7935c4bbdfSmrg    str[255] = 0;
8035c4bbdfSmrg    GetClientRect(draw->hwndItem, &rect);
8135c4bbdfSmrg
8235c4bbdfSmrg    /* Color the button depending upon its state */
8335c4bbdfSmrg    if (draw->itemState & ODS_SELECTED)
8435c4bbdfSmrg        crText = RGB(128 + 64, 0, 0);
8535c4bbdfSmrg    else if (draw->itemState & ODS_FOCUS)
8635c4bbdfSmrg        crText = RGB(0, 128 + 64, 0);
8735c4bbdfSmrg    else
8835c4bbdfSmrg        crText = RGB(0, 0, 128 + 64);
8935c4bbdfSmrg    SetTextColor(draw->hDC, crText);
9035c4bbdfSmrg
9135c4bbdfSmrg    /* Create font 8 high, standard dialog font */
9235c4bbdfSmrg    font = CreateFont(-8, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
9335c4bbdfSmrg                      0, 0, 0, 0, 0, "MS Sans Serif");
9435c4bbdfSmrg    if (!font) {
9535c4bbdfSmrg        ErrorF("winDrawURLWindow: Unable to create URL font, bailing.\n");
9635c4bbdfSmrg        return;
9705b261ecSmrg    }
9835c4bbdfSmrg    /* Draw it */
9935c4bbdfSmrg    SetBkMode(draw->hDC, OPAQUE);
10035c4bbdfSmrg    SelectObject(draw->hDC, font);
10135c4bbdfSmrg    DrawText(draw->hDC, str, strlen(str), &rect, DT_LEFT | DT_VCENTER);
10235c4bbdfSmrg    /* Delete the created font, replace it with stock font */
10335c4bbdfSmrg    DeleteObject(SelectObject(draw->hDC, GetStockObject(ANSI_VAR_FONT)));
10405b261ecSmrg}
10505b261ecSmrg
10605b261ecSmrg/*
10705b261ecSmrg * WndProc for overridden buttons
10805b261ecSmrg */
10905b261ecSmrg
11005b261ecSmrgstatic LRESULT CALLBACK
11105b261ecSmrgwinURLWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
11205b261ecSmrg{
11335c4bbdfSmrg    WNDPROC origCB = NULL;
11435c4bbdfSmrg    HCURSOR cursor;
11535c4bbdfSmrg
11635c4bbdfSmrg    /* If it's a SetCursor message, tell it to the hand */
11735c4bbdfSmrg    if (msg == WM_SETCURSOR) {
11835c4bbdfSmrg        cursor = LoadCursor(NULL, IDC_HAND);
11935c4bbdfSmrg        if (cursor)
12035c4bbdfSmrg            SetCursor(cursor);
12135c4bbdfSmrg        return TRUE;
12235c4bbdfSmrg    }
12335c4bbdfSmrg    origCB = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_USERDATA);
12435c4bbdfSmrg    /* Otherwise fall through to original WndProc */
12535c4bbdfSmrg    if (origCB)
12635c4bbdfSmrg        return CallWindowProc(origCB, hwnd, msg, wParam, lParam);
12735c4bbdfSmrg    else
12835c4bbdfSmrg        return FALSE;
12905b261ecSmrg}
13005b261ecSmrg
13105b261ecSmrg/*
13205b261ecSmrg * Register and unregister the custom WndProc
13305b261ecSmrg */
13405b261ecSmrg
13505b261ecSmrgstatic void
13635c4bbdfSmrgwinOverrideURLButton(HWND hwnd, int id)
13705b261ecSmrg{
13835c4bbdfSmrg    WNDPROC origCB;
13935c4bbdfSmrg
14035c4bbdfSmrg    origCB = (WNDPROC) SetWindowLongPtr(GetDlgItem(hwnd, id),
14135c4bbdfSmrg                                        GWLP_WNDPROC, (LONG_PTR) winURLWndProc);
14235c4bbdfSmrg    SetWindowLongPtr(GetDlgItem(hwnd, id), GWLP_USERDATA, (LONG_PTR) origCB);
14305b261ecSmrg}
14405b261ecSmrg
14505b261ecSmrgstatic void
14635c4bbdfSmrgwinUnoverrideURLButton(HWND hwnd, int id)
14705b261ecSmrg{
14835c4bbdfSmrg    WNDPROC origCB;
14905b261ecSmrg
15035c4bbdfSmrg    origCB = (WNDPROC) SetWindowLongPtr(GetDlgItem(hwnd, id), GWLP_USERDATA, 0);
15135c4bbdfSmrg    if (origCB)
15235c4bbdfSmrg        SetWindowLongPtr(GetDlgItem(hwnd, id), GWLP_WNDPROC, (LONG_PTR) origCB);
15335c4bbdfSmrg}
15405b261ecSmrg
15505b261ecSmrg/*
15605b261ecSmrg * Center a dialog window in the desktop window
1576747b715Smrg * and set small and large icons to X icons.
15805b261ecSmrg */
15905b261ecSmrg
16005b261ecSmrgstatic void
16135c4bbdfSmrgwinInitDialog(HWND hwndDlg)
16205b261ecSmrg{
16335c4bbdfSmrg    HWND hwndDesk;
16435c4bbdfSmrg    RECT rc, rcDlg, rcDesk;
16535c4bbdfSmrg    HICON hIcon, hIconSmall;
16635c4bbdfSmrg
16735c4bbdfSmrg    hwndDesk = GetParent(hwndDlg);
16835c4bbdfSmrg    if (!hwndDesk || IsIconic(hwndDesk))
16935c4bbdfSmrg        hwndDesk = GetDesktopWindow();
17035c4bbdfSmrg
17135c4bbdfSmrg    /* Remove minimize and maximize buttons */
17235c4bbdfSmrg    SetWindowLongPtr(hwndDlg, GWL_STYLE, GetWindowLongPtr(hwndDlg, GWL_STYLE)
17335c4bbdfSmrg                     & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
17435c4bbdfSmrg
17535c4bbdfSmrg    /* Set Window not to show in the task bar */
17635c4bbdfSmrg    SetWindowLongPtr(hwndDlg, GWL_EXSTYLE,
17735c4bbdfSmrg                     GetWindowLongPtr(hwndDlg, GWL_EXSTYLE) & ~WS_EX_APPWINDOW);
17835c4bbdfSmrg
17935c4bbdfSmrg    /* Center dialog window in the screen. Not done for multi-monitor systems, where
18035c4bbdfSmrg     * it is likely to end up split across the screens. In that case, it appears
18135c4bbdfSmrg     * near the Tray icon.
18235c4bbdfSmrg     */
18335c4bbdfSmrg    if (GetSystemMetrics(SM_CMONITORS) > 1) {
18435c4bbdfSmrg        /* Still need to refresh the frame change. */
18535c4bbdfSmrg        SetWindowPos(hwndDlg, HWND_TOPMOST, 0, 0, 0, 0,
18635c4bbdfSmrg                     SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
18735c4bbdfSmrg    }
18835c4bbdfSmrg    else {
18935c4bbdfSmrg        GetWindowRect(hwndDesk, &rcDesk);
19035c4bbdfSmrg        GetWindowRect(hwndDlg, &rcDlg);
19135c4bbdfSmrg        CopyRect(&rc, &rcDesk);
19235c4bbdfSmrg
19335c4bbdfSmrg        OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top);
19435c4bbdfSmrg        OffsetRect(&rc, -rc.left, -rc.top);
19535c4bbdfSmrg        OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom);
19635c4bbdfSmrg
19735c4bbdfSmrg        SetWindowPos(hwndDlg,
19835c4bbdfSmrg                     HWND_TOPMOST,
19935c4bbdfSmrg                     rcDesk.left + (rc.right / 2),
20035c4bbdfSmrg                     rcDesk.top + (rc.bottom / 2),
20135c4bbdfSmrg                     0, 0, SWP_NOSIZE | SWP_FRAMECHANGED);
20235c4bbdfSmrg    }
2036747b715Smrg
20435c4bbdfSmrg    if (g_hIconX)
20535c4bbdfSmrg        hIcon = g_hIconX;
20635c4bbdfSmrg    else
20735c4bbdfSmrg        hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
2086747b715Smrg
20935c4bbdfSmrg    if (g_hSmallIconX)
21035c4bbdfSmrg        hIconSmall = g_hSmallIconX;
21135c4bbdfSmrg    else
21235c4bbdfSmrg        hIconSmall = LoadImage(g_hInstance,
21335c4bbdfSmrg                               MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
21435c4bbdfSmrg                               GetSystemMetrics(SM_CXSMICON),
21535c4bbdfSmrg                               GetSystemMetrics(SM_CYSMICON), LR_SHARED);
21605b261ecSmrg
21735c4bbdfSmrg    PostMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon);
21835c4bbdfSmrg    PostMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall);
21935c4bbdfSmrg}
22005b261ecSmrg
22105b261ecSmrg/*
22205b261ecSmrg * Display the Exit dialog box
22305b261ecSmrg */
22405b261ecSmrg
22505b261ecSmrgvoid
22635c4bbdfSmrgwinDisplayExitDialog(winPrivScreenPtr pScreenPriv)
22705b261ecSmrg{
22835c4bbdfSmrg    int i;
22935c4bbdfSmrg    int liveClients = 0;
23005b261ecSmrg
23135c4bbdfSmrg    /* Count up running clients (clients[0] is serverClient) */
23235c4bbdfSmrg    for (i = 1; i < currentMaxClients; i++)
23335c4bbdfSmrg        if (clients[i] != NullClient)
23435c4bbdfSmrg            liveClients++;
23535c4bbdfSmrg    /* Count down server internal clients */
23635c4bbdfSmrg    if (pScreenPriv->pScreenInfo->fMultiWindow)
23735c4bbdfSmrg        liveClients -= 2;       /* multiwindow window manager & XMsgProc  */
23835c4bbdfSmrg    if (g_fClipboardStarted)
23935c4bbdfSmrg        liveClients--;          /* clipboard manager */
24005b261ecSmrg
24135c4bbdfSmrg    /* A user reported that this sometimes drops below zero. just eye-candy. */
24235c4bbdfSmrg    if (liveClients < 0)
24335c4bbdfSmrg        liveClients = 0;
24435c4bbdfSmrg
24535c4bbdfSmrg    /* Don't show the exit confirmation dialog if SilentExit & no clients,
24635c4bbdfSmrg       or ForceExit, is enabled */
24735c4bbdfSmrg    if ((pref.fSilentExit && liveClients <= 0) || pref.fForceExit) {
24835c4bbdfSmrg        if (g_hDlgExit != NULL) {
24935c4bbdfSmrg            DestroyWindow(g_hDlgExit);
25035c4bbdfSmrg            g_hDlgExit = NULL;
25135c4bbdfSmrg        }
25235c4bbdfSmrg        PostMessage(pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
25335c4bbdfSmrg        return;
25405b261ecSmrg    }
25505b261ecSmrg
25635c4bbdfSmrg    pScreenPriv->iConnectedClients = liveClients;
25735c4bbdfSmrg
25835c4bbdfSmrg    /* Check if dialog already exists */
25935c4bbdfSmrg    if (g_hDlgExit != NULL) {
26035c4bbdfSmrg        /* Dialog box already exists, display it */
26135c4bbdfSmrg        ShowWindow(g_hDlgExit, SW_SHOWDEFAULT);
26205b261ecSmrg
26335c4bbdfSmrg        /* User has lost the dialog.  Show them where it is. */
26435c4bbdfSmrg        SetForegroundWindow(g_hDlgExit);
26505b261ecSmrg
26635c4bbdfSmrg        return;
26705b261ecSmrg    }
26805b261ecSmrg
26935c4bbdfSmrg    /* Create dialog box */
27035c4bbdfSmrg    g_hDlgExit = CreateDialogParam(g_hInstance,
27135c4bbdfSmrg                                   "EXIT_DIALOG",
27235c4bbdfSmrg                                   pScreenPriv->hwndScreen,
27335c4bbdfSmrg                                   winExitDlgProc, (LPARAM) pScreenPriv);
27435c4bbdfSmrg
27535c4bbdfSmrg    /* Show the dialog box */
27635c4bbdfSmrg    ShowWindow(g_hDlgExit, SW_SHOW);
27735c4bbdfSmrg
27835c4bbdfSmrg    /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */
27935c4bbdfSmrg    SetForegroundWindow(g_hDlgExit);
28035c4bbdfSmrg
28135c4bbdfSmrg    /* Set focus to the Cancel button */
28235c4bbdfSmrg    PostMessage(g_hDlgExit, WM_NEXTDLGCTL,
28335c4bbdfSmrg                (WPARAM) GetDlgItem(g_hDlgExit, IDCANCEL), TRUE);
28405b261ecSmrg}
28505b261ecSmrg
2866747b715Smrg#define CONNECTED_CLIENTS_FORMAT	"There %s currently %d client%s connected."
28705b261ecSmrg
28805b261ecSmrg/*
28905b261ecSmrg * Exit dialog window procedure
29005b261ecSmrg */
29105b261ecSmrg
29235c4bbdfSmrgstatic INT_PTR CALLBACK
29335c4bbdfSmrgwinExitDlgProc(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam)
29405b261ecSmrg{
29535c4bbdfSmrg    static winPrivScreenPtr s_pScreenPriv = NULL;
29605b261ecSmrg
29735c4bbdfSmrg    /* Branch on message type */
29835c4bbdfSmrg    switch (message) {
29905b261ecSmrg    case WM_INITDIALOG:
30035c4bbdfSmrg    {
30135c4bbdfSmrg        char *pszConnectedClients;
30235c4bbdfSmrg
30335c4bbdfSmrg        /* Store pointers to private structures for future use */
30435c4bbdfSmrg        s_pScreenPriv = (winPrivScreenPtr) lParam;
30535c4bbdfSmrg
30635c4bbdfSmrg        winInitDialog(hDialog);
30735c4bbdfSmrg
30835c4bbdfSmrg        /* Format the connected clients string */
30935c4bbdfSmrg        if (asprintf(&pszConnectedClients, CONNECTED_CLIENTS_FORMAT,
31035c4bbdfSmrg                     (s_pScreenPriv->iConnectedClients == 1) ? "is" : "are",
31135c4bbdfSmrg                     s_pScreenPriv->iConnectedClients,
31235c4bbdfSmrg                     (s_pScreenPriv->iConnectedClients == 1) ? "" : "s") == -1)
31335c4bbdfSmrg            return TRUE;
31435c4bbdfSmrg
31535c4bbdfSmrg        /* Set the number of connected clients */
31635c4bbdfSmrg        SetWindowText(GetDlgItem(hDialog, IDC_CLIENTS_CONNECTED),
31735c4bbdfSmrg                      pszConnectedClients);
31835c4bbdfSmrg        free(pszConnectedClients);
31935c4bbdfSmrg    }
32035c4bbdfSmrg        return TRUE;
32105b261ecSmrg
32205b261ecSmrg    case WM_COMMAND:
32335c4bbdfSmrg        switch (LOWORD(wParam)) {
32435c4bbdfSmrg        case IDOK:
32535c4bbdfSmrg            /* Send message to call the GiveUp function */
32635c4bbdfSmrg            PostMessage(s_pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
32735c4bbdfSmrg            DestroyWindow(g_hDlgExit);
32835c4bbdfSmrg            g_hDlgExit = NULL;
32935c4bbdfSmrg
33035c4bbdfSmrg            /* Fix to make sure keyboard focus isn't trapped */
33135c4bbdfSmrg            PostMessage(s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
33235c4bbdfSmrg            return TRUE;
33335c4bbdfSmrg
33435c4bbdfSmrg        case IDCANCEL:
33535c4bbdfSmrg            DestroyWindow(g_hDlgExit);
33635c4bbdfSmrg            g_hDlgExit = NULL;
33735c4bbdfSmrg
33835c4bbdfSmrg            /* Fix to make sure keyboard focus isn't trapped */
33935c4bbdfSmrg            PostMessage(s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
34035c4bbdfSmrg            return TRUE;
34135c4bbdfSmrg        }
34235c4bbdfSmrg        break;
34305b261ecSmrg
34405b261ecSmrg    case WM_MOUSEMOVE:
34505b261ecSmrg    case WM_NCMOUSEMOVE:
34635c4bbdfSmrg        /* Show the cursor if it is hidden */
34735c4bbdfSmrg        if (g_fSoftwareCursor && !g_fCursor) {
34835c4bbdfSmrg            g_fCursor = TRUE;
34935c4bbdfSmrg            ShowCursor(TRUE);
35035c4bbdfSmrg        }
35135c4bbdfSmrg        return TRUE;
35205b261ecSmrg
35305b261ecSmrg    case WM_CLOSE:
35435c4bbdfSmrg        DestroyWindow(g_hDlgExit);
35535c4bbdfSmrg        g_hDlgExit = NULL;
35605b261ecSmrg
35735c4bbdfSmrg        /* Fix to make sure keyboard focus isn't trapped */
35835c4bbdfSmrg        PostMessage(s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
35935c4bbdfSmrg        return TRUE;
36005b261ecSmrg    }
36105b261ecSmrg
36235c4bbdfSmrg    return FALSE;
36305b261ecSmrg}
36405b261ecSmrg
36505b261ecSmrg/*
36605b261ecSmrg * Display the Depth Change dialog box
36705b261ecSmrg */
36805b261ecSmrg
36905b261ecSmrgvoid
37035c4bbdfSmrgwinDisplayDepthChangeDialog(winPrivScreenPtr pScreenPriv)
37105b261ecSmrg{
37235c4bbdfSmrg    /* Check if dialog already exists */
37335c4bbdfSmrg    if (g_hDlgDepthChange != NULL) {
37435c4bbdfSmrg        /* Dialog box already exists, display it */
37535c4bbdfSmrg        ShowWindow(g_hDlgDepthChange, SW_SHOWDEFAULT);
37605b261ecSmrg
37735c4bbdfSmrg        /* User has lost the dialog.  Show them where it is. */
37835c4bbdfSmrg        SetForegroundWindow(g_hDlgDepthChange);
37905b261ecSmrg
38035c4bbdfSmrg        return;
38105b261ecSmrg    }
38205b261ecSmrg
38335c4bbdfSmrg    /*
38435c4bbdfSmrg     * Display a notification to the user that the visual
38535c4bbdfSmrg     * will not be displayed until the Windows display depth
38635c4bbdfSmrg     * is restored to the original value.
38735c4bbdfSmrg     */
38835c4bbdfSmrg    g_hDlgDepthChange = CreateDialogParam(g_hInstance,
38935c4bbdfSmrg                                          "DEPTH_CHANGE_BOX",
39035c4bbdfSmrg                                          pScreenPriv->hwndScreen,
39135c4bbdfSmrg                                          winChangeDepthDlgProc,
39235c4bbdfSmrg                                          (LPARAM) pScreenPriv);
39335c4bbdfSmrg    /* Show the dialog box */
39435c4bbdfSmrg    ShowWindow(g_hDlgDepthChange, SW_SHOW);
39535c4bbdfSmrg
39635c4bbdfSmrg    if (!g_hDlgDepthChange)
39735c4bbdfSmrg        ErrorF("winDisplayDepthChangeDialog - GetLastError: %d\n",
39835c4bbdfSmrg                (int) GetLastError());
39935c4bbdfSmrg
40035c4bbdfSmrg    /* Minimize the display window */
40135c4bbdfSmrg    ShowWindow(pScreenPriv->hwndScreen, SW_MINIMIZE);
40205b261ecSmrg}
40305b261ecSmrg
40405b261ecSmrg/*
40505b261ecSmrg * Process messages for the dialog that is displayed for
40635c4bbdfSmrg * disruptive screen depth changes.
40705b261ecSmrg */
40805b261ecSmrg
40935c4bbdfSmrgstatic INT_PTR CALLBACK
41035c4bbdfSmrgwinChangeDepthDlgProc(HWND hwndDialog, UINT message,
41135c4bbdfSmrg                      WPARAM wParam, LPARAM lParam)
41205b261ecSmrg{
41335c4bbdfSmrg    static winPrivScreenPtr s_pScreenPriv = NULL;
41435c4bbdfSmrg    static winScreenInfo *s_pScreenInfo = NULL;
41505b261ecSmrg
41605b261ecSmrg#if CYGDEBUG
41735c4bbdfSmrg    winDebug("winChangeDepthDlgProc\n");
41805b261ecSmrg#endif
41905b261ecSmrg
42035c4bbdfSmrg    /* Branch on message type */
42135c4bbdfSmrg    switch (message) {
42205b261ecSmrg    case WM_INITDIALOG:
42305b261ecSmrg#if CYGDEBUG
42435c4bbdfSmrg        winDebug("winChangeDepthDlgProc - WM_INITDIALOG\n");
42505b261ecSmrg#endif
42605b261ecSmrg
42735c4bbdfSmrg        /* Store pointers to private structures for future use */
42835c4bbdfSmrg        s_pScreenPriv = (winPrivScreenPtr) lParam;
42935c4bbdfSmrg        s_pScreenInfo = s_pScreenPriv->pScreenInfo;
43005b261ecSmrg
43105b261ecSmrg#if CYGDEBUG
43235c4bbdfSmrg        winDebug("winChangeDepthDlgProc - WM_INITDIALOG - s_pScreenPriv: %p, "
43335c4bbdfSmrg                 "s_pScreenInfo: %p\n",
43435c4bbdfSmrg                 s_pScreenPriv, s_pScreenInfo);
43505b261ecSmrg#endif
43605b261ecSmrg
43705b261ecSmrg#if CYGDEBUG
43835c4bbdfSmrg        winDebug("winChangeDepthDlgProc - WM_INITDIALOG - orig bpp: %u, "
43935c4bbdfSmrg                 "current bpp: %d\n",
44035c4bbdfSmrg                 (unsigned int)s_pScreenInfo->dwBPP,
44135c4bbdfSmrg                 GetDeviceCaps(s_pScreenPriv->hdcScreen, BITSPIXEL));
44205b261ecSmrg#endif
4439ace9065Smrg
44435c4bbdfSmrg        winInitDialog(hwndDialog);
44505b261ecSmrg
44635c4bbdfSmrg        return TRUE;
44705b261ecSmrg
44805b261ecSmrg    case WM_DISPLAYCHANGE:
44905b261ecSmrg#if CYGDEBUG
45035c4bbdfSmrg        winDebug("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %u, "
45135c4bbdfSmrg                 "new bpp: %d\n",
45235c4bbdfSmrg                 (unsigned int)s_pScreenInfo->dwBPP,
45335c4bbdfSmrg                 GetDeviceCaps(s_pScreenPriv->hdcScreen, BITSPIXEL));
45405b261ecSmrg#endif
45505b261ecSmrg
45635c4bbdfSmrg        /* Dismiss the dialog if the display returns to the original depth */
45735c4bbdfSmrg        if (GetDeviceCaps(s_pScreenPriv->hdcScreen, BITSPIXEL) ==
45835c4bbdfSmrg            s_pScreenInfo->dwBPP) {
45935c4bbdfSmrg            ErrorF("winChangeDelthDlgProc - wParam == s_pScreenInfo->dwBPP\n");
46005b261ecSmrg
46135c4bbdfSmrg            /* Depth has been restored, dismiss dialog */
46235c4bbdfSmrg            DestroyWindow(g_hDlgDepthChange);
46335c4bbdfSmrg            g_hDlgDepthChange = NULL;
46405b261ecSmrg
46535c4bbdfSmrg            /* Flag that we have a valid screen depth */
46635c4bbdfSmrg            s_pScreenPriv->fBadDepth = FALSE;
46735c4bbdfSmrg        }
46835c4bbdfSmrg        return TRUE;
46905b261ecSmrg
47005b261ecSmrg    case WM_COMMAND:
47135c4bbdfSmrg        switch (LOWORD(wParam)) {
47235c4bbdfSmrg        case IDOK:
47335c4bbdfSmrg        case IDCANCEL:
47435c4bbdfSmrg            winDebug("winChangeDepthDlgProc - WM_COMMAND - IDOK or IDCANCEL\n");
47535c4bbdfSmrg
47635c4bbdfSmrg            /*
47735c4bbdfSmrg             * User dismissed the dialog, hide it until the
47835c4bbdfSmrg             * display mode is restored.
47935c4bbdfSmrg             */
48035c4bbdfSmrg            ShowWindow(g_hDlgDepthChange, SW_HIDE);
48135c4bbdfSmrg            return TRUE;
48235c4bbdfSmrg        }
48335c4bbdfSmrg        break;
48405b261ecSmrg
48505b261ecSmrg    case WM_CLOSE:
48635c4bbdfSmrg        winDebug("winChangeDepthDlgProc - WM_CLOSE\n");
48705b261ecSmrg
48835c4bbdfSmrg        DestroyWindow(g_hDlgAbout);
48935c4bbdfSmrg        g_hDlgAbout = NULL;
49005b261ecSmrg
49135c4bbdfSmrg        /* Fix to make sure keyboard focus isn't trapped */
49235c4bbdfSmrg        PostMessage(s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
49335c4bbdfSmrg        return TRUE;
49405b261ecSmrg    }
49505b261ecSmrg
49635c4bbdfSmrg    return FALSE;
49705b261ecSmrg}
49805b261ecSmrg
49905b261ecSmrg/*
50005b261ecSmrg * Display the About dialog box
50105b261ecSmrg */
50205b261ecSmrg
50305b261ecSmrgvoid
50435c4bbdfSmrgwinDisplayAboutDialog(winPrivScreenPtr pScreenPriv)
50505b261ecSmrg{
50635c4bbdfSmrg    /* Check if dialog already exists */
50735c4bbdfSmrg    if (g_hDlgAbout != NULL) {
50835c4bbdfSmrg        /* Dialog box already exists, display it */
50935c4bbdfSmrg        ShowWindow(g_hDlgAbout, SW_SHOWDEFAULT);
51005b261ecSmrg
51135c4bbdfSmrg        /* User has lost the dialog.  Show them where it is. */
51235c4bbdfSmrg        SetForegroundWindow(g_hDlgAbout);
51305b261ecSmrg
51435c4bbdfSmrg        return;
51505b261ecSmrg    }
51605b261ecSmrg
51735c4bbdfSmrg    /*
51835c4bbdfSmrg     * Display the about box
51935c4bbdfSmrg     */
52035c4bbdfSmrg    g_hDlgAbout = CreateDialogParam(g_hInstance,
52135c4bbdfSmrg                                    "ABOUT_BOX",
52235c4bbdfSmrg                                    pScreenPriv->hwndScreen,
52335c4bbdfSmrg                                    winAboutDlgProc, (LPARAM) pScreenPriv);
52435c4bbdfSmrg
52535c4bbdfSmrg    /* Show the dialog box */
52635c4bbdfSmrg    ShowWindow(g_hDlgAbout, SW_SHOW);
52705b261ecSmrg
52835c4bbdfSmrg    /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */
52935c4bbdfSmrg    SetForegroundWindow(g_hDlgAbout);
53035c4bbdfSmrg
53135c4bbdfSmrg    /* Set focus to the OK button */
53235c4bbdfSmrg    PostMessage(g_hDlgAbout, WM_NEXTDLGCTL,
53335c4bbdfSmrg                (WPARAM) GetDlgItem(g_hDlgAbout, IDOK), TRUE);
53435c4bbdfSmrg}
53505b261ecSmrg
53605b261ecSmrg/*
53705b261ecSmrg * Process messages for the about dialog.
53805b261ecSmrg */
53905b261ecSmrg
54035c4bbdfSmrgstatic INT_PTR CALLBACK
54135c4bbdfSmrgwinAboutDlgProc(HWND hwndDialog, UINT message, WPARAM wParam, LPARAM lParam)
54205b261ecSmrg{
54335c4bbdfSmrg    static winPrivScreenPtr s_pScreenPriv = NULL;
54405b261ecSmrg
54505b261ecSmrg#if CYGDEBUG
54635c4bbdfSmrg    winDebug("winAboutDlgProc\n");
54705b261ecSmrg#endif
54805b261ecSmrg
54935c4bbdfSmrg    /* Branch on message type */
55035c4bbdfSmrg    switch (message) {
55105b261ecSmrg    case WM_INITDIALOG:
55205b261ecSmrg#if CYGDEBUG
55335c4bbdfSmrg        winDebug("winAboutDlgProc - WM_INITDIALOG\n");
55405b261ecSmrg#endif
55505b261ecSmrg
55635c4bbdfSmrg        /* Store pointer to private structure for future use */
55735c4bbdfSmrg        s_pScreenPriv = (winPrivScreenPtr) lParam;
55805b261ecSmrg
55935c4bbdfSmrg        winInitDialog(hwndDialog);
56005b261ecSmrg
56135c4bbdfSmrg        /* Override the URL buttons */
56235c4bbdfSmrg        winOverrideURLButton(hwndDialog, ID_ABOUT_WEBSITE);
56305b261ecSmrg
56435c4bbdfSmrg        return TRUE;
56505b261ecSmrg
56605b261ecSmrg    case WM_DRAWITEM:
56735c4bbdfSmrg        /* Draw the URL buttons as needed */
56835c4bbdfSmrg        winDrawURLWindow(lParam);
56935c4bbdfSmrg        return TRUE;
57005b261ecSmrg
57105b261ecSmrg    case WM_MOUSEMOVE:
57205b261ecSmrg    case WM_NCMOUSEMOVE:
57335c4bbdfSmrg        /* Show the cursor if it is hidden */
57435c4bbdfSmrg        if (g_fSoftwareCursor && !g_fCursor) {
57535c4bbdfSmrg            g_fCursor = TRUE;
57635c4bbdfSmrg            ShowCursor(TRUE);
57735c4bbdfSmrg        }
57835c4bbdfSmrg        return TRUE;
57905b261ecSmrg
58005b261ecSmrg    case WM_COMMAND:
58135c4bbdfSmrg        switch (LOWORD(wParam)) {
58235c4bbdfSmrg        case IDOK:
58335c4bbdfSmrg        case IDCANCEL:
58435c4bbdfSmrg            winDebug("winAboutDlgProc - WM_COMMAND - IDOK or IDCANCEL\n");
58535c4bbdfSmrg
58635c4bbdfSmrg            DestroyWindow(g_hDlgAbout);
58735c4bbdfSmrg            g_hDlgAbout = NULL;
58835c4bbdfSmrg
58935c4bbdfSmrg            /* Fix to make sure keyboard focus isn't trapped */
59035c4bbdfSmrg            PostMessage(s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
59135c4bbdfSmrg
59235c4bbdfSmrg            /* Restore window procedures for URL buttons */
59335c4bbdfSmrg            winUnoverrideURLButton(hwndDialog, ID_ABOUT_WEBSITE);
59435c4bbdfSmrg
59535c4bbdfSmrg            return TRUE;
59635c4bbdfSmrg
59735c4bbdfSmrg        case ID_ABOUT_WEBSITE:
59835c4bbdfSmrg        {
59935c4bbdfSmrg            const char *pszPath = __VENDORDWEBSUPPORT__;
60035c4bbdfSmrg            INT_PTR iReturn;
60135c4bbdfSmrg
60235c4bbdfSmrg            iReturn = (INT_PTR) ShellExecute(NULL,
60335c4bbdfSmrg                                         "open",
60435c4bbdfSmrg                                         pszPath, NULL, NULL, SW_MAXIMIZE);
60535c4bbdfSmrg            if (iReturn < 32) {
60635c4bbdfSmrg                ErrorF("winAboutDlgProc - WM_COMMAND - ID_ABOUT_WEBSITE - "
60735c4bbdfSmrg                       "ShellExecute failed: %d\n", (int)iReturn);
60835c4bbdfSmrg
60935c4bbdfSmrg            }
61035c4bbdfSmrg        }
61135c4bbdfSmrg            return TRUE;
61235c4bbdfSmrg        }
61335c4bbdfSmrg        break;
61405b261ecSmrg
61505b261ecSmrg    case WM_CLOSE:
61635c4bbdfSmrg        winDebug("winAboutDlgProc - WM_CLOSE\n");
61705b261ecSmrg
61835c4bbdfSmrg        DestroyWindow(g_hDlgAbout);
61935c4bbdfSmrg        g_hDlgAbout = NULL;
62005b261ecSmrg
62135c4bbdfSmrg        /* Fix to make sure keyboard focus isn't trapped */
62235c4bbdfSmrg        PostMessage(s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
62305b261ecSmrg
62435c4bbdfSmrg        /* Restore window procedures for URL buttons */
62535c4bbdfSmrg        winUnoverrideURLButton(hwndDialog, ID_ABOUT_WEBSITE);
62605b261ecSmrg
62735c4bbdfSmrg        return TRUE;
62805b261ecSmrg    }
62905b261ecSmrg
63035c4bbdfSmrg    return FALSE;
63105b261ecSmrg}
632