2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Nicklas P Andersson
22 #include "../stdafx.h"
24 #include "FlashAxContainer.h"
25 #include "../interop/TimerHelper.h"
27 #include <common/log.h>
30 #pragma warning (push, 2) // TODO
35 namespace caspar { namespace flash {
37 CComBSTR FlashAxContainer::flashGUID_(_T("{D27CDB6E-AE6D-11CF-96B8-444553540000}"));
39 _ATL_FUNC_INFO fnInfoFlashCallEvent = { CC_STDCALL, VT_EMPTY, 1, { VT_BSTR } };
40 _ATL_FUNC_INFO fnInfoReadyStateChangeEvent = { CC_STDCALL, VT_EMPTY, 1, { VT_I4 } };
42 FlashAxContainer::FlashAxContainer() : bInPlaceActive_(FALSE), pTimerHelper(0), bInvalidRect_(false), bReadyToRender_(false), bHasNewTiming_(false), m_lpDD4(0), timerCount_(0), bIsEmpty_(true)
45 FlashAxContainer::~FlashAxContainer()
61 HRESULT STDMETHODCALLTYPE FlashAxContainer::SetSite(IUnknown* pUnkSite)
63 ATLTRACE(_T("IObjectWithSite::SetSite\n"));
64 HRESULT hr = IObjectWithSiteImpl<FlashAxContainer>::SetSite(pUnkSite);
66 if (SUCCEEDED(hr) && m_spUnkSite)
68 // Look for "outer" IServiceProvider
69 hr = m_spUnkSite->QueryInterface(__uuidof(IServiceProvider), (void**)&m_spServices);
70 ATLASSERT( !hr && _T("No ServiceProvider!") );
74 m_spServices.Release();
82 HRESULT STDMETHODCALLTYPE FlashAxContainer::SaveObject()
84 ATLTRACENOTIMPL(_T("IOleClientSite::SaveObject"));
87 HRESULT STDMETHODCALLTYPE FlashAxContainer::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, IMoniker** ppmk)
89 /* if(*ppmk != NULL) {
90 if(m_spMyMoniker == NULL) {
91 ATL::CComObject<MyMoniker>* pMoniker = NULL;
92 HRESULT hr = ATL::CComObject<MyMoniker>::CreateInstance(&pMoniker);
94 m_spMyMoniker = pMoniker;
97 if(m_spMyMoniker != NULL) {
98 *ppmk = m_spMyMoniker;
108 HRESULT STDMETHODCALLTYPE FlashAxContainer::GetContainer(IOleContainer** ppContainer)
110 ATLTRACE(_T("IOleClientSite::GetContainer\n"));
111 (*ppContainer) = NULL;
112 return E_NOINTERFACE;
115 HRESULT STDMETHODCALLTYPE FlashAxContainer::ShowObject()
117 ATLTRACE(_T("IOleClientSite::ShowObject\n"));
121 HRESULT STDMETHODCALLTYPE FlashAxContainer::OnShowWindow(BOOL fShow)
123 ATLTRACE(_T("IOleClientSite::OnShowWindow"));
127 HRESULT STDMETHODCALLTYPE FlashAxContainer::RequestNewObjectLayout()
129 ATLTRACE(_T("IOleClientSite::RequestNewObjectLayout"));
136 HRESULT STDMETHODCALLTYPE FlashAxContainer::GetWindow(HWND* pHwnd)
138 ATLTRACE(_T("IOleInPlaceSite::GetWindow\n"));
139 (*pHwnd) = NULL;//GetApplication()->GetMainWindow()->getHwnd();
142 HRESULT STDMETHODCALLTYPE FlashAxContainer::ContextSensitiveHelp(BOOL fEnterMode)
144 ATLTRACE(_T("IOleInPlaceSite::ContextSensitiveHelp"));
148 HRESULT STDMETHODCALLTYPE FlashAxContainer::CanInPlaceActivate()
150 ATLTRACE(_T("IOleInPlaceSite::CanInPlaceActivate\n"));
154 HRESULT STDMETHODCALLTYPE FlashAxContainer::OnInPlaceActivate()
156 ATLTRACE(_T("IOleInPlaceSite::OnInPlaceActivate"));
160 HRESULT STDMETHODCALLTYPE FlashAxContainer::OnUIActivate()
162 ATLTRACE(_T("IOleInPlaceSite::OnUIActivate\n"));
167 HRESULT STDMETHODCALLTYPE FlashAxContainer::GetWindowContext(IOleInPlaceFrame** ppFrame, IOleInPlaceUIWindow** ppDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO pFrameInfo)
169 ATLTRACE(_T("IOleInPlaceSite::GetWindowContext\n"));
175 if (ppFrame == NULL || ppDoc == NULL || lprcPosRect == NULL || lprcClipRect == NULL)
178 pFrameInfo->fMDIApp = FALSE;
179 pFrameInfo->haccel = NULL;
180 pFrameInfo->cAccelEntries = 0;
181 pFrameInfo->hwndFrame = NULL;
183 lprcPosRect->top = m_rcPos.top;
184 lprcPosRect->left = m_rcPos.left;
185 lprcPosRect->right = m_rcPos.right;
186 lprcPosRect->bottom = m_rcPos.bottom;
188 lprcClipRect->top = m_rcPos.top;
189 lprcClipRect->left = m_rcPos.left;
190 lprcClipRect->right = m_rcPos.right;
191 lprcClipRect->bottom = m_rcPos.bottom;
196 HRESULT STDMETHODCALLTYPE FlashAxContainer::Scroll(SIZE scrollExtant)
198 ATLTRACE(_T("IOleInPlaceSite::Scroll"));
202 HRESULT STDMETHODCALLTYPE FlashAxContainer::OnUIDeactivate(BOOL fUndoable)
204 ATLTRACE(_T("IOleInPlaceSite::OnUIDeactivate\n"));
209 HRESULT STDMETHODCALLTYPE FlashAxContainer::OnInPlaceDeactivate()
211 ATLTRACE(_T("IOleInPlaceSite::OnInPlaceDeactivate\n"));
212 bInPlaceActive_ = FALSE;
213 m_spInPlaceObjectWindowless.Release();
217 HRESULT STDMETHODCALLTYPE FlashAxContainer::DiscardUndoState()
219 ATLTRACE(_T("IOleInPlaceSite::DiscardUndoState"));
223 HRESULT STDMETHODCALLTYPE FlashAxContainer::DeactivateAndUndo()
225 ATLTRACE(_T("IOleInPlaceSite::DeactivateAndUndo"));
229 HRESULT STDMETHODCALLTYPE FlashAxContainer::OnPosRectChange(LPCRECT lprcPosRect)
231 ATLTRACE(_T("IOleInPlaceSite::OnPosRectChange"));
239 HRESULT STDMETHODCALLTYPE FlashAxContainer::OnInPlaceActivateEx(BOOL* pfNoRedraw, DWORD dwFlags)
241 // should only be called once the first time control is inplace-activated
242 ATLTRACE(_T("IOleInPlaceSiteEx::OnInPlaceActivateEx\n"));
243 ATLASSERT(bInPlaceActive_ == FALSE);
244 ATLASSERT(m_spInPlaceObjectWindowless == NULL);
246 bInPlaceActive_ = TRUE;
247 OleLockRunning(m_spOleObject, TRUE, FALSE);
249 if (dwFlags & ACTIVATE_WINDOWLESS)
251 hr = m_spOleObject->QueryInterface(__uuidof(IOleInPlaceObjectWindowless), (void**) &m_spInPlaceObjectWindowless);
253 if (m_spInPlaceObjectWindowless != NULL)
254 m_spInPlaceObjectWindowless->SetObjectRects(&m_rcPos, &m_rcPos);
257 return (m_spInPlaceObjectWindowless != NULL) ? S_OK : E_FAIL;
260 HRESULT STDMETHODCALLTYPE FlashAxContainer::OnInPlaceDeactivateEx(BOOL fNoRedraw)
262 ATLTRACE(_T("IOleInPlaceSiteEx::OnInPlaceDeactivateEx\n"));
263 bInPlaceActive_ = FALSE;
264 m_spInPlaceObjectWindowless.Release();
268 HRESULT STDMETHODCALLTYPE FlashAxContainer::RequestUIActivate()
270 ATLTRACE(_T("IOleInPlaceSiteEx::RequestUIActivate\n"));
276 // IOleInPlaceSiteWindowless
278 HRESULT STDMETHODCALLTYPE FlashAxContainer::CanWindowlessActivate()
280 ATLTRACE(_T("IOleInPlaceSiteWindowless::CanWindowlessActivate\n"));
285 HRESULT STDMETHODCALLTYPE FlashAxContainer::GetCapture()
287 ATLTRACE(_T("IOleInPlaceSiteWindowless::GetCapture\n"));
288 return bCapture_ ? S_OK : S_FALSE;
291 HRESULT STDMETHODCALLTYPE FlashAxContainer::SetCapture(BOOL fCapture)
293 ATLTRACE(_T("IOleInPlaceSiteWindowless::SetCapture\n"));
294 bCapture_ = fCapture;
298 HRESULT STDMETHODCALLTYPE FlashAxContainer::GetFocus()
300 ATLTRACE(_T("IOleInPlaceSiteWindowless::GetFocus\n"));
301 return bHaveFocus_ ? S_OK : S_FALSE;
304 HRESULT STDMETHODCALLTYPE FlashAxContainer::SetFocus(BOOL fGotFocus)
306 ATLTRACE(_T("IOleInPlaceSiteWindowless::SetFocus\n"));
307 bHaveFocus_ = fGotFocus;
311 HRESULT STDMETHODCALLTYPE FlashAxContainer::GetDC(LPCRECT pRect, DWORD grfFlags, HDC* phDC)
313 ATLTRACE(_T("IOleInPlaceSiteWindowless::GetDC"));
317 HRESULT STDMETHODCALLTYPE FlashAxContainer::ReleaseDC(HDC hDC)
319 ATLTRACE(_T("IOleInPlaceSiteWindowless::ReleaseDC"));
323 HRESULT STDMETHODCALLTYPE FlashAxContainer::InvalidateRect(LPCRECT pRect, BOOL fErase)
325 // ATLTRACE(_T("IOleInPlaceSiteWindowless::InvalidateRect\n"));
327 bInvalidRect_ = true;
329 /* //Keep a list of dirty rectangles in order to be able to redraw only them
331 bDirtyRects_.push_back(DirtyRect(*pRect, fErase != 0));
334 bDirtyRects_.push_back(DirtyRect(true));
339 HRESULT STDMETHODCALLTYPE FlashAxContainer::InvalidateRgn(HRGN hRGN, BOOL fErase)
341 ATLTRACE(_T("IOleInPlaceSiteWindowless::InvalidateRng\n"));
345 HRESULT STDMETHODCALLTYPE FlashAxContainer::ScrollRect(INT dx, INT dy, LPCRECT pRectScroll, LPCRECT pRectClip)
347 ATLTRACE(_T("IOleInPlaceSiteWindowless::ScrollRect"));
351 HRESULT STDMETHODCALLTYPE FlashAxContainer::AdjustRect(LPRECT prc)
353 ATLTRACE(_T("IOleInPlaceSiteWindowless::AdjustRect"));
357 HRESULT STDMETHODCALLTYPE FlashAxContainer::OnDefWindowMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult)
359 ATLTRACE(_T("IOleInPlaceSiteWindowless::OnDefWindowMessage"));
366 HRESULT STDMETHODCALLTYPE FlashAxContainer::OnControlInfoChanged()
368 ATLTRACE(_T("IOleControlSite::OnControlInfoChanged"));
372 HRESULT STDMETHODCALLTYPE FlashAxContainer::LockInPlaceActive(BOOL fLock)
374 ATLTRACE(_T("IOleControlSite::LockInPlaceActive"));
378 HRESULT STDMETHODCALLTYPE FlashAxContainer::GetExtendedControl(IDispatch** ppDisp)
380 ATLTRACE(_T("IOleControlSite::GetExtendedControl"));
384 return m_spOleObject.QueryInterface(ppDisp);
387 HRESULT STDMETHODCALLTYPE FlashAxContainer::TransformCoords(POINTL* pPtlHimetric, POINTF* pPtfContainer, DWORD dwFlags)
389 ATLTRACE(_T("IOleControlSite::TransformCoords"));
393 HRESULT STDMETHODCALLTYPE FlashAxContainer::TranslateAccelerator(LPMSG lpMsg, DWORD grfModifiers)
395 ATLTRACE(_T("IOleControlSite::TranslateAccelerator"));
399 HRESULT STDMETHODCALLTYPE FlashAxContainer::OnFocus(BOOL fGotFocus)
401 bHaveFocus_ = fGotFocus;
405 HRESULT STDMETHODCALLTYPE FlashAxContainer::ShowPropertyFrame()
407 ATLTRACE(_T("IOleControlSite::ShowPropertyFrame"));
415 void STDMETHODCALLTYPE FlashAxContainer::OnDataChange(FORMATETC* pFormatetc, STGMEDIUM* pStgmed)
417 ATLTRACE(_T("IAdviseSink::OnDataChange\n"));
420 void STDMETHODCALLTYPE FlashAxContainer::OnViewChange(DWORD dwAspect, LONG lindex)
422 ATLTRACE(_T("IAdviseSink::OnViewChange\n"));
425 void STDMETHODCALLTYPE FlashAxContainer::OnRename(IMoniker* pmk)
427 ATLTRACE(_T("IAdviseSink::OnRename\n"));
430 void STDMETHODCALLTYPE FlashAxContainer::OnSave()
432 ATLTRACE(_T("IAdviseSink::OnSave\n"));
435 void STDMETHODCALLTYPE FlashAxContainer::OnClose()
437 ATLTRACE(_T("IAdviseSink::OnClose\n"));
443 DEFINE_GUID2(CLSID_DirectDraw,0xD7B70EE0,0x4340,0x11CF,0xB0,0x63,0x00,0x20,0xAF,0xC2,0xCD,0x35);
444 DEFINE_GUID2(CLSID_DirectDraw7,0x3c305196,0x50db,0x11d3,0x9c,0xfe,0x00,0xc0,0x4f,0xd9,0x30,0xc5);
446 DEFINE_GUID2(IID_IDirectDraw,0x6C14DB80,0xA733,0x11CE,0xA5,0x21,0x00,0x20,0xAF,0x0B,0xE5,0x60);
447 DEFINE_GUID2(IID_IDirectDraw3,0x618f8ad4,0x8b7a,0x11d0,0x8f,0xcc,0x0,0xc0,0x4f,0xd9,0x18,0x9d);
448 DEFINE_GUID2(IID_IDirectDraw4,0x9c59509a,0x39bd,0x11d1,0x8c,0x4a,0x00,0xc0,0x4f,0xd9,0x30,0xc5);
449 DEFINE_GUID2(IID_IDirectDraw7,0x15e65ec0,0x3b9c,0x11d2,0xb9,0x2f,0x00,0x60,0x97,0x97,0xea,0x5b);
454 HRESULT STDMETHODCALLTYPE FlashAxContainer::QueryService( REFGUID rsid, REFIID riid, void** ppvObj)
456 // ATLTRACE(_T("IServiceProvider::QueryService\n"));
457 //the flashcontrol asks for an interface {618F8AD4-8B7A-11D0-8FCC-00C04FD9189D}, this is IID for a DirectDraw3 object
459 ATLASSERT(ppvObj != NULL);
465 // Author: Makarov Igor
466 // Transparent Flash Control in Plain C++
467 // http://www.codeproject.com/KB/COM/flashcontrol.aspx
468 if (IsEqualGUID(rsid, IID_IDirectDraw3))
472 m_lpDD4 = new IDirectDraw4Ptr;
473 hr = m_lpDD4->CreateInstance(CLSID_DirectDraw, NULL, CLSCTX_INPROC_SERVER);
478 CASPAR_LOG(info) << print_() << " DirectDraw not installed. Running without DirectDraw.";
479 return E_NOINTERFACE;
482 if (m_lpDD4 && m_lpDD4->GetInterfacePtr())
484 *ppvObj = m_lpDD4->GetInterfacePtr();
490 //TODO: The fullscreen-consumer requires that ths does NOT return an ITimerService
491 hr = QueryInterface(riid, ppvObj);//E_NOINTERFACE;
500 HRESULT STDMETHODCALLTYPE FlashAxContainer::CreateTimer(ITimer *pReferenceTimer, ITimer **ppNewTimer)
502 ATLTRACE(_T("ITimerService::CreateTimer\n"));
503 if(pTimerHelper != 0)
508 pTimerHelper = new TimerHelper();
509 return QueryInterface(__uuidof(ITimer), (void**) ppNewTimer);
512 HRESULT STDMETHODCALLTYPE FlashAxContainer::GetNamedTimer(REFGUID rguidName, ITimer **ppTimer)
514 ATLTRACE(_T("ITimerService::GetNamedTimer"));
523 HRESULT STDMETHODCALLTYPE FlashAxContainer::SetNamedTimerReference(REFGUID rguidName, ITimer *pReferenceTimer)
525 ATLTRACE(_T("ITimerService::SetNamedTimerReference"));
532 HRESULT STDMETHODCALLTYPE FlashAxContainer::Advise(VARIANT vtimeMin, VARIANT vtimeMax, VARIANT vtimeInterval, DWORD dwFlags, ITimerSink *pTimerSink, DWORD *pdwCookie)
534 ATLTRACE(_T("Timer::Advise\n"));
539 if(pTimerHelper != 0)
541 pTimerHelper->Setup(vtimeMin.ulVal, vtimeInterval.ulVal, pTimerSink);
542 *pdwCookie = pTimerHelper->ID;
543 bHasNewTiming_ = true;
548 return E_OUTOFMEMORY;
551 HRESULT STDMETHODCALLTYPE FlashAxContainer::Unadvise(/* [in] */ DWORD dwCookie)
553 ATLTRACE(_T("Timer::Unadvice\n"));
554 if(pTimerHelper != 0)
556 pTimerHelper->pTimerSink = 0;
563 HRESULT STDMETHODCALLTYPE FlashAxContainer::Freeze(/* [in] */ BOOL fFreeze)
565 ATLTRACE(_T("Timer::Freeze\n"));
569 HRESULT STDMETHODCALLTYPE FlashAxContainer::GetTime(/* [out] */ VARIANT *pvtime)
571 ATLTRACE(_T("Timer::GetTime\n"));
580 double FlashAxContainer::GetFPS() {
581 if(pTimerHelper != 0 && pTimerHelper->interval > 0)
582 return (1000.0 / static_cast<double>(pTimerHelper->interval));
587 bool FlashAxContainer::IsReadyToRender() const {
588 return bReadyToRender_;
591 void FlashAxContainer::EnterFullscreen()
593 if(m_spInPlaceObjectWindowless != 0)
596 m_spInPlaceObjectWindowless->OnWindowMessage(WM_LBUTTONDOWN, 0, MAKELPARAM(1, 1), &result);
597 m_spInPlaceObjectWindowless->OnWindowMessage(WM_LBUTTONUP, 0, MAKELPARAM(1, 1), &result);
601 void STDMETHODCALLTYPE FlashAxContainer::OnFlashCall(BSTR request)
603 std::wstring str(request);
604 if(str.find(TEXT("DisplayedTemplate")) != std::wstring::npos)
606 ATLTRACE(_T("ShockwaveFlash::DisplayedTemplate\n"));
607 bReadyToRender_ = true;
609 else if(str.find(TEXT("OnCommand")) != std::wstring::npos) {
610 //this is how templatehost 1.8 reports that a command has been received
611 CASPAR_LOG(debug) << print_() << L" [command] " << str;
612 bCallSuccessful_ = true;
614 else if(str.find(TEXT("Activity")) != std::wstring::npos)
616 CASPAR_LOG(debug) << print_() << L" [activity] " << str;
618 //this is how templatehost 1.7 reports that a command has been received
619 if(str.find(TEXT("Command recieved")) != std::wstring::npos)
620 bCallSuccessful_ = true;
622 /*if(pFlashProducer_ != 0 && pFlashProducer_->pMonitor_) {
623 std::wstring::size_type pos = str.find(TEXT('@'));
624 if(pos != std::wstring::npos)
625 pFlashProducer_->pMonitor_->Inform(str.substr(pos, str.find(TEXT('<'), pos)-pos));
628 else if(str.find(TEXT("OnNotify")) != std::wstring::npos)
630 CASPAR_LOG(info) << print_() << L" [notification] " << str;
632 //if(pFlashProducer_ != 0 && pFlashProducer_->pMonitor_) {
633 // std::wstring::size_type pos = str.find(TEXT('@'));
634 // if(pos != std::wstring::npos)
635 // pFlashProducer_->pMonitor_->Inform(str.substr(pos, str.find(TEXT('<'), pos)-pos));
638 else if(str.find(TEXT("IsEmpty")) != std::wstring::npos)
640 CASPAR_LOG(trace) << print_() << L" Empty.";
641 ATLTRACE(_T("ShockwaveFlash::IsEmpty\n"));
644 else if(str.find(TEXT("OnError")) != std::wstring::npos)
646 CASPAR_LOG(error) << print_() << L" [error] " << str;
648 else if(str.find(TEXT("OnDebug")) != std::wstring::npos)
650 CASPAR_LOG(debug) << print_() << L" [debug] " << str;
652 //else if(str.find(TEXT("OnTemplateDescription")) != std::wstring::npos)
654 // CASPAR_LOG(error) << print_() << L" TemplateDescription: \n-------------------------------------------\n" << str << L"\n-------------------------------------------";
656 //else if(str.find(TEXT("OnGetInfo")) != std::wstring::npos)
658 // CASPAR_LOG(error) << print_() << L" Info: \n-------------------------------------------\n" << str << L"\n-------------------------------------------";
662 // CASPAR_LOG(error) << print_() << L" Unknown: \n-------------------------------------------\n" << str << L"\n-------------------------------------------";
665 CComPtr<IShockwaveFlash> spFlash;
666 HRESULT hr = m_spOleObject->QueryInterface(__uuidof(IShockwaveFlash), (void**) &spFlash);
667 if(hr == S_OK && spFlash)
669 hr = spFlash->SetReturnValue(TEXT("<null/>"));
673 void STDMETHODCALLTYPE FlashAxContainer::OnReadyStateChange(long newState)
677 bReadyToRender_ = true;
680 bReadyToRender_ = false;
683 void FlashAxContainer::DestroyAxControl()
685 GetControllingUnknown()->AddRef();
687 if ((!m_spViewObject) == false)
688 m_spViewObject->SetAdvise(DVASPECT_CONTENT, 0, NULL);
690 if ((!m_spOleObject) == false)
692 DispEventUnadvise(m_spOleObject, &DIID__IShockwaveFlashEvents);
693 m_spOleObject->Unadvise(m_dwOleObject);
694 m_spOleObject->Close(OLECLOSE_NOSAVE);
695 m_spOleObject->SetClientSite(NULL);
698 if ((!m_spUnknown) == false)
700 CComPtr<IObjectWithSite> spSite;
701 m_spUnknown->QueryInterface(__uuidof(IObjectWithSite), (void**)&spSite);
703 spSite->SetSite(NULL);
706 if ((!m_spViewObject) == false)
707 m_spViewObject.Release();
709 if ((!m_spInPlaceObjectWindowless) == false)
710 m_spInPlaceObjectWindowless.Release();
712 if ((!m_spOleObject) == false)
713 m_spOleObject.Release();
715 if ((!m_spUnknown) == false)
716 m_spUnknown.Release();
719 bool FlashAxContainer::CheckForFlashSupport()
722 return SUCCEEDED(CLSIDFromString((LPOLESTR)flashGUID_, &clsid));
725 HRESULT FlashAxContainer::CreateAxControl()
728 HRESULT hr = CLSIDFromString((LPOLESTR)flashGUID_, &clsid);
730 hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, __uuidof(IUnknown), (void**)&m_spUnknown);
735 m_spUnknown->QueryInterface(__uuidof(IOleObject), (void**)&m_spOleObject);
738 m_spOleObject->GetMiscStatus(DVASPECT_CONTENT, &m_dwMiscStatus);
739 if (m_dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST)
741 CComQIPtr<IOleClientSite> spClientSite(GetControllingUnknown());
742 m_spOleObject->SetClientSite(spClientSite);
746 CComQIPtr<IPersistStreamInit> spPSI(m_spOleObject);
748 hr = spPSI->InitNew();
750 if (FAILED(hr)) // If the initialization of the control failed...
752 // Clean up and return
753 if (m_dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST)
754 m_spOleObject->SetClientSite(NULL);
757 m_spOleObject.Release();
758 m_spUnknown.Release();
762 //end Initialize object
764 if (0 == (m_dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST))
766 CComQIPtr<IOleClientSite> spClientSite(GetControllingUnknown());
767 m_spOleObject->SetClientSite(spClientSite);
770 CComPtr<IShockwaveFlash> spFlash;
771 HRESULT hResultQuality;
772 HRESULT hr2 = m_spOleObject->QueryInterface(__uuidof(IShockwaveFlash), (void**) &spFlash);
773 if(hr2 == S_OK && spFlash)
775 if(FAILED(spFlash->put_WMode(TEXT("Transparent"))))
776 CASPAR_LOG(warning) << print_() << L" Failed to set flash container to transparent mode.";
777 //spFlash->put_WMode(TEXT("ogl"));
778 hResultQuality = spFlash->put_Quality2(TEXT("Best"));
780 if(SUCCEEDED(DispEventAdvise(spFlash, &DIID__IShockwaveFlashEvents)))
784 HRESULT hrView = m_spOleObject->QueryInterface(__uuidof(IViewObjectEx), (void**) &m_spViewObject);
786 CComQIPtr<IAdviseSink> spAdviseSink(GetControllingUnknown());
787 m_spOleObject->Advise(spAdviseSink, &m_dwOleObject);
789 m_spViewObject->SetAdvise(DVASPECT_CONTENT, 0, spAdviseSink);
791 if ((m_dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME) == 0)
793 //Initialize window to some dummy size
797 m_rcPos.bottom = 576;
799 m_pxSize.cx = m_rcPos.right - m_rcPos.left;
800 m_pxSize.cy = m_rcPos.bottom - m_rcPos.top;
801 AtlPixelToHiMetric(&m_pxSize, &m_hmSize);
802 m_spOleObject->SetExtent(DVASPECT_CONTENT, &m_hmSize);
803 m_spOleObject->GetExtent(DVASPECT_CONTENT, &m_hmSize);
804 AtlHiMetricToPixel(&m_hmSize, &m_pxSize);
805 m_rcPos.right = m_rcPos.left + m_pxSize.cx;
806 m_rcPos.bottom = m_rcPos.top + m_pxSize.cy;
808 CComQIPtr<IOleClientSite> spClientSite(GetControllingUnknown());
809 hr = m_spOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, spClientSite, 0, NULL, &m_rcPos);
812 CComPtr<IObjectWithSite> spSite;
813 m_spUnknown->QueryInterface(__uuidof(IObjectWithSite), (void**)&spSite);
815 spSite->SetSite(GetControllingUnknown());
820 if (FAILED(hr) || m_spUnknown == NULL)
823 // We don't have a control or something failed so release
830 void FlashAxContainer::SetSize(size_t width, size_t height) {
831 if(m_spInPlaceObjectWindowless != 0)
835 m_rcPos.right = width;
836 m_rcPos.bottom = height;
838 m_pxSize.cx = m_rcPos.right - m_rcPos.left;
839 m_pxSize.cy = m_rcPos.bottom - m_rcPos.top;
840 AtlPixelToHiMetric(&m_pxSize, &m_hmSize);
841 m_spOleObject->SetExtent(DVASPECT_CONTENT, &m_hmSize);
842 m_spOleObject->GetExtent(DVASPECT_CONTENT, &m_hmSize);
843 AtlHiMetricToPixel(&m_hmSize, &m_pxSize);
844 m_rcPos.right = m_rcPos.left + m_pxSize.cx;
845 m_rcPos.bottom = m_rcPos.top + m_pxSize.cy;
847 m_spInPlaceObjectWindowless->SetObjectRects(&m_rcPos, &m_rcPos);
848 bInvalidRect_ = true;
852 HRESULT FlashAxContainer::QueryControl(REFIID iid, void** ppUnk)
854 ATLASSERT(ppUnk != NULL);
858 hr = m_spOleObject->QueryInterface(iid, ppUnk);
862 bool FlashAxContainer::DrawControl(HDC targetDC)
864 // ATLTRACE(_T("FlashAxContainer::DrawControl\n"));
865 DVASPECTINFO aspectInfo = {sizeof(DVASPECTINFO), DVASPECTINFOFLAG_CANOPTIMIZE};
868 hr = m_spViewObject->Draw(DVASPECT_CONTENT, -1, &aspectInfo, NULL, NULL, targetDC, NULL, NULL, NULL, NULL);
869 bInvalidRect_ = false;
870 /* const video_format_desc& fmtDesc = video_format_desc::FormatDescriptions[format_];
872 //Trying to redraw just the dirty rectangles. Doesn't seem to work when the movie uses "filters", such as glow, dropshadow etc.
873 std::vector<flash::DirtyRect>::iterator it = bDirtyRects_.begin();
874 std::vector<flash::DirtyRect>::iterator end = bDirtyRects_.end();
875 for(; it != end; ++it) {
876 flash::DirtyRect& dirtyRect = (*it);
877 if(dirtyRect.bWhole || dirtyRect.rect.right >= fmtDesc.width || dirtyRect.rect.bottom >= fmtDesc.height) {
878 m_spInPlaceObjectWindowless->SetObjectRects(&m_rcPos, &m_rcPos);
879 hr = m_spViewObject->Draw(DVASPECT_OPAQUE, -1, NULL, NULL, NULL, targetDC, NULL, NULL, NULL, NULL);
883 m_spInPlaceObjectWindowless->SetObjectRects(&m_rcPos, &(dirtyRect.rect));
884 hr = m_spViewObject->Draw(DVASPECT_OPAQUE, -1, NULL, NULL, NULL, targetDC, NULL, NULL, NULL, NULL);
887 bDirtyRects_.clear();
893 void FlashAxContainer::Tick()
897 DWORD time = pTimerHelper->Invoke(); // Tick flash
898 if(time - timerCount_ >= 400)
902 m_spInPlaceObjectWindowless->OnWindowMessage(WM_TIMER, 3, 0, &hr);
907 bool FlashAxContainer::FlashCall(const std::wstring& str, std::wstring& result2)
910 CComPtr<IShockwaveFlash> spFlash;
911 QueryControl(&spFlash);
912 CComBSTR request(str.c_str());
915 bCallSuccessful_ = false;
916 for(size_t retries = 0; !bCallSuccessful_ && retries < 4; ++retries)
917 spFlash->CallFunction(request, &result);
922 return bCallSuccessful_;