viewport.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:15k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #include "hxtypes.h"
  36. #include "hxcom.h"
  37. #include "hxresult.h"
  38. #include "hxengin.h"
  39. #include "hxcore.h"
  40. #include "hxslist.h"
  41. #include "hxmap.h"
  42. #include "hxgroup.h"
  43. #include "hxplay.h"
  44. #include "hxcleng.h"
  45. #include "viewport.h"
  46. #include "hxheap.h"
  47. #ifdef _DEBUG
  48. #undef HX_THIS_FILE
  49. static const char HX_THIS_FILE[] = __FILE__;
  50. #endif
  51. #ifndef _UNIX /* probably a chinstrap tlc :) */
  52. #define XXXMEH_VIEWPORT_HACK 1
  53. #endif
  54. HXViewPort::HXViewPort(HXViewPortManager* pViewPortManager,
  55.  IHXValues* pValues,
  56.  const char* pszName)
  57.  : m_lRefCount(0)
  58.  , m_pszName(pszName)
  59.  , m_pParent(pViewPortManager)
  60.  , m_pValues(pValues)
  61. {   
  62.     if (m_pValues)
  63.     {
  64. m_pValues->AddRef();
  65.     }
  66. }
  67. HXViewPort::~HXViewPort()
  68. {
  69.     HX_RELEASE(m_pValues);
  70. }
  71. STDMETHODIMP
  72. HXViewPort::QueryInterface(REFIID riid, void**ppvObj)
  73. {
  74.     QInterfaceList qiList[] =
  75.         {
  76.             { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)this },
  77.             { GET_IIDHANDLE(IID_IHXViewPort), (IHXViewPort*)this },
  78.         };
  79.     
  80.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  81. }
  82. /////////////////////////////////////////////////////////////////////////
  83. //  Method:
  84. // IUnknown::AddRef
  85. //  Purpose:
  86. // Everyone usually implements this the same... feel free to use
  87. // this implementation.
  88. //
  89. STDMETHODIMP_(ULONG32) 
  90. HXViewPort::AddRef()
  91. {
  92.     return InterlockedIncrement(&m_lRefCount);
  93. }
  94. /////////////////////////////////////////////////////////////////////////
  95. //  Method:
  96. // IUnknown::Release
  97. //  Purpose:
  98. // Everyone usually implements this the same... feel free to use
  99. // this implementation.
  100. //
  101. STDMETHODIMP_(ULONG32) 
  102. HXViewPort::Release()
  103. {
  104.     if (InterlockedDecrement(&m_lRefCount) > 0)
  105.     {
  106.         return m_lRefCount;
  107.     }
  108.     delete this;
  109.     return 0;
  110. }
  111. /************************************************************************
  112.  * Method:
  113.  *     IHXViewPort::GetName
  114.  * Purpose:
  115.  *     get name of the viewport
  116.  */
  117. STDMETHODIMP_(const char*)
  118. HXViewPort::GetName()
  119. {
  120.     return m_pszName;
  121. }
  122. /************************************************************************
  123.  * Method:
  124.  *     IHXViewPort::GetProperties
  125.  * Purpose:
  126.  *     get properties of the viewport
  127.  */
  128. STDMETHODIMP
  129. HXViewPort::GetProperties(REF(IHXValues*)   pValues)
  130. {
  131.     pValues = m_pValues;
  132.     if (pValues)
  133.     {
  134. pValues->AddRef();
  135.     }
  136.     return HXR_OK;
  137. }
  138. /************************************************************************
  139.  * Method:
  140.  *     IHXViewPort::Show
  141.  * Purpose:
  142.  *     show viewport
  143.  */
  144. STDMETHODIMP
  145. HXViewPort::Show()
  146. {
  147.     return m_pParent->OnViewPortShow(m_pszName);
  148. }
  149. /************************************************************************
  150.  * Method:
  151.  *     IHXViewPort::Hide
  152.  * Purpose:
  153.  *     hide viewport
  154.  */
  155. STDMETHODIMP
  156. HXViewPort::Hide()
  157. {
  158.     return m_pParent->OnViewPortHide(m_pszName);
  159. }
  160. /************************************************************************
  161.  * Method:
  162.  *     IHXViewPort::SetFocus
  163.  * Purpose:
  164.  *     set focus on viewport
  165.  */
  166. STDMETHODIMP
  167. HXViewPort::SetFocus()
  168. {
  169.     return m_pParent->OnViewPortFocus(m_pszName);
  170. }
  171. /************************************************************************
  172.  * Method:
  173.  *     IHXViewPort::SetZOrder
  174.  * Purpose:
  175.  *     set Z order on viewport
  176.  */
  177. STDMETHODIMP
  178. HXViewPort::SetZOrder(UINT32 ulZOrder)
  179. {
  180.     return m_pParent->OnViewPortZOrder(m_pszName, ulZOrder);
  181. }
  182. HXViewPortManager::HXViewPortManager(HXPlayer* pPlayer)
  183. :   m_lRefCount(0)
  184. ,   m_pPlayer(pPlayer)
  185. ,   m_pViewPortMap(NULL)
  186. ,   m_pViewPortSinkList(NULL)
  187. ,   m_pViewPortSupplier(NULL)
  188. {
  189.     if (m_pPlayer)
  190.         m_pPlayer->AddRef();
  191. }
  192. HXViewPortManager::~HXViewPortManager()
  193. {
  194.     Close();
  195. }
  196. STDMETHODIMP
  197. HXViewPortManager::QueryInterface(REFIID riid, void**ppvObj)
  198. {
  199.     QInterfaceList qiList[] =
  200.         {
  201.             { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)this },
  202.             { GET_IIDHANDLE(IID_IHXViewPortManager), (IHXViewPortManager*)this },
  203.         };
  204.     
  205.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  206. }
  207. /////////////////////////////////////////////////////////////////////////
  208. //  Method:
  209. // IUnknown::AddRef
  210. //  Purpose:
  211. // Everyone usually implements this the same... feel free to use
  212. // this implementation.
  213. //
  214. STDMETHODIMP_(ULONG32) 
  215. HXViewPortManager::AddRef()
  216. {
  217.     return InterlockedIncrement(&m_lRefCount);
  218. }
  219. /////////////////////////////////////////////////////////////////////////
  220. //  Method:
  221. // IUnknown::Release
  222. //  Purpose:
  223. // Everyone usually implements this the same... feel free to use
  224. // this implementation.
  225. //
  226. STDMETHODIMP_(ULONG32) 
  227. HXViewPortManager::Release()
  228. {
  229.     if (InterlockedDecrement(&m_lRefCount) > 0)
  230.     {
  231.         return m_lRefCount;
  232.     }
  233.     delete this;
  234.     return 0;
  235. }
  236. /************************************************************************
  237.  * Method:
  238.  *     IHXViewPortManager::OpenViewPort
  239.  * Purpose:
  240.  *     create viewport
  241.  */
  242. STDMETHODIMP
  243. HXViewPortManager::OpenViewPort(IHXValues* pValues, IHXSiteUser* pSiteUser)
  244. {
  245.     HX_RESULT rc = HXR_OK;
  246.     const char* pszViewPort = NULL;
  247.     IHXBuffer* pBuffer = NULL;
  248.     HXViewPort* pViewPort = NULL;
  249.     IHXViewPortSink* pViewPortSink = NULL;
  250.     CHXSimpleList::Iterator ndx;
  251.     if (!pValues)
  252.     {
  253. rc = HXR_FAILED;
  254. goto cleanup;
  255.     }
  256.     if (HXR_OK != pValues->GetPropertyCString("playto", pBuffer))
  257.     {
  258. rc = HXR_FAILED;
  259. goto cleanup;
  260.     }
  261.     pszViewPort = (const char*)pBuffer->GetBuffer();
  262.     pViewPort = new HXViewPort(this, pValues, pszViewPort);
  263.     pViewPort->AddRef();
  264.     if (!m_pViewPortMap)  
  265.     {
  266. m_pViewPortMap = new CHXMapStringToOb();
  267.     }
  268.     m_pViewPortMap->SetAt(pszViewPort, (void*)pViewPort);
  269. #ifdef XXXMEH_VIEWPORT_HACK
  270.     // XXXMEH - hack for now until we get TLC support for
  271.     // IHXViewPortSupplier. If we don't get support from
  272.     // the TLC for IHXViewPortSupplier, then QI the SMIL
  273.     // renderer for it. We also have to check it every time
  274.     // to see if it has changed. This is because the core
  275.     // may change the persistent component and not let us
  276.     // know about it.
  277.     {
  278.         if (m_pViewPortSinkList)
  279.         {
  280.             LISTPOSITION pos = m_pViewPortSinkList->GetHeadPosition();
  281.             while (pos)
  282.             {
  283.                 IHXViewPortSink* pSink =
  284.                     (IHXViewPortSink*) m_pViewPortSinkList->GetNext(pos);
  285.                 if (pSink)
  286.                 {
  287.                     // QI for IHXViewPortSupplier
  288.                     IHXViewPortSupplier* pSupplier = NULL;
  289.                     pSink->QueryInterface(IID_IHXViewPortSupplier, (void**) &pSupplier);
  290.                     if (pSupplier != m_pViewPortSupplier)
  291.                     {
  292.                         HX_RELEASE(m_pViewPortSupplier);
  293.                         m_pViewPortSupplier = pSupplier;
  294.                         m_pViewPortSupplier->AddRef();
  295.                         HX_RELEASE(pSupplier);
  296.                         break;
  297.                     }
  298.                     HX_RELEASE(pSupplier);
  299.                 }
  300.             }
  301.         }
  302.     }
  303. #else
  304.     if (m_pPlayer && !m_pViewPortSupplier)
  305.     {
  306. if (HXR_OK != m_pPlayer->QueryInterface(IID_IHXViewPortSupplier, (void**)&m_pViewPortSupplier))
  307. {
  308.     m_pViewPortSupplier = NULL;
  309. }
  310.     }
  311. #endif
  312.     if (m_pViewPortSupplier)
  313.     {
  314. m_pViewPortSupplier->OnViewPortOpen(pValues, pSiteUser);
  315. if (m_pViewPortSinkList)
  316. {
  317.     ndx = m_pViewPortSinkList->Begin();
  318.     for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  319.     {
  320. pViewPortSink = (IHXViewPortSink*) (*ndx);
  321. pViewPortSink->ViewPortOpened(pszViewPort);
  322.     }
  323. }
  324.     }
  325. cleanup:
  326.    HX_RELEASE(pBuffer);
  327.    
  328.    return rc;
  329. }
  330. /************************************************************************
  331.  * Method:
  332.  *     IHXViewPortManager::GetViewPort
  333.  * Purpose:
  334.  *     get viewport
  335.  */
  336. STDMETHODIMP
  337. HXViewPortManager::GetViewPort(const char* pszViewPort,
  338. REF(IHXViewPort*) pViewPort)
  339. {
  340.     HX_RESULT rc = HXR_OK;
  341.     pViewPort = NULL;
  342.     if (!m_pViewPortMap)
  343.     {
  344. rc = HXR_FAILED;
  345. goto cleanup;
  346.     }
  347.     if (!m_pViewPortMap->Lookup(pszViewPort, (void*&)pViewPort))
  348.     {
  349. rc = HXR_FAILED;
  350. goto cleanup;
  351.     }
  352.     pViewPort->AddRef();
  353. cleanup:
  354.     return rc;
  355. }
  356. /************************************************************************
  357.  * Method:
  358.  *     IHXViewPortManager::CloseViewPort
  359.  * Purpose:
  360.  *     remove viewport
  361.  */
  362. STDMETHODIMP
  363. HXViewPortManager::CloseViewPort(const char* pszViewPort)
  364. {
  365.     HX_RESULT rc = HXR_OK;
  366.     IHXViewPort* pViewPort = NULL;
  367.     IHXViewPortSink* pViewPortSink = NULL;
  368.     CHXSimpleList::Iterator ndx;
  369.     if (m_pViewPortMap &&
  370. m_pViewPortMap->Lookup(pszViewPort, (void*&)pViewPort))
  371.     {
  372. m_pViewPortMap->RemoveKey(pszViewPort);
  373. HX_RELEASE(pViewPort);
  374.     }
  375.     if (m_pViewPortSupplier)
  376.     {
  377. m_pViewPortSupplier->OnViewPortClose(pszViewPort);
  378. if (m_pViewPortSinkList)
  379. {
  380.     ndx = m_pViewPortSinkList->Begin();
  381.     for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  382.     {
  383. pViewPortSink = (IHXViewPortSink*) (*ndx);
  384. pViewPortSink->ViewPortClosed(pszViewPort);
  385.     }
  386. }
  387.     }
  388.     return rc;
  389. }
  390. /************************************************************************
  391.  * Method:
  392.  *     IHXViewPortManager::AddViewPortSink
  393.  * Purpose:
  394.  *     add viewport sinker
  395.  */
  396. STDMETHODIMP
  397. HXViewPortManager::AddViewPortSink(IHXViewPortSink*  pViewPortSink)
  398. {
  399.     HX_RESULT rc = HXR_OK;
  400.     if (!m_pViewPortSinkList)
  401.     {
  402. m_pViewPortSinkList = new CHXSimpleList();
  403.     }
  404.     m_pViewPortSinkList->AddTail(pViewPortSink);
  405.     pViewPortSink->AddRef();
  406.     return rc;
  407. }
  408. /************************************************************************
  409.  * Method:
  410.  *     IHXViewPortManager::RemoveViewPortSink
  411.  * Purpose:
  412.  *     remove viewport sinker
  413.  */
  414. STDMETHODIMP
  415. HXViewPortManager::RemoveViewPortSink(IHXViewPortSink*  pViewPortSink)
  416. {
  417.     if (!m_pViewPortSinkList)
  418.     {
  419. return HXR_UNEXPECTED;
  420.     }
  421.     LISTPOSITION lPosition = m_pViewPortSinkList->Find(pViewPortSink);
  422.     if (!lPosition)
  423.     {
  424. return HXR_UNEXPECTED;
  425.     }
  426.     m_pViewPortSinkList->RemoveAt(lPosition);
  427.     HX_RELEASE(pViewPortSink);
  428.     
  429.     return HXR_OK;
  430. }
  431. HX_RESULT
  432. HXViewPortManager::OnViewPortShow(const char* pszViewPortName)
  433. {
  434.     HX_RESULT rc = HXR_OK;
  435.     IHXViewPortSink* pViewPortSink = NULL;
  436.     CHXSimpleList::Iterator ndx;
  437.     if (!m_pViewPortSupplier)
  438.     {
  439. rc = HXR_FAILED;
  440. goto cleanup;
  441.     }
  442.     m_pViewPortSupplier->OnViewPortShow(pszViewPortName);
  443.     if (m_pViewPortSinkList)
  444.     {
  445. ndx = m_pViewPortSinkList->Begin();
  446. for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  447. {
  448.     pViewPortSink = (IHXViewPortSink*) (*ndx);
  449.     pViewPortSink->ViewPortShown(pszViewPortName);
  450. }
  451.     }
  452. cleanup:
  453.     return rc;
  454. }
  455. HX_RESULT
  456. HXViewPortManager::OnViewPortHide(const char* pszViewPortName)
  457. {
  458.     HX_RESULT rc = HXR_OK;
  459.     IHXViewPortSink* pViewPortSink = NULL;
  460.     CHXSimpleList::Iterator ndx;
  461.     if (!m_pViewPortSupplier)
  462.     {
  463. rc = HXR_FAILED;
  464. goto cleanup;
  465.     }
  466.     m_pViewPortSupplier->OnViewPortHide(pszViewPortName);
  467.     if (m_pViewPortSinkList)
  468.     {
  469. ndx = m_pViewPortSinkList->Begin();
  470. for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  471. {
  472.     pViewPortSink = (IHXViewPortSink*) (*ndx);
  473.     pViewPortSink->ViewPortHidden(pszViewPortName);
  474. }
  475.     }
  476. cleanup:
  477.     return rc;
  478. }
  479. HX_RESULT
  480. HXViewPortManager::OnViewPortFocus(const char* pszViewPortName)
  481. {
  482.     HX_RESULT rc = HXR_OK;
  483.     IHXViewPortSink* pViewPortSink = NULL;
  484.     CHXSimpleList::Iterator ndx;
  485.     if (!m_pViewPortSupplier)
  486.     {
  487. rc = HXR_FAILED;
  488. goto cleanup;
  489.     }
  490.     m_pViewPortSupplier->OnViewPortFocus(pszViewPortName);
  491.     if (m_pViewPortSinkList)
  492.     {
  493. ndx = m_pViewPortSinkList->Begin();
  494. for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  495. {
  496.     pViewPortSink = (IHXViewPortSink*) (*ndx);
  497.     pViewPortSink->ViewPortFocusSet(pszViewPortName);
  498. }
  499.     }
  500. cleanup:
  501.     return rc;
  502. }
  503. HX_RESULT
  504. HXViewPortManager::OnViewPortZOrder(const char* pszViewPortName, 
  505.      UINT32 ulZOrder)
  506. {
  507.     HX_RESULT rc = HXR_OK;
  508.     IHXViewPortSink* pViewPortSink = NULL;
  509.     CHXSimpleList::Iterator ndx;
  510.     if (!m_pViewPortSupplier)
  511.     {
  512. rc = HXR_FAILED;
  513. goto cleanup;
  514.     }
  515.     m_pViewPortSupplier->OnViewPortZOrder(pszViewPortName, ulZOrder);
  516.     if (m_pViewPortSinkList)
  517.     {
  518. ndx = m_pViewPortSinkList->Begin();
  519. for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  520. {
  521.     pViewPortSink = (IHXViewPortSink*) (*ndx);
  522.     pViewPortSink->ViewPortZOrderSet(pszViewPortName, ulZOrder);
  523. }
  524.     }
  525. cleanup:
  526.     return rc;
  527. }
  528. void
  529. HXViewPortManager::Close()
  530. {
  531.     if (m_pViewPortMap)
  532.     {
  533. CHXMapStringToOb::Iterator ndx = m_pViewPortMap->Begin();
  534. for (; ndx != m_pViewPortMap->End(); ++ndx)
  535. {
  536.     HXViewPort* pViewPort = (HXViewPort*)(*ndx);
  537.     HX_RELEASE(pViewPort);
  538. }
  539.     }
  540.     HX_DELETE(m_pViewPortMap);
  541.     if (m_pViewPortSinkList)
  542.     {
  543. CHXSimpleList::Iterator ndx = m_pViewPortSinkList->Begin();
  544. for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  545. {
  546.     IHXViewPortSink* pViewPortSink = (IHXViewPortSink*)(*ndx);
  547.     HX_RELEASE(pViewPortSink);
  548. }
  549.     }
  550.     HX_DELETE(m_pViewPortSinkList);
  551.     HX_RELEASE(m_pViewPortSupplier);
  552.     HX_RELEASE(m_pPlayer);
  553. }