generic_window.cpp 4.92 KB
Newer Older
1 2 3
/*****************************************************************************
 * generic_window.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 27
 *****************************************************************************/

#include "generic_window.hpp"
#include "os_window.hpp"
#include "os_factory.hpp"
28
#include "var_manager.hpp"
29
#include "../events/evt_refresh.hpp"
30 31 32


GenericWindow::GenericWindow( intf_thread_t *pIntf, int left, int top,
33
                              bool dragDrop, bool playOnDrop,
34
                              GenericWindow *pParent, WindowType_t type ):
35
    SkinObject( pIntf ), m_left( left ), m_top( top ), m_width( 0 ),
36
    m_height( 0 ), m_pVarVisible( NULL )
37
{
38
    // Get the OSFactory
39 40
    OSFactory *pOsFactory = OSFactory::instance( getIntf() );

41 42 43 44 45 46 47
    // Get the parent OSWindow, if any
    OSWindow *pOSParent = NULL;
    if( pParent )
    {
        pOSParent = pParent->m_pOsWindow;
    }

48
    // Create an OSWindow to handle OS specific processing
49
    m_pOsWindow = pOsFactory->createOSWindow( *this, dragDrop, playOnDrop,
50
                                              pOSParent, type );
51

52 53 54 55
    // Create the visibility variable and register it in the manager
    m_pVarVisible = new VarBoolImpl( pIntf );
    VarManager::instance( pIntf )->registerVar( VariablePtr( m_pVarVisible ) );

56
    // Observe the visibility variable
57
    m_pVarVisible->addObserver( this );
58 59 60 61 62
}


GenericWindow::~GenericWindow()
{
63
    m_pVarVisible->delObserver( this );
64

Rémi Duraffort's avatar
Rémi Duraffort committed
65
    delete m_pOsWindow;
66 67 68
}


69 70 71 72 73 74 75 76
void GenericWindow::processEvent( EvtRefresh &rEvtRefresh )
{
    // Refresh the given area
    refresh( rEvtRefresh.getXStart(), rEvtRefresh.getYStart(),
             rEvtRefresh.getWidth(), rEvtRefresh.getHeight() );
}


77
void GenericWindow::show() const
78
{
79
    m_pVarVisible->set( true );
80 81 82
}


83
void GenericWindow::hide() const
84
{
85
    m_pVarVisible->set( false );
86 87 88 89 90 91 92 93 94
}


void GenericWindow::move( int left, int top )
{
    // Update the window coordinates
    m_left = left;
    m_top = top;

95 96
    if( m_pOsWindow && isVisible() )
        m_pOsWindow->moveResize( left, top, m_width, m_height );
97 98 99 100 101
}


void GenericWindow::resize( int width, int height )
{
Erwan Tulou's avatar
Erwan Tulou committed
102
    // don't try when value is 0 (may crash)
103
    if( !width || !height )
Erwan Tulou's avatar
Erwan Tulou committed
104 105
        return;

106 107 108 109
    // Update the window size
    m_width = width;
    m_height = height;

110 111
    if( m_pOsWindow && isVisible() )
        m_pOsWindow->moveResize( m_left, m_top, width, height );
112 113 114
}


115
void GenericWindow::raise() const
116
{
117 118
    if( m_pOsWindow )
        m_pOsWindow->raise();
119 120 121 122 123 124 125 126 127
}


void GenericWindow::setOpacity( uint8_t value )
{
    m_pOsWindow->setOpacity( value );
}


128
void GenericWindow::toggleOnTop( bool onTop ) const
129
{
130 131
    if( m_pOsWindow )
        m_pOsWindow->toggleOnTop( onTop );
132 133 134
}


135
void GenericWindow::onUpdate( Subject<VarBool> &rVariable, void*arg )
136
{
Olivier Teulière's avatar
Olivier Teulière committed
137
    if (&rVariable == m_pVarVisible )
138
    {
Olivier Teulière's avatar
Olivier Teulière committed
139 140 141 142 143 144 145 146
        if( m_pVarVisible->get() )
        {
            innerShow();
        }
        else
        {
            innerHide();
        }
147 148 149 150 151 152 153 154
    }
}


void GenericWindow::innerShow()
{
    if( m_pOsWindow )
    {
Erwan Tulou's avatar
Erwan Tulou committed
155
        m_pOsWindow->show();
156
        m_pOsWindow->moveResize( m_left, m_top, m_width, m_height );
157 158 159 160 161 162 163 164 165 166 167 168
    }
}


void GenericWindow::innerHide()
{
    if( m_pOsWindow )
    {
        m_pOsWindow->hide();
    }
}

Erwan Tulou's avatar
Erwan Tulou committed
169 170 171 172 173 174 175 176 177

void* GenericWindow::getOSHandle() const
{
    return m_pOsWindow->getOSHandle();
}


void GenericWindow::setParent( GenericWindow* pParent, int x, int y, int w, int h )
{
178 179 180 181 182
    // Update the window size and position
    m_left = x;
    m_top = y;
    m_width  = ( w > 0 ) ? w : m_width;
    m_height = ( h > 0 ) ? h : m_height;
183

Erwan Tulou's avatar
Erwan Tulou committed
184
    void* handle = pParent ? pParent->getOSHandle() : NULL;
185
    m_pOsWindow->reparent( handle, m_left, m_top, m_width, m_height );
Erwan Tulou's avatar
Erwan Tulou committed
186
}
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201


void GenericWindow::invalidateRect( int left, int top, int width, int height )
{
    if( m_pOsWindow )
    {
        // tell the OS we invalidate a window client area
        bool b_supported =
            m_pOsWindow->invalidateRect( left, top, width, height );

        // if not supported, directly refresh the area
        if( !b_supported )
            refresh( left, top, width, height );
    }
}