update dev300-m58
[ooovba.git] / fpicker / source / office / OfficeFolderPicker.cxx
blob090aed73b0b208d40ebc50963d3d89bf791da0e4
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: OfficeFolderPicker.cxx,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_fpicker.hxx"
34 #include "OfficeFolderPicker.hxx"
36 #include "iodlg.hxx"
38 #include <list>
39 #include <tools/urlobj.hxx>
41 #define _SVSTDARR_STRINGSDTOR
42 #include "svtools/svstdarr.hxx"
43 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
44 #include <com/sun/star/container/XSet.hpp>
45 #include <com/sun/star/uno/Any.hxx>
46 #include <cppuhelper/factory.hxx>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <svtools/pathoptions.hxx>
50 // using ----------------------------------------------------------------
52 using namespace ::com::sun::star::container;
53 using namespace ::com::sun::star::lang;
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::beans;
57 //------------------------------------------------------------------------------------
58 // class SvtFolderPicker
59 //------------------------------------------------------------------------------------
61 //------------------------------------------------------------------------------------
62 SvtFolderPicker::SvtFolderPicker( const Reference < XMultiServiceFactory >& _rxFactory )
63 :OCommonPicker( _rxFactory )
67 //------------------------------------------------------------------------------------
68 SvtFolderPicker::~SvtFolderPicker()
72 //------------------------------------------------------------------------------------
73 // disambiguate XInterface
74 //------------------------------------------------------------------------------------
75 IMPLEMENT_FORWARD_XINTERFACE2( SvtFolderPicker, OCommonPicker, SvtFolderPicker_Base )
77 //------------------------------------------------------------------------------------
78 // disambiguate XTypeProvider
79 //------------------------------------------------------------------------------------
80 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvtFolderPicker, OCommonPicker, SvtFolderPicker_Base )
82 //------------------------------------------------------------------------------------
83 // XExecutableDialog functions
84 //------------------------------------------------------------------------------------
86 //------------------------------------------------------------------------------------
87 void SAL_CALL SvtFolderPicker::setTitle( const ::rtl::OUString& _rTitle ) throw (RuntimeException)
89 OCommonPicker::setTitle( _rTitle );
92 //------------------------------------------------------------------------------------
93 sal_Int16 SAL_CALL SvtFolderPicker::execute( ) throw (RuntimeException)
95 return OCommonPicker::execute();
98 //------------------------------------------------------------------------------------
99 // XAsynchronousExecutableDialog functions
100 //------------------------------------------------------------------------------------
102 //------------------------------------------------------------------------------------
103 void SAL_CALL SvtFolderPicker::setDialogTitle( const ::rtl::OUString& _rTitle) throw (RuntimeException)
105 setTitle( _rTitle );
108 //------------------------------------------------------------------------------------
109 void SAL_CALL SvtFolderPicker::startExecuteModal( const Reference< ::com::sun::star::ui::dialogs::XDialogClosedListener >& xListener ) throw (RuntimeException)
111 m_xListener = xListener;
112 prepareDialog();
113 prepareExecute();
114 getDialog()->EnableAutocompletion( TRUE );
115 getDialog()->StartExecuteModal( LINK( this, SvtFolderPicker, DialogClosedHdl ) );
118 //------------------------------------------------------------------------------------
119 SvtFileDialog* SvtFolderPicker::implCreateDialog( Window* _pParent )
121 return new SvtFileDialog( _pParent, SFXWB_PATHDIALOG );
124 //------------------------------------------------------------------------------------
125 sal_Int16 SvtFolderPicker::implExecutePicker( )
127 prepareExecute();
129 // now we are ready to execute the dialog
130 getDialog()->EnableAutocompletion( FALSE );
131 sal_Int16 nRet = getDialog()->Execute();
133 return nRet;
136 //------------------------------------------------------------------------------------
137 void SvtFolderPicker::prepareExecute()
139 // set the default directory
140 if ( m_aDisplayDirectory.getLength() > 0 )
141 getDialog()->SetPath( m_aDisplayDirectory );
142 else
144 // Default-Standard-Dir setzen
145 INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
146 getDialog()->SetPath( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE) );
150 //-----------------------------------------------------------------------------
151 IMPL_LINK( SvtFolderPicker, DialogClosedHdl, Dialog*, pDlg )
153 if ( m_xListener.is() )
155 sal_Int16 nRet = static_cast< sal_Int16 >( pDlg->GetResult() );
156 ::com::sun::star::ui::dialogs::DialogClosedEvent aEvent( *this, nRet );
157 m_xListener->dialogClosed( aEvent );
158 m_xListener.clear();
160 return 0;
163 //------------------------------------------------------------------------------------
164 // XFolderPicker functions
165 //------------------------------------------------------------------------------------
167 void SAL_CALL SvtFolderPicker::setDisplayDirectory( const ::rtl::OUString& aDirectory )
168 throw( IllegalArgumentException, RuntimeException )
170 m_aDisplayDirectory = aDirectory;
173 //------------------------------------------------------------------------------------
174 ::rtl::OUString SAL_CALL SvtFolderPicker::getDisplayDirectory() throw( RuntimeException )
176 ::rtl::OUString aResult;
178 if ( ! getDialog() )
179 return m_aDisplayDirectory;
181 SvStringsDtor* pPathList = getDialog()->GetPathList();
183 if ( pPathList->Count() )
184 aResult = ::rtl::OUString( *pPathList->GetObject( 0 ) );
186 delete pPathList;
188 return aResult;
191 //------------------------------------------------------------------------------------
192 ::rtl::OUString SAL_CALL SvtFolderPicker::getDirectory() throw( RuntimeException )
194 ::rtl::OUString aResult;
196 if ( ! getDialog() )
197 return m_aDisplayDirectory;
199 SvStringsDtor* pPathList = getDialog()->GetPathList();
201 if ( pPathList->Count() )
202 aResult = ::rtl::OUString( *pPathList->GetObject( 0 ) );
204 delete pPathList;
206 return aResult;
209 //------------------------------------------------------------------------------------
210 void SAL_CALL SvtFolderPicker::setDescription( const ::rtl::OUString& aDescription )
211 throw( RuntimeException )
213 m_aDescription = aDescription;
216 //------------------------------------------------------------------------------------
217 // XServiceInfo
218 //------------------------------------------------------------------------------------
220 /* XServiceInfo */
221 ::rtl::OUString SAL_CALL SvtFolderPicker::getImplementationName() throw( RuntimeException )
223 return impl_getStaticImplementationName();
226 /* XServiceInfo */
227 sal_Bool SAL_CALL SvtFolderPicker::supportsService( const ::rtl::OUString& sServiceName ) throw( RuntimeException )
229 Sequence< ::rtl::OUString > seqServiceNames = getSupportedServiceNames();
230 const ::rtl::OUString* pArray = seqServiceNames.getConstArray();
231 for ( sal_Int32 i = 0; i < seqServiceNames.getLength(); i++ )
233 if ( sServiceName == pArray[i] )
235 return sal_True ;
238 return sal_False ;
241 /* XServiceInfo */
242 Sequence< ::rtl::OUString > SAL_CALL SvtFolderPicker::getSupportedServiceNames() throw( RuntimeException )
244 return impl_getStaticSupportedServiceNames();
247 /* Helper for XServiceInfo */
248 Sequence< ::rtl::OUString > SvtFolderPicker::impl_getStaticSupportedServiceNames()
250 Sequence< ::rtl::OUString > seqServiceNames(1);
251 seqServiceNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.OfficeFolderPicker" );
252 return seqServiceNames ;
255 /* Helper for XServiceInfo */
256 ::rtl::OUString SvtFolderPicker::impl_getStaticImplementationName()
258 return ::rtl::OUString::createFromAscii( "com.sun.star.svtools.OfficeFolderPicker" );
261 /* Helper for registry */
262 Reference< XInterface > SAL_CALL SvtFolderPicker::impl_createInstance( const Reference< XComponentContext >& rxContext )
263 throw( Exception )
265 Reference< XMultiServiceFactory > xServiceManager (rxContext->getServiceManager(), UNO_QUERY_THROW);
266 return Reference< XInterface >( *new SvtFolderPicker( xServiceManager ) );