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_BASE_BUFFEREDGRAPHICDEVICEBASE_HXX
21 #define INCLUDED_CANVAS_BASE_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. 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
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
) SAL_OVERRIDE
103 virtual ::sal_Int32 SAL_CALL
createBuffers( ::sal_Int32 nBuffers
) throw (::com::sun::star::lang::IllegalArgumentException
,
104 ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
106 tools::verifyRange( nBuffers
, (sal_Int32
)1 );
111 virtual void SAL_CALL
destroyBuffers( ) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
115 virtual sal_Bool SAL_CALL
showBuffer( sal_Bool bUpdateAll
)
116 throw (::com::sun::star::uno::RuntimeException
,
117 std::exception
) SAL_OVERRIDE
119 MutexType
aGuard( BaseType::m_aMutex
);
121 return BaseType::maDeviceHelper
.showBuffer( mbIsVisible
, bUpdateAll
);
124 virtual sal_Bool SAL_CALL
switchBuffer( sal_Bool bUpdateAll
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
126 MutexType
aGuard( BaseType::m_aMutex
);
128 return BaseType::maDeviceHelper
.switchBuffer( mbIsVisible
, bUpdateAll
);
132 /** Set corresponding canvas window
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.
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
143 void setWindow( const ::com::sun::star::uno::Reference
<
144 ::com::sun::star::awt::XWindow2
>& rWindow
)
147 mxWindow
->removeWindowListener( this );
153 mbIsVisible
= mxWindow
->isVisible();
155 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTopWindow
>(
157 ::com::sun::star::uno::UNO_QUERY
).is();
159 maBounds
= transformBounds( mxWindow
->getPosSize() );
160 mxWindow
->addWindowListener( this );
164 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow2
> getWindow() const
169 ::com::sun::star::uno::Any
getXWindow() const
171 return ::com::sun::star::uno::makeAny(mxWindow
);
174 virtual void disposeThis() SAL_OVERRIDE
176 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
180 mxWindow
->removeWindowListener(this);
184 // pass on to base class
185 BaseType::disposeThis();
188 ::com::sun::star::awt::Rectangle
transformBounds( const ::com::sun::star::awt::Rectangle
& rBounds
)
190 // notifySizeUpdate's bounds are relative to the toplevel
193 return tools::getAbsoluteWindowRect(
197 return ::com::sun::star::awt::Rectangle( 0,0,rBounds
.Width
,rBounds
.Height
);
200 void boundsChanged( const ::com::sun::star::awt::WindowEvent
& e
)
202 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
204 const ::com::sun::star::awt::Rectangle
& rNewBounds(
206 ::com::sun::star::awt::Rectangle( e
.X
,
211 if( rNewBounds
.X
!= maBounds
.X
||
212 rNewBounds
.Y
!= maBounds
.Y
||
213 rNewBounds
.Width
!= maBounds
.Width
||
214 rNewBounds
.Height
!= maBounds
.Height
)
216 maBounds
= rNewBounds
;
217 BaseType::maDeviceHelper
.notifySizeUpdate( maBounds
);
222 virtual void disposeEventSource( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
224 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
226 if( Source
.Source
== mxWindow
)
229 BaseType::disposeEventSource(Source
);
232 virtual void SAL_CALL
windowResized( const ::com::sun::star::awt::WindowEvent
& e
) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
237 virtual void SAL_CALL
windowMoved( const ::com::sun::star::awt::WindowEvent
& e
) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
242 virtual void SAL_CALL
windowShown( const ::com::sun::star::lang::EventObject
& ) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
244 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
249 virtual void SAL_CALL
windowHidden( const ::com::sun::star::lang::EventObject
& ) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
251 typename
BaseType::MutexType
aGuard( BaseType::m_aMutex
);
257 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow2
> mxWindow
;
259 /// Current bounds of the owning Window
260 ::com::sun::star::awt::Rectangle maBounds
;
262 /// True, if the window this canvas is contained in, is visible
266 /// True, if the window this canvas is contained in, is a toplevel window
271 #endif // INCLUDED_CANVAS_BASE_BUFFEREDGRAPHICDEVICEBASE_HXX
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */