1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CANVAS_BUFFEREDGRAPHICDEVICEBASE_HXX
21 #define INCLUDED_CANVAS_BUFFEREDGRAPHICDEVICEBASE_HXX
23 #include <com/sun/star/awt/XWindow2.hpp>
24 #include <com/sun/star/awt/XTopWindow.hpp>
25 #include <com/sun/star/awt/XWindowListener.hpp>
27 #include <canvas/canvastools.hxx>
28 #include <canvas/base/graphicdevicebase.hxx>
31 /* Definition of BufferedGraphicDeviceBase class */
35 /** Helper template base class for XGraphicDevice implementations
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
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.
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.
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
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)
75 class Mutex
=::osl::MutexGuard
,
76 class UnambiguousBase
=::com::sun::star::uno::XInterface
> class BufferedGraphicDeviceBase
:
77 public GraphicDeviceBase
< Base
, DeviceHelper
, Mutex
, UnambiguousBase
>
80 typedef GraphicDeviceBase
< Base
, DeviceHelper
, Mutex
, UnambiguousBase
> BaseType
;
81 typedef BufferedGraphicDeviceBase OurType
;
82 typedef Mutex MutexType
;
84 BufferedGraphicDeviceBase() :
90 BaseType::maPropHelper
.addProperties( PropertySetHelper::MakeMap
92 boost::bind(&OurType::getXWindow
,
97 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::rendering::XBufferController
> SAL_CALL
getBufferController( ) throw (::com::sun::star::uno::RuntimeException
)
103 virtual ::sal_Int32 SAL_CALL
createBuffers( ::sal_Int32 nBuffers
) throw (::com::sun::star::lang::IllegalArgumentException
,
104 ::com::sun::star::uno::RuntimeException
)
106 tools::verifyRange( nBuffers
, (sal_Int32
)1 );
108 MutexType
aGuard( BaseType::m_aMutex
);
110 return BaseType::maDeviceHelper
.createBuffers( nBuffers
);
113 virtual void SAL_CALL
destroyBuffers( ) throw (::com::sun::star::uno::RuntimeException
)
115 MutexType
aGuard( BaseType::m_aMutex
);
117 BaseType::maDeviceHelper
.destroyBuffers();
120 virtual ::sal_Bool SAL_CALL
showBuffer( ::sal_Bool bUpdateAll
) throw (::com::sun::star::uno::RuntimeException
)
122 MutexType
aGuard( BaseType::m_aMutex
);
124 return BaseType::maDeviceHelper
.showBuffer( mbIsVisible
, bUpdateAll
);
127 virtual ::sal_Bool SAL_CALL
switchBuffer( ::sal_Bool bUpdateAll
) throw (::com::sun::star::uno::RuntimeException
)
129 MutexType
aGuard( BaseType::m_aMutex
);
131 return BaseType::maDeviceHelper
.switchBuffer( mbIsVisible
, bUpdateAll
);
135 /** Set corresponding canvas window
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.
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
146 void setWindow( const ::com::sun::star::uno::Reference
<
147 ::com::sun::star::awt::XWindow2
>& rWindow
)
150 mxWindow
->removeWindowListener( this );
156 mbIsVisible
= mxWindow
->isVisible();
158 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTopWindow
>(
160 ::com::sun::star::uno::UNO_QUERY
).is();
162 maBounds
= transformBounds( mxWindow
->getPosSize() );
163 mxWindow
->addWindowListener( this );
167 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow2
> getWindow() const
172 ::com::sun::star::uno::Any
getXWindow() const
174 return ::com::sun::star::uno::makeAny(mxWindow
);
177 virtual void disposeThis()
179 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
183 mxWindow
->removeWindowListener(this);
187 // pass on to base class
188 BaseType::disposeThis();
191 ::com::sun::star::awt::Rectangle
transformBounds( const ::com::sun::star::awt::Rectangle
& rBounds
)
193 // notifySizeUpdate's bounds are relative to the toplevel
196 return tools::getAbsoluteWindowRect(
200 return ::com::sun::star::awt::Rectangle( 0,0,rBounds
.Width
,rBounds
.Height
);
203 void boundsChanged( const ::com::sun::star::awt::WindowEvent
& e
)
205 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
207 const ::com::sun::star::awt::Rectangle
& rNewBounds(
209 ::com::sun::star::awt::Rectangle( e
.X
,
214 if( rNewBounds
.X
!= maBounds
.X
||
215 rNewBounds
.Y
!= maBounds
.Y
||
216 rNewBounds
.Width
!= maBounds
.Width
||
217 rNewBounds
.Height
!= maBounds
.Height
)
219 maBounds
= rNewBounds
;
220 BaseType::maDeviceHelper
.notifySizeUpdate( maBounds
);
225 virtual void disposeEventSource( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
)
227 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
229 if( Source
.Source
== mxWindow
)
232 BaseType::disposeEventSource(Source
);
235 virtual void SAL_CALL
windowResized( const ::com::sun::star::awt::WindowEvent
& e
) throw (::com::sun::star::uno::RuntimeException
)
240 virtual void SAL_CALL
windowMoved( const ::com::sun::star::awt::WindowEvent
& e
) throw (::com::sun::star::uno::RuntimeException
)
245 virtual void SAL_CALL
windowShown( const ::com::sun::star::lang::EventObject
& ) throw (::com::sun::star::uno::RuntimeException
)
247 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
252 virtual void SAL_CALL
windowHidden( const ::com::sun::star::lang::EventObject
& ) throw (::com::sun::star::uno::RuntimeException
)
254 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
260 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow2
> mxWindow
;
262 /// Current bounds of the owning Window
263 ::com::sun::star::awt::Rectangle maBounds
;
265 /// True, if the window this canvas is contained in, is visible
269 /// True, if the window this canvas is contained in, is a toplevel window
274 #endif /* INCLUDED_CANVAS_BUFFEREDGRAPHICDEVICEBASE_HXX */
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */