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

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 "minisite.h"
  36. #include "hxvsurf.h"
  37. #include "hxtick.h"
  38. #include "minisurf.h"
  39. CMiniBaseSite::CMiniBaseSite(IUnknown* pContext,
  40.                              IUnknown* pUnkOuter,
  41.                              INT32 lZorder)
  42.     :  m_pContext(pContext),
  43.        m_pCCF(NULL),
  44.        m_pUser(NULL),
  45.        m_pWatcher(NULL),
  46.        m_pValues(NULL),
  47.        m_pVideoSurface(NULL),
  48.        m_pWindow(NULL),
  49.        m_lRefCount(0),
  50.        m_lZOrder(lZorder),
  51. #if defined (HELIX_FEATURE_SMIL_SITE)
  52.        m_pTopLevelSite(NULL),
  53.        m_pParentSite(NULL),
  54.        m_Region(NULL),
  55.        m_RegionWithoutChildren(NULL),
  56.        m_bIsVisible(TRUE),
  57.        m_CallbackHandle(0),
  58.        m_pScheduler(NULL),
  59.        m_bfCallBacks(0),
  60.        m_ulCallbackTime(0),
  61. #endif
  62.        m_bWindowCreatedByCreate(FALSE)
  63. {
  64.     memset(&m_size,      0, sizeof(m_size));
  65.     memset(&m_position , 0, sizeof(m_position ));
  66. #if defined (HELIX_FEATURE_SMIL_SITE)
  67.     m_pTopLevelSite = this;
  68.     memset(&m_topleft ,  0, sizeof(m_topleft ));
  69.     memset(&m_TopLevelWindow , 0, sizeof(m_TopLevelWindow ));
  70.     if( m_pContext )
  71.     {
  72.         m_pContext->QueryInterface(IID_IHXScheduler, (void**)&m_pScheduler);
  73.     }
  74.     HX_ASSERT(m_pScheduler);
  75. #endif
  76.     if(m_pContext)
  77.     {
  78.         m_pContext->AddRef();
  79.         
  80.         // get the CCF 
  81.         m_pContext->QueryInterface(IID_IHXCommonClassFactory,
  82.                                    (void**)&m_pCCF);
  83.         if( m_pCCF )
  84.         {
  85.             m_pCCF->CreateInstance(CLSID_IHXValues, (void**)&m_pValues);
  86.         }
  87.     }
  88.     m_pVideoSurface = CMiniBaseSurface::Create(m_pContext, this);
  89.     m_pVideoSurface->AddRef();
  90. }
  91. CMiniBaseSite::~CMiniBaseSite()
  92. {
  93.     // release intefaces
  94.     HX_RELEASE(m_pValues);
  95.     HX_RELEASE(m_pCCF);
  96.     HX_RELEASE(m_pContext);
  97.     HX_RELEASE(m_pVideoSurface);
  98. #if defined(HELIX_FEATURE_SMIL_SITE)
  99.     if( m_CallbackHandle )
  100.     {
  101.         if( m_pScheduler)
  102.             m_pScheduler->Remove(m_CallbackHandle);
  103.         m_CallbackHandle = 0;
  104.     }
  105.     HX_RELEASE(m_pScheduler);
  106.     
  107.     m_ChildrenInZOrder.RemoveAll();
  108.     //clean up passive site watchers
  109.     while(m_PassiveSiteWatchers.GetCount())
  110.     {
  111.         IHXPassiveSiteWatcher* pWatcher =
  112.             (IHXPassiveSiteWatcher*)m_PassiveSiteWatchers.GetHead();
  113.         HX_RELEASE(pWatcher);
  114.         m_PassiveSiteWatchers.RemoveHead();
  115.     }
  116.     
  117. #endif    
  118. }
  119. /************************************************************************
  120.  *  Method:
  121.  *    IUnknown::QueryInterface
  122.  */
  123. STDMETHODIMP CMiniBaseSite::QueryInterface(REFIID riid, void** ppvObj)
  124. {
  125.     if(IsEqualIID(riid, IID_IUnknown))
  126.     {
  127.         *ppvObj = (IUnknown*)(IHXSite*)this;
  128.     }
  129.     else if (IsEqualIID(riid, IID_IHXSite))
  130.     {
  131.         *ppvObj = (IHXSite*)this;
  132.     }
  133. #if defined (HELIX_FEATURE_SMIL_SITE)    
  134.     else if (IsEqualIID(riid, IID_IHXSite2))
  135.     {
  136.         *ppvObj = (IHXSite2*)this;
  137.     }
  138.     else if (IsEqualIID(riid, IID_IHXSiteControl))
  139.     {
  140.         *ppvObj = (IHXSiteControl*)this;
  141.     }
  142. #endif //HELIX_FEATURE_SMIL_SITE
  143.     
  144.     else if (IsEqualIID(riid, IID_IHXSiteWindowed))
  145.     {
  146.         *ppvObj = (IHXSiteWindowed*)this;
  147.     }
  148.     else if (m_pValues &&
  149.              m_pValues->QueryInterface(riid, ppvObj) == HXR_OK)
  150.     {
  151.         return HXR_OK;
  152.     }
  153.     else
  154.     {
  155.         *ppvObj = NULL;
  156.         return HXR_NOINTERFACE;
  157.     }
  158.     AddRef();
  159.     return HXR_OK;
  160. }
  161. /************************************************************************
  162.  *  Method:
  163.  *    IUnknown::AddRef
  164.  */
  165. STDMETHODIMP_(ULONG32) CMiniBaseSite::AddRef()
  166. {
  167.     return InterlockedIncrement(&m_lRefCount);
  168. }
  169. /************************************************************************
  170.  *  Method:
  171.  *    IUnknown::Release
  172.  */
  173. STDMETHODIMP_(ULONG32) CMiniBaseSite::Release()
  174. {
  175.     if (InterlockedDecrement(&m_lRefCount) > 0)
  176.     {
  177.         return m_lRefCount;
  178.     }
  179.     delete this;
  180.     return 0;
  181. }
  182. /************************************************************************
  183.  *  Method:
  184.  *    CMiniBaseSite::AttachWindow
  185.  */
  186. STDMETHODIMP CMiniBaseSite::AttachWindow(HXxWindow* pWindow)
  187. {
  188.     if (m_pWindow && m_pWindow->window)
  189.         return HXR_UNEXPECTED;
  190.     m_pWindow = pWindow;
  191. #if defined(HELIX_FEATURE_SMIL_SITE)
  192.     if (!m_pParentSite)
  193.     {
  194.         memcpy(&m_TopLevelWindow,
  195.                pWindow,
  196.                sizeof(HXxWindow)); /* Flawfinder: ignore */
  197.     }
  198. #endif
  199.     
  200.     _AttachWindow();
  201.     if (m_pUser)
  202.     {
  203.         // send HX_ATTACH_WINDOW msg to the renderers
  204.         void *  lpParam1 = NULL;
  205.         void *  lpParam2 = NULL;
  206.         HXxEvent event = {HX_ATTACH_WINDOW,
  207.                           m_pWindow ? m_pWindow->window : NULL,
  208.                           lpParam1, lpParam2,
  209.                           0, 0 };
  210.         m_pUser->HandleEvent(&event);     
  211.     }
  212.    
  213.     return HXR_OK;
  214. }
  215. /************************************************************************
  216.  *  Method:
  217.  *    IHXSiteWindowed::DetachWindow
  218.  */
  219. STDMETHODIMP CMiniBaseSite::DetachWindow()
  220. {
  221.     if (!m_pWindow || !m_pWindow->window)
  222.         return HXR_UNEXPECTED;
  223.     
  224.     if (m_pUser)
  225.     {
  226.         // send HX_DETACH_WINDOW msg to the renderers
  227.         void *  lpParam1 = NULL;
  228.         void *  lpParam2 = NULL;
  229.         HXxEvent event = {HX_DETACH_WINDOW, m_pWindow ? m_pWindow->window : NULL, lpParam1, lpParam2, 0, 0};
  230.  
  231.         m_pUser->HandleEvent(&event);
  232.     }
  233.     // let the OS specific site do its cleanup.
  234.     _DetachWindow();
  235.     m_pWindow = NULL;
  236. #if defined(HELIX_FEATURE_SMIL_SITE)
  237.     if (m_pTopLevelSite == this)
  238.     {
  239.         if (m_CallbackHandle)
  240.         {
  241.             if( m_pScheduler )
  242.                 m_pScheduler->Remove(m_CallbackHandle);
  243.             m_CallbackHandle = 0;
  244.         }
  245.     }
  246. #endif
  247.     return HXR_OK;
  248. }
  249. /************************************************************************
  250.  *  Method:
  251.  *    IHXSiteWindowed::Create
  252.  */
  253. STDMETHODIMP CMiniBaseSite::Create(void* ParentWindow, UINT32 style)
  254. {
  255.     HRESULT retVal = HXR_OK;
  256.     
  257.     if( m_pWindow && m_pWindow->window )
  258.     {
  259.         //We already have one.
  260.         return HXR_FAIL;
  261.     }
  262.    
  263.     void* hWnd = _Create(ParentWindow, style);
  264.     if (!hWnd)
  265.     {
  266.         retVal = HXR_FAIL;
  267.     }
  268.     else
  269.     {
  270.         HXxWindow* pWindow = new HXxWindow;
  271.         memset(pWindow,0,sizeof(HXxWindow));
  272.         pWindow->window = hWnd;
  273.         //This flags tells us if Create was used to make the window
  274.         //or not. We use this in SetSize and SetPosition so that we
  275.         //never resize or move the TLCs window. But, in TLC that call
  276.         //create, like testplay, we need to do the move and resize
  277.         //for them.
  278.         m_bWindowCreatedByCreate = TRUE;
  279.       
  280.         //This way we always pass through attach window.
  281.         AttachWindow(pWindow);
  282.     }
  283.     
  284.     return retVal;
  285. }
  286. /************************************************************************
  287.  *  Method:
  288.  *    IHXSiteWindowed::Destroy
  289.  */
  290. STDMETHODIMP CMiniBaseSite::Destroy() 
  291. {
  292.     //This could be the site that owns the overlay even though
  293.     //it doesn't have a window. Give it a chance to clean up
  294.     //here...
  295.     if( m_pVideoSurface )
  296.     {
  297.         m_pVideoSurface->EndOptimizedBlt();
  298.     }
  299.     
  300.     if(!m_pWindow || !m_pWindow->window)
  301.     {
  302.         return HXR_UNEXPECTED;
  303.     }
  304.     HXxWindow tempWindow;
  305.     memcpy( &tempWindow, m_pWindow, sizeof( HXxWindow ) ); /* Flawfinder: ignore */
  306.     DetachWindow();
  307.     _Destroy(&tempWindow);
  308.     m_pWindow = NULL;
  309.     return HXR_OK;
  310. }
  311. STDMETHODIMP_(HXxWindow*) CMiniBaseSite::GetWindow() 
  312. {
  313.     HXxWindow* pRet = m_pWindow;
  314. #if defined(HELIX_FEATURE_SMIL_SITE)    
  315.     if( m_pTopLevelSite != this && m_pParentSite )
  316.         pRet = m_pParentSite->GetWindow();
  317. #endif    
  318.     return pRet;
  319. }
  320. /************************************************************************
  321.  *  Method:
  322.  *    IHXSite::AttachUser
  323.  */
  324. STDMETHODIMP CMiniBaseSite::AttachUser(IHXSiteUser* /*IN*/ pUser)
  325. {
  326.     if (m_pUser)
  327.         return HXR_UNEXPECTED;
  328.     m_pUser = pUser;
  329.     m_pUser->AddRef();
  330.     m_pUser->AttachSite(this);
  331.     /*if (m_bAttachWindowPending)
  332.       {
  333.       m_bAttachWindowPending = FALSE;
  334.       m_bDetachWndMsgPending = TRUE;
  335.       // send HX_ATTACH_WINDOW msg to the renderers
  336.       void *  lpParam1 = NULL;
  337.       void *  lpParam2 = NULL;
  338.       HXxEvent event = {HX_ATTACH_WINDOW, m_pWindow ? m_pWindow->window : NULL, lpParam1, lpParam2, 0, 0};
  339.       m_pUser->HandleEvent(&event);     
  340.       }*/
  341.     return HXR_OK;
  342. }
  343. /************************************************************************
  344.  *  Method:
  345.  *    IHXSite::DetachUser
  346.  */
  347. STDMETHODIMP CMiniBaseSite::DetachUser()
  348. {
  349.     if (!m_pUser)
  350.         return HXR_UNEXPECTED;
  351. #if defined(HELIX_FEATURE_SMIL_SITE)
  352.     if (m_CallbackHandle)
  353.     {
  354.         if( m_pScheduler)
  355.             m_pScheduler->Remove(m_CallbackHandle);
  356.         m_CallbackHandle = 0;
  357.     }
  358. #endif
  359.     AddRef();
  360.     if (HXR_OK == m_pUser->DetachSite())
  361.     {
  362.         HX_RELEASE(m_pUser);
  363.     }
  364.     Release();
  365.     return HXR_OK;
  366. }
  367. /************************************************************************
  368.  *  Method:
  369.  *    IHXSite::GetUser
  370.  */
  371. STDMETHODIMP CMiniBaseSite::GetUser(REF(IHXSiteUser*) /*OUT*/ pUser)
  372. {
  373.     if (!m_pUser)
  374.         return HXR_UNEXPECTED;
  375.     pUser = m_pUser;
  376.     pUser->AddRef();
  377.     return HXR_OK;
  378. }
  379. /************************************************************************
  380.  *  Method:
  381.  *    IHXSite::CreateChild
  382.  */
  383. STDMETHODIMP CMiniBaseSite::CreateChild(REF(IHXSite*) /*OUT*/ pChildSite)
  384. {
  385.     HRESULT result = HXR_NOTIMPL;
  386. #if defined (HELIX_FEATURE_SMIL_SITE)
  387.     // Create an instance of CMiniBaseSite, let it know it's in child
  388.     // window mode.
  389.     CMiniBaseSite* pChildSiteWindowless =
  390.         CMiniBaseSite::CreateSite(m_pContext, NULL, m_ChildrenInZOrder.GetCount());
  391.     pChildSiteWindowless->SetParentSite(this);
  392.     pChildSiteWindowless->SetTopLevelSite(m_pTopLevelSite);
  393.     pChildSiteWindowless->SetParentWindow(&m_TopLevelWindow);
  394.     // Get the IHXSite interface from the child to return to the
  395.     // outside world.
  396.     pChildSiteWindowless->QueryInterface(IID_IHXSite, (void**)&pChildSite);
  397.     //Add it to our children list
  398.     m_ChildrenInZOrder.AddTail(pChildSite);
  399.     //Make sure it has the lowest z-order.
  400.     pChildSiteWindowless->SetInternalZOrder(m_ChildrenInZOrder.GetCount());
  401.     
  402.     //Set the child's origin
  403.     pChildSiteWindowless->SetOrigin(&m_topleft);
  404.     //Let subclasses do any platform specific work.
  405.     _ChildCreated();
  406.     
  407.     result = HXR_OK;
  408. #endif
  409.     return result;
  410. }
  411. /************************************************************************
  412.  *  Method:
  413.  *    IHXSite::DestroyChild
  414.  */
  415. STDMETHODIMP CMiniBaseSite::DestroyChild(IHXSite* /*IN*/ pChildSite)
  416. {
  417.     HX_RESULT res = HXR_FAIL;
  418. #ifdef HELIX_FEATURE_SMIL_SITE
  419.     //Find this child and remove it from our list
  420.     LISTPOSITION pos = m_ChildrenInZOrder.Find((void*)pChildSite);
  421.     if(pos)
  422.     {
  423.         res = HXR_OK;
  424.         CMiniBaseSite* pSite = (CMiniBaseSite*)m_ChildrenInZOrder.GetAt(pos);
  425.         m_ChildrenInZOrder.RemoveAt(pos);
  426.     }
  427. #endif
  428.     return res;
  429. }
  430. /************************************************************************
  431.  *  Method:
  432.  *    IHXSite::AttachWatcher
  433.  */
  434. STDMETHODIMP CMiniBaseSite::AttachWatcher(IHXSiteWatcher* /*IN*/ pWatcher)
  435. {
  436.     if (m_pWatcher)
  437.         return HXR_UNEXPECTED;
  438.     m_pWatcher = pWatcher;
  439.     if (m_pWatcher)
  440.     {
  441.         m_pWatcher->AddRef();
  442.         m_pWatcher->AttachSite(this);
  443.     }
  444.     return HXR_OK;
  445. }
  446. /************************************************************************
  447.  *  Method:
  448.  *    IHXSite::DetachWatcher
  449.  */
  450. STDMETHODIMP CMiniBaseSite::DetachWatcher()
  451. {
  452.     if (!m_pWatcher)
  453.         return HXR_UNEXPECTED;
  454.     m_pWatcher->DetachSite();
  455.     HX_RELEASE(m_pWatcher);
  456.     return HXR_OK;
  457. }
  458. /************************************************************************
  459.  *  Method:
  460.  *    IHXSite::SetSize
  461.  */
  462. STDMETHODIMP CMiniBaseSite::SetSize(HXxSize size)
  463. {
  464.     HRESULT hres = HXR_OK;
  465. #if defined (HELIX_FEATURE_SMIL_SITE)
  466.     CHXSimpleList::Iterator i;
  467.     
  468.     size.cx = size.cx<0?0:size.cx;
  469.     size.cy = size.cy<0?0:size.cy;
  470.     //before we do anything, we give the SiteWatcher a chance to
  471.     //influence this operation.
  472.     if (m_pWatcher)
  473.     {
  474.         hres = m_pWatcher->ChangingSize(m_size, size);
  475.     }
  476.     
  477.     if (HXR_OK == hres )
  478.     {
  479.         m_size = size;
  480.         
  481.         // iterate child site list 
  482.         for(i=m_PassiveSiteWatchers.Begin(); i!= m_PassiveSiteWatchers.End(); ++i)
  483.         {
  484.             ((IHXPassiveSiteWatcher*) *i)->SizeChanged(&m_size);
  485.         }
  486.         if( m_pWindow && m_pWindow->window &&
  487.             (m_pTopLevelSite!=this || m_bWindowCreatedByCreate ) )
  488.         {
  489.             _SetSize(size);
  490.         }
  491.     }
  492.     if (m_pTopLevelSite==this)  
  493.     {
  494.         m_pTopLevelSite->RecomputeClip();
  495.     } 
  496.     else
  497.     {
  498.         if(m_pTopLevelSite)
  499.             m_pTopLevelSite->ScheduleCallback(CLIP, 0);
  500.     }
  501. #else
  502.     m_size = size;
  503.     _SetSize(m_size);
  504. #endif   
  505.     return hres;
  506. }
  507. /************************************************************************
  508.  *  Method:
  509.  *    IHXSite::SetPosition
  510.  */
  511. STDMETHODIMP CMiniBaseSite::SetPosition(HXxPoint position)
  512. {
  513.     HRESULT hres = HXR_OK;
  514. #if defined (HELIX_FEATURE_SMIL_SITE)
  515.     CHXSimpleList::Iterator i;
  516.     CHXMapPtrToPtr::Iterator j;
  517.     //Before we do anything, we give the SiteWatcher a chance to
  518.     //influence this operation.
  519.     if (m_pWatcher)
  520.     {
  521.         hres = m_pWatcher->ChangingPosition(m_position, position);
  522.     }
  523.     if (HXR_OK == hres)
  524.     {
  525.         if(!m_bWindowCreatedByCreate )
  526.         {
  527.             // if we've created the window we don't want to move the site
  528.             // just the window
  529.             m_position = position;
  530.         }
  531.         
  532.         //fixup our top left
  533.         ResetOrigin();
  534.         //iterate passive site watcher list 
  535.         for(i=m_PassiveSiteWatchers.Begin(); i!= m_PassiveSiteWatchers.End(); ++i)
  536.         {
  537.             ((IHXPassiveSiteWatcher*) *i)->PositionChanged(&m_position);
  538.         }
  539.         if( m_pWindow &&
  540.             m_pWindow->window &&
  541.             (m_pTopLevelSite!=this || m_bWindowCreatedByCreate )
  542.             )
  543.         {
  544.             _SetPosition(position);
  545.         }
  546.     }
  547.     if (m_pTopLevelSite==this)
  548.     {
  549.         m_pTopLevelSite->RecomputeClip();
  550.     }
  551.     else
  552.     {
  553.         if (m_pTopLevelSite)
  554.         {
  555.             m_pTopLevelSite->ScheduleCallback(CLIP, 0);
  556.         }
  557.     }
  558. #else
  559.     m_position = position;
  560.     _SetPosition(m_position);
  561. #endif    
  562.     return hres;
  563. }
  564. /************************************************************************
  565.  *  Method:
  566.  *    IHXSite::GetSize
  567.  */
  568. STDMETHODIMP CMiniBaseSite::GetSize(REF(HXxSize) size)
  569. {
  570.     size = m_size;
  571.     return HXR_OK;
  572. }
  573. /************************************************************************
  574.  *  Method:
  575.  *    IHXSite::GetPosition
  576.  */
  577. STDMETHODIMP CMiniBaseSite::GetPosition(REF(HXxPoint) position)
  578. {
  579.     position = m_position;
  580.     return HXR_OK;
  581. }
  582. /************************************************************************
  583.  *  Method:
  584.  *    IHXSite::DamageRect
  585.  */
  586. STDMETHODIMP CMiniBaseSite::DamageRect(HXxRect rect)
  587. {
  588.     return HXR_OK;
  589. }
  590. /************************************************************************
  591.  *  Method:
  592.  *    IHXSite::DamageRegion
  593.  */
  594. STDMETHODIMP CMiniBaseSite::DamageRegion(HXxRegion region)
  595. {
  596.     return HXR_OK;
  597. }
  598. /************************************************************************
  599.  *  Method:
  600.  *    IHXSite::ForceRedraw
  601.  */
  602. STDMETHODIMP CMiniBaseSite::ForceRedraw()
  603. {
  604.     
  605.     if(m_pUser)
  606.     {
  607.         HXxEvent event;
  608.         HXxWindow* hxxWin = GetWindow();
  609.         event.event   = HX_SURFACE_UPDATE;
  610.         event.window  = m_pWindow ? m_pWindow->window : NULL;
  611.         event.param1  = m_pVideoSurface;
  612.         event.param2  = NULL;
  613.         event.result  = 0;
  614.         event.handled = 0;
  615.         m_pUser->HandleEvent(&event);
  616.     }
  617.     return HXR_OK;
  618. }
  619. #if defined (HELIX_FEATURE_SMIL_SITE)
  620. STDMETHODIMP CMiniBaseSite::ForceRedrawAll()
  621. {
  622.     HX_RESULT retVal = HXR_OK;
  623.     _ForceRedrawAll();
  624.     return retVal;
  625. }
  626. /************************************************************************
  627.  *  Method:
  628.  *    IHXSite2::UpdateSiteWindow
  629.  *      
  630.  *      Not used on Windows platform
  631.  */
  632. STDMETHODIMP CMiniBaseSite::UpdateSiteWindow
  633. (
  634.     HXxWindow* /*IN*/ pWindow
  635.     )
  636. {
  637.     return HXR_NOTIMPL;
  638. }
  639. /************************************************************************
  640.  *  Method:
  641.  *    IHXSite2::ShowSite
  642.  */
  643. STDMETHODIMP CMiniBaseSite::ShowSite(BOOL bShow)
  644. {
  645.     HX_RESULT res = HXR_OK;
  646. #ifdef HELIX_FEATURE_SMIL_SITE    
  647.     if(m_bIsVisible != bShow)
  648.     {
  649.         m_bIsVisible = bShow;
  650.         if( this == m_pTopLevelSite )
  651.         {
  652.             RecomputeClip();
  653.         }
  654.         else
  655.         {
  656.             if(m_pTopLevelSite)
  657.                 m_pTopLevelSite->ScheduleCallback(CLIP, 0);
  658.         }
  659.     }
  660.     res = HXR_OK;
  661. #endif
  662.     return res;
  663. }
  664. /************************************************************************
  665.  *  Method:
  666.  *    IHXSite2::MoveSiteToTop
  667.  */
  668. STDMETHODIMP CMiniBaseSite::MoveSiteToTop()
  669. {
  670.     SetZOrder(-1); //-1 means the top.
  671.     return HXR_OK; 
  672. }
  673. /************************************************************************
  674.  *  Method:
  675.  *    IHXSite2::GetVideoSurface
  676.  */
  677. STDMETHODIMP CMiniBaseSite::GetVideoSurface(REF(IHXVideoSurface*) pSurface)
  678. {
  679.     HX_RESULT res = HXR_FAIL;
  680.     if (m_pVideoSurface)
  681.     {
  682.         res = m_pVideoSurface->QueryInterface(IID_IHXVideoSurface, 
  683.                                               (void**)&pSurface);
  684.     }
  685.     return res;
  686. }
  687. /************************************************************************
  688.  *  Method:
  689.  *    IHXSite2::AddPassiveSiteWatcher
  690.  */
  691. STDMETHODIMP CMiniBaseSite::AddPassiveSiteWatcher(IHXPassiveSiteWatcher* pWatcher)
  692. {
  693.     pWatcher->AddRef();
  694.     m_PassiveSiteWatchers.AddTail(pWatcher);
  695.     return HXR_OK;
  696. }
  697. /************************************************************************
  698.  *  Method:
  699.  *    IHXSite2::RemovePassiveSiteWatcher
  700.  */
  701. STDMETHODIMP CMiniBaseSite::RemovePassiveSiteWatcher(IHXPassiveSiteWatcher* pWatcher)
  702. {
  703.     // iterate child site list 
  704.     IHXPassiveSiteWatcher* pThisWatcher = NULL;
  705.     LISTPOSITION pPos = m_PassiveSiteWatchers.Find(pWatcher);
  706.     HX_RESULT retVal = HXR_FAIL;
  707.     if (pPos)
  708.     {
  709.         m_PassiveSiteWatchers.RemoveAt(pPos);
  710.         HX_RELEASE(pWatcher);
  711.         retVal = HXR_OK;
  712.     }
  713.     return retVal;
  714. }
  715. /************************************************************************
  716.  *  Method:
  717.  *    IHXSite2::SetCursor
  718.  */
  719. STDMETHODIMP CMiniBaseSite::SetCursor(HXxCursor cursor, REF(HXxCursor) oldCursor)
  720. {
  721.     return HXR_NOTIMPL;
  722. }
  723. STDMETHODIMP CMiniBaseSite::SetZOrder(INT32 lZOrder)
  724. {
  725.     if(!m_pParentSite) 
  726.     {
  727.         return HXR_UNEXPECTED;
  728.     }
  729.     if (lZOrder == -1)
  730.     {
  731.         lZOrder = m_pParentSite->GetNumberOfChildSites() - 1; 
  732.     }
  733.     
  734.     if (lZOrder >= (INT32) m_pParentSite->GetNumberOfChildSites())
  735.     {
  736.         lZOrder = m_pParentSite->GetNumberOfChildSites() - 1;
  737.     }
  738.     if (m_lZOrder != lZOrder)
  739.     {
  740.         m_pParentSite->UpdateZOrder(this, lZOrder);
  741.     }
  742.     if( this == m_pTopLevelSite)
  743.     {
  744.         RecomputeClip();
  745.     }
  746.     else
  747.     {
  748.         if (m_pTopLevelSite)
  749.             m_pTopLevelSite->ScheduleCallback(CLIP, 0);
  750.     }
  751.     return HXR_OK;
  752. }
  753. void CMiniBaseSite::UpdateZOrder( CMiniBaseSite* pUpdatedChildSite,INT32 lNewZOrder)
  754. {
  755.     HX_ASSERT(pUpdatedChildSite);
  756.     LISTPOSITION pos = m_ChildrenInZOrder.Find((void*)pUpdatedChildSite);
  757.     if (!pos)
  758.     {
  759.         return;
  760.     }
  761.     
  762.     m_ChildrenInZOrder.RemoveAt(pos);
  763.     
  764.     BOOL bHasReinsertedChild = FALSE;
  765.     INT32 zOrder = 0;
  766.     INT32 newZOrder = 0;
  767.     LISTPOSITION posNext = m_ChildrenInZOrder.GetHeadPosition();
  768.     while (posNext)
  769.     {
  770.         pos = posNext;
  771.         CMiniBaseSite* pSite = (CMiniBaseSite*)m_ChildrenInZOrder.GetNext(posNext);
  772.         if (!bHasReinsertedChild)
  773.         {
  774.             pSite->GetZOrder(zOrder);
  775.             
  776.             if (zOrder > lNewZOrder)
  777.             {
  778.                 m_ChildrenInZOrder.InsertBefore(pos, (void*)pUpdatedChildSite);
  779.                 bHasReinsertedChild = TRUE;
  780.                 pUpdatedChildSite->SetInternalZOrder(newZOrder++);
  781.             }
  782.         }
  783.         pSite->SetInternalZOrder(newZOrder++);
  784.     }
  785.     
  786.     if (!bHasReinsertedChild)
  787.     {
  788.         m_ChildrenInZOrder.AddTail((void*)pUpdatedChildSite);
  789.         pUpdatedChildSite->SetInternalZOrder(newZOrder++);
  790.     }
  791. }
  792. void CMiniBaseSite::RecomputeClip()
  793. {
  794.     // this recomputes our clipping rect.
  795.     if( ComputeSubRects() )
  796.     {
  797.         //We need to do this in Z-Order.
  798.         LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  799.         while(pos)
  800.         {
  801.             CMiniBaseSite* pSite = (CMiniBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  802.             pSite->RecomputeClip();
  803.         }
  804.     }
  805. }
  806. BOOL CMiniBaseSite::IsSiteVisible()
  807. {
  808.     BOOL bIsVisible = m_bIsVisible;
  809.     if(m_pParentSite)
  810.     {
  811.         bIsVisible &= m_pParentSite->IsSiteVisible();
  812.     }
  813.     if( bIsVisible )
  814.     {
  815.         //If we are a m_bSiteNeverBlts then it doesn't matter if we are
  816.         //visible or not, we must have at least one child that is
  817.         //visible and not m_bSiteNeverBlts. Otherwise we really aren't
  818.         //visible at all. This distinction is needed because of our
  819.         //favorite logic in computesubrecs not that we have transparent
  820.         //regions.
  821.         if(!_CheckForVisibleChild())
  822.         {
  823.             bIsVisible = FALSE;
  824.         }
  825.     }
  826.     return bIsVisible;
  827. }
  828. BOOL CMiniBaseSite::_CheckForVisibleChild()
  829. {
  830.     BOOL       retVal = FALSE;
  831.     BOOL       bSiteNeverBlts = FALSE;
  832.     IHXBuffer* pBuf=NULL;
  833.     m_pValues->GetPropertyCString( "SiteNeverBlts", pBuf );
  834.     if( pBuf )
  835.     {
  836.         bSiteNeverBlts = atoi( (const char*)pBuf->GetBuffer() )==1;
  837.         HX_RELEASE(pBuf);
  838.     }
  839.     
  840.     if( m_bIsVisible && !bSiteNeverBlts )
  841.     {
  842.         retVal = TRUE;
  843.     }
  844.     else
  845.     {
  846.         LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  847.         while(pos)
  848.         {
  849.             CMiniBaseSite* pSite = (CMiniBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  850.             if( pSite->_CheckForVisibleChild() )
  851.             {
  852.                 retVal = TRUE;
  853.                 break;
  854.             }
  855.         }
  856.     }
  857.     return retVal;
  858. }
  859. BOOL CMiniBaseSite::ComputeSubRects()
  860. {
  861.     BOOL         retVal          = TRUE;        
  862.     HXREGION*    hTemp           = NULL;
  863.     HXxSize      size;
  864.     HXxPoint*    pPosition       = NULL;
  865.     LISTPOSITION pos             = NULL;
  866.     if (m_Region)
  867.     {
  868.         HXDestroyRegion(m_Region);
  869.         m_Region = NULL;
  870.     }
  871.     if (m_RegionWithoutChildren)
  872.     {
  873.         HXDestroyRegion(m_RegionWithoutChildren);
  874.         m_RegionWithoutChildren = NULL;
  875.     }
  876.     if( IsSiteVisible() )
  877.     {
  878.         m_RegionWithoutChildren = HXCreateRectRegion(m_topleft.x,
  879.                                                      m_topleft.y,
  880.                                                      m_size.cx, 
  881.                                                      m_size.cy
  882.                                                      );
  883.         if (m_pParentSite)
  884.             m_pParentSite->BuildParnetClipping(m_RegionWithoutChildren,this);
  885.         // subtract all of my children from my clipping region
  886.         m_Region = HXCreateRectRegion(0,0,0,0);
  887.         HXUnionRegion(m_Region, m_RegionWithoutChildren, m_Region);
  888.         if (m_Region->numRects == 0)
  889.         {
  890.             retVal = FALSE;
  891.         }
  892.         else
  893.         {
  894.             pos = m_ChildrenInZOrder.GetHeadPosition();
  895.             while(pos)
  896.             {
  897.                 CMiniBaseSite* pSite = (CMiniBaseSite*) m_ChildrenInZOrder.GetNext(pos);
  898.                 if(pSite->IsSiteVisible())
  899.                 {    
  900.                     pPosition = pSite->GetOrigin();
  901.                     pSite->GetSize(size);
  902.                     hTemp = HXCreateRectRegion( pPosition->x,
  903.                                                 pPosition->y,
  904.                                                 size.cx, 
  905.                                                 size.cy);
  906.                     
  907.                     HXSubtractRegion(m_Region, hTemp, m_Region);
  908.                     HXDestroyRegion(hTemp);
  909.                     hTemp = NULL;
  910.                 }
  911.             }
  912.         }
  913.     }
  914.     else
  915.     {
  916.         m_RegionWithoutChildren = HXCreateRectRegion(0,0,0,0);
  917.         m_Region                = HXCreateRectRegion(0,0,0,0);
  918.     }
  919.     return TRUE;
  920. }
  921. void CMiniBaseSite::BuildParnetClipping(HXREGION* hClip, CMiniBaseSite* pChild)
  922. {
  923.     HXREGION* hTemp     = NULL;
  924.     HXxPoint* pPosition = NULL;
  925.     HXxSize   size;
  926.     BOOL      bFound    = FALSE;
  927.     // subtract all of my children from my clipping region
  928.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  929.     while(pos)
  930.     {
  931.         CMiniBaseSite* pSite = (CMiniBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  932.         //Keep in mind that all sites before pChild have zorder less than
  933.         //pChild and all sites after have a higher zorder.
  934.         if( pChild == pSite )
  935.         {
  936.             bFound = TRUE;
  937.         }
  938.         if(bFound && pChild!=pSite && pSite->IsSiteVisible())
  939.         {
  940.             pSite->GetSize(size);
  941.             pPosition = pSite->GetOrigin();
  942.             hTemp = HXCreateRectRegion( pPosition->x,
  943.                                         pPosition->y,
  944.                                         size.cx, 
  945.                                         size.cy);
  946.             HXSubtractRegion(hClip, hTemp, hClip);
  947.             HXDestroyRegion(hTemp);
  948.             hTemp=NULL;
  949.         }
  950.     }
  951.     // now handle my clipping region
  952.     hTemp = HXCreateRectRegion(m_topleft.x,
  953.                                m_topleft.y,
  954.                                m_size.cx, 
  955.                                m_size.cy);
  956.     
  957.     HXIntersectRegion(hClip, hTemp, hClip);
  958.     HXDestroyRegion(hTemp);
  959.     hTemp=NULL;
  960.     
  961.     if (m_pParentSite)
  962.         m_pParentSite->BuildParnetClipping(hClip,this);
  963. }
  964. void CMiniBaseSite::ScheduleCallback(CALLBACK_TYPE nWhichCallback,
  965.                                    INT32 nMilliseconds)
  966. {
  967.     HX_ASSERT(m_pTopLevelSite == this);
  968.     if( !(m_bfCallBacks & nWhichCallback))
  969.     {
  970.         //It is not already set.
  971.         m_bfCallBacks |= nWhichCallback;
  972.         
  973.         if (m_pScheduler)
  974.         {
  975.             ULONG32 now = HX_GET_TICKCOUNT();
  976.             if(m_CallbackHandle && m_ulCallbackTime>(now+nMilliseconds) )
  977.             {
  978.                 m_pScheduler->Remove(m_CallbackHandle);
  979.                 m_CallbackHandle = 0;
  980.             }
  981.             if( !m_CallbackHandle )
  982.             {
  983.                 //Don't schedule a new one if we are already waiting.
  984.                 m_CallbackHandle = m_pScheduler->RelativeEnter( this,
  985.                                                                 nMilliseconds);
  986.                 m_ulCallbackTime = now+nMilliseconds;
  987.             }
  988.         }
  989.     }
  990. }
  991. STDMETHODIMP CMiniBaseSite::Func(void)
  992. {
  993.     m_CallbackHandle = 0;
  994.     AddRef();
  995.     if( m_bfCallBacks & CLIP )
  996.     {
  997.         RecomputeClip();
  998.         _ForceRedrawAll();
  999.         m_bfCallBacks &= ~CLIP;
  1000.         m_bfCallBacks &= ~REDRAW_ALL;
  1001.     }
  1002.     if (m_bfCallBacks & REPAINT)
  1003.     {
  1004.         _ForceRedrawAll();
  1005.         m_bfCallBacks &= ~REPAINT;
  1006.     }
  1007.     if( m_bfCallBacks & REDRAW_ALL )
  1008.     {
  1009.         _ForceRedrawAll();
  1010.         m_bfCallBacks &= ~REDRAW_ALL;
  1011.     }
  1012.     Release();
  1013.     return HXR_OK;
  1014. }
  1015. void CMiniBaseSite::_ForceRedrawAll()
  1016. {
  1017.     if( (IsSiteVisible() && m_Region && !HXEmptyRegion(m_Region)))
  1018.     {
  1019.         ForceRedraw();
  1020.     }
  1021.    
  1022.     //Now do all the children in z-order
  1023.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1024.     while(pos)
  1025.     {
  1026.         CMiniBaseSite* pSite = (CMiniBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1027.         pSite->_ForceRedrawAll();
  1028.     }
  1029. }
  1030. void CMiniBaseSite::ResetOrigin()
  1031. {
  1032.     m_topleft.x =0;
  1033.     m_topleft.y =0;
  1034.     GetAbsoluteCords(m_topleft);
  1035.    
  1036.     LISTPOSITION pos = m_ChildrenInZOrder.GetHeadPosition();
  1037.     while(pos)
  1038.     {
  1039.         CMiniBaseSite* pChildSite = (CMiniBaseSite*)m_ChildrenInZOrder.GetNext(pos);
  1040.         pChildSite->ResetOrigin();
  1041.     }
  1042. }
  1043. void CMiniBaseSite::GetAbsoluteCords(HXxPoint& point)
  1044. {
  1045.     point.x += m_position.x;
  1046.     point.y += m_position.y;
  1047.     if (m_pParentSite)
  1048.     {
  1049.         m_pParentSite->GetAbsoluteCords(point);
  1050.     }
  1051. }
  1052. #endif //HELIX_FEATURE_SMIL_SITE