Update ooo320-m1
[ooovba.git] / odk / examples / cpp / complextoolbarcontrols / exports.cxx
blobb71e939d044491858a2a259ea3f778abcc518d1e
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: exports.cxx,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
32 #include <stdio.h>
34 #include <osl/mutex.hxx>
35 #include <osl/thread.h>
36 #include <cppuhelper/factory.hxx>
37 #include <rtl/ustring.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <sal/types.h>
40 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
42 #include "MyProtocolHandler.h"
43 #include "MyListener.h"
45 namespace css = ::com::sun::star;
47 static void writeInfo(const css::uno::Reference< css::registry::XRegistryKey >& xRegistryKey ,
48 const char* pImplementationName,
49 const char* pServiceName )
51 ::rtl::OUStringBuffer sKey(256);
52 sKey.append (::rtl::OUString::createFromAscii(pImplementationName));
53 sKey.appendAscii("/UNO/SERVICES/");
54 sKey.append (::rtl::OUString::createFromAscii(pServiceName));
56 xRegistryKey->createKey(sKey.makeStringAndClear());
59 extern "C"
61 //==================================================================================================
62 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char** ppEnvTypeName,
63 uno_Environment** ppEnv )
65 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
68 //==================================================================================================
69 SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void* pServiceManager,
70 void* pRegistryKey )
72 if (!pRegistryKey)
73 return sal_False;
75 try
77 css::uno::Reference< css::registry::XRegistryKey > xKey(reinterpret_cast< css::registry::XRegistryKey* >(pRegistryKey), css::uno::UNO_QUERY);
79 writeInfo( xKey, MYLISTENER_IMPLEMENTATIONNAME , MYLISTENER_SERVICENAME );
80 writeInfo( xKey, MYPROTOCOLHANDLER_IMPLEMENTATIONNAME, MYPROTOCOLHANDLER_SERVICENAME );
82 return sal_True;
84 catch(const css::registry::InvalidRegistryException&)
85 { OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); }
87 return sal_False;
90 //==================================================================================================
91 SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(const sal_Char* pImplName ,
92 void* pServiceManager,
93 void* pRegistryKey )
95 if ( !pServiceManager || !pImplName )
96 return 0;
98 css::uno::Reference< css::lang::XSingleServiceFactory > xFactory ;
99 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR (reinterpret_cast< css::lang::XMultiServiceFactory* >(pServiceManager), css::uno::UNO_QUERY);
100 ::rtl::OUString sImplName = ::rtl::OUString::createFromAscii(pImplName);
102 if (sImplName.equalsAscii(MYLISTENER_IMPLEMENTATIONNAME))
104 css::uno::Sequence< ::rtl::OUString > lNames(1);
105 lNames[0] = ::rtl::OUString::createFromAscii(MYLISTENER_IMPLEMENTATIONNAME);
106 xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, MyListener::st_createInstance, lNames);
108 else
109 if (sImplName.equalsAscii(MYPROTOCOLHANDLER_IMPLEMENTATIONNAME))
111 css::uno::Sequence< ::rtl::OUString > lNames(1);
112 lNames[0] = ::rtl::OUString::createFromAscii(MYPROTOCOLHANDLER_SERVICENAME);
113 xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, MyProtocolHandler_createInstance, lNames);
116 if (!xFactory.is())
117 return 0;
119 xFactory->acquire();
120 return xFactory.get();
123 } // extern C