/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * 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/. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace ::com::sun::star; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::document; using namespace ::com::sun::star::frame; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::task; using namespace ::com::sun::star::util; SfxTemplateInfoDlg::SfxTemplateInfoDlg (vcl::Window *pParent) : ModalDialog(pParent, "TemplateInfo", "sfx/ui/templateinfodialog.ui") { get(mpBtnClose, "close"); get(mpBox, "box"); get(mpInfoView, "infoDrawingArea"); mpPreviewView = new vcl::Window(mpBox); Size aSize(LogicToPixel(Size(250, 160), MAP_APPFONT)); mpBox->set_width_request(aSize.Width()); mpBox->set_height_request(aSize.Height()); mpBtnClose->SetClickHdl(LINK(this,SfxTemplateInfoDlg,CloseHdl)); xWindow = VCLUnoHelper::GetInterface(mpPreviewView); m_xFrame = Frame::create( comphelper::getProcessComponentContext() ); m_xFrame->initialize( xWindow ); } SfxTemplateInfoDlg::~SfxTemplateInfoDlg() { m_xFrame->dispose(); } void SfxTemplateInfoDlg::loadDocument(const OUString &rURL) { assert(!rURL.isEmpty()); uno::Reference xContext(comphelper::getProcessComponentContext()); try { uno::Reference xInteractionHandler( task::InteractionHandler::createWithParent(xContext, 0) ); uno::Sequence aProps(1); aProps[0].Name = "InteractionHandler"; aProps[0].Value <<= xInteractionHandler; uno::Reference xDocProps( document::DocumentProperties::create(comphelper::getProcessComponentContext()) ); xDocProps->loadFromMedium( rURL, aProps ); mpInfoView->fill( xDocProps, rURL ); // Create template preview uno::Reference xTrans( util::URLTransformer::create(comphelper::getProcessComponentContext())); util::URL aURL; aURL.Complete = rURL; xTrans->parseStrict(aURL); uno::Reference xDisp = m_xFrame->queryDispatch( aURL, "_self", 0 ); if ( xDisp.is() ) { mpPreviewView->EnableInput( false, true ); bool b = true; uno::Sequence aArgs( 4 ); aArgs[0].Name = "Preview"; aArgs[0].Value.setValue( &b, ::getBooleanCppuType() ); aArgs[1].Name = "ReadOnly"; aArgs[1].Value.setValue( &b, ::getBooleanCppuType() ); aArgs[2].Name = "AsTemplate"; // prevents getting an empty URL with getURL()! aArgs[3].Name = "InteractionHandler"; aArgs[3].Value <<= xInteractionHandler; b = false; aArgs[2].Value.setValue( &b, ::getBooleanCppuType() ); xDisp->dispatch( aURL, aArgs ); } } catch ( beans::UnknownPropertyException& ) { } catch ( uno::Exception& ) { } } IMPL_LINK_NOARG (SfxTemplateInfoDlg, CloseHdl) { Close(); return 0; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */