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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_fpicker.hxx"
26 
27 //----------------------------------------------
28 //	includes of other projects
29 //----------------------------------------------
30 #include <cppuhelper/factory.hxx>
31 #include <com/sun/star/container/XSet.hpp>
32 #include <osl/diagnose.h>
33 #include "FilePicker.hxx"
34 #include "FPServiceInfo.hxx"
35 
36 #pragma warning (disable:4917)
37 #include "VistaFilePicker.hxx"
38 #include "..\misc\WinImplHelper.hxx"
39 #include <stdio.h>
40 
41 //-----------------------------------------------
42 // namespace directives
43 //-----------------------------------------------
44 
45 using namespace ::rtl						;
46 using namespace ::com::sun::star::uno		;
47 using namespace ::com::sun::star::container	;
48 using namespace ::com::sun::star::lang		;
49 using namespace ::com::sun::star::registry	;
50 using namespace ::cppu					    ;
51 using ::com::sun::star::ui::dialogs::XFilePicker;
52 using ::com::sun::star::ui::dialogs::XFilePicker2;
53 
54 //------------------------------------------------
55 //
56 //------------------------------------------------
57 
createInstance(const Reference<XMultiServiceFactory> & rServiceManager)58 static Reference< XInterface > SAL_CALL createInstance(
59 	const Reference< XMultiServiceFactory >& rServiceManager )
60 {
61 	Reference< XInterface > xDlg;
62 	bool					bVistaOrNewer = IsWindowsVistaOrNewer();
63 
64 	if (bVistaOrNewer)
65 	{
66         OSL_TRACE("use special (vista) system file picker ...");
67 		xDlg.set(
68 			static_cast< XFilePicker2* >(
69 				new ::fpicker::win32::vista::VistaFilePicker( rServiceManager ) ) );
70 	}
71 	else
72 	{
73         OSL_TRACE("use normal system file picker ...");
74 		xDlg.set(
75 			static_cast< XFilePicker2* >(
76 				new CFilePicker( rServiceManager ) ) );
77 	}
78 
79 	return xDlg;
80 }
81 
82 //------------------------------------------------
83 // the three uno functions that will be exported
84 //------------------------------------------------
85 
86 extern "C"
87 {
88 
89 //------------------------------------------------
90 // component_getImplementationEnvironment
91 //------------------------------------------------
92 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)93 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
94 	const sal_Char ** ppEnvTypeName, uno_Environment ** )
95 {
96 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
97 }
98 
99 //------------------------------------------------
100 //
101 //------------------------------------------------
102 
component_getFactory(const sal_Char * pImplName,uno_Interface * pSrvManager,uno_Interface *)103 SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
104 	const sal_Char* pImplName, uno_Interface* pSrvManager, uno_Interface* )
105 {
106 	void* pRet = 0;
107 
108 	if ( pSrvManager && ( 0 == rtl_str_compare( pImplName, FILE_PICKER_IMPL_NAME ) ) )
109 	{
110 		Sequence< OUString > aSNS( 1 );
111 		aSNS.getArray( )[0] = OUString::createFromAscii( FILE_PICKER_SERVICE_NAME );
112 
113 		Reference< XSingleServiceFactory > xFactory ( createSingleFactory(
114 			reinterpret_cast< XMultiServiceFactory* > ( pSrvManager ),
115 			OUString::createFromAscii( pImplName ),
116 			createInstance,
117 			aSNS ) );
118 		if ( xFactory.is() )
119 		{
120 			xFactory->acquire();
121 			pRet = xFactory.get();
122 		}
123 	}
124 
125 	return pRet;
126 }
127 
128 } // extern "C"
129