1*b557fc96SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b557fc96SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b557fc96SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b557fc96SAndrew Rist * distributed with this work for additional information
6*b557fc96SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b557fc96SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b557fc96SAndrew Rist * "License"); you may not use this file except in compliance
9*b557fc96SAndrew Rist * with the License. You may obtain a copy of the License at
10*b557fc96SAndrew Rist *
11*b557fc96SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b557fc96SAndrew Rist *
13*b557fc96SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b557fc96SAndrew Rist * software distributed under the License is distributed on an
15*b557fc96SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b557fc96SAndrew Rist * KIND, either express or implied. See the License for the
17*b557fc96SAndrew Rist * specific language governing permissions and limitations
18*b557fc96SAndrew Rist * under the License.
19*b557fc96SAndrew Rist *
20*b557fc96SAndrew Rist *************************************************************/
21*b557fc96SAndrew Rist
22*b557fc96SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_fpicker.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir //------------------------------------------------------------------------
28cdf0e10cSrcweir // includes
29cdf0e10cSrcweir //------------------------------------------------------------------------
30cdf0e10cSrcweir
31cdf0e10cSrcweir #ifndef _WINDIRBROWSEIMPL_HXX_
32cdf0e10cSrcweir #include "WinFOPImpl.hxx"
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #include <osl/diagnose.h>
35cdf0e10cSrcweir #include <com/sun/star/lang/EventObject.hpp>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_FILEDIALOGRESULTS_HPP_
38cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
39cdf0e10cSrcweir #endif
40cdf0e10cSrcweir #include "FopEvtDisp.hxx"
41cdf0e10cSrcweir #include <osl/file.hxx>
42cdf0e10cSrcweir #include "FolderPicker.hxx"
43cdf0e10cSrcweir
44cdf0e10cSrcweir //------------------------------------------------------------------------
45cdf0e10cSrcweir // namespace directives
46cdf0e10cSrcweir //------------------------------------------------------------------------
47cdf0e10cSrcweir
48cdf0e10cSrcweir using com::sun::star::uno::RuntimeException;
49cdf0e10cSrcweir using com::sun::star::lang::IllegalArgumentException;
50cdf0e10cSrcweir using com::sun::star::lang::EventObject;
51cdf0e10cSrcweir using rtl::OUString;
52cdf0e10cSrcweir
53cdf0e10cSrcweir using namespace com::sun::star::ui::dialogs;
54cdf0e10cSrcweir using osl::FileBase;
55cdf0e10cSrcweir
56cdf0e10cSrcweir //------------------------------------------------------------------------
57cdf0e10cSrcweir //
58cdf0e10cSrcweir //------------------------------------------------------------------------
59cdf0e10cSrcweir
60cdf0e10cSrcweir const OUString BACKSLASH = OUString::createFromAscii( "\\" );
61cdf0e10cSrcweir
62cdf0e10cSrcweir //------------------------------------------------------------------------
63cdf0e10cSrcweir // ctor
64cdf0e10cSrcweir //------------------------------------------------------------------------
65cdf0e10cSrcweir
CWinFolderPickerImpl(CFolderPicker * aFolderPicker)66cdf0e10cSrcweir CWinFolderPickerImpl::CWinFolderPickerImpl( CFolderPicker* aFolderPicker ) :
67cdf0e10cSrcweir CMtaFolderPicker( BIF_RETURNONLYFSDIRS | BIF_RETURNFSANCESTORS | BIF_EDITBOX | BIF_VALIDATE ),
68cdf0e10cSrcweir m_pFolderPicker( aFolderPicker ),
69cdf0e10cSrcweir m_nLastDlgResult( ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
73cdf0e10cSrcweir //------------------------------------------------------------------------
74cdf0e10cSrcweir // get directory in URL format, convert it to system format and set the
75cdf0e10cSrcweir // member variable
76cdf0e10cSrcweir // If the given URL for the directory is invalid the function throws an
77cdf0e10cSrcweir // IllegalArgumentException
78cdf0e10cSrcweir // If the specified path is well formed but invalid for the underlying
79cdf0e10cSrcweir // OS the FolderPicker starts in the root of the file system hierarchie
80cdf0e10cSrcweir //------------------------------------------------------------------------
81cdf0e10cSrcweir
setDisplayDirectory(const OUString & aDirectory)82cdf0e10cSrcweir void SAL_CALL CWinFolderPickerImpl::setDisplayDirectory( const OUString& aDirectory )
83cdf0e10cSrcweir throw( IllegalArgumentException, RuntimeException )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir OUString sysDir;
86cdf0e10cSrcweir
87cdf0e10cSrcweir if( aDirectory.getLength( ) )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir // assuming that this function succeeds after successful execution
90cdf0e10cSrcweir // of getAbsolutePath
91cdf0e10cSrcweir ::osl::FileBase::RC rc =
92cdf0e10cSrcweir ::osl::FileBase::getSystemPathFromFileURL( aDirectory, sysDir );
93cdf0e10cSrcweir
94cdf0e10cSrcweir if ( ::osl::FileBase::E_None != rc )
95cdf0e10cSrcweir throw IllegalArgumentException(
96cdf0e10cSrcweir OUString::createFromAscii( "directory is not a valid file url" ),
97cdf0e10cSrcweir static_cast< XFolderPicker* >( m_pFolderPicker ),
98cdf0e10cSrcweir 1 );
99cdf0e10cSrcweir
100cdf0e10cSrcweir // we ensure that there is a trailing '/' at the end of
101cdf0e10cSrcweir // he given file url, because the windows functions only
102cdf0e10cSrcweir // works correctly when providing "c:\" or an environment
103cdf0e10cSrcweir // variable like "=c:=c:\.." etc. is set, else the
104cdf0e10cSrcweir // FolderPicker would stand in the root of the shell
105cdf0e10cSrcweir // hierarchie which is the desktop folder
106cdf0e10cSrcweir if ( sysDir.lastIndexOf( BACKSLASH ) != (sysDir.getLength( ) - 1) )
107cdf0e10cSrcweir sysDir += BACKSLASH;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir // call base class method
111cdf0e10cSrcweir CMtaFolderPicker::setDisplayDirectory( sysDir );
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114cdf0e10cSrcweir //------------------------------------------------------------------------
115cdf0e10cSrcweir // we return the directory in URL format
116cdf0e10cSrcweir //------------------------------------------------------------------------
117cdf0e10cSrcweir
getDisplayDirectory()118cdf0e10cSrcweir OUString CWinFolderPickerImpl::getDisplayDirectory( )
119cdf0e10cSrcweir throw( RuntimeException )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir // call base class method to get the directory in system format
122cdf0e10cSrcweir OUString displayDirectory = CMtaFolderPicker::getDisplayDirectory( );
123cdf0e10cSrcweir
124cdf0e10cSrcweir OUString displayDirectoryURL;
125cdf0e10cSrcweir if ( displayDirectory.getLength( ) )
126cdf0e10cSrcweir ::osl::FileBase::getFileURLFromSystemPath( displayDirectory, displayDirectoryURL );
127cdf0e10cSrcweir
128cdf0e10cSrcweir return displayDirectoryURL;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir //------------------------------------------------------------------------
132cdf0e10cSrcweir //
133cdf0e10cSrcweir //------------------------------------------------------------------------
134cdf0e10cSrcweir
getDirectory()135cdf0e10cSrcweir OUString SAL_CALL CWinFolderPickerImpl::getDirectory( ) throw( RuntimeException )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir OUString sysDir = CMtaFolderPicker::getDirectory( );
138cdf0e10cSrcweir OUString dirURL;
139cdf0e10cSrcweir
140cdf0e10cSrcweir if ( sysDir.getLength( ) )
141cdf0e10cSrcweir ::osl::FileBase::getFileURLFromSystemPath( sysDir, dirURL );
142cdf0e10cSrcweir
143cdf0e10cSrcweir return dirURL;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir
146cdf0e10cSrcweir //------------------------------------------------------------------------
147cdf0e10cSrcweir //
148cdf0e10cSrcweir //------------------------------------------------------------------------
149cdf0e10cSrcweir
execute()150cdf0e10cSrcweir sal_Int16 SAL_CALL CWinFolderPickerImpl::execute( ) throw( RuntimeException )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir return m_nLastDlgResult = CMtaFolderPicker::browseForFolder( ) ?
153cdf0e10cSrcweir ::com::sun::star::ui::dialogs::ExecutableDialogResults::OK :
154cdf0e10cSrcweir ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir
157cdf0e10cSrcweir //---------------------------------------------------------------------
158cdf0e10cSrcweir //
159cdf0e10cSrcweir //---------------------------------------------------------------------
160cdf0e10cSrcweir
onSelChanged(const OUString & aNewPath)161cdf0e10cSrcweir void CWinFolderPickerImpl::onSelChanged( const OUString& aNewPath )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir setStatusText( aNewPath );
164cdf0e10cSrcweir }
165