/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * Copyright 2012 LibreOffice contributors. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // NOTE: Work in progress, most likely makes little sense #include #include #include #include #include #include #include #include #include #include #include #include using namespace ::com::sun::star; using ::rtl::OUString; using ::osl::MutexGuard; namespace org { namespace libreoffice { namespace touch { class DocumentImpl: public XDocument { private: OUString m_sURI; uno::Reference< uno::XComponentContext > m_rContext; uno::Reference< lang::XComponent > m_xComponent; uno::Reference< frame::XController > m_xController; uno::Reference< awt::XDevice > m_xDevice; uno::Reference< view::XRenderable > m_xRenderable; beans::PropertyValues m_aRenderProps; // XRenderable.getRendererCount() and .render() need an XController in the // properties, at least in the test Java code it seemed that a totally // dummy one works, so try that here, too. typedef ::cppu::WeakImplHelper1< frame::XController > MyXController_Base; class MyXController: public MyXController_Base, public ::cppu::BaseMutex { private: uno::Reference< frame::XFrame > m_xFrame; uno::Reference< frame::XModel > m_xModel; public: virtual void SAL_CALL attachFrame( const uno::Reference< frame::XFrame >& xFrame ) throw( uno::RuntimeException ) { m_xFrame = xFrame; } virtual sal_Bool SAL_CALL attachModel( const uno::Reference< frame::XModel >& xModel ) throw( uno::RuntimeException ) { m_xModel = xModel; return sal_True; } virtual sal_Bool SAL_CALL suspend( sal_Bool /* bSuspend */ ) throw( uno::RuntimeException ) { return sal_False; } virtual uno::Any SAL_CALL getViewData() throw( uno::RuntimeException ) { return uno::Any(); } virtual void SAL_CALL restoreViewData( const uno::Any& /* data */ ) throw ( uno::RuntimeException ) { } virtual uno::Reference< frame::XModel > SAL_CALL getModel() throw ( uno::RuntimeException ) { return m_xModel; } virtual uno::Reference< frame::XFrame > SAL_CALL getFrame() throw ( uno::RuntimeException ) { return m_xFrame; } virtual void SAL_CALL dispose() throw ( uno::RuntimeException ) { } virtual void SAL_CALL addEventListener( const uno::Reference< lang::XEventListener >& /* xListener */ ) throw ( uno::RuntimeException ) { } virtual void SAL_CALL removeEventListener( const uno::Reference< lang::XEventListener >& /* xListener */ ) throw ( uno::RuntimeException ) { } }; protected: DocumentImpl( const uno::Reference< uno::XComponentContext > context ): m_rContext( context ) { } virtual ~DocumentImpl() { } // XInitialization virtual void SAL_CALL initialize( const uno::Sequence< uno::Any >& arguments ) throw ( uno::Exception, uno::RuntimeException ) { if ( arguments.getLength() != 1 ) throw lang::IllegalArgumentException( OUString(), static_cast >(this), 1 ); uno::Sequence< beans::NamedValue > settings; if ( arguments[0] >>= m_sURI ) { // create( [in] string uri ); uno::Reference< frame::XDesktop > desktop( m_rContext->getServiceManager()->createInstanceWithContext( "com.sun.star.frame.Desktop", m_rContext ), uno::UNO_QUERY_THROW ); uno::Reference< frame::XComponentLoader > componentLoader( desktop, uno::UNO_QUERY_THROW ); (void) componentLoader; beans::PropertyValues loadProps(3); loadProps[0].Name = "Hidden"; loadProps[0].Value <<= sal_Bool(true); loadProps[1].Name = "ReadOnly"; loadProps[1].Value <<= sal_Bool(true); loadProps[2].Name = "Preview"; loadProps[2].Value <<= sal_Bool(true); m_xComponent = componentLoader->loadComponentFromURL( m_sURI, "_blank", 0, loadProps ); uno::Reference< awt::XToolkit > toolkit( m_rContext->getServiceManager()->createInstanceWithContext( "com.sun.star.awt.Toolkit", m_rContext ), uno::UNO_QUERY_THROW ); m_xDevice = toolkit->createScreenCompatibleDevice( 1024, 1024 ); m_xRenderable = uno::Reference< view::XRenderable >( m_rContext->getServiceManager()->createInstanceWithContext( "com.sun.star.view.Renderable", m_rContext ), uno::UNO_QUERY_THROW ); m_xController = new MyXController(); m_aRenderProps.realloc( 3 ); m_aRenderProps[0].Name = "IsPrinter"; m_aRenderProps[0].Value <<= sal_Bool(true); m_aRenderProps[1].Name = "RenderDevice"; m_aRenderProps[1].Value <<= m_xDevice; m_aRenderProps[2].Name = "View"; m_aRenderProps[2].Value <<= m_xController; } } // XDocument virtual sal_Int32 SAL_CALL getNumberOfPages() throw ( uno::RuntimeException ) { uno::Any selection; selection <<= m_xComponent; return m_xRenderable->getRendererCount( selection, m_aRenderProps ); } virtual void SAL_CALL render( sal_Int64 buffer, sal_Int32 bufferSize, const uno::Reference< XDocumentRenderCallback >& listener, sal_Int32 pageNo, sal_Int32 zoomLevel, sal_Int32 x, sal_Int32 y ) throw ( lang::IllegalArgumentException, uno::RuntimeException) { uno::Any selection; (void) buffer; (void) bufferSize; (void) listener; (void) zoomLevel; (void) x; (void) y; selection <<= m_xComponent; m_xRenderable->render( pageNo, selection, m_aRenderProps ); uno::Reference< awt::XBitmap> bitmap( m_xDevice->createBitmap( 0, 0, 1024, 1024 ) ); } }; } } } // namespace org::libreoffice::touch /* vim:set shiftwidth=4 softtabstop=4 expandtab: */