LCOV - code coverage report
Current view: top level - fpicker/source/office - OfficeFilePicker.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 500 0.0 %
Date: 2012-08-25 Functions: 0 73 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       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/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      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 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include "OfficeFilePicker.hxx"
      22                 :            : #include "iodlg.hxx"
      23                 :            : 
      24                 :            : #ifndef _LIST_
      25                 :            : #include <list>
      26                 :            : #endif
      27                 :            : #ifndef _FUNCTIONAL_
      28                 :            : #include <functional>
      29                 :            : #endif
      30                 :            : #ifndef _ALGORITHM_
      31                 :            : #include <algorithm>
      32                 :            : #endif
      33                 :            : #include <tools/urlobj.hxx>
      34                 :            : #include <com/sun/star/uno/Any.hxx>
      35                 :            : #include <com/sun/star/ui/dialogs/FilePickerEvent.hpp>
      36                 :            : #include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
      37                 :            : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      38                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      39                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      40                 :            : #include <com/sun/star/awt/XWindow.hpp>
      41                 :            : #include <com/sun/star/beans/StringPair.hpp>
      42                 :            : #include <com/sun/star/uno/Sequence.hxx>
      43                 :            : #include <com/sun/star/beans/NamedValue.hpp>
      44                 :            : #include <unotools/ucbhelper.hxx>
      45                 :            : #include <unotools/pathoptions.hxx>
      46                 :            : #include <comphelper/sequence.hxx>
      47                 :            : #include <cppuhelper/typeprovider.hxx>
      48                 :            : #include "osl/mutex.hxx"
      49                 :            : #include "vcl/svapp.hxx"
      50                 :            : 
      51                 :            : // using ----------------------------------------------------------------
      52                 :            : 
      53                 :            : using namespace     ::com::sun::star::container;
      54                 :            : using namespace     ::com::sun::star::lang;
      55                 :            : using namespace     ::com::sun::star::ui::dialogs;
      56                 :            : using namespace     ::com::sun::star::uno;
      57                 :            : using namespace     ::com::sun::star::beans;
      58                 :            : using namespace     ::com::sun::star::awt;
      59                 :            : using namespace     ::utl;
      60                 :            : 
      61                 :            : //=====================================================================
      62                 :            : 
      63                 :            : //=====================================================================
      64                 :            : 
      65                 :          0 : struct FilterEntry
      66                 :            : {
      67                 :            : protected:
      68                 :            :     ::rtl::OUString     m_sTitle;
      69                 :            :     ::rtl::OUString     m_sFilter;
      70                 :            : 
      71                 :            :     UnoFilterList       m_aSubFilters;
      72                 :            : 
      73                 :            : public:
      74                 :          0 :     FilterEntry( const ::rtl::OUString& _rTitle, const ::rtl::OUString& _rFilter )
      75                 :            :         :m_sTitle( _rTitle )
      76                 :          0 :         ,m_sFilter( _rFilter )
      77                 :            :     {
      78                 :          0 :     }
      79                 :            : 
      80                 :            :     FilterEntry( const ::rtl::OUString& _rTitle, const UnoFilterList& _rSubFilters );
      81                 :            : 
      82                 :          0 :     ::rtl::OUString     getTitle() const { return m_sTitle; }
      83                 :          0 :     ::rtl::OUString     getFilter() const { return m_sFilter; }
      84                 :            : 
      85                 :            :     /// determines if the filter has sub filter (i.e., the filter is a filter group in real)
      86                 :            :     sal_Bool            hasSubFilters( ) const;
      87                 :            : 
      88                 :            :     /** retrieves the filters belonging to the entry
      89                 :            :     @return
      90                 :            :         the number of sub filters
      91                 :            :     */
      92                 :            :     sal_Int32           getSubFilters( UnoFilterList& _rSubFilterList );
      93                 :            : 
      94                 :            :     // helpers for iterating the sub filters
      95                 :          0 :     const UnoFilterEntry*   beginSubFilters() const { return m_aSubFilters.getConstArray(); }
      96                 :          0 :     const UnoFilterEntry*   endSubFilters() const { return m_aSubFilters.getConstArray() + m_aSubFilters.getLength(); }
      97                 :            : };
      98                 :            : 
      99                 :            : //=====================================================================
     100                 :            : 
     101                 :            : //---------------------------------------------------------------------
     102                 :          0 : FilterEntry::FilterEntry( const ::rtl::OUString& _rTitle, const UnoFilterList& _rSubFilters )
     103                 :            :     :m_sTitle( _rTitle )
     104                 :          0 :     ,m_aSubFilters( _rSubFilters )
     105                 :            : {
     106                 :          0 : }
     107                 :            : 
     108                 :            : //---------------------------------------------------------------------
     109                 :          0 : sal_Bool FilterEntry::hasSubFilters( ) const
     110                 :            : {
     111                 :          0 :     return ( 0 < m_aSubFilters.getLength() );
     112                 :            : }
     113                 :            : 
     114                 :            : //---------------------------------------------------------------------
     115                 :          0 : sal_Int32 FilterEntry::getSubFilters( UnoFilterList& _rSubFilterList )
     116                 :            : {
     117                 :          0 :     _rSubFilterList = m_aSubFilters;
     118                 :          0 :     return m_aSubFilters.getLength();
     119                 :            : }
     120                 :            : 
     121                 :            : // struct ElementEntry_Impl ----------------------------------------------
     122                 :            : 
     123                 :          0 : struct ElementEntry_Impl
     124                 :            : {
     125                 :            :     sal_Int16       m_nElementID;
     126                 :            :     sal_Int16       m_nControlAction;
     127                 :            :     Any         m_aValue;
     128                 :            :     rtl::OUString       m_aLabel;
     129                 :            :     sal_Bool        m_bEnabled      : 1;
     130                 :            : 
     131                 :            :     sal_Bool        m_bHasValue     : 1;
     132                 :            :     sal_Bool        m_bHasLabel     : 1;
     133                 :            :     sal_Bool        m_bHasEnabled   : 1;
     134                 :            : 
     135                 :            :                     ElementEntry_Impl( sal_Int16 nId );
     136                 :            : 
     137                 :          0 :     void            setValue( const Any& rVal ) { m_aValue = rVal; m_bHasValue = sal_True; }
     138                 :          0 :     void            setAction( sal_Int16 nAction ) { m_nControlAction = nAction; }
     139                 :          0 :     void            setLabel( const rtl::OUString& rVal ) { m_aLabel = rVal; m_bHasLabel = sal_True; }
     140                 :          0 :     void            setEnabled( sal_Bool bEnabled ) { m_bEnabled = bEnabled; m_bHasEnabled = sal_True; }
     141                 :            : };
     142                 :            : 
     143                 :          0 : ElementEntry_Impl::ElementEntry_Impl( sal_Int16 nId )
     144                 :            :     : m_nElementID( nId )
     145                 :            :     , m_nControlAction( 0 )
     146                 :            :     , m_bEnabled( sal_False )
     147                 :            :     , m_bHasValue( sal_False )
     148                 :            :     , m_bHasLabel( sal_False )
     149                 :          0 :     , m_bHasEnabled( sal_False )
     150                 :          0 : {}
     151                 :            : 
     152                 :            : //------------------------------------------------------------------------------------
     153                 :          0 : void SvtFilePicker::prepareExecute()
     154                 :            : {
     155                 :            :     // set the default directory
     156                 :            :     // --**-- doesn't match the spec yet
     157                 :          0 :     if ( !m_aDisplayDirectory.isEmpty() || !m_aDefaultName.isEmpty() )
     158                 :            :     {
     159                 :          0 :         if ( !m_aDisplayDirectory.isEmpty() )
     160                 :            :         {
     161                 :            : 
     162                 :          0 :             INetURLObject aPath( m_aDisplayDirectory );
     163                 :          0 :             if ( !m_aDefaultName.isEmpty() )
     164                 :            :             {
     165                 :          0 :                 aPath.insertName( m_aDefaultName );
     166                 :          0 :                 getDialog()->SetHasFilename( true );
     167                 :            :             }
     168                 :          0 :             String sPath = aPath.GetMainURL( INetURLObject::NO_DECODE );
     169                 :          0 :             getDialog()->SetPath( aPath.GetMainURL( INetURLObject::NO_DECODE ) );
     170                 :            :         }
     171                 :          0 :         else if ( !m_aDefaultName.isEmpty() )
     172                 :            :         {
     173                 :          0 :             getDialog()->SetPath( m_aDefaultName );
     174                 :          0 :             getDialog()->SetHasFilename( true );
     175                 :            :         }
     176                 :            :     }
     177                 :            :     else
     178                 :            :     {
     179                 :            :         // Default-Standard-Dir setzen
     180                 :          0 :         INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
     181                 :          0 :         getDialog()->SetPath( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE ) );
     182                 :            :     }
     183                 :            : 
     184                 :            :     // set the control values and set the control labels, too
     185                 :          0 :     if ( m_pElemList && !m_pElemList->empty() )
     186                 :            :     {
     187                 :          0 :         ::svt::OControlAccess aAccess( getDialog(), getDialog()->GetView() );
     188                 :            : 
     189                 :          0 :         ElementList::iterator aListIter;
     190                 :          0 :         for ( aListIter = m_pElemList->begin();
     191                 :          0 :               aListIter != m_pElemList->end(); ++aListIter )
     192                 :            :         {
     193                 :          0 :             ElementEntry_Impl& rEntry = *aListIter;
     194                 :          0 :             if ( rEntry.m_bHasValue )
     195                 :          0 :                 aAccess.setValue( rEntry.m_nElementID, rEntry.m_nControlAction, rEntry.m_aValue );
     196                 :          0 :             if ( rEntry.m_bHasLabel )
     197                 :          0 :                 aAccess.setLabel( rEntry.m_nElementID, rEntry.m_aLabel );
     198                 :          0 :             if ( rEntry.m_bHasEnabled )
     199                 :          0 :                 aAccess.enableControl( rEntry.m_nElementID, rEntry.m_bEnabled );
     200                 :            :         }
     201                 :            : 
     202                 :          0 :         getDialog()->updateListboxLabelSizes();
     203                 :            :     }
     204                 :            : 
     205                 :          0 :     if ( m_pFilterList && !m_pFilterList->empty() )
     206                 :            :     {
     207                 :          0 :         for (   FilterList::iterator aListIter = m_pFilterList->begin();
     208                 :          0 :                 aListIter != m_pFilterList->end();
     209                 :            :                 ++aListIter
     210                 :            :             )
     211                 :            :         {
     212                 :          0 :             if ( aListIter->hasSubFilters() )
     213                 :            :             {   // it's a filter group
     214                 :          0 :                 UnoFilterList aSubFilters;
     215                 :          0 :                 aListIter->getSubFilters( aSubFilters );
     216                 :            : 
     217                 :          0 :                 getDialog()->AddFilterGroup( aListIter->getTitle(), aSubFilters );
     218                 :            :              }
     219                 :            :             else
     220                 :            :                 // it's a single filter
     221                 :          0 :                 getDialog()->AddFilter( aListIter->getTitle(), aListIter->getFilter() );
     222                 :            :         }
     223                 :            :     }
     224                 :            : 
     225                 :            :     // set the default filter
     226                 :          0 :     if ( !m_aCurrentFilter.isEmpty() )
     227                 :          0 :         getDialog()->SetCurFilter( m_aCurrentFilter );
     228                 :            : 
     229                 :          0 : }
     230                 :            : 
     231                 :            : //-----------------------------------------------------------------------------
     232                 :          0 : IMPL_LINK( SvtFilePicker, DialogClosedHdl, Dialog*, pDlg )
     233                 :            : {
     234                 :          0 :     if ( m_xDlgClosedListener.is() )
     235                 :            :     {
     236                 :          0 :         sal_Int16 nRet = static_cast< sal_Int16 >( pDlg->GetResult() );
     237                 :          0 :         ::com::sun::star::ui::dialogs::DialogClosedEvent aEvent( *this, nRet );
     238                 :          0 :         m_xDlgClosedListener->dialogClosed( aEvent );
     239                 :          0 :         m_xDlgClosedListener.clear();
     240                 :            :     }
     241                 :          0 :     return 0;
     242                 :            : }
     243                 :            : 
     244                 :            : //------------------------------------------------------------------------------------
     245                 :            : // SvtFilePicker
     246                 :            : //------------------------------------------------------------------------------------
     247                 :            : 
     248                 :            : //------------------------------------------------------------------------------------
     249                 :          0 : WinBits SvtFilePicker::getWinBits( WinBits& rExtraBits )
     250                 :            : {
     251                 :            :     // set the winbits for creating the filedialog
     252                 :          0 :     WinBits nBits = 0L;
     253                 :          0 :     rExtraBits = 0L;
     254                 :            : 
     255                 :            :     // set the standard bits acording to the service name
     256                 :          0 :     if ( m_nServiceType == TemplateDescription::FILEOPEN_SIMPLE )
     257                 :            :     {
     258                 :          0 :         nBits = WB_OPEN;
     259                 :            :     }
     260                 :          0 :     else if ( m_nServiceType == TemplateDescription::FILESAVE_SIMPLE )
     261                 :            :     {
     262                 :          0 :         nBits = WB_SAVEAS;
     263                 :            :     }
     264                 :          0 :     else if ( m_nServiceType == TemplateDescription::FILESAVE_AUTOEXTENSION )
     265                 :            :     {
     266                 :          0 :         nBits = WB_SAVEAS;
     267                 :          0 :         rExtraBits = SFX_EXTRA_AUTOEXTENSION;
     268                 :            :     }
     269                 :          0 :     else if ( m_nServiceType == TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD )
     270                 :            :     {
     271                 :          0 :         nBits = WB_SAVEAS | SFXWB_PASSWORD;
     272                 :          0 :         rExtraBits = SFX_EXTRA_AUTOEXTENSION;
     273                 :            :     }
     274                 :          0 :     else if ( m_nServiceType == TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS )
     275                 :            :     {
     276                 :          0 :         nBits = WB_SAVEAS | SFXWB_PASSWORD;
     277                 :          0 :         rExtraBits = SFX_EXTRA_AUTOEXTENSION | SFX_EXTRA_FILTEROPTIONS;
     278                 :            :     }
     279                 :          0 :     else if ( m_nServiceType == TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE )
     280                 :            :     {
     281                 :          0 :         nBits = WB_SAVEAS;
     282                 :          0 :         rExtraBits = SFX_EXTRA_AUTOEXTENSION | SFX_EXTRA_TEMPLATES;
     283                 :            :     }
     284                 :          0 :     else if ( m_nServiceType == TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION )
     285                 :            :     {
     286                 :          0 :         nBits = WB_SAVEAS;
     287                 :          0 :         rExtraBits = SFX_EXTRA_AUTOEXTENSION | SFX_EXTRA_SELECTION;
     288                 :            :     }
     289                 :            : 
     290                 :          0 :     else if ( m_nServiceType == TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE )
     291                 :            :     {
     292                 :          0 :         nBits = WB_OPEN;
     293                 :          0 :         rExtraBits = SFX_EXTRA_INSERTASLINK | SFX_EXTRA_SHOWPREVIEW | SFX_EXTRA_IMAGE_TEMPLATE;
     294                 :            :     }
     295                 :          0 :     else if ( m_nServiceType == TemplateDescription::FILEOPEN_PLAY )
     296                 :            :     {
     297                 :          0 :         nBits = WB_OPEN;
     298                 :          0 :         rExtraBits = SFX_EXTRA_PLAYBUTTON;
     299                 :            :     }
     300                 :          0 :     else if ( m_nServiceType == TemplateDescription::FILEOPEN_READONLY_VERSION )
     301                 :            :     {
     302                 :          0 :         nBits = WB_OPEN | SFXWB_READONLY;
     303                 :          0 :         rExtraBits = SFX_EXTRA_SHOWVERSIONS;
     304                 :            :     }
     305                 :          0 :     else if ( m_nServiceType == TemplateDescription::FILEOPEN_LINK_PREVIEW )
     306                 :            :     {
     307                 :          0 :         nBits = WB_OPEN;
     308                 :          0 :         rExtraBits = SFX_EXTRA_INSERTASLINK | SFX_EXTRA_SHOWPREVIEW;
     309                 :            :     }
     310                 :          0 :     if ( m_bMultiSelection && ( ( nBits & WB_OPEN ) == WB_OPEN ) )
     311                 :          0 :         nBits |= SFXWB_MULTISELECTION;
     312                 :            : 
     313                 :          0 :     return nBits;
     314                 :            : }
     315                 :            : 
     316                 :            : //------------------------------------------------------------------------------------
     317                 :          0 : void SvtFilePicker::notify( sal_Int16 _nEventId, sal_Int16 _nControlId )
     318                 :            : {
     319                 :          0 :     if ( !m_xListener.is() )
     320                 :          0 :         return;
     321                 :            : 
     322                 :          0 :     FilePickerEvent aEvent( *this, _nControlId );
     323                 :            : 
     324                 :          0 :     switch ( _nEventId )
     325                 :            :     {
     326                 :            :         case FILE_SELECTION_CHANGED:
     327                 :          0 :             m_xListener->fileSelectionChanged( aEvent );
     328                 :          0 :             break;
     329                 :            :         case DIRECTORY_CHANGED:
     330                 :          0 :             m_xListener->directoryChanged( aEvent );
     331                 :          0 :             break;
     332                 :            :         case HELP_REQUESTED:
     333                 :          0 :             m_xListener->helpRequested( aEvent );
     334                 :          0 :             break;
     335                 :            :         case CTRL_STATE_CHANGED:
     336                 :          0 :             m_xListener->controlStateChanged( aEvent );
     337                 :          0 :             break;
     338                 :            :         case DIALOG_SIZE_CHANGED:
     339                 :          0 :             m_xListener->dialogSizeChanged();
     340                 :          0 :             break;
     341                 :            :         default:
     342                 :            :             SAL_WARN( "fpicker.office", "SvtFilePicker::notify(): Unknown event id!" );
     343                 :          0 :             break;
     344                 :          0 :     }
     345                 :            : }
     346                 :            : 
     347                 :            : //------------------------------------------------------------------------------------
     348                 :            : namespace {
     349                 :            :     //................................................................................
     350                 :            :     struct FilterTitleMatch : public ::std::unary_function< FilterEntry, bool >
     351                 :            :     {
     352                 :            :     protected:
     353                 :            :         const ::rtl::OUString& rTitle;
     354                 :            : 
     355                 :            :     public:
     356                 :          0 :         FilterTitleMatch( const ::rtl::OUString& _rTitle ) : rTitle( _rTitle ) { }
     357                 :            : 
     358                 :            :         //............................................................................
     359                 :          0 :         bool operator () ( const FilterEntry& _rEntry )
     360                 :            :         {
     361                 :            :             sal_Bool bMatch;
     362                 :          0 :             if ( !_rEntry.hasSubFilters() )
     363                 :            :                 // a real filter
     364                 :          0 :                 bMatch = ( _rEntry.getTitle() == rTitle );
     365                 :            :             else
     366                 :            :                 // a filter group -> search the sub filters
     367                 :            :                 bMatch =
     368                 :          0 :                     _rEntry.endSubFilters() != ::std::find_if(
     369                 :            :                         _rEntry.beginSubFilters(),
     370                 :            :                         _rEntry.endSubFilters(),
     371                 :            :                         *this
     372                 :          0 :                     );
     373                 :            : 
     374                 :          0 :             return bMatch ? true : false;
     375                 :            :         }
     376                 :          0 :         bool operator () ( const UnoFilterEntry& _rEntry )
     377                 :            :         {
     378                 :          0 :             return _rEntry.First == rTitle ? true : false;
     379                 :            :         }
     380                 :            :     };
     381                 :            : }
     382                 :            : 
     383                 :            : //------------------------------------------------------------------------------------
     384                 :          0 : sal_Bool SvtFilePicker::FilterNameExists( const ::rtl::OUString& rTitle )
     385                 :            : {
     386                 :          0 :     sal_Bool bRet = sal_False;
     387                 :            : 
     388                 :          0 :     if ( m_pFilterList )
     389                 :            :         bRet =
     390                 :          0 :             m_pFilterList->end() != ::std::find_if(
     391                 :            :                 m_pFilterList->begin(),
     392                 :            :                 m_pFilterList->end(),
     393                 :            :                 FilterTitleMatch( rTitle )
     394                 :          0 :             );
     395                 :            : 
     396                 :          0 :     return bRet;
     397                 :            : }
     398                 :            : 
     399                 :            : //------------------------------------------------------------------------------------
     400                 :          0 : sal_Bool SvtFilePicker::FilterNameExists( const UnoFilterList& _rGroupedFilters )
     401                 :            : {
     402                 :          0 :     sal_Bool bRet = sal_False;
     403                 :            : 
     404                 :          0 :     if ( m_pFilterList )
     405                 :            :     {
     406                 :          0 :         const UnoFilterEntry* pStart = _rGroupedFilters.getConstArray();
     407                 :          0 :         const UnoFilterEntry* pEnd = pStart + _rGroupedFilters.getLength();
     408                 :          0 :         for ( ; pStart != pEnd; ++pStart )
     409                 :          0 :             if ( m_pFilterList->end() != ::std::find_if( m_pFilterList->begin(), m_pFilterList->end(), FilterTitleMatch( pStart->First ) ) )
     410                 :          0 :                 break;
     411                 :            : 
     412                 :          0 :         bRet = pStart != pEnd;
     413                 :            :     }
     414                 :            : 
     415                 :          0 :     return bRet;
     416                 :            : }
     417                 :            : 
     418                 :            : //------------------------------------------------------------------------------------
     419                 :          0 : void SvtFilePicker::ensureFilterList( const ::rtl::OUString& _rInitialCurrentFilter )
     420                 :            : {
     421                 :          0 :     if ( !m_pFilterList )
     422                 :            :     {
     423                 :          0 :         m_pFilterList = new FilterList;
     424                 :            : 
     425                 :            :         // set the first filter to the current filter
     426                 :          0 :         if ( m_aCurrentFilter.isEmpty() )
     427                 :          0 :             m_aCurrentFilter = _rInitialCurrentFilter;
     428                 :            :     }
     429                 :          0 : }
     430                 :            : 
     431                 :            : //------------------------------------------------------------------------------------
     432                 :            : // class SvtFilePicker
     433                 :            : //------------------------------------------------------------------------------------
     434                 :          0 : SvtFilePicker::SvtFilePicker( const Reference < XMultiServiceFactory >& xFactory )
     435                 :            :     :OCommonPicker( xFactory )
     436                 :            :     ,m_pFilterList      ( NULL )
     437                 :            :     ,m_pElemList        ( NULL )
     438                 :            :     ,m_bMultiSelection  ( sal_False )
     439                 :          0 :     ,m_nServiceType     ( TemplateDescription::FILEOPEN_SIMPLE )
     440                 :            : {
     441                 :          0 : }
     442                 :            : 
     443                 :          0 : SvtFilePicker::~SvtFilePicker()
     444                 :            : {
     445                 :          0 :     if ( m_pFilterList && !m_pFilterList->empty() )
     446                 :          0 :         m_pFilterList->erase( m_pFilterList->begin(), m_pFilterList->end() );
     447                 :          0 :     delete m_pFilterList;
     448                 :            : 
     449                 :          0 :     if ( m_pElemList && !m_pElemList->empty() )
     450                 :          0 :         m_pElemList->erase( m_pElemList->begin(), m_pElemList->end() );
     451                 :          0 :     delete m_pElemList;
     452                 :          0 : }
     453                 :            : 
     454                 :            : //------------------------------------------------------------------------------------
     455                 :          0 : sal_Int16 SvtFilePicker::implExecutePicker( )
     456                 :            : {
     457                 :          0 :     getDialog()->SetFileCallback( this );
     458                 :            : 
     459                 :          0 :     prepareExecute();
     460                 :            : 
     461                 :          0 :     getDialog()->EnableAutocompletion( sal_True );
     462                 :            :     // now we are ready to execute the dialog
     463                 :          0 :     sal_Int16 nRet = getDialog()->Execute();
     464                 :            : 
     465                 :            :     // the execution of the dialog yields, so it is possible the at this point the window or the dialog is closed
     466                 :          0 :     if ( getDialog() )
     467                 :          0 :         getDialog()->SetFileCallback( NULL );
     468                 :            : 
     469                 :          0 :     return nRet;
     470                 :            : }
     471                 :            : 
     472                 :            : //------------------------------------------------------------------------------------
     473                 :          0 : SvtFileDialog* SvtFilePicker::implCreateDialog( Window* _pParent )
     474                 :            : {
     475                 :            :     WinBits nExtraBits;
     476                 :          0 :     WinBits nBits = getWinBits( nExtraBits );
     477                 :            : 
     478                 :          0 :     SvtFileDialog* dialog = new SvtFileDialog( _pParent, nBits, nExtraBits );
     479                 :            : 
     480                 :            :     // Set StandardDir if present
     481                 :          0 :     if ( !m_aStandardDir.isEmpty())
     482                 :            :     {
     483                 :          0 :         String sStandardDir = String( m_aStandardDir );
     484                 :          0 :         dialog->SetStandardDir( sStandardDir );
     485                 :          0 :         dialog->SetBlackList( m_aBlackList );
     486                 :            :     }
     487                 :            : 
     488                 :          0 :     return dialog;
     489                 :            : }
     490                 :            : 
     491                 :            : //------------------------------------------------------------------------------------
     492                 :            : // disambiguate XInterface
     493                 :            : //------------------------------------------------------------------------------------
     494                 :          0 : IMPLEMENT_FORWARD_XINTERFACE2( SvtFilePicker, OCommonPicker, SvtFilePicker_Base )
     495                 :            : 
     496                 :            : //------------------------------------------------------------------------------------
     497                 :            : // disambiguate XTypeProvider
     498                 :            : //------------------------------------------------------------------------------------
     499                 :          0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvtFilePicker, OCommonPicker, SvtFilePicker_Base )
     500                 :            : 
     501                 :            : //------------------------------------------------------------------------------------
     502                 :            : // XExecutableDialog functions
     503                 :            : //------------------------------------------------------------------------------------
     504                 :            : 
     505                 :            : //------------------------------------------------------------------------------------
     506                 :          0 : void SAL_CALL SvtFilePicker::setTitle( const ::rtl::OUString& _rTitle ) throw (RuntimeException)
     507                 :            : {
     508                 :          0 :     OCommonPicker::setTitle( _rTitle );
     509                 :          0 : }
     510                 :            : 
     511                 :            : //------------------------------------------------------------------------------------
     512                 :          0 : sal_Int16 SAL_CALL SvtFilePicker::execute(  ) throw (RuntimeException)
     513                 :            : {
     514                 :          0 :     return OCommonPicker::execute();
     515                 :            : }
     516                 :            : 
     517                 :            : //------------------------------------------------------------------------------------
     518                 :            : // XAsynchronousExecutableDialog functions
     519                 :            : //------------------------------------------------------------------------------------
     520                 :            : 
     521                 :            : //------------------------------------------------------------------------------------
     522                 :          0 : void SAL_CALL SvtFilePicker::setDialogTitle( const ::rtl::OUString& _rTitle ) throw (RuntimeException)
     523                 :            : {
     524                 :          0 :     setTitle( _rTitle );
     525                 :          0 : }
     526                 :            : 
     527                 :            : //------------------------------------------------------------------------------------
     528                 :          0 : void SAL_CALL SvtFilePicker::startExecuteModal( const Reference< ::com::sun::star::ui::dialogs::XDialogClosedListener >& xListener ) throw (RuntimeException)
     529                 :            : {
     530                 :          0 :     m_xDlgClosedListener = xListener;
     531                 :          0 :     prepareDialog();
     532                 :          0 :     prepareExecute();
     533                 :          0 :     getDialog()->EnableAutocompletion( sal_True );
     534                 :          0 :     getDialog()->StartExecuteModal( LINK( this, SvtFilePicker, DialogClosedHdl ) );
     535                 :          0 : }
     536                 :            : 
     537                 :            : //------------------------------------------------------------------------------------
     538                 :            : // XFilePicker functions
     539                 :            : //------------------------------------------------------------------------------------
     540                 :            : 
     541                 :          0 : void SAL_CALL SvtFilePicker::setMultiSelectionMode( sal_Bool bMode ) throw( RuntimeException )
     542                 :            : {
     543                 :          0 :     checkAlive();
     544                 :            : 
     545                 :          0 :     SolarMutexGuard aGuard;
     546                 :          0 :     m_bMultiSelection = bMode;
     547                 :          0 : }
     548                 :            : 
     549                 :          0 : void SAL_CALL SvtFilePicker::setDefaultName( const rtl::OUString& aName ) throw( RuntimeException )
     550                 :            : {
     551                 :          0 :     checkAlive();
     552                 :            : 
     553                 :          0 :     SolarMutexGuard aGuard;
     554                 :          0 :     m_aDefaultName = aName;
     555                 :          0 : }
     556                 :            : 
     557                 :          0 : void SAL_CALL SvtFilePicker::setDisplayDirectory( const rtl::OUString& aDirectory )
     558                 :            :     throw( IllegalArgumentException, RuntimeException )
     559                 :            : {
     560                 :          0 :     checkAlive();
     561                 :            : 
     562                 :          0 :     SolarMutexGuard aGuard;
     563                 :          0 :     m_aDisplayDirectory = aDirectory;
     564                 :          0 : }
     565                 :            : 
     566                 :          0 : rtl::OUString SAL_CALL SvtFilePicker::getDisplayDirectory() throw( RuntimeException )
     567                 :            : {
     568                 :          0 :     checkAlive();
     569                 :            : 
     570                 :          0 :     SolarMutexGuard aGuard;
     571                 :          0 :     if ( getDialog() )
     572                 :            :     {
     573                 :          0 :         rtl::OUString aPath = getDialog()->GetPath();
     574                 :            : 
     575                 :            :         // #97148# ----
     576                 :          0 :         if( m_aOldHideDirectory == aPath )
     577                 :          0 :             return m_aOldDisplayDirectory;
     578                 :          0 :         m_aOldHideDirectory = aPath;
     579                 :            : 
     580                 :            :         // #102204# -----
     581                 :          0 :         if( !getDialog()->ContentIsFolder( aPath ) )
     582                 :            :         {
     583                 :          0 :             INetURLObject aFolder( aPath );
     584                 :          0 :             aFolder.CutLastName();
     585                 :          0 :             aPath = aFolder.GetMainURL( INetURLObject::NO_DECODE );
     586                 :            :         }
     587                 :          0 :         m_aOldDisplayDirectory = aPath;
     588                 :          0 :         return aPath;
     589                 :            :     }
     590                 :            :     else
     591                 :          0 :         return m_aDisplayDirectory;
     592                 :            : }
     593                 :            : 
     594                 :          0 : Sequence< rtl::OUString > SAL_CALL SvtFilePicker::getFiles() throw( RuntimeException )
     595                 :            : {
     596                 :          0 :     checkAlive();
     597                 :            : 
     598                 :          0 :     SolarMutexGuard aGuard;
     599                 :          0 :     if ( ! getDialog() )
     600                 :            :     {
     601                 :          0 :         Sequence< rtl::OUString > aEmpty;
     602                 :          0 :         return aEmpty;
     603                 :            :     }
     604                 :            : 
     605                 :            :     // if there is more than one path we have to return the path to the
     606                 :            :     // files first and then the list of the selected entries
     607                 :            : 
     608                 :          0 :     std::vector<rtl::OUString> aPathList(getDialog()->GetPathList());
     609                 :          0 :     size_t nCount = aPathList.size();
     610                 :          0 :     size_t nTotal = nCount > 1 ? nCount+1: nCount;
     611                 :            : 
     612                 :          0 :     Sequence< rtl::OUString > aPath( nTotal );
     613                 :            : 
     614                 :          0 :     if ( nCount == 1 )
     615                 :          0 :         aPath[0] = rtl::OUString(aPathList[0]);
     616                 :          0 :     else if ( nCount > 1 )
     617                 :            :     {
     618                 :          0 :         INetURLObject aObj(aPathList[0]);
     619                 :          0 :         aObj.removeSegment();
     620                 :          0 :         aPath[0] = aObj.GetMainURL( INetURLObject::NO_DECODE );
     621                 :            : 
     622                 :          0 :         for(size_t i = 0; i < aPathList.size(); ++i)
     623                 :            :         {
     624                 :          0 :             aObj.SetURL(aPathList[i]);
     625                 :          0 :             aPath[i] = aObj.getName();
     626                 :          0 :         }
     627                 :            :     }
     628                 :            : 
     629                 :          0 :     return aPath;
     630                 :            : }
     631                 :            : 
     632                 :            : //------------------------------------------------------------------------------------
     633                 :            : // XFilePickerControlAccess functions
     634                 :            : //------------------------------------------------------------------------------------
     635                 :            : 
     636                 :          0 : void SAL_CALL SvtFilePicker::setValue( sal_Int16 nElementID,
     637                 :            :                                        sal_Int16 nControlAction,
     638                 :            :                                        const Any& rValue )
     639                 :            :     throw( RuntimeException )
     640                 :            : {
     641                 :          0 :     checkAlive();
     642                 :            : 
     643                 :          0 :     SolarMutexGuard aGuard;
     644                 :          0 :     if ( getDialog() )
     645                 :            :     {
     646                 :          0 :         ::svt::OControlAccess aAccess( getDialog(), getDialog()->GetView() );
     647                 :          0 :         aAccess.setValue( nElementID, nControlAction, rValue );
     648                 :            :     }
     649                 :            :     else
     650                 :            :     {
     651                 :          0 :         if ( !m_pElemList )
     652                 :          0 :             m_pElemList = new ElementList;
     653                 :            : 
     654                 :          0 :         sal_Bool bFound = sal_False;
     655                 :          0 :         ElementList::iterator aListIter;
     656                 :            : 
     657                 :          0 :         for ( aListIter = m_pElemList->begin();
     658                 :          0 :               aListIter != m_pElemList->end(); ++aListIter )
     659                 :            :         {
     660                 :          0 :             ElementEntry_Impl& rEntry = *aListIter;
     661                 :          0 :             if ( ( rEntry.m_nElementID == nElementID ) &&
     662                 :          0 :                  ( !rEntry.m_bHasValue || ( rEntry.m_nControlAction == nControlAction ) ) )
     663                 :            :             {
     664                 :          0 :                 rEntry.setAction( nControlAction );
     665                 :          0 :                 rEntry.setValue( rValue );
     666                 :          0 :                 bFound = sal_True;
     667                 :            :             }
     668                 :            :         }
     669                 :            : 
     670                 :          0 :         if ( !bFound )
     671                 :            :         {
     672                 :          0 :             ElementEntry_Impl aNew( nElementID );
     673                 :          0 :             aNew.setAction( nControlAction );
     674                 :          0 :             aNew.setValue( rValue );
     675                 :          0 :             m_pElemList->insert( m_pElemList->end(), aNew );
     676                 :            :         }
     677                 :          0 :     }
     678                 :          0 : }
     679                 :            : 
     680                 :            : //------------------------------------------------------------------------------------
     681                 :            : 
     682                 :          0 : Any SAL_CALL SvtFilePicker::getValue( sal_Int16 nElementID, sal_Int16 nControlAction )
     683                 :            :     throw( RuntimeException )
     684                 :            : {
     685                 :          0 :     checkAlive();
     686                 :            : 
     687                 :          0 :     SolarMutexGuard aGuard;
     688                 :          0 :     Any      aAny;
     689                 :            : 
     690                 :            :     // execute() called?
     691                 :          0 :     if ( getDialog() )
     692                 :            :     {
     693                 :          0 :         ::svt::OControlAccess aAccess( getDialog(), getDialog()->GetView() );
     694                 :          0 :         aAny = aAccess.getValue( nElementID, nControlAction );
     695                 :            :     }
     696                 :          0 :     else if ( m_pElemList && !m_pElemList->empty() )
     697                 :            :     {
     698                 :          0 :         ElementList::iterator aListIter;
     699                 :          0 :         for ( aListIter = m_pElemList->begin();
     700                 :          0 :               aListIter != m_pElemList->end(); ++aListIter )
     701                 :            :         {
     702                 :          0 :             ElementEntry_Impl& rEntry = *aListIter;
     703                 :          0 :             if ( ( rEntry.m_nElementID == nElementID ) &&
     704                 :            :                  ( rEntry.m_bHasValue ) &&
     705                 :            :                  ( rEntry.m_nControlAction == nControlAction ) )
     706                 :            :             {
     707                 :          0 :                 aAny = rEntry.m_aValue;
     708                 :          0 :                 break;
     709                 :            :             }
     710                 :            :         }
     711                 :            :     }
     712                 :            : 
     713                 :          0 :     return aAny;
     714                 :            : }
     715                 :            : 
     716                 :            : 
     717                 :            : //------------------------------------------------------------------------------------
     718                 :          0 : void SAL_CALL SvtFilePicker::setLabel( sal_Int16 nLabelID, const rtl::OUString& rValue )
     719                 :            :     throw ( RuntimeException )
     720                 :            : {
     721                 :          0 :     checkAlive();
     722                 :            : 
     723                 :          0 :     SolarMutexGuard aGuard;
     724                 :          0 :     if ( getDialog() )
     725                 :            :     {
     726                 :          0 :         ::svt::OControlAccess aAccess( getDialog(), getDialog()->GetView() );
     727                 :          0 :         aAccess.setLabel( nLabelID, rValue );
     728                 :            :     }
     729                 :            :     else
     730                 :            :     {
     731                 :          0 :         if ( !m_pElemList )
     732                 :          0 :             m_pElemList = new ElementList;
     733                 :            : 
     734                 :          0 :         sal_Bool bFound = sal_False;
     735                 :          0 :         ElementList::iterator aListIter;
     736                 :            : 
     737                 :          0 :         for ( aListIter = m_pElemList->begin();
     738                 :          0 :               aListIter != m_pElemList->end(); ++aListIter )
     739                 :            :         {
     740                 :          0 :             ElementEntry_Impl& rEntry = *aListIter;
     741                 :          0 :             if ( rEntry.m_nElementID == nLabelID )
     742                 :            :             {
     743                 :          0 :                 rEntry.setLabel( rValue );
     744                 :          0 :                 bFound = sal_True;
     745                 :            :             }
     746                 :            :         }
     747                 :            : 
     748                 :          0 :         if ( !bFound )
     749                 :            :         {
     750                 :          0 :             ElementEntry_Impl aNew( nLabelID );
     751                 :          0 :             aNew.setLabel( rValue );
     752                 :          0 :             m_pElemList->insert( m_pElemList->end(), aNew );
     753                 :            :         }
     754                 :          0 :     }
     755                 :          0 : }
     756                 :            : 
     757                 :            : //------------------------------------------------------------------------------------
     758                 :          0 : rtl::OUString SAL_CALL SvtFilePicker::getLabel( sal_Int16 nLabelID )
     759                 :            :     throw ( RuntimeException )
     760                 :            : {
     761                 :          0 :     checkAlive();
     762                 :            : 
     763                 :          0 :     SolarMutexGuard aGuard;
     764                 :          0 :     rtl::OUString aLabel;
     765                 :            : 
     766                 :          0 :     if ( getDialog() )
     767                 :            :     {
     768                 :          0 :         ::svt::OControlAccess aAccess( getDialog(), getDialog()->GetView() );
     769                 :          0 :         aLabel = aAccess.getLabel( nLabelID );
     770                 :            :     }
     771                 :          0 :     else if ( m_pElemList && !m_pElemList->empty() )
     772                 :            :     {
     773                 :          0 :         ElementList::iterator aListIter;
     774                 :          0 :         for ( aListIter = m_pElemList->begin();
     775                 :          0 :               aListIter != m_pElemList->end(); ++aListIter )
     776                 :            :         {
     777                 :          0 :             ElementEntry_Impl& rEntry = *aListIter;
     778                 :          0 :             if ( rEntry.m_nElementID == nLabelID )
     779                 :            :             {
     780                 :          0 :                 if ( rEntry.m_bHasLabel )
     781                 :          0 :                     aLabel = rEntry.m_aLabel;
     782                 :          0 :                 break;
     783                 :            :             }
     784                 :            :         }
     785                 :            :     }
     786                 :            : 
     787                 :          0 :     return aLabel;
     788                 :            : }
     789                 :            : 
     790                 :            : //------------------------------------------------------------------------------------
     791                 :          0 : void SAL_CALL SvtFilePicker::enableControl( sal_Int16 nElementID, sal_Bool bEnable )
     792                 :            :     throw( RuntimeException )
     793                 :            : {
     794                 :          0 :     checkAlive();
     795                 :            : 
     796                 :          0 :     SolarMutexGuard aGuard;
     797                 :          0 :     if ( getDialog() )
     798                 :            :     {
     799                 :          0 :         ::svt::OControlAccess aAccess( getDialog(), getDialog()->GetView() );
     800                 :          0 :         aAccess.enableControl( nElementID, bEnable );
     801                 :            :     }
     802                 :            :     else
     803                 :            :     {
     804                 :          0 :         if ( !m_pElemList )
     805                 :          0 :             m_pElemList = new ElementList;
     806                 :            : 
     807                 :          0 :         sal_Bool bFound = sal_False;
     808                 :          0 :         ElementList::iterator aListIter;
     809                 :            : 
     810                 :          0 :         for ( aListIter = m_pElemList->begin();
     811                 :          0 :               aListIter != m_pElemList->end(); ++aListIter )
     812                 :            :         {
     813                 :          0 :             ElementEntry_Impl& rEntry = *aListIter;
     814                 :          0 :             if ( rEntry.m_nElementID == nElementID )
     815                 :            :             {
     816                 :          0 :                 rEntry.setEnabled( bEnable );
     817                 :          0 :                 bFound = sal_True;
     818                 :            :             }
     819                 :            :         }
     820                 :            : 
     821                 :          0 :         if ( !bFound )
     822                 :            :         {
     823                 :          0 :             ElementEntry_Impl aNew( nElementID );
     824                 :          0 :             aNew.setEnabled( bEnable );
     825                 :          0 :             m_pElemList->insert( m_pElemList->end(), aNew );
     826                 :            :         }
     827                 :          0 :     }
     828                 :          0 : }
     829                 :            : 
     830                 :            : //------------------------------------------------------------------------------------
     831                 :            : // XFilePickerNotifier functions
     832                 :            : //------------------------------------------------------------------------------------
     833                 :            : 
     834                 :          0 : void SAL_CALL SvtFilePicker::addFilePickerListener( const Reference< XFilePickerListener >& xListener ) throw ( RuntimeException )
     835                 :            : {
     836                 :          0 :     checkAlive();
     837                 :            : 
     838                 :          0 :     SolarMutexGuard aGuard;
     839                 :          0 :     m_xListener = xListener;
     840                 :          0 : }
     841                 :            : 
     842                 :            : //------------------------------------------------------------------------------------
     843                 :          0 : void SAL_CALL SvtFilePicker::removeFilePickerListener( const Reference< XFilePickerListener >& ) throw ( RuntimeException )
     844                 :            : {
     845                 :          0 :     checkAlive();
     846                 :            : 
     847                 :          0 :     SolarMutexGuard aGuard;
     848                 :          0 :     m_xListener.clear();
     849                 :          0 : }
     850                 :            : 
     851                 :            : //------------------------------------------------------------------------------------
     852                 :            : // XFilePreview functions
     853                 :            : //------------------------------------------------------------------------------------
     854                 :            : 
     855                 :          0 : Sequence< sal_Int16 > SAL_CALL SvtFilePicker::getSupportedImageFormats()
     856                 :            :     throw ( RuntimeException )
     857                 :            : {
     858                 :          0 :     checkAlive();
     859                 :            : 
     860                 :          0 :     SolarMutexGuard aGuard;
     861                 :          0 :     Sequence< sal_Int16 > aFormats( 1 );
     862                 :            : 
     863                 :          0 :     aFormats[0] = FilePreviewImageFormats::BITMAP;
     864                 :            : 
     865                 :          0 :     return aFormats;
     866                 :            : }
     867                 :            : 
     868                 :            : //------------------------------------------------------------------------------------
     869                 :          0 : sal_Int32 SAL_CALL SvtFilePicker::getTargetColorDepth() throw ( RuntimeException )
     870                 :            : {
     871                 :          0 :     checkAlive();
     872                 :            : 
     873                 :          0 :     SolarMutexGuard aGuard;
     874                 :          0 :     sal_Int32 nDepth = 0;
     875                 :            : 
     876                 :          0 :     if ( getDialog() )
     877                 :          0 :         nDepth = getDialog()->getTargetColorDepth();
     878                 :            : 
     879                 :          0 :     return nDepth;
     880                 :            : }
     881                 :            : 
     882                 :            : //------------------------------------------------------------------------------------
     883                 :          0 : sal_Int32 SAL_CALL SvtFilePicker::getAvailableWidth() throw ( RuntimeException )
     884                 :            : {
     885                 :          0 :     checkAlive();
     886                 :            : 
     887                 :          0 :     SolarMutexGuard aGuard;
     888                 :          0 :     sal_Int32 nWidth = 0;
     889                 :            : 
     890                 :          0 :     if ( getDialog() )
     891                 :          0 :         nWidth = getDialog()->getAvailableWidth();
     892                 :            : 
     893                 :          0 :     return nWidth;
     894                 :            : }
     895                 :            : 
     896                 :            : //------------------------------------------------------------------------------------
     897                 :          0 : sal_Int32 SAL_CALL SvtFilePicker::getAvailableHeight() throw ( RuntimeException )
     898                 :            : {
     899                 :          0 :     checkAlive();
     900                 :            : 
     901                 :          0 :     SolarMutexGuard aGuard;
     902                 :          0 :     sal_Int32 nHeigth = 0;
     903                 :            : 
     904                 :          0 :     if ( getDialog() )
     905                 :          0 :         nHeigth = getDialog()->getAvailableHeight();
     906                 :            : 
     907                 :          0 :     return nHeigth;
     908                 :            : }
     909                 :            : 
     910                 :            : //------------------------------------------------------------------------------------
     911                 :          0 : void SAL_CALL SvtFilePicker::setImage( sal_Int16 aImageFormat, const Any& rImage )
     912                 :            :     throw ( IllegalArgumentException, RuntimeException )
     913                 :            : {
     914                 :          0 :     checkAlive();
     915                 :            : 
     916                 :          0 :     SolarMutexGuard aGuard;
     917                 :          0 :     if ( getDialog() )
     918                 :          0 :         getDialog()->setImage( aImageFormat, rImage );
     919                 :          0 : }
     920                 :            : 
     921                 :            : //------------------------------------------------------------------------------------
     922                 :          0 : sal_Bool SAL_CALL SvtFilePicker::setShowState( sal_Bool bShowState )
     923                 :            :     throw ( RuntimeException )
     924                 :            : {
     925                 :          0 :     checkAlive();
     926                 :            : 
     927                 :          0 :     SolarMutexGuard aGuard;
     928                 :          0 :     sal_Bool bRet = sal_False;
     929                 :            : 
     930                 :          0 :     if ( getDialog() )
     931                 :          0 :         bRet = getDialog()->setShowState( bShowState );
     932                 :            : 
     933                 :          0 :     return bRet;
     934                 :            : }
     935                 :            : 
     936                 :            : //------------------------------------------------------------------------------------
     937                 :          0 : sal_Bool SAL_CALL SvtFilePicker::getShowState() throw ( RuntimeException )
     938                 :            : {
     939                 :          0 :     checkAlive();
     940                 :            : 
     941                 :          0 :     SolarMutexGuard aGuard;
     942                 :          0 :     sal_Bool bRet = sal_False;
     943                 :            : 
     944                 :          0 :     if ( getDialog() )
     945                 :          0 :         bRet = getDialog()->getShowState();
     946                 :            : 
     947                 :          0 :     return bRet;
     948                 :            : }
     949                 :            : 
     950                 :            : //------------------------------------------------------------------------------------
     951                 :            : // XFilterGroupManager functions
     952                 :            : //------------------------------------------------------------------------------------
     953                 :            : 
     954                 :          0 : void SAL_CALL SvtFilePicker::appendFilterGroup( const ::rtl::OUString& sGroupTitle,
     955                 :            :                                                 const Sequence< StringPair >& aFilters )
     956                 :            :     throw ( IllegalArgumentException, RuntimeException )
     957                 :            : {
     958                 :          0 :     checkAlive();
     959                 :            : 
     960                 :          0 :     SolarMutexGuard aGuard;
     961                 :            : 
     962                 :            :     // check the names
     963                 :          0 :     if ( FilterNameExists( aFilters ) )
     964                 :            :         throw IllegalArgumentException(
     965                 :            :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("filter name exists")),
     966                 :          0 :             static_cast< OWeakObject * >(this), 1);
     967                 :            : 
     968                 :            :     // ensure that we have a filter list
     969                 :          0 :     ::rtl::OUString sInitialCurrentFilter;
     970                 :          0 :     if ( aFilters.getLength() )
     971                 :          0 :         sInitialCurrentFilter = aFilters[0].First;
     972                 :          0 :     ensureFilterList( sInitialCurrentFilter );
     973                 :            : 
     974                 :            :     // append the filter
     975                 :          0 :     m_pFilterList->insert( m_pFilterList->end(), FilterEntry( sGroupTitle, aFilters ) );
     976                 :          0 : }
     977                 :            : 
     978                 :            : //------------------------------------------------------------------------------------
     979                 :            : // XFilterManager functions
     980                 :            : //------------------------------------------------------------------------------------
     981                 :            : 
     982                 :          0 : void SAL_CALL SvtFilePicker::appendFilter( const rtl::OUString& aTitle,
     983                 :            :                                            const rtl::OUString& aFilter )
     984                 :            :     throw( IllegalArgumentException, RuntimeException )
     985                 :            : {
     986                 :          0 :     checkAlive();
     987                 :            : 
     988                 :          0 :     SolarMutexGuard aGuard;
     989                 :            :     // check the name
     990                 :          0 :     if ( FilterNameExists( aTitle ) )
     991                 :            :         // TODO: a more precise exception message
     992                 :          0 :         throw IllegalArgumentException();
     993                 :            : 
     994                 :            :     // ensure that we have a filter list
     995                 :          0 :     ensureFilterList( aTitle );
     996                 :            : 
     997                 :            :     // append the filter
     998                 :          0 :     m_pFilterList->insert( m_pFilterList->end(), FilterEntry( aTitle, aFilter ) );
     999                 :          0 : }
    1000                 :            : 
    1001                 :            : //------------------------------------------------------------------------------------
    1002                 :          0 : void SAL_CALL SvtFilePicker::setCurrentFilter( const rtl::OUString& aTitle )
    1003                 :            :     throw( IllegalArgumentException, RuntimeException )
    1004                 :            : {
    1005                 :          0 :     checkAlive();
    1006                 :            : 
    1007                 :          0 :     SolarMutexGuard aGuard;
    1008                 :          0 :     if ( ! FilterNameExists( aTitle ) )
    1009                 :          0 :         throw IllegalArgumentException();
    1010                 :            : 
    1011                 :          0 :     m_aCurrentFilter = aTitle;
    1012                 :            : 
    1013                 :          0 :     if ( getDialog() )
    1014                 :          0 :         getDialog()->SetCurFilter( aTitle );
    1015                 :          0 : }
    1016                 :            : 
    1017                 :            : //------------------------------------------------------------------------------------
    1018                 :          0 : rtl::OUString SAL_CALL SvtFilePicker::getCurrentFilter()
    1019                 :            :     throw( RuntimeException )
    1020                 :            : {
    1021                 :          0 :     checkAlive();
    1022                 :            : 
    1023                 :          0 :     SolarMutexGuard aGuard;
    1024                 :          0 :     rtl::OUString aFilter = getDialog() ? rtl::OUString( getDialog()->GetCurFilter() ) :
    1025                 :          0 :                                             rtl::OUString( m_aCurrentFilter );
    1026                 :          0 :     return aFilter;
    1027                 :            : }
    1028                 :            : 
    1029                 :            : 
    1030                 :            : //------------------------------------------------------------------------------------
    1031                 :            : // XInitialization functions
    1032                 :            : //------------------------------------------------------------------------------------
    1033                 :            : 
    1034                 :          0 : void SAL_CALL SvtFilePicker::initialize( const Sequence< Any >& _rArguments )
    1035                 :            :     throw ( Exception, RuntimeException )
    1036                 :            : {
    1037                 :          0 :     checkAlive();
    1038                 :            : 
    1039                 :          0 :     Sequence< Any > aArguments( _rArguments.getLength());
    1040                 :            : 
    1041                 :          0 :     m_nServiceType = TemplateDescription::FILEOPEN_SIMPLE;
    1042                 :            : 
    1043                 :          0 :     if ( _rArguments.getLength() >= 1 )
    1044                 :            :     {
    1045                 :            :         // compatibility: one argument, type sal_Int16 , specifies the service type
    1046                 :          0 :         int index = 0;
    1047                 :            : 
    1048                 :          0 :         if (_rArguments[0] >>= m_nServiceType)
    1049                 :            :         {
    1050                 :            :             // skip the first entry if it was the ServiceType, because it's not needed in OCommonPicker::initialize and it's not a NamedValue
    1051                 :          0 :             NamedValue emptyNamedValue;
    1052                 :          0 :             aArguments[0] <<= emptyNamedValue;
    1053                 :          0 :             index = 1;
    1054                 :            : 
    1055                 :            :         }
    1056                 :          0 :         for ( int i = index; i < _rArguments.getLength(); i++)
    1057                 :            :         {
    1058                 :          0 :             NamedValue namedValue;
    1059                 :          0 :             aArguments[i] <<= _rArguments[i];
    1060                 :            : 
    1061                 :          0 :             if (aArguments[i] >>= namedValue )
    1062                 :            :             {
    1063                 :            : 
    1064                 :          0 :                 if ( namedValue.Name == "StandardDir" )
    1065                 :            :                 {
    1066                 :          0 :                     ::rtl::OUString sStandardDir;
    1067                 :            : 
    1068                 :          0 :                     namedValue.Value >>= sStandardDir;
    1069                 :            : 
    1070                 :            :                     // Set the directory for the "back to the default dir" button
    1071                 :          0 :                         if ( !sStandardDir.isEmpty() )
    1072                 :            :                     {
    1073                 :          0 :                         m_aStandardDir = sStandardDir;
    1074                 :          0 :                     }
    1075                 :            :                 }
    1076                 :          0 :                 else if ( namedValue.Name == "BlackList" )
    1077                 :            :                 {
    1078                 :          0 :                     namedValue.Value >>= m_aBlackList;
    1079                 :            :                 }
    1080                 :            :             }
    1081                 :          0 :         }
    1082                 :            :     }
    1083                 :            : 
    1084                 :            :     // let the base class analyze the sequence (will call into implHandleInitializationArgument)
    1085                 :          0 :     OCommonPicker::initialize( aArguments );
    1086                 :          0 : }
    1087                 :            : 
    1088                 :            : //-------------------------------------------------------------------------
    1089                 :          0 : sal_Bool SvtFilePicker::implHandleInitializationArgument( const ::rtl::OUString& _rName, const Any& _rValue ) SAL_THROW( ( Exception, RuntimeException ) )
    1090                 :            : {
    1091                 :          0 :     if ( _rName == "TemplateDescription" )
    1092                 :            :     {
    1093                 :          0 :         m_nServiceType = TemplateDescription::FILEOPEN_SIMPLE;
    1094                 :          0 :         OSL_VERIFY( _rValue >>= m_nServiceType );
    1095                 :          0 :         return sal_True;
    1096                 :            :     }
    1097                 :          0 :     if ( _rName == "StandardDir" )
    1098                 :            :     {
    1099                 :          0 :         OSL_VERIFY( _rValue >>= m_aStandardDir );
    1100                 :          0 :         return sal_True;
    1101                 :            :     }
    1102                 :            : 
    1103                 :          0 :     if ( _rName == "BlackList" )
    1104                 :            :     {
    1105                 :          0 :         OSL_VERIFY( _rValue >>= m_aBlackList );
    1106                 :          0 :         return sal_True;
    1107                 :            :     }
    1108                 :            : 
    1109                 :            : 
    1110                 :            : 
    1111                 :          0 :     return OCommonPicker::implHandleInitializationArgument( _rName, _rValue );
    1112                 :            : }
    1113                 :            : 
    1114                 :            : //------------------------------------------------------------------------------------
    1115                 :            : // XServiceInfo
    1116                 :            : //------------------------------------------------------------------------------------
    1117                 :            : 
    1118                 :            : /* XServiceInfo */
    1119                 :          0 : rtl::OUString SAL_CALL SvtFilePicker::getImplementationName() throw( RuntimeException )
    1120                 :            : {
    1121                 :          0 :     return impl_getStaticImplementationName();
    1122                 :            : }
    1123                 :            : 
    1124                 :            : /* XServiceInfo */
    1125                 :          0 : sal_Bool SAL_CALL SvtFilePicker::supportsService( const rtl::OUString& sServiceName ) throw( RuntimeException )
    1126                 :            : {
    1127                 :          0 :     Sequence< rtl::OUString > seqServiceNames = getSupportedServiceNames();
    1128                 :          0 :     const rtl::OUString* pArray = seqServiceNames.getConstArray();
    1129                 :          0 :     for ( sal_Int32 i = 0; i < seqServiceNames.getLength(); i++ )
    1130                 :            :     {
    1131                 :          0 :         if ( sServiceName == pArray[i] )
    1132                 :            :         {
    1133                 :          0 :             return sal_True ;
    1134                 :            :         }
    1135                 :            :     }
    1136                 :          0 :     return sal_False ;
    1137                 :            : }
    1138                 :            : 
    1139                 :            : /* XServiceInfo */
    1140                 :          0 : Sequence< rtl::OUString > SAL_CALL SvtFilePicker::getSupportedServiceNames() throw( RuntimeException )
    1141                 :            : {
    1142                 :          0 :     return impl_getStaticSupportedServiceNames();
    1143                 :            : }
    1144                 :            : 
    1145                 :            : /* Helper for XServiceInfo */
    1146                 :          0 : Sequence< rtl::OUString > SvtFilePicker::impl_getStaticSupportedServiceNames()
    1147                 :            : {
    1148                 :          0 :     Sequence< rtl::OUString > seqServiceNames( 1 );
    1149                 :          0 :     rtl::OUString* pArray = seqServiceNames.getArray();
    1150                 :          0 :     pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.OfficeFilePicker" ));
    1151                 :          0 :     return seqServiceNames ;
    1152                 :            : }
    1153                 :            : 
    1154                 :            : /* Helper for XServiceInfo */
    1155                 :          0 : rtl::OUString SvtFilePicker::impl_getStaticImplementationName()
    1156                 :            : {
    1157                 :          0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.svtools.OfficeFilePicker" ));
    1158                 :            : }
    1159                 :            : 
    1160                 :            : /* Helper for registry */
    1161                 :          0 : Reference< XInterface > SAL_CALL SvtFilePicker::impl_createInstance(
    1162                 :            :     const Reference< XComponentContext >& rxContext) throw( Exception )
    1163                 :            : {
    1164                 :          0 :     Reference< XMultiServiceFactory > xServiceManager (rxContext->getServiceManager(), UNO_QUERY_THROW);
    1165                 :          0 :     return Reference< XInterface >( *new SvtFilePicker( xServiceManager ) );
    1166                 :            : }
    1167                 :            : 
    1168                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10