Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / dialog / templateinfodlg.cxx
blob9437f3308e1116e0bffda753d23e982540bf8ff8
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 #include <sfx2/templateinfodlg.hxx>
12 #include <comphelper/processfactory.hxx>
13 #include <sfx2/sfxresid.hxx>
14 #include <svtools/DocumentInfoPreview.hxx>
15 #include <toolkit/helper/vclunohelper.hxx>
17 #include <com/sun/star/beans/XPropertySet.hpp>
18 #include <com/sun/star/document/DocumentProperties.hpp>
19 #include <com/sun/star/frame/XDispatchProvider.hpp>
20 #include <com/sun/star/frame/Frame.hpp>
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/task/InteractionHandler.hpp>
23 #include <com/sun/star/util/URL.hpp>
24 #include <com/sun/star/util/URLTransformer.hpp>
25 #include <com/sun/star/util/XURLTransformer.hpp>
27 #include "templateinfodlg.hrc"
29 #define DLG_BORDER_SIZE 12
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::beans;
33 using namespace ::com::sun::star::document;
34 using namespace ::com::sun::star::frame;
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::task;
37 using namespace ::com::sun::star::util;
39 SfxTemplateInfoDlg::SfxTemplateInfoDlg (Window *pParent)
40 : ModalDialog(pParent,SfxResId(DLG_TEMPLATE_INFORMATION)),
41 maBtnClose(this,SfxResId(BTN_TEMPLATE_INFO_CLOSE)),
42 mpPreviewView(new Window(this)),
43 mpInfoView(new svtools::ODocumentInfoPreview(this,WB_LEFT | WB_VSCROLL | WB_READONLY | WB_BORDER | WB_3DLOOK))
45 maBtnClose.SetClickHdl(LINK(this,SfxTemplateInfoDlg,CloseHdl));
47 Size aWinSize = GetOutputSizePixel();
48 aWinSize.setHeight( aWinSize.getHeight() - 3*DLG_BORDER_SIZE - maBtnClose.GetOutputHeightPixel() );
49 aWinSize.setWidth( (aWinSize.getWidth() - 3*DLG_BORDER_SIZE)/2 );
50 mpInfoView->SetPosSizePixel(Point(DLG_BORDER_SIZE,DLG_BORDER_SIZE),aWinSize);
52 mpPreviewView->SetPosSizePixel(Point(aWinSize.getWidth()+2*DLG_BORDER_SIZE,DLG_BORDER_SIZE),aWinSize);
54 xWindow = VCLUnoHelper::GetInterface(mpPreviewView);
56 m_xFrame = Frame::create( comphelper::getProcessComponentContext() );
57 m_xFrame->initialize( xWindow );
59 mpPreviewView->Show();
60 mpInfoView->Show();
63 SfxTemplateInfoDlg::~SfxTemplateInfoDlg()
65 m_xFrame->dispose();
67 delete mpInfoView;
70 void SfxTemplateInfoDlg::loadDocument(const OUString &rURL)
72 assert(!rURL.isEmpty());
74 uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
76 try
78 uno::Reference<task::XInteractionHandler2> xInteractionHandler(
79 task::InteractionHandler::createWithParent(xContext, 0) );
81 uno::Sequence<beans::PropertyValue> aProps(1);
82 aProps[0].Name = "InteractionHandler";
83 aProps[0].Value <<= xInteractionHandler;
85 uno::Reference<document::XDocumentProperties> xDocProps(
86 document::DocumentProperties::create(comphelper::getProcessComponentContext()) );
88 xDocProps->loadFromMedium( rURL, aProps );
90 mpInfoView->fill( xDocProps, rURL );
92 // Create template preview
93 uno::Reference<util::XURLTransformer > xTrans(
94 util::URLTransformer::create(comphelper::getProcessComponentContext()));
96 util::URL aURL;
97 aURL.Complete = rURL;
98 xTrans->parseStrict(aURL);
100 uno::Reference<frame::XDispatch> xDisp = m_xFrame->queryDispatch( aURL, "_self", 0 );
102 if ( xDisp.is() )
104 mpPreviewView->EnableInput( false, true );
106 bool b = true;
107 uno::Sequence <beans::PropertyValue> aArgs( 4 );
108 aArgs[0].Name = "Preview";
109 aArgs[0].Value.setValue( &b, ::getBooleanCppuType() );
110 aArgs[1].Name = "ReadOnly";
111 aArgs[1].Value.setValue( &b, ::getBooleanCppuType() );
112 aArgs[2].Name = "AsTemplate"; // prevents getting an empty URL with getURL()!
113 aArgs[3].Name = "InteractionHandler";
114 aArgs[3].Value <<= xInteractionHandler;
116 b = false;
117 aArgs[2].Value.setValue( &b, ::getBooleanCppuType() );
118 xDisp->dispatch( aURL, aArgs );
121 catch ( beans::UnknownPropertyException& )
124 catch ( uno::Exception& )
129 IMPL_LINK_NOARG (SfxTemplateInfoDlg, CloseHdl)
131 Close();
132 return 0;
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */