LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/canvas/base - bufferedgraphicdevicebase.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 71 0.0 %
Date: 2012-08-25 Functions: 0 53 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10