nss: upgrade to release 3.73
[LibreOffice.git] / canvas / inc / base / bufferedgraphicdevicebase.hxx
blob067d37a984f0d4bac43a39589cf9b2ba2d43aedd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <com/sun/star/awt/XWindow2.hpp>
24 #include <canvas/canvastools.hxx>
25 #include <base/graphicdevicebase.hxx>
27 namespace com::sun::star::awt { class XTopWindow; }
30 /* Definition of BufferedGraphicDeviceBase class */
32 namespace canvas
34 /** Helper template base class for XGraphicDevice implementations
35 on windows.
37 Use this base class if your target device is a
38 window. Additionally to GraphicDeviceBase, this template
39 provides an implementation of the awt::XWindowListener
40 interface, to receive notifications about state changes of the
41 associated window.
43 @tpl Base
44 Base class to use, most probably one of the
45 WeakComponentImplHelperN templates with the appropriate
46 interfaces. At least XGraphicDevice should be among them (why else
47 would you use this template, then?). Base class must have an
48 Base( const Mutex& ) constructor (like the
49 WeakComponentImplHelperN templates have). As the very least,
50 the base class must be derived from uno::XInterface, as some
51 error reporting mechanisms rely on that.
53 @tpl DeviceHelper
54 Device helper implementation for the backend in question. This
55 object will be held as a member of this template class, and
56 basically gets forwarded all XGraphicDevice API calls that
57 could not be handled generically.
59 @tpl Mutex
60 Lock strategy to use. Defaults to using the
61 BaseMutex-provided lock. Every time one of the methods is
62 entered, an object of type Mutex is created with m_aMutex as
63 the sole parameter, and destroyed again when the method scope
64 is left.
66 @tpl UnambiguousBase
67 Optional unambiguous base class for XInterface of Base. It's
68 sometimes necessary to specify this parameter, e.g. if Base
69 derives from multiple UNO interface (were each provides its
70 own version of XInterface, making the conversion ambiguous)
72 template< class Base,
73 class DeviceHelper,
74 class Mutex=::osl::MutexGuard,
75 class UnambiguousBase = css::uno::XInterface > class BufferedGraphicDeviceBase :
76 public GraphicDeviceBase< Base, DeviceHelper, Mutex, UnambiguousBase >
78 public:
79 typedef GraphicDeviceBase< Base, DeviceHelper, Mutex, UnambiguousBase > BaseType;
80 typedef Mutex MutexType;
82 BufferedGraphicDeviceBase() :
83 mxWindow(),
84 maBounds(),
85 mbIsVisible( false ),
86 mbIsTopLevel( false )
88 BaseType::maPropHelper.addProperties(
89 PropertySetHelper::MakeMap("Window",
90 [this] () { return this->getXWindow(); }));
93 // XGraphicDevice
94 virtual css::uno::Reference< css::rendering::XBufferController > SAL_CALL getBufferController( ) override
96 return this;
99 // XBufferController
100 virtual ::sal_Int32 SAL_CALL createBuffers( ::sal_Int32 nBuffers ) override
102 tools::verifyRange( nBuffers, sal_Int32(1) );
104 return 1;
107 virtual void SAL_CALL destroyBuffers( ) override
111 virtual sal_Bool SAL_CALL showBuffer( sal_Bool bUpdateAll ) override
113 MutexType aGuard( BaseType::m_aMutex );
115 return BaseType::maDeviceHelper.showBuffer( mbIsVisible, bUpdateAll );
118 virtual sal_Bool SAL_CALL switchBuffer( sal_Bool bUpdateAll ) override
120 MutexType aGuard( BaseType::m_aMutex );
122 return BaseType::maDeviceHelper.switchBuffer( mbIsVisible, bUpdateAll );
126 /** Set corresponding canvas window
128 Use this method to set the window this canvas displays
129 on. Comes in handy when the canvas needs to adapt size or
130 output position to the changing window.
132 Whenever the bounds of the window change, <code>void
133 notifySizeUpdate( const awt::Rectangle& rBounds )</code>
134 is called, with rBounds the window bound rect relative to
135 the frame window.
137 void setWindow( const css::uno::Reference< css::awt::XWindow2 >& rWindow )
139 if( mxWindow.is() )
140 mxWindow->removeWindowListener( this );
142 mxWindow = rWindow;
144 if( mxWindow.is() )
146 mbIsVisible = mxWindow->isVisible();
147 mbIsTopLevel =
148 css::uno::Reference< css::awt::XTopWindow >(
149 mxWindow,
150 css::uno::UNO_QUERY ).is();
152 maBounds = transformBounds( mxWindow->getPosSize() );
153 mxWindow->addWindowListener( this );
157 css::uno::Any getXWindow() const
159 return css::uno::makeAny(mxWindow);
162 virtual void disposeThis() override
164 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
166 if( mxWindow.is() )
168 mxWindow->removeWindowListener(this);
169 mxWindow.clear();
172 // pass on to base class
173 BaseType::disposeThis();
176 css::awt::Rectangle transformBounds( const css::awt::Rectangle& rBounds )
178 // notifySizeUpdate's bounds are relative to the toplevel
179 // window
180 if( !mbIsTopLevel )
181 return tools::getAbsoluteWindowRect(
182 rBounds,
183 mxWindow );
184 else
185 return css::awt::Rectangle( 0,0,rBounds.Width,rBounds.Height );
188 void boundsChanged( const css::awt::WindowEvent& e )
190 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
192 const css::awt::Rectangle& rNewBounds(
193 transformBounds( css::awt::Rectangle( e.X,
194 e.Y,
195 e.Width,
196 e.Height )));
198 if( rNewBounds.X != maBounds.X ||
199 rNewBounds.Y != maBounds.Y ||
200 rNewBounds.Width != maBounds.Width ||
201 rNewBounds.Height != maBounds.Height )
203 maBounds = rNewBounds;
204 BaseType::maDeviceHelper.notifySizeUpdate( maBounds );
208 // XWindowListener
209 virtual void disposeEventSource( const css::lang::EventObject& Source ) override
211 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
213 if( Source.Source == mxWindow )
214 mxWindow.clear();
216 BaseType::disposeEventSource(Source);
219 virtual void SAL_CALL windowResized( const css::awt::WindowEvent& e ) override
221 boundsChanged( e );
224 virtual void SAL_CALL windowMoved( const css::awt::WindowEvent& e ) override
226 boundsChanged( e );
229 virtual void SAL_CALL windowShown( const css::lang::EventObject& ) override
231 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
233 mbIsVisible = true;
236 virtual void SAL_CALL windowHidden( const css::lang::EventObject& ) override
238 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
240 mbIsVisible = false;
243 protected:
244 css::uno::Reference< css::awt::XWindow2 > mxWindow;
246 /// Current bounds of the owning Window
247 css::awt::Rectangle maBounds;
249 /// True, if the window this canvas is contained in, is visible
250 bool mbIsVisible;
252 private:
253 /// True, if the window this canvas is contained in, is a toplevel window
254 bool mbIsTopLevel;
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */