LibreOffice Module canvas (master) 1
bufferedgraphicdevicebase.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <com/sun/star/awt/XWindow2.hpp>
23
26
27namespace com::sun::star::awt { class XTopWindow; }
28
29
30/* Definition of BufferedGraphicDeviceBase class */
31
32namespace canvas
33{
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 >
77 {
78 public:
80 typedef Mutex MutexType;
81
83 mbIsVisible( false ),
84 mbIsTopLevel( false )
85 {
88 [this] () { return this->getXWindow(); }));
89 }
90
91 // XGraphicDevice
92 virtual css::uno::Reference< css::rendering::XBufferController > SAL_CALL getBufferController( ) override
93 {
94 return this;
95 }
96
97 // XBufferController
98 virtual ::sal_Int32 SAL_CALL createBuffers( ::sal_Int32 nBuffers ) override
99 {
100 tools::verifyRange( nBuffers, sal_Int32(1) );
101
102 return 1;
103 }
104
105 virtual void SAL_CALL destroyBuffers( ) override
106 {
107 }
108
109 virtual sal_Bool SAL_CALL showBuffer( sal_Bool bUpdateAll ) override
110 {
111 MutexType aGuard( BaseType::m_aMutex );
112
113 return BaseType::maDeviceHelper.showBuffer( mbIsVisible, bUpdateAll );
114 }
115
116 virtual sal_Bool SAL_CALL switchBuffer( sal_Bool bUpdateAll ) override
117 {
118 MutexType aGuard( BaseType::m_aMutex );
119
120 return BaseType::maDeviceHelper.switchBuffer( mbIsVisible, bUpdateAll );
121 }
122
123
135 void setWindow( const css::uno::Reference< css::awt::XWindow2 >& rWindow )
136 {
137 if( mxWindow.is() )
138 mxWindow->removeWindowListener( this );
139
140 mxWindow = rWindow;
141
142 if( mxWindow.is() )
143 {
144 mbIsVisible = mxWindow->isVisible();
146 css::uno::Reference< css::awt::XTopWindow >(
147 mxWindow,
148 css::uno::UNO_QUERY ).is();
149
150 maBounds = transformBounds( mxWindow->getPosSize() );
151 mxWindow->addWindowListener( this );
152 }
153 }
154
155 css::uno::Any getXWindow() const
156 {
157 return css::uno::Any(mxWindow);
158 }
159
160 virtual void disposeThis() override
161 {
162 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
163
164 if( mxWindow.is() )
165 {
166 mxWindow->removeWindowListener(this);
167 mxWindow.clear();
168 }
169
170 // pass on to base class
172 }
173
174 css::awt::Rectangle transformBounds( const css::awt::Rectangle& rBounds )
175 {
176 // notifySizeUpdate's bounds are relative to the toplevel
177 // window
178 if( !mbIsTopLevel )
180 rBounds,
181 mxWindow );
182 else
183 return css::awt::Rectangle( 0,0,rBounds.Width,rBounds.Height );
184 }
185
186 void boundsChanged( const css::awt::WindowEvent& e )
187 {
188 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
189
190 const css::awt::Rectangle& rNewBounds(
191 transformBounds( css::awt::Rectangle( e.X,
192 e.Y,
193 e.Width,
194 e.Height )));
195
196 if( rNewBounds.X != maBounds.X ||
197 rNewBounds.Y != maBounds.Y ||
198 rNewBounds.Width != maBounds.Width ||
199 rNewBounds.Height != maBounds.Height )
200 {
201 maBounds = rNewBounds;
202 BaseType::maDeviceHelper.notifySizeUpdate( maBounds );
203 }
204 }
205
206 // XWindowListener
207 virtual void disposeEventSource( const css::lang::EventObject& Source ) override
208 {
209 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
210
211 if( Source.Source == mxWindow )
212 mxWindow.clear();
213
214 BaseType::disposeEventSource(Source);
215 }
216
217 virtual void SAL_CALL windowResized( const css::awt::WindowEvent& e ) override
218 {
219 boundsChanged( e );
220 }
221
222 virtual void SAL_CALL windowMoved( const css::awt::WindowEvent& e ) override
223 {
224 boundsChanged( e );
225 }
226
227 virtual void SAL_CALL windowShown( const css::lang::EventObject& ) override
228 {
229 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
230
231 mbIsVisible = true;
232 }
233
234 virtual void SAL_CALL windowHidden( const css::lang::EventObject& ) override
235 {
236 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
237
238 mbIsVisible = false;
239 }
240
241 protected:
242 css::uno::Reference< css::awt::XWindow2 > mxWindow;
243
245 css::awt::Rectangle maBounds;
246
249
250 private:
253 };
254}
255
256/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper template base class for XGraphicDevice implementations on windows.
virtual void SAL_CALL windowShown(const css::lang::EventObject &) override
bool mbIsVisible
True, if the window this canvas is contained in, is visible.
virtual void SAL_CALL destroyBuffers() override
virtual sal_Bool SAL_CALL switchBuffer(sal_Bool bUpdateAll) override
virtual void SAL_CALL windowResized(const css::awt::WindowEvent &e) override
css::awt::Rectangle maBounds
Current bounds of the owning Window.
virtual void SAL_CALL windowMoved(const css::awt::WindowEvent &e) override
virtual ::sal_Int32 SAL_CALL createBuffers(::sal_Int32 nBuffers) override
void setWindow(const css::uno::Reference< css::awt::XWindow2 > &rWindow)
Set corresponding canvas window.
GraphicDeviceBase< Base, DeviceHelper, Mutex, UnambiguousBase > BaseType
virtual void disposeEventSource(const css::lang::EventObject &Source) override
void boundsChanged(const css::awt::WindowEvent &e)
virtual sal_Bool SAL_CALL showBuffer(sal_Bool bUpdateAll) override
bool mbIsTopLevel
True, if the window this canvas is contained in, is a toplevel window.
css::awt::Rectangle transformBounds(const css::awt::Rectangle &rBounds)
virtual void SAL_CALL windowHidden(const css::lang::EventObject &) override
virtual css::uno::Reference< css::rendering::XBufferController > SAL_CALL getBufferController() override
css::uno::Reference< css::awt::XWindow2 > mxWindow
Helper template base class for XGraphicDevice implementations.
virtual void disposeThis() override
void addProperties(const InputMap &rMap)
Add given properties to helper.
void verifyRange(NumType arg, NumType lowerBound, NumType upperBound)
Range checker, which throws css::lang::IllegalArgument exception, when range is violated.
awt::Rectangle getAbsoluteWindowRect(const awt::Rectangle &rRect, const uno::Reference< awt::XWindow2 > &xWin)
unsigned char sal_Bool
Base