LCOV - code coverage report
Current view: top level - fpicker/source/office - OfficeControlAccess.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 266 0.4 %
Date: 2014-11-03 Functions: 2 26 7.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10