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

Generated by: LCOV version 1.10