Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <sfx2/templateinfodlg.hxx>
11 :
12 : #include <comphelper/processfactory.hxx>
13 : #include <sfx2/sfxresid.hxx>
14 : #include <svtools/DocumentInfoPreview.hxx>
15 : #include <toolkit/helper/vclunohelper.hxx>
16 :
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/XFrame.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>
26 :
27 : #include "templateinfodlg.hrc"
28 :
29 : #define DLG_BORDER_SIZE 12
30 :
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;
38 :
39 0 : SfxTemplateInfoDlg::SfxTemplateInfoDlg (Window *pParent)
40 : : ModalDialog(pParent,SfxResId(DLG_TEMPLATE_INFORMATION)),
41 : maBtnClose(this,SfxResId(BTN_TEMPLATE_INFO_CLOSE)),
42 0 : mpPreviewView(new Window(this)),
43 0 : mpInfoView(new svtools::ODocumentInfoPreview(this,WB_LEFT | WB_VSCROLL | WB_READONLY | WB_BORDER | WB_3DLOOK))
44 : {
45 0 : maBtnClose.SetClickHdl(LINK(this,SfxTemplateInfoDlg,CloseHdl));
46 :
47 0 : Size aWinSize = GetOutputSizePixel();
48 0 : aWinSize.setHeight( aWinSize.getHeight() - 3*DLG_BORDER_SIZE - maBtnClose.GetOutputHeightPixel() );
49 0 : aWinSize.setWidth( (aWinSize.getWidth() - 3*DLG_BORDER_SIZE)/2 );
50 0 : mpInfoView->SetPosSizePixel(Point(DLG_BORDER_SIZE,DLG_BORDER_SIZE),aWinSize);
51 :
52 0 : mpPreviewView->SetPosSizePixel(Point(aWinSize.getWidth()+2*DLG_BORDER_SIZE,DLG_BORDER_SIZE),aWinSize);
53 :
54 0 : xWindow = VCLUnoHelper::GetInterface(mpPreviewView);
55 :
56 0 : xFrame.set(comphelper::getProcessServiceFactory()->createInstance("com.sun.star.frame.Frame"), uno::UNO_QUERY );
57 0 : xFrame->initialize( xWindow );
58 :
59 0 : mpPreviewView->Show();
60 0 : mpInfoView->Show();
61 0 : }
62 :
63 0 : SfxTemplateInfoDlg::~SfxTemplateInfoDlg()
64 : {
65 0 : xFrame->dispose();
66 :
67 0 : delete mpInfoView;
68 0 : }
69 :
70 0 : void SfxTemplateInfoDlg::loadDocument(const OUString &rURL)
71 : {
72 : assert(!rURL.isEmpty());
73 :
74 0 : uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
75 :
76 : try
77 : {
78 : uno::Reference<task::XInteractionHandler2> xInteractionHandler(
79 0 : task::InteractionHandler::createWithParent(xContext, 0) );
80 :
81 0 : uno::Sequence<beans::PropertyValue> aProps(1);
82 0 : aProps[0].Name = "InteractionHandler";
83 0 : aProps[0].Value <<= xInteractionHandler;
84 :
85 : uno::Reference<document::XDocumentProperties> xDocProps(
86 0 : document::DocumentProperties::create(comphelper::getProcessComponentContext()) );
87 :
88 0 : xDocProps->loadFromMedium( rURL, aProps );
89 :
90 0 : mpInfoView->fill( xDocProps, rURL );
91 :
92 : // Create template preview
93 : uno::Reference<util::XURLTransformer > xTrans(
94 0 : util::URLTransformer::create(comphelper::getProcessComponentContext()));
95 :
96 0 : util::URL aURL;
97 0 : aURL.Complete = rURL;
98 0 : xTrans->parseStrict(aURL);
99 :
100 0 : uno::Reference<frame::XDispatchProvider> xProv( xFrame, uno::UNO_QUERY );
101 :
102 0 : uno::Reference<frame::XDispatch> xDisp = xProv.is() ?
103 0 : xProv->queryDispatch( aURL, "_self", 0 ) : uno::Reference<XDispatch>();
104 :
105 0 : if ( xDisp.is() )
106 : {
107 0 : mpPreviewView->EnableInput( false, true );
108 :
109 0 : bool b = true;
110 0 : uno::Sequence <beans::PropertyValue> aArgs( 4 );
111 0 : aArgs[0].Name = "Preview";
112 0 : aArgs[0].Value.setValue( &b, ::getBooleanCppuType() );
113 0 : aArgs[1].Name = "ReadOnly";
114 0 : aArgs[1].Value.setValue( &b, ::getBooleanCppuType() );
115 0 : aArgs[2].Name = "AsTemplate"; // prevents getting an empty URL with getURL()!
116 0 : aArgs[3].Name = "InteractionHandler";
117 0 : aArgs[3].Value <<= xInteractionHandler;
118 :
119 0 : b = false;
120 0 : aArgs[2].Value.setValue( &b, ::getBooleanCppuType() );
121 0 : xDisp->dispatch( aURL, aArgs );
122 0 : }
123 : }
124 0 : catch ( beans::UnknownPropertyException& )
125 : {
126 : }
127 0 : catch ( uno::Exception& )
128 : {
129 0 : }
130 0 : }
131 :
132 0 : IMPL_LINK_NOARG (SfxTemplateInfoDlg, CloseHdl)
133 : {
134 0 : Close();
135 0 : return 0;
136 : }
137 :
138 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|