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

📄 chtextoutput.cpp

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

    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 ChTextOutputBar class.

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

// $Header: /home/cvs/chaco/modules/client/msw/ChWorld/ChTextOutput.cpp,v 2.44 1996/09/12 19:10:07 pritham Exp $

#include "headers.h"

#include <ChConst.h>
#include <ChCore.h>

#include "World.h"
#include "ChTextOutput.h"
#include "ChTextInput.h"
#include "ChWorldStream.h"
#include "ChSaveAs.h" 


#define 	PUEBLO_FORM_CMD   		TEXT( "PUEBLOFORM" )


#if defined( CH_PUEBLO_PLUGIN )
#include <AFXPRIV.H>
#include <ChSplit.h>
#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( ChWorldMainInfo* pInfo, ChTextOutput* pTextOutput,
						ChPane* pPane ) :
				ChTextOutputWnd( pInfo, pTextOutput ),
				m_pPane( pPane )
					{
					}
		virtual ~ChPaneOutWnd() {}

		virtual void OnFrameDisconnect( const ChModuleID& idNewModule );
		virtual void OnMouseUp();


	protected:
		ChPane*		m_pPane;
};


void ChPaneOutWnd::OnFrameDisconnect( const ChModuleID& idNewModule )
{
	DestroyWindow();
	delete this;
}


void ChPaneOutWnd::OnMouseUp()
{
	if (m_pPane && m_pPane->IsInternal())
	{										/* For panes within the main frame,
												we want to call the default
												OnMouseUp() method, which
												switches focus back to the
												input window */
		ChTextOutputWnd::OnMouseUp();
	}
}



/*----------------------------------------------------------------------------
	ChTextOutput class
----------------------------------------------------------------------------*/

chint16		ChTextOutput::m_sMinWidth;
chint16		ChTextOutput::m_sIdealWidth;
chint16		ChTextOutput::m_sMinHeight;
chint16		ChTextOutput::m_sIdealHeight;

ChTextOutput::ChTextOutput( ChWorldMainInfo* pMainInfo ) :
				m_pMainInfo( pMainInfo ),
				m_pOutWnd( 0 ),
				m_boolLogging( false ),
				m_boolShown( false )
{
	ChPane*		pPane;

	m_pOutWnd = new ChTextOutputWnd( GetMainInfo(), this );
	ASSERT( m_pOutWnd );

	m_pOutWnd->SetPaneMgr( GetMainInfo()->GetPaneMgr() );

	pPane = GetMainInfo()->GetPaneMgr()->FindPane( ChPaneMgr::strTextName );

											// Calculate sizing values
	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;

	UpdatePreferences();
	CreateOutputWindow();
}


ChTextOutput::~ChTextOutput()
{
	ChModuleID		idModule = GetMainInfo()->GetModuleID();

	if (IsShown())
	{
		Show( false );
	}
											// Clear all panes

	GetMainInfo()->GetPaneMgr()->ShowAllPanes( idModule, false );
	GetMainInfo()->GetPaneMgr()->DestroyAllPanes( idModule );

											// Destroy the window
	if (GetOutputWnd())
	{
		GetOutputWnd()->DestroyWindow();

		delete m_pOutWnd;
		m_pOutWnd = 0;
	}
}


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

	pPane = GetMainInfo()->GetPaneMgr()->FindPane( ChPaneMgr::strTextName );

	if (boolShow && !IsShown())
	{										// Show the window
		pPane->Show();
		m_boolShown = true;
	}
	else if (!boolShow && IsShown())
	{										// Hide the window
		pPane->Show( false );
		m_boolShown = false;
	}
}


void ChTextOutput::SetFocus()
{
	GetOutputWnd()->SetFocus();
}


void ChTextOutput::Clear()
{
	GetOutputWnd()->NewPage();
}


void ChTextOutput::Reset()
{
	ChWorldMainInfo*	pInfo = GetMainInfo();

	ASSERT( pInfo );
	pInfo->GetPaneMgr()->DestroyAllPanes( pInfo->GetModuleID(), false );
}


void ChTextOutput::Add( const string& strText, bool boolOutputToDebug )
{
	if (boolOutputToDebug && GetMainInfo()->IsConnected())
	{
		GetMainInfo()->GetCore()->Trace( strText, ChCore::traceHTML );
	}

	GetOutputWnd()->AppendText( strText );
}

void ChTextOutput::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 );
	}
}


void ChTextOutput::ToggleLogging()
{
	if (IsLogging())
	{										// Stop logging
		GetOutputWnd()->CloseFile();
		m_boolLogging = false;
	}
	else
	{										// Get logging file path
		bool		boolContinue = false;
		string		strFilePath;
		chflag32	flOptions;

		#if defined( CH_MSW )
		{
			boolContinue = GetLogFilePath( strFilePath, &flOptions );
		}
		#endif	// defined( CH_MSW )

		if (boolContinue)
		{									// Turn on logging
			SetLogging( strFilePath, flOptions );
		}
	}
}


bool ChTextOutput::SetLogging( const string& strFilepath, chflag32 flOptions )
{
	string		strWorkingFilepath;

	if (IsLogging())
	{										// Stop logging
		GetOutputWnd()->CloseFile();
	}

	if (-1 == strFilepath.Find( '\\' ))
	{
		string		strDefDir;
											/* Get the default directory for
												log files */

		ChUtil::GetAppDirectory( strWorkingFilepath );
		strWorkingFilepath += SAVE_LOG_DIR;
		strWorkingFilepath += "\\";
		strWorkingFilepath += strFilepath;
	}
	else
	{
		strWorkingFilepath = strFilepath;
	}
											// Open the new file

	m_boolLogging = GetOutputWnd()->WriteFile( strWorkingFilepath, flOptions );

	return m_boolLogging;
}


void ChTextOutput::UpdatePreferences()
{
}


#if !defined( CH_PUEBLO_PLUGIN )
bool ChTextOutput::CheckEditMenuItem( EditMenuItem item )
{
	bool	boolEnable;

	switch( item )
	{
		case editMenuCopy:
		{
			chint32 lStart, lEnd;

			GetOutputWnd()->GetSel( lStart, lEnd );

			boolEnable = lStart != lEnd;
			break;
		}

		case editMenuCut:
		case editMenuPaste:
		{
			boolEnable = false;
			break;
		}

		default:
		{
			boolEnable = false;
			break;
		}
	}

	return boolEnable;
}


void ChTextOutput::DoEditMenuItem( EditMenuItem item )
{
	switch( item )
	{
		case editMenuCopy:
		{
			GetOutputWnd()->CopyToClipboard();
			break;
		}
		case editMenuCut:
		case editMenuPaste:
		default:
		{
			break;
		}
	}
}

#endif // #if !defined( CH_PUEBLO_PLUGIN )

bool ChTextOutput::DoPaneCommand( ChPane::ChPaneCmd paneCmd,
									const char* pstrArgs )
{
	string		strWarning;

	LOADSTRING( IDS_WARNING_OLD_PANE_FORMAT, strWarning );
	GetMainInfo()->GetCore()->Trace( strWarning, ChCore::traceWarnings );

	switch( paneCmd )
	{
		case ChPane::paneOpen:
		{
			string		strURL;

			ChHtmlWnd::GetHTMLHref( pstrArgs, true, strURL );

			if (!strURL.IsEmpty())
			{ 
				ChWorldFileHTTPReq*		pLoadInfo;

				pLoadInfo = new ChWorldFileHTTPReq( GetMainInfo()->GetConnectID(), 
												GetOutputWnd()->GetSafeHwnd(),
												pstrArgs );

				GetMainInfo()->GetCore()->GetURL( strURL, 0, 
								GetMainInfo()->GetStream(), 
								(chparam)pLoadInfo  );
			}
			else
			{
				TRACE1( "Empty URL passed into "
						"ChTextOutput::DoPaneCommand : %s ", pstrArgs );
			}
			break;
		}

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

		default:
		{
			break;
		}
	}

	return true;
}


/*----------------------------------------------------------------------------
	ChTextOutput protected methods
----------------------------------------------------------------------------*/

void ChTextOutput::DoPaneOpen( const string& strFilename,
								const string& strMimeType,
								const string& strURL, const string& strHTML )
{
	bool				boolPaneAttrs;
	ChPaneMgr*			pPaneManager = GetMainInfo()->GetPaneMgr();
	ChPane*				pPane;
	ChPaneOutWnd*		pChild;
	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 = pPaneManager->FindPane( strPaneName )))
	{
		pPane = pPaneManager->CreatePane( strPaneName, 0, sIdealWidth,
											sIdealHeight, flPaneOptions );
		ASSERT( pPane );
	}

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

		pChild = new ChPaneOutWnd( GetMainInfo(), this, pPane );
		ASSERT( pChild );
											/* Create the new child using the
												pane frame window as the
												parent */
		#if defined( CH_MSW )

		if (flPaneOptions & paneInternal)
		{									/* Leave the border off of a banner
												pane child, since it shows up
												in a banner */

			dwPaneStyle = WS_VISIBLE | WS_VSCROLL;
		}
		else
		{
			dwPaneStyle = WS_VISIBLE | WS_BORDER | WS_VSCROLL;
		}

		if (boolCreated = pChild->Create( rtChild, pPane->GetFrameWnd(),
											dwPaneStyle ))
		{
			chint16		sBorderHorz = -1;
			chint16		sBorderVert = -1;
												// Take ownership of the pane

			pPane->SetOwner( GetMainInfo()->GetModuleID(), pChild, pChild );
			pPane->SetTitle( strPaneTitle );
			pPane->SetSizePrefs( sIdealWidth, sIdealHeight, sMinWidth,
									sMinHeight );

												/* Set view indents, if
													necessary */

			ChPane::GetPaneBorderAttrs( strHTML, sBorderHorz, sBorderVert );
			if ((sBorderHorz != -1) && (sBorderVert != -1))
			{
				ChRect		rtIndent;

				pChild->GetViewIndents( rtIndent );

				if (sBorderHorz != -1)
				{
					rtIndent.left = rtIndent.right = sBorderHorz;
				}

				if (sBorderVert != -1)
				{
					rtIndent.top = rtIndent.bottom = sBorderVert;
				}

				pChild->SetViewIndents( rtIndent );
			}
		}
		else

		#endif	// defined( CH_MSW )

		{
			delete pChild;
			GetMainInfo()->GetCore()->
				Trace( "ChTextOutput::DoPaneOpen : Error creating pane.",
						ChCore::traceMiscMessages );
		}
	}
	else
	{
		pChild = (ChPaneOutWnd*)pPane->GetWindow();
	}

	if (boolCreated)
	{										// Display the file

		pChild->DisplayFile( strFilename, strMimeType, ChHtmlWnd::fileReplace,
								strURL );
											/* Size the pane if necessary.  The
												pane is sized if it's either
												not sizeable, or if it hasn't
												been automatically sized to
												a previous size. */

		if (!pPane->IsSizeable() || !pPane->IsSized())
		{
			pPane->SetSize( sIdealWidth, sIdealHeight );
		}
											// Turn off scrolling if necessary
		if (pPane->IsNoScroll())
		{
			CRect	rtEdges( 0, 0, 0, 0 );

			pChild->AllowScroll( false, false );
			pChild->SetViewIndents( rtEdges );
		}
												// Finally show the pane
		pPane->Show();
	}
}


void ChTextOutput::DoPaneClose( const string& strHTML )
{
	bool					boolPaneAttrs;
	string					strPaneName;
	string					strPaneTitle;

	ASSERT( !strHTML.IsEmpty() );

	boolPaneAttrs = ChPane::GetPaneNameAttr( strHTML, strPaneName );

	ASSERT( boolPaneAttrs );

	if (!strPaneName.IsEmpty())
	{
		GetMainInfo()->GetPaneMgr()->DestroyPane( strPaneName );
	}
}


void ChTextOutput::CreateOutputWindow()
{
	ChRect			rtChild( -100, -100, -1, -1 );
	bool			boolCreated;
	ChPane*			pPane;
	string			strDummy;

	pPane = GetMainInfo()->GetPaneMgr()->FindPane( ChPaneMgr::strTextName );

											/* 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( GetMainInfo()->GetModuleID(), GetOutputWnd(),
						GetOutputWnd() );
	pPane->SetSizePrefs( m_sIdealWidth, m_sIdealHeight, m_sMinWidth,
							m_sMinHeight );
}


#if defined( CH_MSW )

bool ChTextOutput::GetLogFilePath( string& strFilePath, chflag32* pflOptions )
{
	bool			boolSuccess;
	ChLogSaveAsDlg	fileDlg;
	chflag32		flTempOptions;

	if (0 == pflOptions)
	{
		pflOptions = &flTempOptions;
	}

	ASSERT( 0 != pflOptions );

	*pflOptions = ChHtmlWnd::writeNew;

⌨️ 快捷键说明

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