home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Loisirs 18
/
cd.iso
/
PLANETE
/
MUDWIN
/
SOURCE.ZIP
/
PLAYER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-04
|
24KB
|
928 lines
//
// MODULE Player.c
//
// PURPOSE Contains routines for managing MDI child windows
//
// EXPORTS Player_CreateNew()
// Player_DestroyConnection ()
//
#include "defcon.h"
#include "global.h"
#pragma hdrstop
#include <mem.h>
#include <string.h>
/* note when we were last compiled */
TS(Player)
BOOL bEatMessage;
/*******************************************************************
NAME: Player_CreateNew
SYNOPSIS: Creates a new MDI child window
ENTRY: pPlayerData - Points to a CLIENT_DATA structure
containing data for this new session
RETURNS: HWND - Handle to the new child window
********************************************************************/
HWND FAR
Player_CreateNew(LPCHILDINFOSTRUCT pPlayerData)
{
MDICREATESTRUCT mcs;
HWND hwnd;
char szTitle[MAX_HOST + 20];
mcs.szClass = szPlayer;
wsprintf(szTitle, "%s:%d", pPlayerData->szServer, pPlayerData->wPort);
mcs.szTitle = szTitle;
mcs.hOwner = hInst;
mcs.x = CW_USEDEFAULT;
mcs.y = CW_USEDEFAULT;
mcs.cx = CW_USEDEFAULT;
mcs.cy = CW_USEDEFAULT;
mcs.style = 0;
mcs.lParam = (LPARAM) pPlayerData;
hwnd = FORWARD_WM_MDICREATE(hClient, &mcs, SendMessage);
// Success!
ShowWindow(hwnd,
GetPrivateInt(NULL, "MDI Create", "State", SW_SHOW));
return hwnd;
}
/*******************************************************************
NAME: Player_DestroyConnection
SYNOPSIS: Destroys an existing connection
ENTRY: hwnd - The client-side window handle.
pPlayerData - Points to a CLIENT_DATA structure
describing the connection
********************************************************************/
#pragma argsused
VOID
Player_DestroyConnection(HWND hwnd,
LPCHILDINFOSTRUCT pPlayerData)
{
if (pPlayerData->sReply != INVALID_SOCKET) {
ResetSocket(pPlayerData->sReply);
pPlayerData->sReply = INVALID_SOCKET;
}
}
// FUNCTION SetWrap
//
// PURPOSE Toggles word wrapping of commands
//
// PARAMETERS hwnd - Window handle
// fWrap - Desired state of wrapping
//
// COMMENTS Since this change cannot be done by direct means,
// the function creates a new edit control, moves data
// from the old control to the new control and destroys
// the original control. Note that the function assumes
// that the child being modified is currently active.
VOID NEAR
SetWrap(HWND hWnd, BOOL fWrap)
{
LONG dws;
HWND hwndOld, hwndNew;
RECT r;
LPCHILDINFOSTRUCT lpCIS;
lpCIS = CLIENTPTR(hWnd);
if (!lpCIS)
return;
/* Change word wrap mode */
if (fWrap)
lpCIS->Flags |= CIS_WORDWRAP;
else
lpCIS->Flags &= ~CIS_WORDWRAP;
/* Create the appropriate window style. */
/* Add horizontal scroll if not wrapping. */
dws = WS_CHILD | WS_MAXIMIZE | WS_VISIBLE | WS_VSCROLL
| ES_AUTOVSCROLL | ES_MULTILINE;
if (!fWrap)
dws |= WS_HSCROLL | ES_AUTOHSCROLL;
/* Create a new child window */
GetClientRect(hWnd, &r);
hwndNew = CreateWindow(szEdit, NULL, dws,
0, 0, r.right, r.bottom,
hWnd, 0, hInst, NULL);
/* Get handle to current edit control */
hwndOld = lpCIS->hEdit;
/*
* Create a dummy data handle and make it the handle to the old edit
* control (hT still references the text of old control).
* Free the new window's old data handle and set it to hT (text of
* old edit control)
*/
if (hwndOld) {
HANDLE hT = Edit_GetHandle(hwndOld);
Edit_SetHandle(hwndOld, LocalAlloc(LHND, 0));
DestroyWindow(hwndOld);
LocalFree((HANDLE) Edit_GetHandle(hwndOld));
Edit_SetHandle(hwndNew, hT);
}
/* Point and set focus to the new edit control */
lpCIS->hEdit = hwndNew;
SetFocus(hwndNew);
}
// FUNCTION SetEcho
//
// PURPOSE Toggles local echoing of commands
//
// PARAMETERS hwnd - Window handle
// fEcho - Desired state of echoing
VOID NEAR
SetEcho(HWND hWnd, BOOL fEcho)
{
LPCHILDINFOSTRUCT lpCIS;
lpCIS = CLIENTPTR(hWnd);
if (!lpCIS)
return;
/* Change word wrap mode */
if (fEcho)
lpCIS->Flags |= CIS_ECHODATA;
else
lpCIS->Flags &= ~CIS_ECHODATA;
}
// FUNCTION SetColor
//
// PURPOSE Sets the Color used by a window
//
// PARAMETERS hwnd - Window handle
// junk - Desired Color
VOID NEAR
SetColor(HWND hwnd, LPCOLORREF lprgb)
{
LPCHILDINFOSTRUCT lpCIS;
LOGFONT lfTemp;
lpCIS = CLIENTPTR(hwnd);
if (!lpCIS) return;
lpCIS->Flags |= CIS_BACKGRND;
lpCIS->sis.crBgndColor = *lprgb;
if (lpCIS->sis.hbr) DeleteObject(lpCIS->sis.hbr);
lpCIS->sis.hbr = CreateSolidBrush(*lprgb);
// redraw the client
InvalidateRect(lpCIS->hEdit, NULL, TRUE);
}
// FUNCTION SetFont
//
// PURPOSE Sets the font used by a window
//
// PARAMETERS hwnd - Window handle
// junk - Desired font
VOID NEAR
SetFont(HWND hwnd, LPLOGFONT lpcf, LPCOLORREF lpcr)
{
LPCHILDINFOSTRUCT lpCIS;
LOGFONT lfTemp;
int nyLogPix;
if (!(*lpcf->lfFaceName) || !lpcf->lfHeight) return;
lpCIS = CLIENTPTR(hwnd);
if (!lpCIS) return;
lpCIS->Flags |= CIS_FONTINFO;
lpCIS->sis.crTextColor = *lpcr;
if (lpCIS->sis.hScreenFont != NULL)
DeleteObject(lpCIS->sis.hScreenFont);
lpCIS->sis.hScreenFont = CreateFontIndirect(&lpCIS->sis.lfCurrFont);
SendMessage(lpCIS->hEdit, WM_SETFONT,
(WPARAM) lpCIS->sis.hScreenFont,
(LPARAM) MAKELONG((WORD) TRUE, 0));
// create printer font using temp
lfTemp = lpCIS->sis.lfCurrFont;
/*** problem: hPrnDC doesn't exist here! ***/
// adjust font height for correct size on printer */
//nyLogPix = GetDeviceCaps(hPrnDC, LOGPIXELSY);
//lfTemp.lfHeight = -((cf->iPointSize/10) * nyLogPix)/72;
if (lpCIS->sis.hScreenFont != NULL)
DeleteObject(lpCIS->sis.hScreenFont);
lpCIS->sis.hScreenFont = CreateFontIndirect(&lfTemp);
// redraw the client
InvalidateRect(lpCIS->hEdit, NULL, TRUE);
}
/*******************************************************************
NAME: Player_On..
SYNOPSIS: Handles WM_... messages
********************************************************************/
VOID
Player_OnClose(HWND hwnd)
{
LPCHILDINFOSTRUCT pPlayerData;
if (Player_OnQueryEndSession(hwnd)) {
pPlayerData = CLIENTPTR(hwnd);
if (pPlayerData != NULL) {
// This window has client data. Close any open
// socket/file handles before freeing the buffer
Player_DestroyConnection(NULL, pPlayerData);
(void) GlobalFreePtr(pPlayerData);
SetWindowLong(hwnd, 0, 0L);
}
FORWARD_WM_CLOSE(hwnd, DefMDIChildProc);
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#pragma argsused
VOID
Player_OnCommand(HWND hwnd,
int id,
HWND hwndCtl,
UINT codeNotify)
{
LPCHILDINFOSTRUCT pPlayerData = CLIENTPTR(hwnd);
switch (id) {
/* this never seems to fire */
case EN_ERRSPACE:
{
INT nLines, ichSize;
DWORD SaveSel;
SaveSel = Edit_GetSel(pPlayerData->hEdit);
nLines = Edit_GetLineCount(pPlayerData->hEdit);
MsgBox(MB_OK, IDS_DEBUGBOTH, (LPCSTR)"ERRSPACE", nLines,
GetWindowTextLength(pPlayerData->hEdit));
ichSize = Edit_LineIndex(pPlayerData->hEdit, nLines << 2);
/* no cracker or replacement for the following */
SendMessage((hwndCtl), EM_SETSEL, 1, ichSize);
Edit_ReplaceSel(pPlayerData->hEdit, "");
/* no cracker or replacement for the following */
SendMessage(pPlayerData->hEdit, EM_SETSEL, 1, SaveSel);
}
break;
case IDM_FILE_SAVE:
if ((pPlayerData->Flags & CIS_UNTITLED) && !ChangeFile(hwnd))
break;
SaveFile(hwnd);
break;
case IDM_FILE_SAVEAS:
if (ChangeFile(hwnd))
SaveFile(hwnd);
break;
case IDM_FILE_PRINT:
MsgBox(MB_OK, IDS_DEBUGBOTH, (LPCSTR)"lines/chars",
Edit_GetLineCount(pPlayerData->hEdit),
GetWindowTextLength(pPlayerData->hEdit));
//ShowPrintBox(hwnd);
break;
case IDM_EDIT_COPY:
if (pPlayerData && pPlayerData->hEdit)
FORWARD_WM_COPY(pPlayerData->hEdit, SendMessage);
break;
case IDM_EDI