1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include "vbatemplate.hxx" 28 #include <vbahelper/vbahelper.hxx> 29 #include "wordvbahelper.hxx" 30 #include "vbaautotextentry.hxx" 31 #include <comphelper/processfactory.hxx> 32 #include <com/sun/star/text/XAutoTextContainer.hpp> 33 34 using namespace ::ooo::vba; 35 using namespace ::com::sun::star; 36 37 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 ) 38 : SwVbaTemplate_BASE( rParent, rContext ), mxModel( rModel ), msName( rName ) 39 { 40 } 41 42 43 SwVbaTemplate::~SwVbaTemplate() 44 { 45 } 46 47 rtl::OUString 48 SwVbaTemplate::getName() throw ( css::uno::RuntimeException ) 49 { 50 return msName; 51 } 52 53 uno::Any SAL_CALL 54 SwVbaTemplate::AutoTextEntries( const uno::Any& index ) throw (uno::RuntimeException) 55 { 56 uno::Reference< lang::XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory(); 57 uno::Reference< text::XAutoTextContainer > xAutoTextContainer( xMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.AutoTextContainer") ) ), uno::UNO_QUERY_THROW ); 58 59 // the default template is "Normal.dot" in Word. 60 rtl::OUString sGroup( RTL_CONSTASCII_USTRINGPARAM("Normal") ); 61 sal_Int32 nIndex = msName.lastIndexOf( sal_Unicode('.') ); 62 if( nIndex > 0 ) 63 { 64 sGroup = msName.copy( 0, msName.lastIndexOf( sal_Unicode('.') ) ); 65 // OSL_TRACE("SwVbaTemplate::AutoTextEntries: %s", rtl::OUStringToOString( sGroup, RTL_TEXTENCODING_UTF8 ).getStr() ); 66 } 67 68 uno::Reference< container::XIndexAccess > xGroup; 69 if( xAutoTextContainer->hasByName( sGroup ) ) 70 { 71 xGroup.set( xAutoTextContainer->getByName( sGroup ), uno::UNO_QUERY_THROW ); 72 } 73 else 74 { 75 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Auto Text Entry doesn't exist") ), uno::Reference< uno::XInterface >() ); 76 //xGroup.set( xAutoTextContainer->insertNewByName( sGroup ), uno::UNO_QUERY_THROW ); 77 } 78 79 uno::Reference< XCollection > xCol( new SwVbaAutoTextEntries( this, mxContext, xGroup ) ); 80 if( index.hasValue() ) 81 return xCol->Item( index, uno::Any() ); 82 return uno::makeAny( xCol ); 83 } 84 85 rtl::OUString& 86 SwVbaTemplate::getServiceImplName() 87 { 88 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaTemplate") ); 89 return sImplName; 90 } 91 92 uno::Sequence< rtl::OUString > 93 SwVbaTemplate::getServiceNames() 94 { 95 static uno::Sequence< rtl::OUString > aServiceNames; 96 if ( aServiceNames.getLength() == 0 ) 97 { 98 aServiceNames.realloc( 1 ); 99 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Template" ) ); 100 } 101 return aServiceNames; 102 } 103 104