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: OfficeFilePicker.cxx,v $
10 * $Revision: 1.17.20.1 $
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 "OfficeFilePicker.hxx"
46 #include <tools/urlobj.hxx>
47 #include <tools/debug.hxx>
48 #define _SVSTDARR_STRINGSDTOR
49 #include "svtools/svstdarr.hxx"
50 #include <com/sun/star/uno/Any.hxx>
51 #include <com/sun/star/ui/dialogs/FilePickerEvent.hpp>
52 #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
53 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
54 #include <com/sun/star/beans/PropertyValue.hpp>
55 #include <com/sun/star/beans/XPropertySet.hpp>
56 #include <com/sun/star/awt/XWindow.hpp>
57 #include <com/sun/star/beans/StringPair.hpp>
58 #include <com/sun/star/uno/Sequence.hxx>
59 #include <com/sun/star/beans/NamedValue.hpp>
60 #include <unotools/ucbhelper.hxx>
61 #include <svtools/pathoptions.hxx>
62 #include <comphelper/sequence.hxx>
63 #include <cppuhelper/typeprovider.hxx>
64 #include "vos/mutex.hxx"
66 #include "vcl/svapp.hxx"
69 // define ----------------------------------------------------------------
71 #define MAKE_ANY ::com::sun::star::uno::makeAny
73 // using ----------------------------------------------------------------
75 using namespace ::com::sun::star::container
;
76 using namespace ::com::sun::star::lang
;
77 using namespace ::com::sun::star::ui::dialogs
;
78 using namespace ::com::sun::star::uno
;
79 using namespace ::com::sun::star::beans
;
80 using namespace ::com::sun::star::awt
;
81 using namespace ::utl
;
83 //=====================================================================
85 //=====================================================================
90 ::rtl::OUString m_sTitle
;
91 ::rtl::OUString m_sFilter
;
93 UnoFilterList m_aSubFilters
;
96 FilterEntry( const ::rtl::OUString
& _rTitle
, const ::rtl::OUString
& _rFilter
)
98 ,m_sFilter( _rFilter
)
102 FilterEntry( const ::rtl::OUString
& _rTitle
, const UnoFilterList
& _rSubFilters
);
104 ::rtl::OUString
getTitle() const { return m_sTitle
; }
105 ::rtl::OUString
getFilter() const { return m_sFilter
; }
107 /// determines if the filter has sub filter (i.e., the filter is a filter group in real)
108 sal_Bool
hasSubFilters( ) const;
110 /** retrieves the filters belonging to the entry
112 the number of sub filters
114 sal_Int32
getSubFilters( UnoFilterList
& _rSubFilterList
);
116 // helpers for iterating the sub filters
117 const UnoFilterEntry
* beginSubFilters() const { return m_aSubFilters
.getConstArray(); }
118 const UnoFilterEntry
* endSubFilters() const { return m_aSubFilters
.getConstArray() + m_aSubFilters
.getLength(); }
121 //=====================================================================
123 //---------------------------------------------------------------------
124 FilterEntry::FilterEntry( const ::rtl::OUString
& _rTitle
, const UnoFilterList
& _rSubFilters
)
126 ,m_aSubFilters( _rSubFilters
)
130 //---------------------------------------------------------------------
131 sal_Bool
FilterEntry::hasSubFilters( ) const
133 return ( 0 < m_aSubFilters
.getLength() );
136 //---------------------------------------------------------------------
137 sal_Int32
FilterEntry::getSubFilters( UnoFilterList
& _rSubFilterList
)
139 _rSubFilterList
= m_aSubFilters
;
140 return m_aSubFilters
.getLength();
143 // struct ElementEntry_Impl ----------------------------------------------
145 struct ElementEntry_Impl
147 sal_Int16 m_nElementID
;
148 sal_Int16 m_nControlAction
;
150 rtl::OUString m_aLabel
;
151 sal_Bool m_bEnabled
: 1;
153 sal_Bool m_bHasValue
: 1;
154 sal_Bool m_bHasLabel
: 1;
155 sal_Bool m_bHasEnabled
: 1;
157 ElementEntry_Impl( sal_Int16 nId
);
159 void setValue( const Any
& rVal
) { m_aValue
= rVal
; m_bHasValue
= sal_True
; }
160 void setAction( sal_Int16 nAction
) { m_nControlAction
= nAction
; }
161 void setLabel( const rtl::OUString
& rVal
) { m_aLabel
= rVal
; m_bHasLabel
= sal_True
; }
162 void setEnabled( sal_Bool bEnabled
) { m_bEnabled
= bEnabled
; m_bHasEnabled
= sal_True
; }
165 ElementEntry_Impl::ElementEntry_Impl( sal_Int16 nId
)
166 : m_nElementID( nId
)
167 , m_nControlAction( 0 )
168 , m_bEnabled( sal_False
)
169 , m_bHasValue( sal_False
)
170 , m_bHasLabel( sal_False
)
171 , m_bHasEnabled( sal_False
)
174 //------------------------------------------------------------------------------------
175 void SvtFilePicker::prepareExecute()
177 // set the default directory
178 // --**-- doesn't match the spec yet
179 if ( m_aDisplayDirectory
.getLength() > 0 || m_aDefaultName
.getLength() > 0 )
181 if ( m_aDisplayDirectory
.getLength() > 0 )
184 INetURLObject
aPath( m_aDisplayDirectory
);
185 if ( m_aDefaultName
.getLength() > 0 )
187 aPath
.insertName( m_aDefaultName
);
188 getDialog()->SetHasFilename( true );
190 String sPath
= aPath
.GetMainURL( INetURLObject::NO_DECODE
);
191 getDialog()->SetPath( aPath
.GetMainURL( INetURLObject::NO_DECODE
) );
193 else if ( m_aDefaultName
.getLength() > 0 )
195 getDialog()->SetPath( m_aDefaultName
);
196 getDialog()->SetHasFilename( true );
201 // Default-Standard-Dir setzen
202 INetURLObject
aStdDirObj( SvtPathOptions().GetWorkPath() );
203 getDialog()->SetPath( aStdDirObj
.GetMainURL( INetURLObject::NO_DECODE
) );
206 // set the control values and set the control labels, too
207 if ( m_pElemList
&& !m_pElemList
->empty() )
209 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
211 ElementList::iterator aListIter
;
212 for ( aListIter
= m_pElemList
->begin();
213 aListIter
!= m_pElemList
->end(); ++aListIter
)
215 ElementEntry_Impl
& rEntry
= *aListIter
;
216 if ( rEntry
.m_bHasValue
)
217 aAccess
.setValue( rEntry
.m_nElementID
, rEntry
.m_nControlAction
, rEntry
.m_aValue
);
218 if ( rEntry
.m_bHasLabel
)
219 aAccess
.setLabel( rEntry
.m_nElementID
, rEntry
.m_aLabel
);
220 if ( rEntry
.m_bHasEnabled
)
221 aAccess
.enableControl( rEntry
.m_nElementID
, rEntry
.m_bEnabled
);
224 getDialog()->updateListboxLabelSizes();
227 if ( m_pFilterList
&& !m_pFilterList
->empty() )
229 for ( FilterList::iterator aListIter
= m_pFilterList
->begin();
230 aListIter
!= m_pFilterList
->end();
234 if ( aListIter
->hasSubFilters() )
235 { // it's a filter group
236 UnoFilterList aSubFilters
;
237 aListIter
->getSubFilters( aSubFilters
);
239 getDialog()->AddFilterGroup( aListIter
->getTitle(), aSubFilters
);
242 // it's a single filter
243 getDialog()->AddFilter( aListIter
->getTitle(), aListIter
->getFilter() );
247 // set the default filter
248 if ( m_aCurrentFilter
.getLength() > 0 )
249 getDialog()->SetCurFilter( m_aCurrentFilter
);
253 //-----------------------------------------------------------------------------
254 IMPL_LINK( SvtFilePicker
, DialogClosedHdl
, Dialog
*, pDlg
)
256 if ( m_xDlgClosedListener
.is() )
258 sal_Int16 nRet
= static_cast< sal_Int16
>( pDlg
->GetResult() );
259 ::com::sun::star::ui::dialogs::DialogClosedEvent
aEvent( *this, nRet
);
260 m_xDlgClosedListener
->dialogClosed( aEvent
);
261 m_xDlgClosedListener
.clear();
266 //------------------------------------------------------------------------------------
268 //------------------------------------------------------------------------------------
270 //------------------------------------------------------------------------------------
271 WinBits
SvtFilePicker::getWinBits( WinBits
& rExtraBits
)
273 // set the winbits for creating the filedialog
277 // set the standard bits acording to the service name
278 if ( m_nServiceType
== TemplateDescription::FILEOPEN_SIMPLE
)
282 else if ( m_nServiceType
== TemplateDescription::FILESAVE_SIMPLE
)
286 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION
)
289 rExtraBits
= SFX_EXTRA_AUTOEXTENSION
;
291 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD
)
293 nBits
= WB_SAVEAS
| SFXWB_PASSWORD
;
294 rExtraBits
= SFX_EXTRA_AUTOEXTENSION
;
296 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS
)
298 nBits
= WB_SAVEAS
| SFXWB_PASSWORD
;
299 rExtraBits
= SFX_EXTRA_AUTOEXTENSION
| SFX_EXTRA_FILTEROPTIONS
;
301 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE
)
304 rExtraBits
= SFX_EXTRA_AUTOEXTENSION
| SFX_EXTRA_TEMPLATES
;
306 else if ( m_nServiceType
== TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION
)
309 rExtraBits
= SFX_EXTRA_AUTOEXTENSION
| SFX_EXTRA_SELECTION
;
312 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE
)
315 rExtraBits
= SFX_EXTRA_INSERTASLINK
| SFX_EXTRA_SHOWPREVIEW
| SFX_EXTRA_IMAGE_TEMPLATE
;
317 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_PLAY
)
320 rExtraBits
= SFX_EXTRA_PLAYBUTTON
;
322 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_READONLY_VERSION
)
324 nBits
= WB_OPEN
| SFXWB_READONLY
;
325 rExtraBits
= SFX_EXTRA_SHOWVERSIONS
;
327 else if ( m_nServiceType
== TemplateDescription::FILEOPEN_LINK_PREVIEW
)
330 rExtraBits
= SFX_EXTRA_INSERTASLINK
| SFX_EXTRA_SHOWPREVIEW
;
332 if ( m_bMultiSelection
&& ( ( nBits
& WB_OPEN
) == WB_OPEN
) )
333 nBits
|= SFXWB_MULTISELECTION
;
338 //------------------------------------------------------------------------------------
339 void SvtFilePicker::notify( sal_Int16 _nEventId
, sal_Int16 _nControlId
)
341 if ( !m_xListener
.is() )
344 FilePickerEvent
aEvent( *this, _nControlId
);
348 case FILE_SELECTION_CHANGED
:
349 m_xListener
->fileSelectionChanged( aEvent
);
351 case DIRECTORY_CHANGED
:
352 m_xListener
->directoryChanged( aEvent
);
355 m_xListener
->helpRequested( aEvent
);
357 case CTRL_STATE_CHANGED
:
358 m_xListener
->controlStateChanged( aEvent
);
360 case DIALOG_SIZE_CHANGED
:
361 m_xListener
->dialogSizeChanged();
364 DBG_ERRORFILE( "SvtFilePicker::notify(): Unknown event id!" );
369 //------------------------------------------------------------------------------------
371 //................................................................................
372 struct FilterTitleMatch
: public ::std::unary_function
< FilterEntry
, bool >
375 const ::rtl::OUString
& rTitle
;
378 FilterTitleMatch( const ::rtl::OUString
& _rTitle
) : rTitle( _rTitle
) { }
380 //............................................................................
381 bool operator () ( const FilterEntry
& _rEntry
)
384 if ( !_rEntry
.hasSubFilters() )
386 bMatch
= ( _rEntry
.getTitle() == rTitle
);
388 // a filter group -> search the sub filters
390 _rEntry
.endSubFilters() != ::std::find_if(
391 _rEntry
.beginSubFilters(),
392 _rEntry
.endSubFilters(),
396 return bMatch
? true : false;
398 bool operator () ( const UnoFilterEntry
& _rEntry
)
400 return _rEntry
.First
== rTitle
? true : false;
405 //------------------------------------------------------------------------------------
406 sal_Bool
SvtFilePicker::FilterNameExists( const ::rtl::OUString
& rTitle
)
408 sal_Bool bRet
= sal_False
;
412 m_pFilterList
->end() != ::std::find_if(
413 m_pFilterList
->begin(),
414 m_pFilterList
->end(),
415 FilterTitleMatch( rTitle
)
421 //------------------------------------------------------------------------------------
422 sal_Bool
SvtFilePicker::FilterNameExists( const UnoFilterList
& _rGroupedFilters
)
424 sal_Bool bRet
= sal_False
;
428 const UnoFilterEntry
* pStart
= _rGroupedFilters
.getConstArray();
429 const UnoFilterEntry
* pEnd
= pStart
+ _rGroupedFilters
.getLength();
430 for ( ; pStart
!= pEnd
; ++pStart
)
431 if ( m_pFilterList
->end() != ::std::find_if( m_pFilterList
->begin(), m_pFilterList
->end(), FilterTitleMatch( pStart
->First
) ) )
434 bRet
= pStart
!= pEnd
;
440 //------------------------------------------------------------------------------------
441 void SvtFilePicker::ensureFilterList( const ::rtl::OUString
& _rInitialCurrentFilter
)
443 if ( !m_pFilterList
)
445 m_pFilterList
= new FilterList
;
447 // set the first filter to the current filter
448 if ( ! m_aCurrentFilter
.getLength() )
449 m_aCurrentFilter
= _rInitialCurrentFilter
;
453 //------------------------------------------------------------------------------------
454 // class SvtFilePicker
455 //------------------------------------------------------------------------------------
456 SvtFilePicker::SvtFilePicker( const Reference
< XMultiServiceFactory
>& xFactory
)
457 :OCommonPicker( xFactory
)
458 ,m_pFilterList ( NULL
)
459 ,m_pElemList ( NULL
)
460 ,m_bMultiSelection ( sal_False
)
461 ,m_nServiceType ( TemplateDescription::FILEOPEN_SIMPLE
)
465 SvtFilePicker::~SvtFilePicker()
467 if ( m_pFilterList
&& !m_pFilterList
->empty() )
468 m_pFilterList
->erase( m_pFilterList
->begin(), m_pFilterList
->end() );
469 delete m_pFilterList
;
471 if ( m_pElemList
&& !m_pElemList
->empty() )
472 m_pElemList
->erase( m_pElemList
->begin(), m_pElemList
->end() );
476 //------------------------------------------------------------------------------------
477 sal_Int16
SvtFilePicker::implExecutePicker( )
479 getDialog()->SetFileCallback( this );
483 getDialog()->EnableAutocompletion( TRUE
);
484 // now we are ready to execute the dialog
485 sal_Int16 nRet
= getDialog()->Execute();
487 // the execution of the dialog yields, so it is possible the at this point the window or the dialog is closed
489 getDialog()->SetFileCallback( NULL
);
494 //------------------------------------------------------------------------------------
495 SvtFileDialog
* SvtFilePicker::implCreateDialog( Window
* _pParent
)
498 WinBits nBits
= getWinBits( nExtraBits
);
500 SvtFileDialog
* dialog
= new SvtFileDialog( _pParent
, nBits
, nExtraBits
);
502 // Set StandardDir if present
503 if ( m_aStandardDir
.getLength() > 0)
505 String sStandardDir
= String( m_aStandardDir
);
506 dialog
->SetStandardDir( sStandardDir
);
507 dialog
->SetBlackList( m_aBlackList
);
513 //------------------------------------------------------------------------------------
514 // disambiguate XInterface
515 //------------------------------------------------------------------------------------
516 IMPLEMENT_FORWARD_XINTERFACE2( SvtFilePicker
, OCommonPicker
, SvtFilePicker_Base
)
518 //------------------------------------------------------------------------------------
519 // disambiguate XTypeProvider
520 //------------------------------------------------------------------------------------
521 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvtFilePicker
, OCommonPicker
, SvtFilePicker_Base
)
523 //------------------------------------------------------------------------------------
524 // XExecutableDialog functions
525 //------------------------------------------------------------------------------------
527 //------------------------------------------------------------------------------------
528 void SAL_CALL
SvtFilePicker::setTitle( const ::rtl::OUString
& _rTitle
) throw (RuntimeException
)
530 OCommonPicker::setTitle( _rTitle
);
533 //------------------------------------------------------------------------------------
534 sal_Int16 SAL_CALL
SvtFilePicker::execute( ) throw (RuntimeException
)
536 return OCommonPicker::execute();
539 //------------------------------------------------------------------------------------
540 // XAsynchronousExecutableDialog functions
541 //------------------------------------------------------------------------------------
543 //------------------------------------------------------------------------------------
544 void SAL_CALL
SvtFilePicker::setDialogTitle( const ::rtl::OUString
& _rTitle
) throw (RuntimeException
)
549 //------------------------------------------------------------------------------------
550 void SAL_CALL
SvtFilePicker::startExecuteModal( const Reference
< ::com::sun::star::ui::dialogs::XDialogClosedListener
>& xListener
) throw (RuntimeException
)
552 m_xDlgClosedListener
= xListener
;
555 getDialog()->EnableAutocompletion( TRUE
);
556 getDialog()->StartExecuteModal( LINK( this, SvtFilePicker
, DialogClosedHdl
) );
559 //------------------------------------------------------------------------------------
560 // XFilePicker functions
561 //------------------------------------------------------------------------------------
563 void SAL_CALL
SvtFilePicker::setMultiSelectionMode( sal_Bool bMode
) throw( RuntimeException
)
567 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
568 m_bMultiSelection
= bMode
;
571 void SAL_CALL
SvtFilePicker::setDefaultName( const rtl::OUString
& aName
) throw( RuntimeException
)
575 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
576 m_aDefaultName
= aName
;
579 void SAL_CALL
SvtFilePicker::setDisplayDirectory( const rtl::OUString
& aDirectory
)
580 throw( IllegalArgumentException
, RuntimeException
)
584 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
585 m_aDisplayDirectory
= aDirectory
;
588 rtl::OUString SAL_CALL
SvtFilePicker::getDisplayDirectory() throw( RuntimeException
)
592 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
595 rtl::OUString aPath
= getDialog()->GetPath();
598 if( m_aOldHideDirectory
== aPath
)
599 return m_aOldDisplayDirectory
;
600 m_aOldHideDirectory
= aPath
;
603 if( !getDialog()->ContentIsFolder( aPath
) )
605 INetURLObject
aFolder( aPath
);
606 aFolder
.CutLastName();
607 aPath
= aFolder
.GetMainURL( INetURLObject::NO_DECODE
);
609 m_aOldDisplayDirectory
= aPath
;
613 return m_aDisplayDirectory
;
616 Sequence
< rtl::OUString
> SAL_CALL
SvtFilePicker::getFiles() throw( RuntimeException
)
620 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
623 Sequence
< rtl::OUString
> aEmpty
;
627 // if there is more than one path we have to return the path to the
628 // files first and then the list of the selected entries
630 SvStringsDtor
* pPathList
= getDialog()->GetPathList();
631 USHORT i
, nCount
= pPathList
->Count();
632 USHORT nTotal
= nCount
> 1 ? nCount
+1: nCount
;
634 Sequence
< rtl::OUString
> aPath( nTotal
);
637 aPath
[0] = rtl::OUString( *pPathList
->GetObject( 0 ) );
638 else if ( nCount
> 1 )
640 INetURLObject
aObj( *pPathList
->GetObject( 0 ) );
641 aObj
.removeSegment();
642 aPath
[0] = aObj
.GetMainURL( INetURLObject::NO_DECODE
);
644 for ( i
= 0; i
< nCount
; /* i++ is done below */ )
646 aObj
.SetURL( *pPathList
->GetObject(i
++) );
647 aPath
[i
] = aObj
.getName();
655 //------------------------------------------------------------------------------------
656 // XFilePickerControlAccess functions
657 //------------------------------------------------------------------------------------
659 void SAL_CALL
SvtFilePicker::setValue( sal_Int16 nElementID
,
660 sal_Int16 nControlAction
,
662 throw( RuntimeException
)
666 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
669 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
670 aAccess
.setValue( nElementID
, nControlAction
, rValue
);
675 m_pElemList
= new ElementList
;
677 sal_Bool bFound
= sal_False
;
678 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
|| ( rEntry
.m_nControlAction
== nControlAction
) ) )
687 rEntry
.setAction( nControlAction
);
688 rEntry
.setValue( rValue
);
695 ElementEntry_Impl
aNew( nElementID
);
696 aNew
.setAction( nControlAction
);
697 aNew
.setValue( rValue
);
698 m_pElemList
->insert( m_pElemList
->end(), aNew
);
703 //------------------------------------------------------------------------------------
705 Any SAL_CALL
SvtFilePicker::getValue( sal_Int16 nElementID
, sal_Int16 nControlAction
)
706 throw( RuntimeException
)
710 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
716 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
717 aAny
= aAccess
.getValue( nElementID
, nControlAction
);
719 else if ( m_pElemList
&& !m_pElemList
->empty() )
721 ElementList::iterator aListIter
;
722 for ( aListIter
= m_pElemList
->begin();
723 aListIter
!= m_pElemList
->end(); ++aListIter
)
725 ElementEntry_Impl
& rEntry
= *aListIter
;
726 if ( ( rEntry
.m_nElementID
== nElementID
) &&
727 ( rEntry
.m_bHasValue
) &&
728 ( rEntry
.m_nControlAction
== nControlAction
) )
730 aAny
= rEntry
.m_aValue
;
740 //------------------------------------------------------------------------------------
741 void SAL_CALL
SvtFilePicker::setLabel( sal_Int16 nLabelID
, const rtl::OUString
& rValue
)
742 throw ( RuntimeException
)
746 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
749 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
750 aAccess
.setLabel( nLabelID
, rValue
);
755 m_pElemList
= new ElementList
;
757 sal_Bool bFound
= sal_False
;
758 ElementList::iterator aListIter
;
760 for ( aListIter
= m_pElemList
->begin();
761 aListIter
!= m_pElemList
->end(); ++aListIter
)
763 ElementEntry_Impl
& rEntry
= *aListIter
;
764 if ( rEntry
.m_nElementID
== nLabelID
)
766 rEntry
.setLabel( rValue
);
773 ElementEntry_Impl
aNew( nLabelID
);
774 aNew
.setLabel( rValue
);
775 m_pElemList
->insert( m_pElemList
->end(), aNew
);
780 //------------------------------------------------------------------------------------
781 rtl::OUString SAL_CALL
SvtFilePicker::getLabel( sal_Int16 nLabelID
)
782 throw ( RuntimeException
)
786 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
787 rtl::OUString aLabel
;
791 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
792 aLabel
= aAccess
.getLabel( nLabelID
);
794 else if ( m_pElemList
&& !m_pElemList
->empty() )
796 ElementList::iterator aListIter
;
797 for ( aListIter
= m_pElemList
->begin();
798 aListIter
!= m_pElemList
->end(); ++aListIter
)
800 ElementEntry_Impl
& rEntry
= *aListIter
;
801 if ( rEntry
.m_nElementID
== nLabelID
)
803 if ( rEntry
.m_bHasLabel
)
804 aLabel
= rEntry
.m_aLabel
;
813 //------------------------------------------------------------------------------------
814 void SAL_CALL
SvtFilePicker::enableControl( sal_Int16 nElementID
, sal_Bool bEnable
)
815 throw( RuntimeException
)
819 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
822 ::svt::OControlAccess
aAccess( getDialog(), getDialog()->GetView() );
823 aAccess
.enableControl( nElementID
, bEnable
);
828 m_pElemList
= new ElementList
;
830 sal_Bool bFound
= sal_False
;
831 ElementList::iterator aListIter
;
833 for ( aListIter
= m_pElemList
->begin();
834 aListIter
!= m_pElemList
->end(); ++aListIter
)
836 ElementEntry_Impl
& rEntry
= *aListIter
;
837 if ( rEntry
.m_nElementID
== nElementID
)
839 rEntry
.setEnabled( bEnable
);
846 ElementEntry_Impl
aNew( nElementID
);
847 aNew
.setEnabled( bEnable
);
848 m_pElemList
->insert( m_pElemList
->end(), aNew
);
853 //------------------------------------------------------------------------------------
854 // XFilePickerNotifier functions
855 //------------------------------------------------------------------------------------
857 void SAL_CALL
SvtFilePicker::addFilePickerListener( const Reference
< XFilePickerListener
>& xListener
) throw ( RuntimeException
)
861 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
862 m_xListener
= xListener
;
865 //------------------------------------------------------------------------------------
866 void SAL_CALL
SvtFilePicker::removeFilePickerListener( const Reference
< XFilePickerListener
>& ) throw ( RuntimeException
)
870 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
874 //------------------------------------------------------------------------------------
875 // XFilePreview functions
876 //------------------------------------------------------------------------------------
878 Sequence
< sal_Int16
> SAL_CALL
SvtFilePicker::getSupportedImageFormats()
879 throw ( RuntimeException
)
883 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
884 Sequence
< sal_Int16
> aFormats( 1 );
886 aFormats
[0] = FilePreviewImageFormats::BITMAP
;
891 //------------------------------------------------------------------------------------
892 sal_Int32 SAL_CALL
SvtFilePicker::getTargetColorDepth() throw ( RuntimeException
)
896 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
897 sal_Int32 nDepth
= 0;
900 nDepth
= getDialog()->getTargetColorDepth();
905 //------------------------------------------------------------------------------------
906 sal_Int32 SAL_CALL
SvtFilePicker::getAvailableWidth() throw ( RuntimeException
)
910 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
911 sal_Int32 nWidth
= 0;
914 nWidth
= getDialog()->getAvailableWidth();
919 //------------------------------------------------------------------------------------
920 sal_Int32 SAL_CALL
SvtFilePicker::getAvailableHeight() throw ( RuntimeException
)
924 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
925 sal_Int32 nHeigth
= 0;
928 nHeigth
= getDialog()->getAvailableHeight();
933 //------------------------------------------------------------------------------------
934 void SAL_CALL
SvtFilePicker::setImage( sal_Int16 aImageFormat
, const Any
& rImage
)
935 throw ( IllegalArgumentException
, RuntimeException
)
939 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
941 getDialog()->setImage( aImageFormat
, rImage
);
944 //------------------------------------------------------------------------------------
945 sal_Bool SAL_CALL
SvtFilePicker::setShowState( sal_Bool bShowState
)
946 throw ( RuntimeException
)
950 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
951 sal_Bool bRet
= sal_False
;
954 bRet
= getDialog()->setShowState( bShowState
);
959 //------------------------------------------------------------------------------------
960 sal_Bool SAL_CALL
SvtFilePicker::getShowState() throw ( RuntimeException
)
964 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
965 sal_Bool bRet
= sal_False
;
968 bRet
= getDialog()->getShowState();
973 //------------------------------------------------------------------------------------
974 // XFilterGroupManager functions
975 //------------------------------------------------------------------------------------
977 void SAL_CALL
SvtFilePicker::appendFilterGroup( const ::rtl::OUString
& sGroupTitle
,
978 const Sequence
< StringPair
>& aFilters
)
979 throw ( IllegalArgumentException
, RuntimeException
)
983 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
986 if ( FilterNameExists( aFilters
) )
987 // TODO: a more precise exception message
988 throw IllegalArgumentException();
990 // ensure that we have a filter list
991 ::rtl::OUString sInitialCurrentFilter
;
992 if ( aFilters
.getLength() )
993 sInitialCurrentFilter
= aFilters
[0].First
;
994 ensureFilterList( sInitialCurrentFilter
);
997 m_pFilterList
->insert( m_pFilterList
->end(), FilterEntry( sGroupTitle
, aFilters
) );
1000 //------------------------------------------------------------------------------------
1001 // XFilterManager functions
1002 //------------------------------------------------------------------------------------
1004 void SAL_CALL
SvtFilePicker::appendFilter( const rtl::OUString
& aTitle
,
1005 const rtl::OUString
& aFilter
)
1006 throw( IllegalArgumentException
, RuntimeException
)
1010 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1012 if ( FilterNameExists( aTitle
) )
1013 // TODO: a more precise exception message
1014 throw IllegalArgumentException();
1016 // ensure that we have a filter list
1017 ensureFilterList( aTitle
);
1019 // append the filter
1020 m_pFilterList
->insert( m_pFilterList
->end(), FilterEntry( aTitle
, aFilter
) );
1023 //------------------------------------------------------------------------------------
1024 void SAL_CALL
SvtFilePicker::setCurrentFilter( const rtl::OUString
& aTitle
)
1025 throw( IllegalArgumentException
, RuntimeException
)
1029 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1030 if ( ! FilterNameExists( aTitle
) )
1031 throw IllegalArgumentException();
1033 m_aCurrentFilter
= aTitle
;
1036 getDialog()->SetCurFilter( aTitle
);
1039 //------------------------------------------------------------------------------------
1040 rtl::OUString SAL_CALL
SvtFilePicker::getCurrentFilter()
1041 throw( RuntimeException
)
1045 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1046 rtl::OUString aFilter
= getDialog() ? rtl::OUString( getDialog()->GetCurFilter() ) :
1047 rtl::OUString( m_aCurrentFilter
);
1052 //------------------------------------------------------------------------------------
1053 // XInitialization functions
1054 //------------------------------------------------------------------------------------
1056 void SAL_CALL
SvtFilePicker::initialize( const Sequence
< Any
>& _rArguments
)
1057 throw ( Exception
, RuntimeException
)
1061 Sequence
< Any
> aArguments( _rArguments
.getLength());
1063 m_nServiceType
= TemplateDescription::FILEOPEN_SIMPLE
;
1065 if ( _rArguments
.getLength() >= 1 )
1067 // compatibility: one argument, type sal_Int16 , specifies the service type
1070 if (_rArguments
[0] >>= m_nServiceType
)
1072 // skip the first entry if it was the ServiceType, because it's not needed in OCommonPicker::initialize and it's not a NamedValue
1073 NamedValue emptyNamedValue
;
1074 aArguments
[0] <<= emptyNamedValue
;
1078 for ( int i
= index
; i
< _rArguments
.getLength(); i
++)
1080 NamedValue namedValue
;
1081 aArguments
[i
] <<= _rArguments
[i
];
1083 if (aArguments
[i
] >>= namedValue
)
1086 if ( namedValue
.Name
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StandardDir" ) ) ) )
1088 ::rtl::OUString sStandardDir
;
1090 namedValue
.Value
>>= sStandardDir
;
1092 // Set the directory for the "back to the default dir" button
1093 if ( sStandardDir
.getLength() > 0 )
1095 m_aStandardDir
= sStandardDir
;
1098 else if ( namedValue
.Name
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BlackList" ) ) ) )
1100 namedValue
.Value
>>= m_aBlackList
;
1106 // let the base class analyze the sequence (will call into implHandleInitializationArgument)
1107 OCommonPicker::initialize( aArguments
);
1110 //-------------------------------------------------------------------------
1111 sal_Bool
SvtFilePicker::implHandleInitializationArgument( const ::rtl::OUString
& _rName
, const Any
& _rValue
) SAL_THROW( ( Exception
, RuntimeException
) )
1113 if ( _rName
.equalsAscii( "TemplateDescription" ) )
1115 m_nServiceType
= TemplateDescription::FILEOPEN_SIMPLE
;
1116 OSL_VERIFY( _rValue
>>= m_nServiceType
);
1119 if ( _rName
.equalsAscii( "StandardDir" ) )
1121 OSL_VERIFY( _rValue
>>= m_aStandardDir
);
1125 if ( _rName
.equalsAscii( "BlackList" ) )
1127 OSL_VERIFY( _rValue
>>= m_aBlackList
);
1133 return OCommonPicker::implHandleInitializationArgument( _rName
, _rValue
);
1136 //------------------------------------------------------------------------------------
1138 //------------------------------------------------------------------------------------
1141 rtl::OUString SAL_CALL
SvtFilePicker::getImplementationName() throw( RuntimeException
)
1143 return impl_getStaticImplementationName();
1147 sal_Bool SAL_CALL
SvtFilePicker::supportsService( const rtl::OUString
& sServiceName
) throw( RuntimeException
)
1149 Sequence
< rtl::OUString
> seqServiceNames
= getSupportedServiceNames();
1150 const rtl::OUString
* pArray
= seqServiceNames
.getConstArray();
1151 for ( sal_Int32 i
= 0; i
< seqServiceNames
.getLength(); i
++ )
1153 if ( sServiceName
== pArray
[i
] )
1162 Sequence
< rtl::OUString
> SAL_CALL
SvtFilePicker::getSupportedServiceNames() throw( RuntimeException
)
1164 return impl_getStaticSupportedServiceNames();
1167 /* Helper for XServiceInfo */
1168 Sequence
< rtl::OUString
> SvtFilePicker::impl_getStaticSupportedServiceNames()
1170 Sequence
< rtl::OUString
> seqServiceNames( 1 );
1171 rtl::OUString
* pArray
= seqServiceNames
.getArray();
1172 pArray
[0] = rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.OfficeFilePicker" );
1173 return seqServiceNames
;
1176 /* Helper for XServiceInfo */
1177 rtl::OUString
SvtFilePicker::impl_getStaticImplementationName()
1179 return rtl::OUString::createFromAscii( "com.sun.star.svtools.OfficeFilePicker" );
1182 /* Helper for registry */
1183 Reference
< XInterface
> SAL_CALL
SvtFilePicker::impl_createInstance(
1184 const Reference
< XComponentContext
>& rxContext
) throw( Exception
)
1186 Reference
< XMultiServiceFactory
> xServiceManager (rxContext
->getServiceManager(), UNO_QUERY_THROW
);
1187 return Reference
< XInterface
>( *new SvtFilePicker( xServiceManager
) );