LCOV - code coverage report
Current view: top level - include/canvas/base - bufferedgraphicdevicebase.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 70 0.0 %
Date: 2015-06-13 12:38:46 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.  Every time 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 :             return 1;
     109             :         }
     110             : 
     111           0 :         virtual void SAL_CALL destroyBuffers(  ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     112             :         {
     113           0 :         }
     114             : 
     115           0 :         virtual sal_Bool SAL_CALL showBuffer( sal_Bool bUpdateAll )
     116             :             throw (::com::sun::star::uno::RuntimeException,
     117             :                    std::exception) SAL_OVERRIDE
     118             :         {
     119           0 :             MutexType aGuard( BaseType::m_aMutex );
     120             : 
     121           0 :             return BaseType::maDeviceHelper.showBuffer( mbIsVisible, bUpdateAll );
     122             :         }
     123             : 
     124           0 :         virtual sal_Bool SAL_CALL switchBuffer( sal_Bool bUpdateAll ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     125             :         {
     126           0 :             MutexType aGuard( BaseType::m_aMutex );
     127             : 
     128           0 :             return BaseType::maDeviceHelper.switchBuffer( mbIsVisible, bUpdateAll );
     129             :         }
     130             : 
     131             : 
     132             :         /** Set corresponding canvas window
     133             : 
     134             :             Use this method to set the window this canvas displays
     135             :             on. Comes in handy when the canvas needs to adapt size or
     136             :             output position to the changing window.
     137             : 
     138             :             Whenever the bounds of the window change, <code>void
     139             :             notifySizeUpdate( const awt::Rectangle& rBounds )</code>
     140             :             is called, with rBounds the window bound rect relative to
     141             :             the frame window.
     142             :          */
     143           0 :         void setWindow( const ::com::sun::star::uno::Reference<
     144             :                               ::com::sun::star::awt::XWindow2 >& rWindow )
     145             :         {
     146           0 :             if( mxWindow.is() )
     147           0 :                 mxWindow->removeWindowListener( this );
     148             : 
     149           0 :             mxWindow = rWindow;
     150             : 
     151           0 :             if( mxWindow.is() )
     152             :             {
     153           0 :                 mbIsVisible = mxWindow->isVisible();
     154           0 :                 mbIsTopLevel =
     155             :                     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindow >(
     156             :                         mxWindow,
     157           0 :                         ::com::sun::star::uno::UNO_QUERY ).is();
     158             : 
     159           0 :                 maBounds = transformBounds( mxWindow->getPosSize() );
     160           0 :                 mxWindow->addWindowListener( this );
     161             :             }
     162           0 :         }
     163             : 
     164             :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow2 > getWindow() const
     165             :         {
     166             :             return mxWindow;
     167             :         }
     168             : 
     169           0 :         ::com::sun::star::uno::Any getXWindow() const
     170             :         {
     171           0 :             return ::com::sun::star::uno::makeAny(mxWindow);
     172             :         }
     173             : 
     174           0 :         virtual void disposeThis() SAL_OVERRIDE
     175             :         {
     176           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     177             : 
     178           0 :             if( mxWindow.is() )
     179             :             {
     180           0 :                 mxWindow->removeWindowListener(this);
     181           0 :                 mxWindow.clear();
     182             :             }
     183             : 
     184             :             // pass on to base class
     185           0 :             BaseType::disposeThis();
     186           0 :         }
     187             : 
     188           0 :         ::com::sun::star::awt::Rectangle transformBounds( const ::com::sun::star::awt::Rectangle& rBounds )
     189             :         {
     190             :             // notifySizeUpdate's bounds are relative to the toplevel
     191             :             // window
     192           0 :             if( !mbIsTopLevel )
     193             :                 return tools::getAbsoluteWindowRect(
     194             :                     rBounds,
     195           0 :                     mxWindow );
     196             :             else
     197           0 :                 return ::com::sun::star::awt::Rectangle( 0,0,rBounds.Width,rBounds.Height );
     198             :         }
     199             : 
     200           0 :         void boundsChanged( const ::com::sun::star::awt::WindowEvent& e )
     201             :         {
     202           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     203             : 
     204             :             const ::com::sun::star::awt::Rectangle& rNewBounds(
     205             :                 transformBounds(
     206             :                     ::com::sun::star::awt::Rectangle( e.X,
     207             :                                                       e.Y,
     208             :                                                       e.Width,
     209           0 :                                                       e.Height )));
     210             : 
     211           0 :             if( rNewBounds.X != maBounds.X ||
     212             :                 rNewBounds.Y != maBounds.Y ||
     213             :                 rNewBounds.Width != maBounds.Width ||
     214             :                 rNewBounds.Height != maBounds.Height )
     215             :             {
     216           0 :                 maBounds = rNewBounds;
     217           0 :                 BaseType::maDeviceHelper.notifySizeUpdate( maBounds );
     218           0 :             }
     219           0 :         }
     220             : 
     221             :         // XWindowListener
     222           0 :         virtual void disposeEventSource( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     223             :         {
     224           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     225             : 
     226           0 :             if( Source.Source == mxWindow )
     227           0 :                 mxWindow.clear();
     228             : 
     229           0 :             BaseType::disposeEventSource(Source);
     230           0 :         }
     231             : 
     232           0 :         virtual void SAL_CALL windowResized( const ::com::sun::star::awt::WindowEvent& e ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     233             :         {
     234           0 :             boundsChanged( e );
     235           0 :         }
     236             : 
     237           0 :         virtual void SAL_CALL windowMoved( 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 windowShown( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     243             :         {
     244           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     245             : 
     246           0 :             mbIsVisible = true;
     247           0 :         }
     248             : 
     249           0 :         virtual void SAL_CALL windowHidden( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
     250             :         {
     251           0 :             typename BaseType::MutexType aGuard( BaseType::m_aMutex );
     252             : 
     253           0 :             mbIsVisible = false;
     254           0 :         }
     255             : 
     256             :     protected:
     257             :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow2 >  mxWindow;
     258             : 
     259             :         /// Current bounds of the owning Window
     260             :         ::com::sun::star::awt::Rectangle                                     maBounds;
     261             : 
     262             :         /// True, if the window this canvas is contained in, is visible
     263             :         bool                                                                 mbIsVisible;
     264             : 
     265             :     private:
     266             :         /// True, if the window this canvas is contained in, is a toplevel window
     267             :         bool                                                                 mbIsTopLevel;
     268             :     };
     269             : }
     270             : 
     271             : #endif // INCLUDED_CANVAS_BASE_BUFFEREDGRAPHICDEVICEBASE_HXX
     272             : 
     273             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11