fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / touch / source / uno / Document.cxx
blobdd97f10c888d3f5710740d304c1fe641a349b7ef
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/.
8 */
10 // NOTE: Work in progress, most likely makes little sense
12 #include <com/sun/star/awt/XBitmap.hpp>
13 #include <com/sun/star/awt/XDevice.hpp>
14 #include <com/sun/star/awt/XToolkitExperimental.hpp>
15 #include <com/sun/star/beans/NamedValue.hpp>
16 #include <com/sun/star/beans/PropertyValues.hpp>
17 #include <com/sun/star/frame/XComponentLoader.hpp>
18 #include <com/sun/star/frame/Desktop.hpp>
19 #include <com/sun/star/lang/XInitialization.hpp>
20 #include <com/sun/star/view/XRenderable.hpp>
22 #include <cppuhelper/implbase1.hxx>
23 #include <cppuhelper/basemutex.hxx>
25 #include <org/libreoffice/touch/Document.hpp>
27 using namespace ::com::sun::star;
29 using ::osl::MutexGuard;
31 namespace org { namespace libreoffice { namespace touch
34 class DocumentImpl:
35 public XDocument
38 private:
39 OUString m_sURI;
40 uno::Reference< uno::XComponentContext > m_rContext;
41 uno::Reference< lang::XComponent > m_xComponent;
42 uno::Reference< awt::XToolkitExperimental > m_xToolkit;
43 uno::Reference< frame::XController > m_xController;
45 // XRenderable.getRendererCount() and .render() need an XController in the
46 // properties, at least in the test Java code it seemed that a totally
47 // dummy one works, so try that here, too.
49 typedef ::cppu::WeakImplHelper1< frame::XController > MyXController_Base;
51 class MyXController:
52 public MyXController_Base,
53 public ::cppu::BaseMutex
55 private:
56 uno::Reference< frame::XFrame > m_xFrame;
57 uno::Reference< frame::XModel > m_xModel;
59 public:
60 virtual void SAL_CALL
61 attachFrame( const uno::Reference< frame::XFrame >& xFrame )
62 throw( uno::RuntimeException )
64 m_xFrame = xFrame;
67 virtual sal_Bool SAL_CALL
68 attachModel( const uno::Reference< frame::XModel >& xModel )
69 throw( uno::RuntimeException )
71 m_xModel = xModel;
72 return sal_True;
75 virtual sal_Bool SAL_CALL
76 suspend( sal_Bool /* bSuspend */ )
77 throw( uno::RuntimeException )
79 return sal_False;
82 virtual uno::Any SAL_CALL getViewData()
83 throw( uno::RuntimeException )
85 return uno::Any();
88 virtual void SAL_CALL restoreViewData( const uno::Any& /* data */ )
89 throw ( uno::RuntimeException )
93 virtual uno::Reference< frame::XModel > SAL_CALL
94 getModel()
95 throw ( uno::RuntimeException )
97 return m_xModel;
100 virtual uno::Reference< frame::XFrame > SAL_CALL
101 getFrame()
102 throw ( uno::RuntimeException )
104 return m_xFrame;
107 virtual void SAL_CALL
108 dispose()
109 throw ( uno::RuntimeException )
113 virtual void SAL_CALL
114 addEventListener( const uno::Reference< lang::XEventListener >& /* xListener */ )
115 throw ( uno::RuntimeException )
119 virtual void SAL_CALL
120 removeEventListener( const uno::Reference< lang::XEventListener >& /* xListener */ )
121 throw ( uno::RuntimeException )
126 protected:
127 DocumentImpl( const uno::Reference< uno::XComponentContext > context ):
128 m_rContext( context )
132 virtual ~DocumentImpl()
136 public:
137 // XInitialization
138 virtual void SAL_CALL
139 initialize( const uno::Sequence< uno::Any >& arguments )
140 throw ( uno::Exception, uno::RuntimeException )
142 if ( arguments.getLength() != 1 )
143 throw lang::IllegalArgumentException( OUString(), static_cast<uno::Reference< uno::XInterface> >(this), 1 );
145 uno::Sequence< beans::NamedValue > settings;
146 if ( arguments[0] >>= m_sURI )
148 // create( [in] string uri );
149 uno::Reference< frame::XDesktop2 > desktop = frame::Desktop::create( m_rContext );
151 beans::PropertyValues loadProps(3);
152 loadProps[0].Name = "Hidden";
153 loadProps[0].Value <<= sal_Bool(true);
154 loadProps[1].Name = "ReadOnly";
155 loadProps[1].Value <<= sal_Bool(true);
156 loadProps[2].Name = "Preview";
157 loadProps[2].Value <<= sal_Bool(true);
159 m_xComponent = desktop->loadComponentFromURL( m_sURI, "_blank", 0, loadProps );
161 m_xToolkit = uno::Reference< awt::XToolkitExperimental >( m_rContext->getServiceManager()->createInstanceWithContext( "com.sun.star.awt.ToolkitExperimental", m_rContext ), uno::UNO_QUERY_THROW );
163 m_xController = new MyXController();
167 // XDocument
168 virtual sal_Int32 SAL_CALL
169 getNumberOfPages()
170 throw ( uno::RuntimeException )
172 uno::Any selection;
173 selection <<= m_xComponent;
175 uno::Reference< awt::XDevice > device;
176 uno::Reference< view::XRenderable > renderable;
178 beans::PropertyValues renderProps;
180 device = m_xToolkit->createScreenCompatibleDevice( 128, 128 );
182 renderable = uno::Reference< view::XRenderable >( m_rContext->getServiceManager()->createInstanceWithContext( "com.sun.star.view.Renderable", m_rContext ), uno::UNO_QUERY_THROW );
184 renderProps.realloc( 3 );
185 renderProps[0].Name = "IsPrinter";
186 renderProps[0].Value <<= sal_Bool(true);
187 renderProps[1].Name = "RenderDevice";
188 renderProps[1].Value <<= device;
189 renderProps[2].Name = "View";
190 renderProps[2].Value <<= m_xController;
192 return renderable->getRendererCount( selection, renderProps );
195 virtual void SAL_CALL
196 render( sal_Int64 buffer,
197 sal_Int32 width,
198 sal_Int32 height,
199 const uno::Reference< XDocumentRenderCallback >& listener,
200 sal_Int32 pageNo,
201 sal_Int32 zoomLevel,
202 sal_Int32 x,
203 sal_Int32 y )
204 throw ( lang::IllegalArgumentException, uno::RuntimeException)
206 (void) listener;
207 (void) zoomLevel;
208 (void) x;
209 (void) y;
211 uno::Any selection;
213 selection <<= m_xComponent;
215 uno::Reference< awt::XDevice > device( m_xToolkit->createScreenCompatibleDeviceUsingBuffer( width, height, 1, 1, 0, 0, buffer ) );
217 beans::PropertyValues renderProps;
219 renderProps.realloc( 3 );
220 renderProps[0].Name = "IsPrinter";
221 renderProps[0].Value <<= sal_Bool(true);
222 renderProps[1].Name = "RenderDevice";
223 renderProps[1].Value <<= device;
224 renderProps[2].Name = "View";
225 renderProps[2].Value <<= m_xController;
227 uno::Reference< view::XRenderable > renderable( m_rContext->getServiceManager()->createInstanceWithContext( "com.sun.star.view.Renderable", m_rContext ), uno::UNO_QUERY_THROW );
229 renderable->render( pageNo, selection, renderProps );
234 } } } // namespace org::libreoffice::touch
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */