ctrl_generic.cpp 3.98 KB
Newer Older
1 2 3
/*****************************************************************************
 * ctrl_generic.cpp
 *****************************************************************************
4
 * Copyright (C) 2003 the VideoLAN team
5
 * $Id$
6 7
 *
 * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8
 *          Olivier Teulière <ipkiss@via.ecp.fr>
9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26
 *****************************************************************************/

#include "ctrl_generic.hpp"
#include "../src/generic_layout.hpp"
27
#include "../src/top_window.hpp"
28 29
#include "../src/os_graphics.hpp"
#include "../utils/position.hpp"
30
#include "../utils/var_bool.hpp"
31 32


33 34
CtrlGeneric::CtrlGeneric( intf_thread_t *pIntf, const UString &rHelp,
                          VarBool *pVisible):
35
    SkinObject( pIntf ), m_pLayout( NULL ), m_pPosition( NULL ),
36
    m_help( rHelp ), m_pVisible( pVisible )
37
{
38 39 40 41 42
    // Observe the visibility variable
    if( m_pVisible )
    {
        m_pVisible->addObserver( this );
    }
43 44 45 46 47 48 49 50 51
}


CtrlGeneric::~CtrlGeneric()
{
    if( m_pPosition )
    {
        delete m_pPosition;
    }
52 53 54 55
    if( m_pVisible )
    {
        m_pVisible->delObserver( this );
    }
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
}


void CtrlGeneric::setLayout( GenericLayout *pLayout,
                             const Position &rPosition )
{
    m_pLayout = pLayout;
    if( m_pPosition )
    {
        delete m_pPosition;
    }
    m_pPosition = new Position( rPosition );
    onPositionChange();
}


72 73
void CtrlGeneric::notifyLayout( int width, int height,
                                int xOffSet, int yOffSet ) const
74 75 76 77
{
    // Notify the layout
    if( m_pLayout )
    {
78
        m_pLayout->onControlUpdate( *this, width, height, xOffSet, yOffSet );
79 80 81 82
    }
}


83
void CtrlGeneric::notifyLayoutMaxSize( const Box *pImg1, const Box *pImg2 )
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
{
    if( pImg1 == NULL )
    {
        if( pImg2 == NULL )
        {
            notifyLayout();
        }
        else
        {
            notifyLayout( pImg2->getWidth(), pImg2->getHeight() );
        }
    }
    else
    {
        if( pImg2 == NULL )
        {
            notifyLayout( pImg1->getWidth(), pImg1->getHeight() );
        }
        else
        {
            notifyLayout( max( pImg1->getWidth(), pImg2->getWidth() ),
                          max( pImg1->getHeight(), pImg2->getHeight() ) );
        }
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    }
}


void CtrlGeneric::captureMouse() const
{
    // Tell the layout we want to capture the mouse
    if( m_pLayout )
    {
        m_pLayout->onControlCapture( *this );
    }
}


void CtrlGeneric::releaseMouse() const
{
    // Tell the layout we want to release the mouse
    if( m_pLayout )
    {
        m_pLayout->onControlRelease( *this );
    }
}


void CtrlGeneric::notifyTooltipChange() const
{
133
    TopWindow *pWin = getWindow();
134 135 136 137 138 139 140 141
    if( pWin )
    {
        // Notify the window
        pWin->onTooltipChange( *this );
    }
}


142
TopWindow *CtrlGeneric::getWindow() const
143 144 145 146 147 148 149 150
{
    if( m_pLayout )
    {
        return m_pLayout->getWindow();
    }
    return NULL;
}

151 152 153 154 155 156 157

bool CtrlGeneric::isVisible() const
{
    return !m_pVisible || m_pVisible->get();
}


158
void CtrlGeneric::onUpdate( Subject<VarBool, void*> &rVariable, void *arg  )
159
{
160
    // Is it the visibility variable ?
161 162 163 164 165 166 167 168 169 170 171 172
    if( &rVariable == m_pVisible )
    {
        // Redraw the layout
        notifyLayout();
    }
    else
    {
        // Call the user-defined callback
        onVarBoolUpdate( (VarBool&)rVariable );
    }
}