/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: windowgraphicdevicebase.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: hr $ $Date: 2006/06/20 02:14:37 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef INCLUDED_CANVAS_WINDOWGRAPHICDEVICEBASE_HXX
#define INCLUDED_CANVAS_WINDOWGRAPHICDEVICEBASE_HXX

#ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
#include <com/sun/star/awt/XWindow.hpp>
#endif

#ifndef INCLUDED_CANVAS_GRAPHICDEVICEBASE_HXX
#include <canvas/base/graphicdevicebase.hxx>
#endif


/* Definition of WindowGraphicDeviceBase class */

namespace canvas
{
    /** Helper template base class for XGraphicDevice implementations
        on windows.
        
        Use this base class if your target device is a
        window. Additionally to GraphicDeviceBase, this template
        provides an implementation of the awt::XWindow interface, to
        receive notifications about state changes of the associated
        window.

        @tpl Base
        Base class to use, most probably one of the
        WeakComponentImplHelperN templates with the appropriate
        interfaces. At least XGraphicDevice should be among them (why else
        would you use this template, then?). Base class must have an
        Base( const Mutex& ) constructor (like the
        WeakComponentImplHelperN templates have). As the very least,
        the base class must be derived from uno::XInterface, as some
        error reporting mechanisms rely on that.

        @tpl DeviceHelper
        Device helper implementation for the backend in question. This
        object will be held as a member of this template class, and
        basically gets forwarded all XGraphicDevice API calls that
        could not be handled generically.

        @tpl Mutex
        Lock strategy to use. Defaults to using the
        OBaseMutex-provided lock.  Everytime one of the methods is
        entered, an object of type Mutex is created with m_aMutex as
        the sole parameter, and destroyed again when the method scope
        is left.

        @tpl UnambiguousBase
        Optional unambiguous base class for XInterface of Base. It's
        sometimes necessary to specify this parameter, e.g. if Base
        derives from multiple UNO interface (were each provides its
        own version of XInterface, making the conversion ambiguous)
     */
    template< class Base, 
              class DeviceHelper, 
              class Mutex=::osl::MutexGuard, 
              class UnambiguousBase=::com::sun::star::uno::XInterface > class WindowGraphicDeviceBase : 
        public GraphicDeviceBase< Base, DeviceHelper, Mutex, UnambiguousBase >
    {
    public:
        typedef GraphicDeviceBase< Base, DeviceHelper, Mutex, UnambiguousBase >	BaseType;

        WindowGraphicDeviceBase() :
            maBounds(),
            mbIsVisible( false )
        {
        }

        virtual void SAL_CALL disposing()
        {
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );

            BaseType::maDeviceHelper.disposing();

            // pass on to base class
            BaseType::disposing();
        }

        // XWindow
        virtual void SAL_CALL setPosSize( ::sal_Int32 nX, 
                                          ::sal_Int32 nY, 
                                          ::sal_Int32 nWidth, 
                                          ::sal_Int32 nHeight, 
                                          ::sal_Int16 /*nFlags*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );

            maBounds.X = nX;
            maBounds.Y = nY;
            maBounds.Width = nWidth;
            maBounds.Height = nHeight;
            
            BaseType::maDeviceHelper.notifySizeUpdate( maBounds );
        }

        virtual ::com::sun::star::awt::Rectangle SAL_CALL getPosSize(  ) throw (::com::sun::star::uno::RuntimeException)
        {
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );

            return maBounds;
        }

        virtual void SAL_CALL setVisible( ::sal_Bool bVisible ) throw (::com::sun::star::uno::RuntimeException)
        {
            typename BaseType::MutexType aGuard( BaseType::m_aMutex );

            mbIsVisible = bVisible;
        }

        virtual void SAL_CALL setEnable( ::sal_Bool /*bEnable*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL setFocus(  ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL addWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL removeWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL addKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL removeKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL addMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL removeMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL addMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL removeMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL addPaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

        virtual void SAL_CALL removePaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& /*xListener*/ ) throw (::com::sun::star::uno::RuntimeException)
        {
            // Ignored
        }

    protected:
        /// Current bounds of the owning Window
	    ::com::sun::star::awt::Rectangle	maBounds;

        /// True, if the window this canvas is contained in, is visible
        bool								mbIsVisible;
    };
}

#endif /* INCLUDED_CANVAS_WINDOWGRAPHICDEVICEBASE_HXX */
