xref: /AOO41X/main/xmlhelp/source/treeview/tvfactory.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
30*cdf0e10cSrcweir #include "precompiled_xmlhelp.hxx"
31*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
34*cdf0e10cSrcweir #include "tvfactory.hxx"
35*cdf0e10cSrcweir #include "tvread.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir using namespace treeview;
39*cdf0e10cSrcweir using namespace com::sun::star;
40*cdf0e10cSrcweir using namespace com::sun::star::uno;
41*cdf0e10cSrcweir using namespace com::sun::star::lang;
42*cdf0e10cSrcweir using namespace com::sun::star::beans;
43*cdf0e10cSrcweir using namespace com::sun::star::container;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir TVFactory::TVFactory( const uno::Reference< XMultiServiceFactory >& xMSF )
48*cdf0e10cSrcweir 	: m_xMSF( xMSF )
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir }
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir TVFactory::~TVFactory()
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir }
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
59*cdf0e10cSrcweir // XInterface
60*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir void SAL_CALL
63*cdf0e10cSrcweir TVFactory::acquire(
64*cdf0e10cSrcweir 	void )
65*cdf0e10cSrcweir 	throw()
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir   OWeakObject::acquire();
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir void SAL_CALL
72*cdf0e10cSrcweir TVFactory::release(
73*cdf0e10cSrcweir 		      void )
74*cdf0e10cSrcweir   throw()
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir   OWeakObject::release();
77*cdf0e10cSrcweir }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir Any SAL_CALL
81*cdf0e10cSrcweir TVFactory::queryInterface(
82*cdf0e10cSrcweir 	const Type& rType )
83*cdf0e10cSrcweir 	throw( RuntimeException )
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir 	Any aRet = cppu::queryInterface( rType,
86*cdf0e10cSrcweir 									 SAL_STATIC_CAST( XServiceInfo*,  this ),
87*cdf0e10cSrcweir 									 SAL_STATIC_CAST( XTypeProvider*, this ),
88*cdf0e10cSrcweir 									 SAL_STATIC_CAST( XMultiServiceFactory*, this ) );
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
95*cdf0e10cSrcweir //
96*cdf0e10cSrcweir // XTypeProvider methods.
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( TVFactory,
99*cdf0e10cSrcweir 				   	  XServiceInfo,
100*cdf0e10cSrcweir 				   	  XTypeProvider,
101*cdf0e10cSrcweir 				   	  XMultiServiceFactory );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir // XServiceInfo methods.
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir rtl::OUString SAL_CALL
110*cdf0e10cSrcweir TVFactory::getImplementationName()
111*cdf0e10cSrcweir 	throw( RuntimeException )
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir 	return TVFactory::getImplementationName_static();
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir sal_Bool SAL_CALL
118*cdf0e10cSrcweir TVFactory::supportsService(
119*cdf0e10cSrcweir 	const rtl::OUString& ServiceName )
120*cdf0e10cSrcweir 	throw( RuntimeException )
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir 	return
123*cdf0e10cSrcweir 		ServiceName.compareToAscii( "com.sun.star.help.TreeView" ) == 0 ||
124*cdf0e10cSrcweir 		ServiceName.compareToAscii( "com.sun.star.ucb.HiearchyDataSource" ) == 0;
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir Sequence< rtl::OUString > SAL_CALL
129*cdf0e10cSrcweir TVFactory::getSupportedServiceNames( void )
130*cdf0e10cSrcweir 	throw( RuntimeException )
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir 	return TVFactory::getSupportedServiceNames_static();
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir // XMultiServiceFactory
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir Reference< XInterface > SAL_CALL
140*cdf0e10cSrcweir TVFactory::createInstance(
141*cdf0e10cSrcweir 	const rtl::OUString& aServiceSpecifier )
142*cdf0e10cSrcweir 	throw( Exception,
143*cdf0e10cSrcweir 		   RuntimeException )
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir 	Any aAny;
146*cdf0e10cSrcweir 	aAny <<= rtl::OUString();
147*cdf0e10cSrcweir 	Sequence< Any > seq( 1 );
148*cdf0e10cSrcweir 	seq[0] <<= PropertyValue(
149*cdf0e10cSrcweir 		rtl::OUString::createFromAscii( "nodepath" ),
150*cdf0e10cSrcweir 		-1,
151*cdf0e10cSrcweir 		aAny,
152*cdf0e10cSrcweir 		PropertyState_DIRECT_VALUE );
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 	return createInstanceWithArguments( aServiceSpecifier,
155*cdf0e10cSrcweir 										seq );
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir Reference< XInterface > SAL_CALL
160*cdf0e10cSrcweir TVFactory::createInstanceWithArguments(
161*cdf0e10cSrcweir 	const rtl::OUString& ServiceSpecifier,
162*cdf0e10cSrcweir 	const Sequence< Any >& Arguments )
163*cdf0e10cSrcweir 	throw( Exception,
164*cdf0e10cSrcweir 		   RuntimeException )
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	(void)ServiceSpecifier;
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	if( ! m_xHDS.is() )
169*cdf0e10cSrcweir 	{
170*cdf0e10cSrcweir 		cppu::OWeakObject* p = new TVChildTarget( m_xMSF );
171*cdf0e10cSrcweir 		m_xHDS = Reference< XInterface >( p );
172*cdf0e10cSrcweir 	}
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 	Reference< XInterface > ret = m_xHDS;
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	rtl::OUString hierview;
177*cdf0e10cSrcweir 	for( int i = 0; i < Arguments.getLength(); ++i )
178*cdf0e10cSrcweir 	{
179*cdf0e10cSrcweir 		PropertyValue pV;
180*cdf0e10cSrcweir 		if( ! ( Arguments[i] >>= pV ) )
181*cdf0e10cSrcweir 			continue;
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 		if( pV.Name.compareToAscii( "nodepath" ) )
184*cdf0e10cSrcweir 			continue;
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 		if( ! ( pV.Value >>= hierview ) )
187*cdf0e10cSrcweir 			continue;
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 		break;
190*cdf0e10cSrcweir 	}
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 	if( hierview.getLength() )
193*cdf0e10cSrcweir 	{
194*cdf0e10cSrcweir 		Reference< XHierarchicalNameAccess > xhieraccess( m_xHDS,UNO_QUERY );
195*cdf0e10cSrcweir 		Any aAny = xhieraccess->getByHierarchicalName( hierview );
196*cdf0e10cSrcweir 		Reference< XInterface > xInterface;
197*cdf0e10cSrcweir 		aAny >>= xInterface;
198*cdf0e10cSrcweir 		return xInterface;
199*cdf0e10cSrcweir 	}
200*cdf0e10cSrcweir 	else
201*cdf0e10cSrcweir 		return m_xHDS;
202*cdf0e10cSrcweir }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir Sequence< rtl::OUString > SAL_CALL
206*cdf0e10cSrcweir TVFactory::getAvailableServiceNames( )
207*cdf0e10cSrcweir 	throw( RuntimeException )
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir 	Sequence< rtl::OUString > seq( 1 );
210*cdf0e10cSrcweir 	seq[0] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HierarchyDataReadAccess" );
211*cdf0e10cSrcweir 	return seq;
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir // static
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir rtl::OUString SAL_CALL
220*cdf0e10cSrcweir TVFactory::getImplementationName_static()
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir 	return rtl::OUString::createFromAscii( "com.sun.star.help.TreeViewImpl" );
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir Sequence< rtl::OUString > SAL_CALL
227*cdf0e10cSrcweir TVFactory::getSupportedServiceNames_static()
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir 	Sequence< rtl::OUString > seq( 2 );
230*cdf0e10cSrcweir 	seq[0] = rtl::OUString::createFromAscii( "com.sun.star.help.TreeView" );
231*cdf0e10cSrcweir 	seq[1] = rtl::OUString::createFromAscii( "com.sun.star.ucb.HiearchyDataSource" );
232*cdf0e10cSrcweir 	return seq;
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir Reference< XSingleServiceFactory > SAL_CALL
237*cdf0e10cSrcweir TVFactory::createServiceFactory(
238*cdf0e10cSrcweir 	const Reference< XMultiServiceFactory >& rxServiceMgr )
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir 	return Reference< XSingleServiceFactory > (
241*cdf0e10cSrcweir 		cppu::createSingleFactory(
242*cdf0e10cSrcweir 			rxServiceMgr,
243*cdf0e10cSrcweir 			TVFactory::getImplementationName_static(),
244*cdf0e10cSrcweir 			TVFactory::CreateInstance,
245*cdf0e10cSrcweir 			TVFactory::getSupportedServiceNames_static() ) );
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir Reference< XInterface > SAL_CALL
251*cdf0e10cSrcweir TVFactory::CreateInstance(
252*cdf0e10cSrcweir 	const Reference< XMultiServiceFactory >& xMultiServiceFactory )
253*cdf0e10cSrcweir {
254*cdf0e10cSrcweir 	XServiceInfo* xP = (XServiceInfo*) new TVFactory( xMultiServiceFactory );
255*cdf0e10cSrcweir 	return Reference< XInterface >::query( xP );
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir //=========================================================================
259*cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment(
260*cdf0e10cSrcweir 	const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir 	(void)ppEnv;
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir //=========================================================================
268*cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory(
269*cdf0e10cSrcweir 	const sal_Char * pImplName,void * pServiceManager,void * pRegistryKey )
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir 	(void)pRegistryKey;
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 	void * pRet = 0;
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xSMgr(
276*cdf0e10cSrcweir 		reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir 	Reference< XSingleServiceFactory > xFactory;
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
281*cdf0e10cSrcweir 	// File Content Provider.
282*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 	if ( TVFactory::getImplementationName_static().compareToAscii( pImplName ) == 0 )
285*cdf0e10cSrcweir 	{
286*cdf0e10cSrcweir 		xFactory = TVFactory::createServiceFactory( xSMgr );
287*cdf0e10cSrcweir 	}
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 	if ( xFactory.is() )
292*cdf0e10cSrcweir 	{
293*cdf0e10cSrcweir 		xFactory->acquire();
294*cdf0e10cSrcweir 		pRet = xFactory.get();
295*cdf0e10cSrcweir 	}
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 	return pRet;
298*cdf0e10cSrcweir }
299