LCOV - code coverage report
Current view: top level - include/canvas/base - bufferedgraphicdevicebase.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 73 0.0 %
Date: 2014-04-14 Functions: 0 54 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_CANVAS_BASE_BUFFEREDGRAPHICDEVICEBASE_HXX
      21             : #define INCLUDED_CANVAS_BASE_BUFFEREDGRAPHICDEVICEBASE_HXX
      22             : 
      23             : #include <com/sun/star/awt/XWindow2.hpp>
      24             : #include <com/sun/star/awt/XTopWindow.hpp>
      25             : #include <com/sun/star/awt/XWindowListener.hpp>
      26             : 
      27             : #include <canvas/canvastools.hxx>
      28             : #include <canvas/base/graphicdevicebase.hxx>
      29             : 
      30             : 
      31             : /* Definition of BufferedGraphicDeviceBase class */
      32             : 
      33             : namespace canvas
      34             : {
      35             :     /** Helper template base class for XGraphicDevice implementations
      36             :         on windows.
      37             : 
      38             :         Use this base class if your target device is a
      39             :         window. Additionally to GraphicDeviceBase, this template
      40             :         provides an implementation of the awt::XWindowListener
      41             :         interface, to receive notifications about state changes of the
      42             :         associated window.
      43             : 
      44             :         @tpl Base
      45             :         Base class to use, most probably one of the
      46             :         WeakComponentImplHelperN templates with the appropriate
      47             :         interfaces. At least XGraphicDevice should be among them (why else
      48             :         would you use this template, then?). Base class must have an
      49             :         Base( const Mutex& ) constructor (like the
      50             :         WeakComponentImplHelperN templates have). As the very least,
      51             :         the base class must be derived from uno::XInterface, as some
      52             :         error reporting mechanisms rely on that.
      53             : 
      54             :         @tpl DeviceHelper
      55             :         Device helper implementation for the backend in question. This
      56             :         object will be held as a member of this template class, and
      57             :         basically gets forwarded all XGraphicDevice API calls that
      58             :         could not be handled generically.
      59             : 
      60             :         @tpl Mutex
      61             :         Lock strategy to use. Defaults to using the
      62             :         OBaseMutex-provided lock.  Everytime one of the methods is
      63             :         entered, an object of type Mutex is created with m_aMutex as
      64             :         the sole parameter, and destroyed again when the method scope
      65             :         is left.
      66             : 
      67             :         @tpl UnambiguousBase
      68             :         Optional unambiguous base class for XInterface of Base. It's
      69             :         sometimes necessary to specify this parameter, e.g. if Base
      70             :         derives from multiple UNO interface (were each provides its
      71             :         own version of XInterface, making the conversion ambiguous)
      72             :      */
      73             :     template< class Base,
      74             :               class DeviceHelper,
      75             :               class Mutex=::osl::MutexGuard,
      76           0 :               class UnambiguousBase=::com::sun::star::uno::XInterface > class BufferedGraphicDeviceBase :
      77             :         public GraphicDeviceBase< Base, DeviceHelper, Mutex, UnambiguousBase >
      78             :     {
      79             :     public:
      80             :         typedef GraphicDeviceBase< Base, DeviceHelper, Mutex, UnambiguousBase > BaseType;
      81             :         typedef BufferedGraphicDeviceBase OurType;
      82             :         typedef Mutex MutexType;
      83             : 
      84           0 :         BufferedGraphicDeviceBase() :
      85             :             mxWindow(),
      86             :             maBounds(),
      87             :             mbIsVisible( false ),
      88           0 :             mbIsTopLevel( false )
      89             :         {
      90           0 :             BaseType::maPropHelper.addProperties( PropertySetHelper::MakeMap
      91             :                                                   ("Window",
      92             :                                                    boost::bind(&OurType::getXWindow,
      93             :                                                                this)));
      94           0 :         }
      95             : 
      96             :         // XGraphicDevice
      97           0 :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBufferController > SAL_CALL getBufferController(  ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
      98             :         {
      99           0 :             return this;
     100             :         }
     101             : 
     102             :         // XBufferController
     103           0 :         virtual ::sal_Int32 SAL_CALL createBuffers( ::sal_Int32 nBuffers ) throw (::com::sun::star::lang::IllegalArgumentException,
     104             :                                                                                   ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     105             :         {
     106           0 :             tools::verifyRange( nBuffers, (sal_Int32)1 );
     107             : 
     108           0 :             MutexType aGuard( BaseType::m_aMutex );
     109             : 
     110           0 :             return BaseType::maDeviceHelper.createBuffers( nBuffers );
     111             :         }
     112             : 
     113           0 :         virtual void SAL_CALL destroyBuffers(  ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     114             :         {
     115           0 :             MutexType aGuard( BaseType::m_aMutex );
     116             : 
     117           0 :             BaseType::maDeviceHelper.destroyBuffers();
     118           0 :         }
     119             : 
     120           0 :         virtual sal_Bool SAL_CALL showBuffer( sal_Bool bUpdateAll )
     121             :             throw (::com::sun::star::uno::RuntimeException,
     122             :                    std::exception) SAL_OVERRIDE
     123             :         {
     124           0 :             MutexType aGuard( BaseType::m_aMutex );
     125             : 
     126           0 :             return BaseType::maDeviceHelper.showBuffer( mbIsVisible, bUpdateAll );
     127             :         }
     128             : 
     129           0 :         virtual sal_Bool SAL_CALL switchBuffer( sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     130             :         {
     131           0 :             MutexType aGuard( BaseType::m_aMutex );
     132             : 
     133           0 :             return BaseType::maDeviceHelper.switchBuffer( mbIsVisible, bUpdateAll );
     134             :         }
     135             : 
     136             : 
     137             :         /** Set corresponding canvas window
     138             : 
     139             :             Use this method to set the window this canvas displays
     140             :             on. Comes in handy when the canvas needs to adapt size or
     141             :             output position to the changing window.
     142             : 
     143             :             Whenever the bounds of the window change, <code>void
     144             :             notifySizeUpdate( const awt::Rectangle& rBounds )</code>
     145             :             is called, with rBounds the window bound rect relative to
     146             :             the frame window.
     147             :          */
     148           0 :         void setWindow( const ::com::sun::star::uno::Reference<
     149             :                               ::com::sun::star::awt::XWindow2 >& rWindow )
     150             :         {
     151           0 :             if( mxWindow.is() )
     152           0 :                 mxWindow->removeWindowListener( this );
     153             : 
     154           0 :             mxWindow = rWindow;
     155             : 
     156           0 :             if( mxWindow.is() )
     157             :             {
     158           0 :                 mbIsVisible = mxWindow->isVisible();
     159           0 :                 mbIsTopLevel =
     160             :                     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindow >(
     161             :                         mxWindow,
     162           0 :                         ::com::sun::star::uno::UNO_QUERY ).is();
     163             : 
     164           0 :                 maBounds = transformBounds( mxWindow->getPosSize() );
     165           0 :                 mxWindow->addWindowListener( this );
     166             :             }
     167           0 :         }
     168             : 
     169             :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow2 > getWindow() const
     170             :         {
     171             :             return mxWindow;
     172             :         }
     173             : 
     174           0 :         ::com::sun::star::uno::Any getXWindow() const
     175             :         {
     176           0 :             return ::com::sun::star::uno::makeAny(mxWindow);
     177             :         }
     178             : 
     179           0 :         virtual void disposeThis() SAL_OVERRIDE
     180             :         {
     181           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     182             : 
     183           0 :             if( mxWindow.is() )
     184             :             {
     185           0 :                 mxWindow->removeWindowListener(this);
     186           0 :                 mxWindow.clear();
     187             :             }
     188             : 
     189             :             // pass on to base class
     190           0 :             BaseType::disposeThis();
     191           0 :         }
     192             : 
     193           0 :         ::com::sun::star::awt::Rectangle transformBounds( const ::com::sun::star::awt::Rectangle& rBounds )
     194             :         {
     195             :             // notifySizeUpdate's bounds are relative to the toplevel
     196             :             // window
     197           0 :             if( !mbIsTopLevel )
     198             :                 return tools::getAbsoluteWindowRect(
     199             :                     rBounds,
     200           0 :                     mxWindow );
     201             :             else
     202           0 :                 return ::com::sun::star::awt::Rectangle( 0,0,rBounds.Width,rBounds.Height );
     203             :         }
     204             : 
     205           0 :         void boundsChanged( const ::com::sun::star::awt::WindowEvent& e )
     206             :         {
     207           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     208             : 
     209             :             const ::com::sun::star::awt::Rectangle& rNewBounds(
     210             :                 transformBounds(
     211             :                     ::com::sun::star::awt::Rectangle( e.X,
     212             :                                                       e.Y,
     213             :                                                       e.Width,
     214           0 :                                                       e.Height )));
     215             : 
     216           0 :             if( rNewBounds.X != maBounds.X ||
     217             :                 rNewBounds.Y != maBounds.Y ||
     218             :                 rNewBounds.Width != maBounds.Width ||
     219             :                 rNewBounds.Height != maBounds.Height )
     220             :             {
     221           0 :                 maBounds = rNewBounds;
     222           0 :                 BaseType::maDeviceHelper.notifySizeUpdate( maBounds );
     223           0 :             }
     224           0 :         }
     225             : 
     226             :         // XWindowListener
     227           0 :         virtual void disposeEventSource( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     228             :         {
     229           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     230             : 
     231           0 :             if( Source.Source == mxWindow )
     232           0 :                 mxWindow.clear();
     233             : 
     234           0 :             BaseType::disposeEventSource(Source);
     235           0 :         }
     236             : 
     237           0 :         virtual void SAL_CALL windowResized( const ::com::sun::star::awt::WindowEvent& e ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     238             :         {
     239           0 :             boundsChanged( e );
     240           0 :         }
     241             : 
     242           0 :         virtual void SAL_CALL windowMoved( const ::com::sun::star::awt::WindowEvent& e ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     243             :         {
     244           0 :             boundsChanged( e );
     245           0 :         }
     246             : 
     247           0 :         virtual void SAL_CALL windowShown( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     248             :         {
     249           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     250             : 
     251           0 :             mbIsVisible = true;
     252           0 :         }
     253             : 
     254           0 :         virtual void SAL_CALL windowHidden( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     255             :         {
     256           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     257             : 
     258           0 :             mbIsVisible = false;
     259           0 :         }
     260             : 
     261             :     protected:
     262             :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow2 >  mxWindow;
     263             : 
     264             :         /// Current bounds of the owning Window
     265             :         ::com::sun::star::awt::Rectangle                                     maBounds;
     266             : 
     267             :         /// True, if the window this canvas is contained in, is visible
     268             :         bool                                                                 mbIsVisible;
     269             : 
     270             :     private:
     271             :         /// True, if the window this canvas is contained in, is a toplevel window
     272             :         bool                                                                 mbIsTopLevel;
     273             :     };
     274             : }
     275             : 
     276             : #endif // INCLUDED_CANVAS_BASE_BUFFEREDGRAPHICDEVICEBASE_HXX
     277             : 
     278             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10