1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 27 28 29 30 #include <doc.hxx> 31 #include <docsh.hxx> 32 #include <com/sun/star/uno/Reference.hxx> 33 #include <com/sun/star/container/XNameContainer.hpp> 34 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 35 #include <com/sun/star/frame/XModule.hpp> 36 #include <com/sun/star/xforms/XModel.hpp> 37 #include <com/sun/star/xforms/XFormsUIHelper1.hpp> 38 #include <unotools/processfactory.hxx> 39 #include <tools/diagnose_ex.h> 40 41 42 using namespace ::com::sun::star; 43 44 using uno::Reference; 45 using uno::XInterface; 46 using uno::UNO_QUERY; 47 using uno::makeAny; 48 using uno::Exception; 49 using container::XNameContainer; 50 using xforms::XModel; 51 using frame::XModule; 52 using xforms::XFormsUIHelper1; 53 using rtl::OUString; 54 55 56 Reference<XNameContainer> SwDoc::getXForms() const 57 { 58 return xXForms; 59 } 60 61 bool SwDoc::isXForms() const 62 { 63 return xXForms.is(); 64 } 65 66 Reference<XInterface> lcl_createInstance( const sal_Char* pServiceName ) 67 { 68 DBG_ASSERT( pServiceName != NULL, "no service name" ); 69 return utl::getProcessServiceFactory()->createInstance( 70 OUString::createFromAscii( pServiceName ) ); 71 } 72 73 void SwDoc::initXForms( bool bCreateDefaultModel ) 74 { 75 DBG_ASSERT( ! isXForms(), "please initialize only once" ); 76 77 try 78 { 79 // create XForms components 80 xXForms.set( lcl_createInstance( "com.sun.star.xforms.XForms" ), 81 UNO_QUERY ); 82 DBG_ASSERT( xXForms.is(), "can't create XForms container" ); 83 84 // change our module identifier, to be able to have a dedicated UI 85 Reference< XModule > xModule; 86 SwDocShell* pShell( GetDocShell() ); 87 if ( pShell ) 88 xModule = xModule.query( pShell->GetModel() ); 89 DBG_ASSERT( xModule.is(), "SwDoc::initXForms: no XModule at the document!" ); 90 if ( xModule.is() ) 91 xModule->setIdentifier( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xforms.XMLFormDocument" ) ) ); 92 93 // create default model 94 if( bCreateDefaultModel && xXForms.is() ) 95 { 96 OUString sName(RTL_CONSTASCII_USTRINGPARAM("Model 1")); 97 Reference<XModel> xModel( 98 lcl_createInstance( "com.sun.star.xforms.Model" ), 99 UNO_QUERY ); 100 DBG_ASSERT( xModel.is(), "no model?" ); 101 if( xModel.is() ) 102 { 103 xModel->setID( sName ); 104 Reference<XFormsUIHelper1>( xModel, UNO_QUERY )->newInstance( 105 OUString(RTL_CONSTASCII_USTRINGPARAM("Instance 1")), 106 OUString(), sal_True ); 107 xModel->initialize(); 108 xXForms->insertByName( sName, makeAny( xModel ) ); 109 } 110 DBG_ASSERT( xXForms->hasElements(), "can't create XForms model" ); 111 } 112 113 DBG_ASSERT( isXForms(), "initialization failed" ); 114 } 115 catch( const Exception& ) 116 { 117 DBG_UNHANDLED_EXCEPTION(); 118 } 119 } 120