diff options
author | Oliver Bolte <obo@openoffice.org> | 2005-04-13 07:48:45 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2005-04-13 07:48:45 +0000 |
commit | f98218a9396780e2a9ef3d0e3a2e3ccd18dbc785 (patch) | |
tree | aaea16375fe1fca692eeda4cfe20643377cea4f7 /fpicker | |
parent | 2b81894e0c1817107bb53e7fb3324c8e658c3e13 (diff) |
INTEGRATION: CWS visibility03 (1.1.2); FILE ADDED
2005/03/24 16:43:58 mhu 1.1.2.1: #i45006# Factored out and moved from svtools/source/filepicker/
Diffstat (limited to 'fpicker')
-rw-r--r-- | fpicker/source/office/OfficeControlAccess.cxx | 827 | ||||
-rw-r--r-- | fpicker/source/office/OfficeControlAccess.hxx | 167 |
2 files changed, 994 insertions, 0 deletions
diff --git a/fpicker/source/office/OfficeControlAccess.cxx b/fpicker/source/office/OfficeControlAccess.cxx new file mode 100644 index 000000000000..b0c5ae1a72e2 --- /dev/null +++ b/fpicker/source/office/OfficeControlAccess.cxx @@ -0,0 +1,827 @@ +/************************************************************************* + * + * $RCSfile: OfficeControlAccess.cxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: obo $ $Date: 2005-04-13 08:48:26 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "OfficeControlAccess.hxx" + +#ifndef _COM_SUN_STAR_UI_DIALOGS_EXTENDEDFILEPICKERELEMENTIDS_HPP_ +#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> +#endif +#ifndef _COM_SUN_STAR_UI_DIALOGS_COMMONFILEPICKERELEMENTIDS_HPP_ +#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> +#endif +#ifndef _COM_SUN_STAR_UI_DIALOGS_CONTROLACTIONS_HPP_ +#include <com/sun/star/ui/dialogs/ControlActions.hpp> +#endif +#ifndef _SV_LSTBOX_HXX +#include <vcl/lstbox.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HPP_ +#include <com/sun/star/uno/Sequence.hxx> +#endif + +#include <algorithm> +#include <functional> + +//......................................................................... +namespace svt +{ +//......................................................................... + + // helper ------------------------------------------------------------- + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::ui::dialogs; + + using namespace ExtendedFilePickerElementIds; + using namespace CommonFilePickerElementIds; + using namespace InternalFilePickerElementIds; + + // -------------------------------------------------------------------- + namespace + { + // ---------------------------------------------------------------- + #define PROPERTY_FLAG_TEXT 0x00000001 + #define PROPERTY_FLAG_ENDBALED 0x00000002 + #define PROPERTY_FLAG_VISIBLE 0x00000004 + #define PROPERTY_FLAG_HELPURL 0x00000008 + #define PROPERTY_FLAG_LISTITEMS 0x00000010 + #define PROPERTY_FLAG_SELECTEDITEM 0x00000020 + #define PROPERTY_FLAG_SELECTEDITEMINDEX 0x00000040 + #define PROPERTY_FLAG_CHECKED 0x00000080 + + // ---------------------------------------------------------------- + // ................................................................ + struct ControlDescription + { + const sal_Char* pControlName; + sal_Int16 nControlId; + sal_Int32 nPropertyFlags; + }; + + // ................................................................ + typedef const ControlDescription* ControlDescIterator; + typedef ::std::pair< ControlDescIterator, ControlDescIterator > ControlDescRange; + + // ...................................................................... + #define PROPERTY_FLAGS_COMMON ( PROPERTY_FLAG_ENDBALED | PROPERTY_FLAG_VISIBLE | PROPERTY_FLAG_HELPURL ) + #define PROPERTY_FLAGS_LISTBOX ( PROPERTY_FLAG_LISTITEMS | PROPERTY_FLAG_SELECTEDITEM | PROPERTY_FLAG_SELECTEDITEMINDEX ) + #define PROPERTY_FLAGS_CHECKBOX ( PROPERTY_FLAG_CHECKED | PROPERTY_FLAG_TEXT ) + + // Note: this array MUST be sorted by name! + static const ControlDescription aDescriptions[] = { + { "AutoExtensionBox", CHECKBOX_AUTOEXTENSION, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, + { "CancelButton", PUSHBUTTON_CANCEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, + { "CurrentFolderText", FIXEDTEXT_CURRENTFOLDER, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, + { "DefaultLocationButton", TOOLBOXBUTOON_DEFAULT_LOCATION, PROPERTY_FLAGS_COMMON }, + { "FileURLEdit", EDIT_FILEURL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, + { "FileURLEditLabel", EDIT_FILEURL_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, + { "FileView", CONTROL_FILEVIEW, PROPERTY_FLAGS_COMMON }, + { "FilterList", LISTBOX_FILTER, PROPERTY_FLAGS_COMMON }, + { "FilterListLabel", LISTBOX_FILTER_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, + { "FilterOptionsBox", CHECKBOX_FILTEROPTIONS, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, + { "HelpButton", PUSHBUTTON_HELP, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, + { "ImageTemplateList", LISTBOX_IMAGE_TEMPLATE, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX }, + { "ImageTemplateListLabel", LISTBOX_IMAGE_TEMPLATE_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, + { "LevelUpButton", TOOLBOXBUTOON_LEVEL_UP, PROPERTY_FLAGS_COMMON }, + { "LinkBox", CHECKBOX_LINK, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, + { "NewFolderButton", TOOLBOXBUTOON_NEW_FOLDER, PROPERTY_FLAGS_COMMON }, + { "OkButton", PUSHBUTTON_OK , PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, + { "PasswordBox", CHECKBOX_PASSWORD, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, + { "PlayButton", PUSHBUTTON_PLAY, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, + { "PreviewBox", CHECKBOX_PREVIEW, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, + { "ReadOnlyBox", CHECKBOX_READONLY, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, + { "SelectionBox", CHECKBOX_SELECTION, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_CHECKBOX }, + { "TemplateList", LISTBOX_TEMPLATE, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX }, + { "TemplateListLabel", LISTBOX_TEMPLATE_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT }, + { "VersionList", LISTBOX_VERSION, PROPERTY_FLAGS_COMMON | PROPERTY_FLAGS_LISTBOX }, + { "VersionListLabel", LISTBOX_VERSION_LABEL, PROPERTY_FLAGS_COMMON | PROPERTY_FLAG_TEXT } + }; + + // ................................................................ + static const sal_Int32 s_nControlCount = sizeof( aDescriptions ) / sizeof( aDescriptions[0] ); + + static ControlDescIterator s_pControls = aDescriptions; + static ControlDescIterator s_pControlsEnd = aDescriptions + s_nControlCount; + + // ................................................................ + struct ControlDescriptionLookup + { + bool operator()( const ::rtl::OUString& _rLookup, const ControlDescription& _rDesc ) + { + return _rLookup.compareToAscii( _rDesc.pControlName ) < 0; + } + bool operator()( const ControlDescription& _rDesc, const ::rtl::OUString& _rLookup ) + { + return _rLookup.compareToAscii( _rDesc.pControlName ) > 0; + } + }; + + // ................................................................ + struct ExtractControlName : public ::std::unary_function< ControlDescription, ::rtl::OUString > + { + ::rtl::OUString operator()( const ControlDescription& _rDesc ) + { + return ::rtl::OUString::createFromAscii( _rDesc.pControlName ); + } + }; + + // ---------------------------------------------------------------- + // ................................................................ + struct ControlProperty + { + const sal_Char* pPropertyName; + sal_Int16 nPropertyId; + }; + + typedef const ControlProperty* ControlPropertyIterator; + + // ................................................................ + static const ControlProperty aProperties[] = { + { "Text", PROPERTY_FLAG_TEXT }, + { "Enabled", PROPERTY_FLAG_ENDBALED }, + { "Visible", PROPERTY_FLAG_VISIBLE }, + { "HelpURL", PROPERTY_FLAG_HELPURL }, + { "ListItems", PROPERTY_FLAG_LISTITEMS }, + { "SelectedItem", PROPERTY_FLAG_SELECTEDITEM }, + { "SelectedItemIndex", PROPERTY_FLAG_SELECTEDITEMINDEX }, + { "Checked", PROPERTY_FLAG_CHECKED } + }; + + // ................................................................ + static const int s_nPropertyCount = sizeof( aProperties ) / sizeof( aProperties[0] ); + + static ControlPropertyIterator s_pProperties = aProperties; + static ControlPropertyIterator s_pPropertiesEnd = aProperties + s_nPropertyCount; + + // ................................................................ + struct ControlPropertyLookup + { + ::rtl::OUString m_sLookup; + ControlPropertyLookup( const ::rtl::OUString& _rLookup ) : m_sLookup( _rLookup ) { } + + sal_Bool operator()( const ControlProperty& _rProp ) + { + return m_sLookup.equalsAscii( _rProp.pPropertyName ); + } + }; + + //----------------------------------------------------------------- + void lcl_throwIllegalArgumentException( ) SAL_THROW( (IllegalArgumentException) ) + { + throw IllegalArgumentException(); + // TODO: error message in the exception + } + } + + //--------------------------------------------------------------------- + OControlAccess::OControlAccess( IFilePickerController* _pController, SvtFileView* _pFileView ) + :m_pFilePickerController( _pController ) + ,m_pFileView( _pFileView ) + { + DBG_ASSERT( m_pFilePickerController, "OControlAccess::OControlAccess: invalid control locator!" ); + } + + //--------------------------------------------------------------------- + void OControlAccess::setHelpURL( Window* _pControl, const ::rtl::OUString& _rURL, sal_Bool _bFileView ) + { + String sHelpURL( _rURL ); + if ( COMPARE_EQUAL == sHelpURL.CompareIgnoreCaseToAscii( "HID:", sizeof( "HID:" ) - 1 ) ) + { + String sID = sHelpURL.Copy( sizeof( "HID:" ) - 1 ); + sal_Int32 nHelpId = sID.ToInt32(); + + if ( _bFileView ) + // the file view "overloaded" the SetHelpId + static_cast< SvtFileView* >( _pControl )->SetHelpId( nHelpId ); + else + _pControl->SetHelpId( nHelpId ); + } + else + DBG_ERRORFILE( "OControlAccess::setHelpURL: unsupported help URL type!" ); + } + + //--------------------------------------------------------------------- + ::rtl::OUString OControlAccess::getHelpURL( Window* _pControl, sal_Bool _bFileView ) + { + sal_Int32 nHelpId = _pControl->GetHelpId(); + if ( _bFileView ) + // the file view "overloaded" the SetHelpId + nHelpId = static_cast< SvtFileView* >( _pControl )->GetHelpId( ); + + ::rtl::OUString sHelpURL( RTL_CONSTASCII_USTRINGPARAM( "HID:" ) ); + sHelpURL += ::rtl::OUString::valueOf( (sal_Int32)nHelpId ); + + return sHelpURL; + } + + // -------------------------------------------------------------------------- + Any OControlAccess::getControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty ) + { + // look up the control + sal_Int16 nControlId = -1; + sal_Int32 nPropertyMask = 0; + Control* pControl = implGetControl( _rControlName, &nControlId, &nPropertyMask ); + // will throw an IllegalArgumentException if the name is not valid + + // look up the property + ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) ); + if ( aPropDesc == s_pPropertiesEnd ) + // it's a completely unknown property + lcl_throwIllegalArgumentException(); + + if ( 0 == ( nPropertyMask & aPropDesc->nPropertyId ) ) + // it's a property which is known, but not allowed for this control + lcl_throwIllegalArgumentException(); + + return implGetControlProperty( pControl, aPropDesc->nPropertyId ); + } + + //--------------------------------------------------------------------- + Control* OControlAccess::implGetControl( const ::rtl::OUString& _rControlName, sal_Int16* _pId, sal_Int32* _pPropertyMask ) const SAL_THROW( (IllegalArgumentException) ) + { + Control* pControl = NULL; + + // translate the name into an id + ControlDescRange aFoundRange = ::std::equal_range( s_pControls, s_pControlsEnd, _rControlName, ControlDescriptionLookup() ); + if ( aFoundRange.first != aFoundRange.second ) + { + // get the VCL control determined by this id + pControl = m_pFilePickerController->getControl( aFoundRange.first->nControlId ); + } + + // if not found 'til here, the name is invalid, or we do not have the control in the current mode + if ( !pControl ) + lcl_throwIllegalArgumentException(); + + // out parameters and outta here + if ( _pId ) + *_pId = aFoundRange.first->nControlId; + if ( _pPropertyMask ) + *_pPropertyMask = aFoundRange.first->nPropertyFlags; + + return pControl; + } + + //--------------------------------------------------------------------- + void OControlAccess::setControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty, const ::com::sun::star::uno::Any& _rValue ) + { + // look up the control + sal_Int16 nControlId = -1; + Control* pControl = implGetControl( _rControlName, &nControlId ); + // will throw an IllegalArgumentException if the name is not valid + + // look up the property + ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) ); + if ( aPropDesc == s_pPropertiesEnd ) + lcl_throwIllegalArgumentException(); + + // set the property + implSetControlProperty( nControlId, pControl, aPropDesc->nPropertyId, _rValue, sal_False ); + } + + // -------------------------------------------------------------------------- + Sequence< ::rtl::OUString > OControlAccess::getSupportedControls( ) + { + Sequence< ::rtl::OUString > aControls( s_nControlCount ); + ::rtl::OUString* pControls = aControls.getArray(); + + // collect the names of all _actually_existent_ controls + for ( ControlDescIterator aControl = s_pControls; aControl != s_pControlsEnd; ++aControl ) + { + if ( m_pFilePickerController->getControl( aControl->nControlId ) ) + *pControls++ = ::rtl::OUString::createFromAscii( aControl->pControlName ); + } + + aControls.realloc( pControls - aControls.getArray() ); + return aControls; + } + + // -------------------------------------------------------------------------- + Sequence< ::rtl::OUString > OControlAccess::getSupportedControlProperties( const ::rtl::OUString& _rControlName ) + { + sal_Int16 nControlId = -1; + sal_Int32 nPropertyMask = 0; + implGetControl( _rControlName, &nControlId, &nPropertyMask ); + // will throw an IllegalArgumentException if the name is not valid + + // fill in the property names + Sequence< ::rtl::OUString > aProperties( s_nPropertyCount ); + ::rtl::OUString* pProperty = aProperties.getArray(); + + for ( ControlPropertyIterator aProp = s_pProperties; aProp != s_pPropertiesEnd; ++aProp ) + if ( 0 != ( nPropertyMask & aProp->nPropertyId ) ) + *pProperty++ = ::rtl::OUString::createFromAscii( aProp->pPropertyName ); + + aProperties.realloc( pProperty - aProperties.getArray() ); + return aProperties; + } + + // -------------------------------------------------------------------------- + sal_Bool OControlAccess::isControlSupported( const ::rtl::OUString& _rControlName ) + { + return ::std::binary_search( s_pControls, s_pControlsEnd, _rControlName, ControlDescriptionLookup() ); + } + + // -------------------------------------------------------------------------- + sal_Bool OControlAccess::isControlPropertySupported( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty ) + { + // look up the control + sal_Int16 nControlId = -1; + sal_Int32 nPropertyMask = 0; + implGetControl( _rControlName, &nControlId, &nPropertyMask ); + // will throw an IllegalArgumentException if the name is not valid + + // look up the property + ControlPropertyIterator aPropDesc = ::std::find_if( s_pProperties, s_pPropertiesEnd, ControlPropertyLookup( _rControlProperty ) ); + if ( aPropDesc == s_pPropertiesEnd ) + // it's a property which is completely unknown + return sal_False; + + return 0 != ( aPropDesc->nPropertyId & nPropertyMask ); + } + + //----------------------------------------------------------------------------- + void OControlAccess::setValue( sal_Int16 _nControlId, sal_Int16 _nControlAction, const Any& _rValue ) + { + Control* pControl = m_pFilePickerController->getControl( _nControlId ); + DBG_ASSERT( pControl, "OControlAccess::SetValue: don't have this control in the current mode!" ); + if ( pControl ) + { + sal_Int16 nPropertyId = -1; + if ( ControlActions::SET_HELP_URL == _nControlAction ) + { + nPropertyId = PROPERTY_FLAG_HELPURL; + } + else + { + switch ( _nControlId ) + { + case CHECKBOX_AUTOEXTENSION: + case CHECKBOX_PASSWORD: + case CHECKBOX_FILTEROPTIONS: + case CHECKBOX_READONLY: + case CHECKBOX_LINK: + case CHECKBOX_PREVIEW: + case CHECKBOX_SELECTION: + nPropertyId = PROPERTY_FLAG_CHECKED; + break; + + case LISTBOX_FILTER: + DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" ); + break; + + case LISTBOX_VERSION: + case LISTBOX_TEMPLATE: + case LISTBOX_IMAGE_TEMPLATE: + if ( ControlActions::SET_SELECT_ITEM == _nControlAction ) + { + nPropertyId = PROPERTY_FLAG_SELECTEDITEMINDEX; + } + else + { + DBG_ASSERT( WINDOW_LISTBOX == pControl->GetType(), "OControlAccess::SetValue: implGetControl returned nonsense!" ); + implDoListboxAction( static_cast< ListBox* >( pControl ), _nControlAction, _rValue ); + } + break; + } + } + + if ( -1 != nPropertyId ) + implSetControlProperty( _nControlId, pControl, nPropertyId, _rValue ); + } + } + + //----------------------------------------------------------------------------- + Any OControlAccess::getValue( sal_Int16 _nControlId, sal_Int16 _nControlAction ) const + { + Any aRet; + + Control* pControl = m_pFilePickerController->getControl( _nControlId, sal_False ); + DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" ); + if ( pControl ) + { + sal_Int16 nPropertyId = -1; + if ( ControlActions::SET_HELP_URL == _nControlAction ) + { + nPropertyId = PROPERTY_FLAG_HELPURL; + } + else + { + switch ( _nControlId ) + { + case CHECKBOX_AUTOEXTENSION: + case CHECKBOX_PASSWORD: + case CHECKBOX_FILTEROPTIONS: + case CHECKBOX_READONLY: + case CHECKBOX_LINK: + case CHECKBOX_PREVIEW: + case CHECKBOX_SELECTION: + nPropertyId = PROPERTY_FLAG_CHECKED; + break; + + case LISTBOX_FILTER: + if ( ControlActions::GET_SELECTED_ITEM == _nControlAction ) + { + aRet <<= ::rtl::OUString( m_pFilePickerController->getCurFilter() );; + } + else + DBG_ERRORFILE( "Use the XFilterManager to access the filter listbox" ); + break; + + case LISTBOX_VERSION: + case LISTBOX_TEMPLATE: + case LISTBOX_IMAGE_TEMPLATE: + switch ( _nControlAction ) + { + case ControlActions::GET_SELECTED_ITEM: + nPropertyId = PROPERTY_FLAG_SELECTEDITEM; + break; + case ControlActions::GET_SELECTED_ITEM_INDEX: + nPropertyId = PROPERTY_FLAG_SELECTEDITEMINDEX; + break; + case ControlActions::GET_ITEMS: + nPropertyId = PROPERTY_FLAG_LISTITEMS; + break; + default: + DBG_ERRORFILE( "OControlAccess::GetValue: invalid control action for the listbox!" ); + break; + } + break; + } + } + + if ( -1 != nPropertyId ) + aRet = implGetControlProperty( pControl, nPropertyId ); + } + + return aRet; + } + + //----------------------------------------------------------------------------- + void OControlAccess::setLabel( sal_Int16 nId, const ::rtl::OUString &rLabel ) + { + Control* pControl = m_pFilePickerController->getControl( nId, sal_True ); + DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" ); + if ( pControl ) + pControl->SetText( rLabel ); + } + + //----------------------------------------------------------------------------- + ::rtl::OUString OControlAccess::getLabel( sal_Int16 nId ) const + { + ::rtl::OUString sLabel; + + Control* pControl = m_pFilePickerController->getControl( nId, sal_True ); + DBG_ASSERT( pControl, "OControlAccess::GetValue: don't have this control in the current mode!" ); + if ( pControl ) + sLabel = pControl->GetText(); + + return sLabel; + } + + //----------------------------------------------------------------------------- + void OControlAccess::enableControl( sal_Int16 _nId, sal_Bool _bEnable ) + { + m_pFilePickerController->enableControl( _nId, _bEnable ); + } + + // ----------------------------------------------------------------------- + void OControlAccess::implDoListboxAction( ListBox* _pListbox, sal_Int16 _nControlAction, const Any& _rValue ) + { + switch ( _nControlAction ) + { + case ControlActions::ADD_ITEM: + { + ::rtl::OUString aEntry; + _rValue >>= aEntry; + if ( aEntry.getLength() ) + _pListbox->InsertEntry( aEntry ); + } + break; + + case ControlActions::ADD_ITEMS: + { + Sequence < ::rtl::OUString > aTemplateList; + _rValue >>= aTemplateList; + + if ( aTemplateList.getLength() ) + { + for ( long i=0; i < aTemplateList.getLength(); i++ ) + _pListbox->InsertEntry( aTemplateList[i] ); + } + } + break; + + case ControlActions::DELETE_ITEM: + { + sal_Int32 nPos; + if ( _rValue >>= nPos ) + _pListbox->RemoveEntry( (USHORT) nPos ); + } + break; + + case ControlActions::DELETE_ITEMS: + _pListbox->Clear(); + break; + + default: + DBG_ERRORFILE( "Wrong ControlAction for implDoListboxAction()" ); + } + } + + //----------------------------------------------------------------------------- + void OControlAccess::implSetControlProperty( sal_Int16 _nControlId, Control* _pControl, sal_Int16 _nProperty, const Any& _rValue, sal_Bool _bIgnoreIllegalArgument ) + { + if ( !_pControl ) + _pControl = m_pFilePickerController->getControl( _nControlId ); + DBG_ASSERT( _pControl, "OControlAccess::implSetControlProperty: invalid argument, this will crash!" ); + if ( !_pControl ) + return; + + DBG_ASSERT( _pControl == m_pFilePickerController->getControl( _nControlId ), + "OControlAccess::implSetControlProperty: inconsistent parameters!" ); + + switch ( _nProperty ) + { + case PROPERTY_FLAG_TEXT: + { + ::rtl::OUString sText; + if ( _rValue >>= sText ) + { + _pControl->SetText( sText ); + } + else if ( !_bIgnoreIllegalArgument ) + { + lcl_throwIllegalArgumentException(); + } + } + break; + + case PROPERTY_FLAG_ENDBALED: + { + sal_Bool bEnabled = sal_False; + if ( _rValue >>= bEnabled ) + { + m_pFilePickerController->enableControl( _nControlId, bEnabled ); + } + else if ( !_bIgnoreIllegalArgument ) + { + lcl_throwIllegalArgumentException(); + } + } + break; + + case PROPERTY_FLAG_VISIBLE: + { + sal_Bool bVisible = sal_False; + if ( _rValue >>= bVisible ) + { + _pControl->Show( bVisible ); + } + else if ( !_bIgnoreIllegalArgument ) + { + lcl_throwIllegalArgumentException(); + } + } + break; + + case PROPERTY_FLAG_HELPURL: + { + ::rtl::OUString sHelpURL; + if ( _rValue >>= sHelpURL ) + { + setHelpURL( _pControl, sHelpURL, m_pFileView == _pControl ); + } + else if ( !_bIgnoreIllegalArgument ) + { + lcl_throwIllegalArgumentException(); + } + } + break; + + case PROPERTY_FLAG_LISTITEMS: + { + DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), + "OControlAccess::implSetControlProperty: invalid control/property combination!" ); + + Sequence< ::rtl::OUString > aItems; + if ( _rValue >>= aItems ) + { + // remove all previous items + static_cast< ListBox* >( _pControl )->Clear(); + + // add the new ones + const ::rtl::OUString* pItems = aItems.getConstArray(); + const ::rtl::OUString* pItemsEnd = aItems.getConstArray() + aItems.getLength(); + for ( const ::rtl::OUString* pItem = pItems; + pItem != pItemsEnd; + ++pItem + ) + { + static_cast< ListBox* >( _pControl )->InsertEntry( *pItem ); + } + + } + else if ( !_bIgnoreIllegalArgument ) + { + lcl_throwIllegalArgumentException(); + } + } + break; + + case PROPERTY_FLAG_SELECTEDITEM: + { + DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), + "OControlAccess::implSetControlProperty: invalid control/property combination!" ); + + ::rtl::OUString sSelected; + if ( _rValue >>= sSelected ) + { + static_cast< ListBox* >( _pControl )->SelectEntry( sSelected ); + } + else if ( !_bIgnoreIllegalArgument ) + { + lcl_throwIllegalArgumentException(); + } + } + break; + + case PROPERTY_FLAG_SELECTEDITEMINDEX: + { + DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), + "OControlAccess::implSetControlProperty: invalid control/property combination!" ); + + sal_Int32 nPos; + if ( _rValue >>= nPos ) + { + static_cast< ListBox* >( _pControl )->SelectEntryPos( (USHORT) nPos ); + } + else if ( !_bIgnoreIllegalArgument ) + { + lcl_throwIllegalArgumentException(); + } + } + break; + + case PROPERTY_FLAG_CHECKED: + { + DBG_ASSERT( WINDOW_CHECKBOX == _pControl->GetType(), + "OControlAccess::implSetControlProperty: invalid control/property combination!" ); + + sal_Bool bChecked = sal_False; + if ( _rValue >>= bChecked ) + { + static_cast< CheckBox* >( _pControl )->Check( bChecked ); + } + else if ( !_bIgnoreIllegalArgument ) + { + lcl_throwIllegalArgumentException(); + } + } + break; + + default: + DBG_ERROR( "OControlAccess::implSetControlProperty: invalid property id!" ); + } + } + + //----------------------------------------------------------------------------- + Any OControlAccess::implGetControlProperty( Control* _pControl, sal_Int16 _nProperty ) const + { + DBG_ASSERT( _pControl, "OControlAccess::implGetControlProperty: invalid argument, this will crash!" ); + + Any aReturn; + switch ( _nProperty ) + { + case PROPERTY_FLAG_TEXT: + aReturn <<= ::rtl::OUString( _pControl->GetText() ); + break; + + case PROPERTY_FLAG_ENDBALED: + aReturn <<= (sal_Bool)_pControl->IsEnabled(); + break; + + case PROPERTY_FLAG_VISIBLE: + aReturn <<= (sal_Bool)_pControl->IsVisible(); + break; + + case PROPERTY_FLAG_HELPURL: + aReturn <<= getHelpURL( _pControl, m_pFileView == _pControl ); + break; + + case PROPERTY_FLAG_LISTITEMS: + { + DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), + "OControlAccess::implGetControlProperty: invalid control/property combination!" ); + + Sequence< ::rtl::OUString > aItems( static_cast< ListBox* >( _pControl )->GetEntryCount() ); + ::rtl::OUString* pItems = aItems.getArray(); + for ( USHORT i=0; i<static_cast< ListBox* >( _pControl )->GetEntryCount(); ++i ) + *pItems++ = static_cast< ListBox* >( _pControl )->GetEntry( i ); + + aReturn <<= aItems; + } + break; + + case PROPERTY_FLAG_SELECTEDITEM: + { + DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), + "OControlAccess::implGetControlProperty: invalid control/property combination!" ); + + USHORT nSelected = static_cast< ListBox* >( _pControl )->GetSelectEntryPos(); + ::rtl::OUString sSelected; + if ( LISTBOX_ENTRY_NOTFOUND != nSelected ) + sSelected = static_cast< ListBox* >( _pControl )->GetSelectEntry(); + aReturn <<= sSelected; + } + break; + + case PROPERTY_FLAG_SELECTEDITEMINDEX: + { + DBG_ASSERT( WINDOW_LISTBOX == _pControl->GetType(), + "OControlAccess::implGetControlProperty: invalid control/property combination!" ); + + USHORT nSelected = static_cast< ListBox* >( _pControl )->GetSelectEntryPos(); + if ( LISTBOX_ENTRY_NOTFOUND != nSelected ) + aReturn <<= (sal_Int32)static_cast< ListBox* >( _pControl )->GetSelectEntryPos(); + else + aReturn <<= (sal_Int32)-1; + } + break; + + case PROPERTY_FLAG_CHECKED: + DBG_ASSERT( WINDOW_CHECKBOX == _pControl->GetType(), + "OControlAccess::implGetControlProperty: invalid control/property combination!" ); + + aReturn <<= (sal_Bool)static_cast< CheckBox* >( _pControl )->IsChecked( ); + break; + + default: + DBG_ERROR( "OControlAccess::implGetControlProperty: invalid property id!" ); + } + return aReturn; + } + +//......................................................................... +} // namespace svt +//......................................................................... + diff --git a/fpicker/source/office/OfficeControlAccess.hxx b/fpicker/source/office/OfficeControlAccess.hxx new file mode 100644 index 000000000000..1c29b16ef70a --- /dev/null +++ b/fpicker/source/office/OfficeControlAccess.hxx @@ -0,0 +1,167 @@ +/************************************************************************* + * + * $RCSfile: OfficeControlAccess.hxx,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: obo $ $Date: 2005-04-13 08:48:45 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef SVTOOLS_CONTROLACCESS_HXX +#define SVTOOLS_CONTROLACCESS_HXX + +#ifndef _SVT_FILEVIEW_HXX +#include <svtools/fileview.hxx> +#endif +#ifndef _SV_LSTBOX_HXX +#include <vcl/lstbox.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_ +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#endif +#ifndef SVTOOLS_PICKER_CALLBACKS_HXX +#include "pickercallbacks.hxx" +#endif + +//......................................................................... +namespace svt +{ +//......................................................................... + + // -------------------------------------------------------------------- + namespace InternalFilePickerElementIds + { + static const sal_Int16 PUSHBUTTON_HELP = (sal_Int16)0x1000; + static const sal_Int16 TOOLBOXBUTOON_DEFAULT_LOCATION = (sal_Int16)0x1001; + static const sal_Int16 TOOLBOXBUTOON_LEVEL_UP = (sal_Int16)0x1002; + static const sal_Int16 TOOLBOXBUTOON_NEW_FOLDER = (sal_Int16)0x1003; + static const sal_Int16 FIXEDTEXT_CURRENTFOLDER = (sal_Int16)0x1004; + } + + // -------------------------------------------------------------------- + /** implements the XControlAccess, XControlInformation and XFilePickerControlAccess for the file picker + */ + class OControlAccess + { + IFilePickerController* m_pFilePickerController; + SvtFileView* m_pFileView; + + public: + OControlAccess( IFilePickerController* _pController, SvtFileView* _pFileView ); + + // XControlAccess implementation + void setControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty, const ::com::sun::star::uno::Any& _rValue ); + ::com::sun::star::uno::Any getControlProperty( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty ); + + // XControlInformation implementation + ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedControls( ); + ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedControlProperties( const ::rtl::OUString& _rControlName ); + sal_Bool isControlSupported( const ::rtl::OUString& _rControlName ); + sal_Bool isControlPropertySupported( const ::rtl::OUString& _rControlName, const ::rtl::OUString& _rControlProperty ); + + // XFilePickerControlAccess + void setValue( sal_Int16 _nId, sal_Int16 _nCtrlAction, const ::com::sun::star::uno::Any& _rValue ); + ::com::sun::star::uno::Any getValue( sal_Int16 _nId, sal_Int16 _nCtrlAction ) const; + void setLabel( sal_Int16 _nId, const ::rtl::OUString& _rValue ); + ::rtl::OUString getLabel( sal_Int16 _nId ) const; + void enableControl( sal_Int16 _nId, sal_Bool _bEnable ); + + static void setHelpURL( Window* _pControl, const ::rtl::OUString& _rURL, sal_Bool _bFileView ); + static ::rtl::OUString getHelpURL( Window* _pControl, sal_Bool _bFileView ); + + private: + /** implements the various methods for setting properties on controls + + @param _nControlId + the id of the control + @param _pControl + the affected control. Must be the same as referred by <arg>_nControlId</arg>, or NULL. + @param _nProperty + the property to set + See PROPERTY_FLAG_* + @param _rValue + the value to set + @param _bIgnoreIllegalArgument + if <FALSE/>, an exception will be thrown if the given value is of improper type + */ + void implSetControlProperty( + sal_Int16 _nControlId, + Control* _pControl, sal_Int16 _nProperty, const ::com::sun::star::uno::Any& _rValue, + sal_Bool _bIgnoreIllegalArgument = sal_True ); + + Control* implGetControl( const ::rtl::OUString& _rControlName, sal_Int16* _pId = NULL, sal_Int32* _pPropertyMask = NULL ) const SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ); + + /** implements the various methods for retrieving properties from controls + + @param _pControl + the affected control + @PRECOND not <NULL/> + @param _nProperty + the property to retrieve + See PROPERTY_FLAG_* + @return + */ + ::com::sun::star::uno::Any implGetControlProperty( Control* _pControl, sal_Int16 _nProperty ) const; + + void implDoListboxAction( ListBox* _pListbox, sal_Int16 _nCtrlAction, const ::com::sun::star::uno::Any& _rValue ); + + }; + +//......................................................................... +} // namespace svt +//......................................................................... + +#endif // SVTOOLS_CONTROLACCESS_HXX + |