📄 chpanmod.cpp
字号:
m_pPendingViewers->Insert( type, pViewer );
}
ChViewerMsgDispatch * ChGraphicPaneInfo::GetMimeViewer( string strType )
{
ChModuleID id;
return GetMimeViewer(strType, id);
}
ChViewerMsgDispatch * ChGraphicPaneInfo::GetMimeViewer( string strType, ChModuleID &id)
{
ChViewerMsgDispatch* pViewer = 0;
ChHTTPConn::tagMimeTypes type;
ChGraphicViewer** ppViewerDef;
type = (ChHTTPConn::tagMimeTypes)ChHTTPConn::GetMimeType( strType );
if (m_pViewers)
{
ppViewerDef = m_pViewers->Find( type );
if (ppViewerDef)
{
pViewer = (*ppViewerDef)->GetModule();
id = (*ppViewerDef)->GetModuleID();
}
}
return pViewer;
}
// Answer whether a mime type has an outstanding load of a viewer module, and also
// return the name of the module if pstrViewer is not null
bool ChGraphicPaneInfo::IsMimeViewerPending( string strType, string *pstrViewer /*= 0*/ )
{
ChHTTPConn::tagMimeTypes type = (ChHTTPConn::tagMimeTypes)ChHTTPConn::GetMimeType(strType);
ChGraphicViewer ** ppViewerDef;
if (m_pPendingViewers)
{
ppViewerDef = m_pPendingViewers->Find(type);
if (ppViewerDef && pstrViewer)
{
// they wanna know the name
*pstrViewer = (*ppViewerDef)->GetModuleName();
}
}
return (ppViewerDef != 0);
}
// Load commands to be sent to viewer
bool ChGraphicPaneInfo::Load( ChGraphicDocumentHTTPReq *pReq, ChViewerMsgDispatch* pViewer /* = 0*/,
ChModuleID id /* = 0 */ )
{
string strURL = pReq->GetURL();
string strFilename = pReq->GetFilename();
string strType = pReq->GetMimeType();
return Load( pReq, strURL, strFilename, strType, pViewer, id );
}
// This function assumes we definitely have a viewer for the mime type
bool ChGraphicPaneInfo::Load( ChGraphicDocumentHTTPReq *pReq, const string &strURL,
const string &strFilename, const string &strType, ChViewerMsgDispatch* pViewer /* = 0*/,
ChModuleID id /* = 0 */ )
{
if(!pViewer || !id)
{
pViewer = GetMimeViewer( strType, id );
}
bool boolSuccess = false;
if(pViewer)
{
ChViewerMsgDispatch *pOldViewer = 0;
if(id != GetCurrentViewerID())
{
SetCurrentViewer(pViewer, id);
}
int iOptions = pReq->GetNotificationOption();
ChSceneMsg sceneMsg(strURL, strFilename, strType, true, chparam(pReq));
pViewer->Send(sceneMsg);
//DoQueuedCommands(pReq); // take care of any queued commands
boolSuccess = true;
}
SetSuspendedLoad(0);
return boolSuccess;
}
bool ChGraphicPaneInfo::IsGraphicViewer(ChModuleID idModule)
{
return (idModule == m_idMazeModule || idModule == m_idMazeModule);
}
#if 0
void ChGraphicPaneInfo::OnParseComplete(string &strURL, chparam data)
{
ChGraphicDocumentHTTPReq* pReq = (ChGraphicDocumentHTTPReq* )data;
DoQueuedCommands(pReq); // take care of any queued commands
}
#endif
///////////////////////////////////////////////////////////////////////////////
////////////////////////////// Handlers //////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
CH_IMPLEMENT_MESSAGE_HANDLER( paneInitHandler )
{
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
pInfo->Initialize();
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( paneLoadCompleteHandler )
{
ChLoadCompleteMsg* pMsg = (ChLoadCompleteMsg*)&msg;
string strURL;
string strFilename;
chparam userData;
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
string strModuleName;
ChModuleID idModule;
// Get message params
pMsg->GetParams( strModuleName, idModule, strFilename, userData );
if ("" == strModuleName)
{ // Not a module, must be data
pMsg->GetParams( strURL, strFilename, userData );
// TODO handle loading real stuff
ChGraphicHTTPReq *pHTTPReq = (ChGraphicHTTPReq *)userData;
TRACE( "MESSAGE: CH_MSG_LOAD_COMPLETE (Graphics Pane Mgr)\n" );
TRACE1( " %s ->\n", (const char*)strURL );
TRACE1( " %s\n", (const char*)strFilename );
switch (pHTTPReq->GetType())
{
case ChGraphicHTTPReq::document:
{ /* Find out the mime type, and send
the load msg on to the proper
viewer */
ChGraphicDocumentHTTPReq *pReq = (ChGraphicDocumentHTTPReq *)pHTTPReq;
if (!pReq->IsCancelled())
{
string strType = pMsg->GetType();
string strViewerName;
ChModuleID idViewer;
ChViewerMsgDispatch* pViewer;
pViewer = pInfo->GetMimeViewer( strType, idViewer );
pInfo->SetPendingLoad( 0 );
if (pViewer)
{
pInfo->Load( pReq, strURL, strFilename, strType, pViewer, idViewer );
//delete pReq; // it's done, altho it may have spawned more ?????????????????
}
else if (pInfo->IsMimeViewerPending( strType, &strViewerName ))
{
TRACE2("Awaiting arrival of viewer '%s' for mime type '%s'\n", strViewerName, strType);
pReq->SetFile( strURL, strFilename, strType );
pInfo->SetSuspendedLoad(pReq); // awaiting the arrival of a viewer
}
else
{
// no viewer configured; do nothing
TRACE1("No viewer configured for mime type '%s'!\n", strType);
delete pReq; // it's done, altho it may have spawned more
}
}
else
{
// Trash it
TRACE1("Graphics file load pre-empted: %s\r", LPCTSTR(strFilename));
delete pReq; // it's done, altho it may have spawned more
}
break;
}
default:
{
break;
}
}
}
else
{
if(CH_MODULE_GRAPHICS_ANIMATION == strModuleName)
{
pInfo->m_idAnimModule = idModule; // i confess
pInfo->RegisterViewer(strModuleName, idModule);
}
else if(CH_MODULE_GRAPHICS_MAZE == strModuleName)
{
pInfo->m_idMazeModule = idModule;
pInfo->RegisterViewer(strModuleName, idModule);
}
}
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( paneLoadErrorHandler )
{
ChLoadErrorMsg* pMsg = (ChLoadErrorMsg*)&msg;
string strURL;
string strModuleName;
string strError;
ChModuleID idModule;
chint32 lError;
chparam userData;
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
// Get message params
pMsg->GetParams( strModuleName, idModule, strURL, lError, userData, strError );
ChGraphicHTTPReq *pHTTPReq = (ChGraphicHTTPReq *)userData;
// Clean up
if(pInfo->GetPendingLoad() == pHTTPReq) pInfo->SetPendingLoad(0);
delete pHTTPReq;
// Send to trace window
string strMsg;
if(strError.IsEmpty())
{
strMsg.Format("URL Load Failed: Error number %ld\n", lError);
}
else
{
strMsg.Format("URL Load Failed: %s\n", strError);
}
pInfo->GetCore()->Trace( strMsg, ChCore::traceErrors, true );
// Tell the viewer it's ok to animate now
ChViewerMsgDispatch* pViewer = pInfo->GetCurrentViewer();
if(pViewer)
{
// probably a bug for 2 d - We really need a resume and suspend message
ChPlayGraphicMsg restartPlayingRightNow(0, true, ChPlayGraphicMsg::immediate);
pViewer->Send(restartPlayingRightNow);
}
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( paneLoadImageHandler )
{
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
// for now, assumes URL is just a file
// !!!!!!!!!!!!
#if 0
ChImageMsg *pMsg = (ChImageMsg *)&msg;
string strURL;
pMsg->GetParams(strURL);
// load a VRML URL
ChGraphicBackgroundHTTPReq *pHTTPReq = new ChGraphicBackgroundHTTPReq ( pInfo->GetView(), strURL );
pInfo->GetHTTPConn()->GetURL( strURL, (chparam)pHTTPReq );
pInfo->SetLeafDependent(pHTTPReq);
#endif
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( paneCmdHookHandler )
{
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
ChCmdMsg *pMsg = (ChCmdMsg *)&msg;
string strArgs;
pMsg->GetParams(strArgs);
ChModuleID idOrigin = msg.GetOriginModule();
if(pInfo->IsGraphicViewer(idOrigin))
{
/* If this is a graphic viewer
controlled by us, pass its cmd
message on to our hook chain */
ChCmdMsg newMsg(strArgs);
bool boolProcessed = false;
pInfo->GetCmdHookMgr()->Dispatch( newMsg, boolProcessed );
}
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( paneImageHookHandler )
{
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
ChInlineMsg *pMsg = (ChInlineMsg *)&msg;
string strArgs;
pMsg->GetParams(strArgs);
//xch_graph="load" href="http://www.chaco.com/pueblo/0.6/ChAnim/msw32/pueblo.wrl>"
// xch_module="load" xch_module_name="Chaco VRML Module" xch_module_name_base="ChGraphx">
// xch_graph="load" href="http://www.chaco.com/pueblo/0.6/ChAnim/msw32/pueblo.wrl>
// xch_graph="light 1 .5">
string strValue;
// Respond to hooked img messages
if (ChHtmlWnd::GetHTMLAttribute( strArgs, CH_GRAPH_CMD, strValue ) ||
ChHtmlWnd::GetHTMLAttribute( strArgs, CH_GRAPH_CMD_NODE, strValue ) ||
ChHtmlWnd::GetHTMLAttribute( strArgs, CH_EVENT_NOTIFY, strValue ))
{
// Do it
if(pInfo->DoCommand( strArgs ))
{
msg.SetProcessed(true);
}
}
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( paneLoadSceneHandler )
{
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
ChSceneMsg *pMsg = (ChSceneMsg *)&msg;
string strURL, strFilename, strType;
bool boolNew;
pMsg->GetParams(strURL, strFilename, strType, boolNew);
// Load a file of something
// Needs to prempt in-progress load
ChGraphicDocumentHTTPReq *pHTTPReq = new ChGraphicDocumentHTTPReq ( pMainInfo->GetModuleID(), strURL );
if (pInfo->GetPendingLoad())
{
pInfo->GetPendingLoad()->Cancel();
pInfo->SetPendingLoad( 0 );
}
pInfo->SetPendingLoad( pHTTPReq );
pInfo->GetCore()->GetURL( strURL, 0, pInfo->GetStream(), (chparam)pHTTPReq );
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( paneShowModuleHandler )
{
ChShowModuleMsg* pMsg = (ChShowModuleMsg*)&msg;
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
pInfo->ShowModule( pMsg->IsShowing() );
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( paneResetHandler )
{
ChResetMsg* pMsg = (ChResetMsg*)&msg;
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
if (pInfo->GetCurrentViewer())
{
ChResetMsg msg;
pInfo->GetCurrentViewer()->Send( msg );
}
pInfo->SetCurrentViewer(0,0);
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( paneInstallHookHandler )
{
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
ChInstallHookMsg* pMsg = (ChInstallHookMsg*)&msg;
ChHookManager* pHookMgr;
ChModuleID idHookModule;
chint32 lMessage;
pMsg->GetParams( idHookModule, lMessage );
//ASSERT( 0 == lMessage || CH_MSG_CMD == lMessage || CH_MSG_INLINE == lMessage);
switch(lMessage)
{
case CH_MSG_CMD:
{
pHookMgr = pInfo->GetCmdHookMgr();
pHookMgr->Install( idHookModule );
break;
}
case CH_MSG_INLINE:
{
pHookMgr = pInfo->GetImageHookMgr();
pHookMgr->Install( idHookModule );
break;
}
}
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( panePromoteHookHandler )
{
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
ChPromoteHookMsg* pMsg = (ChPromoteHookMsg*)&msg;
ChHookManager* pHookMgr;
ChModuleID idHookModule;
bool boolPromote;
chint32 lMessage;
pMsg->GetParams( idHookModule, boolPromote, lMessage );
//ASSERT( 0 == lMessage || CH_MSG_CMD == lMessage || CH_MSG_INLINE == lMessage);
switch(lMessage)
{
case CH_MSG_CMD:
{
pHookMgr = pInfo->GetCmdHookMgr();
pHookMgr->Promote( idHookModule, boolPromote );
break;
}
case CH_MSG_INLINE:
{
pHookMgr = pInfo->GetImageHookMgr();
pHookMgr->Promote( idHookModule, boolPromote );
break;
}
case 0:
{
pHookMgr = pInfo->GetCmdHookMgr();
pHookMgr->Promote( idHookModule, boolPromote );
pHookMgr = pInfo->GetImageHookMgr();
pHookMgr->Promote( idHookModule, boolPromote );
break;
}
default:
break;
}
return 0;
}
CH_IMPLEMENT_MESSAGE_HANDLER( paneUninstallHookHandler )
{
ChGraphicPaneInfo* pInfo = (ChGraphicPaneInfo*)pMainInfo;
ChUninstallHookMsg* pMsg = (ChUninstallHookMsg*)&msg;
ChHookManager* pHookMgr;
ChModuleID idHookModule;
chint32 lMessage;
pMsg->GetParams( idHookModule, lMessage );
//ASSERT( 0 == lMessage || CH_MSG_CMD == lMessage || CH_MSG_INLINE == lMessage);
switch(lMessage)
{
case CH_MSG_CMD:
{
pHookMgr = pInfo->GetCmdHookMgr();
pHookMgr->Uninstall( idHookModule );
break;
}
case CH_MSG_INLINE:
{
pHookMgr = pInfo->GetImageHookMgr();
pHookMgr->Uninstall( idHookModule );
break;
}
case 0:
{
pHookMgr = pInfo->GetCmdHookMgr();
pHookMgr->Uninstall( idHookModule );
pHookMgr = pInfo->GetImageHookMgr();
pHookMgr->Uninstall( idHookModule );
break;
}
default:
break;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -