189dcb3daSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 389dcb3daSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 489dcb3daSAndrew Rist * or more contributor license agreements. See the NOTICE file 589dcb3daSAndrew Rist * distributed with this work for additional information 689dcb3daSAndrew Rist * regarding copyright ownership. The ASF licenses this file 789dcb3daSAndrew Rist * to you under the Apache License, Version 2.0 (the 889dcb3daSAndrew Rist * "License"); you may not use this file except in compliance 989dcb3daSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1189dcb3daSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1389dcb3daSAndrew Rist * Unless required by applicable law or agreed to in writing, 1489dcb3daSAndrew Rist * software distributed under the License is distributed on an 1589dcb3daSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1689dcb3daSAndrew Rist * KIND, either express or implied. See the License for the 1789dcb3daSAndrew Rist * specific language governing permissions and limitations 1889dcb3daSAndrew Rist * under the License. 19cdf0e10cSrcweir * 2089dcb3daSAndrew Rist *************************************************************/ 2189dcb3daSAndrew Rist 2289dcb3daSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 26cdf0e10cSrcweir #include "precompiled_xmlhelp.hxx" 27cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 28cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 29cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 30cdf0e10cSrcweir #include "tvfactory.hxx" 31cdf0e10cSrcweir #include "tvread.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir 34cdf0e10cSrcweir using namespace treeview; 35cdf0e10cSrcweir using namespace com::sun::star; 36cdf0e10cSrcweir using namespace com::sun::star::uno; 37cdf0e10cSrcweir using namespace com::sun::star::lang; 38cdf0e10cSrcweir using namespace com::sun::star::beans; 39cdf0e10cSrcweir using namespace com::sun::star::container; 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir 43cdf0e10cSrcweir TVFactory::TVFactory( const uno::Reference< XMultiServiceFactory >& xMSF ) 44cdf0e10cSrcweir : m_xMSF( xMSF ) 45cdf0e10cSrcweir { 46cdf0e10cSrcweir } 47cdf0e10cSrcweir 48cdf0e10cSrcweir 49cdf0e10cSrcweir TVFactory::~TVFactory() 50cdf0e10cSrcweir { 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir 54cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 55cdf0e10cSrcweir // XInterface 56cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 57cdf0e10cSrcweir 58cdf0e10cSrcweir void SAL_CALL 59cdf0e10cSrcweir TVFactory::acquire( 60cdf0e10cSrcweir void ) 61cdf0e10cSrcweir throw() 62cdf0e10cSrcweir { 63cdf0e10cSrcweir OWeakObject::acquire(); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir 67cdf0e10cSrcweir void SAL_CALL 68cdf0e10cSrcweir TVFactory::release( 69cdf0e10cSrcweir void ) 70cdf0e10cSrcweir throw() 71cdf0e10cSrcweir { 72cdf0e10cSrcweir OWeakObject::release(); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir 76cdf0e10cSrcweir Any SAL_CALL 77cdf0e10cSrcweir TVFactory::queryInterface( 78cdf0e10cSrcweir const Type& rType ) 79cdf0e10cSrcweir throw( RuntimeException ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir Any aRet = cppu::queryInterface( rType, 82cdf0e10cSrcweir SAL_STATIC_CAST( XServiceInfo*, this ), 83cdf0e10cSrcweir SAL_STATIC_CAST( XTypeProvider*, this ), 84cdf0e10cSrcweir SAL_STATIC_CAST( XMultiServiceFactory*, this ) ); 85cdf0e10cSrcweir 86cdf0e10cSrcweir return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir 90cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////// 91cdf0e10cSrcweir // 92cdf0e10cSrcweir // XTypeProvider methods. 93cdf0e10cSrcweir 94cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( TVFactory, 95cdf0e10cSrcweir XServiceInfo, 96cdf0e10cSrcweir XTypeProvider, 97cdf0e10cSrcweir XMultiServiceFactory ); 98cdf0e10cSrcweir 99cdf0e10cSrcweir 100cdf0e10cSrcweir 101cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////// 102cdf0e10cSrcweir 103cdf0e10cSrcweir // XServiceInfo methods. 104cdf0e10cSrcweir 105cdf0e10cSrcweir rtl::OUString SAL_CALL 106cdf0e10cSrcweir TVFactory::getImplementationName() 107cdf0e10cSrcweir throw( RuntimeException ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir return TVFactory::getImplementationName_static(); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir 113cdf0e10cSrcweir sal_Bool SAL_CALL 114cdf0e10cSrcweir TVFactory::supportsService( 115cdf0e10cSrcweir const rtl::OUString& ServiceName ) 116cdf0e10cSrcweir throw( RuntimeException ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir return 119cdf0e10cSrcweir ServiceName.compareToAscii( "com.sun.star.help.TreeView" ) == 0 || 120cdf0e10cSrcweir ServiceName.compareToAscii( "com.sun.star.ucb.HiearchyDataSource" ) == 0; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir 124cdf0e10cSrcweir Sequence< rtl::OUString > SAL_CALL 125cdf0e10cSrcweir TVFactory::getSupportedServiceNames( void ) 126cdf0e10cSrcweir throw( RuntimeException ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir return TVFactory::getSupportedServiceNames_static(); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir 132cdf0e10cSrcweir 133cdf0e10cSrcweir // XMultiServiceFactory 134cdf0e10cSrcweir 135cdf0e10cSrcweir Reference< XInterface > SAL_CALL 136cdf0e10cSrcweir TVFactory::createInstance( 137cdf0e10cSrcweir const rtl::OUString& aServiceSpecifier ) 138cdf0e10cSrcweir throw( Exception, 139cdf0e10cSrcweir RuntimeException ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir Any aAny; 142cdf0e10cSrcweir aAny <<= rtl::OUString(); 143cdf0e10cSrcweir Sequence< Any > seq( 1 ); 144cdf0e10cSrcweir seq[0] <<= PropertyValue( 145cdf0e10cSrcweir rtl::OUString::createFromAscii( "nodepath" ), 146cdf0e10cSrcweir -1, 147cdf0e10cSrcweir aAny, 148cdf0e10cSrcweir PropertyState_DIRECT_VALUE ); 149cdf0e10cSrcweir 150cdf0e10cSrcweir return createInstanceWithArguments( aServiceSpecifier, 151cdf0e10cSrcweir seq ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir 155cdf0e10cSrcweir Reference< XInterface > SAL_CALL 156cdf0e10cSrcweir TVFactory::createInstanceWithArguments( 157cdf0e10cSrcweir const rtl::OUString& ServiceSpecifier, 158cdf0e10cSrcweir const Sequence< Any >& Arguments ) 159cdf0e10cSrcweir throw( Exception, 160cdf0e10cSrcweir RuntimeException ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir (void)ServiceSpecifier; 163cdf0e10cSrcweir 164cdf0e10cSrcweir if( ! m_xHDS.is() ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir cppu::OWeakObject* p = new TVChildTarget( m_xMSF ); 167cdf0e10cSrcweir m_xHDS = Reference< XInterface >( p ); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir Reference< XInterface > ret = m_xHDS; 171cdf0e10cSrcweir 172cdf0e10cSrcweir rtl::OUString hierview; 173cdf0e10cSrcweir for( int i = 0; i < Arguments.getLength(); ++i ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir PropertyValue pV; 176cdf0e10cSrcweir if( ! ( Arguments[i] >>= pV ) ) 177cdf0e10cSrcweir continue; 178cdf0e10cSrcweir 179cdf0e10cSrcweir if( pV.Name.compareToAscii( "nodepath" ) ) 180cdf0e10cSrcweir continue; 181cdf0e10cSrcweir 182cdf0e10cSrcweir if( ! ( pV.Value >>= hierview ) ) 183cdf0e10cSrcweir continue; 184cdf0e10cSrcweir 185cdf0e10cSrcweir break; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir if( hierview.getLength() ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xhieraccess( m_xHDS,UNO_QUERY ); 191cdf0e10cSrcweir Any aAny = xhieraccess->getByHierarchicalName( hierview ); 192cdf0e10cSrcweir Reference< XInterface > xInterface; 193cdf0e10cSrcweir aAny >>= xInterface; 194cdf0e10cSrcweir return xInterface; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir else 197cdf0e10cSrcweir return m_xHDS; 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir 201cdf0e10cSrcweir Sequence< rtl::OUString > SAL_CALL 202cdf0e10cSrcweir TVFactory::getAvailableServiceNames( ) 203cdf0e10cSrcweir throw( RuntimeException ) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir Sequence< rtl::OUString > seq( 1 ); 206cdf0e10cSrcweir seq[0] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HierarchyDataReadAccess" ); 207cdf0e10cSrcweir return seq; 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir 211cdf0e10cSrcweir 212cdf0e10cSrcweir // static 213cdf0e10cSrcweir 214cdf0e10cSrcweir 215cdf0e10cSrcweir rtl::OUString SAL_CALL 216cdf0e10cSrcweir TVFactory::getImplementationName_static() 217cdf0e10cSrcweir { 218cdf0e10cSrcweir return rtl::OUString::createFromAscii( "com.sun.star.help.TreeViewImpl" ); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir 222cdf0e10cSrcweir Sequence< rtl::OUString > SAL_CALL 223cdf0e10cSrcweir TVFactory::getSupportedServiceNames_static() 224cdf0e10cSrcweir { 225cdf0e10cSrcweir Sequence< rtl::OUString > seq( 2 ); 226cdf0e10cSrcweir seq[0] = rtl::OUString::createFromAscii( "com.sun.star.help.TreeView" ); 227cdf0e10cSrcweir seq[1] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HiearchyDataSource" ); 228cdf0e10cSrcweir return seq; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir 232cdf0e10cSrcweir Reference< XSingleServiceFactory > SAL_CALL 233cdf0e10cSrcweir TVFactory::createServiceFactory( 234cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rxServiceMgr ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir return Reference< XSingleServiceFactory > ( 237cdf0e10cSrcweir cppu::createSingleFactory( 238cdf0e10cSrcweir rxServiceMgr, 239cdf0e10cSrcweir TVFactory::getImplementationName_static(), 240cdf0e10cSrcweir TVFactory::CreateInstance, 241cdf0e10cSrcweir TVFactory::getSupportedServiceNames_static() ) ); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir 245cdf0e10cSrcweir 246cdf0e10cSrcweir Reference< XInterface > SAL_CALL 247cdf0e10cSrcweir TVFactory::CreateInstance( 248cdf0e10cSrcweir const Reference< XMultiServiceFactory >& xMultiServiceFactory ) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir XServiceInfo* xP = (XServiceInfo*) new TVFactory( xMultiServiceFactory ); 251cdf0e10cSrcweir return Reference< XInterface >::query( xP ); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir //========================================================================= 255*e4ed64deSDamjan Jovanovic extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( 256cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir (void)ppEnv; 259cdf0e10cSrcweir 260cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 261cdf0e10cSrcweir } 262cdf0e10cSrcweir 263cdf0e10cSrcweir //========================================================================= 264*e4ed64deSDamjan Jovanovic extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( 265cdf0e10cSrcweir const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey ) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir (void)pRegistryKey; 268cdf0e10cSrcweir 269cdf0e10cSrcweir void * pRet = 0; 270cdf0e10cSrcweir 271cdf0e10cSrcweir Reference< XMultiServiceFactory > xSMgr( 272cdf0e10cSrcweir reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) ); 273cdf0e10cSrcweir 274cdf0e10cSrcweir Reference< XSingleServiceFactory > xFactory; 275cdf0e10cSrcweir 276cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 277cdf0e10cSrcweir // File Content Provider. 278cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 279cdf0e10cSrcweir 280cdf0e10cSrcweir if ( TVFactory::getImplementationName_static().compareToAscii( pImplName ) == 0 ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir xFactory = TVFactory::createServiceFactory( xSMgr ); 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 286cdf0e10cSrcweir 287cdf0e10cSrcweir if ( xFactory.is() ) 288cdf0e10cSrcweir { 289cdf0e10cSrcweir xFactory->acquire(); 290cdf0e10cSrcweir pRet = xFactory.get(); 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir return pRet; 294cdf0e10cSrcweir } 295