merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / vba / vbatemplate.cxx
blob136a9ec43a51f5c2cf91cfba6cb3b511e87a5f7e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile:
10 * $Revision:
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 ************************************************************************/
30 #include "vbatemplate.hxx"
31 #include <vbahelper/vbahelper.hxx>
32 #include "wordvbahelper.hxx"
33 #include "vbaautotextentry.hxx"
34 #include <comphelper/processfactory.hxx>
35 #include <com/sun/star/text/XAutoTextContainer.hpp>
37 using namespace ::ooo::vba;
38 using namespace ::com::sun::star;
40 SwVbaTemplate::SwVbaTemplate( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const css::uno::Reference< css::frame::XModel >& rModel, const rtl::OUString& rName )
41 : SwVbaTemplate_BASE( rParent, rContext ), mxModel( rModel ), msName( rName )
46 SwVbaTemplate::~SwVbaTemplate()
50 rtl::OUString
51 SwVbaTemplate::getName() throw ( css::uno::RuntimeException )
53 return msName;
56 uno::Any SAL_CALL
57 SwVbaTemplate::AutoTextEntries( const uno::Any& index ) throw (uno::RuntimeException)
59 uno::Reference< lang::XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
60 uno::Reference< text::XAutoTextContainer > xAutoTextContainer( xMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.AutoTextContainer") ) ), uno::UNO_QUERY_THROW );
62 // the default template is "Normal.dot" in Word.
63 rtl::OUString sGroup( RTL_CONSTASCII_USTRINGPARAM("Normal") );
64 sal_Int32 nIndex = msName.lastIndexOf( sal_Unicode('.') );
65 if( nIndex > 0 )
67 sGroup = msName.copy( 0, msName.lastIndexOf( sal_Unicode('.') ) );
68 // OSL_TRACE("SwVbaTemplate::AutoTextEntries: %s", rtl::OUStringToOString( sGroup, RTL_TEXTENCODING_UTF8 ).getStr() );
71 uno::Reference< container::XIndexAccess > xGroup;
72 if( xAutoTextContainer->hasByName( sGroup ) )
74 xGroup.set( xAutoTextContainer->getByName( sGroup ), uno::UNO_QUERY_THROW );
76 else
78 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Auto Text Entry doesn't exist") ), uno::Reference< uno::XInterface >() );
79 //xGroup.set( xAutoTextContainer->insertNewByName( sGroup ), uno::UNO_QUERY_THROW );
82 uno::Reference< XCollection > xCol( new SwVbaAutoTextEntries( this, mxContext, xGroup ) );
83 if( index.hasValue() )
84 return xCol->Item( index, uno::Any() );
85 return uno::makeAny( xCol );
88 rtl::OUString&
89 SwVbaTemplate::getServiceImplName()
91 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaTemplate") );
92 return sImplName;
95 uno::Sequence< rtl::OUString >
96 SwVbaTemplate::getServiceNames()
98 static uno::Sequence< rtl::OUString > aServiceNames;
99 if ( aServiceNames.getLength() == 0 )
101 aServiceNames.realloc( 1 );
102 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Template" ) );
104 return aServiceNames;