// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
+/*
+ FIXME FIXME FIXME:
+ - extract different backends in different files (better yet, make backends
+ dynamically loadable...), they have nothing to do with each other and
+ this file is huge and also separate the standard contents from our code
+ itself
+ */
+
//===========================================================================
// DECLARATIONS
//===========================================================================
// Pre-compiled header stuff
//---------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "mediactrl.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "wx/log.h" //wxLogDebug
#include "wx/math.h" //log10 & pow
#include "wx/msw/private.h" //user info and wndproc setting/getting
+#include "wx/dcclient.h"
+#include "wx/timer.h"
+#include "wx/dynlib.h"
//---------------------------------------------------------------------------
// Externals (somewhere in src/msw/app.cpp and src/msw/window.cpp)
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
-// COM includes
+// wxActiveXContainer - includes all the COM-specific stuff we need
//---------------------------------------------------------------------------
-#include "wx/msw/ole/oleutils.h" //wxBasicString, IID etc.
-#include "wx/msw/ole/uuid.h" //IID etc..
-#include <oleidl.h>
-#include <olectl.h>
-#include <exdisp.h>
-#include <docobj.h>
-
-//
-// These defines are from another ole header - but its not in the
-// latest sdk. Also the ifndef DISPID_READYSTATE is here because at
-// least on my machine with the latest sdk olectl.h defines these 3
-//
-#ifndef DISPID_READYSTATE
- #define DISPID_READYSTATE -525
- #define DISPID_READYSTATECHANGE -609
- #define DISPID_AMBIENT_TRANSFERPRIORITY -728
-#endif
-
-#define DISPID_AMBIENT_OFFLINEIFNOTCONNECTED -5501
-#define DISPID_AMBIENT_SILENT -5502
-
-#ifndef DISPID_AMBIENT_CODEPAGE
-# define DISPID_AMBIENT_CODEPAGE -725
-# define DISPID_AMBIENT_CHARSET -727
-#endif
-
-//---------------------------------------------------------------------------
-// COM compatability definitions
-//---------------------------------------------------------------------------
-#ifndef STDMETHODCALLTYPE
-#define STDMETHODCALLTYPE __stdcall
-#endif
-#ifndef STDMETHOD
-#define STDMETHOD(funcname) virtual HRESULT STDMETHODCALLTYPE funcname
-#endif
-#ifndef PURE
-#define PURE = 0
-#endif
-#ifndef __RPC_FAR
-#define __RPC_FAR FAR
-#endif
+#include "wx/msw/ole/activex.h"
//---------------------------------------------------------------------------
// IIDS - used by CoCreateInstance and IUnknown::QueryInterface
STDMETHOD(QueryVendorInfo)(LPWSTR *pVendorInfo) PURE;
};
-//---------------------------------------------------------------------------
-//
-// wxActiveX (Ryan Norton's version :))
-// wxActiveX is (C) 2003 Lindsay Mathieson
-//
-//---------------------------------------------------------------------------
-#define WX_DECLARE_AUTOOLE(wxAutoOleInterface, I) \
-class wxAutoOleInterface \
-{ \
- protected: \
- I *m_interface; \
-\
- public: \
- explicit wxAutoOleInterface(I *pInterface = NULL) : m_interface(pInterface) {} \
- wxAutoOleInterface(REFIID riid, IUnknown *pUnk) : m_interface(NULL) \
- { QueryInterface(riid, pUnk); } \
- wxAutoOleInterface(REFIID riid, IDispatch *pDispatch) : m_interface(NULL) \
- { QueryInterface(riid, pDispatch); } \
- wxAutoOleInterface(REFCLSID clsid, REFIID riid) : m_interface(NULL)\
- { CreateInstance(clsid, riid); }\
- wxAutoOleInterface(const wxAutoOleInterface& ti) : m_interface(NULL)\
- { operator = (ti); }\
-\
- wxAutoOleInterface& operator = (const wxAutoOleInterface& ti)\
- {\
- if (ti.m_interface)\
- ti.m_interface->AddRef();\
- Free();\
- m_interface = ti.m_interface;\
- return *this;\
- }\
-\
- wxAutoOleInterface& operator = (I *&ti)\
- {\
- Free();\
- m_interface = ti;\
- return *this;\
- }\
-\
- ~wxAutoOleInterface() { Free(); }\
-\
- inline void Free()\
- {\
- if (m_interface)\
- m_interface->Release();\
- m_interface = NULL;\
- }\
-\
- HRESULT QueryInterface(REFIID riid, IUnknown *pUnk)\
- {\
- Free();\
- wxASSERT(pUnk != NULL);\
- return pUnk->QueryInterface(riid, (void **) &m_interface);\
- }\
-\
- HRESULT CreateInstance(REFCLSID clsid, REFIID riid)\
- {\
- Free();\
- return CoCreateInstance(clsid, NULL, CLSCTX_ALL, riid, (void **) &m_interface);\
- }\
-\
- inline operator I *() const {return m_interface;}\
- inline I* operator ->() {return m_interface;}\
- inline I** GetRef() {return &m_interface;}\
- inline bool Ok() const {return m_interface != NULL;}\
-};
-
-WX_DECLARE_AUTOOLE(wxAutoIDispatch, IDispatch)
-WX_DECLARE_AUTOOLE(wxAutoIOleClientSite, IOleClientSite)
-WX_DECLARE_AUTOOLE(wxAutoIUnknown, IUnknown)
-WX_DECLARE_AUTOOLE(wxAutoIOleObject, IOleObject)
-WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceObject, IOleInPlaceObject)
-WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceActiveObject, IOleInPlaceActiveObject)
-WX_DECLARE_AUTOOLE(wxAutoIOleDocumentView, IOleDocumentView)
-WX_DECLARE_AUTOOLE(wxAutoIViewObject, IViewObject)
-WX_DECLARE_AUTOOLE(wxAutoIOleInPlaceSite, IOleInPlaceSite)
-WX_DECLARE_AUTOOLE(wxAutoIOleDocument, IOleDocument)
-WX_DECLARE_AUTOOLE(wxAutoIPersistStreamInit, IPersistStreamInit)
-WX_DECLARE_AUTOOLE(wxAutoIAdviseSink, IAdviseSink)
-
-class wxActiveX : public wxWindow
-{
-public:
- wxActiveX(wxWindow * parent, REFIID iid, IUnknown* pUnk);
- virtual ~wxActiveX();
-
- void OnSize(wxSizeEvent&);
- void OnPaint(wxPaintEvent&);
- void OnSetFocus(wxFocusEvent&);
- void OnKillFocus(wxFocusEvent&);
-
-protected:
- friend class FrameSite;
-
- wxAutoIDispatch m_Dispatch;
- wxAutoIOleClientSite m_clientSite;
- wxAutoIUnknown m_ActiveX;
- wxAutoIOleObject m_oleObject;
- wxAutoIOleInPlaceObject m_oleInPlaceObject;
- wxAutoIOleInPlaceActiveObject m_oleInPlaceActiveObject;
- wxAutoIOleDocumentView m_docView;
- wxAutoIViewObject m_viewObject;
- HWND m_oleObjectHWND;
- bool m_bAmbientUserMode;
- DWORD m_docAdviseCookie;
- wxWindow* m_realparent;
-
- void CreateActiveX(REFIID, IUnknown*);
-};
-
-#define DECLARE_OLE_UNKNOWN(cls)\
- private:\
- class TAutoInitInt\
- {\
- public:\
- LONG l;\
- TAutoInitInt() : l(0) {}\
- };\
- TAutoInitInt refCount, lockCount;\
- static void _GetInterface(cls *self, REFIID iid, void **_interface, const char *&desc);\
- public:\
- LONG GetRefCount();\
- HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void ** ppvObject);\
- ULONG STDMETHODCALLTYPE AddRef();\
- ULONG STDMETHODCALLTYPE Release();\
- ULONG STDMETHODCALLTYPE AddLock();\
- ULONG STDMETHODCALLTYPE ReleaseLock()
-
-#define DEFINE_OLE_TABLE(cls)\
- LONG cls::GetRefCount() {return refCount.l;}\
- HRESULT STDMETHODCALLTYPE cls::QueryInterface(REFIID iid, void ** ppvObject)\
- {\
- if (! ppvObject)\
- {\
- return E_FAIL;\
- };\
- const char *desc = NULL;\
- cls::_GetInterface(this, iid, ppvObject, desc);\
- if (! *ppvObject)\
- {\
- return E_NOINTERFACE;\
- };\
- ((IUnknown * )(*ppvObject))->AddRef();\
- return S_OK;\
- };\
- ULONG STDMETHODCALLTYPE cls::AddRef()\
- {\
- InterlockedIncrement(&refCount.l);\
- return refCount.l;\
- };\
- ULONG STDMETHODCALLTYPE cls::Release()\
- {\
- if (refCount.l > 0)\
- {\
- InterlockedDecrement(&refCount.l);\
- if (refCount.l == 0)\
- {\
- delete this;\
- return 0;\
- };\
- return refCount.l;\
- }\
- else\
- return 0;\
- }\
- ULONG STDMETHODCALLTYPE cls::AddLock()\
- {\
- InterlockedIncrement(&lockCount.l);\
- return lockCount.l;\
- };\
- ULONG STDMETHODCALLTYPE cls::ReleaseLock()\
- {\
- if (lockCount.l > 0)\
- {\
- InterlockedDecrement(&lockCount.l);\
- return lockCount.l;\
- }\
- else\
- return 0;\
- }\
- DEFINE_OLE_BASE(cls)
-
-#define DEFINE_OLE_BASE(cls)\
- void cls::_GetInterface(cls *self, REFIID iid, void **_interface, const char *&desc)\
- {\
- *_interface = NULL;\
- desc = NULL;
-
-#define OLE_INTERFACE(_iid, _type)\
- if (IsEqualIID(iid, _iid))\
- {\
- *_interface = (IUnknown *) (_type *) self;\
- desc = # _iid;\
- return;\
- }
-
-#define OLE_IINTERFACE(_face) OLE_INTERFACE(IID_##_face, _face)
-
-#define OLE_INTERFACE_CUSTOM(func)\
- if (func(self, iid, _interface, desc))\
- {\
- return;\
- }
-
-#define END_OLE_TABLE\
- }
-
-
-class FrameSite :
- public IOleClientSite,
- public IOleInPlaceSiteEx,
- public IOleInPlaceFrame,
- public IOleItemContainer,
- public IDispatch,
- public IOleCommandTarget,
- public IOleDocumentSite,
- public IAdviseSink,
- public IOleControlSite
-{
-private:
- DECLARE_OLE_UNKNOWN(FrameSite);
-
-public:
- FrameSite(wxWindow * win, wxActiveX * win2)
- {
- m_window = win2;
- m_bSupportsWindowlessActivation = true;
- m_bInPlaceLocked = false;
- m_bUIActive = false;
- m_bInPlaceActive = false;
- m_bWindowless = false;
-
- m_nAmbientLocale = 0;
- m_clrAmbientForeColor = ::GetSysColor(COLOR_WINDOWTEXT);
- m_clrAmbientBackColor = ::GetSysColor(COLOR_WINDOW);
- m_bAmbientShowHatching = true;
- m_bAmbientShowGrabHandles = true;
- m_bAmbientAppearance = true;
-
- m_hDCBuffer = NULL;
- m_hWndParent = (HWND)win->GetHWND();
- }
- virtual ~FrameSite(){}
- //***************************IDispatch*****************************
- HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID, OLECHAR ** ,
- unsigned int , LCID ,
- DISPID * )
- { return E_NOTIMPL; }
- STDMETHOD(GetTypeInfo)(unsigned int, LCID, ITypeInfo **)
- { return E_NOTIMPL; }
- HRESULT STDMETHODCALLTYPE GetTypeInfoCount(unsigned int *)
- { return E_NOTIMPL; }
- HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID, LCID,
- WORD wFlags, DISPPARAMS *,
- VARIANT * pVarResult, EXCEPINFO *,
- unsigned int *)
- {
- if (!(wFlags & DISPATCH_PROPERTYGET))
- return S_OK;
-
- if (pVarResult == NULL)
- return E_INVALIDARG;
-
- //The most common case is boolean, use as an initial type
- V_VT(pVarResult) = VT_BOOL;
-
- switch (dispIdMember)
- {
- case DISPID_AMBIENT_MESSAGEREFLECT:
- V_BOOL(pVarResult)= FALSE;
- return S_OK;
-
- case DISPID_AMBIENT_DISPLAYASDEFAULT:
- V_BOOL(pVarResult)= TRUE;
- return S_OK;
-
- case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
- V_BOOL(pVarResult) = TRUE;
- return S_OK;
-
- case DISPID_AMBIENT_SILENT:
- V_BOOL(pVarResult)= TRUE;
- return S_OK;
-
- case DISPID_AMBIENT_APPEARANCE:
- pVarResult->vt = VT_BOOL;
- pVarResult->boolVal = m_bAmbientAppearance;
- break;
-
- case DISPID_AMBIENT_FORECOLOR:
- pVarResult->vt = VT_I4;
- pVarResult->lVal = (long) m_clrAmbientForeColor;
- break;
-
- case DISPID_AMBIENT_BACKCOLOR:
- pVarResult->vt = VT_I4;
- pVarResult->lVal = (long) m_clrAmbientBackColor;
- break;
-
- case DISPID_AMBIENT_LOCALEID:
- pVarResult->vt = VT_I4;
- pVarResult->lVal = (long) m_nAmbientLocale;
- break;
-
- case DISPID_AMBIENT_USERMODE:
- pVarResult->vt = VT_BOOL;
- pVarResult->boolVal = m_window->m_bAmbientUserMode;
- break;
-
- case DISPID_AMBIENT_SHOWGRABHANDLES:
- pVarResult->vt = VT_BOOL;
- pVarResult->boolVal = m_bAmbientShowGrabHandles;
- break;
-
- case DISPID_AMBIENT_SHOWHATCHING:
- pVarResult->vt = VT_BOOL;
- pVarResult->boolVal = m_bAmbientShowHatching;
- break;
-
- default:
- return DISP_E_MEMBERNOTFOUND;
- }
-
- return S_OK;
- }
-
- //**************************IOleWindow***************************
- HRESULT STDMETHODCALLTYPE GetWindow(HWND * phwnd)
- {
- if (phwnd == NULL)
- return E_INVALIDARG;
- (*phwnd) = m_hWndParent;
- return S_OK;
- }
- HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL)
- {return S_OK;}
- //**************************IOleInPlaceUIWindow*****************
- HRESULT STDMETHODCALLTYPE GetBorder(LPRECT lprectBorder)
- {
- if (lprectBorder == NULL)
- return E_INVALIDARG;
- return INPLACE_E_NOTOOLSPACE;
- }
- HRESULT STDMETHODCALLTYPE RequestBorderSpace(LPCBORDERWIDTHS pborderwidths)
- {
- if (pborderwidths == NULL)
- return E_INVALIDARG;
- return INPLACE_E_NOTOOLSPACE;
- }
- HRESULT STDMETHODCALLTYPE SetBorderSpace(LPCBORDERWIDTHS)
- {return S_OK;}
- HRESULT STDMETHODCALLTYPE SetActiveObject(
- IOleInPlaceActiveObject *pActiveObject, LPCOLESTR)
- {
- if (pActiveObject)
- pActiveObject->AddRef();
-
- m_window->m_oleInPlaceActiveObject = pActiveObject;
- return S_OK;
- }
-
- //********************IOleInPlaceFrame************************
-
- STDMETHOD(InsertMenus)(HMENU, LPOLEMENUGROUPWIDTHS){return S_OK;}
- STDMETHOD(SetMenu)(HMENU, HOLEMENU, HWND){ return S_OK;}
- STDMETHOD(RemoveMenus)(HMENU){return S_OK;}
- STDMETHOD(SetStatusText)(LPCOLESTR){ return S_OK;}
- HRESULT STDMETHODCALLTYPE EnableModeless(BOOL){return S_OK;}
- HRESULT STDMETHODCALLTYPE TranslateAccelerator(LPMSG lpmsg, WORD)
- {
- // TODO: send an event with this id
- if (m_window->m_oleInPlaceActiveObject.Ok())
- m_window->m_oleInPlaceActiveObject->TranslateAccelerator(lpmsg);
- return S_FALSE;
- }
-
- //*******************IOleInPlaceSite**************************
- HRESULT STDMETHODCALLTYPE CanInPlaceActivate(){return S_OK;}
- HRESULT STDMETHODCALLTYPE OnInPlaceActivate()
- { m_bInPlaceActive = true; return S_OK; }
- HRESULT STDMETHODCALLTYPE OnUIActivate()
- { m_bUIActive = true; return S_OK; }
- HRESULT STDMETHODCALLTYPE GetWindowContext(IOleInPlaceFrame **ppFrame,
- IOleInPlaceUIWindow **ppDoc,
- LPRECT lprcPosRect,
- LPRECT lprcClipRect,
- LPOLEINPLACEFRAMEINFO lpFrameInfo)
- {
- if (ppFrame == NULL || ppDoc == NULL || lprcPosRect == NULL ||
- lprcClipRect == NULL || lpFrameInfo == NULL)
- {
- if (ppFrame != NULL)
- (*ppFrame) = NULL;
- if (ppDoc != NULL)
- (*ppDoc) = NULL;
- return E_INVALIDARG;
- }
-
- HRESULT hr = QueryInterface(IID_IOleInPlaceFrame, (void **) ppFrame);
- if (! SUCCEEDED(hr))
- {
- return E_UNEXPECTED;
- };
-
- hr = QueryInterface(IID_IOleInPlaceUIWindow, (void **) ppDoc);
- if (! SUCCEEDED(hr))
- {
- (*ppFrame)->Release();
- *ppFrame = NULL;
- return E_UNEXPECTED;
- };
-
- RECT rect;
- ::GetClientRect(m_hWndParent, &rect);
- if (lprcPosRect)
- {
- lprcPosRect->left = lprcPosRect->top = 0;
- lprcPosRect->right = rect.right;
- lprcPosRect->bottom = rect.bottom;
- };
- if (lprcClipRect)
- {
- lprcClipRect->left = lprcClipRect->top = 0;
- lprcClipRect->right = rect.right;
- lprcClipRect->bottom = rect.bottom;
- };
-
- memset(lpFrameInfo, 0, sizeof(OLEINPLACEFRAMEINFO));
- lpFrameInfo->cb = sizeof(OLEINPLACEFRAMEINFO);
- lpFrameInfo->hwndFrame = m_hWndParent;
-
- return S_OK;
- }
- HRESULT STDMETHODCALLTYPE Scroll(SIZE){return S_OK;}
- HRESULT STDMETHODCALLTYPE OnUIDeactivate(BOOL)
- { m_bUIActive = false; return S_OK; }
- HRESULT STDMETHODCALLTYPE OnInPlaceDeactivate()
- { m_bInPlaceActive = false; return S_OK; }
- HRESULT STDMETHODCALLTYPE DiscardUndoState(){return S_OK;}
- HRESULT STDMETHODCALLTYPE DeactivateAndUndo(){return S_OK; }
- HRESULT STDMETHODCALLTYPE OnPosRectChange(LPCRECT lprcPosRect)
- {
- if (m_window->m_oleInPlaceObject.Ok() && lprcPosRect)
- {
- m_window->m_oleInPlaceObject->SetObjectRects(
- lprcPosRect, lprcPosRect);
- }
- return S_OK;
- }
- //*************************IOleInPlaceSiteEx***********************
- HRESULT STDMETHODCALLTYPE OnInPlaceActivateEx(BOOL * pfNoRedraw, DWORD)
- {
- OleLockRunning(m_window->m_ActiveX, TRUE, FALSE);
- if (pfNoRedraw)
- (*pfNoRedraw) = FALSE;
- return S_OK;
- }
-
- HRESULT STDMETHODCALLTYPE OnInPlaceDeactivateEx(BOOL)
- {
- OleLockRunning(m_window->m_ActiveX, FALSE, FALSE);
- return S_OK;
- }
- STDMETHOD(RequestUIActivate)(){ return S_OK;}
- //*************************IOleClientSite**************************
- HRESULT STDMETHODCALLTYPE SaveObject(){return S_OK;}
- const char *OleGetMonikerToStr(DWORD dwAssign)
- {
- switch (dwAssign)
- {
- case OLEGETMONIKER_ONLYIFTHERE : return "OLEGETMONIKER_ONLYIFTHERE";
- case OLEGETMONIKER_FORCEASSIGN : return "OLEGETMONIKER_FORCEASSIGN";
- case OLEGETMONIKER_UNASSIGN : return "OLEGETMONIKER_UNASSIGN";
- case OLEGETMONIKER_TEMPFORUSER : return "OLEGETMONIKER_TEMPFORUSER";
- default : return "Bad Enum";
- };
- };
-
- const char *OleGetWhicMonikerStr(DWORD dwWhichMoniker)
- {
- switch(dwWhichMoniker)
- {
- case OLEWHICHMK_CONTAINER : return "OLEWHICHMK_CONTAINER";
- case OLEWHICHMK_OBJREL : return "OLEWHICHMK_OBJREL";
- case OLEWHICHMK_OBJFULL : return "OLEWHICHMK_OBJFULL";
- default : return "Bad Enum";
- };
- };
- STDMETHOD(GetMoniker)(DWORD, DWORD, IMoniker **){return E_FAIL;}
- HRESULT STDMETHODCALLTYPE GetContainer(LPOLECONTAINER * ppContainer)
- {
- if (ppContainer == NULL)
- return E_INVALIDARG;
- HRESULT hr = QueryInterface(
- IID_IOleContainer, (void**)(ppContainer));
- wxASSERT(SUCCEEDED(hr));
- return hr;
- }
- HRESULT STDMETHODCALLTYPE ShowObject()
- {
- if (m_window->m_oleObjectHWND)
- ::ShowWindow(m_window->m_oleObjectHWND, SW_SHOW);
- return S_OK;
- }
- STDMETHOD(OnShowWindow)(BOOL){return S_OK;}
- STDMETHOD(RequestNewObjectLayout)(){return E_NOTIMPL;}
- //********************IParseDisplayName***************************
- HRESULT STDMETHODCALLTYPE ParseDisplayName(
- IBindCtx *, LPOLESTR, ULONG *, IMoniker **){return E_NOTIMPL;}
- //********************IOleContainer*******************************
- STDMETHOD(EnumObjects)(DWORD, IEnumUnknown **){return E_NOTIMPL;}
- HRESULT STDMETHODCALLTYPE LockContainer(BOOL){return S_OK;}
- //********************IOleItemContainer***************************
- HRESULT STDMETHODCALLTYPE
- #ifdef _UNICODE
- GetObjectW
- #else
- GetObjectA
- #endif
- (LPOLESTR pszItem, DWORD, IBindCtx *, REFIID, void ** ppvObject)
- {
- if (pszItem == NULL || ppvObject == NULL)
- return E_INVALIDARG;
- *ppvObject = NULL;
- return MK_E_NOOBJECT;
- }
- HRESULT STDMETHODCALLTYPE GetObjectStorage(
- LPOLESTR pszItem, IBindCtx * , REFIID, void ** ppvStorage)
- {
- if (pszItem == NULL || ppvStorage == NULL)
- return E_INVALIDARG;
- *ppvStorage = NULL;
- return MK_E_NOOBJECT;
- }
- HRESULT STDMETHODCALLTYPE IsRunning(LPOLESTR pszItem)
- {
- if (pszItem == NULL)
- return E_INVALIDARG;
- return MK_E_NOOBJECT;
- }
- //***********************IOleControlSite*****************************
- HRESULT STDMETHODCALLTYPE OnControlInfoChanged()
- {return S_OK;}
- HRESULT STDMETHODCALLTYPE LockInPlaceActive(BOOL fLock)
- {
- m_bInPlaceLocked = (fLock) ? true : false;
- return S_OK;
- }
- HRESULT STDMETHODCALLTYPE GetExtendedControl(IDispatch **)
- {return E_NOTIMPL;}
- HRESULT STDMETHODCALLTYPE TransformCoords(
- POINTL * pPtlHimetric, POINTF * pPtfContainer, DWORD)
- {
- if (pPtlHimetric == NULL || pPtfContainer == NULL)
- return E_INVALIDARG;
- return E_NOTIMPL;
- }
- HRESULT STDMETHODCALLTYPE TranslateAccelerator(LPMSG, DWORD)
- {return E_NOTIMPL;}
- HRESULT STDMETHODCALLTYPE OnFocus(BOOL){return S_OK;}
- HRESULT STDMETHODCALLTYPE ShowPropertyFrame(){return E_NOTIMPL;}
- //**************************IOleCommandTarget***********************
- HRESULT STDMETHODCALLTYPE QueryStatus(const GUID *, ULONG cCmds,
- OLECMD * prgCmds, OLECMDTEXT *)
- {
- if (prgCmds == NULL) return E_INVALIDARG;
- for (ULONG nCmd = 0; nCmd < cCmds; nCmd++)
- {
- // unsupported by default
- prgCmds[nCmd].cmdf = 0;
- }
- return OLECMDERR_E_UNKNOWNGROUP;
- }
-
- HRESULT STDMETHODCALLTYPE Exec(const GUID *, DWORD,
- DWORD, VARIANTARG *, VARIANTARG *)
- {return OLECMDERR_E_NOTSUPPORTED;}
-
- //**********************IAdviseSink************************************
- void STDMETHODCALLTYPE OnDataChange(FORMATETC *, STGMEDIUM *) {}
- void STDMETHODCALLTYPE OnViewChange(DWORD, LONG) {}
- void STDMETHODCALLTYPE OnRename(IMoniker *){}
- void STDMETHODCALLTYPE OnSave(){}
- void STDMETHODCALLTYPE OnClose(){}
-
- //**********************IOleDocumentSite***************************
- HRESULT STDMETHODCALLTYPE ActivateMe(
- IOleDocumentView __RPC_FAR *pViewToActivate)
- {
- wxAutoIOleInPlaceSite inPlaceSite(
- IID_IOleInPlaceSite, (IDispatch *) this);
- if (!inPlaceSite.Ok())
- return E_FAIL;
-
- if (pViewToActivate)
- {
- m_window->m_docView = pViewToActivate;
- m_window->m_docView->SetInPlaceSite(inPlaceSite);
- }
- else
- {
- wxAutoIOleDocument oleDoc(
- IID_IOleDocument, m_window->m_oleObject);
- if (! oleDoc.Ok())
- return E_FAIL;
-
- HRESULT hr = oleDoc->CreateView(inPlaceSite, NULL,
- 0, m_window->m_docView.GetRef());
- if (hr != S_OK)
- return E_FAIL;
-
- m_window->m_docView->SetInPlaceSite(inPlaceSite);
- };
-
- m_window->m_docView->UIActivate(TRUE);
- return S_OK;
- };
-
-
-protected:
- wxActiveX * m_window;
-
- HDC m_hDCBuffer;
- HWND m_hWndParent;
-
- bool m_bSupportsWindowlessActivation;
- bool m_bInPlaceLocked;
- bool m_bInPlaceActive;
- bool m_bUIActive;
- bool m_bWindowless;
-
- LCID m_nAmbientLocale;
- COLORREF m_clrAmbientForeColor;
- COLORREF m_clrAmbientBackColor;
- bool m_bAmbientShowHatching;
- bool m_bAmbientShowGrabHandles;
- bool m_bAmbientAppearance;
-};
-
-DEFINE_OLE_TABLE(FrameSite)
- OLE_INTERFACE(IID_IUnknown, IOleClientSite)
- OLE_IINTERFACE(IOleClientSite)
- OLE_INTERFACE(IID_IOleWindow, IOleInPlaceSite)
- OLE_IINTERFACE(IOleInPlaceSite)
- OLE_IINTERFACE(IOleInPlaceSiteEx)
- OLE_IINTERFACE(IOleInPlaceUIWindow)
- OLE_IINTERFACE(IOleInPlaceFrame)
- OLE_IINTERFACE(IParseDisplayName)
- OLE_IINTERFACE(IOleContainer)
- OLE_IINTERFACE(IOleItemContainer)
- OLE_IINTERFACE(IDispatch)
- OLE_IINTERFACE(IOleCommandTarget)
- OLE_IINTERFACE(IOleDocumentSite)
- OLE_IINTERFACE(IAdviseSink)
- OLE_IINTERFACE(IOleControlSite)
-END_OLE_TABLE;
-
-
-wxActiveX::wxActiveX(wxWindow * parent, REFIID iid, IUnknown* pUnk)
- : m_realparent(parent)
-{
- m_bAmbientUserMode = true;
- m_docAdviseCookie = 0;
- CreateActiveX(iid, pUnk);
-}
-
-wxActiveX::~wxActiveX()
-{
- // disconnect connection points
- if (m_oleInPlaceObject.Ok())
- {
- m_oleInPlaceObject->InPlaceDeactivate();
- m_oleInPlaceObject->UIDeactivate();
- }
-
- if (m_oleObject.Ok())
- {
- if (m_docAdviseCookie != 0)
- m_oleObject->Unadvise(m_docAdviseCookie);
-
- m_oleObject->DoVerb(
- OLEIVERB_HIDE, NULL, m_clientSite, 0, (HWND) GetHWND(), NULL);
- m_oleObject->Close(OLECLOSE_NOSAVE);
- m_oleObject->SetClientSite(NULL);
- }
-}
-
-void wxActiveX::CreateActiveX(REFIID iid, IUnknown* pUnk)
-{
- HRESULT hret;
- hret = m_ActiveX.QueryInterface(iid, pUnk);
- wxASSERT(SUCCEEDED(hret));
-
- // FrameSite
- FrameSite *frame = new FrameSite(m_realparent, this);
- // oleClientSite
- hret = m_clientSite.QueryInterface(
- IID_IOleClientSite, (IDispatch *) frame);
- wxASSERT(SUCCEEDED(hret));
- // adviseSink
- wxAutoIAdviseSink adviseSink(IID_IAdviseSink, (IDispatch *) frame);
- wxASSERT(adviseSink.Ok());
-
- // Get Dispatch interface
- hret = m_Dispatch.QueryInterface(IID_IDispatch, m_ActiveX);
-
- // Get IOleObject interface
- hret = m_oleObject.QueryInterface(IID_IOleObject, m_ActiveX);
- wxASSERT(SUCCEEDED(hret));
-
- // get IViewObject Interface
- hret = m_viewObject.QueryInterface(IID_IViewObject, m_ActiveX);
- wxASSERT(SUCCEEDED(hret));
-
- // document advise
- m_docAdviseCookie = 0;
- hret = m_oleObject->Advise(adviseSink, &m_docAdviseCookie);
- m_oleObject->SetHostNames(L"wxActiveXContainer", NULL);
- OleSetContainedObject(m_oleObject, TRUE);
- OleRun(m_oleObject);
-
-
- // Get IOleInPlaceObject interface
- hret = m_oleInPlaceObject.QueryInterface(
- IID_IOleInPlaceObject, m_ActiveX);
- wxASSERT(SUCCEEDED(hret));
-
- // status
- DWORD dwMiscStatus;
- m_oleObject->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus);
- wxASSERT(SUCCEEDED(hret));
-
- // set client site first ?
- if (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST)
- m_oleObject->SetClientSite(m_clientSite);
-
-
- // stream init
- wxAutoIPersistStreamInit
- pPersistStreamInit(IID_IPersistStreamInit, m_oleObject);
-
- if (pPersistStreamInit.Ok())
- {
- hret = pPersistStreamInit->InitNew();
- }
-
- if (! (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST))
- m_oleObject->SetClientSite(m_clientSite);
-
-
- RECT posRect;
- ::GetClientRect((HWND)m_realparent->GetHWND(), &posRect);
-
- m_oleObjectHWND = 0;
-
- if (m_oleInPlaceObject.Ok())
- {
- hret = m_oleInPlaceObject->GetWindow(&m_oleObjectHWND);
- if (SUCCEEDED(hret))
- ::SetActiveWindow(m_oleObjectHWND);
- }
-
-
- if (! (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME))
- {
- if (posRect.right > 0 && posRect.bottom > 0 &&
- m_oleInPlaceObject.Ok())
- m_oleInPlaceObject->SetObjectRects(&posRect, &posRect);
-
- hret = m_oleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL,
- m_clientSite, 0, (HWND)m_realparent->GetHWND(), &posRect);
- hret = m_oleObject->DoVerb(OLEIVERB_SHOW, 0, m_clientSite, 0,
- (HWND)m_realparent->GetHWND(), &posRect);
- }
-
- if (! m_oleObjectHWND && m_oleInPlaceObject.Ok())
- {
- hret = m_oleInPlaceObject->GetWindow(&m_oleObjectHWND);
- }
-
- if (m_oleObjectHWND)
- {
- ::SetActiveWindow(m_oleObjectHWND);
- ::ShowWindow(m_oleObjectHWND, SW_SHOW);
-
- this->AssociateHandle(m_oleObjectHWND);
- this->Reparent(m_realparent);
-
- wxWindow* pWnd = m_realparent;
- int id = m_realparent->GetId();
-
- pWnd->Connect(id, wxEVT_SIZE,
- wxSizeEventHandler(wxActiveX::OnSize), 0, this);
- pWnd->Connect(id, wxEVT_SET_FOCUS,
- wxFocusEventHandler(wxActiveX::OnSetFocus), 0, this);
- pWnd->Connect(id, wxEVT_KILL_FOCUS,
- wxFocusEventHandler(wxActiveX::OnKillFocus), 0, this);
- }
-}
-
-#define HIMETRIC_PER_INCH 2540
-#define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
-
-static void PixelsToHimetric(SIZEL &sz)
-{
- static int logX = 0;
- static int logY = 0;
-
- if (logY == 0)
- {
- // initaliase
- HDC dc = GetDC(NULL);
- logX = GetDeviceCaps(dc, LOGPIXELSX);
- logY = GetDeviceCaps(dc, LOGPIXELSY);
- ReleaseDC(NULL, dc);
- };
-
-#define HIMETRIC_INCH 2540
-#define CONVERT(x, logpixels) MulDiv(HIMETRIC_INCH, (x), (logpixels))
-
- sz.cx = CONVERT(sz.cx, logX);
- sz.cy = CONVERT(sz.cy, logY);
-
-#undef CONVERT
-#undef HIMETRIC_INCH
-}
-
-
-void wxActiveX::OnSize(wxSizeEvent& event)
-{
- int w, h;
- GetParent()->GetClientSize(&w, &h);
-
- RECT posRect;
- posRect.left = 0;
- posRect.top = 0;
- posRect.right = w;
- posRect.bottom = h;
-
- if (w <= 0 && h <= 0)
- return;
-
- // extents are in HIMETRIC units
- if (m_oleObject.Ok())
- {
- SIZEL sz = {w, h};
- PixelsToHimetric(sz);
-
- SIZEL sz2;
-
- m_oleObject->GetExtent(DVASPECT_CONTENT, &sz2);
- if (sz2.cx != sz.cx || sz.cy != sz2.cy)
- m_oleObject->SetExtent(DVASPECT_CONTENT, &sz);
- };
-
- if (m_oleInPlaceObject.Ok())
- m_oleInPlaceObject->SetObjectRects(&posRect, &posRect);
-
- event.Skip();
-}
-
-void wxActiveX::OnPaint(wxPaintEvent& WXUNUSED(event))
-{
- wxPaintDC dc(this);
- // Draw only when control is windowless or deactivated
- if (m_viewObject)
- {
- dc.BeginDrawing();
- int w, h;
- GetParent()->GetSize(&w, &h);
- RECT posRect;
- posRect.left = 0;
- posRect.top = 0;
- posRect.right = w;
- posRect.bottom = h;
-
- ::RedrawWindow(m_oleObjectHWND, NULL, NULL, RDW_INTERNALPAINT);
- RECTL *prcBounds = (RECTL *) &posRect;
- m_viewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, NULL,
- (HDC)dc.GetHDC(), prcBounds, NULL, NULL, 0);
-
- dc.EndDrawing();
- }
-
-// We've got this one I think
-// event.Skip();
-}
-
-void wxActiveX::OnSetFocus(wxFocusEvent& event)
-{
- if (m_oleInPlaceActiveObject.Ok())
- m_oleInPlaceActiveObject->OnFrameWindowActivate(TRUE);
-
- event.Skip();
-}
-
-void wxActiveX::OnKillFocus(wxFocusEvent& event)
-{
- if (m_oleInPlaceActiveObject.Ok())
- m_oleInPlaceActiveObject->OnFrameWindowActivate(FALSE);
-
- event.Skip();
-}
//###########################################################################
//
typedef BOOL (WINAPI* LPAMGETERRORTEXT)(HRESULT, wxChar *, DWORD);
-//cludgy workaround for wx events. slots would be nice :)
-class WXDLLIMPEXP_MEDIA wxAMMediaEvtHandler : public wxEvtHandler
-{
-public:
- void OnPaint(wxPaintEvent&);
- void OnEraseBackground(wxEraseEvent&);
-};
-
-class WXDLLIMPEXP_MEDIA wxAMMediaBackend : public wxMediaBackend
+class WXDLLIMPEXP_MEDIA wxAMMediaBackend : public wxMediaBackendCommonBase
{
public:
wxAMMediaBackend();
return total;
}
- wxControl* m_ctrl;
- wxActiveX* m_pAX;
+ wxActiveXContainer* m_pAX;
IActiveMovie* m_pAM;
IMediaPlayer* m_pMP;
wxTimer* m_pTimer;
wxSize m_bestSize;
+
#ifdef __WXDEBUG__
- HMODULE m_hQuartzDll;
+ wxDynamicLibrary m_dllQuartz;
LPAMGETERRORTEXT m_lpAMGetErrorText;
wxString GetErrorString(HRESULT hrdsv);
-#endif
+#endif // __WXDEBUG__
DECLARE_DYNAMIC_CLASS(wxAMMediaBackend)
};
//---------------------------------------------------------------------------
#include <mmsystem.h>
-class WXDLLIMPEXP_MEDIA wxMCIMediaBackend : public wxMediaBackend
+class WXDLLIMPEXP_MEDIA wxMCIMediaBackend : public wxMediaBackendCommonBase
{
public:
virtual bool Pause();
virtual bool Stop();
+ virtual bool Load(const wxURI& location,
+ const wxURI& proxy)
+ { return wxMediaBackend::Load(location, proxy); }
+
virtual bool Load(const wxString& fileName);
virtual bool Load(const wxURI& location);
WPARAM wParam, LPARAM lParam);
MCIDEVICEID m_hDev; //Our MCI Device ID/Handler
- wxControl* m_ctrl; //Parent control
HWND m_hNotifyWnd; //Window to use for MCI events
bool m_bVideo; //Whether or not we have video
return true;
}
-//cludgy workaround for wx events. slots would be nice :)
-class WXDLLIMPEXP_MEDIA wxQTMediaEvtHandler : public wxEvtHandler
-{
-public:
- void OnPaint(wxPaintEvent&);
- void OnEraseBackground(wxEraseEvent&);
-};
-
-class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackend
+class WXDLLIMPEXP_MEDIA wxQTMediaBackend : public wxMediaBackendCommonBase
{
public:
wxQTMediaBackend();
virtual bool Pause();
virtual bool Stop();
+ virtual bool Load(const wxURI& location,
+ const wxURI& proxy)
+ { return wxMediaBackend::Load(location, proxy); }
+
virtual bool Load(const wxString& fileName);
virtual bool Load(const wxURI& location);
wxSize m_bestSize; //Original movie size
Movie m_movie; //QT Movie handle/instance
- wxControl* m_ctrl; //Parent control
bool m_bVideo; //Whether or not we have video
bool m_bPlaying; //Whether or not movie is playing
wxTimer* m_timer; //Load or Play timer
wxQuickTimeLibrary m_lib; //DLL to load functions from
ComponentInstance m_pMC; //Movie Controller
+ friend class wxQTMediaEvtHandler;
DECLARE_DYNAMIC_CLASS(wxQTMediaBackend)
};
+// helper to hijack background erasing for the QT window
+class WXDLLIMPEXP_MEDIA wxQTMediaEvtHandler : public wxEvtHandler
+{
+public:
+ wxQTMediaEvtHandler(wxQTMediaBackend *qtb, WXHWND hwnd)
+ {
+ m_qtb = qtb;
+ m_hwnd = hwnd;
+
+ m_qtb->m_ctrl->Connect(m_qtb->m_ctrl->GetId(),
+ wxEVT_ERASE_BACKGROUND,
+ wxEraseEventHandler(wxQTMediaEvtHandler::OnEraseBackground),
+ NULL, this
+ );
+ }
+
+ void OnEraseBackground(wxEraseEvent& event);
+
+private:
+ wxQTMediaBackend *m_qtb;
+ WXHWND m_hwnd;
+
+ DECLARE_NO_COPY_CLASS(wxQTMediaEvtHandler)
+};
+
//===========================================================================
// IMPLEMENTATION
//they can still get sent in some cases
m_parent->GetPosition() == m_parent->GetDuration())
{
- wxMediaEvent theEvent(wxEVT_MEDIA_STOP,
- m_parent->m_ctrl->GetId());
- m_parent->m_ctrl->ProcessEvent(theEvent);
-
- if(theEvent.IsAllowed())
+ if ( m_parent->SendStopEvent() )
{
//Seek to beginning of movie
m_parent->wxAMMediaBackend::SetPosition(0);
Stop();
//send the event to our child
- wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED,
- m_parent->m_ctrl->GetId());
- m_parent->m_ctrl->AddPendingEvent(theEvent);
+ m_parent->QueueFinishEvent();
}
}
}
// If this is the end of the clip, notify handler
else if(1 == evCode) //EC_COMPLETE
{
- wxMediaEvent theEvent(wxEVT_MEDIA_STOP,
- m_pBE->m_ctrl->GetId());
- m_pBE->m_ctrl->ProcessEvent(theEvent);
-
- if(theEvent.IsAllowed())
+ if ( m_pBE->SendStopEvent() )
{
Stop();
- //send the event to our child
- wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED,
- m_pBE->m_ctrl->GetId());
- m_pBE->m_ctrl->AddPendingEvent(theEvent);
+ m_pBE->QueueFinishEvent();
}
}
}
m_pAM(NULL),
m_pMP(NULL),
m_pTimer(NULL)
-#ifdef __WXDEBUG__
- ,m_hQuartzDll(NULL)
-#endif
{
}
if(m_pMP)
m_pMP->Release();
}
-#ifdef __WXDEBUG__
- if(m_hQuartzDll)
- ::FreeLibrary(m_hQuartzDll);
-#endif
}
//---------------------------------------------------------------------------
// First get the AMGetErrorText procedure in debug
// mode for more meaningful messages
#ifdef __WXDEBUG__
- m_hQuartzDll = ::LoadLibrary(wxT("quartz.dll"));
- if(m_hQuartzDll)
+ if ( m_dllQuartz.Load(_T("quartz.dll"), wxDL_VERBATIM) )
{
- m_lpAMGetErrorText = (LPAMGETERRORTEXT) ::GetProcAddress(
- m_hQuartzDll,
- wxString::Format(wxT("AMGetErrorText%s"),
-
-#if wxUSE_UNICODE
- wxT("W")
-#else
- wxT("A")
-#endif
-#ifdef __WXWINCE__
- )
-#else
- ).mb_str(wxConvLocal)
-#endif
- );
+ m_lpAMGetErrorText = (LPAMGETERRORTEXT)
+ m_dllQuartz.GetSymbolAorW(wxT("AMGetErrorText"));
}
-#endif
+#endif // __WXDEBUG__
+
// Now determine which (if any) media player interface is
// available - IMediaPlayer or IActiveMovie
if( ::CoCreateInstance(CLSID_MediaPlayer, NULL,
if( ::CoCreateInstance(CLSID_ActiveMovie, NULL,
CLSCTX_INPROC_SERVER,
IID_IActiveMovie, (void**)&m_pAM) != 0 )
- return false;
+ return false;
m_pAM->QueryInterface(IID_IMediaPlayer, (void**)&m_pMP);
}
else
// Now create the ActiveX container along with the media player
// interface and query them
//
- m_ctrl = ctrl;
- m_pAX = new wxActiveX(ctrl,
+ m_ctrl = wxStaticCast(ctrl, wxMediaCtrl);
+ m_pAX = new wxActiveXContainer(ctrl,
m_pMP ? IID_IMediaPlayer : IID_IActiveMovie,
m_pAM);
//by default with AM only 0.5
wxAMMediaBackend::SetVolume(1.0);
- // My problem with this was only with a previous patch, probably the
- // third rewrite fixed it as a side-effect. In fact, the erase
- // background style of drawing not only works now, but is much better
- // than paint-based updates (the paint event handler flickers if the
- // wxMediaCtrl shares a sizer with another child window, or is on a
- // notebook)
- // - Greg Hazel
- m_ctrl->Connect(m_ctrl->GetId(), wxEVT_ERASE_BACKGROUND,
- wxEraseEventHandler(wxAMMediaEvtHandler::OnEraseBackground),
- NULL, (wxEvtHandler*) this);
+ // don't erase the background of our control window so that resizing is a
+ // bit smoother
+ m_ctrl->SetBackgroundStyle(wxBG_STYLE_CUSTOM);
// success
return true;
//
m_pTimer = new wxAMPlayTimer(this);
- //Here, if the parent of the control has a sizer - we
- //tell it to recalculate the size of this control since
- //the user opened a separate media file
- //
- m_ctrl->InvalidateBestSize();
- m_ctrl->GetParent()->Layout();
- m_ctrl->GetParent()->Refresh();
- m_ctrl->GetParent()->Update();
- m_ctrl->SetSize(m_ctrl->GetSize());
-
- //Send event to our children
- wxMediaEvent theEvent(wxEVT_MEDIA_LOADED,
- m_ctrl->GetId());
- m_ctrl->AddPendingEvent(theEvent);
+ NotifyMovieLoaded();
}
//---------------------------------------------------------------------------
bool wxAMMediaBackend::SetVolume(double dVolume)
{
//pow(10.0, -80.0) to correct 0 == -INF
- long lVolume = (2000.0 * log10(pow(10.0, -80.0)+dVolume));
+ long lVolume = (long)(2000.0 * log10(pow(10.0, -80.0)+dVolume));
HRESULT hr = m_pAM->put_Volume( lVolume );
if(FAILED(hr))
{
{
}
-//---------------------------------------------------------------------------
-// wxAMMediaEvtHandler::OnEraseBackground
-//
-// Tell WX not to erase the background of our control window
-// so that resizing is a bit smoother
-//---------------------------------------------------------------------------
-void wxAMMediaEvtHandler::OnEraseBackground(wxEraseEvent& WXUNUSED(evt))
-{
-}
-
//---------------------------------------------------------------------------
// End of wxAMMediaBackend
//---------------------------------------------------------------------------
validator, name) )
return false;
- m_ctrl = ctrl;
+ m_ctrl = wxStaticCast(ctrl, wxMediaCtrl);
return true;
}
wxSetWindowProc(m_hNotifyWnd, wxMCIMediaBackend::NotifyWndProc);
wxSetWindowUserData(m_hNotifyWnd, this);
- //
- //Here, if the parent of the control has a sizer - we
- //tell it to recalculate the size of this control since
- //the user opened a separate media file
- //
- m_ctrl->InvalidateBestSize();
- m_ctrl->GetParent()->Layout();
- m_ctrl->GetParent()->Refresh();
- m_ctrl->GetParent()->Update();
- m_ctrl->SetSize(m_ctrl->GetSize());
-
- //send loaded event
- wxMediaEvent theEvent(wxEVT_MEDIA_LOADED,
- m_ctrl->GetId());
- m_ctrl->AddPendingEvent(theEvent);
+ NotifyMovieLoaded();
return true;
}
wxASSERT(lParam == (LPARAM) m_hDev);
if(wParam == MCI_NOTIFY_SUCCESSFUL && lParam == (LPARAM)m_hDev)
{
- wxMediaEvent theEvent(wxEVT_MEDIA_STOP, m_ctrl->GetId());
- m_ctrl->ProcessEvent(theEvent);
-
- if(theEvent.IsAllowed())
+ if ( SendStopEvent() )
{
wxMCIVERIFY( mciSendCommand(m_hDev, MCI_SEEK,
MCI_SEEK_TO_START, 0) );
- //send the event to our child
- wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED,
- m_ctrl->GetId());
- m_ctrl->ProcessEvent(theEvent);
+ QueueFinishEvent();
}
}
}
{
if(m_pLib->IsMovieDone(m_movie))
{
- wxMediaEvent theEvent(wxEVT_MEDIA_STOP,
- m_parent->m_ctrl->GetId());
- m_parent->m_ctrl->ProcessEvent(theEvent);
-
- if(theEvent.IsAllowed())
+ if ( m_parent->SendStopEvent() )
{
m_parent->Stop();
wxASSERT(m_pLib->GetMoviesError() == noErr);
- //send the event to our child
- wxMediaEvent theEvent(wxEVT_MEDIA_FINISHED,
- m_parent->m_ctrl->GetId());
- m_parent->m_ctrl->AddPendingEvent(theEvent);
+ m_parent->QueueFinishEvent();
}
}
}
// m_pMC = NULL;
}
+ // destroy wxQTMediaEvtHandler we pushed on it
+ m_ctrl->PopEventHandler(true);
+
m_lib.DestroyPortAssociation(
(CGrafPtr)m_lib.GetNativeWindowPort(m_ctrl->GetHWND()));
return false;
- m_ctrl = ctrl; //assign the control to our member
+ m_ctrl = wxStaticCast(ctrl, wxMediaCtrl);
// Create a port association for our window so we
// can use it as a WindowRef
//Part of a suggestion from Greg Hazel to repaint
//movie when idle
- m_ctrl->Connect(m_ctrl->GetId(), wxEVT_ERASE_BACKGROUND,
- wxEraseEventHandler(wxQTMediaEvtHandler::OnEraseBackground),
- NULL, (wxEvtHandler*) this);
+ m_ctrl->PushEventHandler(new wxQTMediaEvtHandler(this, m_ctrl->GetHWND()));
// done
return true;
// Note that in 99% of the cases this does nothing...
// Anyway we set up the loading timer here to tell us when the movie is done
//---------------------------------------------------------------------------
-void wxQTMediaBackend::PPRMProc (Movie theMovie, OSErr theErr, void* theRefCon)
+void wxQTMediaBackend::PPRMProc (Movie theMovie,
+ OSErr WXUNUSED_UNLESS_DEBUG(theErr),
+ void* theRefCon)
{
wxASSERT( theMovie );
wxASSERT( theRefCon );
m_lib.SetMovieTimeScale(m_movie, 1000);
wxASSERT(m_lib.GetMoviesError() == noErr);
- //
- //Here, if the parent of the control has a sizer - we
- //tell it to recalculate the size of this control since
- //the user opened a separate media file
- //
- m_ctrl->InvalidateBestSize();
- m_ctrl->GetParent()->Layout();
- m_ctrl->GetParent()->Refresh();
- m_ctrl->GetParent()->Update();
- m_ctrl->SetSize(m_ctrl->GetSize());
-
- //loaded - note that MoviesTask must and will be called before this
- //by the previous timer since this gets appended to the event list after
- //the timer's first go
- wxMediaEvent theEvent(wxEVT_MEDIA_LOADED,
- m_ctrl->GetId());
- m_ctrl->AddPendingEvent(theEvent);
+ NotifyMovieLoaded();
}
//---------------------------------------------------------------------------
if(wxrect.width < 320)
wxrect.width = 320;
- rect.top = wxrect.y;
- rect.left = wxrect.x;
- rect.right = rect.left + wxrect.width;
- rect.bottom = rect.top + wxrect.height;
+ rect.top = (short)wxrect.y;
+ rect.left = (short)wxrect.x;
+ rect.right = (short)(rect.left + wxrect.width);
+ rect.bottom = (short)(rect.top + wxrect.height);
if(!m_pMC)
{
}
}
- //
- //Here, if the parent of the control has a sizer - we
- //tell it to recalculate the size of this control since
- //the user opened a separate media file
- //
- m_ctrl->InvalidateBestSize();
- m_ctrl->GetParent()->Layout();
- m_ctrl->GetParent()->Refresh();
- m_ctrl->GetParent()->Update();
- m_ctrl->SetSize(m_ctrl->GetSize());
+ NotifyMovieSizeChanged();
return m_lib.GetMoviesError() == noErr;
}
//---------------------------------------------------------------------------
void wxQTMediaEvtHandler::OnEraseBackground(wxEraseEvent& evt)
{
- wxQTMediaBackend* qtb = (wxQTMediaBackend*)this;
- wxQuickTimeLibrary* m_pLib = &(qtb->m_lib);
+ wxQuickTimeLibrary& m_pLib = m_qtb->m_lib;
- if(qtb->m_pMC)
+ if ( m_qtb->m_pMC )
{
- //repaint movie controller
- m_pLib->MCDoAction(qtb->m_pMC, 2 /*mcActionDraw*/,
- m_pLib->GetNativeWindowPort(qtb->m_ctrl->GetHWND())
- );
+ // repaint movie controller
+ m_pLib.MCDoAction(m_qtb->m_pMC, 2 /*mcActionDraw*/,
+ m_pLib.GetNativeWindowPort(m_hwnd));
}
- else if(qtb->m_movie)
+ else // no movie controller
{
- CGrafPtr port = (CGrafPtr)m_pLib->GetNativeWindowPort
- (qtb->m_ctrl->GetHWND());
+ if ( m_qtb->m_movie )
+ {
+ CGrafPtr port = (CGrafPtr)m_pLib.GetNativeWindowPort(m_hwnd);
- m_pLib->BeginUpdate(port);
- m_pLib->UpdateMovie(qtb->m_movie);
- wxASSERT(m_pLib->GetMoviesError() == noErr);
- m_pLib->EndUpdate(port);
+ m_pLib.BeginUpdate(port);
+ m_pLib.UpdateMovie(m_qtb->m_movie);
+ wxASSERT(m_pLib.GetMoviesError() == noErr);
+ m_pLib.EndUpdate(port);
+ }
+ else // no movie
+ {
+ // let the system repaint the window
+ evt.Skip();
+ }
}
-
- evt.Skip(); //repaint with window background (TODO: maybe !m_movie?)
}
//---------------------------------------------------------------------------