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 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <doc.hxx>
21 : #include <docsh.hxx>
22 : #include <com/sun/star/uno/Reference.hxx>
23 : #include <com/sun/star/container/XNameContainer.hpp>
24 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 : #include <com/sun/star/frame/XModule.hpp>
26 : #include <com/sun/star/xforms/XModel.hpp>
27 : #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
28 : #include <comphelper/processfactory.hxx>
29 : #include <tools/diagnose_ex.h>
30 :
31 :
32 : using namespace ::com::sun::star;
33 :
34 : using uno::Reference;
35 : using uno::XInterface;
36 : using uno::UNO_QUERY;
37 : using uno::makeAny;
38 : using uno::Exception;
39 : using container::XNameContainer;
40 : using xforms::XModel;
41 : using frame::XModule;
42 : using xforms::XFormsUIHelper1;
43 : using rtl::OUString;
44 :
45 :
46 8 : Reference<XNameContainer> SwDoc::getXForms() const
47 : {
48 8 : return xXForms;
49 : }
50 :
51 2977 : bool SwDoc::isXForms() const
52 : {
53 2977 : return xXForms.is();
54 : }
55 :
56 0 : static Reference<XInterface> lcl_createInstance( const sal_Char* pServiceName )
57 : {
58 : OSL_ENSURE( pServiceName != NULL, "no service name" );
59 0 : return comphelper::getProcessServiceFactory()->createInstance(
60 0 : OUString::createFromAscii( pServiceName ) );
61 : }
62 :
63 0 : void SwDoc::initXForms( bool bCreateDefaultModel )
64 : {
65 : OSL_ENSURE( ! isXForms(), "please initialize only once" );
66 :
67 : try
68 : {
69 : // create XForms components
70 : xXForms.set( lcl_createInstance( "com.sun.star.xforms.XForms" ),
71 0 : UNO_QUERY );
72 : OSL_ENSURE( xXForms.is(), "can't create XForms container" );
73 :
74 : // change our module identifier, to be able to have a dedicated UI
75 0 : Reference< XModule > xModule;
76 0 : SwDocShell* pShell( GetDocShell() );
77 0 : if ( pShell )
78 0 : xModule = xModule.query( pShell->GetModel() );
79 : OSL_ENSURE( xModule.is(), "SwDoc::initXForms: no XModule at the document!" );
80 0 : if ( xModule.is() )
81 0 : xModule->setIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xforms.XMLFormDocument" ) ) );
82 :
83 : // create default model
84 0 : if( bCreateDefaultModel && xXForms.is() )
85 : {
86 0 : OUString sName(RTL_CONSTASCII_USTRINGPARAM("Model 1"));
87 : Reference<XModel> xModel(
88 : lcl_createInstance( "com.sun.star.xforms.Model" ),
89 0 : UNO_QUERY );
90 : OSL_ENSURE( xModel.is(), "no model?" );
91 0 : if( xModel.is() )
92 : {
93 0 : xModel->setID( sName );
94 0 : Reference<XFormsUIHelper1>( xModel, UNO_QUERY )->newInstance(
95 : OUString(RTL_CONSTASCII_USTRINGPARAM("Instance 1")),
96 0 : OUString(), sal_True );
97 0 : xModel->initialize();
98 0 : xXForms->insertByName( sName, makeAny( xModel ) );
99 : }
100 0 : OSL_ENSURE( xXForms->hasElements(), "can't create XForms model" );
101 : }
102 :
103 0 : OSL_ENSURE( isXForms(), "initialization failed" );
104 : }
105 0 : catch( const Exception& )
106 : {
107 : DBG_UNHANDLED_EXCEPTION();
108 : }
109 0 : }
110 :
111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|