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/.
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
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
;
52 public MyXController_Base
,
53 public ::cppu::BaseMutex
56 uno::Reference
< frame::XFrame
> m_xFrame
;
57 uno::Reference
< frame::XModel
> m_xModel
;
61 attachFrame( const uno::Reference
< frame::XFrame
>& xFrame
)
62 throw( uno::RuntimeException
)
67 virtual sal_Bool SAL_CALL
68 attachModel( const uno::Reference
< frame::XModel
>& xModel
)
69 throw( uno::RuntimeException
)
75 virtual sal_Bool SAL_CALL
76 suspend( sal_Bool
/* bSuspend */ )
77 throw( uno::RuntimeException
)
82 virtual uno::Any SAL_CALL
getViewData()
83 throw( uno::RuntimeException
)
88 virtual void SAL_CALL
restoreViewData( const uno::Any
& /* data */ )
89 throw ( uno::RuntimeException
)
93 virtual uno::Reference
< frame::XModel
> SAL_CALL
95 throw ( uno::RuntimeException
)
100 virtual uno::Reference
< frame::XFrame
> SAL_CALL
102 throw ( uno::RuntimeException
)
107 virtual void SAL_CALL
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
)
127 DocumentImpl( const uno::Reference
< uno::XComponentContext
> context
):
128 m_rContext( context
)
132 virtual ~DocumentImpl()
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();
168 virtual sal_Int32 SAL_CALL
170 throw ( uno::RuntimeException
)
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
,
199 const uno::Reference
< XDocumentRenderCallback
>& listener
,
204 throw ( lang::IllegalArgumentException
, uno::RuntimeException
)
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: */