1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docxforms.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
39 #include <com/sun/star/uno/Reference.hxx>
40 #include <com/sun/star/container/XNameContainer.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/frame/XModule.hpp>
43 #include <com/sun/star/xforms/XModel.hpp>
44 #include <com/sun/star/xforms/XFormsUIHelper1.hpp>
45 #include <unotools/processfactory.hxx>
46 #include <tools/diagnose_ex.h>
49 using namespace ::com::sun::star
;
52 using uno::XInterface
;
56 using container::XNameContainer
;
59 using xforms::XFormsUIHelper1
;
63 Reference
<XNameContainer
> SwDoc::getXForms() const
68 bool SwDoc::isXForms() const
73 Reference
<XInterface
> lcl_createInstance( const sal_Char
* pServiceName
)
75 DBG_ASSERT( pServiceName
!= NULL
, "no service name" );
76 return utl::getProcessServiceFactory()->createInstance(
77 OUString::createFromAscii( pServiceName
) );
80 void SwDoc::initXForms( bool bCreateDefaultModel
)
82 DBG_ASSERT( ! isXForms(), "please initialize only once" );
86 // create XForms components
87 xXForms
.set( lcl_createInstance( "com.sun.star.xforms.XForms" ),
89 DBG_ASSERT( xXForms
.is(), "can't create XForms container" );
91 // change our module identifier, to be able to have a dedicated UI
92 Reference
< XModule
> xModule
;
93 SwDocShell
* pShell( GetDocShell() );
95 xModule
= xModule
.query( pShell
->GetModel() );
96 DBG_ASSERT( xModule
.is(), "SwDoc::initXForms: no XModule at the document!" );
98 xModule
->setIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xforms.XMLFormDocument" ) ) );
100 // create default model
101 if( bCreateDefaultModel
&& xXForms
.is() )
103 OUString
sName(RTL_CONSTASCII_USTRINGPARAM("Model 1"));
104 Reference
<XModel
> xModel(
105 lcl_createInstance( "com.sun.star.xforms.Model" ),
107 DBG_ASSERT( xModel
.is(), "no model?" );
110 xModel
->setID( sName
);
111 Reference
<XFormsUIHelper1
>( xModel
, UNO_QUERY
)->newInstance(
112 OUString(RTL_CONSTASCII_USTRINGPARAM("Instance 1")),
113 OUString(), sal_True
);
114 xModel
->initialize();
115 xXForms
->insertByName( sName
, makeAny( xModel
) );
117 DBG_ASSERT( xXForms
->hasElements(), "can't create XForms model" );
120 DBG_ASSERT( isXForms(), "initialization failed" );
122 catch( const Exception
& )
124 DBG_UNHANDLED_EXCEPTION();