oleobject.cpp
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:12k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * oleobject.cpp: ActiveX control for VLC
  3.  *****************************************************************************
  4.  * Copyright (C) 2005 the VideoLAN team
  5.  *
  6.  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  21.  *****************************************************************************/
  22. #include "plugin.h"
  23. #include "oleobject.h"
  24. #include "utils.h"
  25. #include <docobj.h>
  26. using namespace std;
  27. VLCOleObject::VLCOleObject(VLCPlugin *p_instance) :
  28. _p_clientsite(NULL), _p_instance(p_instance)
  29. {
  30.     CreateOleAdviseHolder(&_p_advise_holder);
  31. };
  32. VLCOleObject::~VLCOleObject()
  33. {
  34.     SetClientSite(NULL);
  35.     Close(OLECLOSE_NOSAVE);
  36.     _p_advise_holder->Release();
  37. };
  38. STDMETHODIMP VLCOleObject::Advise(IAdviseSink *pAdvSink, DWORD *dwConnection)
  39. {
  40.     return _p_advise_holder->Advise(pAdvSink, dwConnection);
  41. };
  42. STDMETHODIMP VLCOleObject::Close(DWORD dwSaveOption)
  43. {
  44.     if( _p_instance->isRunning() )
  45.     {
  46.         _p_advise_holder->SendOnClose();
  47.         return _p_instance->onClose(dwSaveOption);
  48.     }
  49.     return S_OK;
  50. };
  51. STDMETHODIMP VLCOleObject::DoVerb(LONG iVerb, LPMSG lpMsg, LPOLECLIENTSITE pActiveSite,
  52.                                     LONG lIndex, HWND hwndParent, LPCRECT lprcPosRect)
  53. {
  54.     switch( iVerb )
  55.     {
  56.         case OLEIVERB_PRIMARY:
  57.         case OLEIVERB_SHOW:
  58.         case OLEIVERB_OPEN:
  59.             // force control to be visible when activating in place
  60.             _p_instance->setVisible(TRUE);
  61.             return doInPlaceActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect, TRUE);
  62.         case OLEIVERB_INPLACEACTIVATE:
  63.             return doInPlaceActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect, FALSE);
  64.         case OLEIVERB_HIDE:
  65.             _p_instance->setVisible(FALSE);
  66.             return S_OK;
  67.         case OLEIVERB_UIACTIVATE:
  68.             // UI activate only if visible
  69.             if( _p_instance->isVisible() )
  70.                 return doInPlaceActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect, TRUE);
  71.             return OLEOBJ_S_CANNOT_DOVERB_NOW;
  72.         case OLEIVERB_DISCARDUNDOSTATE:
  73.             return S_OK;
  74.         default:
  75.             if( iVerb > 0 ) {
  76.                 _p_instance->setVisible(TRUE);
  77.                 doInPlaceActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect, TRUE);
  78.                 return OLEOBJ_S_INVALIDVERB;
  79.             }
  80.             return E_NOTIMPL;
  81.     }
  82. };
  83. HRESULT VLCOleObject::doInPlaceActivate(LPMSG lpMsg, LPOLECLIENTSITE pActiveSite, HWND hwndParent, LPCRECT lprcPosRect, BOOL uiActivate)
  84. {
  85.     RECT posRect;
  86.     RECT clipRect;
  87.     LPCRECT lprcClipRect = lprcPosRect;
  88.     if( pActiveSite )
  89.     {
  90.         LPOLEINPLACESITE p_inPlaceSite;
  91.         IOleInPlaceSiteEx *p_inPlaceSiteEx;
  92.         LPOLEINPLACEFRAME p_inPlaceFrame;
  93.         LPOLEINPLACEUIWINDOW p_inPlaceUIWindow;
  94.         if( SUCCEEDED(pActiveSite->QueryInterface(IID_IOleInPlaceSiteEx, reinterpret_cast<void**>(&p_inPlaceSiteEx))) )
  95.         {
  96.             p_inPlaceSite = p_inPlaceSiteEx;
  97.             p_inPlaceSite->AddRef();
  98.         }
  99.         else if FAILED(pActiveSite->QueryInterface(IID_IOleInPlaceSite, reinterpret_cast<void**>(&p_inPlaceSite)) )
  100.         {
  101.             p_inPlaceSite = p_inPlaceSiteEx = NULL;
  102.         }
  103.         if( p_inPlaceSite )
  104.         {
  105.             OLEINPLACEFRAMEINFO oleFrameInfo;
  106.             oleFrameInfo.cb = sizeof(OLEINPLACEFRAMEINFO);
  107.             if( SUCCEEDED(p_inPlaceSite->GetWindowContext(&p_inPlaceFrame, &p_inPlaceUIWindow, &posRect, &clipRect, &oleFrameInfo)) )
  108.             {
  109.                 lprcPosRect = &posRect;
  110.                 lprcClipRect = &clipRect;
  111.             }
  112.             if( (NULL == hwndParent) && FAILED(p_inPlaceSite->GetWindow(&hwndParent)) )
  113.             {
  114.                 p_inPlaceSite->Release();
  115.                 if( p_inPlaceSiteEx )
  116.                     p_inPlaceSiteEx->Release();
  117.                 if( p_inPlaceFrame )
  118.                     p_inPlaceFrame->Release();
  119.                 if( p_inPlaceUIWindow )
  120.                     p_inPlaceUIWindow->Release();
  121.                 return OLEOBJ_S_INVALIDHWND;
  122.             }
  123.         }
  124.         else if( NULL == hwndParent )
  125.         {
  126.             return OLEOBJ_S_INVALIDHWND;
  127.         }
  128.         else if( NULL == lprcPosRect )
  129.         {
  130.             SetRect(&posRect, 0, 0, 0, 0);
  131.             lprcPosRect = &posRect;
  132.             lprcClipRect = &posRect;
  133.         }
  134.         // check if not already activated
  135.         if( ! _p_instance->isInPlaceActive() )
  136.         {
  137.             if( ((NULL == p_inPlaceSite) || (S_OK == p_inPlaceSite->CanInPlaceActivate()))
  138.              && SUCCEEDED(_p_instance->onActivateInPlace(lpMsg, hwndParent, lprcPosRect, lprcClipRect)) )
  139.             {
  140.                 if( p_inPlaceSiteEx )
  141.                 {
  142.                     BOOL needsRedraw;
  143.                     p_inPlaceSiteEx->OnInPlaceActivateEx(&needsRedraw, 0);
  144.                 }
  145.                 else if( p_inPlaceSite )
  146.                     p_inPlaceSite->OnInPlaceActivate();
  147.             }
  148.             else
  149.             {
  150.                 if( p_inPlaceSite )
  151.                 {
  152.                     p_inPlaceSite->Release();
  153.                     if( p_inPlaceSiteEx )
  154.                         p_inPlaceSiteEx->Release();
  155.                     if( p_inPlaceFrame )
  156.                         p_inPlaceFrame->Release();
  157.                     if( p_inPlaceUIWindow )
  158.                         p_inPlaceUIWindow->Release();
  159.                 }
  160.                 return OLEOBJ_S_CANNOT_DOVERB_NOW;
  161.             }
  162.         }
  163.         if( p_inPlaceSite )
  164.             p_inPlaceSite->OnPosRectChange(lprcPosRect);
  165.         if( uiActivate )
  166.         {
  167.             if( (NULL == p_inPlaceSiteEx) || (S_OK == p_inPlaceSiteEx->RequestUIActivate()) )
  168.             {
  169.                 if( p_inPlaceSite)
  170.                 {
  171.                     p_inPlaceSite->OnUIActivate();
  172.                     LPOLEINPLACEACTIVEOBJECT p_inPlaceActiveObject;
  173.                     if( SUCCEEDED(QueryInterface(IID_IOleInPlaceActiveObject, reinterpret_cast<void**>(&p_inPlaceActiveObject))) )
  174.                     {
  175.                         if( p_inPlaceFrame )
  176.                             p_inPlaceFrame->SetActiveObject(p_inPlaceActiveObject, NULL);
  177.                         if( p_inPlaceUIWindow )
  178.                             p_inPlaceUIWindow->SetActiveObject(p_inPlaceActiveObject, NULL);
  179.                         p_inPlaceActiveObject->Release();
  180.                     }
  181.                     if( p_inPlaceFrame )
  182.                         p_inPlaceFrame->RequestBorderSpace(NULL);
  183.                     pActiveSite->ShowObject();
  184.                 }
  185.                 _p_instance->setFocus(TRUE);
  186.             }
  187.         }
  188.         if( p_inPlaceSite )
  189.         {
  190.             p_inPlaceSite->Release();
  191.             if( p_inPlaceSiteEx )
  192.                 p_inPlaceSiteEx->Release();
  193.             if( p_inPlaceFrame )
  194.                 p_inPlaceFrame->Release();
  195.             if( p_inPlaceUIWindow )
  196.                 p_inPlaceUIWindow->Release();
  197.         }
  198.         return S_OK;
  199.     }
  200.     return OLEOBJ_S_CANNOT_DOVERB_NOW;
  201. };
  202. STDMETHODIMP VLCOleObject::EnumAdvise(IEnumSTATDATA **ppEnumAdvise)
  203. {
  204.     return _p_advise_holder->EnumAdvise(ppEnumAdvise);
  205. };
  206. STDMETHODIMP VLCOleObject::EnumVerbs(IEnumOleVerb **ppEnumOleVerb)
  207. {
  208.     return OleRegEnumVerbs(_p_instance->getClassID(),
  209.         ppEnumOleVerb);
  210. };
  211. STDMETHODIMP VLCOleObject::GetClientSite(LPOLECLIENTSITE *ppClientSite)
  212. {
  213.     if( NULL == ppClientSite )
  214.         return E_POINTER;
  215.     if( NULL != _p_clientsite )
  216.         _p_clientsite->AddRef();
  217.     *ppClientSite = _p_clientsite;
  218.     return S_OK;
  219. };
  220. STDMETHODIMP VLCOleObject::GetClipboardData(DWORD dwReserved, LPDATAOBJECT *ppDataObject)
  221. {
  222.     return _p_instance->pUnkOuter->QueryInterface(IID_IDataObject, (void **)ppDataObject);
  223. };
  224. STDMETHODIMP VLCOleObject::GetExtent(DWORD dwDrawAspect, SIZEL *pSizel)
  225. {
  226.     if( NULL == pSizel )
  227.         return E_POINTER;
  228.     if( dwDrawAspect & DVASPECT_CONTENT )
  229.     {
  230.         *pSizel = _p_instance->getExtent();
  231.         return S_OK;
  232.     }
  233.     pSizel->cx= 0L;
  234.     pSizel->cy= 0L;
  235.     return E_NOTIMPL;
  236. };
  237. STDMETHODIMP VLCOleObject::GetMiscStatus(DWORD dwAspect, DWORD *pdwStatus)
  238. {
  239.     if( NULL == pdwStatus )
  240.         return E_POINTER;
  241.     switch( dwAspect )
  242.     {
  243.         case DVASPECT_CONTENT:
  244.             *pdwStatus = OLEMISC_RECOMPOSEONRESIZE
  245.                 | OLEMISC_CANTLINKINSIDE
  246.                 | OLEMISC_INSIDEOUT
  247.                 | OLEMISC_ACTIVATEWHENVISIBLE
  248.                 | OLEMISC_SETCLIENTSITEFIRST;
  249.             break;
  250.         default:
  251.             *pdwStatus = 0;
  252.     }
  253.     return S_OK;
  254. };
  255. STDMETHODIMP VLCOleObject::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER *ppMoniker)
  256. {
  257.     if( NULL != _p_clientsite )
  258.         return _p_clientsite->GetMoniker(dwAssign,dwWhichMoniker, ppMoniker);
  259.     return E_UNEXPECTED;
  260. };
  261. STDMETHODIMP VLCOleObject::GetUserClassID(LPCLSID pClsid)
  262. {
  263.     if( NULL == pClsid )
  264.         return E_POINTER;
  265.  
  266.     *pClsid = _p_instance->getClassID();
  267.     return S_OK;
  268. };
  269. STDMETHODIMP VLCOleObject::GetUserType(DWORD dwFormOfType, LPOLESTR *pszUserType)
  270. {
  271.     return OleRegGetUserType(_p_instance->getClassID(),
  272.         dwFormOfType, pszUserType);
  273. };
  274. STDMETHODIMP VLCOleObject::InitFromData(LPDATAOBJECT pDataObject, BOOL fCreation, DWORD dwReserved)
  275. {
  276.     return E_NOTIMPL;
  277. };
  278. STDMETHODIMP VLCOleObject::IsUpToDate(void)
  279. {
  280.     return S_OK;
  281. };
  282. STDMETHODIMP VLCOleObject::SetClientSite(LPOLECLIENTSITE pClientSite)
  283. {
  284.     if( NULL != _p_clientsite )
  285.         _p_clientsite->Release();
  286.     _p_clientsite = pClientSite;
  287.     if( NULL != pClientSite )
  288.     {
  289.         pClientSite->AddRef();
  290.         _p_instance->onAmbientChanged(pClientSite, DISPID_UNKNOWN);
  291.     }
  292.     return S_OK;
  293. };
  294. STDMETHODIMP VLCOleObject::SetColorScheme(LOGPALETTE *pLogpal)
  295. {
  296.     return E_NOTIMPL;
  297. };
  298. STDMETHODIMP VLCOleObject::SetExtent(DWORD dwDrawAspect, SIZEL *pSizel)
  299. {
  300.     if( NULL == pSizel )
  301.         return E_POINTER;
  302.     if( dwDrawAspect & DVASPECT_CONTENT )
  303.     {
  304.         _p_instance->setExtent(*pSizel);
  305.         if( _p_instance->isInPlaceActive() )
  306.         {
  307.             LPOLEINPLACESITE p_inPlaceSite;
  308.             if( SUCCEEDED(_p_clientsite->QueryInterface(IID_IOleInPlaceSite, (void**)&p_inPlaceSite)) )
  309.             {
  310.                 HWND hwnd;
  311.                 if( SUCCEEDED(p_inPlaceSite->GetWindow(&hwnd)) )
  312.                 {
  313.                     // use HIMETRIC to pixel transform
  314.                     RECT posRect = _p_instance->getPosRect();
  315.                     HDC hDC = GetDC(hwnd);
  316.                     posRect.right = (pSizel->cx*GetDeviceCaps(hDC, LOGPIXELSX)/2540L)+posRect.left;
  317.                     posRect.bottom = (pSizel->cy*GetDeviceCaps(hDC, LOGPIXELSY)/2540L)+posRect.top;
  318.                     DeleteDC(hDC);
  319.                     p_inPlaceSite->OnPosRectChange(&posRect);
  320.                 }
  321.                 p_inPlaceSite->Release();
  322.             }
  323.         }
  324.         return S_OK;
  325.     }
  326.     return E_NOTIMPL;
  327. };
  328. STDMETHODIMP VLCOleObject::SetHostNames(LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
  329. {
  330.     return S_OK;
  331. };
  332. STDMETHODIMP VLCOleObject::SetMoniker(DWORD dwWhichMoniker, LPMONIKER pMoniker)
  333. {
  334.     return _p_advise_holder->SendOnRename(pMoniker);
  335. };
  336. STDMETHODIMP VLCOleObject::Unadvise(DWORD dwConnection)
  337. {
  338.     return _p_advise_holder->Unadvise(dwConnection);
  339. };
  340. STDMETHODIMP VLCOleObject::Update(void)
  341. {
  342.     return S_OK;
  343. };