📄 chtextoutput.cpp
字号:
boolSuccess = (IDOK == fileDlg.DoModal());
if (boolSuccess)
{ // Cool -- they pressed okay
strFilePath = fileDlg.GetPathName();
if (fileDlg.IsHTML())
{
*pflOptions |= ChHtmlWnd::writeHTML;
}
if (fileDlg.IsEntireBuffer())
{
*pflOptions |= ChHtmlWnd::writeAll;
}
}
return boolSuccess;
}
#endif // defined( CH_MSW )
/*----------------------------------------------------------------------------
ChTextOutputWnd class
----------------------------------------------------------------------------*/
ChTextOutputWnd::ChTextOutputWnd( ChWorldMainInfo* pInfo,
ChTextOutput* pTextOutput ) :
#if defined( CH_PUEBLO_PLUGIN )
ChHtmlWnd( pInfo->GetCore()->GetHTTPConn() ),
#endif
m_pMainInfo( pInfo ),
m_pTextOutput( pTextOutput )
{
SetAnchorTarget( string( TEXT("_webtracker" ) ) );
SetBufferLimit( 0x7FFF ); // 32k of text
}
ChTextOutputWnd::~ChTextOutputWnd()
{
DestroyWindow();
}
void ChTextOutputWnd::GetIdealSize( ChSize& size )
{
GetDocumentSize( size );
}
void ChTextOutputWnd::OnMouseUp()
{
if (GetMainInfo()->GetTextInput()->IsShown())
{
chint32 lStart, lEnd;
GetSel( lStart, lEnd );
if (lStart == lEnd)
{
GetMainInfo()->GetTextInput()->SetFocus();
}
}
}
/*----------------------------------------------------------------------------
ChTextOutputWnd protected methods
----------------------------------------------------------------------------*/
bool 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 ))
{
GetTextOutput()->DoPaneCommand( paneCmd, pstrArgs );
}
else
{ /* Otherwise send the anchor
through the hook chain */
bool boolProcessed;
#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 )
boolProcessed = GetMainInfo()->DoCommand( pstrArgs, ptRel.x,
ptRel.y );
if (boolProcessed)
{ /* Set focus back to the input
window */
GetMainInfo()->GetTextInput()->SetFocus();
}
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 ))
{
return ChHtmlWnd::OnSelectHotSpot( x, y, ptRel, userData,
strDocURL );
}
else
{
ChURLParts urlMap;
if (urlMap.GetURLParts( strValue, strDocURL ))
{
OnRedirect( urlMap.GetURL(), false );
}
}
}
}
}
}
return true;
}
bool ChTextOutputWnd::OnRedirect( const string& strURL, bool boolWebTracker )
{
GetMainInfo()->GetCore()->DisplayWebPage( strURL, boolWebTracker
? ChCore::browserWebTracker
: ChCore::browserUserPref );
return true;
}
void ChTextOutputWnd::OnSubmitForm( const string& strAction, const string& strMD5,
const string& strFormData )
{
// Data is of the form:
// xch_cmd="action?formdata"
string strCommand( TEXT( "xch_cmd=" ) );
// quote the data we pass
strCommand += TEXT( '"' );
if (strAction.IsEmpty() || strMD5.IsEmpty() ||
!GetMainInfo()->VerifyMD5( strMD5 ))
{ /* This is not secure, we allow
only PUEBLO form command */
if (strAction.IsEmpty() || lstrcmpi( strAction, PUEBLO_FORM_CMD ))
{
string strMsg;
strMsg.Format( "Invalid form action : %s", LPCSTR(strAction) );
OnTrace( strMsg, ChHtmlWnd::traceWarning );
}
strCommand += PUEBLO_FORM_CMD;
}
else
{ /* MD5 matches, we will allow any
command specified */
strCommand += strAction;
}
strCommand += TEXT( " ?" );
strCommand += strFormData;
strCommand += TEXT( '"' );
GetMainInfo()->DoCommand( strCommand );
}
void ChTextOutputWnd::OnLoadComplete( const string& strFile,
const string& strURL,
const string& strMimeType,
chparam userData )
{
/* Set the window to not scroll
to the end, and to have no
text limit */
ShowAppend( false );
SetBufferLimit( 0 );
GetMainInfo()->SetCurrentURL( strURL );
GetMainInfo()->SetLoadPending( false );
// Load the file to display
ChHtmlWnd::OnLoadComplete( strFile, strURL, strMimeType, userData );
}
// called when load error occurs for user requested URLs only.
void ChTextOutputWnd::OnLoadError( chint32 lError, const string& strErrMsg,
const string& strURL, chparam userData )
{
GetMainInfo()->SetLoadPending( false );
string strErrorCaption;
LOADSTRING( IDS_LOAD_ERROR_CAPTION, strErrorCaption );
GetMainInfo()->GetCore()->GetFrameWnd()->MessageBox( strErrMsg,
strErrorCaption );
}
void ChTextOutputWnd::OnTrace( const string& strMsg, int iType )
{
GetMainInfo()->GetCore()->Trace( strMsg, iType == traceError
? ChCore::traceErrors
: ChCore::traceWarnings,
true );
}
void ChTextOutputWnd::OnHotSpot( chparam userData, const string& strDocURL )
{
char* pstrCmd;
if (userData)
{
pstrCmd = (char*)userData;
}
else
{
pstrCmd = "";
}
GetMainInfo()->DoHint( pstrCmd );
}
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 = GetTextOutput()->DoPaneCommand( paneCmd, pstrArgs );
}
else
{ // Otherwise process the inline
boolProcessed = GetMainInfo()->DoInline( pstrArgs );
}
}
return boolProcessed;
}
void ChTextOutputWnd::DoPopupMenu( CPoint point, const string& strWindowName )
{
m_strMenuWindow = strWindowName;
#if defined( CH_MSW )
{
#if defined( CH_PUEBLO_PLUGIN )
HINSTANCE hModule = AfxGetInstanceHandle();
#else
HINSTANCE hModule = ChWorldDLL.hModule;
#endif
HINSTANCE hInstOld = AfxGetResourceHandle();
CMenu menuLoaded;
CMenu menuPopup;
AfxSetResourceHandle( hModule );
#if !defined( CH_PUEBLO_PLUGIN )
menuLoaded.LoadMenu( ID_MENU_LOG );
#else
menuLoaded.LoadMenu( IDR_MAINFRAME );
#endif
// Restore the old resource chain
AfxSetResourceHandle( hInstOld );
menuPopup.Attach( menuLoaded.GetSubMenu( 0 )->GetSafeHmenu() );
#if !defined( CH_PUEBLO_PLUGIN )
chflag32 flEnable;
bool boolConnected = GetMainInfo()->IsConnected();
chint32 lStart;
chint32 lEnd;
// Enable & disable items
menuPopup.EnableMenuItem( ID_MENU_WORLD_ADD,
boolConnected ? MF_ENABLED : MF_GRAYED );
GetSel( lStart, lEnd, GetMenuWindow() );
flEnable = (lStart != lEnd) ? MF_ENABLED : MF_GRAYED;
menuPopup.EnableMenuItem( ID_EDIT_COPY, flEnable );
flEnable = ((lStart != lEnd) && boolConnected) ? MF_ENABLED :
MF_GRAYED;
menuPopup.EnableMenuItem( ID_EDIT_COPY_TO_INPUT, flEnable );
#endif
// Display the menu
ClientToScreen( &point );
menuPopup.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON,
point.x, point.y, this, 0 );
}
#else // defined( CH_MSW )
{
#pragma message( "Popup menu not defined for this platform." )
}
#endif // defined( CH_MSW )
}
#ifndef CH_UNIX
BEGIN_MESSAGE_MAP( ChTextOutputWnd, ChHtmlWnd )
//{{AFX_MSG_MAP(ChTextOutputWnd)
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
ON_WM_KEYDOWN()
#if defined( CH_PUEBLO_PLUGIN )
ON_WM_INITMENUPOPUP()
ON_WM_MENUSELECT()
#endif
//}}AFX_MSG_MAP
ON_MESSAGE( WM_MODULE_HTTP_REQ_MSG, OnHTTPLoadComplete )
ON_MESSAGE( WM_EXECUTE_PUEBLO_SCRIPT, OnExecuteScript )
END_MESSAGE_MAP()
/*----------------------------------------------------------------------------
ChTextOutputWnd message handlers
----------------------------------------------------------------------------*/
#if defined( CH_PUEBLO_PLUGIN )
void ChTextOutputWnd::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
ChHtmlWnd ::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
// TODO: Add your message handler code here
if ( 0 == nIndex && pPopupMenu->GetMenuItemCount() > 2 )
{
bool boolConnected = GetMainInfo()->IsConnected();
chflag32 flEnable;
chint32 lStart;
chint32 lEnd;
pPopupMenu->EnableMenuItem( ID_MENU_WORLD_ADD,
boolConnected ? MF_ENABLED : MF_GRAYED );
GetSel( lStart, lEnd, GetMenuWindow() );
flEnable = (lStart != lEnd) ? MF_ENABLED : MF_GRAYED;
pPopupMenu->EnableMenuItem( ID_EDIT_COPY, flEnable );
flEnable = ((lStart != lEnd) && boolConnected) ? MF_ENABLED :
MF_GRAYED;
pPopupMenu->EnableMenuItem( ID_EDIT_COPY_TO_INPUT, flEnable );
flEnable= (!GetMainInfo()->IsLoadPending() &&
!GetMainInfo()->IsTopLevelWorldList() &&
!boolConnected )
? MF_ENABLED : MF_GRAYED;
pPopupMenu->EnableMenuItem( ID_VIEW_PREVIOUS, flEnable );
flEnable = GetMainInfo()->GetCore()->GetSplitter()->GetPaneCount() > 1
? MF_ENABLED : MF_GRAYED;
pPopupMenu->EnableMenuItem( ID_VIEW_TOGGLE_ORIENTATION, flEnable );
pPopupMenu->EnableMenuItem( ID_VIEW_SWAP_PANES, flEnable );
pPopupMenu->EnableMenuItem( ID_WORLD_LOG_TO_FILE,
boolConnected ? MF_ENABLED : MF_GRAYED );
if ( boolConnected && GetMainInfo()->GetTextOutput()->IsLogging() )
{
pPopupMenu->CheckMenuItem( ID_WORLD_LOG_TO_FILE, MF_CHECKED | MF_BYCOMMAND );
}
//pPopupMenu->EnableMenuItem( ID_WORLD_EDIT_PERSONAL, flEnable );
pPopupMenu->EnableMenuItem( ID_MENU_WORLD_ADD,
boolConnected ? MF_ENABLED : MF_GRAYED );
pPopupMenu->EnableMenuItem( ID_WORLD_DISCONNECT,
boolConnected ? MF_ENABLED : MF_GRAYED );
}
}
void ChTextOutputWnd::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
ChHtmlWnd ::OnMenuSelect(nItemID, nFlags, hSysMenu);
// TODO: Add your message handler code here
GetMainInfo()->GetCore()->GetFrameWnd()->
SendMessage( WM_SETMESSAGESTRING, nItemID );
}
#endif // #if defined( CH_PUEBLO_PLUGIN )
bool ChTextOutputWnd::OnCommand( WPARAM wParam, LPARAM lParam )
{
bool boolProcessed = true;
switch( wParam )
{
case ID_EDIT_COPY:
case ID_EDIT_COPY_TO_INPUT:
{
CopyToClipboard( GetMenuWindow() );
if (ID_EDIT_COPY_TO_INPUT == wParam)
{
ASSERT( GetMainInfo()->GetTextInput()->IsShown() );
GetMainInfo()->GetTextInput()->Paste();
GetMainInfo()->GetTextInput()->SetFocus();
SetSel( 0, 0 );
}
break;
}
case ID_MENU_WORLD_ADD:
{
GetMainInfo()->AddCurrentWorld();
break;
}
#if defined( CH_PUEBLO_PLUGIN )
case ID_VIEW_PREVIOUS :
{
GetMainInfo()->DoPreviousURL();
break;
}
case ID_WORLD_EDIT_PERSONAL :
{
GetMainInfo()->EditPersonalWorldList();
break;
}
case ID_WORLD_SHORTCUT :
{
if (GetMainInfo()->IsConnected())
{
GetMainInfo()->CreateCurrentWorldShortcut();
}
else
{
GetMainInfo()->CreateShortcut();
}
break;
}
case ID_WORLD_DISCONNECT :
{
GetMainInfo()->ShutdownWorld();
break;
}
case ID_WORLD_LOG_TO_FILE :
{
GetMainInfo()->GetTextOutput()->ToggleLogging();
break;
}
case ID_VIEW_TOGGLE_ORIENTATION :
{
GetMainInfo()->GetCore()->GetSplitter()->TogglePaneOrientation();
break;
}
case ID_VIEW_SWAP_PANES :
{
GetMainInfo()->GetCore()->GetSplitter()->SwapPanes();
break;
}
default:
{
return GetMainInfo()->GetCore()->GetFrameWnd()->
SendMessage( WM_COMMAND, wParam, lParam );
}
#else
default:
{
boolProcessed = false;
break;
}
#endif
}
return boolProcessed;
}
void ChTextOutputWnd::OnKillFocus( CWnd* pNewWnd )
{
ChHtmlWnd::OnKillFocus( pNewWnd );
GetMainInfo()->SetFocusTarget( focusTextOutput, false );
}
void ChTextOutputWnd::OnSetFocus( CWnd* pOldWnd )
{
ChHtmlWnd::OnSetFocus( pOldWnd );
GetMainInfo()->SetFocusTarget( focusTextOutput, true );
}
void ChTextOutputWnd::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
{
ChHtmlWnd::OnKeyDown( nChar, nRepCnt, nFlags );
if ('C' == nChar)
{
if (GetKeyState( VK_CONTROL ) & 0x8000)
{
// Ctrl + C
if (GetMainInfo()->GetTextInput()->IsShown())
{
GetMainInfo()->GetTextInput()->SetFocus();
SetSel( 0, 0 );
}
}
}
}
/*----------------------------------------------------------------------------
This method called when HTTP posts a message
----------------------------------------------------------------------------*/
LONG ChTextOutputWnd::OnHTTPLoadComplete( UINT wParam, LONG lParam )
{
ChWorldFileHTTPReq* pLoadInfo = (ChWorldFileHTTPReq*)lParam;
if ( pLoadInfo->GetReqID() != GetMainInfo()->GetConnectID()
|| !GetMainInfo()->IsConnected() )
{ // Too late to use the request
delete pLoadInfo;
return 0;
}
if ( wParam == 0 )
{
GetTextOutput()->LoadFile( pLoadInfo->GetFileName(), pLoadInfo->GetURL(),
pLoadInfo->GetHTML(), pLoadInfo->GetMimeType() );
}
else
{ // Display error message
string strErrorCaption;
LOADSTRING( IDS_LOAD_ERROR_CAPTION, strErrorCaption );
GetMainInfo()->GetCore()->GetFrameWnd()->MessageBox( pLoadInfo->GetErrorMsg(),
strErrorCaption );
}
delete pLoadInfo;
return 0;
}
/*----------------------------------------------------------------------------
This method called when onEnhanced mud sends a script
----------------------------------------------------------------------------*/
LONG ChTextOutputWnd::OnExecuteScript( UINT wParam, LONG lParam )
{
char* pstrFile = (char*)lParam;
if ( wParam == 0 )
{
ChWorldScript* pWorldScript = new ChWorldScript( GetMainInfo() );
ASSERT( pWorldScript );
pWorldScript->ProcessScript( pstrFile );
delete pWorldScript;
}
delete []pstrFile;
return 0;
}
#endif // !CH_UNIX
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -