1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WinFOPImpl.cxx,v $
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 //------------------------------------------------------------------------
36 //------------------------------------------------------------------------
38 #ifndef _WINDIRBROWSEIMPL_HXX_
39 #include "WinFOPImpl.hxx"
41 #include <osl/diagnose.h>
42 #include <com/sun/star/lang/EventObject.hpp>
44 #ifndef _COM_SUN_STAR_UI_FILEDIALOGRESULTS_HPP_
45 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
47 #include "FopEvtDisp.hxx"
48 #include <osl/file.hxx>
49 #include "FolderPicker.hxx"
51 //------------------------------------------------------------------------
52 // namespace directives
53 //------------------------------------------------------------------------
55 using com::sun::star::uno::RuntimeException
;
56 using com::sun::star::lang::IllegalArgumentException
;
57 using com::sun::star::lang::EventObject
;
60 using namespace com::sun::star::ui::dialogs
;
63 //------------------------------------------------------------------------
65 //------------------------------------------------------------------------
67 const OUString BACKSLASH
= OUString::createFromAscii( "\\" );
69 //------------------------------------------------------------------------
71 //------------------------------------------------------------------------
73 CWinFolderPickerImpl::CWinFolderPickerImpl( CFolderPicker
* aFolderPicker
) :
74 CMtaFolderPicker( BIF_RETURNONLYFSDIRS
| BIF_RETURNFSANCESTORS
| BIF_EDITBOX
| BIF_VALIDATE
),
75 m_pFolderPicker( aFolderPicker
),
76 m_nLastDlgResult( ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL
)
80 //------------------------------------------------------------------------
81 // get directory in URL format, convert it to system format and set the
83 // If the given URL for the directory is invalid the function throws an
84 // IllegalArgumentException
85 // If the specified path is well formed but invalid for the underlying
86 // OS the FolderPicker starts in the root of the file system hierarchie
87 //------------------------------------------------------------------------
89 void SAL_CALL
CWinFolderPickerImpl::setDisplayDirectory( const OUString
& aDirectory
)
90 throw( IllegalArgumentException
, RuntimeException
)
94 if( aDirectory
.getLength( ) )
96 // assuming that this function succeeds after successful execution
98 ::osl::FileBase::RC rc
=
99 ::osl::FileBase::getSystemPathFromFileURL( aDirectory
, sysDir
);
101 if ( ::osl::FileBase::E_None
!= rc
)
102 throw IllegalArgumentException(
103 OUString::createFromAscii( "directory is not a valid file url" ),
104 static_cast< XFolderPicker
* >( m_pFolderPicker
),
107 // we ensure that there is a trailing '/' at the end of
108 // he given file url, because the windows functions only
109 // works correctly when providing "c:\" or an environment
110 // variable like "=c:=c:\.." etc. is set, else the
111 // FolderPicker would stand in the root of the shell
112 // hierarchie which is the desktop folder
113 if ( sysDir
.lastIndexOf( BACKSLASH
) != (sysDir
.getLength( ) - 1) )
117 // call base class method
118 CMtaFolderPicker::setDisplayDirectory( sysDir
);
121 //------------------------------------------------------------------------
122 // we return the directory in URL format
123 //------------------------------------------------------------------------
125 OUString
CWinFolderPickerImpl::getDisplayDirectory( )
126 throw( RuntimeException
)
128 // call base class method to get the directory in system format
129 OUString displayDirectory
= CMtaFolderPicker::getDisplayDirectory( );
131 OUString displayDirectoryURL
;
132 if ( displayDirectory
.getLength( ) )
133 ::osl::FileBase::getFileURLFromSystemPath( displayDirectory
, displayDirectoryURL
);
135 return displayDirectoryURL
;
138 //------------------------------------------------------------------------
140 //------------------------------------------------------------------------
142 OUString SAL_CALL
CWinFolderPickerImpl::getDirectory( ) throw( RuntimeException
)
144 OUString sysDir
= CMtaFolderPicker::getDirectory( );
147 if ( sysDir
.getLength( ) )
148 ::osl::FileBase::getFileURLFromSystemPath( sysDir
, dirURL
);
153 //------------------------------------------------------------------------
155 //------------------------------------------------------------------------
157 sal_Int16 SAL_CALL
CWinFolderPickerImpl::execute( ) throw( RuntimeException
)
159 return m_nLastDlgResult
= CMtaFolderPicker::browseForFolder( ) ?
160 ::com::sun::star::ui::dialogs::ExecutableDialogResults::OK
:
161 ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL
;
164 //---------------------------------------------------------------------
166 //---------------------------------------------------------------------
168 void CWinFolderPickerImpl::onSelChanged( const OUString
& aNewPath
)
170 setStatusText( aNewPath
);