// TangramLittle Library - version 1.0
// Author: Sunhui
// Modified by:
// Created: 2005-04-06
// Copyright: (c) Sunhui
// Licence: wxWindows licence
//
// This source code is a part of Tangram library.
// The use and distribution terms for this software are covered by the
// The wxWindows Library Licence (http://opensource.org/licenses/wxwindows.php)
// which can be found in the file licence.txt at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license. You must not remove this notice, or
// any other, from this software.
// TangramFlashView.cpp : implementation file
//
#include "stdafx.h"
#include "dotnetextimpl.h"
#include "FlashView.h"
#include "XDocument.h"
// CTangramFlashView
IMPLEMENT_DYNCREATE(CTangramFlashView, CView)
BEGIN_EVENTSINK_MAP(CTangramFlashView, CView)
ON_EVENT(CTangramFlashView, AFX_IDW_PANE_FIRST, DISPID_READYSTATECHANGE, OnReadyStateChangeShockwaveflash, VTS_I4)
ON_EVENT(CTangramFlashView, AFX_IDW_PANE_FIRST, 1958, OnProgressShockwaveflash, VTS_I4)
ON_EVENT(CTangramFlashView, AFX_IDW_PANE_FIRST, 150, FSCommandShockwaveflash, VTS_BSTR VTS_BSTR)
END_EVENTSINK_MAP()
CTangramFlashView::CTangramFlashView()
{
m_pDoc = NULL;
m_bFlashMenu = false;
m_bBKView = false;
}
CTangramFlashView::~CTangramFlashView()
{
if (0 == _taccess(LPCTSTR(m_TangramFlashWnd.m_strMoviePath),0))
{
CFile::Remove(LPCTSTR(m_TangramFlashWnd.m_strMoviePath));
}
}
void CTangramFlashView::OnReadyStateChangeShockwaveflash(long newState)
{
// TODO: Add your message handler code here
}
void CTangramFlashView::OnProgressShockwaveflash(long percentDone)
{
// TODO: Add your message handler code here
}
void CTangramFlashView::FSCommandShockwaveflash(LPCTSTR command, LPCTSTR args)
{
if(m_pDoc)
{
m_pDoc->OnExternalCommand(command,args);
}
}
BEGIN_MESSAGE_MAP(CTangramFlashView, CView)
ON_WM_SIZE()
ON_WM_RBUTTONDOWN()
ON_WM_WINDOWPOSCHANGING()
END_MESSAGE_MAP()
// CTangramFlashView drawing
void CTangramFlashView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
// CTangramFlashView diagnostics
#ifdef _DEBUG
void CTangramFlashView::AssertValid() const
{
CView::AssertValid();
}
void CTangramFlashView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
// CTangramFlashView message handlers
BOOL CTangramFlashView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
// create the view window itself
if (!CView::Create(lpszClassName, lpszWindowName,
dwStyle, rect, pParentWnd, nID, pContext))
{
return FALSE;
}
// assure that control containment is on
AfxEnableControlContainer();
GetClientRect(&m_OldClientRect);
// create the control window
// AFX_IDW_PANE_FIRST is a safe but arbitrary ID
if(!m_TangramFlashWnd.Create(NULL,NULL,WS_CHILD|WS_VISIBLE,m_OldClientRect,this,AFX_IDW_PANE_FIRST))
{
DestroyWindow();
return FALSE;
}
// cache the dispinterface
LPUNKNOWN lpUnk = m_TangramFlashWnd.GetControlUnknown();
HRESULT hr = lpUnk->QueryInterface(IID_IDispatch, (void**) &m_pFlashDisp);
if (!SUCCEEDED(hr))
{
m_pFlashDisp = NULL;
m_TangramFlashWnd.DestroyWindow();
DestroyWindow();
return FALSE;
}
return true;
}
void CTangramFlashView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if(m_pFlashDisp)
{
CRect rect(CPoint(0,0),CSize(cx,cy));
CComQIPtr<IOleInPlaceObject> spInPlace(m_pFlashDisp);
spInPlace->SetObjectRects(&rect,&rect);
m_OldClientRect = rect;
}
}
BOOL CTangramFlashView::LoadFromResource(CString strResType, CString strResName)
{
CString strFlashName = m_TangramFlashWnd.m_strMoviePath;
CString strTempPath;
GetTempPath (MAX_PATH, strTempPath.GetBuffer (MAX_PATH));
strTempPath.ReleaseBuffer();
//-------------------------------------------
// Create a temporary file for the output....
//-------------------------------------------
::GetTempFileName (strTempPath, _T("~tg"), 0, m_TangramFlashWnd.m_strMoviePath.GetBuffer (MAX_PATH));
m_TangramFlashWnd.m_strMoviePath.ReleaseBuffer ();
m_TangramFlashWnd.m_strMoviePath.MakeLower();
if(!g_pDotNetExtImpl->CreateFileFromResource(strResName,strResType,m_TangramFlashWnd.m_strMoviePath))
return false;
if(m_TangramFlashWnd.m_strMoviePath!=_T(""))
{
LPTSTR lpstrMovie = new TCHAR[MAX_PATH];
GetLongPathName( LPCTSTR(m_TangramFlashWnd.m_strMoviePath), lpstrMovie, MAX_PATH);
CString m_strMovie = _T("");
m_strMovie+=lpstrMovie;
put_Movie(LPCTSTR(m_strMovie));
Play();
delete lpstrMovie;
put_Playing(true);
}
if (0 == _taccess(LPCTSTR(strFlashName),0))
{
CFile::Remove(LPCTSTR(strFlashName));
}
return 0;
}
BOOL CTangramFlashView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass = AfxRegisterWndClass(0);
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
cs.style|=WS_CLIPSIBLINGS;
return CView::PreCreateWindow(cs);
}
BOOL CTangramFlashView::PreTranslateMessage(MSG* pMsg)
{
ASSERT(pMsg != NULL);
ASSERT_VALID(this);
ASSERT(m_hWnd != NULL);
/*if(g_pTangramServer->m_pActiveItem&&pMsg->message==WM_LBUTTONUP)
{
g_pTangramServer->m_pActiveItem->OnDeactivate();
g_pTangramServer->m_pActiveItem=NULL;
}*/
// allow tooltip messages to be filtered (skip CFormView)
if (CView::PreTranslateMessage(pMsg))
return TRUE;
// don't translate dialog messages when in Shift+F1 help mode
CFrameWnd* pFrameWnd = GetTopLevelFrame();
if (pFrameWnd != NULL && pFrameWnd->m_bHelpMode)
return FALSE;
// call all frame windows' PreTranslateMessage first
pFrameWnd = GetParentFrame(); // start with first parent frame
while (pFrameWnd != NULL)
{
// allow owner & frames to translate
if (pFrameWnd->PreTranslateMessage(pMsg))
return TRUE;
// try parent frames until there are no parent frames
pFrameWnd = pFrameWnd->GetParentFrame();
}
// check if the flash control wants to handle the message
BOOL bRet = FALSE;
if(m_pFlashDisp != NULL)
{
CComQIPtr<IOleInPlaceActiveObject> spInPlace = m_pFlashDisp;
if (spInPlace)
{
if(!m_bFlashMenu&&(pMsg->message == WM_RBUTTONDOWN||pMsg->message == WM_RBUTTONUP))
{
LPARAM lparam = MAKELPARAM(pMsg->pt.x,pMsg->pt.y);
CPoint m_MourecPoint;
m_MourecPoint.x = pMsg->pt.x;
m_MourecPoint.y = pMsg->pt.y;
UINT nFlags = (UINT)pMsg->wParam;
OnRButtonDown(nFlags,m_MourecPoint);
return true;
}
else
{
bRet = (spInPlace->TranslateAccelerator(pMsg) == S_OK) ? TRUE : FALSE;
}
}
CRect rect;
m_TangramFlashWnd.GetClientRect(&rect);
if(m_OldClientRect != rect)
{
GetClientRect(&rect);
CComQIPtr<IOleInPlaceObject> spInPlace(m_pFlashDisp);
spInPlace->SetObjectRects(&rect,&rect);
m_OldClientRect = rect;
}
}
return bRet;
}
void CTangramFlashView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
LPARAM lparam = MAKELPARAM(point.x,point.y);
g_pDotNetExtImpl->m_pMainFrame->SendMessage(WM_CONTEXTMENU,(WPARAM)m_hWnd,lparam);
CView::OnRButtonDown(nFlags, point);
}
void CTangramFlashView::OnWindowPosChanging(WINDOWPOS* lpwndpos)
{
CView::OnWindowPosChanging(lpwndpos);
if(m_bBKView)
lpwndpos->flags|=SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW;
}
extern DotNetExtImpl* g_pDotNetExtImpl;
/////////////////////////////////////////////////////////////////////////////
// CTangramFlashWnd
IMPLEMENT_DYNCREATE(CTangramFlashWnd, CWnd)
// CTangramFlashWnd properties
CTangramFlashWnd::CTangramFlashWnd()
{
m_strMoviePath = _T("");
}
CTangramFlashWnd::~CTangramFlashWnd()
{
}
// CTangramFlashWnd operations
BOOL CTangramFlashWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
BOOL rt = CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID);
if(m_strMoviePath!=_T(""))
{
LPTSTR lpstrMovie = new TCHAR[MAX_PATH];
GetLongPathName( LPCTSTR(m_strMoviePath), lpstrMovie, MAX_PATH);
CString m_strMovie = _T("");
m_strMovie+=lpstrMovie;
put_Movie(LPCTSTR(m_strMovie));
CString m_strStartInfo = g_pDotNetExtImpl->GetStartInfo();
SetVariable(_T("TangramStartInfo"),LPCTSTR(m_strStartInfo));
Play();
delete lpstrMovie;
}
return rt;
}
BEGIN_MESSAGE_MAP(CTangramFlashWnd, CWnd)
ON_WM_SIZE()
END_MESSAGE_MAP()
void CTangramFlashWnd::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
if(cx*cy==0)
{
LPUNKNOWN lpUnk = GetControlUnknown();
CRect rectParent;
GetParent()->GetClientRect(&rectParent);
CRect rect(CPoint(0,0),CSize(rectParent.Width(),rectParent.Height()));
CComQIPtr<IOleInPlaceObject> spInPlace(lpUnk);
spInPlace->SetObjectRects(&rect,&rect);
}
// TODO: Add your message handler code here
}