1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
30 
31 #include <canvas/debug.hxx>
32 #include <tools/diagnose_ex.h>
33 #include <canvas/verbosetrace.hxx>
34 #include <canvas/canvastools.hxx>
35 
36 #include <osl/mutex.hxx>
37 
38 #include <com/sun/star/registry/XRegistryKey.hpp>
39 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
40 #include <com/sun/star/uno/XComponentContext.hpp>
41 
42 #include <cppuhelper/factory.hxx>
43 #include <cppuhelper/implementationentry.hxx>
44 #include <comphelper/servicedecl.hxx>
45 
46 #include <basegfx/matrix/b2dhommatrix.hxx>
47 #include <basegfx/point/b2dpoint.hxx>
48 #include <basegfx/tools/canvastools.hxx>
49 #include <basegfx/numeric/ftools.hxx>
50 
51 #include "null_spritecanvas.hxx"
52 
53 
54 using namespace ::com::sun::star;
55 
56 #define SERVICE_NAME "com.sun.star.rendering.NullCanvas"
57 
58 namespace nullcanvas
59 {
60     SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >&                aArguments,
61                                 const uno::Reference< uno::XComponentContext >& rxContext ) :
62         maArguments(aArguments),
63         mxComponentContext( rxContext )
64     {
65     }
66 
67     void SpriteCanvas::initialize()
68     {
69         // #i64742# Only call initialize when not in probe mode
70         if( maArguments.getLength() == 0 )
71             return;
72 
73         VERBOSE_TRACE( "SpriteCanvas::initialize called" );
74 
75         // At index 1, we expect a system window handle here,
76         // containing a pointer to a valid window, on which to output
77         // At index 2, we expect the current window bound rect
78         ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
79                              maArguments[1].getValueTypeClass() == uno::TypeClass_LONG,
80                              "SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
81 
82         awt::Rectangle aRect;
83         maArguments[2] >>= aRect;
84         const ::basegfx::B2ISize aSize(aRect.Width,
85                                        aRect.Height);
86 
87         sal_Bool bIsFullscreen( sal_False );
88         maArguments[3] >>= bIsFullscreen;
89 
90         // setup helper
91         maDeviceHelper.init( *this,
92                              aSize,
93                              bIsFullscreen );
94         maCanvasHelper.init( maRedrawManager,
95                              *this,
96                              aSize,
97                              false );
98 
99         maArguments.realloc(0);
100     }
101 
102     void SAL_CALL SpriteCanvas::disposing()
103     {
104         ::osl::MutexGuard aGuard( m_aMutex );
105 
106         mxComponentContext.clear();
107 
108         // forward to parent
109         SpriteCanvasBaseT::disposing();
110     }
111 
112     ::sal_Bool SAL_CALL SpriteCanvas::showBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
113     {
114         ::osl::MutexGuard aGuard( m_aMutex );
115 
116         // avoid repaints on hidden window (hidden: not mapped to
117         // screen). Return failure, since the screen really has _not_
118         // been updated (caller should try again later)
119         return !mbIsVisible ? false : SpriteCanvasBaseT::showBuffer( bUpdateAll );
120     }
121 
122     ::sal_Bool SAL_CALL SpriteCanvas::switchBuffer( ::sal_Bool bUpdateAll ) throw (uno::RuntimeException)
123     {
124         ::osl::MutexGuard aGuard( m_aMutex );
125 
126         // avoid repaints on hidden window (hidden: not mapped to
127         // screen). Return failure, since the screen really has _not_
128         // been updated (caller should try again later)
129         return !mbIsVisible ? false : SpriteCanvasBaseT::switchBuffer( bUpdateAll );
130     }
131 
132     sal_Bool SAL_CALL SpriteCanvas::updateScreen( sal_Bool bUpdateAll ) throw (uno::RuntimeException)
133     {
134         ::osl::MutexGuard aGuard( m_aMutex );
135 
136         // avoid repaints on hidden window (hidden: not mapped to
137         // screen). Return failure, since the screen really has _not_
138         // been updated (caller should try again later)
139         return !mbIsVisible ? false : maCanvasHelper.updateScreen(
140             ::basegfx::unotools::b2IRectangleFromAwtRectangle(maBounds),
141             bUpdateAll,
142             mbSurfaceDirty );
143     }
144 
145     ::rtl::OUString SAL_CALL SpriteCanvas::getServiceName(  ) throw (uno::RuntimeException)
146     {
147         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
148     }
149 
150     static uno::Reference<uno::XInterface> initCanvas( SpriteCanvas* pCanvas )
151     {
152         uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas));
153         pCanvas->initialize();
154         return xRet;
155     }
156 
157     namespace sdecl = comphelper::service_decl;
158     sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas);
159     const sdecl::ServiceDecl nullCanvasDecl(
160         serviceImpl,
161         "com.sun.star.comp.rendering.NullCanvas",
162         SERVICE_NAME );
163 }
164 
165 // The C shared lib entry points
166 COMPHELPER_SERVICEDECL_EXPORTS1(nullcanvas::nullCanvasDecl)
167