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 .
21 #include "OfficeFilePicker.hxx"
23 #include "RemoteFilesDialog.hxx"
28 #include <tools/urlobj.hxx>
29 #include <com/sun/star/uno/Any.hxx>
30 #include <com/sun/star/ui/dialogs/FilePickerEvent.hpp>
31 #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
32 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
33 #include <com/sun/star/beans/PropertyValue.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/awt/XWindow.hpp>
36 #include <com/sun/star/beans/StringPair.hpp>
37 #include <com/sun/star/uno/Sequence.hxx>
38 #include <com/sun/star/beans/NamedValue.hpp>
39 #include <unotools/ucbhelper.hxx>
40 #include <unotools/pathoptions.hxx>
41 #include <comphelper/sequence.hxx>
42 #include <cppuhelper/supportsservice.hxx>
43 #include <cppuhelper/typeprovider.hxx>
44 #include "osl/mutex.hxx"
45 #include <vcl/svapp.hxx>
47 using namespace ::com::sun::star::container
;
48 using namespace ::com::sun::star::lang
;
49 using namespace ::com::sun::star::ui::dialogs
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::beans
;
52 using namespace ::com::sun::star::awt
;
53 using namespace ::utl
;
62 UnoFilterList m_aSubFilters
;
65 FilterEntry( const OUString
& _rTitle
, const OUString
& _rFilter
)
67 ,m_sFilter( _rFilter
)
71 FilterEntry( const OUString
& _rTitle
, const UnoFilterList
& _rSubFilters
);
73 const OUString
& getTitle() const { return m_sTitle
; }
74 const OUString
& getFilter() const { return m_sFilter
; }
76 /// determines if the filter has sub filter (i.e., the filter is a filter group in real)
77 bool hasSubFilters( ) const;
79 /** retrieves the filters belonging to the entry
81 void getSubFilters( UnoFilterList
& _rSubFilterList
);
83 // helpers for iterating the sub filters
84 const UnoFilterEntry
* beginSubFilters() const { return m_aSubFilters
.getConstArray(); }
85 const UnoFilterEntry
* endSubFilters() const { return m_aSubFilters
.getConstArray() + m_aSubFilters
.getLength(); }
89 FilterEntry::FilterEntry( const OUString
& _rTitle
, const UnoFilterList
& _rSubFilters
)
91 ,m_aSubFilters( _rSubFilters
)
96 bool FilterEntry::hasSubFilters( ) const
98 return ( 0 < m_aSubFilters
.getLength() );
102 void FilterEntry::getSubFilters( UnoFilterList
& _rSubFilterList
)
104 _rSubFilterList
= m_aSubFilters
;
107 struct ElementEntry_Impl
109 sal_Int16 m_nElementID
;
110 sal_Int16 m_nControlAction
;
115 bool m_bHasValue
: 1;
116 bool m_bHasLabel
: 1;
117 bool m_bHasEnabled
: 1;
119 explicit ElementEntry_Impl( sal_Int16 nId
);
121 void setValue( const Any
& rVal
) { m_aValue
= rVal
; m_bHasValue
= true; }
122 void setAction( sal_Int16 nAction
) { m_nControlAction
= nAction
; }
123 void setLabel( const OUString
& rVal
) { m_aLabel
= rVal
; m_bHasLabel
= true; }
124 void setEnabled( bool bEnabled
) { m_bEnabled
= bEnabled
; m_bHasEnabled
= true; }
127 ElementEntry_Impl::ElementEntry_Impl( sal_Int16 nId
)
128 : m_nElementID( nId
)
129 , m_nControlAction( 0 )
130 , m_bEnabled( false )
131 , m_bHasValue( false )
132 , m_bHasLabel( false )
133 , m_bHasEnabled( false )
137 void SvtFilePicker::prepareExecute()
139 // set the default directory
140 // --**-- doesn't match the spec yet
141 if ( !m_aDisplayDirectory
.isEmpty() || !m_aDefaultName
.isEmpty() )
143 bool isFileSet
= false;
144 if ( !m_aDisplayDirectory
.isEmpty() )
148 INetURLObject
givenPath( m_aDisplayDirectory
);
149 if (!givenPath
.HasError())
153 INetURLObject
aStdDirObj( SvtPathOptions().GetWorkPath() );
156 if ( !m_aDefaultName
.isEmpty() )
158 aPath
.insertName( m_aDefaultName
);
159 getDialog()->SetHasFilename( true );
161 getDialog()->SetPath( aPath
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
164 if ( !isFileSet
&& !m_aDefaultName
.isEmpty() )
166 getDialog()->SetPath( m_aDefaultName
);
167 getDialog()->SetHasFilename( true );
172 // Default-Standard-Dir setzen
173 INetURLObject
aStdDirObj( SvtPathOptions().GetWorkPath() );
174 getDialog()->SetPath( aStdDirObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
177 // set the control values and set the control labels, too
178 if ( m_pElemList
&& !m_pElemList
->empty() )
180 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
182 ElementList::iterator aListIter
;
183 for ( aListIter
= m_pElemList
->begin();
184 aListIter
!= m_pElemList
->end(); ++aListIter
)
186 ElementEntry_Impl
& rEntry
= *aListIter
;
187 if ( rEntry
.m_bHasValue
)
188 aAccess
.setValue( rEntry
.m_nElementID
, rEntry
.m_nControlAction
, rEntry
.m_aValue
);
189 if ( rEntry
.m_bHasLabel
)
190 aAccess
.setLabel( rEntry
.m_nElementID
, rEntry
.m_aLabel
);
191 if ( rEntry
.m_bHasEnabled
)
192 aAccess
.enableControl( rEntry
.m_nElementID
, rEntry
.m_bEnabled
);
197 if ( m_pFilterList
&& !m_pFilterList
->empty() )
199 for ( FilterList::iterator aListIter
= m_pFilterList
->begin();
200 aListIter
!= m_pFilterList
->end();
204 if ( aListIter
->hasSubFilters() )
205 { // it's a filter group
206 UnoFilterList aSubFilters
;
207 aListIter
->getSubFilters( aSubFilters
);
209 getDialog()->AddFilterGroup( aListIter
->getTitle(), aSubFilters
);
212 // it's a single filter
213 getDialog()->AddFilter( aListIter
->getTitle(), aListIter
->getFilter() );
217 // set the default filter
218 if ( !m_aCurrentFilter
.isEmpty() )
219 getDialog()->SetCurFilter( m_aCurrentFilter
);
224 IMPL_LINK( SvtFilePicker
, DialogClosedHdl
, Dialog
&, rDlg
, void )
226 if ( m_xDlgClosedListener
.is() )
228 sal_Int16 nRet
= static_cast< sal_Int16
>( rDlg
.GetResult() );
229 css::ui::dialogs::DialogClosedEvent
aEvent( *this, nRet
);
230 m_xDlgClosedListener
->dialogClosed( aEvent
);
231 m_xDlgClosedListener
.clear();
239 PickerFlags
SvtFilePicker::getPickerFlags()
241 // set the winbits for creating the filedialog
242 PickerFlags nBits
= PickerFlags::NONE
;
244 // set the standard bits according to the service name
245 if ( m_nServiceType
== TemplateDescription::FILEOPEN_SIMPLE
)
247 nBits
= PickerFlags::Open
;
249 else if ( m_nServiceType
== TemplateDescription::FILESAVE_SIMPLE
)
251 nBits
= PickerFlags::SaveAs
;
253 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION
)
255 nBits
= PickerFlags::SaveAs
| PickerFlags::AutoExtension
;
257 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD
)
259 nBits
= PickerFlags::SaveAs
| PickerFlags::Password
| PickerFlags::AutoExtension
;
261 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS
)
263 nBits
= PickerFlags::SaveAs
| PickerFlags::Password
| PickerFlags::AutoExtension
| PickerFlags::FilterOptions
;
265 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE
)
267 nBits
= PickerFlags::SaveAs
| PickerFlags::AutoExtension
| PickerFlags::Templates
;
269 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION
)
271 nBits
= PickerFlags::SaveAs
| PickerFlags::AutoExtension
| PickerFlags::Selection
;
274 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE
)
276 nBits
= PickerFlags::Open
| PickerFlags::InsertAsLink
| PickerFlags::ShowPreview
| PickerFlags::ImageTemplate
;
278 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_PLAY
)
280 nBits
= PickerFlags::Open
| PickerFlags::PlayButton
;
282 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_LINK_PLAY
)
284 nBits
= PickerFlags::Open
| PickerFlags::InsertAsLink
| PickerFlags::PlayButton
;
286 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_READONLY_VERSION
)
288 nBits
= PickerFlags::Open
| PickerFlags::ReadOnly
| PickerFlags::ShowVersions
;
290 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_LINK_PREVIEW
)
292 nBits
= PickerFlags::Open
| PickerFlags::InsertAsLink
| PickerFlags::ShowPreview
;
294 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_PREVIEW
)
296 nBits
= PickerFlags::Open
| PickerFlags::ShowPreview
;
298 if ( m_bMultiSelection
&& ( nBits
& PickerFlags::Open
) )
299 nBits
|= PickerFlags::MultiSelection
;
305 void SvtFilePicker::notify( sal_Int16 _nEventId
, sal_Int16 _nControlId
)
307 if ( !m_xListener
.is() )
310 FilePickerEvent
aEvent( *this, _nControlId
);
314 case FILE_SELECTION_CHANGED
:
315 m_xListener
->fileSelectionChanged( aEvent
);
317 case DIRECTORY_CHANGED
:
318 m_xListener
->directoryChanged( aEvent
);
320 case CTRL_STATE_CHANGED
:
321 m_xListener
->controlStateChanged( aEvent
);
323 case DIALOG_SIZE_CHANGED
:
324 m_xListener
->dialogSizeChanged();
327 SAL_WARN( "fpicker.office", "SvtFilePicker::notify(): Unknown event id!" );
335 struct FilterTitleMatch
: public ::std::unary_function
< FilterEntry
, bool >
338 const OUString
& rTitle
;
341 explicit FilterTitleMatch( const OUString
& _rTitle
) : rTitle( _rTitle
) { }
344 bool operator () ( const FilterEntry
& _rEntry
)
347 if ( !_rEntry
.hasSubFilters() )
349 bMatch
= ( _rEntry
.getTitle() == rTitle
);
351 // a filter group -> search the sub filters
354 _rEntry
.beginSubFilters(),
355 _rEntry
.endSubFilters(),
361 bool operator () ( const UnoFilterEntry
& _rEntry
)
363 return _rEntry
.First
== rTitle
;
369 bool SvtFilePicker::FilterNameExists( const OUString
& rTitle
)
376 m_pFilterList
->begin(),
377 m_pFilterList
->end(),
378 FilterTitleMatch( rTitle
)
385 bool SvtFilePicker::FilterNameExists( const UnoFilterList
& _rGroupedFilters
)
391 const UnoFilterEntry
* pStart
= _rGroupedFilters
.getConstArray();
392 const UnoFilterEntry
* pEnd
= pStart
+ _rGroupedFilters
.getLength();
393 for ( ; pStart
!= pEnd
; ++pStart
)
394 if ( ::std::any_of( m_pFilterList
->begin(), m_pFilterList
->end(), FilterTitleMatch( pStart
->First
) ) )
397 bRet
= pStart
!= pEnd
;
404 void SvtFilePicker::ensureFilterList( const OUString
& _rInitialCurrentFilter
)
406 if ( !m_pFilterList
)
408 m_pFilterList
= new FilterList
;
410 // set the first filter to the current filter
411 if ( m_aCurrentFilter
.isEmpty() )
412 m_aCurrentFilter
= _rInitialCurrentFilter
;
417 // class SvtFilePicker
419 SvtFilePicker::SvtFilePicker()
420 :m_pFilterList ( nullptr )
421 ,m_pElemList ( nullptr )
422 ,m_bMultiSelection ( false )
423 ,m_nServiceType ( TemplateDescription::FILEOPEN_SIMPLE
)
427 SvtFilePicker::~SvtFilePicker()
429 if ( m_pFilterList
&& !m_pFilterList
->empty() )
430 m_pFilterList
->erase( m_pFilterList
->begin(), m_pFilterList
->end() );
431 delete m_pFilterList
;
433 if ( m_pElemList
&& !m_pElemList
->empty() )
434 m_pElemList
->erase( m_pElemList
->begin(), m_pElemList
->end() );
439 sal_Int16
SvtFilePicker::implExecutePicker( )
441 getDialog()->SetFileCallback( this );
445 getDialog()->EnableAutocompletion();
446 // now we are ready to execute the dialog
447 sal_Int16 nRet
= getDialog()->Execute();
449 // the execution of the dialog yields, so it is possible the at this point the window or the dialog is closed
451 getDialog()->SetFileCallback( nullptr );
457 VclPtr
<SvtFileDialog_Base
> SvtFilePicker::implCreateDialog( vcl::Window
* _pParent
)
459 PickerFlags nBits
= getPickerFlags();
461 VclPtrInstance
<SvtFileDialog
> dialog( _pParent
, nBits
);
463 // Set StandardDir if present
464 if ( !m_aStandardDir
.isEmpty())
466 OUString sStandardDir
= m_aStandardDir
;
467 dialog
->SetStandardDir( sStandardDir
);
468 dialog
->SetBlackList( m_aBlackList
);
475 // disambiguate XInterface
477 IMPLEMENT_FORWARD_XINTERFACE2( SvtFilePicker
, OCommonPicker
, SvtFilePicker_Base
)
480 // disambiguate XTypeProvider
482 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvtFilePicker
, OCommonPicker
, SvtFilePicker_Base
)
484 IMPLEMENT_FORWARD_XINTERFACE3( SvtRemoteFilePicker
, SvtFilePicker
, OCommonPicker
, SvtFilePicker_Base
)
487 // disambiguate XTypeProvider
489 IMPLEMENT_FORWARD_XTYPEPROVIDER3( SvtRemoteFilePicker
, SvtFilePicker
, OCommonPicker
, SvtFilePicker_Base
)
492 // XExecutableDialog functions
495 void SAL_CALL
SvtFilePicker::setTitle( const OUString
& _rTitle
) throw (RuntimeException
, std::exception
)
497 OCommonPicker::setTitle( _rTitle
);
501 sal_Int16 SAL_CALL
SvtFilePicker::execute( ) throw (RuntimeException
, std::exception
)
503 return OCommonPicker::execute();
507 // XAsynchronousExecutableDialog functions
510 void SAL_CALL
SvtFilePicker::setDialogTitle( const OUString
& _rTitle
) throw (RuntimeException
, std::exception
)
516 void SAL_CALL
SvtFilePicker::startExecuteModal( const Reference
< css::ui::dialogs::XDialogClosedListener
>& xListener
)
517 throw (RuntimeException
,
520 m_xDlgClosedListener
= xListener
;
523 getDialog()->EnableAutocompletion();
524 getDialog()->StartExecuteModal( LINK( this, SvtFilePicker
, DialogClosedHdl
) );
528 // XFilePicker functions
531 void SAL_CALL
SvtFilePicker::setMultiSelectionMode( sal_Bool bMode
) throw( RuntimeException
, std::exception
)
535 SolarMutexGuard aGuard
;
536 m_bMultiSelection
= bMode
;
539 void SAL_CALL
SvtFilePicker::setDefaultName( const OUString
& aName
) throw( RuntimeException
, std::exception
)
543 SolarMutexGuard aGuard
;
544 m_aDefaultName
= aName
;
547 void SAL_CALL
SvtFilePicker::setDisplayDirectory( const OUString
& aDirectory
)
548 throw( IllegalArgumentException
, RuntimeException
, std::exception
)
552 SolarMutexGuard aGuard
;
553 m_aDisplayDirectory
= aDirectory
;
556 OUString SAL_CALL
SvtFilePicker::getDisplayDirectory() throw( RuntimeException
, std::exception
)
560 SolarMutexGuard aGuard
;
563 OUString aPath
= getDialog()->GetPath();
565 if( m_aOldHideDirectory
== aPath
)
566 return m_aOldDisplayDirectory
;
567 m_aOldHideDirectory
= aPath
;
569 if( !getDialog()->ContentIsFolder( aPath
) )
571 INetURLObject
aFolder( aPath
);
572 aFolder
.CutLastName();
573 aPath
= aFolder
.GetMainURL( INetURLObject::DecodeMechanism::NONE
);
575 m_aOldDisplayDirectory
= aPath
;
579 return m_aDisplayDirectory
;
582 Sequence
< OUString
> SAL_CALL
SvtFilePicker::getSelectedFiles() throw( RuntimeException
, std::exception
)
586 SolarMutexGuard aGuard
;
589 Sequence
< OUString
> aEmpty
;
593 std::vector
<OUString
> aPathList(getDialog()->GetPathList());
594 size_t nCount
= aPathList
.size();
596 Sequence
< OUString
> aFiles(nCount
);
598 for(size_t i
= 0; i
< aPathList
.size(); ++i
)
600 aFiles
[i
] = aPathList
[i
];
606 Sequence
< OUString
> SAL_CALL
SvtFilePicker::getFiles() throw( RuntimeException
, std::exception
)
608 Sequence
< OUString
> aFiles
= getSelectedFiles();
609 if (aFiles
.getLength() > 1)
615 // XFilePickerControlAccess functions
618 void SAL_CALL
SvtFilePicker::setValue( sal_Int16 nElementID
,
619 sal_Int16 nControlAction
,
621 throw( RuntimeException
, std::exception
)
625 SolarMutexGuard aGuard
;
628 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
629 aAccess
.setValue( nElementID
, nControlAction
, rValue
);
634 m_pElemList
= new ElementList
;
637 ElementList::iterator aListIter
;
639 for ( aListIter
= m_pElemList
->begin();
640 aListIter
!= m_pElemList
->end(); ++aListIter
)
642 ElementEntry_Impl
& rEntry
= *aListIter
;
643 if ( ( rEntry
.m_nElementID
== nElementID
) &&
644 ( !rEntry
.m_bHasValue
|| ( rEntry
.m_nControlAction
== nControlAction
) ) )
646 rEntry
.setAction( nControlAction
);
647 rEntry
.setValue( rValue
);
654 ElementEntry_Impl
aNew( nElementID
);
655 aNew
.setAction( nControlAction
);
656 aNew
.setValue( rValue
);
657 m_pElemList
->insert( m_pElemList
->end(), aNew
);
663 Any SAL_CALL
SvtFilePicker::getValue( sal_Int16 nElementID
, sal_Int16 nControlAction
)
664 throw( RuntimeException
, std::exception
)
668 SolarMutexGuard aGuard
;
674 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
675 aAny
= aAccess
.getValue( nElementID
, nControlAction
);
677 else if ( m_pElemList
&& !m_pElemList
->empty() )
679 ElementList::iterator aListIter
;
680 for ( aListIter
= m_pElemList
->begin();
681 aListIter
!= m_pElemList
->end(); ++aListIter
)
683 ElementEntry_Impl
& rEntry
= *aListIter
;
684 if ( ( rEntry
.m_nElementID
== nElementID
) &&
685 ( rEntry
.m_bHasValue
) &&
686 ( rEntry
.m_nControlAction
== nControlAction
) )
688 aAny
= rEntry
.m_aValue
;
698 void SAL_CALL
SvtFilePicker::setLabel( sal_Int16 nLabelID
, const OUString
& rValue
)
699 throw ( RuntimeException
, std::exception
)
703 SolarMutexGuard aGuard
;
706 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
707 aAccess
.setLabel( nLabelID
, rValue
);
712 m_pElemList
= new ElementList
;
715 ElementList::iterator aListIter
;
717 for ( aListIter
= m_pElemList
->begin();
718 aListIter
!= m_pElemList
->end(); ++aListIter
)
720 ElementEntry_Impl
& rEntry
= *aListIter
;
721 if ( rEntry
.m_nElementID
== nLabelID
)
723 rEntry
.setLabel( rValue
);
730 ElementEntry_Impl
aNew( nLabelID
);
731 aNew
.setLabel( rValue
);
732 m_pElemList
->insert( m_pElemList
->end(), aNew
);
738 OUString SAL_CALL
SvtFilePicker::getLabel( sal_Int16 nLabelID
)
739 throw ( RuntimeException
, std::exception
)
743 SolarMutexGuard aGuard
;
748 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
749 aLabel
= aAccess
.getLabel( nLabelID
);
751 else if ( m_pElemList
&& !m_pElemList
->empty() )
753 ElementList::iterator aListIter
;
754 for ( aListIter
= m_pElemList
->begin();
755 aListIter
!= m_pElemList
->end(); ++aListIter
)
757 ElementEntry_Impl
& rEntry
= *aListIter
;
758 if ( rEntry
.m_nElementID
== nLabelID
)
760 if ( rEntry
.m_bHasLabel
)
761 aLabel
= rEntry
.m_aLabel
;
771 void SAL_CALL
SvtFilePicker::enableControl( sal_Int16 nElementID
, sal_Bool bEnable
)
772 throw( RuntimeException
, std::exception
)
776 SolarMutexGuard aGuard
;
779 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
780 aAccess
.enableControl( nElementID
, bEnable
);
785 m_pElemList
= new ElementList
;
788 ElementList::iterator aListIter
;
790 for ( aListIter
= m_pElemList
->begin();
791 aListIter
!= m_pElemList
->end(); ++aListIter
)
793 ElementEntry_Impl
& rEntry
= *aListIter
;
794 if ( rEntry
.m_nElementID
== nElementID
)
796 rEntry
.setEnabled( bEnable
);
803 ElementEntry_Impl
aNew( nElementID
);
804 aNew
.setEnabled( bEnable
);
805 m_pElemList
->insert( m_pElemList
->end(), aNew
);
811 // XFilePickerNotifier functions
814 void SAL_CALL
SvtFilePicker::addFilePickerListener( const Reference
< XFilePickerListener
>& xListener
) throw ( RuntimeException
, std::exception
)
818 SolarMutexGuard aGuard
;
819 m_xListener
= xListener
;
823 void SAL_CALL
SvtFilePicker::removeFilePickerListener( const Reference
< XFilePickerListener
>& ) throw ( RuntimeException
, std::exception
)
827 SolarMutexGuard aGuard
;
832 // XFilePreview functions
835 Sequence
< sal_Int16
> SAL_CALL
SvtFilePicker::getSupportedImageFormats()
836 throw ( RuntimeException
, std::exception
)
840 SolarMutexGuard aGuard
;
841 Sequence
< sal_Int16
> aFormats( 1 );
843 aFormats
[0] = FilePreviewImageFormats::BITMAP
;
849 sal_Int32 SAL_CALL
SvtFilePicker::getTargetColorDepth() throw ( RuntimeException
, std::exception
)
853 SolarMutexGuard aGuard
;
854 sal_Int32 nDepth
= 0;
857 nDepth
= getDialog()->getTargetColorDepth();
863 sal_Int32 SAL_CALL
SvtFilePicker::getAvailableWidth() throw ( RuntimeException
, std::exception
)
867 SolarMutexGuard aGuard
;
868 sal_Int32 nWidth
= 0;
871 nWidth
= getDialog()->getAvailableWidth();
877 sal_Int32 SAL_CALL
SvtFilePicker::getAvailableHeight() throw ( RuntimeException
, std::exception
)
881 SolarMutexGuard aGuard
;
882 sal_Int32 nHeight
= 0;
885 nHeight
= getDialog()->getAvailableHeight();
891 void SAL_CALL
SvtFilePicker::setImage( sal_Int16 aImageFormat
, const Any
& rImage
)
892 throw ( IllegalArgumentException
, RuntimeException
, std::exception
)
896 SolarMutexGuard aGuard
;
898 getDialog()->setImage( aImageFormat
, rImage
);
902 sal_Bool SAL_CALL
SvtFilePicker::setShowState( sal_Bool
)
903 throw ( RuntimeException
, std::exception
)
907 SolarMutexGuard aGuard
;
912 // #97633 for the system filedialog it's
913 // useful to make the preview switchable
914 // because the preview occupies
915 // half of the size of the file listbox
916 // which is not the case here,
917 // so we (TRA/FS) decided not to make
918 // the preview window switchable because
919 // else we would have to change the layout
920 // of the file dialog dynamically
921 // support for set/getShowState is opionally
922 // see css::ui::dialogs::XFilePreview
931 sal_Bool SAL_CALL
SvtFilePicker::getShowState() throw ( RuntimeException
, std::exception
)
935 SolarMutexGuard aGuard
;
939 bRet
= getDialog()->getShowState();
945 // XFilterGroupManager functions
948 void SAL_CALL
SvtFilePicker::appendFilterGroup( const OUString
& sGroupTitle
,
949 const Sequence
< StringPair
>& aFilters
)
950 throw ( IllegalArgumentException
, RuntimeException
, std::exception
)
954 SolarMutexGuard aGuard
;
957 if ( FilterNameExists( aFilters
) )
958 throw IllegalArgumentException(
959 "filter name exists",
960 static_cast< OWeakObject
* >(this), 1);
962 // ensure that we have a filter list
963 OUString sInitialCurrentFilter
;
964 if ( aFilters
.getLength() )
965 sInitialCurrentFilter
= aFilters
[0].First
;
966 ensureFilterList( sInitialCurrentFilter
);
969 m_pFilterList
->insert( m_pFilterList
->end(), FilterEntry( sGroupTitle
, aFilters
) );
973 // XFilterManager functions
976 void SAL_CALL
SvtFilePicker::appendFilter( const OUString
& aTitle
,
977 const OUString
& aFilter
)
978 throw( IllegalArgumentException
, RuntimeException
, std::exception
)
982 SolarMutexGuard aGuard
;
984 if ( FilterNameExists( aTitle
) )
985 // TODO: a more precise exception message
986 throw IllegalArgumentException();
988 // ensure that we have a filter list
989 ensureFilterList( aTitle
);
992 m_pFilterList
->insert( m_pFilterList
->end(), FilterEntry( aTitle
, aFilter
) );
996 void SAL_CALL
SvtFilePicker::setCurrentFilter( const OUString
& aTitle
)
997 throw( IllegalArgumentException
, RuntimeException
, std::exception
)
1001 SolarMutexGuard aGuard
;
1002 if ( ! FilterNameExists( aTitle
) )
1003 throw IllegalArgumentException();
1005 m_aCurrentFilter
= aTitle
;
1008 getDialog()->SetCurFilter( aTitle
);
1012 OUString SAL_CALL
SvtFilePicker::getCurrentFilter()
1013 throw( RuntimeException
, std::exception
)
1017 SolarMutexGuard aGuard
;
1018 OUString aFilter
= getDialog() ? OUString( getDialog()->GetCurFilter() ) :
1019 OUString( m_aCurrentFilter
);
1024 // XInitialization functions
1027 void SAL_CALL
SvtFilePicker::initialize( const Sequence
< Any
>& _rArguments
)
1028 throw ( Exception
, RuntimeException
, std::exception
)
1032 Sequence
< Any
> aArguments( _rArguments
.getLength());
1034 m_nServiceType
= TemplateDescription::FILEOPEN_SIMPLE
;
1036 if ( _rArguments
.getLength() >= 1 )
1038 // compatibility: one argument, type sal_Int16 , specifies the service type
1041 if (_rArguments
[0] >>= m_nServiceType
)
1043 // skip the first entry if it was the ServiceType, because it's not needed in OCommonPicker::initialize and it's not a NamedValue
1044 NamedValue emptyNamedValue
;
1045 aArguments
[0] <<= emptyNamedValue
;
1049 for ( int i
= index
; i
< _rArguments
.getLength(); i
++)
1051 NamedValue namedValue
;
1052 aArguments
[i
] = _rArguments
[i
];
1054 if (aArguments
[i
] >>= namedValue
)
1057 if ( namedValue
.Name
== "StandardDir" )
1059 OUString sStandardDir
;
1061 namedValue
.Value
>>= sStandardDir
;
1063 // Set the directory for the "back to the default dir" button
1064 if ( !sStandardDir
.isEmpty() )
1066 m_aStandardDir
= sStandardDir
;
1069 else if ( namedValue
.Name
== "BlackList" )
1071 namedValue
.Value
>>= m_aBlackList
;
1077 // let the base class analyze the sequence (will call into implHandleInitializationArgument)
1078 OCommonPicker::initialize( aArguments
);
1082 bool SvtFilePicker::implHandleInitializationArgument( const OUString
& _rName
, const Any
& _rValue
)
1084 if ( _rName
== "TemplateDescription" )
1086 m_nServiceType
= TemplateDescription::FILEOPEN_SIMPLE
;
1087 OSL_VERIFY( _rValue
>>= m_nServiceType
);
1090 if ( _rName
== "StandardDir" )
1092 OSL_VERIFY( _rValue
>>= m_aStandardDir
);
1096 if ( _rName
== "BlackList" )
1098 OSL_VERIFY( _rValue
>>= m_aBlackList
);
1103 return OCommonPicker::implHandleInitializationArgument( _rName
, _rValue
);
1111 OUString SAL_CALL
SvtFilePicker::getImplementationName() throw( RuntimeException
, std::exception
)
1113 return impl_getStaticImplementationName();
1117 sal_Bool SAL_CALL
SvtFilePicker::supportsService( const OUString
& sServiceName
) throw( RuntimeException
, std::exception
)
1119 return cppu::supportsService(this, sServiceName
);
1123 Sequence
< OUString
> SAL_CALL
SvtFilePicker::getSupportedServiceNames() throw( RuntimeException
, std::exception
)
1125 return impl_getStaticSupportedServiceNames();
1128 /* Helper for XServiceInfo */
1129 Sequence
< OUString
> SvtFilePicker::impl_getStaticSupportedServiceNames()
1131 Sequence
<OUString
> seqServiceNames
{ "com.sun.star.ui.dialogs.OfficeFilePicker" };
1132 return seqServiceNames
;
1135 /* Helper for XServiceInfo */
1136 OUString
SvtFilePicker::impl_getStaticImplementationName()
1138 return OUString( "com.sun.star.svtools.OfficeFilePicker" );
1141 /* Helper for registry */
1142 Reference
< XInterface
> SAL_CALL
SvtFilePicker::impl_createInstance(
1143 const Reference
< XComponentContext
>& ) throw( Exception
)
1145 return Reference
< XInterface
>( *new SvtFilePicker
);
1148 // SvtRemoteFilePicker
1150 SvtRemoteFilePicker::SvtRemoteFilePicker()
1154 VclPtr
<SvtFileDialog_Base
> SvtRemoteFilePicker::implCreateDialog( vcl::Window
* _pParent
)
1156 PickerFlags nBits
= getPickerFlags();
1158 VclPtrInstance
<RemoteFilesDialog
> dialog( _pParent
, nBits
);
1160 // Set StandardDir if present
1161 if ( !m_aStandardDir
.isEmpty())
1163 OUString sStandardDir
= m_aStandardDir
;
1164 dialog
->SetStandardDir( sStandardDir
);
1165 dialog
->SetBlackList( m_aBlackList
);
1175 OUString SAL_CALL
SvtRemoteFilePicker::getImplementationName() throw( RuntimeException
, std::exception
)
1177 return impl_getStaticImplementationName();
1181 sal_Bool SAL_CALL
SvtRemoteFilePicker::supportsService( const OUString
& sServiceName
) throw( RuntimeException
, std::exception
)
1183 return cppu::supportsService(this, sServiceName
);
1187 Sequence
< OUString
> SAL_CALL
SvtRemoteFilePicker::getSupportedServiceNames() throw( RuntimeException
, std::exception
)
1189 return impl_getStaticSupportedServiceNames();
1192 /* Helper for XServiceInfo */
1193 Sequence
< OUString
> SvtRemoteFilePicker::impl_getStaticSupportedServiceNames()
1195 Sequence
<OUString
> seqServiceNames
{ "com.sun.star.ui.dialogs.RemoteFilePicker" };
1196 return seqServiceNames
;
1199 /* Helper for XServiceInfo */
1200 OUString
SvtRemoteFilePicker::impl_getStaticImplementationName()
1202 return OUString( "com.sun.star.svtools.RemoteFilePicker" );
1205 /* Helper for registry */
1206 Reference
< XInterface
> SAL_CALL
SvtRemoteFilePicker::impl_createInstance(
1207 const Reference
< XComponentContext
>& ) throw( Exception
)
1209 return Reference
< XInterface
>( *new SvtRemoteFilePicker
);
1212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */