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

Generated by: LCOV version 1.10