#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
#include "win.h"
#ifdef __CYGWIN__
#include <sys/cygwin.h>
#endif
#include <shellapi.h>
#include "winprefs.h"
extern Bool g_fCursor;
extern HWND g_hDlgDepthChange;
extern HWND g_hDlgExit;
extern HWND g_hDlgAbout;
extern WINPREFS pref;
#ifdef XWIN_CLIPBOARD
extern Bool g_fClipboardStarted;
#endif
extern Bool g_fSoftwareCursor;
static wBOOL CALLBACK
winExitDlgProc (HWND hDialog, UINT message,
WPARAM wParam, LPARAM lParam);
static wBOOL CALLBACK
winChangeDepthDlgProc (HWND hDialog, UINT message,
WPARAM wParam, LPARAM lParam);
static wBOOL CALLBACK
winAboutDlgProc (HWND hDialog, UINT message,
WPARAM wParam, LPARAM lParam);
static void
winDrawURLWindow (LPARAM lParam);
static LRESULT CALLBACK
winURLWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static void
winOverrideURLButton (HWND hdlg, int id);
static void
winUnoverrideURLButton (HWND hdlg, int id);
static void
winDrawURLWindow (LPARAM lParam)
{
DRAWITEMSTRUCT *draw;
char str[256];
RECT rect;
HFONT font;
COLORREF crText;
draw = (DRAWITEMSTRUCT *) lParam;
GetWindowText (draw->hwndItem, str, sizeof(str));
str[255] = 0;
GetClientRect (draw->hwndItem, &rect);
if (draw->itemState & ODS_SELECTED)
crText = RGB(128+64,0,0);
else if (draw->itemState & ODS_FOCUS)
crText = RGB(0,128+64,0);
else
crText = RGB(0,0,128+64);
SetTextColor (draw->hDC, crText);
font = CreateFont (-14, 0, 0, 0, FW_NORMAL, FALSE, TRUE, FALSE,
0, 0, 0, 0, 0, "MS Sans Serif");
if (!font)
{
ErrorF ("winDrawURLWindow: Unable to create URL font, bailing.\n");
return;
}
SetBkMode (draw->hDC, OPAQUE);
SelectObject (draw->hDC, font);
DrawText (draw->hDC, str, strlen (str),&rect,DT_CENTER | DT_VCENTER);
DeleteObject (SelectObject (draw->hDC, GetStockObject (ANSI_VAR_FONT)));
}
static LRESULT CALLBACK
winURLWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
WNDPROC origCB = NULL;
HCURSOR cursor;
if (msg==WM_SETCURSOR) {
cursor = LoadCursor (NULL, IDC_HAND);
if (cursor)
SetCursor (cursor);
return TRUE;
}
origCB = (WNDPROC)GetWindowLong (hwnd, GWL_USERDATA);
if (origCB)
return CallWindowProc (origCB, hwnd, msg, wParam, lParam);
else
return FALSE;
}
static void
winOverrideURLButton (HWND hwnd, int id)
{
WNDPROC origCB;
origCB = (WNDPROC)SetWindowLong (GetDlgItem (hwnd, id),
GWL_WNDPROC, (LONG)winURLWndProc);
SetWindowLong (GetDlgItem (hwnd, id), GWL_USERDATA, (LONG)origCB);
}
static void
winUnoverrideURLButton (HWND hwnd, int id)
{
WNDPROC origCB;
origCB = (WNDPROC)SetWindowLong (GetDlgItem (hwnd, id),
GWL_USERDATA, 0);
if (origCB)
SetWindowLong (GetDlgItem (hwnd, id), GWL_WNDPROC, (LONG)origCB);
}
static void
winCenterDialog (HWND hwndDlg)
{
HWND hwndDesk;
RECT rc, rcDlg, rcDesk;
hwndDesk = GetParent (hwndDlg);
if (!hwndDesk || IsIconic (hwndDesk))
hwndDesk = GetDesktopWindow ();
GetWindowRect (hwndDesk, &rcDesk);
GetWindowRect (hwndDlg, &rcDlg);
CopyRect (&rc, &rcDesk);
OffsetRect (&rcDlg, -rcDlg.left, -rcDlg.top);
OffsetRect (&rc, -rc.left, -rc.top);
OffsetRect (&rc, -rcDlg.right, -rcDlg.bottom);
SetWindowPos (hwndDlg,
HWND_TOP,
rcDesk.left + (rc.right / 2),
rcDesk.top + (rc.bottom / 2),
0, 0,
SWP_NOSIZE | SWP_NOZORDER);
}
void
winDisplayExitDialog (winPrivScreenPtr pScreenPriv)
{
int i;
int liveClients = 0;
for (i = 1; i < currentMaxClients; i++)
if (clients[i] != NullClient)
liveClients++;
#if defined(XWIN_MULTIWINDOW)
if (pScreenPriv->pScreenInfo->fMultiWindow)
liveClients -= 2;
#endif
#if defined(XWIN_CLIPBOARD)
if (g_fClipboardStarted)
liveClients--;
#endif
if (liveClients < 0)
liveClients = 0;
if (pref.fSilentExit && liveClients <= 0)
{
if (g_hDlgExit != NULL)
{
DestroyWindow (g_hDlgExit);
g_hDlgExit = NULL;
}
PostMessage (pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
return;
}
pScreenPriv->iConnectedClients = liveClients;
if (g_hDlgExit != NULL)
{
ShowWindow (g_hDlgExit, SW_SHOWDEFAULT);
SetForegroundWindow (g_hDlgExit);
return;
}
g_hDlgExit = CreateDialogParam (g_hInstance,
"EXIT_DIALOG",
pScreenPriv->hwndScreen,
winExitDlgProc,
(int) pScreenPriv);
SetWindowLong (g_hDlgExit, GWL_STYLE,
GetWindowLong (g_hDlgExit, GWL_STYLE)
& ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
SetWindowLong (g_hDlgExit, GWL_EXSTYLE,
GetWindowLong (g_hDlgExit, GWL_EXSTYLE) & ~WS_EX_APPWINDOW );
SetWindowPos (g_hDlgExit, HWND_TOPMOST, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
ShowWindow (g_hDlgExit, SW_SHOW);
SetForegroundWindow (g_hDlgExit);
PostMessage (g_hDlgExit, WM_NEXTDLGCTL,
(int) GetDlgItem (g_hDlgExit, IDCANCEL), TRUE);
}
#define CONNECTED_CLIENTS_FORMAT "There are currently %d clients connected."
static wBOOL CALLBACK
winExitDlgProc (HWND hDialog, UINT message,
WPARAM wParam, LPARAM lParam)
{
static winPrivScreenPtr s_pScreenPriv = NULL;
switch (message)
{
case WM_INITDIALOG:
{
char *pszConnectedClients;
s_pScreenPriv = (winPrivScreenPtr) lParam;
winCenterDialog (hDialog);
PostMessage (hDialog,
WM_SETICON,
ICON_SMALL,
(LPARAM) LoadIcon (g_hInstance,
MAKEINTRESOURCE(IDI_XWIN)));
pszConnectedClients = Xprintf (CONNECTED_CLIENTS_FORMAT,
s_pScreenPriv->iConnectedClients);
if (!pszConnectedClients)
return TRUE;
SetWindowText (GetDlgItem (hDialog, IDC_CLIENTS_CONNECTED),
pszConnectedClients);
xfree (pszConnectedClients);
}
return TRUE;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDOK:
PostMessage (s_pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
DestroyWindow (g_hDlgExit);
g_hDlgExit = NULL;
PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
return TRUE;
case IDCANCEL:
DestroyWindow (g_hDlgExit);
g_hDlgExit = NULL;
PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
return TRUE;
}
break;
case WM_MOUSEMOVE:
case WM_NCMOUSEMOVE:
if (g_fSoftwareCursor && !g_fCursor)
{
g_fCursor = TRUE;
ShowCursor (TRUE);
}
return TRUE;
case WM_CLOSE:
DestroyWindow (g_hDlgExit);
g_hDlgExit = NULL;
PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
return TRUE;
}
return FALSE;
}
void
winDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv)
{
if (g_hDlgDepthChange != NULL)
{
ShowWindow (g_hDlgDepthChange, SW_SHOWDEFAULT);
SetForegroundWindow (g_hDlgDepthChange);
return;
}
g_hDlgDepthChange = CreateDialogParam (g_hInstance,
"DEPTH_CHANGE_BOX",
pScreenPriv->hwndScreen,
winChangeDepthDlgProc,
(int) pScreenPriv);
SetWindowLong (g_hDlgDepthChange, GWL_STYLE,
GetWindowLong (g_hDlgDepthChange, GWL_STYLE)
& ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
SetWindowLong (g_hDlgDepthChange, GWL_EXSTYLE,
GetWindowLong (g_hDlgDepthChange, GWL_EXSTYLE)
& ~WS_EX_APPWINDOW );
SetWindowPos (g_hDlgDepthChange, 0, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOZORDER | SWP_NOSIZE);
ShowWindow (g_hDlgDepthChange, SW_SHOW);
ErrorF ("winDisplayDepthChangeDialog - DialogBox returned: %d\n",
(int) g_hDlgDepthChange);
ErrorF ("winDisplayDepthChangeDialog - GetLastError: %d\n",
(int) GetLastError ());
ShowWindow (pScreenPriv->hwndScreen, SW_MINIMIZE);
}
static wBOOL CALLBACK
winChangeDepthDlgProc (HWND hwndDialog, UINT message,
WPARAM wParam, LPARAM lParam)
{
static winPrivScreenPtr s_pScreenPriv = NULL;
static winScreenInfo *s_pScreenInfo = NULL;
static ScreenPtr s_pScreen = NULL;
#if CYGDEBUG
winDebug ("winChangeDepthDlgProc\n");
#endif
switch (message)
{
case WM_INITDIALOG:
#if CYGDEBUG
winDebug ("winChangeDepthDlgProc - WM_INITDIALOG\n");
#endif
s_pScreenPriv = (winPrivScreenPtr) lParam;
s_pScreenInfo = s_pScreenPriv->pScreenInfo;
s_pScreen = s_pScreenInfo->pScreen;
#if CYGDEBUG
winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - s_pScreenPriv: %08x, "
"s_pScreenInfo: %08x, s_pScreen: %08x\n",
s_pScreenPriv, s_pScreenInfo, s_pScreen);
#endif
#if CYGDEBUG
winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - orig bpp: %d, "
"last bpp: %d\n",
s_pScreenInfo->dwBPP,
s_pScreenPriv->dwLastWindowsBitsPixel);
#endif
winCenterDialog( hwndDialog );
PostMessage (hwndDialog,
WM_SETICON,
ICON_SMALL,
(LPARAM) LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN)));
return TRUE;
case WM_DISPLAYCHANGE:
#if CYGDEBUG
winDebug ("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %d, "
"last bpp: %d, new bpp: %d\n",
s_pScreenInfo->dwBPP,
s_pScreenPriv->dwLastWindowsBitsPixel,
wParam);
#endif
if (wParam == s_pScreenInfo->dwBPP)
{
ErrorF ("winChangeDelthDlgProc - wParam == s_pScreenInfo->dwBPP\n");
DestroyWindow (g_hDlgDepthChange);
g_hDlgDepthChange = NULL;
s_pScreenPriv->fBadDepth = FALSE;
}
return TRUE;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDOK:
case IDCANCEL:
ErrorF ("winChangeDepthDlgProc - WM_COMMAND - IDOK or IDCANCEL\n");
ShowWindow (g_hDlgDepthChange, SW_HIDE);
return TRUE;
}
break;
case WM_CLOSE:
ErrorF ("winChangeDepthDlgProc - WM_CLOSE\n");
DestroyWindow (g_hDlgAbout);
g_hDlgAbout = NULL;
PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
return TRUE;
}
return FALSE;
}
void
winDisplayAboutDialog (winPrivScreenPtr pScreenPriv)
{
if (g_hDlgAbout != NULL)
{
ShowWindow (g_hDlgAbout, SW_SHOWDEFAULT);
SetForegroundWindow (g_hDlgAbout);
return;
}
g_hDlgAbout = CreateDialogParam (g_hInstance,
"ABOUT_BOX",
pScreenPriv->hwndScreen,
winAboutDlgProc,
(int) pScreenPriv);
SetWindowLong (g_hDlgAbout, GWL_STYLE,
GetWindowLong (g_hDlgAbout, GWL_STYLE)
& ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
SetWindowLong (g_hDlgAbout, GWL_EXSTYLE,
GetWindowLong (g_hDlgAbout, GWL_EXSTYLE) & ~WS_EX_APPWINDOW);
SetWindowPos (g_hDlgAbout, 0, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
ShowWindow (g_hDlgAbout, SW_SHOW);
SetForegroundWindow (g_hDlgAbout);
PostMessage (g_hDlgAbout, WM_NEXTDLGCTL,
(int) GetDlgItem (g_hDlgAbout, IDOK), TRUE);
}
static wBOOL CALLBACK
winAboutDlgProc (HWND hwndDialog, UINT message,
WPARAM wParam, LPARAM lParam)
{
static winPrivScreenPtr s_pScreenPriv = NULL;
static winScreenInfo *s_pScreenInfo = NULL;
static ScreenPtr s_pScreen = NULL;
#if CYGDEBUG
winDebug ("winAboutDlgProc\n");
#endif
switch (message)
{
case WM_INITDIALOG:
#if CYGDEBUG
winDebug ("winAboutDlgProc - WM_INITDIALOG\n");
#endif
s_pScreenPriv = (winPrivScreenPtr) lParam;
s_pScreenInfo = s_pScreenPriv->pScreenInfo;
s_pScreen = s_pScreenInfo->pScreen;
winCenterDialog (hwndDialog);
PostMessage (hwndDialog,
WM_SETICON,
ICON_SMALL,
(LPARAM) LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN)));
winOverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
winOverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
winOverrideURLButton (hwndDialog, ID_ABOUT_UG);
winOverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
return TRUE;
case WM_DRAWITEM:
winDrawURLWindow (lParam);
return TRUE;
case WM_MOUSEMOVE:
case WM_NCMOUSEMOVE:
if (g_fSoftwareCursor && !g_fCursor)
{
g_fCursor = TRUE;
ShowCursor (TRUE);
}
return TRUE;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDOK:
case IDCANCEL:
ErrorF ("winAboutDlgProc - WM_COMMAND - IDOK or IDCANCEL\n");
DestroyWindow (g_hDlgAbout);
g_hDlgAbout = NULL;
PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG);
winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
return TRUE;
case ID_ABOUT_CHANGELOG:
{
int iReturn;
#ifdef __CYGWIN__
const char * pszCygPath = "/usr/X11R6/share/doc/"
"xorg-x11-xwin/changelog.html";
char pszWinPath[MAX_PATH + 1];
cygwin_conv_to_win32_path (pszCygPath, pszWinPath);
#else
const char * pszWinPath = "http://x.cygwin.com/"
"devel/server/changelog.html";
#endif
iReturn = (int) ShellExecute (NULL,
"open",
pszWinPath,
NULL,
NULL,
SW_MAXIMIZE);
if (iReturn < 32)
{
ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_CHANGELOG - "
"ShellExecute failed: %d\n",
iReturn);
}
}
return TRUE;
case ID_ABOUT_WEBSITE:
{
const char * pszPath = "http://x.cygwin.com/";
int iReturn;
iReturn = (int) ShellExecute (NULL,
"open",
pszPath,
NULL,
NULL,
SW_MAXIMIZE);
if (iReturn < 32)
{
ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_WEBSITE - "
"ShellExecute failed: %d\n",
iReturn);
}
}
return TRUE;
case ID_ABOUT_UG:
{
const char * pszPath = "http://x.cygwin.com/docs/ug/";
int iReturn;
iReturn = (int) ShellExecute (NULL,
"open",
pszPath,
NULL,
NULL,
SW_MAXIMIZE);
if (iReturn < 32)
{
ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_UG - "
"ShellExecute failed: %d\n",
iReturn);
}
}
return TRUE;
case ID_ABOUT_FAQ:
{
const char * pszPath = "http://x.cygwin.com/docs/faq/";
int iReturn;
iReturn = (int) ShellExecute (NULL,
"open",
pszPath,
NULL,
NULL,
SW_MAXIMIZE);
if (iReturn < 32)
{
ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_FAQ - "
"ShellExecute failed: %d\n",
iReturn);
}
}
return TRUE;
}
break;
case WM_CLOSE:
ErrorF ("winAboutDlgProc - WM_CLOSE\n");
DestroyWindow (g_hDlgAbout);
g_hDlgAbout = NULL;
PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG);
winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
return TRUE;
}
return FALSE;
}