LCOV - code coverage report
Current view: top level - fpicker/source/office - OfficeControlAccess.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 263 0.0 %
Date: 2012-08-25 Functions: 0 24 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 <sal/macros.h>
      22                 :            : #include "OfficeControlAccess.hxx"
      23                 :            : #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
      24                 :            : #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
      25                 :            : #include <com/sun/star/ui/dialogs/ControlActions.hpp>
      26                 :            : #include <vcl/lstbox.hxx>
      27                 :            : #include <com/sun/star/uno/Sequence.hxx>
      28                 :            : #include <tools/urlobj.hxx>
      29                 :            : 
      30                 :            : #include <algorithm>
      31                 :            : #include <functional>
      32                 :            : 
      33                 :            : //.........................................................................
      34                 :            : namespace svt
      35                 :            : {
      36                 :            : //.........................................................................
      37                 :            : 
      38                 :            :     // helper -------------------------------------------------------------
      39                 :            : 
      40                 :            :     using namespace ::com::sun::star::uno;
      41                 :            :     using namespace ::com::sun::star::lang;
      42                 :            :     using namespace ::com::sun::star::ui::dialogs;
      43                 :            : 
      44                 :            :     using namespace ExtendedFilePickerElementIds;
      45                 :            :     using namespace CommonFilePickerElementIds;
      46                 :            :     using namespace InternalFilePickerElementIds;
      47                 :            : 
      48                 :            :     // --------------------------------------------------------------------
      49                 :            :     namespace
      50                 :            :     {
      51                 :            :         // ----------------------------------------------------------------
      52                 :            :         #define PROPERTY_FLAG_TEXT                  0x00000001
      53                 :            :         #define PROPERTY_FLAG_ENDBALED              0x00000002
      54                 :            :         #define PROPERTY_FLAG_VISIBLE               0x00000004
      55                 :            :         #define PROPERTY_FLAG_HELPURL               0x00000008
      56                 :            :         #define PROPERTY_FLAG_LISTITEMS             0x00000010
      57                 :            :         #define PROPERTY_FLAG_SELECTEDITEM          0x00000020
      58                 :            :         #define PROPERTY_FLAG_SELECTEDITEMINDEX     0x00000040
      59                 :            :         #define PROPERTY_FLAG_CHECKED               0x00000080
      60                 :            : 
      61                 :            :         // ----------------------------------------------------------------
      62                 :            :         // ................................................................
      63                 :            :         struct ControlDescription
      64                 :            :         {
      65                 :            :             const sal_Char* pControlName;
      66                 :            :             sal_Int16       nControlId;
      67                 :            :             sal_Int32       nPropertyFlags;
      68                 :            :         };
      69                 :            : 
      70                 :            :         // ................................................................
      71                 :            :         typedef const ControlDescription* ControlDescIterator;
      72                 :            :         typedef ::std::pair< ControlDescIterator, ControlDescIterator > ControlDescRange;
      73                 :            : 
      74                 :            :         // ......................................................................
      75                 :            :         #define PROPERTY_FLAGS_COMMON       ( PROPERTY_FLAG_ENDBALED | PROPERTY_FLAG_VISIBLE | PROPERTY_FLAG_HELPURL )
      76                 :            :         #define PROPERTY_FLAGS_LISTBOX      ( PROPERTY_FLAG_LISTITEMS | PROPERTY_FLAG_SELECTEDITEM | PROPERTY_FLAG_SELECTEDITEMINDEX )
      77                 :            :         #define PROPERTY_FLAGS_CHECKBOX     ( PROPERTY_FLAG_CHECKED | PROPERTY_FLAG_TEXT )
      78                 :            : 
      79                 :            :         // Note: this array MUST be sorted by name!
      80                 :            :         static const ControlDescription aDescriptions[] =  {
      81                 :            :             { "AutoExtensionBox",       CHECKBOX_AUTOEXTENSION,         PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX     },
      82                 :            :             { "CancelButton",           PUSHBUTTON_CANCEL,              PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
      83                 :            :             { "CurrentFolderText",      FIXEDTEXT_CURRENTFOLDER,        PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
      84                 :            :             { "DefaultLocationButton",  TOOLBOXBUTOON_DEFAULT_LOCATION, PROPERTY_FLAGS_COMMON                               },
      85                 :            :             { "FileURLEdit",            EDIT_FILEURL,                   PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
      86                 :            :             { "FileURLEditLabel",       EDIT_FILEURL_LABEL,             PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
      87                 :            :             { "FileView",               CONTROL_FILEVIEW,               PROPERTY_FLAGS_COMMON                               },
      88                 :            :             { "FilterList",             LISTBOX_FILTER,                 PROPERTY_FLAGS_COMMON                               },
      89                 :            :             { "FilterListLabel",        LISTBOX_FILTER_LABEL,           PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
      90                 :            :             { "FilterOptionsBox",       CHECKBOX_FILTEROPTIONS,         PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX     },
      91                 :            :             { "HelpButton",             PUSHBUTTON_HELP,                PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
      92                 :            :             { "ImageTemplateList",      LISTBOX_IMAGE_TEMPLATE,         PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX      },
      93                 :            :             { "ImageTemplateListLabel", LISTBOX_IMAGE_TEMPLATE_LABEL,   PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
      94                 :            :             { "LevelUpButton",          TOOLBOXBUTOON_LEVEL_UP,         PROPERTY_FLAGS_COMMON                               },
      95                 :            :             { "LinkBox",                CHECKBOX_LINK,                  PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX     },
      96                 :            :             { "NewFolderButton",        TOOLBOXBUTOON_NEW_FOLDER,       PROPERTY_FLAGS_COMMON                               },
      97                 :            :             { "OkButton",               PUSHBUTTON_OK ,                 PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
      98                 :            :             { "PasswordBox",            CHECKBOX_PASSWORD,              PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX     },
      99                 :            :             { "PlayButton",             PUSHBUTTON_PLAY,                PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
     100                 :            :             { "PreviewBox",             CHECKBOX_PREVIEW,               PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX     },
     101                 :            :             { "ReadOnlyBox",            CHECKBOX_READONLY,              PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX     },
     102                 :            :             { "SelectionBox",           CHECKBOX_SELECTION,             PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX     },
     103                 :            :             { "TemplateList",           LISTBOX_TEMPLATE,               PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX      },
     104                 :            :             { "TemplateListLabel",      LISTBOX_TEMPLATE_LABEL,         PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          },
     105                 :            :             { "VersionList",            LISTBOX_VERSION,                PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX      },
     106                 :            :             { "VersionListLabel",       LISTBOX_VERSION_LABEL,          PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT          }
     107                 :            :         };
     108                 :            : 
     109                 :            :         // ................................................................
     110                 :            :         static const sal_Int32 s_nControlCount = sizeof( aDescriptions ) / sizeof( aDescriptions[0] );
     111                 :            : 
     112                 :            :         static ControlDescIterator s_pControls = aDescriptions;
     113                 :            :         static ControlDescIterator s_pControlsEnd = aDescriptions + s_nControlCount;
     114                 :            : 
     115                 :            :         // ................................................................
     116                 :            :         struct ControlDescriptionLookup
     117                 :            :         {
     118                 :          0 :             bool operator()( const ControlDescription& _rDesc1, const ControlDescription& _rDesc2 )
     119                 :            :             {
     120                 :          0 :                 return strcmp(_rDesc1.pControlName, _rDesc2.pControlName) < 0;
     121                 :            :             }
     122                 :            :         };
     123                 :            : 
     124                 :            :         // ................................................................
     125                 :            :         struct ExtractControlName : public ::std::unary_function< ControlDescription, ::rtl::OUString >
     126                 :            :         {
     127                 :            :             ::rtl::OUString operator()( const ControlDescription& _rDesc )
     128                 :            :             {
     129                 :            :                 return ::rtl::OUString::createFromAscii( _rDesc.pControlName );
     130                 :            :             }
     131                 :            :         };
     132                 :            : 
     133                 :            :         // ----------------------------------------------------------------
     134                 :            :         // ................................................................
     135                 :            :         struct ControlProperty
     136                 :            :         {
     137                 :            :             const sal_Char* pPropertyName;
     138                 :            :             sal_Int16       nPropertyId;
     139                 :            :         };
     140                 :            : 
     141                 :            :         typedef const ControlProperty* ControlPropertyIterator;
     142                 :            : 
     143                 :            :         // ................................................................
     144                 :            :         static const ControlProperty aProperties[] =  {
     145                 :            :             { "Text",               PROPERTY_FLAG_TEXT              },
     146                 :            :             { "Enabled",            PROPERTY_FLAG_ENDBALED          },
     147                 :            :             { "Visible",            PROPERTY_FLAG_VISIBLE           },
     148                 :            :             { "HelpURL",            PROPERTY_FLAG_HELPURL           },
     149                 :            :             { "ListItems",          PROPERTY_FLAG_LISTITEMS         },
     150                 :            :             { "SelectedItem",       PROPERTY_FLAG_SELECTEDITEM      },
     151                 :            :             { "SelectedItemIndex",  PROPERTY_FLAG_SELECTEDITEMINDEX },
     152                 :            :             { "Checked",            PROPERTY_FLAG_CHECKED           }
     153                 :            :         };
     154                 :            : 
     155                 :            :         // ................................................................
     156                 :            :         static const int s_nPropertyCount = sizeof( aProperties ) / sizeof( aProperties[0] );
     157                 :            : 
     158                 :            :         static ControlPropertyIterator s_pProperties = aProperties;
     159                 :            :         static ControlPropertyIterator s_pPropertiesEnd = aProperties + s_nPropertyCount;
     160                 :            : 
     161                 :            :         // ................................................................
     162                 :          0 :         struct ControlPropertyLookup
     163                 :            :         {
     164                 :            :             ::rtl::OUString m_sLookup;
     165                 :          0 :             ControlPropertyLookup( const ::rtl::OUString& _rLookup ) : m_sLookup( _rLookup ) { }
     166                 :            : 
     167                 :          0 :             sal_Bool operator()( const ControlProperty& _rProp )
     168                 :            :             {
     169                 :          0 :                 return m_sLookup.equalsAscii( _rProp.pPropertyName );
     170                 :            :             }
     171                 :            :         };
     172                 :            : 
     173                 :            :         //-----------------------------------------------------------------
     174                 :          0 :         void lcl_throwIllegalArgumentException( ) SAL_THROW( (IllegalArgumentException) )
     175                 :            :         {
     176                 :          0 :             throw IllegalArgumentException();
     177                 :            :             // TODO: error message in the exception
     178                 :            :         }
     179                 :            :     }
     180                 :            : 
     181                 :            :     //---------------------------------------------------------------------
     182                 :          0 :     OControlAccess::OControlAccess( IFilePickerController* _pController, SvtFileView* _pFileView )
     183                 :            :         :m_pFilePickerController( _pController )
     184                 :          0 :         ,m_pFileView( _pFileView )
     185                 :            :     {
     186                 :            :         DBG_ASSERT( m_pFilePickerController, "OControlAccess::OControlAccess: invalid control locator!" );
     187                 :          0 :     }
     188                 :            : 
     189                 :            :     //---------------------------------------------------------------------
     190                 :          0 :     void OControlAccess::setHelpURL( Window* _pControl, const ::rtl::OUString& sHelpURL, sal_Bool _bFileView )
     191                 :            :     {
     192                 :          0 :         rtl::OUString sHelpID( sHelpURL );
     193                 :          0 :         INetURLObject aHID( sHelpURL );
     194                 :          0 :         if ( aHID.GetProtocol() == INET_PROT_HID )
     195                 :          0 :               sHelpID = aHID.GetURLPath();
     196                 :            : 
     197                 :            :         // URLs should always be UTF8 encoded and escaped
     198                 :          0 :         rtl::OString sID( rtl::OUStringToOString( sHelpID, RTL_TEXTENCODING_UTF8 ) );
     199                 :          0 :         if ( _bFileView )
     200                 :            :             // the file view "overloaded" the SetHelpId
     201                 :          0 :             static_cast< SvtFileView* >( _pControl )->SetHelpId( sID );
     202                 :            :         else
     203                 :          0 :             _pControl->SetHelpId( sID );
     204                 :          0 :     }
     205                 :            : 
     206                 :            :     //---------------------------------------------------------------------
     207                 :          0 :     ::rtl::OUString OControlAccess::getHelpURL( Window* _pControl, sal_Bool _bFileView )
     208                 :            :     {
     209                 :          0 :         rtl::OString aHelpId = _pControl->GetHelpId();
     210                 :          0 :         if ( _bFileView )
     211                 :            :             // the file view "overloaded" the SetHelpId
     212                 :          0 :             aHelpId = static_cast< SvtFileView* >( _pControl )->GetHelpId( );
     213                 :            : 
     214                 :          0 :         ::rtl::OUString sHelpURL;
     215                 :          0 :         ::rtl::OUString aTmp( rtl::OStringToOUString( aHelpId, RTL_TEXTENCODING_UTF8 ) );
     216                 :          0 :         INetURLObject aHID( aTmp );
     217                 :          0 :         if ( aHID.GetProtocol() == INET_PROT_NOT_VALID )
     218                 :          0 :             sHelpURL = rtl::OUString::createFromAscii( INET_HID_SCHEME );
     219                 :          0 :         sHelpURL += aTmp;
     220                 :          0 :         return sHelpURL;
     221                 :            :     }
     222                 :            : 
     223                 :            :     // --------------------------------------------------------------------------
     224                 :          0 :     Any OControlAccess::getControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty )
     225                 :            :     {
     226                 :            :         // look up the control
     227                 :          0 :         sal_Int16 nControlId = -1;
     228                 :          0 :         sal_Int32 nPropertyMask = 0;
     229                 :          0 :         Control* pControl = implGetControl( _rControlName, &nControlId, &nPropertyMask );
     230                 :            :             // will throw an IllegalArgumentException if the name is not valid
     231                 :            : 
     232                 :            :         // look up the property
     233                 :          0 :         ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) );
     234                 :          0 :         if ( aPropDesc == s_pPropertiesEnd )
     235                 :            :             // it's a completely unknown property
     236                 :          0 :             lcl_throwIllegalArgumentException();
     237                 :            : 
     238                 :          0 :         if ( 0 == ( nPropertyMask & aPropDesc->nPropertyId ) )
     239                 :            :             // it's a property which is known, but not allowed for this control
     240                 :          0 :             lcl_throwIllegalArgumentException();
     241                 :            : 
     242                 :          0 :         return implGetControlProperty( pControl, aPropDesc->nPropertyId );
     243                 :            :     }
     244                 :            : 
     245                 :            :     //---------------------------------------------------------------------
     246                 :          0 :     Control* OControlAccess::implGetControl( const ::rtl::OUString& _rControlName, sal_Int16* _pId, sal_Int32* _pPropertyMask ) const SAL_THROW( (IllegalArgumentException) )
     247                 :            :     {
     248                 :          0 :         Control* pControl = NULL;
     249                 :            :         ControlDescription tmpDesc;
     250                 :          0 :         tmpDesc.pControlName = OUStringToOString(_rControlName, RTL_TEXTENCODING_UTF8).getStr();
     251                 :            : 
     252                 :            :         // translate the name into an id
     253                 :          0 :         ControlDescRange aFoundRange = ::std::equal_range( s_pControls, s_pControlsEnd, tmpDesc, ControlDescriptionLookup() );
     254                 :          0 :         if ( aFoundRange.first != aFoundRange.second )
     255                 :            :         {
     256                 :            :             // get the VCL control determined by this id
     257                 :          0 :             pControl = m_pFilePickerController->getControl( aFoundRange.first->nControlId );
     258                 :            :         }
     259                 :            : 
     260                 :            :         // if not found 'til here, the name is invalid, or we do not have the control in the current mode
     261                 :          0 :         if ( !pControl )
     262                 :          0 :             lcl_throwIllegalArgumentException();
     263                 :            : 
     264                 :            :         // out parameters and outta here
     265                 :          0 :         if ( _pId )
     266                 :          0 :             *_pId = aFoundRange.first->nControlId;
     267                 :          0 :         if ( _pPropertyMask )
     268                 :          0 :             *_pPropertyMask = aFoundRange.first->nPropertyFlags;
     269                 :            : 
     270                 :          0 :         return pControl;
     271                 :            :     }
     272                 :            : 
     273                 :            :     //---------------------------------------------------------------------
     274                 :          0 :     void OControlAccess::setControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty, const ::com::sun::star::uno::Any& _rValue )
     275                 :            :     {
     276                 :            :         // look up the control
     277                 :          0 :         sal_Int16 nControlId = -1;
     278                 :          0 :         Control* pControl = implGetControl( _rControlName, &nControlId );
     279                 :            :             // will throw an IllegalArgumentException if the name is not valid
     280                 :            : 
     281                 :            :         // look up the property
     282                 :          0 :         ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) );
     283                 :          0 :         if ( aPropDesc == s_pPropertiesEnd )
     284                 :          0 :             lcl_throwIllegalArgumentException();
     285                 :            : 
     286                 :            :         // set the property
     287                 :          0 :         implSetControlProperty( nControlId, pControl, aPropDesc->nPropertyId, _rValue, sal_False );
     288                 :          0 :     }
     289                 :            : 
     290                 :            :     // --------------------------------------------------------------------------
     291                 :          0 :     Sequence< ::rtl::OUString > OControlAccess::getSupportedControls(  )
     292                 :            :     {
     293                 :          0 :         Sequence< ::rtl::OUString > aControls( s_nControlCount );
     294                 :          0 :         ::rtl::OUString* pControls = aControls.getArray();
     295                 :            : 
     296                 :            :         // collect the names of all _actually_existent_ controls
     297                 :          0 :         for ( ControlDescIterator aControl = s_pControls; aControl != s_pControlsEnd; ++aControl )
     298                 :            :         {
     299                 :          0 :             if ( m_pFilePickerController->getControl( aControl->nControlId ) )
     300                 :          0 :                 *pControls++ = ::rtl::OUString::createFromAscii( aControl->pControlName );
     301                 :            :         }
     302                 :            : 
     303                 :          0 :         aControls.realloc( pControls - aControls.getArray() );
     304                 :          0 :         return aControls;
     305                 :            :     }
     306                 :            : 
     307                 :            :     // --------------------------------------------------------------------------
     308                 :          0 :     Sequence< ::rtl::OUString > OControlAccess::getSupportedControlProperties( const ::rtl::OUString& _rControlName )
     309                 :            :     {
     310                 :          0 :         sal_Int16 nControlId = -1;
     311                 :          0 :         sal_Int32 nPropertyMask = 0;
     312                 :          0 :         implGetControl( _rControlName, &nControlId, &nPropertyMask );
     313                 :            :             // will throw an IllegalArgumentException if the name is not valid
     314                 :            : 
     315                 :            :         // fill in the property names
     316                 :          0 :         Sequence< ::rtl::OUString > aProps( s_nPropertyCount );
     317                 :          0 :         ::rtl::OUString* pProperty = aProps.getArray();
     318                 :            : 
     319                 :          0 :         for ( ControlPropertyIterator aProp = s_pProperties; aProp != s_pPropertiesEnd; ++aProp )
     320                 :          0 :             if ( 0 != ( nPropertyMask & aProp->nPropertyId ) )
     321                 :          0 :                 *pProperty++ = ::rtl::OUString::createFromAscii( aProp->pPropertyName );
     322                 :            : 
     323                 :          0 :         aProps.realloc( pProperty - aProps.getArray() );
     324                 :          0 :         return aProps;
     325                 :            :     }
     326                 :            : 
     327                 :            :     // --------------------------------------------------------------------------
     328                 :          0 :     sal_Bool OControlAccess::isControlSupported( const ::rtl::OUString& _rControlName )
     329                 :            :     {
     330                 :            :         ControlDescription tmpDesc;
     331                 :          0 :         tmpDesc.pControlName = OUStringToOString(_rControlName, RTL_TEXTENCODING_UTF8).getStr();
     332                 :          0 :         return ::std::binary_search( s_pControls, s_pControlsEnd, tmpDesc, ControlDescriptionLookup() );
     333                 :            :     }
     334                 :            : 
     335                 :            :     // --------------------------------------------------------------------------
     336                 :          0 :     sal_Bool OControlAccess::isControlPropertySupported( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty )
     337                 :            :     {
     338                 :            :         // look up the control
     339                 :          0 :         sal_Int16 nControlId = -1;
     340                 :          0 :         sal_Int32 nPropertyMask = 0;
     341                 :          0 :         implGetControl( _rControlName, &nControlId, &nPropertyMask );
     342                 :            :             // will throw an IllegalArgumentException if the name is not valid
     343                 :            : 
     344                 :            :         // look up the property
     345                 :          0 :         ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) );
     346                 :          0 :         if ( aPropDesc == s_pPropertiesEnd )
     347                 :            :             // it's a property which is completely unknown
     348                 :          0 :             return sal_False;
     349                 :            : 
     350                 :          0 :         return 0 != ( aPropDesc->nPropertyId & nPropertyMask );
     351                 :            :     }
     352                 :            : 
     353                 :            :     //-----------------------------------------------------------------------------
     354                 :          0 :     void OControlAccess::setValue( sal_Int16 _nControlId, sal_Int16 _nControlAction, const Any& _rValue )
     355                 :            :     {
     356                 :          0 :         Control* pControl = m_pFilePickerController->getControl( _nControlId );
     357                 :            :         DBG_ASSERT( pControl, "OControlAccess::SetValue: don't have this control in the current mode!" );
     358                 :          0 :         if ( pControl )
     359                 :            :         {
     360                 :          0 :             sal_Int16 nPropertyId = -1;
     361                 :          0 :             if ( ControlActions::SET_HELP_URL == _nControlAction )
     362                 :            :             {
     363                 :          0 :                 nPropertyId = PROPERTY_FLAG_HELPURL;
     364                 :            :             }
     365                 :            :             else
     366                 :            :             {
     367                 :          0 :                 switch ( _nControlId )
     368                 :            :                 {
     369                 :            :                     case CHECKBOX_AUTOEXTENSION:
     370                 :            :                     case CHECKBOX_PASSWORD:
     371                 :            :                     case CHECKBOX_FILTEROPTIONS:
     372                 :            :                     case CHECKBOX_READONLY:
     373                 :            :                     case CHECKBOX_LINK:
     374                 :            :                     case CHECKBOX_PREVIEW:
     375                 :            :                     case CHECKBOX_SELECTION:
     376                 :          0 :                         nPropertyId = PROPERTY_FLAG_CHECKED;
     377                 :          0 :                         break;
     378                 :            : 
     379                 :            :                     case LISTBOX_FILTER:
     380                 :            :                         SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
     381                 :          0 :                         break;
     382                 :            : 
     383                 :            :                     case LISTBOX_VERSION:
     384                 :            :                     case LISTBOX_TEMPLATE:
     385                 :            :                     case LISTBOX_IMAGE_TEMPLATE:
     386                 :          0 :                         if ( ControlActions::SET_SELECT_ITEM == _nControlAction )
     387                 :            :                         {
     388                 :          0 :                             nPropertyId = PROPERTY_FLAG_SELECTEDITEMINDEX;
     389                 :            :                         }
     390                 :            :                         else
     391                 :            :                         {
     392                 :            :                             DBG_ASSERT( WINDOW_LISTBOX == pControl->GetType(), "OControlAccess::SetValue: implGetControl returned nonsense!" );
     393                 :          0 :                             implDoListboxAction( static_cast< ListBox* >( pControl ), _nControlAction, _rValue );
     394                 :            :                         }
     395                 :          0 :                         break;
     396                 :            :                 }
     397                 :            :             }
     398                 :            : 
     399                 :          0 :             if ( -1 != nPropertyId )
     400                 :          0 :                 implSetControlProperty( _nControlId, pControl, nPropertyId, _rValue );
     401                 :            :         }
     402                 :          0 :     }
     403                 :            : 
     404                 :            :     //-----------------------------------------------------------------------------
     405                 :          0 :     Any OControlAccess::getValue( sal_Int16 _nControlId, sal_Int16 _nControlAction ) const
     406                 :            :     {
     407                 :          0 :         Any aRet;
     408                 :            : 
     409                 :          0 :         Control* pControl = m_pFilePickerController->getControl( _nControlId, sal_False );
     410                 :            :         DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" );
     411                 :          0 :         if ( pControl )
     412                 :            :         {
     413                 :          0 :             sal_Int16 nPropertyId = -1;
     414                 :          0 :             if ( ControlActions::SET_HELP_URL == _nControlAction )
     415                 :            :             {
     416                 :          0 :                 nPropertyId = PROPERTY_FLAG_HELPURL;
     417                 :            :             }
     418                 :            :             else
     419                 :            :             {
     420                 :          0 :                 switch ( _nControlId )
     421                 :            :                 {
     422                 :            :                     case CHECKBOX_AUTOEXTENSION:
     423                 :            :                     case CHECKBOX_PASSWORD:
     424                 :            :                     case CHECKBOX_FILTEROPTIONS:
     425                 :            :                     case CHECKBOX_READONLY:
     426                 :            :                     case CHECKBOX_LINK:
     427                 :            :                     case CHECKBOX_PREVIEW:
     428                 :            :                     case CHECKBOX_SELECTION:
     429                 :          0 :                         nPropertyId = PROPERTY_FLAG_CHECKED;
     430                 :          0 :                         break;
     431                 :            : 
     432                 :            :                     case LISTBOX_FILTER:
     433                 :          0 :                         if ( ControlActions::GET_SELECTED_ITEM == _nControlAction )
     434                 :            :                         {
     435                 :          0 :                             aRet <<= ::rtl::OUString( m_pFilePickerController->getCurFilter() );;
     436                 :            :                         }
     437                 :            :                         else
     438                 :            :                         {
     439                 :            :                             SAL_WARN( "fpicker.office", "Use the XFilterManager to access the filter listbox" );
     440                 :            :                         }
     441                 :          0 :                         break;
     442                 :            : 
     443                 :            :                     case LISTBOX_VERSION:
     444                 :            :                     case LISTBOX_TEMPLATE:
     445                 :            :                     case LISTBOX_IMAGE_TEMPLATE:
     446                 :          0 :                         switch ( _nControlAction )
     447                 :            :                         {
     448                 :            :                             case ControlActions::GET_SELECTED_ITEM:
     449                 :          0 :                                 nPropertyId = PROPERTY_FLAG_SELECTEDITEM;
     450                 :          0 :                                 break;
     451                 :            :                             case ControlActions::GET_SELECTED_ITEM_INDEX:
     452                 :          0 :                                 nPropertyId = PROPERTY_FLAG_SELECTEDITEMINDEX;
     453                 :          0 :                                 break;
     454                 :            :                             case ControlActions::GET_ITEMS:
     455                 :          0 :                                 nPropertyId = PROPERTY_FLAG_LISTITEMS;
     456                 :          0 :                                 break;
     457                 :            :                             default:
     458                 :            :                                 SAL_WARN( "fpicker.office", "OControlAccess::GetValue: invalid control action for the listbox!" );
     459                 :          0 :                                 break;
     460                 :            :                         }
     461                 :          0 :                         break;
     462                 :            :                 }
     463                 :            :             }
     464                 :            : 
     465                 :          0 :             if ( -1 != nPropertyId )
     466                 :          0 :                 aRet = implGetControlProperty( pControl, nPropertyId );
     467                 :            :         }
     468                 :            : 
     469                 :          0 :         return aRet;
     470                 :            :     }
     471                 :            : 
     472                 :            :     //-----------------------------------------------------------------------------
     473                 :          0 :     void OControlAccess::setLabel( sal_Int16 nId, const ::rtl::OUString &rLabel )
     474                 :            :     {
     475                 :          0 :         Control* pControl = m_pFilePickerController->getControl( nId, sal_True );
     476                 :            :         DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" );
     477                 :          0 :         if ( pControl )
     478                 :          0 :             pControl->SetText( rLabel );
     479                 :          0 :     }
     480                 :            : 
     481                 :            :     //-----------------------------------------------------------------------------
     482                 :          0 :     ::rtl::OUString OControlAccess::getLabel( sal_Int16 nId ) const
     483                 :            :     {
     484                 :          0 :         ::rtl::OUString sLabel;
     485                 :            : 
     486                 :          0 :         Control* pControl = m_pFilePickerController->getControl( nId, sal_True );
     487                 :            :         DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" );
     488                 :          0 :         if ( pControl )
     489                 :          0 :             sLabel = pControl->GetText();
     490                 :            : 
     491                 :          0 :         return sLabel;
     492                 :            :     }
     493                 :            : 
     494                 :            :     //-----------------------------------------------------------------------------
     495                 :          0 :     void OControlAccess::enableControl( sal_Int16 _nId, sal_Bool _bEnable )
     496                 :            :     {
     497                 :          0 :         m_pFilePickerController->enableControl( _nId, _bEnable );
     498                 :          0 :     }
     499                 :            : 
     500                 :            :     // -----------------------------------------------------------------------
     501                 :          0 :     void OControlAccess::implDoListboxAction( ListBox* _pListbox, sal_Int16 _nControlAction, const Any& _rValue )
     502                 :            :     {
     503                 :          0 :         switch ( _nControlAction )
     504                 :            :         {
     505                 :            :             case ControlActions::ADD_ITEM:
     506                 :            :             {
     507                 :          0 :                 ::rtl::OUString aEntry;
     508                 :          0 :                 _rValue >>= aEntry;
     509                 :          0 :                 if ( !aEntry.isEmpty() )
     510                 :          0 :                     _pListbox->InsertEntry( aEntry );
     511                 :            :             }
     512                 :          0 :             break;
     513                 :            : 
     514                 :            :             case ControlActions::ADD_ITEMS:
     515                 :            :             {
     516                 :          0 :                 Sequence < ::rtl::OUString > aTemplateList;
     517                 :          0 :                 _rValue >>= aTemplateList;
     518                 :            : 
     519                 :          0 :                 if ( aTemplateList.getLength() )
     520                 :            :                 {
     521                 :          0 :                     for ( long i=0; i < aTemplateList.getLength(); i++ )
     522                 :          0 :                         _pListbox->InsertEntry( aTemplateList[i] );
     523                 :          0 :                 }
     524                 :            :             }
     525                 :          0 :             break;
     526                 :            : 
     527                 :            :             case ControlActions::DELETE_ITEM:
     528                 :            :             {
     529                 :          0 :                 sal_Int32 nPos = 0;
     530                 :          0 :                 if ( _rValue >>= nPos )
     531                 :          0 :                     _pListbox->RemoveEntry( (sal_uInt16) nPos );
     532                 :            :             }
     533                 :          0 :             break;
     534                 :            : 
     535                 :            :             case ControlActions::DELETE_ITEMS:
     536                 :          0 :                 _pListbox->Clear();
     537                 :          0 :                 break;
     538                 :            : 
     539                 :            :             default:
     540                 :            :                 SAL_WARN( "fpicker.office", "Wrong ControlAction for implDoListboxAction()" );
     541                 :            :         }
     542                 :          0 :     }
     543                 :            : 
     544                 :            :     //-----------------------------------------------------------------------------
     545                 :          0 :     void OControlAccess::implSetControlProperty( sal_Int16 _nControlId, Control* _pControl, sal_Int16 _nProperty, const Any& _rValue, sal_Bool _bIgnoreIllegalArgument )
     546                 :            :     {
     547                 :          0 :         if ( !_pControl )
     548                 :          0 :             _pControl = m_pFilePickerController->getControl( _nControlId );
     549                 :            :         DBG_ASSERT( _pControl, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" );
     550                 :          0 :         if ( !_pControl )
     551                 :          0 :             return;
     552                 :            : 
     553                 :            :         DBG_ASSERT( _pControl == m_pFilePickerController->getControl( _nControlId ),
     554                 :            :             "OControlAccess::implSetControlProperty: inconsistent parameters!" );
     555                 :            : 
     556                 :          0 :         switch ( _nProperty )
     557                 :            :         {
     558                 :            :             case PROPERTY_FLAG_TEXT:
     559                 :            :             {
     560                 :          0 :                 ::rtl::OUString sText;
     561                 :          0 :                 if ( _rValue >>= sText )
     562                 :            :                 {
     563                 :          0 :                     _pControl->SetText( sText );
     564                 :            :                 }
     565                 :          0 :                 else if ( !_bIgnoreIllegalArgument )
     566                 :            :                 {
     567                 :          0 :                     lcl_throwIllegalArgumentException();
     568                 :          0 :                 }
     569                 :            :             }
     570                 :          0 :             break;
     571                 :            : 
     572                 :            :             case PROPERTY_FLAG_ENDBALED:
     573                 :            :             {
     574                 :          0 :                 sal_Bool bEnabled = sal_False;
     575                 :          0 :                 if ( _rValue >>= bEnabled )
     576                 :            :                 {
     577                 :          0 :                     m_pFilePickerController->enableControl( _nControlId, bEnabled );
     578                 :            :                 }
     579                 :          0 :                 else if ( !_bIgnoreIllegalArgument )
     580                 :            :                 {
     581                 :          0 :                     lcl_throwIllegalArgumentException();
     582                 :            :                 }
     583                 :            :             }
     584                 :          0 :             break;
     585                 :            : 
     586                 :            :             case PROPERTY_FLAG_VISIBLE:
     587                 :            :             {
     588                 :          0 :                 sal_Bool bVisible = sal_False;
     589                 :          0 :                 if ( _rValue >>= bVisible )
     590                 :            :                 {
     591                 :          0 :                     _pControl->Show( bVisible );
     592                 :            :                 }
     593                 :          0 :                 else if ( !_bIgnoreIllegalArgument )
     594                 :            :                 {
     595                 :          0 :                     lcl_throwIllegalArgumentException();
     596                 :            :                 }
     597                 :            :             }
     598                 :          0 :             break;
     599                 :            : 
     600                 :            :             case PROPERTY_FLAG_HELPURL:
     601                 :            :             {
     602                 :          0 :                 ::rtl::OUString sHelpURL;
     603                 :          0 :                 if ( _rValue >>= sHelpURL )
     604                 :            :                 {
     605                 :          0 :                     setHelpURL( _pControl, sHelpURL, m_pFileView == _pControl );
     606                 :            :                 }
     607                 :          0 :                 else if ( !_bIgnoreIllegalArgument )
     608                 :            :                 {
     609                 :          0 :                     lcl_throwIllegalArgumentException();
     610                 :          0 :                 }
     611                 :            :             }
     612                 :          0 :             break;
     613                 :            : 
     614                 :            :             case PROPERTY_FLAG_LISTITEMS:
     615                 :            :             {
     616                 :            :                 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
     617                 :            :                     "OControlAccess::implSetControlProperty: invalid control/property combination!" );
     618                 :            : 
     619                 :          0 :                 Sequence< ::rtl::OUString > aItems;
     620                 :          0 :                 if ( _rValue >>= aItems )
     621                 :            :                 {
     622                 :            :                     // remove all previous items
     623                 :          0 :                     static_cast< ListBox* >( _pControl )->Clear();
     624                 :            : 
     625                 :            :                     // add the new ones
     626                 :          0 :                     const ::rtl::OUString* pItems       = aItems.getConstArray();
     627                 :          0 :                     const ::rtl::OUString* pItemsEnd    = aItems.getConstArray() + aItems.getLength();
     628                 :          0 :                     for (   const ::rtl::OUString* pItem = pItems;
     629                 :            :                             pItem != pItemsEnd;
     630                 :            :                             ++pItem
     631                 :            :                         )
     632                 :            :                     {
     633                 :          0 :                         static_cast< ListBox* >( _pControl )->InsertEntry( *pItem );
     634                 :            :                     }
     635                 :            : 
     636                 :            :                 }
     637                 :          0 :                 else if ( !_bIgnoreIllegalArgument )
     638                 :            :                 {
     639                 :          0 :                     lcl_throwIllegalArgumentException();
     640                 :          0 :                 }
     641                 :            :             }
     642                 :          0 :             break;
     643                 :            : 
     644                 :            :             case PROPERTY_FLAG_SELECTEDITEM:
     645                 :            :             {
     646                 :            :                 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
     647                 :            :                     "OControlAccess::implSetControlProperty: invalid control/property combination!" );
     648                 :            : 
     649                 :          0 :                 ::rtl::OUString sSelected;
     650                 :          0 :                 if ( _rValue >>= sSelected )
     651                 :            :                 {
     652                 :          0 :                     static_cast< ListBox* >( _pControl )->SelectEntry( sSelected );
     653                 :            :                 }
     654                 :          0 :                 else if ( !_bIgnoreIllegalArgument )
     655                 :            :                 {
     656                 :          0 :                     lcl_throwIllegalArgumentException();
     657                 :          0 :                 }
     658                 :            :             }
     659                 :          0 :             break;
     660                 :            : 
     661                 :            :             case PROPERTY_FLAG_SELECTEDITEMINDEX:
     662                 :            :             {
     663                 :            :                 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
     664                 :            :                     "OControlAccess::implSetControlProperty: invalid control/property combination!" );
     665                 :            : 
     666                 :          0 :                 sal_Int32 nPos = 0;
     667                 :          0 :                 if ( _rValue >>= nPos )
     668                 :            :                 {
     669                 :          0 :                     static_cast< ListBox* >( _pControl )->SelectEntryPos( (sal_uInt16) nPos );
     670                 :            :                 }
     671                 :          0 :                 else if ( !_bIgnoreIllegalArgument )
     672                 :            :                 {
     673                 :          0 :                     lcl_throwIllegalArgumentException();
     674                 :            :                 }
     675                 :            :             }
     676                 :          0 :             break;
     677                 :            : 
     678                 :            :             case PROPERTY_FLAG_CHECKED:
     679                 :            :             {
     680                 :            :                 DBG_ASSERT( WINDOW_CHECKBOX == _pControl->GetType(),
     681                 :            :                     "OControlAccess::implSetControlProperty: invalid control/property combination!" );
     682                 :            : 
     683                 :          0 :                 sal_Bool bChecked = sal_False;
     684                 :          0 :                 if ( _rValue >>= bChecked )
     685                 :            :                 {
     686                 :          0 :                     static_cast< CheckBox* >( _pControl )->Check( bChecked );
     687                 :            :                 }
     688                 :          0 :                 else if ( !_bIgnoreIllegalArgument )
     689                 :            :                 {
     690                 :          0 :                     lcl_throwIllegalArgumentException();
     691                 :            :                 }
     692                 :            :             }
     693                 :          0 :             break;
     694                 :            : 
     695                 :            :             default:
     696                 :            :                 OSL_FAIL( "OControlAccess::implSetControlProperty: invalid property id!" );
     697                 :            :         }
     698                 :            :     }
     699                 :            : 
     700                 :            :     //-----------------------------------------------------------------------------
     701                 :          0 :     Any OControlAccess::implGetControlProperty( Control* _pControl, sal_Int16 _nProperty ) const
     702                 :            :     {
     703                 :            :         DBG_ASSERT( _pControl, "OControlAccess::implGetControlProperty: invalid argument, this will crash!" );
     704                 :            : 
     705                 :          0 :         Any aReturn;
     706                 :          0 :         switch ( _nProperty )
     707                 :            :         {
     708                 :            :             case PROPERTY_FLAG_TEXT:
     709                 :          0 :                 aReturn <<= ::rtl::OUString( _pControl->GetText() );
     710                 :          0 :                 break;
     711                 :            : 
     712                 :            :             case PROPERTY_FLAG_ENDBALED:
     713                 :          0 :                 aReturn <<= (sal_Bool)_pControl->IsEnabled();
     714                 :          0 :                 break;
     715                 :            : 
     716                 :            :             case PROPERTY_FLAG_VISIBLE:
     717                 :          0 :                 aReturn <<= (sal_Bool)_pControl->IsVisible();
     718                 :          0 :                 break;
     719                 :            : 
     720                 :            :             case PROPERTY_FLAG_HELPURL:
     721                 :          0 :                 aReturn <<= getHelpURL( _pControl, m_pFileView == _pControl );
     722                 :          0 :                 break;
     723                 :            : 
     724                 :            :             case PROPERTY_FLAG_LISTITEMS:
     725                 :            :             {
     726                 :            :                 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
     727                 :            :                     "OControlAccess::implGetControlProperty: invalid control/property combination!" );
     728                 :            : 
     729                 :          0 :                 Sequence< ::rtl::OUString > aItems( static_cast< ListBox* >( _pControl )->GetEntryCount() );
     730                 :          0 :                 ::rtl::OUString* pItems = aItems.getArray();
     731                 :          0 :                 for ( sal_uInt16 i=0; i<static_cast< ListBox* >( _pControl )->GetEntryCount(); ++i )
     732                 :          0 :                     *pItems++ = static_cast< ListBox* >( _pControl )->GetEntry( i );
     733                 :            : 
     734                 :          0 :                 aReturn <<= aItems;
     735                 :            :             }
     736                 :          0 :             break;
     737                 :            : 
     738                 :            :             case PROPERTY_FLAG_SELECTEDITEM:
     739                 :            :             {
     740                 :            :                 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
     741                 :            :                     "OControlAccess::implGetControlProperty: invalid control/property combination!" );
     742                 :            : 
     743                 :          0 :                 sal_uInt16 nSelected = static_cast< ListBox* >( _pControl )->GetSelectEntryPos();
     744                 :          0 :                 ::rtl::OUString sSelected;
     745                 :          0 :                 if ( LISTBOX_ENTRY_NOTFOUND != nSelected )
     746                 :          0 :                     sSelected = static_cast< ListBox* >( _pControl )->GetSelectEntry();
     747                 :          0 :                 aReturn <<= sSelected;
     748                 :            :             }
     749                 :          0 :             break;
     750                 :            : 
     751                 :            :             case PROPERTY_FLAG_SELECTEDITEMINDEX:
     752                 :            :             {
     753                 :            :                 DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(),
     754                 :            :                     "OControlAccess::implGetControlProperty: invalid control/property combination!" );
     755                 :            : 
     756                 :          0 :                 sal_uInt16 nSelected = static_cast< ListBox* >( _pControl )->GetSelectEntryPos();
     757                 :          0 :                 if ( LISTBOX_ENTRY_NOTFOUND != nSelected )
     758                 :          0 :                     aReturn <<= (sal_Int32)static_cast< ListBox* >( _pControl )->GetSelectEntryPos();
     759                 :            :                 else
     760                 :          0 :                     aReturn <<= (sal_Int32)-1;
     761                 :            :             }
     762                 :          0 :             break;
     763                 :            : 
     764                 :            :             case PROPERTY_FLAG_CHECKED:
     765                 :            :                 DBG_ASSERT( WINDOW_CHECKBOX == _pControl->GetType(),
     766                 :            :                     "OControlAccess::implGetControlProperty: invalid control/property combination!" );
     767                 :            : 
     768                 :          0 :                 aReturn <<= (sal_Bool)static_cast< CheckBox* >( _pControl )->IsChecked( );
     769                 :          0 :                 break;
     770                 :            : 
     771                 :            :             default:
     772                 :            :                 OSL_FAIL( "OControlAccess::implGetControlProperty: invalid property id!" );
     773                 :            :         }
     774                 :          0 :         return aReturn;
     775                 :            :     }
     776                 :            : 
     777                 :            : //.........................................................................
     778                 :            : }   // namespace svt
     779                 :            : //.........................................................................
     780                 :            : 
     781                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10