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 #include "vbatemplate.hxx" 24 #include <vbahelper/vbahelper.hxx> 25 #include "wordvbahelper.hxx" 26 #include "vbaautotextentry.hxx" 27 #include <comphelper/processfactory.hxx> 28 #include <com/sun/star/text/XAutoTextContainer.hpp> 29 30 using namespace ::ooo::vba; 31 using namespace ::com::sun::star; 32 33 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 ) 34 : SwVbaTemplate_BASE( rParent, rContext ), mxModel( rModel ), msName( rName ) 35 { 36 } 37 38 39 SwVbaTemplate::~SwVbaTemplate() 40 { 41 } 42 43 rtl::OUString 44 SwVbaTemplate::getName() throw ( css::uno::RuntimeException ) 45 { 46 return msName; 47 } 48 49 uno::Any SAL_CALL 50 SwVbaTemplate::AutoTextEntries( const uno::Any& index ) throw (uno::RuntimeException) 51 { 52 uno::Reference< lang::XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory(); 53 uno::Reference< text::XAutoTextContainer > xAutoTextContainer( xMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.AutoTextContainer") ) ), uno::UNO_QUERY_THROW ); 54 55 // the default template is "Normal.dot" in Word. 56 rtl::OUString sGroup( RTL_CONSTASCII_USTRINGPARAM("Normal") ); 57 sal_Int32 nIndex = msName.lastIndexOf( sal_Unicode('.') ); 58 if( nIndex > 0 ) 59 { 60 sGroup = msName.copy( 0, msName.lastIndexOf( sal_Unicode('.') ) ); 61 // OSL_TRACE("SwVbaTemplate::AutoTextEntries: %s", rtl::OUStringToOString( sGroup, RTL_TEXTENCODING_UTF8 ).getStr() ); 62 } 63 64 uno::Reference< container::XIndexAccess > xGroup; 65 if( xAutoTextContainer->hasByName( sGroup ) ) 66 { 67 xGroup.set( xAutoTextContainer->getByName( sGroup ), uno::UNO_QUERY_THROW ); 68 } 69 else 70 { 71 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Auto Text Entry doesn't exist") ), uno::Reference< uno::XInterface >() ); 72 //xGroup.set( xAutoTextContainer->insertNewByName( sGroup ), uno::UNO_QUERY_THROW ); 73 } 74 75 uno::Reference< XCollection > xCol( new SwVbaAutoTextEntries( this, mxContext, xGroup ) ); 76 if( index.hasValue() ) 77 return xCol->Item( index, uno::Any() ); 78 return uno::makeAny( xCol ); 79 } 80 81 rtl::OUString& 82 SwVbaTemplate::getServiceImplName() 83 { 84 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaTemplate") ); 85 return sImplName; 86 } 87 88 uno::Sequence< rtl::OUString > 89 SwVbaTemplate::getServiceNames() 90 { 91 static uno::Sequence< rtl::OUString > aServiceNames; 92 if ( aServiceNames.getLength() == 0 ) 93 { 94 aServiceNames.realloc( 1 ); 95 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Template" ) ); 96 } 97 return aServiceNames; 98 } 99 100