Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <doc.hxx>
30 : : #include <docsh.hxx>
31 : : #include <com/sun/star/uno/Reference.hxx>
32 : : #include <com/sun/star/container/XNameContainer.hpp>
33 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 : : #include <com/sun/star/frame/XModule.hpp>
35 : : #include <com/sun/star/xforms/XModel.hpp>
36 : : #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
37 : : #include <comphelper/processfactory.hxx>
38 : : #include <tools/diagnose_ex.h>
39 : :
40 : :
41 : : using namespace ::com::sun::star;
42 : :
43 : : using uno::Reference;
44 : : using uno::XInterface;
45 : : using uno::UNO_QUERY;
46 : : using uno::makeAny;
47 : : using uno::Exception;
48 : : using container::XNameContainer;
49 : : using xforms::XModel;
50 : : using frame::XModule;
51 : : using xforms::XFormsUIHelper1;
52 : : using rtl::OUString;
53 : :
54 : :
55 : 40 : Reference<XNameContainer> SwDoc::getXForms() const
56 : : {
57 : 40 : return xXForms;
58 : : }
59 : :
60 : 13234 : bool SwDoc::isXForms() const
61 : : {
62 : 13234 : return xXForms.is();
63 : : }
64 : :
65 : 0 : Reference<XInterface> lcl_createInstance( const sal_Char* pServiceName )
66 : : {
67 : : OSL_ENSURE( pServiceName != NULL, "no service name" );
68 [ # # ]: 0 : return comphelper::getProcessServiceFactory()->createInstance(
69 [ # # ]: 0 : OUString::createFromAscii( pServiceName ) );
70 : : }
71 : :
72 : 0 : void SwDoc::initXForms( bool bCreateDefaultModel )
73 : : {
74 : : OSL_ENSURE( ! isXForms(), "please initialize only once" );
75 : :
76 : : try
77 : : {
78 : : // create XForms components
79 : : xXForms.set( lcl_createInstance( "com.sun.star.xforms.XForms" ),
80 [ # # ][ # # ]: 0 : UNO_QUERY );
81 : : OSL_ENSURE( xXForms.is(), "can't create XForms container" );
82 : :
83 : : // change our module identifier, to be able to have a dedicated UI
84 : 0 : Reference< XModule > xModule;
85 : 0 : SwDocShell* pShell( GetDocShell() );
86 [ # # ]: 0 : if ( pShell )
87 [ # # ][ # # ]: 0 : xModule = xModule.query( pShell->GetModel() );
[ # # ]
88 : : OSL_ENSURE( xModule.is(), "SwDoc::initXForms: no XModule at the document!" );
89 [ # # ]: 0 : if ( xModule.is() )
90 [ # # ][ # # ]: 0 : xModule->setIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xforms.XMLFormDocument" ) ) );
[ # # ]
91 : :
92 : : // create default model
93 [ # # ][ # # ]: 0 : if( bCreateDefaultModel && xXForms.is() )
[ # # ]
94 : : {
95 [ # # ]: 0 : OUString sName(RTL_CONSTASCII_USTRINGPARAM("Model 1"));
96 : : Reference<XModel> xModel(
97 : : lcl_createInstance( "com.sun.star.xforms.Model" ),
98 [ # # ][ # # ]: 0 : UNO_QUERY );
99 : : OSL_ENSURE( xModel.is(), "no model?" );
100 [ # # ]: 0 : if( xModel.is() )
101 : : {
102 [ # # ][ # # ]: 0 : xModel->setID( sName );
103 [ # # ][ # # ]: 0 : Reference<XFormsUIHelper1>( xModel, UNO_QUERY )->newInstance(
104 : : OUString(RTL_CONSTASCII_USTRINGPARAM("Instance 1")),
105 [ # # ][ # # ]: 0 : OUString(), sal_True );
106 [ # # ][ # # ]: 0 : xModel->initialize();
107 [ # # ][ # # ]: 0 : xXForms->insertByName( sName, makeAny( xModel ) );
[ # # ]
108 : : }
109 : 0 : OSL_ENSURE( xXForms->hasElements(), "can't create XForms model" );
110 : : }
111 : :
112 [ # # ]: 0 : OSL_ENSURE( isXForms(), "initialization failed" );
113 : : }
114 : 0 : catch( const Exception& )
115 : : {
116 : : DBG_UNHANDLED_EXCEPTION();
117 : : }
118 : 0 : }
119 : :
120 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|