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

📄 chtxtout.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:

		pWnd = new ChPaneOutWnd( GetWorldModuleID() );
		ASSERT( pWnd );

		pWnd->SetMainInfo( this );
		InstallOutputHooks( pWnd );
											/* Create the new child using the
												pane frame window as the
												parent */
		#if defined( CH_MSW )

		if (flPaneOptions & paneBanner)
		{									/* 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 = pWnd->Create( rtChild, pPane->GetFrameWnd(),
										dwPaneStyle ))
		{
												// Take ownership of the pane
			pPane->SetOwner( GetModuleID(), pWnd );
			pPane->SetTitle( strPaneTitle );
			pPane->SetSizePrefs( sIdealWidth, sIdealHeight, sMinWidth,
									sMinHeight );
		}
		else

		#endif	// defined( CH_MSW )

		{
			delete pWnd;
			TRACE( "ChTextOutMainInfo::DoPaneOpen : Error creating pane." );
		}
	}
	else
	{
		pWnd = (ChPaneOutWnd*)pPane->GetWindow();
	}

	if (boolCreated)
	{										// Display the file

		pWnd->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 );

			pWnd->AllowScroll( false, false );
			pWnd->SetViewIndents( rtEdges );
		}

		if (pPane->IsSizeToFit())
		{
			ChSize		size;

			pWnd->GetDocumentSize( size );

			pPane->SetSize( (chint16)size.cx +
								(2 * GetSystemMetrics( SM_CXBORDER )),
							(chint16)size.cy + 
								(2 * GetSystemMetrics( SM_CXBORDER )) );
		}
												// Finally show the pane
		pPane->Show();
	}
}


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

	ASSERT( !strHTML.IsEmpty() );

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

	ASSERT( boolPaneAttrs );

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


/*----------------------------------------------------------------------------
	ChTextOutMainInfo protected methods
----------------------------------------------------------------------------*/

void ChTextOutMainInfo::InstallOutputHooks( ChTextOutputWnd* pOutWnd,
												bool boolInstall )
{
	if (boolInstall)
	{										// Hook us into pOutWnd

		pOutWnd->InstallHook( CH_MSG_CMD, GetModuleID() );
		pOutWnd->InstallHook( CH_MSG_INLINE, GetModuleID() );
		pOutWnd->InstallHook( CH_MSG_HINT, GetModuleID() );
	}
	else
	{										// Unhook us from pOutWnd

		pOutWnd->UninstallHook( CH_MSG_CMD, GetModuleID() );
		pOutWnd->UninstallHook( CH_MSG_INLINE, GetModuleID() );
		pOutWnd->UninstallHook( CH_MSG_HINT, GetModuleID() );
	}
}


/*----------------------------------------------------------------------------
	ChTextOutMainInfo private methods
----------------------------------------------------------------------------*/

void ChTextOutMainInfo::CreateMenus()
{
	string			strText;
											/* Add our menu hooks to the
												standard edit menu */
	m_stdEditMenu.GetCopyItem()->
					SetHandler( OnTxtOutStdEditCopy )->SetData( (chparam)this );

	m_stdEditMenu.GetCutItem()->
					SetHandler( OnTxtOutStdEditCutPaste )->SetData( (chparam)this );
	m_stdEditMenu.GetPasteItem()->
					SetHandler( OnTxtOutStdEditCutPaste )->SetData( (chparam)this );

	m_boolMenus = true;
}


void ChTextOutMainInfo::InstallMenus()
{
	m_stdEditMenu.Install( CH_MODULE_TEXT_OUTPUT );

	m_boolMenusInstalled = true;
}


void ChTextOutMainInfo::UninstallMenus()
{
	m_stdEditMenu.Uninstall();

	m_boolMenusInstalled = false;
}


void ChTextOutMainInfo::DestroyMenus()
{
	m_boolMenus = false;
	m_boolMenusInstalled = false;
}

#endif	// !defined( CH_UNIX )


/*----------------------------------------------------------------------------
	ChTextOutputWnd class
----------------------------------------------------------------------------*/

ChTextOutputWnd::ChTextOutputWnd() :
					m_pTxtOutInfo( NULL )
{
	SetAnchorTarget( string( TEXT("_webtracker" ) ) );
}


ChTextOutputWnd::~ChTextOutputWnd()
{
}


/*----------------------------------------------------------------------------
	ChTextOutputWnd protected methods
----------------------------------------------------------------------------*/

void ChTextOutputWnd::OnSelectHotSpot( int x, int y, ChPoint& ptRel, chparam userData,
											const string& strDocURL )
{
	const char* pstrArgs = (const char*)userData;

											/* Notification on hotspot
												selection */
	if (pstrArgs)
	{
		ChPane::ChPaneCmd		paneCmd;
											/* Check to see if this is a pane
												anchor.  If it is, send it to
												the pane command handler. */

		if (ChPane::GetPaneCmdAttr( pstrArgs, paneCmd ))
		{
			GetMainInfo()->DoPaneCommand( paneCmd, pstrArgs );
		}
		else
		{									/* Otherwise send the anchor
												through the hook chain */

			ChCmdMsg			msg( pstrArgs, ptRel.x, ptRel.y );
			ChSetFocusMsg		setFocusMsg;
//			ChClientModule*		pTextInModule;

			#if defined( CH_DEBUG )
			{
				string		strDump( pstrArgs );

				if (strDump.GetLength() > 150)
				{
					strDump = strDump.Left( 150 );
					strDump += " [...]";
				}

				TRACE1( "HTML Hot spot: %s\n", (const char*)strDump );
			}
			#endif	// defined( CH_DEBUG )

			DoHook( msg );

			if (msg.IsProcessed())
			{								/* Stop formatting and abort all
												requests generated by this
												page */
				AbortFormatting();
#if 0
											/* Set focus back to the input
												window */

				pTextInModule = GetMainInfo()->GetTextInModule();
				if (0 != pTextInModule)
				{
					pTextInModule->Post( setFocusMsg );
				}
#endif
			}
			else
			{								/* The selection of a hot spot was
												not processed, check if there
												is a HREF, if it does then
												launch the Web browser if we
												have a valid URL */
			   	string		strValue;

				if (ChHtmlWnd::GetHTMLAttribute( pstrArgs, ATTR_HREF,
													strValue ))
				{
					string		strTarget;

					ChHtmlWnd::GetHTMLAttribute( pstrArgs, ATTR_TARGET,
													strTarget );
					if (IsTargetSelfOutput( strTarget ))
					{
						ChHtmlWnd::OnSelectHotSpot( x, y, ptRel, userData,
													strDocURL );
					}
					else
					{
						ChURLParts		urlMap;

						if (urlMap.GetURLParts( strValue, strDocURL ))
						{
							ChClientModule	coreModule( ChClientModule::GetCoreID() );
							ChLoadFileMsg	loadMsg( urlMap.GetURL() );
						
											// Load the web page 

							coreModule.Send( loadMsg );
						}
					}
				}
			}
		}
	}
}

void ChTextOutputWnd::OnSubmitForm( const string& strFormData )
{
	// submit the HTML form
	ChCmdMsg			msg( strFormData, -1, -1 );

	DoHook( msg );
}



void ChTextOutputWnd::OnHotSpot( chparam userData, const string& strDocURL )
{
	char*	pstrCmd;

	if (userData)
	{
		pstrCmd = (char*)userData;
	}
	else
	{
		pstrCmd = "";
	}

	ChHintMsg	msg( pstrCmd );

	DoHook( msg );
}


bool ChTextOutputWnd::OnInline( const char* pstrArgs, const string& strDocURL )
{
	bool	boolProcessed = false;

	if (pstrArgs)
	{
		ChPane::ChPaneCmd		paneCmd;
											/* Check to see if this is a pane
												inline.  If it is, send it to
												the pane command handler. */

		if (ChPane::GetPaneCmdAttr( pstrArgs, paneCmd ))
		{
			boolProcessed = GetMainInfo()->DoPaneCommand( paneCmd, pstrArgs );
		}
		else
		{									/* Otherwise send the inline
												through the hook chain */
			ChInlineMsg	msg( pstrArgs );

			DoHook( msg );
			boolProcessed = msg.IsProcessed();
		}
	}

	return boolProcessed;
}


void ChTextOutputWnd::OnLoadImage( const char* pstrURL, ChObjInline *pImage,
									const string& strDocURL )
{
											/* called when there is a inline
												image to be loaded */

	ChHtmlWnd::OnLoadImage( pstrURL, pImage, strDocURL );
}


#ifndef CH_UNIX

BEGIN_MESSAGE_MAP( ChTextOutputWnd, ChHtmlWnd )
	//{{AFX_MSG_MAP(ChTextOutputWnd)
	ON_WM_KILLFOCUS()
	ON_WM_SETFOCUS()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/*----------------------------------------------------------------------------
	ChTextOutputWnd message handlers
----------------------------------------------------------------------------*/

void ChTextOutputWnd::OnKillFocus( CWnd* pNewWnd )
{
	ChTextOutMainInfo*	pMainInfo = GetMainInfo();

	ChHtmlWnd::OnKillFocus( pNewWnd );

	if (pMainInfo && pMainInfo->IsMenuInstalled())
	{
		ChEditMenu*		pStdEditMenu;
											/* Demote our window (we no longer
												care about the Copy
												menu messages) */

		if (pStdEditMenu = pMainInfo->GetStdEditMenu())
		{
			pStdEditMenu->Promote( false );
		}
	}
}


void ChTextOutputWnd::OnSetFocus( CWnd* pOldWnd )
{
	ChTextOutMainInfo*	pMainInfo = GetMainInfo();

	ChHtmlWnd::OnSetFocus( pOldWnd );

	if (pMainInfo && pMainInfo->IsMenuInstalled())
	{
											/* Promote our window (we want to
												get the Copy menu
												messages first) */
		pMainInfo->GetStdEditMenu()->Promote();
	}
}


void ChTextOutputWnd::OnPaletteChanged(CWnd* pFocusWnd)
{
    // See if the change was caused by us and ignore it if not.
    if (pFocusWnd != this) {
        OnQueryNewPalette();
    }
}

// Note: Windows actually ignores the return value.
BOOL ChTextOutputWnd::OnQueryNewPalette()
{
	CDC* pdc = GetDC();
	UINT u = pdc->RealizePalette();
	ReleaseDC(pdc);
	if (u != 0) 
	{
		// Some colors changed so we need to do a repaint.
		InvalidateRect(NULL, true); // Repaint the lot.
		return true; // Say we did something.
	}
	return false; // Say we did nothing.
}

#endif // !CH_UNIX

/*----------------------------------------------------------------------------
	Chaco message handlers
----------------------------------------------------------------------------*/

CH_IMPLEMENT_MESSAGE_HANDLER( defTextOutHandler )
{
	chparam		retVal = 0;

	return retVal;
}

CH_IMPLEMENT_MESSAGE_HANDLER( textOutInitHandler )
{
	ChTextOutMainInfo*	pInfo = (ChTextOutMainInfo*)pMainInfo;

	pInfo->Initialize();
	return 0;
}


CH_IMPLEMENT_MESSAGE_HANDLER( textOutLoadCompleteHandler )
{
	ChTextOutMainInfo*	pInfo = (ChTextOutMainInfo*)pMainInfo;
	ChLoadCompleteMsg*	pMsg = (ChLoadCompleteMsg*)&msg;
	string				strModuleName;
	ChModuleID			idModule;
	string				strFilename;
	chparam				userData;

	pMsg->GetParams( strModuleName, idModule, strFilename, userData );

#if 0
	if (CH_MODULE_TEXT_INPUT == strModuleName)
	{
		pInfo->SetTextInID( idModule );
	}
	else

⌨️ 快捷键说明

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