1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "WinFOPImpl.hxx"
21 #include <osl/diagnose.h>
22 #include <com/sun/star/lang/EventObject.hpp>
24 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
25 #include "FopEvtDisp.hxx"
26 #include <osl/file.hxx>
27 #include "FolderPicker.hxx"
30 // namespace directives
33 using com::sun::star::uno::RuntimeException
;
34 using com::sun::star::lang::IllegalArgumentException
;
35 using com::sun::star::lang::EventObject
;
37 using namespace com::sun::star::ui::dialogs
;
44 const OUString
BACKSLASH( "\\" );
50 CWinFolderPickerImpl::CWinFolderPickerImpl( CFolderPicker
* aFolderPicker
) :
51 CMtaFolderPicker( BIF_RETURNONLYFSDIRS
| BIF_RETURNFSANCESTORS
| BIF_EDITBOX
| BIF_VALIDATE
),
52 m_pFolderPicker( aFolderPicker
),
53 m_nLastDlgResult( ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL
)
58 // get directory in URL format, convert it to system format and set the
60 // If the given URL for the directory is invalid the function throws an
61 // IllegalArgumentException
62 // If the specified path is well formed but invalid for the underlying
63 // OS the FolderPicker starts in the root of the file system hierarchy
66 void SAL_CALL
CWinFolderPickerImpl::setDisplayDirectory( const OUString
& aDirectory
)
67 throw( IllegalArgumentException
, RuntimeException
)
71 if( aDirectory
.getLength( ) )
73 // assuming that this function succeeds after successful execution
75 ::osl::FileBase::RC rc
=
76 ::osl::FileBase::getSystemPathFromFileURL( aDirectory
, sysDir
);
78 if ( ::osl::FileBase::E_None
!= rc
)
79 throw IllegalArgumentException(
80 "directory is not a valid file url",
81 static_cast< cppu::OWeakObject
* >( m_pFolderPicker
),
84 // we ensure that there is a trailing '/' at the end of
85 // he given file url, because the windows functions only
86 // works correctly when providing "c:\" or an environment
87 // variable like "=c:=c:\.." etc. is set, else the
88 // FolderPicker would stand in the root of the shell
89 // hierarchy which is the desktop folder
90 if ( sysDir
.lastIndexOf( BACKSLASH
) != (sysDir
.getLength( ) - 1) )
94 // call base class method
95 CMtaFolderPicker::setDisplayDirectory( sysDir
);
99 // we return the directory in URL format
102 OUString
CWinFolderPickerImpl::getDisplayDirectory( )
103 throw( RuntimeException
)
105 // call base class method to get the directory in system format
106 OUString displayDirectory
= CMtaFolderPicker::getDisplayDirectory( );
108 OUString displayDirectoryURL
;
109 if ( displayDirectory
.getLength( ) )
110 ::osl::FileBase::getFileURLFromSystemPath( displayDirectory
, displayDirectoryURL
);
112 return displayDirectoryURL
;
119 OUString SAL_CALL
CWinFolderPickerImpl::getDirectory( ) throw( RuntimeException
)
121 OUString sysDir
= CMtaFolderPicker::getDirectory( );
124 if ( sysDir
.getLength( ) )
125 ::osl::FileBase::getFileURLFromSystemPath( sysDir
, dirURL
);
134 sal_Int16 SAL_CALL
CWinFolderPickerImpl::execute( ) throw( RuntimeException
)
136 return m_nLastDlgResult
= CMtaFolderPicker::browseForFolder( ) ?
137 ::com::sun::star::ui::dialogs::ExecutableDialogResults::OK
:
138 ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL
;
145 void CWinFolderPickerImpl::onSelChanged( const OUString
& aNewPath
)
147 setStatusText( aNewPath
);
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */