⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basesite.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    if (m_pWatcher) return HXR_UNEXPECTED;

    m_pWatcher = pWatcher;

    if (m_pWatcher)
    {
        m_pWatcher->AddRef();
        m_pWatcher->AttachSite(this);
    }

    return HXR_OK;
}

/************************************************************************
 *  Method:
 *    IHXSite::DetachWatcher
 */
STDMETHODIMP CHXBaseSite::DetachWatcher()
{
    if (!m_pWatcher) return HXR_UNEXPECTED;

    m_pWatcher->DetachSite();
    HX_RELEASE(m_pWatcher);

    return HXR_OK;
}

/************************************************************************
 *  Method:
 *    IHXSite::SetSize
 */

STDMETHODIMP CHXBaseSite::SetSize(HXxSize size)
{
    HX_RESULT ret = HXR_OK;

    _TLSLock();

    if (_AtSystemTime())
    {
        m_pTopLevelSite->ExecutePendingTasks();
        ret = _SafeSetSize(size);
        _TLSUnlock();
        return ret;
    }

    PendingTask* pPendingTask = new PendingTask( ONSETSIZE,
                                                 this,
                                                 (void*)size.cx,
                                                 (void*)size.cy,
                                                 (void*)NULL,
                                                 (void*)NULL,
                                                 (void*)NULL,
                                                 (void*)NULL
                                                 );
    m_pTopLevelSite->m_PendingTaskList.AddTail((void*) pPendingTask);
    m_pTopLevelSite->ScheduleCallback(MOUSE, 0);
    _TLSUnlock();

    return TRUE;
}

/************************************************************************
 *  Method:
 *    IHXSite::SetSize
 */
HX_RESULT CHXBaseSite::_SafeSetSize(HXxSize size)
{
    _TLSLock();

    HRESULT hres = HXR_OK;
    CHXSimpleList::Iterator i;

    size.cx = size.cx<0?0:size.cx;
    size.cy = size.cy<0?0:size.cy;

    //Fix up sizes for full screen. Some renderes, MPEG, will get very
    //late setsize calls. If we get a setsize call after we have gone
    //to fullscreen, we need to readjust our full screen window.
    if( IsFullScreen() && this==m_pTopLevelSite )
    {
        double stretchRatio = 0;
        double xRatio       = 0;
        double yRatio       = 0;
        UINT16 newBitsPerPixel = 0;
        UINT16 nHozRes      = 0;
        UINT16 nVertRes     = 0;

        _GetDeviceCaps(NULL, newBitsPerPixel, nHozRes, nVertRes);

        if(m_bPostageStamp)
        {
            if( m_windowSize.cx*2 <= nHozRes &&
                m_windowSize.cy*2 <= nVertRes)
            {
                xRatio  = yRatio = 2.0;
            }
            else
            {
                xRatio  = yRatio = 1.0;
            }

        }
        else
        {
            xRatio = (double)nHozRes  / (double)size.cx ;
            yRatio = (double)nVertRes / (double)size.cy ;
        }

        if (xRatio<yRatio)
            stretchRatio = xRatio;
        else
            stretchRatio = yRatio;

        if( m_bPostageStamp )
        {
            size.cx = (int) ((double) m_windowSize.cx * stretchRatio + 0.5);
            size.cy = (int) ((double) m_windowSize.cy * stretchRatio + 0.5);
        }
        else
        {
            size.cx = (int) ((double) size.cx * stretchRatio + 0.5);
            size.cy = (int) ((double) size.cy * stretchRatio + 0.5);
        }

#if !defined(_UNIX) || defined(_MAC_UNIX)
        m_screenOffset.x = (nHozRes  - size.cx)/2;
        m_screenOffset.y = (nVertRes - size.cy)/2;
#endif

    }

    //before we do anything, we give the SiteWatcher a chance to
    //influence this operation.
    if (m_pWatcher)
    {
        hres = m_pWatcher->ChangingSize(m_size, size);
    }

    //Get rid of our last alpha blend region as it is the wrong size
    //now....
    HX_FREE( m_pVideoSurface->m_pucLastImage );

    if (HXR_OK == hres )
    {
        //We must invalidate our rect.....
        HXxRect pTmp = { m_topleft.x,
                         m_topleft.y,
                         m_topleft.x+m_size.cx,
                         m_topleft.y+m_size.cy};
        m_pTopLevelSite->_RecursiveDamageRect( &pTmp, TRUE );

        m_size = size;

        // iterate child site list
        for(i=m_PassiveSiteWatchers.Begin(); i!= m_PassiveSiteWatchers.End(); ++i)
        {
            ((IHXPassiveSiteWatcher*) *i)->SizeChanged(&m_size);
        }

        if( m_pWindow && m_pWindow->window &&
            (m_pTopLevelSite!=this || m_bWindowCreatedByCreate ) )
        {
            _SetSize(size);
        }

        //Handle scrolling..
        if( m_pValues )
        {
            ULONG32 bScroll = FALSE;
            m_pValues->GetPropertyULONG32("ScrollingSite", bScroll);
            if (bScroll)
            {
                SetXSliderRange(size.cx);
                SetYSliderRange(size.cy);
                m_bScrollingSite = TRUE;
            }
        }
        //We must invalidate our rect after the resize also..
        HXxRect pTmp2 = { m_topleft.x,
                          m_topleft.y,
                          m_topleft.x+m_size.cx,
                          m_topleft.y+m_size.cy};
        m_pTopLevelSite->_RecursiveDamageRect( &pTmp2, TRUE );
    }
    if (this == m_pTopLevelSite && m_pStatusText)
    {
        m_pStatusText->ParentChangedSize();
    }

    if (m_pTopLevelSite==this)
    {
        m_pTopLevelSite->RecomputeClip();
    }
    else
    {
        if(m_pTopLevelSite)
            m_pTopLevelSite->ScheduleCallback(CLIP, 0);
    }


    if( this == m_pTopLevelSite && m_pStatusText )
    {
        m_pStatusText->ParentChangedSize();
    }

    //XXXgfw Don't know where to really do this work. It must be after
    //the site is created and smil can set these values but before we
    //handle events.

    //Get sensitivity setting for mouse clicks.  Only do this
    //once per site on the first event.  If 'sensitivity'
    //isn't set by then too bad.
    if( m_nEventSensitivity==SENSITIVITY_NOT_SET )
    {
        //opaque is the default set by the W3C working group.
        m_nEventSensitivity = SENSITIVITY_OPAQUE;
        if( m_pValues )
        {
            IHXBuffer* pBuf = NULL;
            m_pValues->GetPropertyCString( "sensitivity", pBuf );
            if( pBuf )
            {
                const char* pszBuff = (const char*)pBuf->GetBuffer();
                if( pszBuff)
                {
                    //m_nEventSensitivity is in alpha values [0,255]
                    if( strcmp( pszBuff, "transparent" )==0 )
                    {
                        m_nEventSensitivity = SENSITIVITY_TRANSPARENT;
                    }
                    else if( strcmp( pszBuff, "opaque" )==0 )
                    {
                        m_nEventSensitivity = SENSITIVITY_OPAQUE;
                    }
                    else
                    {

                        double sen = ::atof( pszBuff );
                        if( sen < 0 )
                            sen = 0;
                        if( sen > 100 )
                            sen = 100;
                        //Scale percentages to [0,255]
                        m_nEventSensitivity = 255-(int)(sen*255.0/100.0+0.5);
                    }
                }
                HX_RELEASE(pBuf);
            }
        }
    }


    _TLSUnlock();
    return hres;
}

/************************************************************************
 *  Method:
 *    IHXSite::SetPosition
 */

STDMETHODIMP CHXBaseSite::SetPosition(HXxPoint position)
{
    HX_RESULT ret = HXR_OK;

    _TLSLock();

    if (_AtSystemTime())
    {
        m_pTopLevelSite->ExecutePendingTasks();
        ret = _SafeSetPosition(position);
        _TLSUnlock();
        return ret;
    }

    PendingTask* pPendingTask = new PendingTask(ONSETPOSITION,
                                                this, (void*) position.x,
                                                (void*) position.y,
                                                (void*) NULL,
                                                (void*) NULL,
                                                (void*) NULL,
                                                (void*) NULL);
    m_pTopLevelSite->m_PendingTaskList.AddTail((void*) pPendingTask);
    m_pTopLevelSite->ScheduleCallback(MOUSE, 0);
    _TLSUnlock();
    return TRUE;
}

HX_RESULT CHXBaseSite::_SafeSetPosition(HXxPoint position)
{
    _TLSLock();
    HRESULT hres = HXR_OK;
    CHXSimpleList::Iterator i;
    CHXMapPtrToPtr::Iterator j;

    //Before we do anything, we give the SiteWatcher a chance to
    //influence this operation.
    if (m_pWatcher)
    {
        hres = m_pWatcher->ChangingPosition(m_position, position);
    }

#if defined(_MACINTOSH) || defined(_MAC_UNIX)
    if (this == m_pTopLevelSite)
    {
        // xxxbobclark
        // For the Mac, the top-level site is moved by adjusting
        // its HXxWindow's x and y values. If we go ahead and
        // change m_position, it can screw up situations like the
        // embedded player where it DOES call SetPosition on the
        // top-level site to move it in its window.
        _TLSUnlock();
        return HXR_OK;
    }
#endif

    if (HXR_OK == hres)
    {
        //Damage The old position....
        HXxRect pTmp = { m_topleft.x,
                         m_topleft.y,
                         m_topleft.x+m_size.cx,
                         m_topleft.y+m_size.cy};
        m_pTopLevelSite->_RecursiveDamageRect( &pTmp, TRUE );

        if(!m_bWindowCreatedByCreate )
        {
            // if we've created the window we don't want to move the site
            // just the window
            m_position     = position;
            m_positionOrig = m_position;
        }

        //fixup our top left
        ResetOrigin();

        //iterate passive site watcher list
        for(i=m_PassiveSiteWatchers.Begin(); i!= m_PassiveSiteWatchers.End(); ++i)
        {
            ((IHXPassiveSiteWatcher*) *i)->PositionChanged(&m_position);
        }

        if( m_pWindow &&
            m_pWindow->window &&
            (m_pTopLevelSite!=this || m_bWindowCreatedByCreate )
            )
        {
            m_CreateWindowPos = position;
            _SetPosition(position);
        }
    }

    //We must first remove our old dirty region because we moved and
    //we could get negative offsets...
    HXxRect pTmp2 = { m_topleft.x,
                      m_topleft.y,
                      m_topleft.x+m_size.cx,
                      m_topleft.y+m_size.cy};
    m_pTopLevelSite->_RecursiveDamageRect( &pTmp2, TRUE );

    if (m_pTopLevelSite==this)
    {
        m_pTopLevelSite->RecomputeClip();
    }
    else
    {
        if (m_pTopLevelSite)
        {
            m_pTopLevelSite->ScheduleCallback(CLIP, 0);
        }
    }

    m_pVideoSurface->UpdateDestRect();

    _TLSUnlock();
    return hres;
}


/************************************************************************
 *  Method:
 *    IHXSite::GetSize
 */
STDMETHODIMP CHXBaseSite::GetSize(REF(HXxSize) size)
{
    size = m_size;

    //XXXgfw what???????? why change it after assignment???
//     m_pValues->GetPropertyULONG32("MediaSizeX", (ULONG32&) ttt.cx);
//     m_pValues->GetPropertyULONG32("MediaSizeY", (ULONG32&) ttt.cy);

    return HXR_OK;
}


/************************************************************************
 *  Method:
 *    IHXSite::GetPosition
 */
STDMETHODIMP CHXBaseSite::GetPosition(REF(HXxPoint) position)
{
    position = m_position;
    return HXR_OK;
}

//
// CHXBaseSite::DamageRect()
//
// All incoming coordinates are SITE relative...
//
STDMETHODIMP CHXBaseSite::DamageRect(HXxRect rect)
{
#if defined(_MACINTOSH) || defined(_MAC_UNIX)
    _TLSLock();
#endif
    HXRECTANGLE rectTmp;
    HXxPoint* pOrigin = GetOrigin();

    //Crop
    if( rect.left < 0 )
        rect.left = 0;
    if( rect.top < 0 )
        rect.top = 0;
    if( rect.right > m_size.cx )
        rect.right = m_size.cx;
    if( rect.bottom > m_size.cy )
        rect.bottom = m_size.cy;

    //Translate rect to window coordinates.
    rect.left   += pOrigin->x;
    rect.right  += pOrigin->x;
    rect.top    += pOrigin->y;
    rect.bottom += pOrigin->y;

    rectTmp.x      = (short)rect.left;
    rectTmp.y      = (short)rect.top;
    rectTmp.width  = (short)(rect.right-rect.left);
    rectTmp.height = (short)(rect.bottom-rect.top);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -