⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chtxtout.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*----------------------------------------------------------------------------
                        _                              _ _       
        /\             | |                            | (_)      
       /  \   _ __   __| |_ __ ___  _ __ ___   ___  __| |_  __ _ 
      / /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
     / ____ \| | | | (_| | | | (_) | | | | | |  __/ (_| | | (_| |
    /_/    \_\_| |_|\__,_|_|  \___/|_| |_| |_|\___|\__,_|_|\__,_|

    The contents of this file are subject to the Andromedia Public
	License Version 1.0 (the "License"); you may not use this file
	except in compliance with the License. You may obtain a copy of
	the License at http://www.andromedia.com/APL/

    Software distributed under the License is distributed on an
	"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
	implied. See the License for the specific language governing
	rights and limitations under the License.

    The Original Code is Pueblo client code, released November 4, 1998.

    The Initial Developer of the Original Code is Andromedia Incorporated.
	Portions created by Andromedia are Copyright (C) 1998 Andromedia
	Incorporated.  All Rights Reserved.

	Andromedia Incorporated                         415.365.6700
	818 Mission Street - 2nd Floor                  415.365.6701 fax
	San Francisco, CA 94103

    Contributor(s):
	--------------------------------------------------------------------------
	   Chaco team:  Dan Greening, Glenn Crocker, Jim Doubek,
	                Coyote Lussier, Pritham Shetty.

					Wrote and designed original codebase.

------------------------------------------------------------------------------

	Implementation for the ChTextOutput class, which is used to display
	output text.

----------------------------------------------------------------------------*/

// $Header: /home/cvs/chaco/modules/client/msw/ChText/ChTxtOut.cpp,v 2.63 1996/02/22 01:45:00 coyote Exp $

#include "headers.h"

#include <ChCore.h>
#include <ChClMod.h>
#include <ChPane.h>
//#include <ChMime.h>
#include <ChUrlMap.h>

#include <ChWorld.h>

#include "ChTextStream.h"
#include "ChTxtOut.h"
#include "ChPrefs.h"

#if defined( CH_UNIX )

	#include <ChTypes.h>
	#include "../../unix/ChText/TextPriv.h"

#endif	// defined( CH_UNIX )

#ifdef _DEBUG
	#undef THIS_FILE
	static char THIS_FILE[] = __FILE__;
#endif


/*----------------------------------------------------------------------------
	Constants
----------------------------------------------------------------------------*/

#define ATTR_HREF					TEXT( "href" )
#define ATTR_TARGET					TEXT( "target" )


/*----------------------------------------------------------------------------
	Handler declarations
----------------------------------------------------------------------------*/

CH_DECLARE_MESSAGE_HANDLER( textOutInitHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutLoadCompleteHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutTextHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutFileHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutLoadFileHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutClearTextHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutResetHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutSetScrollHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutShowModuleHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutPaneCmdHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutPaneEventHandler )

#if	!defined( CH_UNIX )

CH_DECLARE_MESSAGE_HANDLER( textOutGetPageCountHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutGetPagesHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutGetPageDataHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutReleasePagesHandler )

#endif // !CH_UNIX

CH_DECLARE_MESSAGE_HANDLER( textOutCommandHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutInlineHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutHintHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutInstallHookHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutPromoteHookHandler )
CH_DECLARE_MESSAGE_HANDLER( textOutUninstallHookHandler )

static ChMsgHandlerDesc	textOutHandlers[] =
					{	{CH_MSG_INIT, textOutInitHandler},
						{CH_MSG_LOAD_COMPLETE, textOutLoadCompleteHandler},
						{CH_MSG_TEXT, textOutTextHandler},
						{CH_MSG_FILE, textOutFileHandler},
						{CH_MSG_LOAD_FILE, textOutLoadFileHandler},
						{CH_MSG_CLEAR_TEXT, textOutClearTextHandler},
						{CH_MSG_RESET, textOutResetHandler},
						{CH_MSG_SET_SCROLL, textOutSetScrollHandler},
						{CH_MSG_SHOW_MODULE, textOutShowModuleHandler},
						{CH_MSG_PANE_CMD, textOutPaneCmdHandler},
						{CH_MSG_PANE_EVENT, textOutPaneEventHandler},
#if !defined( CH_UNIX )
						{CH_MSG_GET_PAGE_COUNT, textOutGetPageCountHandler},
						{CH_MSG_GET_PAGES, textOutGetPagesHandler},
						{CH_MSG_GET_PAGE_DATA, textOutGetPageDataHandler},
						{CH_MSG_RELEASE_PAGES, textOutReleasePagesHandler},
#endif // !defined( CH_UNIX )
						{CH_MSG_CMD, textOutCommandHandler},
						{CH_MSG_INLINE, textOutInlineHandler},
						{CH_MSG_HINT, textOutHintHandler},
						{CH_MSG_INSTALL_HOOK, textOutInstallHookHandler},
						{CH_MSG_PROMOTE_HOOK, textOutPromoteHookHandler},
						{CH_MSG_UNINSTALL_HOOK, textOutUninstallHookHandler} };

// We want ChTxtOutputWnd on Unix, but we don't want TextOutMainInfo.
#ifndef CH_UNIX

/*----------------------------------------------------------------------------
	Chaco menu handlers
----------------------------------------------------------------------------*/

CH_DECLARE_MESSAGE_HANDLER( txtOutStdEditMenuHandler )
CH_DECLARE_MESSAGE_HANDLER( OnTxtOutStdEditCopy )
CH_DECLARE_MESSAGE_HANDLER( OnTxtOutStdEditCutPaste )

#endif


/*----------------------------------------------------------------------------
	Inline functions
----------------------------------------------------------------------------*/

inline bool IsTargetSelfOutput( const string& strTarget )
	{
		bool	boolSelf = (strTarget.CompareNoCase( "_self" ) == 0);

		return boolSelf;
	}


/*----------------------------------------------------------------------------
	class ChPaneOutWnd
----------------------------------------------------------------------------*/

class ChPaneOutWnd : public ChTextOutputWnd
{
	public:
		ChPaneOutWnd( const ChModuleID& idWorld );
		virtual ~ChPaneOutWnd();

	protected:
		virtual void OnSubmitForm( const string& strFormData );

	protected:
		ChClientModule	m_worldModule;
};


ChPaneOutWnd::ChPaneOutWnd( const ChModuleID& idWorld ) :
				m_worldModule( idWorld )
{
}


ChPaneOutWnd::~ChPaneOutWnd()
{
}


void ChPaneOutWnd::OnSubmitForm( const string& strFormData )
{
	ChCmdMsg	msg( strFormData );
											// Submit the HTML form
	m_worldModule.Send( msg );
}


/*----------------------------------------------------------------------------
	ChTextOutMainInfo class
----------------------------------------------------------------------------*/

chint16		ChTextOutMainInfo::m_sMinWidth;
chint16		ChTextOutMainInfo::m_sIdealWidth;
chint16		ChTextOutMainInfo::m_sMinHeight;
chint16		ChTextOutMainInfo::m_sIdealHeight;

#ifndef CH_UNIX

ChTextOutMainInfo::ChTextOutMainInfo( ChModuleID idModule,
										ChModuleID idServerModule ) :
					ChMainInfo( idModule ),
					m_textOutDispatcher( idModule, defTextOutHandler ),
					m_stdEditMenu( txtOutStdEditMenuHandler ),
//					m_idTextInModule( 0 ),
//					m_pTextIn( 0 ),
					m_idWorldModule( 0 ),
					m_boolShown( false ),
					m_boolMenus( false ),
					m_boolMenusInstalled( false ),
					m_httpConn( 0 )
{
	ChPane*		pPane = GetPaneMgr()->FindPane( ChPaneMgr::strTextName );
	CClientDC	dc( pPane->GetFrameWnd() );
	TEXTMETRIC	tm;

	dc.GetTextMetrics( &tm );

	m_sMinWidth = tm.tmAveCharWidth * minCharWidth;
	m_sIdealWidth = tm.tmAveCharWidth * idealCharWidth;
	m_sMinHeight = (tm.tmHeight + tm.tmExternalLeading) * minCharHeight;
	m_sIdealHeight = (tm.tmHeight + tm.tmExternalLeading) * idealCharHeight;

	m_pTextStreamMgr = new ChTextStreamManager( idModule );
	ASSERT( m_pTextStreamMgr );
	m_httpConn.SetStreamMgr( m_pTextStreamMgr );
											/* Register this module as a
												handler for HTML text and
												normal text */

	//GetMimeMgr()->AddHandler( GetModuleID(), "text/plain" );
	//GetMimeMgr()->AddHandler( GetModuleID(), "text/html" );

	InstallOutputHooks( GetOutputWnd() );
}


ChTextOutMainInfo::~ChTextOutMainInfo()
{
	InstallOutputHooks( GetOutputWnd(), false );

	m_httpConn.SetStreamMgr( 0 );
	delete m_pTextStreamMgr;

											// Unhook us from the MIME handler

	//GetMimeMgr()->RemoveHandler( GetModuleID(), "text/plain" );
	//GetMimeMgr()->RemoveHandler( GetModuleID(), "text/html" );

											// Unload the text in module
#if 0
	if (m_idTextInModule)
	{
		UnloadClientModule( m_idTextInModule );
		m_idTextInModule = 0;
	}

	if (m_pTextIn)
	{
		delete m_pTextIn;
		m_pTextIn = 0;
	}
#endif
											// Clear all panes

	GetPaneMgr()->ShowAllPanes( GetModuleID(), false );
	GetPaneMgr()->DestroyAllPanes( GetModuleID() );

	DestroyMenus();
											// Destroy the window
	GetOutputWnd()->DestroyWindow();
}


void ChTextOutMainInfo::Initialize()
{
	ChRect			rtChild( -100, -100, -1, -1 );
	bool			boolCreated;
	ChPane*			pPane = GetPaneMgr()->FindPane( ChPaneMgr::strTextName );
	ChModuleMgr*	pModMgr = ChCore::GetCore()->GetModuleMgr();
	string			strDummy;

//	LoadClientModule( CH_MODULE_TEXT_INPUT, CH_MODULE_TEXT_INPUT_BASE,
//						GetModuleID(), 0 );

	pModMgr->FindModule( CH_MODULE_WORLD, m_idWorldModule, strDummy );
	ASSERT( 0 != GetWorldModuleID() );
	ASSERT( 0 != pPane );
											/* Set the main info, this is used
												for menu processing */
	GetOutputWnd()->SetMainInfo( this );
											/* Create the new child using the
												pane frame window as the
												parent */

	boolCreated = GetOutputWnd()->Create( rtChild, pPane->GetFrameWnd() );
	ASSERT( boolCreated );
											// Set the child into the view

	pPane->SetOwner( GetModuleID(), GetOutputWnd() );
	pPane->SetSizePrefs( m_sIdealWidth, m_sIdealHeight, m_sMinWidth,
							m_sMinHeight );
	CreateMenus();
}

#endif // !CH_UNIX

void ChTextOutMainInfo::RegisterDispatchers()
{
	chint16		sHandlerCount = sizeof( textOutHandlers ) /
								sizeof( ChMsgHandlerDesc );

	m_textOutDispatcher.AddHandler( textOutHandlers, sHandlerCount );
}


#if 0

void ChTextOutMainInfo::SetTextInID( const ChModuleID& idModule )
{
	m_idTextInModule = idModule;

	if (0 == m_pTextIn)
	{
		m_pTextIn = new ChClientModule( m_idTextInModule );
	}
}

#endif

#if !defined( CH_UNIX )

void ChTextOutMainInfo::ShowModule( bool boolShow )
{
	ChPane*		pPane;
											// Get the correct pane

	pPane = GetPaneMgr()->FindPane( ChPaneMgr::strTextName );
	ASSERT( 0 != pPane );

	if (boolShow && !IsShown())
	{
		pPane->Show();
		InstallMenus();

		m_boolShown = true;
	}
	else if (!boolShow && IsShown())
	{
		pPane->Show( false );
		UninstallMenus();

		m_boolShown = false;
	}
}


void ChTextOutMainInfo::LoadFile( const string& strFilename,
									const string& strURL,
									const string& strHTML,
									const string& strMimeType )
{
	bool					boolPaneAttrs;
	ChPane::ChPaneCmd		paneCmd;
	string					strPaneName;
	string					strPaneTitle;

	if (boolPaneAttrs = !strHTML.IsEmpty())
	{
		boolPaneAttrs = ChPane::GetPaneCmdAttr( strHTML, paneCmd );
	}

	if (boolPaneAttrs)
	{
		ASSERT( ChPane::paneOpen == paneCmd );

		DoPaneOpen( strFilename, strMimeType, strURL, strHTML );
	}
	else
	{
		ChTextOutputWnd*	pWnd = GetOutputWnd();

		pWnd->ShowAppend( false );
		pWnd->DisplayFile( strFilename, strMimeType, ChHtmlWnd::fileReplace, strURL );
	}
}


bool ChTextOutMainInfo::DoPaneCommand( ChPane::ChPaneCmd paneCmd,
										const char* pstrArgs )
{
	switch( paneCmd )
	{
		case ChPane::paneOpen:
		{
			string strURL;
			ChHtmlWnd::GetHTMLHref( pstrArgs, true, strURL );
			if (!strURL.IsEmpty())
			{ 
				string *pstrHTML = new string( pstrArgs );
				m_httpConn.GetURL( strURL, (chparam)pstrHTML );
			}
			else
			{
				TRACE1( "Empty URL passed into ChTextOutMainInfo::LoadURL : %s ", pstrArgs );
			}
			//GetMimeMgr()->LoadURL( "", pstrArgs );
			break;
		}

		case ChPane::paneClose:
		{
			DoPaneClose( pstrArgs );
			break;
		}

		default:
		{
			break;
		}
	}

	return true;
}


void ChTextOutMainInfo::DoPaneOpen( const string& strFilename,
									const string& strMimeType,
									const string& strURL,
									const string& strHTML )
{
	bool				boolPaneAttrs;
	ChPane*				pPane;
	ChPaneOutWnd*		pWnd;
	ChRect				rtChild( 10, 10, 300, 500 );
	ChPane::ChPaneCmd	paneCmd;
	string				strPaneName;
	string				strPaneTitle;
	chflag32			flPaneOptions;
	chint16				sIdealWidth = m_sIdealWidth;
	chint16				sIdealHeight = m_sIdealHeight;
	chint16				sMinWidth = m_sMinWidth;
	chint16				sMinHeight = m_sMinHeight;
	bool				boolCreated = true;

	boolPaneAttrs = ChPane::GetPaneAttrs( strHTML, paneCmd, strPaneName,
											strPaneTitle, flPaneOptions );
	ASSERT( boolPaneAttrs );
	ASSERT( ChPane::paneOpen == paneCmd );

	ChPane::GetPaneSizeAttrs( strHTML, sIdealWidth, sIdealHeight, sMinWidth,
								sMinHeight );

	if (!(pPane = GetPaneMgr()->FindPane( strPaneName )))
	{
		pPane = GetPaneMgr()->CreatePane( strPaneName, 0, sIdealWidth,
											sIdealHeight, flPaneOptions );
		ASSERT( pPane );
		ASSERT( 0 != GetWorldModuleID() );
	}

	if (pPane->GetModuleID() != GetModuleID())
	{
		DWORD		dwPaneStyle;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -